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.
fetchPnl reconstructs a daily realized PnL history from the recent trade log. It filters to filled orders only, groups them by calendar day, and matches BUY→SELL pairs using a partial-fill-aware algorithm that also handles cross-day trades (a buy on day N matched against a sell on day N+1 or later). For each day that has realized PnL, it fetches a VWAP from Binance’s 1-hour candles to compute the current portfolio value at day-end. Results are returned sorted most-recent-first.
Signature
Parameters
Binance trading pair symbol, e.g.
"SOLUSDT".Number of historical orders to use as the basis for PnL calculation. Defaults to
25. This maps directly to the limit parameter of the underlying fetchOrders call.Returns
An array of daily PnL records sorted most-recent-first. Only days with at least one realized BUY→SELL match are included. Each record conforms to the All numeric fields are returned as strings rounded to the exchange’s
IDailyPnL interface:PRICE_FILTER tickSize or LOT_SIZE stepSize as appropriate.Algorithm
- Filter: only
FILLEDorders from thefetchOrdersresult are considered. - Group by day: orders are grouped into a
Map<dayStamp, { buys, sells }>usinggetMomentStampfromget-moment-stamp. - Cross-day support: for each day, the SELL side includes sells from the current day and all future days in the dataset, so a buy on day N is properly matched against a sell on day N+2.
- Partial fill matching (
processPartialMatching): buys and sells within each processing window are sorted chronologically. Each buy is matched greedily against future sells, consuming as much quantity as available. AusedSellsmap tracks remaining sell quantity across iterations so a single sell is never counted more than once. - Cumulative balance: a separate pass over all filled orders in chronological order accumulates the coin balance day-by-day (
BUYaddsexecutedQty,SELLsubtracts it, floored at zero). - VWAP per day: for each day with PnL,
binance.candles(symbol, "1h", { startTime, endTime })fetches all 1-hour candles for that calendar day. VWAP is computed asΣ(closePrice × volume) / Σ(volume). - Formatting: all numeric values are rounded via
roundTicksto exchange precision before being returned.
Caching
Results are cached for 10 minutes (PNL_TTL = 10 * 60 * 1_000) keyed by symbol-limit inside WalletPrivateService. The cache is shared with fetchOrders and is busted by the same walletPrivateService.clear() call that runs after every commit* operation. To manually refresh without placing an order, call commitReload(symbol).