Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pass None as a value to certain parameters #250

Open
addrob opened this issue Oct 27, 2024 · 2 comments
Open

Unable to pass None as a value to certain parameters #250

addrob opened this issue Oct 27, 2024 · 2 comments

Comments

@addrob
Copy link

addrob commented Oct 27, 2024

If you try to directly pass None as a value for

"qty",
"price",
"triggerPrice",
"takeProfit",
"stopLoss"

it will be passed to API as a "None" value.

My guess is that the pybit._http_manager._V5HTTPManager.prepare_payload method is responsible for that. It tries to cast values for these params straight to str without caring what type they were originally even if it was a NoneType.

@dextertd
Copy link
Collaborator

Why would you pass None? If you don't want to pass anything to a param, there's no need to pass it at all. Adding extra params with dead data is inefficient for an HTTP request.

@kolya5544
Copy link

Passing "None" values might be useful for complex logic, like passing the price only when the order is Limit:

client.place_order(
            category="linear",
            symbol="OPUSDT",
            side="Sell",
            orderType=orderType,
            qty="0",
            price=price if orderType == "Limit" else None,
            reduceOnly=True,
            closeOnTrigger=True
        )

Most libraries using JSON serialization will set the serializer to ignore null values for this reason specifically. It's also considered the best practice to omit null values for query string values (GET HTTP request).

Just my humble opinion 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants