These three adapters manage the runtime lifecycle of a strategy. Recent stores the most recently published signal for a specific trading context — the value a subscriber would see if they queried right now. State provides named data buckets scoped to an individual signal, enabling complex stateful strategies to persist intermediate computations across bars. Session holds a single active session record per unique strategy configuration, persisting across restarts. Both State and Session implement aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit-redis-mongo-docker/llms.txt
Use this file to discover all available pages before exploring further.
dispose() no-op for lifecycle interface compatibility.
Recent Adapter
The Recent adapter has the most complex context key of any adapter: five fields including abacktest: boolean flag. This ensures that a backtest run and a live run for the same symbol and strategy never overwrite each other’s most-recent signal.
Constructor
The trading pair symbol, e.g.
"BTCUSDT".The unique name of the strategy instance.
The exchange identifier, e.g.
"binance".The name of the strategy frame or timeframe variant, e.g.
"4h-frame".true for backtest mode; false for live or paper trading.readRecentData
Fetches the most recently written signal payload for this context. Returnsnull when no record exists.
RecentData — the stored payload, or null if no record exists.
writeRecentData
Upserts the most recent signal payload for this context, storingwhen alongside it.
The signal payload to store. Must be non-null — use the Signal adapter to clear signal state.
The bar time at which this signal was published.
writeRecentData accepts NonNullable<RecentData> — it is not possible to write null
to the Recent adapter. The Recent record persists until overwritten by a newer signal.Redis Cache Key Pattern
State Adapter
The State adapter provides a single named data bucket per(signalId, bucketName) pair. It is used by strategies that need to persist complex intermediate state — such as a running average, a Fibonacci level, or a sequence of bar patterns — scoped to the lifecycle of an individual signal.
Constructor
The unique ID of the signal that owns this state bucket.
A label for this state slot, e.g.
"entry-analysis" or "trailing-data".readStateData
Fetches the state payload for this context. Returnsnull when no state has been written yet.
StateData | null
writeStateData
Upserts the state payload for this context, storingwhen alongside it.
The state payload to persist.
The bar time at which this state was written.
dispose
A no-op lifecycle method required by theIPersistStateInstance interface.
Session Adapter
The Session adapter persists one active session record per unique strategy configuration. Unlike the State adapter (which is scoped to a signal), a session lives as long as the strategy configuration is running. On restart, the strategy reads its session back and resumes from where it left off. The context key is(strategyName, exchangeName, frameName).
Constructor
The name of the strategy configuration, e.g.
"momentum-v2".The exchange on which the strategy is running.
The frame or timeframe variant, e.g.
"1h". Together with strategyName and exchangeName,
this uniquely identifies one running strategy configuration.readSessionData
Fetches the active session payload for this strategy configuration. Returnsnull on first startup before any session has been written.
SessionData | null
writeSessionData
Upserts the session payload for this strategy configuration.The session state to persist.
The bar time at which the session was last updated.
dispose
A no-op lifecycle method required by theIPersistSessionInstance interface.
Collection Summary
| Adapter | Collection | Context Key | dispose() | Null Write |
|---|---|---|---|---|
| Recent | recent-items | (symbol, strategyName, exchangeName, frameName, backtest) | No | Not supported |
| State | state-items | (signalId, bucketName) | Yes (no-op) | Not applicable |
| Session | session-items | (strategyName, exchangeName, frameName) | Yes (no-op) | Not applicable |
State and Session both implement
dispose() as a no-op (void 0). This satisfies the
lifecycle interface contract used by the backtest-kit framework when tearing down adapter
instances at the end of a run.