backtest-kit 2.3.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
@@ -60,6 +60,7 @@
60
60
  "@rollup/plugin-typescript": "11.1.6",
61
61
  "@types/node": "22.9.0",
62
62
  "glob": "11.0.1",
63
+ "plantuml": "0.0.2",
63
64
  "rimraf": "6.0.1",
64
65
  "rollup": "3.29.5",
65
66
  "rollup-plugin-dts": "6.1.1",
@@ -67,13 +68,13 @@
67
68
  "ts-morph": "27.0.2",
68
69
  "tslib": "2.7.0",
69
70
  "typedoc": "0.27.9",
70
- "plantuml": "0.0.2",
71
71
  "worker-testbed": "1.0.12"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "typescript": "^5.0.0"
75
75
  },
76
76
  "dependencies": {
77
+ "ccxt": "^4.5.35",
77
78
  "di-kit": "^1.0.18",
78
79
  "di-scoped": "^1.0.20",
79
80
  "functools-kit": "^1.0.95",
package/types.d.ts CHANGED
@@ -8393,31 +8393,33 @@ declare class PersistCandleUtils {
8393
8393
  usePersistCandleAdapter(Ctor: TPersistBaseCtor<string, CandleData>): void;
8394
8394
  /**
8395
8395
  * Reads cached candles for a specific exchange, symbol, and interval.
8396
- * Returns candles only if cache contains exactly the requested limit.
8396
+ * Returns candles only if cache contains ALL requested candles.
8397
8397
  *
8398
- * Boundary semantics (EXCLUSIVE):
8399
- * - sinceTimestamp: candle.timestamp must be > sinceTimestamp
8400
- * - untilTimestamp: candle.timestamp + stepMs must be < untilTimestamp
8401
- * - Only fully closed candles within the exclusive range are returned
8398
+ * Algorithm (matches ClientExchange.ts logic):
8399
+ * 1. Calculate expected timestamps: sinceTimestamp, sinceTimestamp + stepMs, ..., sinceTimestamp + (limit-1) * stepMs
8400
+ * 2. Try to read each expected candle by timestamp key
8401
+ * 3. If ANY candle is missing, return null (cache miss)
8402
+ * 4. If all candles found, return them in order
8402
8403
  *
8403
8404
  * @param symbol - Trading pair symbol
8404
8405
  * @param interval - Candle interval
8405
8406
  * @param exchangeName - Exchange identifier
8406
8407
  * @param limit - Number of candles requested
8407
- * @param sinceTimestamp - Exclusive start timestamp in milliseconds
8408
- * @param untilTimestamp - Exclusive end timestamp in milliseconds
8408
+ * @param sinceTimestamp - Aligned start timestamp (openTime of first candle)
8409
+ * @param _untilTimestamp - Unused, kept for API compatibility
8409
8410
  * @returns Promise resolving to array of candles or null if cache is incomplete
8410
8411
  */
8411
- readCandlesData: (symbol: string, interval: CandleInterval, exchangeName: ExchangeName, limit: number, sinceTimestamp: number, untilTimestamp: number) => Promise<CandleData[] | null>;
8412
+ readCandlesData: (symbol: string, interval: CandleInterval, exchangeName: ExchangeName, limit: number, sinceTimestamp: number, _untilTimestamp: number) => Promise<CandleData[] | null>;
8412
8413
  /**
8413
8414
  * Writes candles to cache with atomic file writes.
8414
8415
  * Each candle is stored as a separate JSON file named by its timestamp.
8415
8416
  *
8416
- * The candles passed to this function must already be filtered using EXCLUSIVE boundaries:
8417
- * - candle.timestamp > sinceTimestamp
8418
- * - candle.timestamp + stepMs < untilTimestamp
8417
+ * The candles passed to this function should be validated candles from the adapter:
8418
+ * - First candle.timestamp equals aligned sinceTimestamp (openTime)
8419
+ * - Exact number of candles as requested
8420
+ * - All candles are fully closed (timestamp + stepMs < untilTimestamp)
8419
8421
  *
8420
- * @param candles - Array of candle data to cache (already filtered with exclusive boundaries)
8422
+ * @param candles - Array of candle data to cache (validated by the caller)
8421
8423
  * @param symbol - Trading pair symbol
8422
8424
  * @param interval - Candle interval
8423
8425
  * @param exchangeName - Exchange identifier
@@ -15650,6 +15652,13 @@ declare class ClientExchange implements IExchange {
15650
15652
  /**
15651
15653
  * Fetches historical candles backwards from execution context time.
15652
15654
  *
15655
+ * Algorithm:
15656
+ * 1. Align when down to interval boundary (e.g., 00:17 -> 00:15 for 15m)
15657
+ * 2. Calculate since = alignedWhen - limit * step
15658
+ * 3. Fetch candles starting from since
15659
+ * 4. Validate first candle timestamp matches since (adapter must return inclusive data)
15660
+ * 5. Slice to limit
15661
+ *
15653
15662
  * @param symbol - Trading pair symbol
15654
15663
  * @param interval - Candle interval
15655
15664
  * @param limit - Number of candles to fetch
@@ -15660,6 +15669,13 @@ declare class ClientExchange implements IExchange {
15660
15669
  * Fetches future candles forwards from execution context time.
15661
15670
  * Used in backtest mode to get candles for signal duration.
15662
15671
  *
15672
+ * Algorithm:
15673
+ * 1. Align when down to interval boundary (e.g., 00:17 -> 00:15 for 15m)
15674
+ * 2. since = alignedWhen (start from aligned when)
15675
+ * 3. Fetch candles starting from since
15676
+ * 4. Validate first candle timestamp matches since (adapter must return inclusive data)
15677
+ * 5. Slice to limit
15678
+ *
15663
15679
  * @param symbol - Trading pair symbol
15664
15680
  * @param interval - Candle interval
15665
15681
  * @param limit - Number of candles to fetch
@@ -15703,6 +15719,12 @@ declare class ClientExchange implements IExchange {
15703
15719
  /**
15704
15720
  * Fetches raw candles with flexible date/limit parameters.
15705
15721
  *
15722
+ * Algorithm:
15723
+ * 1. Align all timestamps down to interval boundary
15724
+ * 2. Fetch candles starting from aligned since
15725
+ * 3. Validate first candle timestamp matches aligned since (adapter must return inclusive data)
15726
+ * 4. Slice to limit
15727
+ *
15706
15728
  * All modes respect execution context and prevent look-ahead bias.
15707
15729
  *
15708
15730
  * Parameter combinations: