A limit order that misses the market should never be left alive on the exchange. Resting orders are invisible to the engine: if a forgotten limit fills hours later at a price the engine no longer controls, it creates a real position that no engine state tracks. Wallet Manager prevents this by coupling every limit order to a bounded poll loop and a mandatory fallback: after a fixed waiting window, the limit is cancelled and any unfilled remainder is immediately market-ordered. The entry or exit is guaranteed to complete — one way or another — within the polling window.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.
The Poll Loop
After placing a limit order,commitBuy and commitSell enter a loop that checks order status every 10 seconds for up to 10 iterations — a maximum wait of 100 seconds:
isNotClosed starts as true and is only flipped to false on a confirmed "FILLED" status. If the loop exhausts all 10 iterations without seeing a fill, isNotClosed remains true and the timeout path fires.
The loop checks for
"FILLED" only. A "PARTIALLY_FILLED" status does not
break the loop early — the function continues waiting, giving the limit order
more time to complete its fill before the timeout triggers.Timeout Handling
WhenisNotClosed is still true after the poll loop, three things happen in sequence:
- Cancel the limit order — remove it from the book so it cannot fill later.
- Compute the unfilled remainder — subtract
executedQty(the amount already filled) from the originalquantity. - Market-order the remainder — guarantee the full position is entered or exited at current market price.
commitSell uses binance.marketSell in the same position; the structure is identical. The final return value is the average fill price computed across all fills reported by the market order response (with orderPrice as a fallback if the fills array is empty).
Price Offsets
NeithercommitBuy nor commitSell posts a limit order exactly at the current market price. Each applies a small offset to improve fill probability:
| Function | Limit price | Direction | Rationale |
|---|---|---|---|
commitBuy | averagePrice × 1.001 | Slightly above market | A buy above the current ask is likely to match immediately |
commitSell | averagePrice (no offset) | At market | The order is submitted at the raw averagePrice; orderPrice (averagePrice × 0.999) is computed but used only as the getAveragePrice fallback, not as the submitted limit price |
commitBuy’s 0.1 % premium is narrow enough that price impact is negligible on liquid spot pairs, but wide enough to win queue position over resting orders at exactly the mid-price. commitCancel’s exit sell — a separate code path in commit_cancel.function.ts — does apply the × 0.999 offset and posts slightly below market to favour a fast fill.
Partial Fills
When a limit order partially fills before the 100-second timeout, only the remaining quantity is market-ordered:lastStatus from the market order carries its own fills array. getAveragePrice averages the prices across those fills using the orderPrice as a fallback when fills is empty:
commitBuy or commitSell is the average price of the market fills only — not a blended average across both the partial limit fill and the market fill. The caller (the broker adapter engine) uses this price to record the entry or exit cost.
Where This Pattern Applies
The poll-with-timeout + market fallback is used in three places:commitBuy— entry limit buy, market-buy fallback on timeoutcommitSell— sized exit limit sell (for a specifiedamountUSDT), market-sell fallback on timeoutcommitCancel(sell leg) — after the cancel-verify phase, the exit sell uses the same loop and falls back tobinance.marketSellon timeout
onOrderOpenCommit), a structurally identical loop is also used directly, with the added dimension of Rule 1: any timeout on open causes the partial fill to be rolled back with a market sell before the transient throw.