TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit/llms.txt
Use this file to discover all available pages before exploring further.
Live singleton runs trading strategies against real-time market data. It is the production counterpart of Backtest and exposes an identical API surface—the same run(), background(), getData(), getReport(), dump(), and clear() methods—so strategy code works in both modes without changes. Live mode adds crash-safe persistence: signal state is written atomically to disk on every mutation, and the engine restores open positions automatically on process restart.
Key Differences from Backtest
| Backtest | Live | |
|---|---|---|
| Time source | Frame timestamps | new Date() (real clock) |
| Loop type | Finite (frame start → end) | Infinite while(true) |
| Persistence | Optional | Always enabled (crash-safe) |
frameName required | Yes | No (omit or pass "") |
| Candle source | Historical cache | Exchange API in real time |
run()
break, return, or the stop function to end it. On each iteration, the engine fetches the current VWAP price, evaluates the strategy, and yields results when a position opens or closes. Idle and active ticks are consumed internally.
background()
getData()
LiveStatisticsModel:
| Field | Description |
|---|---|
eventList | All tick events (idle, opened, active, closed). |
totalEvents | Total event count including idle ticks. |
totalClosed | Count of fully closed signals only. |
winRate | Win rate percentage (0–100), null if unsafe. |
avgPnl | Average PNL per closed signal, null if unsafe. |
totalPnl | Cumulative PNL, null if unsafe. |
sharpeRatio | Risk-adjusted return, null if unsafe. |
sortinoRatio | Downside deviation Sharpe variant. |
getReport()
dump()
./dump/live/.
clear()
Context Object
Name of a registered strategy schema.
Name of a registered exchange schema.
Crash Recovery
When a live bot restarts after a crash,ClientStrategy.waitForInit() automatically loads the last persisted signal state from disk. If a position was open when the process died, the engine resumes monitoring it—no manual intervention required. The persistence layer uses atomic writes (writeFileAtomic) to prevent partial or corrupted state files.
Pair
Live with Broker.enable() to connect exchange order execution. When a broker adapter is registered, every position open, close, partial, trailing-stop, and breakeven operation is forwarded to the adapter before the internal state mutates. If the adapter throws (e.g., the exchange rejects the order), the mutation is skipped and the framework retries automatically on the next tick.