backtest-kit 1.5.1 → 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 +443 -152
- package/build/index.mjs +444 -153
- package/package.json +1 -1
- package/types.d.ts +123 -6
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ declare const GLOBAL_CONFIG: {
|
|
|
19
19
|
* Default: 0.3% (covers 2×0.1% fees + minimum profit margin)
|
|
20
20
|
*/
|
|
21
21
|
CC_MIN_TAKEPROFIT_DISTANCE_PERCENT: number;
|
|
22
|
+
/**
|
|
23
|
+
* Minimum StopLoss distance from priceOpen (percentage)
|
|
24
|
+
* Prevents signals from being immediately stopped out due to price volatility
|
|
25
|
+
* Default: 0.5% (buffer to avoid instant stop loss on normal market fluctuations)
|
|
26
|
+
*/
|
|
27
|
+
CC_MIN_STOPLOSS_DISTANCE_PERCENT: number;
|
|
22
28
|
/**
|
|
23
29
|
* Maximum StopLoss distance from priceOpen (percentage)
|
|
24
30
|
* Prevents catastrophic losses from extreme StopLoss values
|
|
@@ -5199,6 +5205,24 @@ declare class BacktestUtils {
|
|
|
5199
5205
|
exchangeName: string;
|
|
5200
5206
|
frameName: string;
|
|
5201
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>;
|
|
5202
5226
|
/**
|
|
5203
5227
|
* Gets statistical data from all closed signals for a symbol-strategy pair.
|
|
5204
5228
|
*
|
|
@@ -5334,6 +5358,24 @@ declare class LiveUtils {
|
|
|
5334
5358
|
strategyName: string;
|
|
5335
5359
|
exchangeName: string;
|
|
5336
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>;
|
|
5337
5379
|
/**
|
|
5338
5380
|
* Gets statistical data from all live trading events for a symbol-strategy pair.
|
|
5339
5381
|
*
|
|
@@ -5641,6 +5683,30 @@ declare class WalkerUtils {
|
|
|
5641
5683
|
background: (symbol: string, context: {
|
|
5642
5684
|
walkerName: string;
|
|
5643
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>;
|
|
5644
5710
|
/**
|
|
5645
5711
|
* Gets walker results data from all strategy comparisons.
|
|
5646
5712
|
*
|
|
@@ -6216,6 +6282,36 @@ declare class ConstantUtils {
|
|
|
6216
6282
|
*/
|
|
6217
6283
|
declare const Constant: ConstantUtils;
|
|
6218
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
|
+
|
|
6219
6315
|
/**
|
|
6220
6316
|
* Global signal emitter for all trading events (live + backtest).
|
|
6221
6317
|
* Emits all signal events regardless of execution mode.
|
|
@@ -6290,11 +6386,10 @@ declare const walkerCompleteSubject: Subject<IWalkerResults>;
|
|
|
6290
6386
|
/**
|
|
6291
6387
|
* Walker stop emitter for walker cancellation events.
|
|
6292
6388
|
* Emits when a walker comparison is stopped/cancelled.
|
|
6389
|
+
*
|
|
6390
|
+
* Includes walkerName to support multiple walkers running on the same symbol.
|
|
6293
6391
|
*/
|
|
6294
|
-
declare const walkerStopSubject: Subject<
|
|
6295
|
-
symbol: string;
|
|
6296
|
-
strategyName: StrategyName;
|
|
6297
|
-
}>;
|
|
6392
|
+
declare const walkerStopSubject: Subject<WalkerStopContract>;
|
|
6298
6393
|
/**
|
|
6299
6394
|
* Validation emitter for risk validation errors.
|
|
6300
6395
|
* Emits when risk validation functions throw errors during signal checking.
|
|
@@ -6604,6 +6699,17 @@ declare class StrategyConnectionService {
|
|
|
6604
6699
|
* @returns Promise resolving to pending signal or null
|
|
6605
6700
|
*/
|
|
6606
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>;
|
|
6607
6713
|
/**
|
|
6608
6714
|
* Executes live trading tick for current strategy.
|
|
6609
6715
|
*
|
|
@@ -6640,7 +6746,7 @@ declare class StrategyConnectionService {
|
|
|
6640
6746
|
stop: (ctx: {
|
|
6641
6747
|
symbol: string;
|
|
6642
6748
|
strategyName: StrategyName;
|
|
6643
|
-
}) => Promise<void>;
|
|
6749
|
+
}, backtest: boolean) => Promise<void>;
|
|
6644
6750
|
/**
|
|
6645
6751
|
* Clears the memoized ClientStrategy instance from cache.
|
|
6646
6752
|
*
|
|
@@ -7073,6 +7179,17 @@ declare class StrategyGlobalService {
|
|
|
7073
7179
|
* @returns Promise resolving to pending signal or null
|
|
7074
7180
|
*/
|
|
7075
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>;
|
|
7076
7193
|
/**
|
|
7077
7194
|
* Checks signal status at a specific timestamp.
|
|
7078
7195
|
*
|
|
@@ -7111,7 +7228,7 @@ declare class StrategyGlobalService {
|
|
|
7111
7228
|
stop: (ctx: {
|
|
7112
7229
|
symbol: string;
|
|
7113
7230
|
strategyName: StrategyName;
|
|
7114
|
-
}) => Promise<void>;
|
|
7231
|
+
}, backtest: boolean) => Promise<void>;
|
|
7115
7232
|
/**
|
|
7116
7233
|
* Clears the memoized ClientStrategy instance from cache.
|
|
7117
7234
|
*
|