-
Notifications
You must be signed in to change notification settings - Fork 134
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
Comments
Why would you pass |
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 😃 |
I want to be able to pass a None value to a method in cases of some conditional param value defining logic. And I obviously expect that a "prepare_payload" method would actually prepare a payload instead of spoiling it when I simply use regular Python syntax. Just noticed that you actually deal with None's by excluding them from parameters dict, but you do it only for GET methods. Why won't you just do the same thing for other request types by adding smth like
before casting values ? |
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.
The text was updated successfully, but these errors were encountered: