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.

WalletPublicService is the recommended entry point for all exchange operations. It wraps the lower-level WalletPrivateService with three key guarantees: per-symbol serialized execution via a queued runner (so concurrent calls on the same symbol are never interleaved), up-front argument validation that throws descriptive errors before anything reaches the exchange, and a structured console.log audit record emitted in a finally block after every commit — whether the operation succeeds or fails.

Accessing the singleton

The wallet export exposes both service layers as a single container object. Always use walletPublicService unless you are debugging the raw exchange adapter directly.
import wallet from "wallet-manager";
// or: import { wallet } from "wallet-manager";

const { walletPublicService } = wallet;
The REPL (started with npm start) injects wallet as a global, so you can call any method directly:
repl => await wallet.walletPublicService.fetchPrice("SOLUSDT")
77.56

Per-symbol execution queue

Internally, WalletPublicService maintains one EventListener instance per symbol, keyed by a memoized runner (getRunner). Each EventListener wraps its execute method with queued from functools-kit, which serializes all calls on that runner. This means two concurrent commitBuy("SOLUSDT", …) calls will run strictly one after the other — the second waits for the first to fully resolve, including its full poll loop and any market-fallback order. Symbols are independent: a commitBuy("SOLUSDT", …) and a commitBuy("BTCUSDT", …) running at the same time do not block each other.

Audit log format

After every commit* call (commitBuy, commitSell, commitTrade, commitCancel), the service emits a structured record via console.log inside the finally block, regardless of whether the operation succeeded or threw:
{
  symbol: string;       // e.g. "SOLUSDT"
  action: "buy" | "sell" | "trade" | "cancel";
  amountUSDT: number;   // 0 for commitCancel
  averagePrice: number; // market price fetched before the operation
  date: Date;           // timestamp of completion
  status: "success" | "failed";
}
After every commit, walletPrivateService.clear() is also called to invalidate the order and PnL caches, ensuring the next fetchOrders or fetchPnl call reflects the latest state.

Methods

commitBuy

Guarded limit BUY at avg×1.001 with poll loop and market fallback. Returns 0 if guards fail.

commitSell

Limit SELL at avg×0.999 with poll loop and market fallback. Returns average fill price.

commitTrade

Buy via commitBuy flow then immediately place an OCO take-profit and stop-loss.

commitCancel

Cancel all open orders, verify clean book, sell entire free coin balance to USDT.

fetchPrice

Current Binance average price for a symbol, formatted to tick size. 30s cache.

fetchBalance

Coin quantity and USDT equivalent, including amounts locked in open orders.

fetchFiat

Total USDT balance (free + locked) from the Binance account.

fetchOrders

Recent FILLED, CANCELED, and NEW orders. 10-minute TTL cache.

fetchPnl

Daily PnL reconstructed from trade history using partial fill matching and VWAP.

commitReload

Clears the WalletPrivateService cache for a symbol, forcing fresh data on the next fetch call.

Full method signatures

class WalletPublicService {
  commitBuy(symbol: string, amountUSDT: number): Promise<number>;
  commitSell(symbol: string, amountUSDT: number): Promise<number>;
  commitTrade(
    symbol: string,
    amountUSDT: number,
    takeProfitPrice: number,
    stopLossPrice: number
  ): Promise<0 | { status: string; content: string }>;
  commitCancel(symbol: string): Promise<number>;
  fetchBalance(symbol: string): Promise<{ usdt: number; quantity: number }>;
  fetchOrders(symbol: string, limit?: number): Promise<IOrderData[]>;
  fetchPrice(symbol: string): Promise<number>;
  fetchFiat(symbol: string): Promise<number>;
  fetchPnl(symbol: string, limit?: number): Promise<IDailyPnL[]>;
  commitReload(symbol: string): Promise<void>;
}

Usage example

import wallet from "wallet-manager";

const { walletPublicService } = wallet;

// Inspect current state
const price   = await walletPublicService.fetchPrice("SOLUSDT");
const fiat    = await walletPublicService.fetchFiat("SOLUSDT");
const balance = await walletPublicService.fetchBalance("SOLUSDT");
console.log({ price, fiat, balance });

// Enter a guarded position
const fillPrice = await walletPublicService.commitBuy("SOLUSDT", 20);
console.log("Filled at", fillPrice); // 0 if guards prevented entry

// Enter with OCO brackets in one call
const result = await walletPublicService.commitTrade("SOLUSDT", 20, 85.0, 74.0);
// => { status: "ok", content: "..." } or 0

// Flatten the entire position
const exitPrice = await walletPublicService.commitCancel("SOLUSDT");
console.log("Exited at", exitPrice);

commitReload

commitReload clears the WalletPrivateService internal cache for a symbol. It calls walletPrivateService.clear(), which invalidates the fetchOrders and fetchPnl TTL caches. After a reload, the next call to fetchOrders or fetchPnl for any symbol will fetch fresh data from the exchange.

Signature

commitReload(symbol: string): Promise<void>

Parameters

symbol
string
required
Binance trading pair symbol, e.g. "SOLUSDT". Used for queue routing — the cache clear applies globally across all symbols, not just the one passed.

Return value

Promise<void> — resolves when the cache has been cleared. Does not interact with the exchange.

Usage example

import wallet from "wallet-manager";

const { walletPublicService } = wallet;

// Force a cache flush before reading fresh order history
await walletPublicService.commitReload("SOLUSDT");
const orders = await walletPublicService.fetchOrders("SOLUSDT");
commitReload is called automatically by all commit* operations (commitBuy, commitSell, commitTrade, commitCancel) in their finally block, so you rarely need to call it manually. Use it when you want to force a cache refresh without placing an order — for example, after an external trade or manual intervention on the exchange.
wallet.walletPrivateService is the raw exchange adapter with no validation or queueing. It is exposed for debugging only. Do not call it directly in production code — concurrent calls on the same symbol can produce interleaved orders.

Build docs developers (and LLMs) love