binance_cancel_replace_order
Cancel an existing order and place its replacement in one atomic request, avoiding the exposure gap of a separate cancel-then-place. Use it to reprice or resize a resting limit order or roll a stop as the market moves.
Instructions
Cancel one order and place its replacement in a single request.
Calls POST /api/v3/order/cancelReplace (SIGNED, IP weight 1, unfilled-order count
1). Use it to reprice a resting order without the window of exposure that a separate
cancel-then-place leaves open.
Kill-switch. Refused with Error: … trading is disabled … unless the server runs
with BINANCE_ALLOW_TRADING=1.
The two halves can diverge, and cancel_replace_mode decides how:
STOP_ON_FAILURE— if the cancel fails, the new order is never attempted.ALLOW_FAILURE— the new order is attempted regardless of the cancel's outcome, so you can end up with both orders live, or neither.
HTTP 409 is the partial-success case: the cancel succeeded and the new order
failed. It is returned as Error (409): Partial success … followed by the same
cancelResult / newOrderResult breakdown as a success — so you can see exactly which
order was cancelled. Read it as "the old order is gone, the replacement is NOT live"
and re-place deliberately.
When to Use:
Repricing or resizing a resting limit order.
Rolling a stop as the market moves.
When NOT to Use:
For a fresh order with nothing to cancel — use
binance_place_order.To only pull an order — use
binance_cancel_order.On an order-list leg — cancel the list with
binance_cancel_order_list(order_lists.py) and place a new list.
Returns:
cancelResult and newOrderResult (SUCCESS / FAILURE / NOT_ATTEMPTED) plus the two
response objects Binance returned, rendered separately so it is unambiguous which
order is live.
Examples: params = {"symbol": "BTCUSDT", "side": "BUY", "type": "LIMIT", "time_in_force": "GTC", "quantity": "0.001", "price": "19500.00", "cancel_replace_mode": "STOP_ON_FAILURE", "cancel_order_id": 123456789} params = {"symbol": "BTCUSDT", "side": "BUY", "type": "LIMIT", "time_in_force": "GTC", "quantity": "0.002", "price": "19000.00", "cancel_replace_mode": "ALLOW_FAILURE", "cancel_orig_client_order_id": "my-entry-001", "cancel_restrictions": "ONLY_NEW"}
Error Handling:
HTTP 409 = cancel succeeded, replacement failed (see above). -2021/-2022 wrap the
failing half in {code, msg, data}. -2011 means the order to cancel was not
cancellable (filled, gone, or cancel_restrictions did not match). A 5xx/timeout
leaves BOTH halves UNKNOWN: read binance_get_open_orders for the symbol before
sending anything else.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |