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.
WalletPublicService is the recommended entry point for all wallet operations. It wraps the lower-level WalletPrivateService with three layers of safety that the raw service deliberately omits: argument validation that throws descriptive errors before any network call is made, a per-symbol serialized execution queue that prevents concurrent orders on the same pair from racing each other, and a structured console.log audit record emitted after every commit* operation regardless of success or failure.
You should reach for WalletPublicService in all normal usage. WalletPrivateService exists as a debugging surface and should not be called directly in production code.
Accessing the service
wallet-manager is a private package and is not published to npm. When you start the REPL with npm start, a wallet global is injected into the session automatically. In scripts or other modules, import from the local build output:
Key behaviors
Per-symbol execution queue
Every method call is routed through an internalEventListener instance that is memoized per symbol using functools-kit’s queued() wrapper. All operations on the same symbol are serialized — a second commitBuy("SOLUSDT", …) called while the first is still polling Binance will wait in the queue rather than running concurrently. Operations on different symbols run independently.
Input validation
Before delegating toWalletPrivateService, WalletPublicService validates caller-supplied arguments and throws descriptive Error instances:
amountUSDTmust be a finite number (typeof amountUSDT !== "number" || isNaN(amountUSDT)) and must not be negative.- For
commitTrade, both caller-supplied price arguments (takeProfitPriceandstopLossPrice) are checked for finiteness. After the current market price is fetched internally,takeProfitPricemust be strictly above it,stopLossPricemust be strictly below it, andstopLossPricemust be less thantakeProfitPrice.
Structured audit log on every commit
After everycommit* call — in the finally block, so it fires on both success and failure — the service emits a structured log entry:
TTL cache invalidation
WalletPrivateService caches fetchOrders and fetchPnl for 10 minutes. After every commit* call, WalletPublicService calls walletPrivateService.clear() to bust both caches so the next read reflects the new state of the account.
Method summary
| Method | Signature | Returns |
|---|---|---|
commitBuy | (symbol, amountUSDT) | Promise<number> |
commitSell | (symbol, amountUSDT) | Promise<number> |
commitTrade | (symbol, amountUSDT, takeProfitPrice, stopLossPrice) | Promise<0 | { status: string, content: string }> |
commitCancel | (symbol) | Promise<number> |
commitReload | (symbol) | Promise<void> |
fetchPrice | (symbol) | Promise<number> |
fetchBalance | (symbol) | Promise<{ usdt: number, quantity: number }> |
fetchFiat | (symbol) | Promise<number> |
fetchOrders | (symbol, limit?) | Promise<IOrderData[]> |
fetchPnl | (symbol, limit?) | Promise<IDailyPnL[]> |
Type definitions
IOrderData
Returned byfetchOrders. Each entry represents a single order from Binance trade history or the open order book.
IDailyPnL
Returned byfetchPnl. Each entry aggregates realized PnL and balance state for one calendar day.
Method pages
commitBuy
Guarded limit buy with market fallback on timeout
commitSell
Limit sell with poll loop and market fallback
commitTrade
Buy with OCO take-profit and stop-loss brackets
commitCancel
Flatten symbol and exit entire balance to USDT
fetchPrice
Current average market price for a symbol
fetchBalance
Coin balance including locked amounts
fetchFiat
Total USDT balance (free and locked)
fetchOrders
Recent order history for a symbol
fetchPnl
Daily PnL estimate from trade history
commitReload
Flush per-symbol cache without placing an order