Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tripolskypetr/wallet-manager/llms.txt
Use this file to discover all available pages before exploring further.
commitBuy is the primary entry function for opening a long position on Binance spot. Before placing any order it checks two guards — open orders on the symbol and available USDT balance — and returns 0 immediately if either guard fails, leaving the exchange untouched. When the guards pass, it places a limit BUY order priced slightly above the current average to improve fill probability, then waits up to 100 seconds for the fill. If the order has not filled by then, it cancels the resting limit order and market-buys whatever quantity is still unfilled, guaranteeing the entry is completed rather than left as a resting order on the book.
Signature
Parameters
Binance trading pair symbol, e.g.
"SOLUSDT". Must be a valid spot symbol listed on Binance.Amount in USDT to spend on the buy. Validated in
WalletPublicService — must be a finite number and must be ≥ 0. Throws if typeof amountUSDT !== "number", if the value is NaN, or if it is negative.Return value
Promise<number> — the average fill price computed from the order’s fills array (arithmetic mean over fill prices). Returns 0 if either guard prevented the trade.
Guards
commitBuy checks two pre-conditions before placing any order. If either fails, the function returns 0 without touching the exchange:
- Open orders guard — calls
binance.openOrders(symbol). If the symbol already has one or more live orders, returns0. This prevents stacking a new buy on top of a locked position. - Balance guard — reads the free USDT balance from
binance.account(). IffreeUSDT < amountUSDT, returns0.
Order logic
- Limit price —
averagePrice × 1.001(0.1% above the 5-minute weighted average), formatted to the symbol’sPRICE_FILTERtickSize. - Quantity —
amountUSDT / averagePriceconverted to coins viausdToCoins(), then formatted to theLOT_SIZEstepSize. - A
LIMIT BUYorder is placed viabinance.order("LIMIT", "BUY", symbol, quantity, price).
Poll loop
If the order is not instantlyFILLED, commitBuy enters a poll loop:
- 10 iterations × 10-second sleep = up to 100 seconds waiting for the fill.
- Each iteration calls
binance.orderStatus(symbol, orderId)and breaks as soon asstatus === "FILLED".
Timeout fallback
If all 10 poll iterations complete without a fill:- The resting limit order is cancelled via
binance.cancel(symbol, orderId). - The unfilled remainder (
quantity - lastStatus.executedQty) is market-bought viabinance.marketBuy(symbol, remainderQty). - The average price from the market order’s
fillsarray is returned.
Validation in WalletPublicService
Before the order flow runs,WalletPublicService.commitBuy validates amountUSDT:
averagePrice is also fetched at this point (before enqueuing) so the queued runner receives a consistent snapshot price, not a price that could drift while waiting in the queue.
Audit log
After the operation completes (success or failure),WalletPublicService emits:
Usage example
The
averagePrice passed to the underlying COMMIT_BUY_FN is the 5-minute Binance weighted average price fetched by WalletPublicService before the call is enqueued. If the symbol is busy and the call waits in the queue for a while, the price used for the limit order will be the price at enqueue time, not at execution time.