Repository navigation
fix(trading): cancel an order by venue id when the in-flight tracker lost it - #252
carlito-hummingbot wants to merge 3 commits into
Conversation
[Medium impact] The PR appears safe to merge; no new actionable issues were found. SummaryAdds a route to cancel orders by venue ID when they are no longer tracked.
Reviews (5) · Last reviewed commit: "style: restore the trailing newline thes..." · Reviewed by Greptile |
6479396 to
7aaabce
Compare
|
Re: P2 "Cancellation appears complete too early" — fixed, thank you. You are right: for a tracked order the service calls The response now carries the path and how far it actually got, and the message follows it: // tracked order — work scheduled, not confirmed
{"success": true, "order_id": "hbot-123", "via": "tracker",
"status": "initiated", "message": "Order 'hbot-123' cancellation initiated"}
// untracked order — cancellation transaction accepted by the venue
{"success": true, "order_id": "106553233", "via": "venue",
"status": "submitted", "message": "Order '106553233' cancellation submitted to the venue"}Neither wording claims the order is gone; the docstring says so explicitly ("Neither means the order is confirmed gone — check the venue for that"), which is also why the reconcile routine I use re-reads Live check against a running API (venue path, non-existent sequence → {"success":true,"message":"Order '999999999' cancellation submitted to the venue",
"order_id":"999999999","via":"venue","status":"submitted"}Tests updated and extended to 5, all passing:
|
Rebased onto main. `cancel_order` gates on `connector.in_flight_orders`, an in-memory map,
so an order whose owning process is gone cannot be cancelled at all -- it rests and can still
fill. Adds `POST /{account}/{connector}/orders/by-exchange-id/{id}/cancel` and
`AccountsService.cancel_order_by_exchange_id`, which prefers the tracker and otherwise calls
the connector's `cancel_by_exchange_order_id`. The response says whether the cancel was
`initiated` (scheduled via the tracker) or `submitted` to the venue.
7aaabce to
67902cf
Compare
Two blank lines before the appended endpoint, as the repo's flake8 config requires. No logic change.
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.)
Problem
cancel_ordergates on the in-flight tracker:in_flight_ordersis an in-memory map owned by the running process. When a bot is stopped, crashes, or is archived while an order is resting, the order is still live at the venue — but the API has no way to reach it. There is no cancel route that accepts a venue-side id, so the order sits on the book until a human clears it by hand.Reproduction (XRPL, live account)
Fix
Add the missing path, without changing behaviour for orders the process still tracks:
services/accounts_service.py—cancel_order_by_exchange_id(account_name, connector_name, exchange_order_id, trading_pair=None). If the tracker holds the order, it uses the existingconnector.cancel(...)path, so tracked orders behave exactly as before. Otherwise it callsconnector.cancel_by_exchange_order_id(...), and reports501when the connector has no such capability,500with the venue's cause when cancellation is rejected.routers/trading.py—POST /{account_name}/{connector_name}/orders/by-exchange-id/{exchange_order_id}/cancel.For XRPL the exchange order id starts with the offer sequence (
<sequence>-<pair>). The connector side is a companion PR againsthummingbot.Tests
test/test_cancel_by_exchange_id.py— 4 passed:501500, cause surfacedVerified end to end on a live XRPL account
Same orphan that the old route
404'd on:Who benefits
Every agent that can be stopped while orders are resting — which is all of them after a crash — with two Condor agents on XRPL (
aegisonRLUSD-XRP/XRP-USDC, and an XRPL maker onRLUSD-XRP) able to use it today through their startup reconcile pass.