backtest-kit 2.0.8 → 2.0.9
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/build/index.cjs +23758 -23175
- package/build/index.mjs +23758 -23175
- package/package.json +1 -1
- package/types.d.ts +195 -1
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -13400,6 +13400,200 @@ declare class BreakevenUtils {
|
|
|
13400
13400
|
*/
|
|
13401
13401
|
declare const Breakeven: BreakevenUtils;
|
|
13402
13402
|
|
|
13403
|
+
/**
|
|
13404
|
+
* Proxy wrapper for user-defined action handlers with automatic error capture.
|
|
13405
|
+
*
|
|
13406
|
+
* Wraps all IPublicAction methods with trycatch to prevent user code errors from crashing the system.
|
|
13407
|
+
* All errors are logged, sent to errorEmitter, and returned as null (non-breaking).
|
|
13408
|
+
*
|
|
13409
|
+
* Key features:
|
|
13410
|
+
* - Automatic error catching and logging for all action methods
|
|
13411
|
+
* - Safe execution of partial user implementations (missing methods return null)
|
|
13412
|
+
* - Consistent error capture across all action lifecycle events
|
|
13413
|
+
* - Non-breaking failure mode (errors logged but execution continues)
|
|
13414
|
+
*
|
|
13415
|
+
* Architecture:
|
|
13416
|
+
* - Private constructor enforces factory pattern via fromInstance()
|
|
13417
|
+
* - Each method checks if target implements the method before calling
|
|
13418
|
+
* - Errors caught with fallback handler (warn log + errorEmitter)
|
|
13419
|
+
* - Returns null on error to prevent undefined behavior
|
|
13420
|
+
*
|
|
13421
|
+
* Used by:
|
|
13422
|
+
* - ClientAction to wrap user-provided action handlers
|
|
13423
|
+
* - ActionCoreService to safely invoke action callbacks
|
|
13424
|
+
*
|
|
13425
|
+
* @example
|
|
13426
|
+
* ```typescript
|
|
13427
|
+
* // Create proxy from user implementation
|
|
13428
|
+
* const userAction = {
|
|
13429
|
+
* signal: async (event) => {
|
|
13430
|
+
* // User code that might throw
|
|
13431
|
+
* throw new Error('User error');
|
|
13432
|
+
* }
|
|
13433
|
+
* };
|
|
13434
|
+
*
|
|
13435
|
+
* const proxy = ActionProxy.fromInstance(userAction);
|
|
13436
|
+
*
|
|
13437
|
+
* // Error is caught and logged, execution continues
|
|
13438
|
+
* await proxy.signal(event); // Logs error, returns null
|
|
13439
|
+
* await proxy.dispose(); // Safe call even though not implemented
|
|
13440
|
+
* ```
|
|
13441
|
+
*
|
|
13442
|
+
* @example
|
|
13443
|
+
* ```typescript
|
|
13444
|
+
* // Partial implementation is safe
|
|
13445
|
+
* const partialAction = {
|
|
13446
|
+
* init: async () => console.log('Initialized'),
|
|
13447
|
+
* // Other methods not implemented
|
|
13448
|
+
* };
|
|
13449
|
+
*
|
|
13450
|
+
* const proxy = ActionProxy.fromInstance(partialAction);
|
|
13451
|
+
* await proxy.init(); // Works
|
|
13452
|
+
* await proxy.signal(event); // Returns null (not implemented)
|
|
13453
|
+
* ```
|
|
13454
|
+
*/
|
|
13455
|
+
declare class ActionProxy implements IPublicAction {
|
|
13456
|
+
readonly _target: Partial<IPublicAction>;
|
|
13457
|
+
/**
|
|
13458
|
+
* Creates a new ActionProxy instance.
|
|
13459
|
+
*
|
|
13460
|
+
* @param _target - Partial action implementation to wrap with error capture
|
|
13461
|
+
* @private Use ActionProxy.fromInstance() instead
|
|
13462
|
+
*/
|
|
13463
|
+
private constructor();
|
|
13464
|
+
/**
|
|
13465
|
+
* Initializes the action handler with error capture.
|
|
13466
|
+
*
|
|
13467
|
+
* Wraps the user's init() method in trycatch to prevent initialization errors from crashing the system.
|
|
13468
|
+
* If the target doesn't implement init(), this method safely returns undefined.
|
|
13469
|
+
*
|
|
13470
|
+
* @returns Promise resolving to user's init() result or undefined if not implemented
|
|
13471
|
+
*/
|
|
13472
|
+
init(): Promise<any>;
|
|
13473
|
+
/**
|
|
13474
|
+
* Handles signal events from all modes with error capture.
|
|
13475
|
+
*
|
|
13476
|
+
* Wraps the user's signal() method to catch and log any errors.
|
|
13477
|
+
* Called on every tick/candle when strategy is evaluated.
|
|
13478
|
+
*
|
|
13479
|
+
* @param event - Signal state result with action, state, signal data, and context
|
|
13480
|
+
* @returns Promise resolving to user's signal() result or null on error
|
|
13481
|
+
*/
|
|
13482
|
+
signal(event: IStrategyTickResult): Promise<any>;
|
|
13483
|
+
/**
|
|
13484
|
+
* Handles signal events from live trading only with error capture.
|
|
13485
|
+
*
|
|
13486
|
+
* Wraps the user's signalLive() method to catch and log any errors.
|
|
13487
|
+
* Called every tick in live mode.
|
|
13488
|
+
*
|
|
13489
|
+
* @param event - Signal state result from live trading
|
|
13490
|
+
* @returns Promise resolving to user's signalLive() result or null on error
|
|
13491
|
+
*/
|
|
13492
|
+
signalLive(event: IStrategyTickResult): Promise<any>;
|
|
13493
|
+
/**
|
|
13494
|
+
* Handles signal events from backtest only with error capture.
|
|
13495
|
+
*
|
|
13496
|
+
* Wraps the user's signalBacktest() method to catch and log any errors.
|
|
13497
|
+
* Called every candle in backtest mode.
|
|
13498
|
+
*
|
|
13499
|
+
* @param event - Signal state result from backtest
|
|
13500
|
+
* @returns Promise resolving to user's signalBacktest() result or null on error
|
|
13501
|
+
*/
|
|
13502
|
+
signalBacktest(event: IStrategyTickResult): Promise<any>;
|
|
13503
|
+
/**
|
|
13504
|
+
* Handles breakeven events with error capture.
|
|
13505
|
+
*
|
|
13506
|
+
* Wraps the user's breakevenAvailable() method to catch and log any errors.
|
|
13507
|
+
* Called once per signal when stop-loss is moved to entry price.
|
|
13508
|
+
*
|
|
13509
|
+
* @param event - Breakeven milestone data with signal info, current price, timestamp
|
|
13510
|
+
* @returns Promise resolving to user's breakevenAvailable() result or null on error
|
|
13511
|
+
*/
|
|
13512
|
+
breakevenAvailable(event: BreakevenContract): Promise<any>;
|
|
13513
|
+
/**
|
|
13514
|
+
* Handles partial profit level events with error capture.
|
|
13515
|
+
*
|
|
13516
|
+
* Wraps the user's partialProfitAvailable() method to catch and log any errors.
|
|
13517
|
+
* Called once per profit level per signal (10%, 20%, 30%, etc).
|
|
13518
|
+
*
|
|
13519
|
+
* @param event - Profit milestone data with signal info, level, price, timestamp
|
|
13520
|
+
* @returns Promise resolving to user's partialProfitAvailable() result or null on error
|
|
13521
|
+
*/
|
|
13522
|
+
partialProfitAvailable(event: PartialProfitContract): Promise<any>;
|
|
13523
|
+
/**
|
|
13524
|
+
* Handles partial loss level events with error capture.
|
|
13525
|
+
*
|
|
13526
|
+
* Wraps the user's partialLossAvailable() method to catch and log any errors.
|
|
13527
|
+
* Called once per loss level per signal (-10%, -20%, -30%, etc).
|
|
13528
|
+
*
|
|
13529
|
+
* @param event - Loss milestone data with signal info, level, price, timestamp
|
|
13530
|
+
* @returns Promise resolving to user's partialLossAvailable() result or null on error
|
|
13531
|
+
*/
|
|
13532
|
+
partialLossAvailable(event: PartialLossContract): Promise<any>;
|
|
13533
|
+
/**
|
|
13534
|
+
* Handles scheduled ping events with error capture.
|
|
13535
|
+
*
|
|
13536
|
+
* Wraps the user's pingScheduled() method to catch and log any errors.
|
|
13537
|
+
* Called every minute while a scheduled signal is waiting for activation.
|
|
13538
|
+
*
|
|
13539
|
+
* @param event - Scheduled signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
13540
|
+
* @returns Promise resolving to user's pingScheduled() result or null on error
|
|
13541
|
+
*/
|
|
13542
|
+
pingScheduled(event: SchedulePingContract): Promise<any>;
|
|
13543
|
+
/**
|
|
13544
|
+
* Handles active ping events with error capture.
|
|
13545
|
+
*
|
|
13546
|
+
* Wraps the user's pingActive() method to catch and log any errors.
|
|
13547
|
+
* Called every minute while a pending signal is active (position open).
|
|
13548
|
+
*
|
|
13549
|
+
* @param event - Active pending signal monitoring data with symbol, strategy info, signal data, timestamp
|
|
13550
|
+
* @returns Promise resolving to user's pingActive() result or null on error
|
|
13551
|
+
*/
|
|
13552
|
+
pingActive(event: ActivePingContract): Promise<any>;
|
|
13553
|
+
/**
|
|
13554
|
+
* Handles risk rejection events with error capture.
|
|
13555
|
+
*
|
|
13556
|
+
* Wraps the user's riskRejection() method to catch and log any errors.
|
|
13557
|
+
* Called only when signal is rejected by risk management validation.
|
|
13558
|
+
*
|
|
13559
|
+
* @param event - Risk rejection data with symbol, pending signal, rejection reason, timestamp
|
|
13560
|
+
* @returns Promise resolving to user's riskRejection() result or null on error
|
|
13561
|
+
*/
|
|
13562
|
+
riskRejection(event: RiskContract): Promise<any>;
|
|
13563
|
+
/**
|
|
13564
|
+
* Cleans up resources with error capture.
|
|
13565
|
+
*
|
|
13566
|
+
* Wraps the user's dispose() method to catch and log any errors.
|
|
13567
|
+
* Called once when strategy execution ends.
|
|
13568
|
+
*
|
|
13569
|
+
* @returns Promise resolving to user's dispose() result or null on error
|
|
13570
|
+
*/
|
|
13571
|
+
dispose(): Promise<any>;
|
|
13572
|
+
/**
|
|
13573
|
+
* Creates a new ActionProxy instance wrapping a user-provided action handler.
|
|
13574
|
+
*
|
|
13575
|
+
* Factory method enforcing the private constructor pattern.
|
|
13576
|
+
* Wraps all methods of the provided instance with error capture.
|
|
13577
|
+
*
|
|
13578
|
+
* @param instance - Partial action implementation to wrap
|
|
13579
|
+
* @returns New ActionProxy instance with error-safe method wrappers
|
|
13580
|
+
*
|
|
13581
|
+
* @example
|
|
13582
|
+
* ```typescript
|
|
13583
|
+
* const userAction = {
|
|
13584
|
+
* signal: async (event) => {
|
|
13585
|
+
* console.log('Signal received:', event);
|
|
13586
|
+
* },
|
|
13587
|
+
* dispose: async () => {
|
|
13588
|
+
* console.log('Cleanup complete');
|
|
13589
|
+
* }
|
|
13590
|
+
* };
|
|
13591
|
+
*
|
|
13592
|
+
* const proxy = ActionProxy.fromInstance(userAction);
|
|
13593
|
+
* ```
|
|
13594
|
+
*/
|
|
13595
|
+
static fromInstance(instance: Partial<IPublicAction>): ActionProxy;
|
|
13596
|
+
}
|
|
13403
13597
|
/**
|
|
13404
13598
|
* Base class for custom action handlers.
|
|
13405
13599
|
*
|
|
@@ -15593,7 +15787,7 @@ declare class ClientAction implements IAction {
|
|
|
15593
15787
|
* Handler instance created from params.handler constructor.
|
|
15594
15788
|
* Starts as null, gets initialized on first use.
|
|
15595
15789
|
*/
|
|
15596
|
-
_handlerInstance:
|
|
15790
|
+
_handlerInstance: ActionProxy | null;
|
|
15597
15791
|
/**
|
|
15598
15792
|
* Creates a new ClientAction instance.
|
|
15599
15793
|
*
|