backtest-kit 1.5.2 → 1.5.3
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 +327 -113
- package/build/index.mjs +328 -114
- package/package.json +1 -1
- package/types.d.ts +117 -6
package/types.d.ts
CHANGED
|
@@ -5205,6 +5205,24 @@ declare class BacktestUtils {
|
|
|
5205
5205
|
exchangeName: string;
|
|
5206
5206
|
frameName: string;
|
|
5207
5207
|
}) => () => void;
|
|
5208
|
+
/**
|
|
5209
|
+
* Stops the strategy from generating new signals.
|
|
5210
|
+
*
|
|
5211
|
+
* Sets internal flag to prevent strategy from opening new signals.
|
|
5212
|
+
* Current active signal (if any) will complete normally.
|
|
5213
|
+
* Backtest will stop at the next safe point (idle state or after signal closes).
|
|
5214
|
+
*
|
|
5215
|
+
* @param symbol - Trading pair symbol
|
|
5216
|
+
* @param strategyName - Strategy name to stop
|
|
5217
|
+
* @returns Promise that resolves when stop flag is set
|
|
5218
|
+
*
|
|
5219
|
+
* @example
|
|
5220
|
+
* ```typescript
|
|
5221
|
+
* // Stop strategy after some condition
|
|
5222
|
+
* await Backtest.stop("BTCUSDT", "my-strategy");
|
|
5223
|
+
* ```
|
|
5224
|
+
*/
|
|
5225
|
+
stop: (symbol: string, strategyName: StrategyName) => Promise<void>;
|
|
5208
5226
|
/**
|
|
5209
5227
|
* Gets statistical data from all closed signals for a symbol-strategy pair.
|
|
5210
5228
|
*
|
|
@@ -5340,6 +5358,24 @@ declare class LiveUtils {
|
|
|
5340
5358
|
strategyName: string;
|
|
5341
5359
|
exchangeName: string;
|
|
5342
5360
|
}) => () => void;
|
|
5361
|
+
/**
|
|
5362
|
+
* Stops the strategy from generating new signals.
|
|
5363
|
+
*
|
|
5364
|
+
* Sets internal flag to prevent strategy from opening new signals.
|
|
5365
|
+
* Current active signal (if any) will complete normally.
|
|
5366
|
+
* Live trading will stop at the next safe point (idle/closed state).
|
|
5367
|
+
*
|
|
5368
|
+
* @param symbol - Trading pair symbol
|
|
5369
|
+
* @param strategyName - Strategy name to stop
|
|
5370
|
+
* @returns Promise that resolves when stop flag is set
|
|
5371
|
+
*
|
|
5372
|
+
* @example
|
|
5373
|
+
* ```typescript
|
|
5374
|
+
* // Stop live trading gracefully
|
|
5375
|
+
* await Live.stop("BTCUSDT", "my-strategy");
|
|
5376
|
+
* ```
|
|
5377
|
+
*/
|
|
5378
|
+
stop: (symbol: string, strategyName: StrategyName) => Promise<void>;
|
|
5343
5379
|
/**
|
|
5344
5380
|
* Gets statistical data from all live trading events for a symbol-strategy pair.
|
|
5345
5381
|
*
|
|
@@ -5647,6 +5683,30 @@ declare class WalkerUtils {
|
|
|
5647
5683
|
background: (symbol: string, context: {
|
|
5648
5684
|
walkerName: string;
|
|
5649
5685
|
}) => () => void;
|
|
5686
|
+
/**
|
|
5687
|
+
* Stops all strategies in the walker from generating new signals.
|
|
5688
|
+
*
|
|
5689
|
+
* Iterates through all strategies defined in walker schema and:
|
|
5690
|
+
* 1. Sends stop signal via walkerStopSubject (interrupts current running strategy)
|
|
5691
|
+
* 2. Sets internal stop flag for each strategy (prevents new signals)
|
|
5692
|
+
*
|
|
5693
|
+
* Current active signals (if any) will complete normally.
|
|
5694
|
+
* Walker will stop at the next safe point.
|
|
5695
|
+
*
|
|
5696
|
+
* Supports multiple walkers running on the same symbol simultaneously.
|
|
5697
|
+
* Stop signal is filtered by walkerName to prevent interference.
|
|
5698
|
+
*
|
|
5699
|
+
* @param symbol - Trading pair symbol
|
|
5700
|
+
* @param walkerName - Walker name to stop
|
|
5701
|
+
* @returns Promise that resolves when all stop flags are set
|
|
5702
|
+
*
|
|
5703
|
+
* @example
|
|
5704
|
+
* ```typescript
|
|
5705
|
+
* // Stop walker and all its strategies
|
|
5706
|
+
* await Walker.stop("BTCUSDT", "my-walker");
|
|
5707
|
+
* ```
|
|
5708
|
+
*/
|
|
5709
|
+
stop: (symbol: string, walkerName: WalkerName) => Promise<void>;
|
|
5650
5710
|
/**
|
|
5651
5711
|
* Gets walker results data from all strategy comparisons.
|
|
5652
5712
|
*
|
|
@@ -6222,6 +6282,36 @@ declare class ConstantUtils {
|
|
|
6222
6282
|
*/
|
|
6223
6283
|
declare const Constant: ConstantUtils;
|
|
6224
6284
|
|
|
6285
|
+
/**
|
|
6286
|
+
* Contract for walker stop signal events.
|
|
6287
|
+
*
|
|
6288
|
+
* Emitted when Walker.stop() is called to interrupt a running walker.
|
|
6289
|
+
* Contains metadata about which walker and strategy should be stopped.
|
|
6290
|
+
*
|
|
6291
|
+
* Supports multiple walkers running on the same symbol simultaneously
|
|
6292
|
+
* by including walkerName for filtering.
|
|
6293
|
+
*
|
|
6294
|
+
* @example
|
|
6295
|
+
* ```typescript
|
|
6296
|
+
* import { walkerStopSubject } from "backtest-kit";
|
|
6297
|
+
*
|
|
6298
|
+
* walkerStopSubject
|
|
6299
|
+
* .filter((event) => event.symbol === "BTCUSDT")
|
|
6300
|
+
* .connect((event) => {
|
|
6301
|
+
* console.log("Walker stopped:", event.walkerName);
|
|
6302
|
+
* console.log("Strategy:", event.strategyName);
|
|
6303
|
+
* });
|
|
6304
|
+
* ```
|
|
6305
|
+
*/
|
|
6306
|
+
interface WalkerStopContract {
|
|
6307
|
+
/** symbol - Trading symbol (e.g., "BTCUSDT") */
|
|
6308
|
+
symbol: string;
|
|
6309
|
+
/** strategyName - Name of the strategy to stop */
|
|
6310
|
+
strategyName: StrategyName;
|
|
6311
|
+
/** walkerName - Name of the walker to stop (for filtering) */
|
|
6312
|
+
walkerName: WalkerName;
|
|
6313
|
+
}
|
|
6314
|
+
|
|
6225
6315
|
/**
|
|
6226
6316
|
* Global signal emitter for all trading events (live + backtest).
|
|
6227
6317
|
* Emits all signal events regardless of execution mode.
|
|
@@ -6296,11 +6386,10 @@ declare const walkerCompleteSubject: Subject<IWalkerResults>;
|
|
|
6296
6386
|
/**
|
|
6297
6387
|
* Walker stop emitter for walker cancellation events.
|
|
6298
6388
|
* Emits when a walker comparison is stopped/cancelled.
|
|
6389
|
+
*
|
|
6390
|
+
* Includes walkerName to support multiple walkers running on the same symbol.
|
|
6299
6391
|
*/
|
|
6300
|
-
declare const walkerStopSubject: Subject<
|
|
6301
|
-
symbol: string;
|
|
6302
|
-
strategyName: StrategyName;
|
|
6303
|
-
}>;
|
|
6392
|
+
declare const walkerStopSubject: Subject<WalkerStopContract>;
|
|
6304
6393
|
/**
|
|
6305
6394
|
* Validation emitter for risk validation errors.
|
|
6306
6395
|
* Emits when risk validation functions throw errors during signal checking.
|
|
@@ -6610,6 +6699,17 @@ declare class StrategyConnectionService {
|
|
|
6610
6699
|
* @returns Promise resolving to pending signal or null
|
|
6611
6700
|
*/
|
|
6612
6701
|
getPendingSignal: (symbol: string, strategyName: StrategyName) => Promise<ISignalRow | null>;
|
|
6702
|
+
/**
|
|
6703
|
+
* Retrieves the stopped state of the strategy.
|
|
6704
|
+
*
|
|
6705
|
+
* Delegates to the underlying strategy instance to check if it has been
|
|
6706
|
+
* marked as stopped and should cease operation.
|
|
6707
|
+
*
|
|
6708
|
+
* @param symbol - Trading pair symbol
|
|
6709
|
+
* @param strategyName - Name of the strategy
|
|
6710
|
+
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
6711
|
+
*/
|
|
6712
|
+
getStopped: (symbol: string, strategyName: StrategyName) => Promise<boolean>;
|
|
6613
6713
|
/**
|
|
6614
6714
|
* Executes live trading tick for current strategy.
|
|
6615
6715
|
*
|
|
@@ -6646,7 +6746,7 @@ declare class StrategyConnectionService {
|
|
|
6646
6746
|
stop: (ctx: {
|
|
6647
6747
|
symbol: string;
|
|
6648
6748
|
strategyName: StrategyName;
|
|
6649
|
-
}) => Promise<void>;
|
|
6749
|
+
}, backtest: boolean) => Promise<void>;
|
|
6650
6750
|
/**
|
|
6651
6751
|
* Clears the memoized ClientStrategy instance from cache.
|
|
6652
6752
|
*
|
|
@@ -7079,6 +7179,17 @@ declare class StrategyGlobalService {
|
|
|
7079
7179
|
* @returns Promise resolving to pending signal or null
|
|
7080
7180
|
*/
|
|
7081
7181
|
getPendingSignal: (symbol: string, strategyName: StrategyName) => Promise<ISignalRow | null>;
|
|
7182
|
+
/**
|
|
7183
|
+
* Checks if the strategy has been stopped.
|
|
7184
|
+
*
|
|
7185
|
+
* Validates strategy existence and delegates to connection service
|
|
7186
|
+
* to retrieve the stopped state from the strategy instance.
|
|
7187
|
+
*
|
|
7188
|
+
* @param symbol - Trading pair symbol
|
|
7189
|
+
* @param strategyName - Name of the strategy
|
|
7190
|
+
* @returns Promise resolving to true if strategy is stopped, false otherwise
|
|
7191
|
+
*/
|
|
7192
|
+
getStopped: (symbol: string, strategyName: StrategyName) => Promise<boolean>;
|
|
7082
7193
|
/**
|
|
7083
7194
|
* Checks signal status at a specific timestamp.
|
|
7084
7195
|
*
|
|
@@ -7117,7 +7228,7 @@ declare class StrategyGlobalService {
|
|
|
7117
7228
|
stop: (ctx: {
|
|
7118
7229
|
symbol: string;
|
|
7119
7230
|
strategyName: StrategyName;
|
|
7120
|
-
}) => Promise<void>;
|
|
7231
|
+
}, backtest: boolean) => Promise<void>;
|
|
7121
7232
|
/**
|
|
7122
7233
|
* Clears the memoized ClientStrategy instance from cache.
|
|
7123
7234
|
*
|