Documentation Index
Fetch the complete documentation index at: https://mintlify.com/backtest-kit/wallet-manager/llms.txt
Use this file to discover all available pages before exploring further.
commitCancel is the definitive “flatten and exit to cash” operation. It is designed around a critical constraint of Binance spot: a resting order (take-profit, stop-loss, or a stale limit entry) locks the base coin or USDT it would need to fill. Attempting to sell over locked funds either fails with an insufficient balance error or silently trades only the unlocked remainder. The correct sequence is always: cancel every pending order, verify the book is empty, and only then sell the full coin balance. commitCancel enforces this sequence unconditionally.
Signature
Parameters
Binance trading pair symbol to flatten, e.g.
"SOLUSDT". All open orders on this symbol will be cancelled and all free coin balance will be sold.Returns
The average fill price of the sell order in USDT. Returns
0 if the free coin quantity after fee and minQty deductions is at or below minQty (dust) — in that case no sell order is placed and the tiny remainder is left on the account.Execution flow
Cancel all open orders
binance.openOrders(symbol) is fetched and every order in the response is cancelled via binance.cancel(symbol, orderId) with a 1-second pause between each cancellation. Individual cancel failures are tolerated — the entire sweep repeats up to 10 times until every order is gone or an unrecoverable error is thrown. If any cancellation error persists after all retries, it is rethrown so the caller can handle it.Verify book is clean
After the cancellation sweep,
binance.openOrders(symbol) is polled again — up to 10 times with a 1-second interval — until it returns an empty array. This confirms that the exchange has processed all cancellations and that no funds remain locked. If open orders are still present after all retries, an Error("Order not canceled") is thrown.Sell entire free balance
The current coin balance is fetched via If
FETCH_BALANCE_FN. The sellable quantity is:quantity <= minQty the function returns 0 (dust, not worth selling). Otherwise a LIMIT SELL is placed at currentPrice × 0.999. If the limit does not fill within 10 polls of 10 seconds each, it is cancelled and the remainder is submitted as a market sell.Fee accounting
Before placing the sell order,commitCancel subtracts the makerCommission percentage (read from binance.account()) and one minQty unit from the raw balance quantity. This ensures the order quantity is within the exchange’s accepted range and that fees do not cause a post-trade negative balance.