backtest-kit 2.2.8 → 2.2.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 CHANGED
@@ -12153,11 +12153,13 @@ class BacktestLogicPrivateService {
12153
12153
  // и если активируется - продолжит с TP/SL мониторингом
12154
12154
  let backtestResult;
12155
12155
  let unScheduleOpen;
12156
+ let scheduleOpenResult;
12156
12157
  {
12157
12158
  const { strategyName, exchangeName, frameName } = this.methodContextService.context;
12158
12159
  unScheduleOpen = backtestScheduleOpenSubject.filter((event) => {
12159
12160
  let isOk = true;
12160
12161
  {
12162
+ isOk = isOk && event.action === "opened";
12161
12163
  isOk = isOk && event.strategyName === strategyName;
12162
12164
  isOk = isOk && event.exchangeName === exchangeName;
12163
12165
  isOk = isOk && event.frameName === frameName;
@@ -12165,6 +12167,8 @@ class BacktestLogicPrivateService {
12165
12167
  }
12166
12168
  return isOk;
12167
12169
  }).connect(async (tick) => {
12170
+ scheduleOpenResult = tick;
12171
+ await signalEmitter.next(tick);
12168
12172
  await signalBacktestEmitter.next(tick);
12169
12173
  await this.actionCoreService.signalBacktest(true, tick, {
12170
12174
  strategyName,
@@ -12223,6 +12227,9 @@ class BacktestLogicPrivateService {
12223
12227
  timeframes[i].getTime() < backtestResult.closeTimestamp) {
12224
12228
  i++;
12225
12229
  }
12230
+ if (scheduleOpenResult) {
12231
+ yield scheduleOpenResult;
12232
+ }
12226
12233
  yield backtestResult;
12227
12234
  // Check if strategy should stop after signal is closed
12228
12235
  if (await this.strategyCoreService.getStopped(true, symbol, {
@@ -32435,6 +32442,7 @@ class NotificationInstance {
32435
32442
  this._notifications = [];
32436
32443
  /**
32437
32444
  * Processes signal events and creates appropriate notifications.
32445
+ * Sorts signal notifications by createdAt to maintain chronological order.
32438
32446
  */
32439
32447
  this._handleSignal = async (data) => {
32440
32448
  if (data.action === "opened") {
@@ -32513,6 +32521,12 @@ class NotificationInstance {
32513
32521
  createdAt: data.createdAt,
32514
32522
  });
32515
32523
  }
32524
+ // Sort signal notifications by createdAt (newest first)
32525
+ this._notifications.sort((a, b) => {
32526
+ const aCreatedAt = "createdAt" in a ? a.createdAt : 0;
32527
+ const bCreatedAt = "createdAt" in b ? b.createdAt : 0;
32528
+ return bCreatedAt - aCreatedAt;
32529
+ });
32516
32530
  };
32517
32531
  /**
32518
32532
  * Processes partial profit events.
package/build/index.mjs CHANGED
@@ -12133,11 +12133,13 @@ class BacktestLogicPrivateService {
12133
12133
  // и если активируется - продолжит с TP/SL мониторингом
12134
12134
  let backtestResult;
12135
12135
  let unScheduleOpen;
12136
+ let scheduleOpenResult;
12136
12137
  {
12137
12138
  const { strategyName, exchangeName, frameName } = this.methodContextService.context;
12138
12139
  unScheduleOpen = backtestScheduleOpenSubject.filter((event) => {
12139
12140
  let isOk = true;
12140
12141
  {
12142
+ isOk = isOk && event.action === "opened";
12141
12143
  isOk = isOk && event.strategyName === strategyName;
12142
12144
  isOk = isOk && event.exchangeName === exchangeName;
12143
12145
  isOk = isOk && event.frameName === frameName;
@@ -12145,6 +12147,8 @@ class BacktestLogicPrivateService {
12145
12147
  }
12146
12148
  return isOk;
12147
12149
  }).connect(async (tick) => {
12150
+ scheduleOpenResult = tick;
12151
+ await signalEmitter.next(tick);
12148
12152
  await signalBacktestEmitter.next(tick);
12149
12153
  await this.actionCoreService.signalBacktest(true, tick, {
12150
12154
  strategyName,
@@ -12203,6 +12207,9 @@ class BacktestLogicPrivateService {
12203
12207
  timeframes[i].getTime() < backtestResult.closeTimestamp) {
12204
12208
  i++;
12205
12209
  }
12210
+ if (scheduleOpenResult) {
12211
+ yield scheduleOpenResult;
12212
+ }
12206
12213
  yield backtestResult;
12207
12214
  // Check if strategy should stop after signal is closed
12208
12215
  if (await this.strategyCoreService.getStopped(true, symbol, {
@@ -32415,6 +32422,7 @@ class NotificationInstance {
32415
32422
  this._notifications = [];
32416
32423
  /**
32417
32424
  * Processes signal events and creates appropriate notifications.
32425
+ * Sorts signal notifications by createdAt to maintain chronological order.
32418
32426
  */
32419
32427
  this._handleSignal = async (data) => {
32420
32428
  if (data.action === "opened") {
@@ -32493,6 +32501,12 @@ class NotificationInstance {
32493
32501
  createdAt: data.createdAt,
32494
32502
  });
32495
32503
  }
32504
+ // Sort signal notifications by createdAt (newest first)
32505
+ this._notifications.sort((a, b) => {
32506
+ const aCreatedAt = "createdAt" in a ? a.createdAt : 0;
32507
+ const bCreatedAt = "createdAt" in b ? b.createdAt : 0;
32508
+ return bCreatedAt - aCreatedAt;
32509
+ });
32496
32510
  };
32497
32511
  /**
32498
32512
  * Processes partial profit events.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -8899,7 +8899,7 @@ declare class BacktestUtils {
8899
8899
  strategyName: StrategyName;
8900
8900
  exchangeName: ExchangeName;
8901
8901
  frameName: FrameName;
8902
- }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
8902
+ }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyBacktestResult, void, unknown>;
8903
8903
  /**
8904
8904
  * Runs backtest in background without yielding results.
8905
8905
  *
@@ -17451,7 +17451,7 @@ declare class BacktestLogicPrivateService {
17451
17451
  * }
17452
17452
  * ```
17453
17453
  */
17454
- run(symbol: string): AsyncGenerator<IStrategyBacktestResult, void, unknown>;
17454
+ run(symbol: string): AsyncGenerator<IStrategyTickResultOpened | IStrategyBacktestResult, void, unknown>;
17455
17455
  }
17456
17456
 
17457
17457
  /**
@@ -17558,7 +17558,7 @@ declare class BacktestLogicPublicService implements TBacktestLogicPrivateService
17558
17558
  strategyName: StrategyName;
17559
17559
  exchangeName: ExchangeName;
17560
17560
  frameName: FrameName;
17561
- }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
17561
+ }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyBacktestResult, void, unknown>;
17562
17562
  }
17563
17563
 
17564
17564
  /**
@@ -17697,7 +17697,7 @@ declare class BacktestCommandService implements TBacktestLogicPublicService {
17697
17697
  strategyName: StrategyName;
17698
17698
  exchangeName: ExchangeName;
17699
17699
  frameName: FrameName;
17700
- }) => AsyncGenerator<IStrategyBacktestResult, void, unknown>;
17700
+ }) => AsyncGenerator<IStrategyTickResultOpened | IStrategyBacktestResult, void, unknown>;
17701
17701
  }
17702
17702
 
17703
17703
  /**