Position management in backtest-kit is split across three adapters, each capturing a different dimension of an open trade. The Risk adapter tracks the full set of active positions for an exchange-level risk controller. The Partial adapter records per-signal profit-taking levels. The Breakeven adapter records whether a signal has moved its stop to breakeven. All three accept 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.
when: Date parameter on writes, which is stored alongside the payload to support look-ahead bias detection during backtesting.
The when Parameter
Every write method in these three adapters accepts a when: Date argument. This timestamp is stored in MongoDB alongside the payload and represents the bar time at which the write occurred. During backtesting, the framework uses this value to verify that a read at time T never retrieves data written at a time T' > T, preventing look-ahead bias.
Risk Adapter
The Risk adapter operates at the exchange level rather than the symbol level. A single(riskName, exchangeName) context tracks all positions managed by a named risk controller on a given exchange.
Constructor
The name of the risk controller, e.g.
"default-risk".The exchange identifier, e.g.
"binance".readPositionData
Reads the stored position array for this risk context. The_when parameter is accepted for interface compatibility but is not used during reads.
The current bar time. Accepted for interface compatibility; not used in the read query.
RiskData — an array of position objects, or an empty array [] when no data exists.
writePositionData
Upserts the full position array for this context, storingwhen alongside the payload.
The complete array of current positions to persist.
The bar time at which this write is occurring.
Partial Adapter
The Partial adapter records partial take-profit state per individual signal. Each signal is identified by asignalId, making the context key a four-tuple. The payload type PartialData is a record of level identifiers to fill states.
Constructor
The trading pair symbol.
The strategy that owns the signal.
The exchange on which the signal is active.
readPartialData
Fetches the partial fill state for a specific signal ID. Returns an empty object{} when no record exists.
The unique ID of the signal whose partial state is being read.
Accepted for interface compatibility; not used in the read query.
PartialData — the stored partial fill record, or {} if absent.
writePartialData
Upserts the partial fill record for a specific signal.The partial fill state to store.
The unique ID of the signal.
The bar time at which this write is occurring.
Breakeven Adapter
The Breakeven adapter records whether a signal has had its stop moved to breakeven. It shares the same constructor shape as Partial and uses the same four-part context key.Constructor
The trading pair symbol.
The strategy that owns the signal.
The exchange on which the signal is active.
readBreakevenData
Fetches the breakeven state for a specific signal. Returns an empty object{} when no record exists.
The unique ID of the signal whose breakeven state is being read.
Accepted for interface compatibility; not used in the read query.
BreakevenData — the stored breakeven record, or {} if absent.
writeBreakevenData
Upserts the breakeven state for a specific signal.The breakeven state to store.
The unique ID of the signal.
The bar time at which this write is occurring.
Collection Summary
| Adapter | Collection | Context Key | Empty Default |
|---|---|---|---|
| Risk | risk-items | (riskName, exchangeName) | [] |
| Partial | partial-items | (symbol, strategyName, exchangeName, signalId) | {} |
| Breakeven | breakeven-items | (symbol, strategyName, exchangeName, signalId) | {} |
Risk uses a two-part context key (
riskName, exchangeName) — it operates at the
exchange level, not the symbol level. Partial and Breakeven both extend to a four-part
key by adding signalId, scoping each record to a single open trade.