Repository navigation
fix(trading): a refused order is not a successful submit - #255
Closed
carlito-hummingbot wants to merge 3 commits into
Closed
carlito-hummingbot wants to merge 3 commits into
carlito-hummingbot wants to merge 3 commits into
Conversation
[Medium impact] The PR appears safe to merge, with no outstanding findings. Summary
Reviews (5) · Last reviewed commit: "style: restore the trailing newline thes..." · Reviewed by Greptile |
carlito-hummingbot
force-pushed
the
fix/refused-order-is-not-a-success
branch
from
November 13, 2026 14:05
5e99951 to
636d10d
Compare
Rebased onto main; the conflict was resolved by keeping this PR's refusal check with main's surrounding code. `AccountsService.place_trade` returned `connector.buy()`/`sell()`, which are fire-and-forget, so `POST /trading/orders` answered 201 for an order the venue had refused.
carlito-hummingbot
force-pushed
the
fix/refused-order-is-not-a-success
branch
from
November 16, 2026 09:14
636d10d to
6fea831
Compare
After the rebase conflict was resolved by hand, the file needed isort and one log call was 149 characters (flake8 limit 130). Formatting only.
The previous push trimmed the final newline off every file it carried, so `end-of-file-fixer` failed on files whose content was otherwise correct. Re-sent byte-exact. (For 8552 this is on top of the real fix: the tests now map the symbol the connector needs, so the cancel path runs instead of raising KeyError.)
This was referenced Nov 16, 2026
Author
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.
The defect
POST /trading/ordersanswered201 submittedfor an order the venue had refused.AccountsService.place_tradereturnsconnector.buy()/connector.sell(), and those calls are fire-and-forget: they register the order with the tracker and return the client order id, while the venue call runs in the connector's own task. A refusal therefore lands on the in-flight order after the method has returned, and nothing on the request path ever looks at it.Reproduced against Derive v3 with a funded subaccount whose risk universe does not contain the pair:
Nothing on the venue had that id. The venue's answer was in the container log only:
An agent reading that response records exposure it does not have.
The fix
place_tradenow waits for the submission to resolve before answering:Three details matter, and the first two were wrong in my own first attempt:
all_orders, not justin_flight_orders. The tracker drops an order the moment it reaches a terminal state, so a refused order is precisely the one missing from the live map. Checking onlyin_flight_ordersreports every refusal as "not tracked".buy()returns — so the check polls to a bounded deadline (SUBMISSION_TIMEOUT_SEC = 15 s) instead of treating the first miss as success.PENDING_CREATEat the deadline, the request keeps its 201: the order may well be live, and failing it would be the opposite error.InFlightOrderin this version carries no failure text (onlyis_failure), so the detail degrades to "the venue rejected the order" when a connector exposes no reason; the connector still logs the venue's own error.Verified live
Same account, same endpoint, before and after:
Book left clean: 0 open orders, 0 positions.
Tests
test/test_place_order_refusal.py— 8 tests, and 4 fail onmain:Not addressed
Reporting the venue's full error text through the API would need the connector to keep it on the order (
InFlightOrderhas nowhere to put it in this version). The classification here is deliberately conservative: refused, accepted, or unconfirmed — never "submitted" for something the venue threw away.