fix(rest): send the order identifier params that were declared but dropped - #29
Open
pucedoteth wants to merge 1 commit into
Open
fix(rest): send the order identifier params that were declared but dropped#29pucedoteth wants to merge 1 commit into
pucedoteth wants to merge 1 commit into
Conversation
…opped
query_order (), cancel_order (), get_open_orders () and cancel_batch_order ()
all accept the parameters that say *which* order to act on, and then build the
request without them:
def cancel_order (self, symbol, orderId=None, origClientOrderId=None, **kwargs):
check_required_parameter (symbol, "symbol")
params = {"symbol": symbol, **kwargs}
orderId and origClientOrderId are bound to the named parameters, so they can
never arrive through **kwargs either - the value is simply discarded. Every one
of these calls goes out carrying nothing but symbol, and the API requires
"either orderId or origClientOrderId" (either orderIdList or
origClientOrderIdList for the batch), so all four fail server-side. There is no
way to query, cancel or inspect a specific order through the connector.
cancel_batch_order additionally declares both lists as required positionals, so
the documented "either ... or ..." call raises TypeError before any request is
built, and the lists need to be JSON arrays with no spaces per the API docs:
orderIdList=[1234567,2345678]
origClientOrderIdList=["my_id_1","my_id_2"]
convert_list_to_json_array () in aster/lib/utils.py already produces exactly
that and was not referenced anywhere in the package - it is wired up here.
Reported for cancel_order in asterdex#1.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1, and the same bug in three more endpoints.
The bug
Four functions in
aster/rest_api/account.pyaccept the parameters that identify which order to act on, and then build the request without them:Because the names are bound to the signature, they cannot arrive through
**kwargseither — the caller's value is simply discarded.query_orderGET /fapi/v1/ordersymbolcancel_orderDELETE /fapi/v1/ordersymbolget_open_ordersGET /fapi/v1/openOrdersymbolcancel_batch_orderDELETE /fapi/v1/batchOrderssymbolThe API docs require "Either
orderIdororigClientOrderIdmust be sent" on the first three and "EitherorderIdListororigClientOrderIdListmust be sent" on the fourth, so all four calls fail server-side. There is currently no way to query, cancel or inspect a specific order through the connector.Captured from the connector with the transport stubbed, no network — the full query string minus
timestamp/signature:cancel_batch_orderhas a second problem: both lists are declared as required positionals, so the documented either/or call raises before a request is even built:The fix
Put the parameters into
params.cleanNoneValue()in_prepare_paramsalready drops whichever one isNone, so only the identifier the caller supplied is sent, and the signature covers it because it is added beforesign_requestencodes.For
cancel_batch_orderthe lists also have to go out as JSON arrays with no spaces, per the docs:convert_list_to_json_array()inaster/lib/utils.pyalready produces exactly that string, and was not referenced anywhere in the package — it is wired up here rather than adding anything new. Passing the raw Python lists would instead produce repeated keys (orderIdList=1234567&orderIdList=2345678), which is not the documented format.Both lists also become optional, matching the docstring that already says "Either orderIdList or origClientOrderIdList must be sent." Existing positional callers are unaffected.
(shown URL-decoded; on the wire the brackets and quotes are percent-encoded, which is what the docs ask for)
Notes
@threewave-hun reported this for
cancel_orderin #1 with essentially this fix. This PR usescleanNoneValue's existingNonehandling rather than truthiness checks, and covers the other three endpoints with the same defect.The repo has no test suite, so there is nothing to add tests to — the before/after above is from driving the real
Clientwith_dispatch_requeststubbed out. Happy to add a smalltests/harness if you'd like one.🤖 Written with Claude Code. All output above is from running the connector locally.