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.
Overview
Thecommit_* and fetch_* functions are the actual order-management and data-retrieval primitives that WalletPrivateService delegates to. Unlike the higher-level WalletPublicService (which adds per-symbol queuing, argument validation, and structured audit logging), these functions accept a Binance instance directly as their second argument — making them usable in any broker adapter without the full DI stack.
Every
commit_* call places real orders on Binance spot. There is no
dry-run mode. Exchange info (LOT_SIZE, PRICE_FILTER) is memoized per symbol
across all calls in a process lifetime.commit_buy
COMMIT_BUY_FN
0 without trading when pre-conditions fail, otherwise returns the average fill price.
Guards (returns 0 immediately if either condition is true):
- The symbol already has open orders (
binance.openOrders(symbol).length > 0) - Free USDT balance is below
amountUSDT
- Formats quantity via
LOT_SIZEstepSize and price viaPRICE_FILTERtickSize usingroundTicks. - Places a
LIMIT BUYataveragePrice × 1.001(slightly above market to maximize fill speed). - If the order fills immediately → returns the average fill price from the fills array.
- Otherwise polls
binance.orderStatus10 × 10s (up to ~100 seconds). - On timeout: cancels the limit order, then
marketBuys the unfilled remainder (quantity − executedQty). - Returns the average fill price across all fills, falling back to the formatted order price if fills are absent.
Trading pair symbol, e.g.
"SOLUSDT".The USDT amount to spend. Converted to coin quantity via
usdToCoins(amountUSDT, averagePrice).Reference price used to compute the limit price (
× 1.001) and to convert USDT to coin quantity.A configured
node-binance-api instance with API key and secret.Promise<number> — average fill price, or 0 if guards fired.
Example — broker adapter using COMMIT_BUY_FN directly:
commit_sell
COMMIT_SELL_FN
amountUSDT worth of the coin. Unlike COMMIT_BUY_FN, this function has no pre-condition guards — it always attempts to place the order.
Order flow:
- Formats quantity via
LOT_SIZEstepSize and price viaPRICE_FILTERtickSize. - Places a
LIMIT SELLataveragePrice × 0.999(slightly below market to improve fill speed). - If the order fills immediately → returns the average fill price.
- Otherwise polls
binance.orderStatus10 × 10s. - On timeout: cancels the limit order, then
marketSells the unfilled remainder (quantity − executedQty). - Returns the average fill price.
Trading pair symbol, e.g.
"SOLUSDT".The USDT-denominated amount of coin to sell. Converted to coin quantity via
usdToCoins(amountUSDT, averagePrice).Reference price used to compute the limit price (
× 0.999) and to convert USDT to coin quantity.A configured
node-binance-api instance.Promise<number> — average fill price.
Example:
commit_cancel
COMMIT_CANCEL_FN
0 if remaining balance is below minQty (dust), otherwise returns the average exit price.
This is the canonical “cancel-first, sell-second” sequence. Attempting to
sell while funds are still frozen in a pending order will either fail with an
insufficient-balance error or silently trade only the unlocked remainder —
leaving the other orders alive on the book.
COMMIT_CANCEL_FN prevents this
by verifying zero open orders before touching the balance.- Fetches all open orders for the symbol.
- Iterates each order, calling
binance.cancelwith a 1s sleep between each. - Individual cancel errors are tolerated; the round is retried.
- Exits the sweep early when
openOrdersreturns an empty array. - Throws if the final round still has errors.
- Polls
binance.openOrders(symbol)every 1s. - Throws
Error("Order not canceled")if any orders remain after 10 checks.
- Calls
FETCH_BALANCE_FNto get the free coin balance. - Deducts maker commission:
quantity − percentValue(quantity, maker) − minQty. - If the resulting quantity ≤
minQty→ returns0(dust, nothing to sell). - Places a
LIMIT SELLataveragePrice × 0.999, with the same 10 × 10s poll loop and cancel +marketSellfallback on timeout.
Trading pair symbol, e.g.
"SOLUSDT".Reference price used to compute the limit sell price (
× 0.999).A configured
node-binance-api instance.Promise<number> — average exit price, or 0 if balance is dust.
Example:
commit_trade
COMMIT_TRADE_FN
COMMIT_BUY_FN, measures the quantity delta (balance after minus balance before), then places an OCO sell order with a take-profit limit and a stop-loss limit. Returns 0 if guards fired, otherwise a report object.
Guards (returns 0 immediately if either condition is true):
- The symbol already has open orders.
- Free USDT balance is below
amountUSDT.
-
Fetches balance before buy (
balanceBefore). -
Calls
COMMIT_BUY_FNto enter the position. -
Fetches balance after buy (
balanceAfter). -
Computes
orderQuantity = (balanceAfter.quantity − balanceBefore.quantity) − percentValue(orderQuantity, maker) − minQty. -
Throws if
orderQuantityis non-finite, NaN, or ≤ 0. -
Waits 1s, then places an OCO SELL via
binance.ocoOrder:Both legs useLeg Type Price field Below (stop-loss) STOP_LOSS_LIMITstopLossPrice(trigger) /stopLossPrice × 0.999(limit)Above (take-profit) TAKE_PROFIT_LIMITtakeProfitPrice(trigger) /takeProfitPrice × 1.001(limit)GTCtime-in-force. -
Verifies the OCO was accepted by polling
openOrders10 × 1s. ThrowsError("Order not created")if no open orders appear. -
Returns a human-readable report:
Trading pair symbol, e.g.
"SOLUSDT".USDT amount to spend on the entry buy.
Reference price passed through to
COMMIT_BUY_FN.Price at which the take-profit limit leg fires.
Price at which the stop-loss limit leg fires.
A configured
node-binance-api instance.Promise<0 | { status: string; content: string }> — 0 on guard failure, otherwise a report object with status: "ok" and a content summary string.
Example:
fetch_balance
FETCH_BALANCE_FN
SYMBOL_LIST. Each entry reflects both free and on-order (locked in open orders) quantities, converted to USDT at the current market price.
Hardcoded coin list (derived from SYMBOL_LIST):
"USDT" (e.g. "SOLUSDT" → "SOL"). The function sums registry[coinName].available + registry[coinName].onOrder from binance.balance(), then multiplies by the current price from binance.prices().
A configured
node-binance-api instance.Promise<Record<string, { usdt: number; quantity: number }>> — keyed by coin name (e.g. "SOL", "BTC").
Example:
fetch_price
FETCH_PRICE_FN
PRICE_FILTER tickSize precision.
Internally calls binance.avgPrice(symbol), which returns Binance’s built-in 5-minute weighted average price. The raw float is then passed through formatPrice → roundTicks to match the symbol’s tick precision before being returned as a number.
Trading pair symbol, e.g.
"SOLUSDT".A configured
node-binance-api instance.Promise<number> — average price rounded to the symbol’s tick precision.
Example:
fetch_fiat
FETCH_FIAT_FN
binance.account() and locates the USDT entry in account.balances. Returns parseFloat(free) + parseFloat(locked). Returns 0 if no USDT balance entry is found.
A configured
node-binance-api instance.Promise<number> — total USDT (free + locked), or 0 if the account holds no USDT.
Example:
fetch_orders
FETCH_ORDERS_FN
limit historical entries.
IOrderData shape:
- Historical orders are iterated via
binance.trades(symbol)usingiterateDocuments/resolveDocumentsfromfunctools-kitto handle pagination. Results are deduplicated byorderId. - Each unique trade
orderIdis enriched with full order details viabinance.orderStatus, using anexecpool-throttled concurrency pool with a 100ms sleep per request. - Open orders are fetched via
binance.openOrders(symbol). - The combined list is returned with pending orders at the top, followed by historical orders sorted newest-first.
Trading pair symbol, e.g.
"SOLUSDT".Maximum number of historical (non-pending) orders to return.
A configured
node-binance-api instance.Promise<IOrderData[]> — open orders first (status "NEW"), then historical orders sorted newest-first.
Example:
fetch_pnl
FETCH_PNL_FN
IDailyPnL shape:
- Filters
orderstostatus === "FILLED"only. - Groups filled orders into
dayGroupskeyed by a day stamp (getMomentStamp). Each group hasbuys[]andsells[]arrays ofProcessedOrder. - Tracks a running
cumulativeBalance(quantity held) across all orders chronologically to populatebalanceByDay. - For each day’s buys, runs
processPartialMatchingagainst the current day’s sells plus all future days’ sells (supporting cross-day trades). Uses ausedSellsmap to track remaining quantity across partial fills:pnl = (sellPrice − buyPrice) × tradeQtyaccumulated per sell-day.totalCostByDayandtotalQtyByDayaccumulate the buy-side cost forwalletCostcomputation.
- For each day with non-zero PnL, calls
getAvgPriceForDaywhich fetches1hcandles viabinance.candlesand computes VWAP:Σ(close × volume) / Σ(volume). - All prices and quantities are formatted to exchange precision before inclusion in the result.
FETCH_PNL_FN accepts a pre-fetched orders array (the output of
FETCH_ORDERS_FN) rather than fetching orders itself. Fetch orders once and
pass the result here to avoid redundant API calls.Pre-fetched orders array, typically from
FETCH_ORDERS_FN. Only FILLED orders are processed.Trading pair symbol used to fetch 1h VWAP candles and to format prices/quantities.
A configured
node-binance-api instance.Promise<IDailyPnL[]> — one entry per day that has realized PnL, sorted newest-first.
Example: