backtest-kit 1.11.9 → 1.11.10

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 CHANGED
@@ -2253,6 +2253,48 @@ const toPlainString = (content) => {
2253
2253
  return text.trim();
2254
2254
  };
2255
2255
 
2256
+ /**
2257
+ * Wraps a function to execute it outside of the current execution context if one exists.
2258
+ *
2259
+ * This utility ensures that the wrapped function runs in isolation from any existing
2260
+ * ExecutionContext, preventing context leakage and unintended context sharing between
2261
+ * async operations.
2262
+ *
2263
+ * @template T - Function type with any parameters and return type
2264
+ * @param {T} run - The function to be wrapped and executed outside of context
2265
+ * @returns {Function} A curried function that accepts the original function's parameters
2266
+ * and executes it outside of the current context if one exists
2267
+ *
2268
+ * @example
2269
+ * ```ts
2270
+ * const myFunction = async (param: string) => {
2271
+ * // This code will run outside of any ExecutionContext
2272
+ * return param.toUpperCase();
2273
+ * };
2274
+ *
2275
+ * const wrappedFunction = beginTime(myFunction);
2276
+ * const result = wrappedFunction('hello'); // Returns 'HELLO'
2277
+ * ```
2278
+ *
2279
+ * @example
2280
+ * ```ts
2281
+ * // Usage with trycatch wrapper
2282
+ * const safeFunction = trycatch(
2283
+ * beginTime(async (id: number) => {
2284
+ * // Function body runs isolated from parent context
2285
+ * return await fetchData(id);
2286
+ * })
2287
+ * );
2288
+ * ```
2289
+ */
2290
+ const beginTime = (run) => (...args) => {
2291
+ let fn = () => run(...args);
2292
+ if (ExecutionContextService.hasContext()) {
2293
+ fn = ExecutionContextService.runOutOfContext(fn);
2294
+ }
2295
+ return fn();
2296
+ };
2297
+
2256
2298
  const INTERVAL_MINUTES$3 = {
2257
2299
  "1m": 1,
2258
2300
  "3m": 3,
@@ -3352,7 +3394,7 @@ const ACTIVATE_SCHEDULED_SIGNAL_FN = async (self, scheduled, activationTimestamp
3352
3394
  await CALL_TICK_CALLBACKS_FN(self, self.params.execution.context.symbol, result, activationTime, self.params.execution.context.backtest);
3353
3395
  return result;
3354
3396
  };
3355
- const CALL_PING_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, scheduled, timestamp, backtest) => {
3397
+ const CALL_PING_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, scheduled, timestamp, backtest) => {
3356
3398
  await ExecutionContextService.runInContext(async () => {
3357
3399
  const publicSignal = TO_PUBLIC_SIGNAL(scheduled);
3358
3400
  // Call system onPing callback first (emits to pingSubject)
@@ -3366,7 +3408,7 @@ const CALL_PING_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, schedu
3366
3408
  symbol: symbol,
3367
3409
  backtest: backtest,
3368
3410
  });
3369
- }, {
3411
+ }), {
3370
3412
  fallback: (error) => {
3371
3413
  const message = "ClientStrategy CALL_PING_CALLBACKS_FN thrown";
3372
3414
  const payload = {
@@ -3378,7 +3420,7 @@ const CALL_PING_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, schedu
3378
3420
  errorEmitter.next(error);
3379
3421
  },
3380
3422
  });
3381
- const CALL_ACTIVE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3423
+ const CALL_ACTIVE_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3382
3424
  await ExecutionContextService.runInContext(async () => {
3383
3425
  if (self.params.callbacks?.onActive) {
3384
3426
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3389,7 +3431,7 @@ const CALL_ACTIVE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, sign
3389
3431
  symbol: symbol,
3390
3432
  backtest: backtest,
3391
3433
  });
3392
- }, {
3434
+ }), {
3393
3435
  fallback: (error) => {
3394
3436
  const message = "ClientStrategy CALL_ACTIVE_CALLBACKS_FN thrown";
3395
3437
  const payload = {
@@ -3401,7 +3443,7 @@ const CALL_ACTIVE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, sign
3401
3443
  errorEmitter.next(error);
3402
3444
  },
3403
3445
  });
3404
- const CALL_SCHEDULE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3446
+ const CALL_SCHEDULE_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3405
3447
  await ExecutionContextService.runInContext(async () => {
3406
3448
  if (self.params.callbacks?.onSchedule) {
3407
3449
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3412,7 +3454,7 @@ const CALL_SCHEDULE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, si
3412
3454
  symbol: symbol,
3413
3455
  backtest: backtest,
3414
3456
  });
3415
- }, {
3457
+ }), {
3416
3458
  fallback: (error) => {
3417
3459
  const message = "ClientStrategy CALL_SCHEDULE_CALLBACKS_FN thrown";
3418
3460
  const payload = {
@@ -3424,7 +3466,7 @@ const CALL_SCHEDULE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, si
3424
3466
  errorEmitter.next(error);
3425
3467
  },
3426
3468
  });
3427
- const CALL_CANCEL_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3469
+ const CALL_CANCEL_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3428
3470
  await ExecutionContextService.runInContext(async () => {
3429
3471
  if (self.params.callbacks?.onCancel) {
3430
3472
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3435,7 +3477,7 @@ const CALL_CANCEL_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, sign
3435
3477
  symbol: symbol,
3436
3478
  backtest: backtest,
3437
3479
  });
3438
- }, {
3480
+ }), {
3439
3481
  fallback: (error) => {
3440
3482
  const message = "ClientStrategy CALL_CANCEL_CALLBACKS_FN thrown";
3441
3483
  const payload = {
@@ -3447,7 +3489,7 @@ const CALL_CANCEL_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, sign
3447
3489
  errorEmitter.next(error);
3448
3490
  },
3449
3491
  });
3450
- const CALL_OPEN_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal, priceOpen, timestamp, backtest) => {
3492
+ const CALL_OPEN_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, priceOpen, timestamp, backtest) => {
3451
3493
  await ExecutionContextService.runInContext(async () => {
3452
3494
  if (self.params.callbacks?.onOpen) {
3453
3495
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3458,7 +3500,7 @@ const CALL_OPEN_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal
3458
3500
  symbol: symbol,
3459
3501
  backtest: backtest,
3460
3502
  });
3461
- }, {
3503
+ }), {
3462
3504
  fallback: (error) => {
3463
3505
  const message = "ClientStrategy CALL_OPEN_CALLBACKS_FN thrown";
3464
3506
  const payload = {
@@ -3470,7 +3512,7 @@ const CALL_OPEN_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal
3470
3512
  errorEmitter.next(error);
3471
3513
  },
3472
3514
  });
3473
- const CALL_CLOSE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3515
+ const CALL_CLOSE_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3474
3516
  await ExecutionContextService.runInContext(async () => {
3475
3517
  if (self.params.callbacks?.onClose) {
3476
3518
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3481,7 +3523,7 @@ const CALL_CLOSE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signa
3481
3523
  symbol: symbol,
3482
3524
  backtest: backtest,
3483
3525
  });
3484
- }, {
3526
+ }), {
3485
3527
  fallback: (error) => {
3486
3528
  const message = "ClientStrategy CALL_CLOSE_CALLBACKS_FN thrown";
3487
3529
  const payload = {
@@ -3493,7 +3535,7 @@ const CALL_CLOSE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signa
3493
3535
  errorEmitter.next(error);
3494
3536
  },
3495
3537
  });
3496
- const CALL_TICK_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, result, timestamp, backtest) => {
3538
+ const CALL_TICK_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, result, timestamp, backtest) => {
3497
3539
  await ExecutionContextService.runInContext(async () => {
3498
3540
  if (self.params.callbacks?.onTick) {
3499
3541
  await self.params.callbacks.onTick(self.params.execution.context.symbol, result, self.params.execution.context.backtest);
@@ -3503,7 +3545,7 @@ const CALL_TICK_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, result
3503
3545
  symbol: symbol,
3504
3546
  backtest: backtest,
3505
3547
  });
3506
- }, {
3548
+ }), {
3507
3549
  fallback: (error) => {
3508
3550
  const message = "ClientStrategy CALL_TICK_CALLBACKS_FN thrown";
3509
3551
  const payload = {
@@ -3515,7 +3557,7 @@ const CALL_TICK_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, result
3515
3557
  errorEmitter.next(error);
3516
3558
  },
3517
3559
  });
3518
- const CALL_IDLE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, currentPrice, timestamp, backtest) => {
3560
+ const CALL_IDLE_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, currentPrice, timestamp, backtest) => {
3519
3561
  await ExecutionContextService.runInContext(async () => {
3520
3562
  if (self.params.callbacks?.onIdle) {
3521
3563
  await self.params.callbacks.onIdle(self.params.execution.context.symbol, currentPrice, self.params.execution.context.backtest);
@@ -3525,7 +3567,7 @@ const CALL_IDLE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, curren
3525
3567
  symbol: symbol,
3526
3568
  backtest: backtest,
3527
3569
  });
3528
- }, {
3570
+ }), {
3529
3571
  fallback: (error) => {
3530
3572
  const message = "ClientStrategy CALL_IDLE_CALLBACKS_FN thrown";
3531
3573
  const payload = {
@@ -3537,7 +3579,7 @@ const CALL_IDLE_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, curren
3537
3579
  errorEmitter.next(error);
3538
3580
  },
3539
3581
  });
