Skip to main content

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.

commitCancel is the full position exit function. It implements the correct “cancel then sell” sequence that avoids the common broker-adapter mistake of selling while funds are still frozen in pending orders. On spot, every resting order locks its base coin (for a SELL) or USDT (for a BUY) — placing a new sell on top of that lock either fails with an insufficient-balance error or silently trades only the unlocked remainder. commitCancel eliminates this problem by first cancelling everything, verifying the book is clean, and only then selling the full free balance.

Signature

commitCancel(symbol: string): Promise<number>

Parameters

symbol
string
required
Binance trading pair symbol to flatten, e.g. "SOLUSDT". All open orders on this symbol will be cancelled and the entire free coin balance will be sold.

Return value

Promise<number> — average exit price from the sell order’s fills array. Returns 0 if the free coin balance (after subtracting the maker fee and minQty dust) is at or below minQty — nothing to sell.

Execution flow

1

Cancel all open orders

Iterates up to 10 rounds. Each round calls binance.openOrders(symbol) and attempts binance.cancel(symbol, orderId) for every live order, with a 1-second sleep between individual cancels. Individual cancel errors are caught and tolerated — the sweep loop continues to the next order and retries on the next round. The loop exits early once openOrders returns an empty list. Throws only if the final round still has errors.
2

Verify zero open orders

After the cancel sweep, a second loop polls binance.openOrders(symbol) up to 10 times (1-second sleep each). If any order remains after all 10 attempts, throws Error("Order not canceled"). This hard verification prevents the sell step from running while any order might still be locking funds.
3

Sell entire free coin balance

Fetches the full balance map via FETCH_BALANCE_FN. Reads the minQty and maker fee for the symbol. Computes the sellable quantity:
const quantity =
  balance.quantity
  - percentValue(balance.quantity, maker)  // subtract maker fee
  - minQty;                                // subtract minimum lot dust
If quantity <= minQty, returns 0 (dust only — nothing to sell).Otherwise, formats the quantity to LOT_SIZE stepSize and places a LIMIT SELL at averagePrice × 0.999 (formatted to PRICE_FILTER tickSize). Polls up to 10 × 10s. On timeout: cancels the limit and market-sells the remaining unfilled quantity via binance.marketSell().

Audit log

After completion, WalletPublicService emits:
console.log({
  symbol,
  action: "cancel",
  amountUSDT: 0,    // always 0 — the full balance is sold, not a fixed amount
  averagePrice,     // price fetched before enqueuing
  date: new Date(),
  status: "success" | "failed",
});

Usage example

import wallet from "wallet-manager";

const { walletPublicService } = wallet;

// REPL usage:
// repl => await wallet.walletPublicService.commitCancel("SOLUSDT")

const exitPrice = await walletPublicService.commitCancel("SOLUSDT");

if (exitPrice === 0) {
  console.log("Nothing to sell — balance was below minimum lot size");
} else {
  console.log(`Exited SOLUSDT at average price: ${exitPrice}`);
}
commitCancel sells your entire free balance of the coin, not a specific USDT amount. If you hold more coins than the position you want to close, do not use this function — use commitSell with an explicit amountUSDT instead. commitCancel is designed for the case where you want to fully flatten a symbol and return all funds to USDT.

Build docs developers (and LLMs) love