backtest-kit 1.5.2 → 1.5.4
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/README.md +177 -7
- package/build/index.cjs +1155 -268
- package/build/index.mjs +1156 -269
- package/package.json +2 -2
- package/types.d.ts +186 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backtest-kit",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "A TypeScript library for trading system backtest",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Petr Tripolsky",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"di-kit": "^1.0.18",
|
|
76
76
|
"di-scoped": "^1.0.20",
|
|
77
|
-
"functools-kit": "^1.0.
|
|
77
|
+
"functools-kit": "^1.0.94",
|
|
78
78
|
"get-moment-stamp": "^1.1.1",
|
|
79
79
|
"ollama": "^0.6.3"
|
|
80
80
|
}
|
package/types.d.ts
CHANGED
|
@@ -5167,6 +5167,11 @@ declare const PersistPartialAdapter: PersistPartialUtils;
|
|
|
5167
5167
|
* ```
|
|
5168
5168
|
*/
|
|
5169
5169
|
declare class BacktestUtils {
|
|
5170
|
+
/**
|
|
5171
|
+
* Memoized function to get or create BacktestInstance for a symbol-strategy pair.
|
|
5172
|
+
* Each symbol-strategy combination gets its own isolated instance.
|
|
5173
|
+
*/
|
|
5174
|
+
private _getInstance;
|
|
5170
5175
|
/**
|
|
5171
5176
|
* Runs backtest for a symbol with context propagation.
|
|
5172
5177
|
*
|
|
@@ -5205,6 +5210,24 @@ declare class BacktestUtils {
|
|
|
5205
5210
|
exchangeName: string;
|
|
5206
5211
|
frameName: string;
|
|
5207
5212
|
}) => () => void;
|
|
5213
|
+
/**
|
|
5214
|
+
* Stops the strategy from generating new signals.
|
|
5215
|
+
*
|
|
5216
|
+
* Sets internal flag to prevent strategy from opening new signals.
|
|
5217
|
+
* Current active signal (if any) will complete normally.
|
|
5218
|
+
* Backtest will stop at the next safe point (idle state or after signal closes).
|
|
5219
|
+
*
|
|
5220
|
+
* @param symbol - Trading pair symbol
|
|
5221
|
+
* @param strategyName - Strategy name to stop
|
|
5222
|
+
* @returns Promise that resolves when stop flag is set
|
|
5223
|
+
*
|
|
5224
|
+
* @example
|
|
5225
|
+
* ```typescript
|
|
5226
|
+
* // Stop strategy after some condition
|
|
5227
|
+
* await Backtest.stop("BTCUSDT", "my-strategy");
|
|
5228
|
+
* ```
|
|
5229
|
+
*/
|
|
5230
|
+
stop: (symbol: string, strategyName: StrategyName) => Promise<void>;
|
|
5208
5231
|
/**
|
|
5209
5232
|
* Gets statistical data from all closed signals for a symbol-strategy pair.
|
|
5210
5233
|
*
|
|
@@ -5250,6 +5273,24 @@ declare class BacktestUtils {
|
|
|
5250
5273
|
* ```
|
|
5251
5274
|
*/
|
|
5252
5275
|
dump: (symbol: string, strategyName: StrategyName, path?: string) => Promise<void>;
|
|
5276
|
+
/**
|
|
5277
|
+
* Lists all active backtest instances with their current status.
|
|
5278
|
+
*
|
|
5279
|
+
* @returns Promise resolving to array of status objects for all instances
|
|
5280
|
+
*
|
|
5281
|
+
* @example
|
|
5282
|
+
* ```typescript
|
|
5283
|
+
* const statusList = await Backtest.list();
|
|
5284
|
+
* statusList.forEach(status => {
|
|
5285
|
+
* console.log(`${status.symbol} - ${status.strategyName}: ${status.status}`);
|
|
5286
|
+
* });
|
|
5287
|
+
* ```
|
|
5288
|
+
*/
|
|
5289
|
+
list: () => Promise<{
|
|
5290
|
+
symbol: string;
|
|
5291
|
+
strategyName: string;
|
|
5292
|
+
status: "pending" | "fulfilled" | "rejected" | "ready";
|
|
5293
|
+
}[]>;
|
|
5253
5294
|
}
|
|
5254
5295
|
/**
|
|
5255
5296
|
* Singleton instance of BacktestUtils for convenient backtest operations.
|
|
@@ -5301,6 +5342,11 @@ declare const Backtest: BacktestUtils;
|
|
|
5301
5342
|
* ```
|
|
5302
5343
|
*/
|
|
5303
5344
|
declare class LiveUtils {
|
|
5345
|
+
/**
|
|
5346
|
+
* Memoized function to get or create LiveInstance for a symbol-strategy pair.
|
|
5347
|
+
* Each symbol-strategy combination gets its own isolated instance.
|
|
5348
|
+
*/
|
|
5349
|
+
private _getInstance;
|
|
5304
5350
|
/**
|
|
5305
5351
|
* Runs live trading for a symbol with context propagation.
|
|
5306
5352
|
*
|
|
@@ -5340,6 +5386,24 @@ declare class LiveUtils {
|
|
|
5340
5386
|
strategyName: string;
|
|
5341
5387
|
exchangeName: string;
|
|
5342
5388
|
}) => () => void;
|
|
5389
|
+
/**
|
|
5390
|
+
* Stops the strategy from generating new signals.
|
|
5391
|
+
*
|
|
5392
|
+
* Sets internal flag to prevent strategy from opening new signals.
|
|
5393
|
+
* Current active signal (if any) will complete normally.
|
|
5394
|
+
* Live trading will stop at the next safe point (idle/closed state).
|
|
5395
|
+
*
|
|
5396
|
+
* @param symbol - Trading pair symbol
|
|
5397
|
+
* @param strategyName - Strategy name to stop
|
|
5398
|
+
* @returns Promise that resolves when stop flag is set
|
|
5399
|
+
*
|
|
5400
|
+
* @example
|
|
5401
|
+
* ```typescript
|
|
5402
|
+
* // Stop live trading gracefully
|
|
5403
|
+
* await Live.stop("BTCUSDT", "my-strategy");
|
|
5404
|
+
* ```
|
|
5405
|
+
*/
|
|
5406
|
+
stop: (symbol: string, strategyName: StrategyName) => Promise<void>;
|
|
5343
5407
|
/**
|
|
5344
5408
|
* Gets statistical data from all live trading events for a symbol-strategy pair.
|
|
5345
5409
|
*
|
|
@@ -5385,6 +5449,24 @@ declare class LiveUtils {
|
|
|
5385
5449
|
* ```
|
|
5386
5450
|
*/
|
|
5387
5451
|
dump: (symbol: string, strategyName: StrategyName, path?: string) => Promise<void>;
|
|
5452
|
+
/**
|
|
5453
|
+
* Lists all active live trading instances with their current status.
|
|
5454
|
+
*
|
|
5455
|
+
* @returns Promise resolving to array of status objects for all instances
|
|
5456
|
+
*
|
|
5457
|
+
* @example
|
|
5458
|
+
* ```typescript
|
|
5459
|
+
* const statusList = await Live.list();
|
|
5460
|
+
* statusList.forEach(status => {
|
|
5461
|
+
* console.log(`${status.symbol} - ${status.strategyName}: ${status.status}`);
|
|
5462
|
+
* });
|
|
5463
|
+
* ```
|
|
5464
|
+
*/
|
|
5465
|
+
list: () => Promise<{
|
|
5466
|
+
symbol: string;
|
|
5467
|
+
strategyName: string;
|
|
5468
|
+
status: "pending" | "fulfilled" | "rejected" | "ready";
|
|
5469
|
+
}[]>;
|
|
5388
5470
|
}
|
|
5389
5471
|
/**
|
|
5390
5472
|
* Singleton instance of LiveUtils for convenient live trading operations.
|
|
@@ -5615,6 +5697,11 @@ declare class Performance {
|
|
|
5615
5697
|
* ```
|
|
5616
5698
|
*/
|
|
5617
5699
|
declare class WalkerUtils {
|
|
5700
|
+
/**
|
|
5701
|
+
* Memoized function to get or create WalkerInstance for a symbol-walker pair.
|
|
5702
|
+
* Each symbol-walker combination gets its own isolated instance.
|
|
5703
|
+
*/
|
|
5704
|
+
private _getInstance;
|
|
5618
5705
|
/**
|
|
5619
5706
|
* Runs walker comparison for a symbol with context propagation.
|
|
5620
5707
|
*
|
|
@@ -5647,6 +5734,30 @@ declare class WalkerUtils {
|
|
|
5647
5734
|
background: (symbol: string, context: {
|
|
5648
5735
|
walkerName: string;
|
|
5649
5736
|
}) => () => void;
|
|
5737
|
+
/**
|
|
5738
|
+
* Stops all strategies in the walker from generating new signals.
|
|
5739
|
+
*
|
|
5740
|
+
* Iterates through all strategies defined in walker schema and:
|
|
5741
|
+
* 1. Sends stop signal via walkerStopSubject (interrupts current running strategy)
|
|
5742
|
+
* 2. Sets internal stop flag for each strategy (prevents new signals)
|
|
5743
|
+
*
|
|
5744
|
+
* Current active signals (if any) will complete normally.
|
|
5745
|
+
* Walker will stop at the next safe point.
|
|
5746
|
+
*
|
|
5747
|
+
* Supports multiple walkers running on the same symbol simultaneously.
|
|
5748
|
+
* Stop signal is filtered by walkerName to prevent interference.
|
|
5749
|
+
*
|
|
5750
|
+
* @param symbol - Trading pair symbol
|
|
5751
|
+
* @param walkerName - Walker name to stop
|
|
5752
|
+
* @returns Promise that resolves when all stop flags are set
|
|
5753
|
+
*
|
|
5754
|
+
* @example
|
|
5755
|
+
* ```typescript
|
|
5756
|
+
* // Stop walker and all its strategies
|
|
5757
|
+
* await Walker.stop("BTCUSDT", "my-walker");
|
|
5758
|
+
* ```
|
|
5759
|
+
*/
|
|
5760
|
+
stop: (symbol: string, walkerName: WalkerName) => Promise<void>;
|
|
5650
5761
|
/**
|
|
5651
5762
|
* Gets walker results data from all strategy comparisons.
|
|
5652
5763
|
*
|
|
@@ -5692,6 +5803,24 @@ declare class WalkerUtils {
|
|
|
5692
5803
|
* ```
|
|
5693
5804
|
*/
|
|
5694
5805
|
dump: (symbol: string, walkerName: WalkerName, path?: string) => Promise<void>;
|
|
5806
|
+
/**
|
|
5807
|
+
* Lists all active walker instances with their current status.
|
|
5808
|
+
*
|
|
5809
|
+
* @returns Promise resolving to array of status objects for all instances
|
|
5810
|
+
*
|
|
5811
|
+
* @example
|
|
5812
|
+
* ```typescript
|
|
5813
|
+
* const statusList = await Walker.list();
|
|
5814
|
+
* statusList.forEach(status => {
|
|
5815
|
+
* console.log(`${status.symbol} - ${status.walkerName}: ${status.status}`);
|
|
5816
|
+
* });
|
|
5817
|
+
* ```
|
|
5818
|
+
*/
|
|
5819
|
+
list: () => Promise<{
|
|
5820
|
+
symbol: string;
|
|
5821
|
+
walkerName: string;
|
|
5822
|
+
status: "pending" | "fulfilled" | "rejected" | "ready";
|
|
5823
|
+
}[]>;
|
|
5695
5824
|
}
|
|
5696
5825
|
/**
|
|
5697
5826
|
* Singleton instance of WalkerUtils for convenient walker operations.
|
|
@@ -6222,6 +6351,36 @@ declare class ConstantUtils {
|
|
|
6222
6351
|
*/
|
|
6223
6352
|
declare const Constant: ConstantUtils;
|
|
6224
6353
|
|
|
6354
|
+
/**
|
|
6355
|
+
* Contract for walker stop signal events.
|
|
6356
|
+
*
|
|
6357
|
+
* Emitted when Walker.stop() is called to interrupt a running walker.
|
|
6358
|
+
* Contains metadata about which walker and strategy should be stopped.
|
|
6359
|
+
*
|
|
6360
|
+
* Supports multiple walkers running on the same symbol simultaneously
|
|
6361
|
+
* by including walkerName for filtering.
|
|
6362
|
+
*
|
|
6363
|
+
* @example
|
|
6364
|
+
* ```typescript
|
|
6365
|
+
* import { walkerStopSubject } from "backtest-kit";
|
|
6366
|
+
*
|
|
6367
|
+
* walkerStopSubject
|
|
6368
|
+
* .filter((event) => event.symbol === "BTCUSDT")
|
|
6369
|
+
* .connect((event) => {
|
|
6370
|
+
* console.log("Walker stopped:", event.walkerName);
|
|
6371
|
+
* console.log("Strategy:", event.strategyName);
|
|
6372
|
+
* });
|
|
6373
|
+
* ```
|
|
6374
|
+
*/
|
|
6375
|
+
interface WalkerStopContract {
|
|
6376
|
+
/** symbol - Trading symbol (e.g., "BTCUSDT") */
|
|
6377
|
+
symbol: string;
|
|
6378
|
+
/** strategyName - Name of the strategy to stop */
|
|
6379
|
+
strategyName: StrategyName;
|
|
6380
|
+
/** walkerName - Name of the walker to stop (for filtering) */
|
|
6381
|
+
walkerName: WalkerName;
|
|
6382
|
+
}
|
|
6383
|
+
|
|
6225
6384
|
/**
|
|
6226
6385
|
* Global signal emitter for all trading events (live + backtest).
|
|
6227
6386
|
* Emits all signal events regardless of execution mode.
|
|
@@ -6296,11 +6455,10 @@ declare const walkerCompleteSubject: Subject<IWalkerResults>;
|
|
|
6296
6455
|
/**
|
|
6297
6456
|
* Walker stop emitter for walker cancellation events.
|
|
6298
6457
|
* Emits when a walker comparison is stopped/cancelled.
|
|
6458
|
+
*
|
|
6459
|
+
* Includes walkerName to support multiple walkers running on the same symbol.
|
|
6299
6460
|
*/
|
|
6300
|
-
declare const walkerStopSubject: Subject<
|
|
6301
|
-
symbol: string;
|
|
6302
|
-
strategyName: StrategyName;
|
|
6303
|
-
}>;
|
|
6461
|
+
declare const walkerStopSubject: Subject<WalkerStopContract>;
|
|
6304
6462
|
/**
|
|
6305
6463
|
* Validation emitter for risk validation errors.
|
|
6306
6464
|
* Emits when risk validation functions throw errors during signal checking.
|
|
@@ -6610,6 +6768,17 @@ declare class StrategyConnectionService {
|
|
|
6610
6768
|
* @returns Promise resolving to pending signal or null
|
|
6611
6769
|
*/
|
|
6612
6770
|
getPendingSignal: (symbol: string, strategyName: StrategyName) => Promise<ISignalRow | null>;
|
|
6771
|
+
/**
|
|
6772
|
+
* Retrieves the stopped state of the strategy.
|
|
6773
|
+
*
|
|
6774
|
+
* Delegates to the underlying strategy instance to check if it has been
|
|
6775
|
+
* marked as stopped and should cease operation.
|
|
6776
|
+
*
|
|
6777
|
+
* @param symbol - Trading pair symbol
|
|
6778
|
+
* @param strategyName - Name of the strategy
|
|
6779
|
+
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
6780
|
+
*/
|
|
6781
|
+
getStopped: (symbol: string, strategyName: StrategyName) => Promise<boolean>;
|
|
6613
6782
|
/**
|
|
6614
6783
|
* Executes live trading tick for current strategy.
|
|
6615
6784
|
*
|
|
@@ -6646,7 +6815,7 @@ declare class StrategyConnectionService {
|
|
|
6646
6815
|
stop: (ctx: {
|
|
6647
6816
|
symbol: string;
|
|
6648
6817
|
strategyName: StrategyName;
|
|
6649
|
-
}) => Promise<void>;
|
|
6818
|
+
}, backtest: boolean) => Promise<void>;
|
|
6650
6819
|
/**
|
|
6651
6820
|
* Clears the memoized ClientStrategy instance from cache.
|
|
6652
6821
|
*
|
|
@@ -7079,6 +7248,17 @@ declare class StrategyGlobalService {
|
|
|
7079
7248
|
* @returns Promise resolving to pending signal or null
|
|
7080
7249
|
*/
|
|
7081
7250
|
getPendingSignal: (symbol: string, strategyName: StrategyName) => Promise<ISignalRow | null>;
|
|
7251
|
+
/**
|
|
7252
|
+
* Checks if the strategy has been stopped.
|
|
7253
|
+
*
|
|
7254
|
+
* Validates strategy existence and delegates to connection service
|
|
7255
|
+
* to retrieve the stopped state from the strategy instance.
|
|
7256
|
+
*
|
|
7257
|
+
* @param symbol - Trading pair symbol
|
|
7258
|
+
* @param strategyName - Name of the strategy
|
|
7259
|
+
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
7260
|
+
*/
|
|
7261
|
+
getStopped: (symbol: string, strategyName: StrategyName) => Promise<boolean>;
|
|
7082
7262
|
/**
|
|
7083
7263
|
* Checks signal status at a specific timestamp.
|
|
7084
7264
|
*
|
|
@@ -7117,7 +7297,7 @@ declare class StrategyGlobalService {
|
|
|
7117
7297
|
stop: (ctx: {
|
|
7118
7298
|
symbol: string;
|
|
7119
7299
|
strategyName: StrategyName;
|
|
7120
|
-
}) => Promise<void>;
|
|
7300
|
+
}, backtest: boolean) => Promise<void>;
|
|
7121
7301
|
/**
|
|
7122
7302
|
* Clears the memoized ClientStrategy instance from cache.
|
|
7123
7303
|
*
|