3540
- const CALL_RISK_ADD_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, signal, timestamp, backtest) => {
3582
+ const CALL_RISK_ADD_SIGNAL_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, timestamp, backtest) => {
3541
3583
  await ExecutionContextService.runInContext(async () => {
3542
3584
  await self.params.risk.addSignal(symbol, {
3543
3585
  strategyName: self.params.method.context.strategyName,
@@ -3557,7 +3599,7 @@ const CALL_RISK_ADD_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, signa
3557
3599
  symbol: symbol,
3558
3600
  backtest: backtest,
3559
3601
  });
3560
- }, {
3602
+ }), {
3561
3603
  fallback: (error) => {
3562
3604
  const message = "ClientStrategy CALL_RISK_ADD_SIGNAL_FN thrown";
3563
3605
  const payload = {
@@ -3569,7 +3611,7 @@ const CALL_RISK_ADD_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, signa
3569
3611
  errorEmitter.next(error);
3570
3612
  },
3571
3613
  });
3572
- const CALL_RISK_REMOVE_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, timestamp, backtest) => {
3614
+ const CALL_RISK_REMOVE_SIGNAL_FN = functoolsKit.trycatch(beginTime(async (self, symbol, timestamp, backtest) => {
3573
3615
  await ExecutionContextService.runInContext(async () => {
3574
3616
  await self.params.risk.removeSignal(symbol, {
3575
3617
  strategyName: self.params.method.context.strategyName,
@@ -3582,7 +3624,7 @@ const CALL_RISK_REMOVE_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, ti
3582
3624
  symbol: symbol,
3583
3625
  backtest: backtest,
3584
3626
  });
3585
- }, {
3627
+ }), {
3586
3628
  fallback: (error) => {
3587
3629
  const message = "ClientStrategy CALL_RISK_REMOVE_SIGNAL_FN thrown";
3588
3630
  const payload = {
@@ -3594,7 +3636,7 @@ const CALL_RISK_REMOVE_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, ti
3594
3636
  errorEmitter.next(error);
3595
3637
  },
3596
3638
  });
3597
- const CALL_PARTIAL_CLEAR_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3639
+ const CALL_PARTIAL_CLEAR_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3598
3640
  await ExecutionContextService.runInContext(async () => {
3599
3641
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3600
3642
  await self.params.partial.clear(symbol, publicSignal, currentPrice, backtest);
@@ -3603,7 +3645,7 @@ const CALL_PARTIAL_CLEAR_FN = functoolsKit.trycatch(async (self, symbol, signal,
3603
3645
  symbol: symbol,
3604
3646
  backtest: backtest,
3605
3647
  });
3606
- }, {
3648
+ }), {
3607
3649
  fallback: (error) => {
3608
3650
  const message = "ClientStrategy CALL_PARTIAL_CLEAR_FN thrown";
3609
3651
  const payload = {
@@ -3615,7 +3657,7 @@ const CALL_PARTIAL_CLEAR_FN = functoolsKit.trycatch(async (self, symbol, signal,
3615
3657
  errorEmitter.next(error);
3616
3658
  },
3617
3659
  });
3618
- const CALL_RISK_CHECK_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, pendingSignal, currentPrice, timestamp, backtest) => {
3660
+ const CALL_RISK_CHECK_SIGNAL_FN = functoolsKit.trycatch(beginTime(async (self, symbol, pendingSignal, currentPrice, timestamp, backtest) => {
3619
3661
  return await ExecutionContextService.runInContext(async () => {
3620
3662
  return await self.params.risk.checkSignal({
3621
3663
  pendingSignal: TO_PUBLIC_SIGNAL(pendingSignal),
@@ -3632,7 +3674,7 @@ const CALL_RISK_CHECK_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, pen
3632
3674
  symbol: symbol,
3633
3675
  backtest: backtest,
3634
3676
  });
3635
- }, {
3677
+ }), {
3636
3678
  defaultValue: false,
3637
3679
  fallback: (error) => {
3638
3680
  const message = "ClientStrategy CALL_RISK_CHECK_SIGNAL_FN thrown";
@@ -3645,7 +3687,7 @@ const CALL_RISK_CHECK_SIGNAL_FN = functoolsKit.trycatch(async (self, symbol, pen
3645
3687
  errorEmitter.next(error);
3646
3688
  },
3647
3689
  });
3648
- const CALL_PARTIAL_PROFIT_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, percentTp, timestamp, backtest) => {
3690
+ const CALL_PARTIAL_PROFIT_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, percentTp, timestamp, backtest) => {
3649
3691
  await ExecutionContextService.runInContext(async () => {
3650
3692
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3651
3693
  await self.params.partial.profit(symbol, publicSignal, currentPrice, percentTp, backtest, new Date(timestamp));
@@ -3657,7 +3699,7 @@ const CALL_PARTIAL_PROFIT_CALLBACKS_FN = functoolsKit.trycatch(async (self, symb
3657
3699
  symbol: symbol,
3658
3700
  backtest: backtest,
3659
3701
  });
3660
- }, {
3702
+ }), {
3661
3703
  fallback: (error) => {
3662
3704
  const message = "ClientStrategy CALL_PARTIAL_PROFIT_CALLBACKS_FN thrown";
3663
3705
  const payload = {
@@ -3669,7 +3711,7 @@ const CALL_PARTIAL_PROFIT_CALLBACKS_FN = functoolsKit.trycatch(async (self, symb
3669
3711
  errorEmitter.next(error);
3670
3712
  },
3671
3713
  });
3672
- const CALL_PARTIAL_LOSS_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, percentSl, timestamp, backtest) => {
3714
+ const CALL_PARTIAL_LOSS_CALLBACKS_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, percentSl, timestamp, backtest) => {
3673
3715
  await ExecutionContextService.runInContext(async () => {
3674
3716
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3675
3717
  await self.params.partial.loss(symbol, publicSignal, currentPrice, percentSl, backtest, new Date(timestamp));
@@ -3681,7 +3723,7 @@ const CALL_PARTIAL_LOSS_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol
3681
3723
  symbol: symbol,
3682
3724
  backtest: backtest,
3683
3725
  });
3684
- }, {
3726
+ }), {
3685
3727
  fallback: (error) => {
3686
3728
  const message = "ClientStrategy CALL_PARTIAL_LOSS_CALLBACKS_FN thrown";
3687
3729
  const payload = {
@@ -3693,7 +3735,7 @@ const CALL_PARTIAL_LOSS_CALLBACKS_FN = functoolsKit.trycatch(async (self, symbol
3693
3735
  errorEmitter.next(error);
3694
3736
  },
3695
3737
  });
3696
- const CALL_BREAKEVEN_CHECK_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3738
+ const CALL_BREAKEVEN_CHECK_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3697
3739
  await ExecutionContextService.runInContext(async () => {
3698
3740
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3699
3741
  const isBreakeven = await self.params.breakeven.check(symbol, publicSignal, currentPrice, backtest, new Date(timestamp));
@@ -3705,7 +3747,7 @@ const CALL_BREAKEVEN_CHECK_FN = functoolsKit.trycatch(async (self, symbol, signa
3705
3747
  symbol: symbol,
3706
3748
  backtest: backtest,
3707
3749
  });
3708
- }, {
3750
+ }), {
3709
3751
  fallback: (error) => {
3710
3752
  const message = "ClientStrategy CALL_BREAKEVEN_CHECK_FN thrown";
3711
3753
  const payload = {
@@ -3717,7 +3759,7 @@ const CALL_BREAKEVEN_CHECK_FN = functoolsKit.trycatch(async (self, symbol, signa
3717
3759
  errorEmitter.next(error);
3718
3760
  },
3719
3761
  });
3720
- const CALL_BREAKEVEN_CLEAR_FN = functoolsKit.trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3762
+ const CALL_BREAKEVEN_CLEAR_FN = functoolsKit.trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3721
3763
  await ExecutionContextService.runInContext(async () => {
3722
3764
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3723
3765
  await self.params.breakeven.clear(symbol, publicSignal, currentPrice, backtest);
@@ -3726,7 +3768,7 @@ const CALL_BREAKEVEN_CLEAR_FN = functoolsKit.trycatch(async (self, symbol, signa
3726
3768
  symbol: symbol,
3727
3769
  backtest: backtest,
3728
3770
  });
3729
- }, {
3771
+ }), {
3730
3772
  fallback: (error) => {
3731
3773
  const message = "ClientStrategy CALL_BREAKEVEN_CLEAR_FN thrown";
3732
3774
  const payload = {
package/build/index.mjs CHANGED
@@ -2233,6 +2233,48 @@ const toPlainString = (content) => {
2233
2233
  return text.trim();
2234
2234
  };
2235
2235
 
2236
+ /**
2237
+ * Wraps a function to execute it outside of the current execution context if one exists.
2238
+ *
2239
+ * This utility ensures that the wrapped function runs in isolation from any existing
2240
+ * ExecutionContext, preventing context leakage and unintended context sharing between
2241
+ * async operations.
2242
+ *
2243
+ * @template T - Function type with any parameters and return type
2244
+ * @param {T} run - The function to be wrapped and executed outside of context
2245
+ * @returns {Function} A curried function that accepts the original function's parameters
2246
+ * and executes it outside of the current context if one exists
2247
+ *
2248
+ * @example
2249
+ * ```ts
2250
+ * const myFunction = async (param: string) => {
2251
+ * // This code will run outside of any ExecutionContext
2252
+ * return param.toUpperCase();
2253
+ * };
2254
+ *
2255
+ * const wrappedFunction = beginTime(myFunction);
2256
+ * const result = wrappedFunction('hello'); // Returns 'HELLO'
2257
+ * ```
2258
+ *
2259
+ * @example
2260
+ * ```ts
2261
+ * // Usage with trycatch wrapper
2262
+ * const safeFunction = trycatch(
2263
+ * beginTime(async (id: number) => {
2264
+ * // Function body runs isolated from parent context
2265
+ * return await fetchData(id);
2266
+ * })
2267
+ * );
2268
+ * ```
2269
+ */
2270
+ const beginTime = (run) => (...args) => {
2271
+ let fn = () => run(...args);
2272
+ if (ExecutionContextService.hasContext()) {
2273
+ fn = ExecutionContextService.runOutOfContext(fn);
2274
+ }
2275
+ return fn();
2276
+ };
2277
+
2236
2278
  const INTERVAL_MINUTES$3 = {
2237
2279
  "1m": 1,
2238
2280
  "3m": 3,
@@ -3332,7 +3374,7 @@ const ACTIVATE_SCHEDULED_SIGNAL_FN = async (self, scheduled, activationTimestamp
3332
3374
  await CALL_TICK_CALLBACKS_FN(self, self.params.execution.context.symbol, result, activationTime, self.params.execution.context.backtest);
3333
3375
  return result;
3334
3376
  };
3335
- const CALL_PING_CALLBACKS_FN = trycatch(async (self, symbol, scheduled, timestamp, backtest) => {
3377
+ const CALL_PING_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, scheduled, timestamp, backtest) => {
3336
3378
  await ExecutionContextService.runInContext(async () => {
3337
3379
  const publicSignal = TO_PUBLIC_SIGNAL(scheduled);
3338
3380
  // Call system onPing callback first (emits to pingSubject)
@@ -3346,7 +3388,7 @@ const CALL_PING_CALLBACKS_FN = trycatch(async (self, symbol, scheduled, timestam
3346
3388
  symbol: symbol,
3347
3389
  backtest: backtest,
3348
3390
  });
3349
- }, {
3391
+ }), {
3350
3392
  fallback: (error) => {
3351
3393
  const message = "ClientStrategy CALL_PING_CALLBACKS_FN thrown";
3352
3394
  const payload = {
@@ -3358,7 +3400,7 @@ const CALL_PING_CALLBACKS_FN = trycatch(async (self, symbol, scheduled, timestam
3358
3400
  errorEmitter.next(error);
3359
3401
  },
3360
3402
  });
3361
- const CALL_ACTIVE_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3403
+ const CALL_ACTIVE_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3362
3404
  await ExecutionContextService.runInContext(async () => {
3363
3405
  if (self.params.callbacks?.onActive) {
3364
3406
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3369,7 +3411,7 @@ const CALL_ACTIVE_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPr
3369
3411
  symbol: symbol,
3370
3412
  backtest: backtest,
3371
3413
  });
3372
- }, {
3414
+ }), {
3373
3415
  fallback: (error) => {
3374
3416
  const message = "ClientStrategy CALL_ACTIVE_CALLBACKS_FN thrown";
3375
3417
  const payload = {
@@ -3381,7 +3423,7 @@ const CALL_ACTIVE_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPr
3381
3423
  errorEmitter.next(error);
3382
3424
  },
3383
3425
  });
3384
- const CALL_SCHEDULE_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3426
+ const CALL_SCHEDULE_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3385
3427
  await ExecutionContextService.runInContext(async () => {
3386
3428
  if (self.params.callbacks?.onSchedule) {
3387
3429
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3392,7 +3434,7 @@ const CALL_SCHEDULE_CALLBACKS_FN = trycatch(async (self, symbol, signal, current
3392
3434
  symbol: symbol,
3393
3435
  backtest: backtest,
3394
3436
  });
3395
- }, {
3437
+ }), {
3396
3438
  fallback: (error) => {
3397
3439
  const message = "ClientStrategy CALL_SCHEDULE_CALLBACKS_FN thrown";
3398
3440
  const payload = {
@@ -3404,7 +3446,7 @@ const CALL_SCHEDULE_CALLBACKS_FN = trycatch(async (self, symbol, signal, current
3404
3446
  errorEmitter.next(error);
3405
3447
  },
3406
3448
  });
3407
- const CALL_CANCEL_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3449
+ const CALL_CANCEL_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3408
3450
  await ExecutionContextService.runInContext(async () => {
3409
3451
  if (self.params.callbacks?.onCancel) {
3410
3452
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3415,7 +3457,7 @@ const CALL_CANCEL_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPr
3415
3457
  symbol: symbol,
3416
3458
  backtest: backtest,
3417
3459
  });
3418
- }, {
3460
+ }), {
3419
3461
  fallback: (error) => {
3420
3462
  const message = "ClientStrategy CALL_CANCEL_CALLBACKS_FN thrown";
3421
3463
  const payload = {
@@ -3427,7 +3469,7 @@ const CALL_CANCEL_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPr
3427
3469
  errorEmitter.next(error);
3428
3470
  },
3429
3471
  });
3430
- const CALL_OPEN_CALLBACKS_FN = trycatch(async (self, symbol, signal, priceOpen, timestamp, backtest) => {
3472
+ const CALL_OPEN_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, signal, priceOpen, timestamp, backtest) => {
3431
3473
  await ExecutionContextService.runInContext(async () => {
3432
3474
  if (self.params.callbacks?.onOpen) {
3433
3475
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3438,7 +3480,7 @@ const CALL_OPEN_CALLBACKS_FN = trycatch(async (self, symbol, signal, priceOpen,
3438
3480
  symbol: symbol,
3439
3481
  backtest: backtest,
3440
3482
  });
3441
- }, {
3483
+ }), {
3442
3484
  fallback: (error) => {
3443
3485
  const message = "ClientStrategy CALL_OPEN_CALLBACKS_FN thrown";
3444
3486
  const payload = {
@@ -3450,7 +3492,7 @@ const CALL_OPEN_CALLBACKS_FN = trycatch(async (self, symbol, signal, priceOpen,
3450
3492
  errorEmitter.next(error);
3451
3493
  },
3452
3494
  });
3453
- const CALL_CLOSE_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3495
+ const CALL_CLOSE_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3454
3496
  await ExecutionContextService.runInContext(async () => {
3455
3497
  if (self.params.callbacks?.onClose) {
3456
3498
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
@@ -3461,7 +3503,7 @@ const CALL_CLOSE_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPri
3461
3503
  symbol: symbol,
3462
3504
  backtest: backtest,
3463
3505
  });
3464
- }, {
3506
+ }), {
3465
3507
  fallback: (error) => {
3466
3508
  const message = "ClientStrategy CALL_CLOSE_CALLBACKS_FN thrown";
3467
3509
  const payload = {
@@ -3473,7 +3515,7 @@ const CALL_CLOSE_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPri
3473
3515
  errorEmitter.next(error);
3474
3516
  },
3475
3517
  });
3476
- const CALL_TICK_CALLBACKS_FN = trycatch(async (self, symbol, result, timestamp, backtest) => {
3518
+ const CALL_TICK_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, result, timestamp, backtest) => {
3477
3519
  await ExecutionContextService.runInContext(async () => {
3478
3520
  if (self.params.callbacks?.onTick) {
3479
3521
  await self.params.callbacks.onTick(self.params.execution.context.symbol, result, self.params.execution.context.backtest);
@@ -3483,7 +3525,7 @@ const CALL_TICK_CALLBACKS_FN = trycatch(async (self, symbol, result, timestamp,
3483
3525
  symbol: symbol,
3484
3526
  backtest: backtest,
3485
3527
  });
3486
- }, {
3528
+ }), {
3487
3529
  fallback: (error) => {
3488
3530
  const message = "ClientStrategy CALL_TICK_CALLBACKS_FN thrown";
3489
3531
  const payload = {
@@ -3495,7 +3537,7 @@ const CALL_TICK_CALLBACKS_FN = trycatch(async (self, symbol, result, timestamp,
3495
3537
  errorEmitter.next(error);
3496
3538
  },
3497
3539
  });
3498
- const CALL_IDLE_CALLBACKS_FN = trycatch(async (self, symbol, currentPrice, timestamp, backtest) => {
3540
+ const CALL_IDLE_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, currentPrice, timestamp, backtest) => {
3499
3541
  await ExecutionContextService.runInContext(async () => {
3500
3542
  if (self.params.callbacks?.onIdle) {
3501
3543
  await self.params.callbacks.onIdle(self.params.execution.context.symbol, currentPrice, self.params.execution.context.backtest);
@@ -3505,7 +3547,7 @@ const CALL_IDLE_CALLBACKS_FN = trycatch(async (self, symbol, currentPrice, times
3505
3547
  symbol: symbol,
3506
3548
  backtest: backtest,
3507
3549
  });
3508
- }, {
3550
+ }), {
3509
3551
  fallback: (error) => {
3510
3552
  const message = "ClientStrategy CALL_IDLE_CALLBACKS_FN thrown";
3511
3553
  const payload = {
@@ -3517,7 +3559,7 @@ const CALL_IDLE_CALLBACKS_FN = trycatch(async (self, symbol, currentPrice, times
3517
3559
  errorEmitter.next(error);
3518
3560
  },
3519
3561
  });
3520
- const CALL_RISK_ADD_SIGNAL_FN = trycatch(async (self, symbol, signal, timestamp, backtest) => {
3562
+ const CALL_RISK_ADD_SIGNAL_FN = trycatch(beginTime(async (self, symbol, signal, timestamp, backtest) => {
3521
3563
  await ExecutionContextService.runInContext(async () => {
3522
3564
  await self.params.risk.addSignal(symbol, {
3523
3565
  strategyName: self.params.method.context.strategyName,
@@ -3537,7 +3579,7 @@ const CALL_RISK_ADD_SIGNAL_FN = trycatch(async (self, symbol, signal, timestamp,
3537
3579
  symbol: symbol,
3538
3580
  backtest: backtest,
3539
3581
  });
3540
- }, {
3582
+ }), {
3541
3583
  fallback: (error) => {
3542
3584
  const message = "ClientStrategy CALL_RISK_ADD_SIGNAL_FN thrown";
3543
3585
  const payload = {
@@ -3549,7 +3591,7 @@ const CALL_RISK_ADD_SIGNAL_FN = trycatch(async (self, symbol, signal, timestamp,
3549
3591
  errorEmitter.next(error);
3550
3592
  },
3551
3593
  });
3552
- const CALL_RISK_REMOVE_SIGNAL_FN = trycatch(async (self, symbol, timestamp, backtest) => {
3594
+ const CALL_RISK_REMOVE_SIGNAL_FN = trycatch(beginTime(async (self, symbol, timestamp, backtest) => {
3553
3595
  await ExecutionContextService.runInContext(async () => {
3554
3596
  await self.params.risk.removeSignal(symbol, {
3555
3597
  strategyName: self.params.method.context.strategyName,
@@ -3562,7 +3604,7 @@ const CALL_RISK_REMOVE_SIGNAL_FN = trycatch(async (self, symbol, timestamp, back
3562
3604
  symbol: symbol,
3563
3605
  backtest: backtest,
3564
3606
  });
3565
- }, {
3607
+ }), {
3566
3608
  fallback: (error) => {
3567
3609
  const message = "ClientStrategy CALL_RISK_REMOVE_SIGNAL_FN thrown";
3568
3610
  const payload = {
@@ -3574,7 +3616,7 @@ const CALL_RISK_REMOVE_SIGNAL_FN = trycatch(async (self, symbol, timestamp, back
3574
3616
  errorEmitter.next(error);
3575
3617
  },
3576
3618
  });
3577
- const CALL_PARTIAL_CLEAR_FN = trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3619
+ const CALL_PARTIAL_CLEAR_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3578
3620
  await ExecutionContextService.runInContext(async () => {
3579
3621
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3580
3622
  await self.params.partial.clear(symbol, publicSignal, currentPrice, backtest);
@@ -3583,7 +3625,7 @@ const CALL_PARTIAL_CLEAR_FN = trycatch(async (self, symbol, signal, currentPrice
3583
3625
  symbol: symbol,
3584
3626
  backtest: backtest,
3585
3627
  });
3586
- }, {
3628
+ }), {
3587
3629
  fallback: (error) => {
3588
3630
  const message = "ClientStrategy CALL_PARTIAL_CLEAR_FN thrown";
3589
3631
  const payload = {
@@ -3595,7 +3637,7 @@ const CALL_PARTIAL_CLEAR_FN = trycatch(async (self, symbol, signal, currentPrice
3595
3637
  errorEmitter.next(error);
3596
3638
  },
3597
3639
  });
3598
- const CALL_RISK_CHECK_SIGNAL_FN = trycatch(async (self, symbol, pendingSignal, currentPrice, timestamp, backtest) => {
3640
+ const CALL_RISK_CHECK_SIGNAL_FN = trycatch(beginTime(async (self, symbol, pendingSignal, currentPrice, timestamp, backtest) => {
3599
3641
  return await ExecutionContextService.runInContext(async () => {
3600
3642
  return await self.params.risk.checkSignal({
3601
3643
  pendingSignal: TO_PUBLIC_SIGNAL(pendingSignal),
@@ -3612,7 +3654,7 @@ const CALL_RISK_CHECK_SIGNAL_FN = trycatch(async (self, symbol, pendingSignal, c
3612
3654
  symbol: symbol,
3613
3655
  backtest: backtest,
3614
3656
  });
3615
- }, {
3657
+ }), {
3616
3658
  defaultValue: false,
3617
3659
  fallback: (error) => {
3618
3660
  const message = "ClientStrategy CALL_RISK_CHECK_SIGNAL_FN thrown";
@@ -3625,7 +3667,7 @@ const CALL_RISK_CHECK_SIGNAL_FN = trycatch(async (self, symbol, pendingSignal, c
3625
3667
  errorEmitter.next(error);
3626
3668
  },
3627
3669
  });
3628
- const CALL_PARTIAL_PROFIT_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPrice, percentTp, timestamp, backtest) => {
3670
+ const CALL_PARTIAL_PROFIT_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, percentTp, timestamp, backtest) => {
3629
3671
  await ExecutionContextService.runInContext(async () => {
3630
3672
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3631
3673
  await self.params.partial.profit(symbol, publicSignal, currentPrice, percentTp, backtest, new Date(timestamp));
@@ -3637,7 +3679,7 @@ const CALL_PARTIAL_PROFIT_CALLBACKS_FN = trycatch(async (self, symbol, signal, c
3637
3679
  symbol: symbol,
3638
3680
  backtest: backtest,
3639
3681
  });
3640
- }, {
3682
+ }), {
3641
3683
  fallback: (error) => {
3642
3684
  const message = "ClientStrategy CALL_PARTIAL_PROFIT_CALLBACKS_FN thrown";
3643
3685
  const payload = {
@@ -3649,7 +3691,7 @@ const CALL_PARTIAL_PROFIT_CALLBACKS_FN = trycatch(async (self, symbol, signal, c
3649
3691
  errorEmitter.next(error);
3650
3692
  },
3651
3693
  });
3652
- const CALL_PARTIAL_LOSS_CALLBACKS_FN = trycatch(async (self, symbol, signal, currentPrice, percentSl, timestamp, backtest) => {
3694
+ const CALL_PARTIAL_LOSS_CALLBACKS_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, percentSl, timestamp, backtest) => {
3653
3695
  await ExecutionContextService.runInContext(async () => {
3654
3696
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3655
3697
  await self.params.partial.loss(symbol, publicSignal, currentPrice, percentSl, backtest, new Date(timestamp));
@@ -3661,7 +3703,7 @@ const CALL_PARTIAL_LOSS_CALLBACKS_FN = trycatch(async (self, symbol, signal, cur
3661
3703
  symbol: symbol,
3662
3704
  backtest: backtest,
3663
3705
  });
3664
- }, {
3706
+ }), {
3665
3707
  fallback: (error) => {
3666
3708
  const message = "ClientStrategy CALL_PARTIAL_LOSS_CALLBACKS_FN thrown";
3667
3709
  const payload = {
@@ -3673,7 +3715,7 @@ const CALL_PARTIAL_LOSS_CALLBACKS_FN = trycatch(async (self, symbol, signal, cur
3673
3715
  errorEmitter.next(error);
3674
3716
  },
3675
3717
  });
3676
- const CALL_BREAKEVEN_CHECK_FN = trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3718
+ const CALL_BREAKEVEN_CHECK_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3677
3719
  await ExecutionContextService.runInContext(async () => {
3678
3720
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3679
3721
  const isBreakeven = await self.params.breakeven.check(symbol, publicSignal, currentPrice, backtest, new Date(timestamp));
@@ -3685,7 +3727,7 @@ const CALL_BREAKEVEN_CHECK_FN = trycatch(async (self, symbol, signal, currentPri
3685
3727
  symbol: symbol,
3686
3728
  backtest: backtest,
3687
3729
  });
3688
- }, {
3730
+ }), {
3689
3731
  fallback: (error) => {
3690
3732
  const message = "ClientStrategy CALL_BREAKEVEN_CHECK_FN thrown";
3691
3733
  const payload = {
@@ -3697,7 +3739,7 @@ const CALL_BREAKEVEN_CHECK_FN = trycatch(async (self, symbol, signal, currentPri
3697
3739
  errorEmitter.next(error);
3698
3740
  },
3699
3741
  });
3700
- const CALL_BREAKEVEN_CLEAR_FN = trycatch(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3742
+ const CALL_BREAKEVEN_CLEAR_FN = trycatch(beginTime(async (self, symbol, signal, currentPrice, timestamp, backtest) => {
3701
3743
  await ExecutionContextService.runInContext(async () => {
3702
3744
  const publicSignal = TO_PUBLIC_SIGNAL(signal);
3703
3745
  await self.params.breakeven.clear(symbol, publicSignal, currentPrice, backtest);
@@ -3706,7 +3748,7 @@ const CALL_BREAKEVEN_CLEAR_FN = trycatch(async (self, symbol, signal, currentPri
3706
3748
  symbol: symbol,
3707
3749
  backtest: backtest,
3708
3750
  });
3709
- }, {
3751
+ }), {
3710
3752
  fallback: (error) => {
3711
3753
  const message = "ClientStrategy CALL_BREAKEVEN_CLEAR_FN thrown";
3712
3754
  const payload = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "1.11.9",
3
+ "version": "1.11.10",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",