Risk, Partial, and Breakeven are the three adapters that carry aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit-redis-postgres-pgpool-docker/llms.txt
Use this file to discover all available pages before exploring further.
when column — a bigint (epoch milliseconds) that records the logical simulation timestamp at the moment of every write. This column is the mechanism by which backtest-kit’s internal look-ahead-bias filter verifies that no read returns a value written in the future relative to the current simulation clock. All three write* methods accept a when: Date argument, and both readPositionData (Risk) and the read*Data methods for Partial and Breakeven also receive when to support time-gated reads.
The
when column uses a shared epochTransformer value transformer. The pg driver returns bigint columns as JavaScript strings; the transformer converts them to plain number values so the adapter layer never needs to parse timestamps manually.Risk Adapter
The Risk adapter snapshots the list of currently active positions managed by a named risk controller. Its context key is(riskName, exchangeName) — intentionally narrower than the signal adapters, because a single risk controller can span multiple trading pairs.
Context Key and Table
| Field | Type | Role |
|---|---|---|
riskName | string | Identifies the risk controller |
exchangeName | string | Exchange identifier |
risk-items — unique index risk_items_uq on (riskName, exchangeName)
Registration
readPositionData receives a _when parameter (prefixed with _ because it is unused on the read path). The when argument is consumed only on the write path to stamp the row. Risk data is always read back as the latest snapshot regardless of simulation time.Table Schema
Column Reference
Auto-generated UUID primary key.
Risk controller name. Part of the unique index.
Exchange identifier. Part of the unique index.
Array of active position objects.
RiskData is the type exported by backtest-kit.Logical simulation timestamp at write time, epoch milliseconds. Read back as
number via epochTransformer.Set by TypeORM on first insert.
Updated by TypeORM on every write.
Partial Adapter
The Partial adapter stores the profit/loss take-partial levels for a specific open signal. Its context key includessignalId, making it the first adapter in this group with a four-field unique index. One row exists per (symbol, strategyName, exchangeName, signalId) combination, and its payload is a PartialData JSONB object.
Context Key and Table
| Field | Type | Role |
|---|---|---|
symbol | string | Trading pair |
strategyName | string | Strategy identifier |
exchangeName | string | Exchange identifier |
signalId | string | Unique signal ID — passed at read and write time |
partial-items — unique index partial_items_uq on (symbol, strategyName, exchangeName, signalId)
Registration
Table Schema
Column Reference
Unique signal identifier. Not stored in the adapter constructor — passed as an argument to
readPartialData and writePartialData at call time. Part of the unique index.Take-partial level configuration for this signal.
PartialData is the type exported by backtest-kit. Returns {} (empty object) when no row exists.Logical simulation timestamp at write time, epoch milliseconds.
Breakeven Adapter
The Breakeven adapter tracks whether the breakeven level has been reached for a specific signal. Like Partial, its context key includessignalId, and it shares an identical table shape — differing only in that its payload type is BreakevenData rather than PartialData.
Context Key and Table
| Field | Type | Role |
|---|---|---|
symbol | string | Trading pair |
strategyName | string | Strategy identifier |
exchangeName | string | Exchange identifier |
signalId | string | Unique signal ID — passed at read and write time |
breakeven-items — unique index breakeven_items_uq on (symbol, strategyName, exchangeName, signalId)
Registration
Table Schema
Look-Ahead Bias: The when Column
All three adapters write the logical simulation clock value into the when column on every upsert. The DbService.upsert() call converts the Date to epoch milliseconds via when.getTime() before passing it to TypeORM, and the epochTransformer converts it back to a number on read: