backtest-kit 7.0.0 → 7.0.1

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 CHANGED
@@ -46,7 +46,7 @@ Sidekick generates a project where the exchange adapter, frame definitions, risk
46
46
 
47
47
  ### 📦 Manual Installation
48
48
 
49
- > **Want to see the code?** 👉 [Demo app](https://github.com/tripolskypetr/backtest-kit/tree/master/demo) 👈
49
+ > **Want to see the code?** 👉 [Demo app](https://github.com/tripolskypetr/backtest-kit/tree/master/example) 👈
50
50
 
51
51
  ```bash
52
52
  npm install backtest-kit ccxt ollama uuid
package/build/index.cjs CHANGED
@@ -46705,17 +46705,31 @@ class RecentAdapter {
46705
46705
  * @returns Whole minutes since the latest signal was created, or null if no signal found
46706
46706
  * @throws Error if RecentAdapter is not enabled
46707
46707
  */
46708
- this.getMinutesSinceLatestSignalCreated = async (timestamp, symbol, context) => {
46708
+ this.getMinutesSinceLatestSignalCreated = async (symbol, context) => {
46709
46709
  backtest.loggerService.info(RECENT_ADAPTER_METHOD_NAME_GET_MINUTES_SINCE_LATEST_SIGNAL, {
46710
46710
  symbol,
46711
46711
  context,
46712
- timestamp,
46713
46712
  });
46714
- const signal = await this.getLatestSignal(symbol, context);
46715
- if (!signal) {
46716
- return null;
46713
+ if (!this.enable.hasValue()) {
46714
+ throw new Error("RecentAdapter is not enabled. Call enable() first.");
46717
46715
  }
46718
- return Math.floor((timestamp - signal.timestamp) / (1000 * 60));
46716
+ if (await RecentBacktest.getLatestSignal(symbol, context.strategyName, context.exchangeName, context.frameName, true)) {
46717
+ const timestamp = await backtest.timeMetaService.getTimestamp(symbol, context, true);
46718
+ const signal = await this.getLatestSignal(symbol, context);
46719
+ if (!signal) {
46720
+ return null;
46721
+ }
46722
+ return Math.floor((timestamp - signal.timestamp) / (1000 * 60));
46723
+ }
46724
+ if (await RecentLive.getLatestSignal(symbol, context.strategyName, context.exchangeName, context.frameName, false)) {
46725
+ const timestamp = await backtest.timeMetaService.getTimestamp(symbol, context, false);
46726
+ const signal = await this.getLatestSignal(symbol, context);
46727
+ if (!signal) {
46728
+ return null;
46729
+ }
46730
+ return Math.floor((timestamp - signal.timestamp) / (1000 * 60));
46731
+ }
46732
+ return null;
46719
46733
  };
46720
46734
  }
46721
46735
  }
@@ -46808,8 +46822,7 @@ async function getMinutesSinceLatestSignalCreated(symbol) {
46808
46822
  throw new Error("getMinutesSinceLatestSignalCreated requires a method context");
46809
46823
  }
46810
46824
  const { exchangeName, frameName, strategyName } = backtest.methodContextService.context;
46811
- const { when } = backtest.executionContextService.context;
46812
- return await Recent.getMinutesSinceLatestSignalCreated(when.getTime(), symbol, { exchangeName, frameName, strategyName });
46825
+ return await Recent.getMinutesSinceLatestSignalCreated(symbol, { exchangeName, frameName, strategyName });
46813
46826
  }
46814
46827
 
46815
46828
  const DEFAULT_BM25_K1 = 1.5;
package/build/index.mjs CHANGED
@@ -46685,17 +46685,31 @@ class RecentAdapter {
46685
46685
  * @returns Whole minutes since the latest signal was created, or null if no signal found
46686
46686
  * @throws Error if RecentAdapter is not enabled
46687
46687
  */
46688
- this.getMinutesSinceLatestSignalCreated = async (timestamp, symbol, context) => {
46688
+ this.getMinutesSinceLatestSignalCreated = async (symbol, context) => {
46689
46689
  backtest.loggerService.info(RECENT_ADAPTER_METHOD_NAME_GET_MINUTES_SINCE_LATEST_SIGNAL, {
46690
46690
  symbol,
46691
46691
  context,
46692
- timestamp,
46693
46692
  });
46694
- const signal = await this.getLatestSignal(symbol, context);
46695
- if (!signal) {
46696
- return null;
46693
+ if (!this.enable.hasValue()) {
46694
+ throw new Error("RecentAdapter is not enabled. Call enable() first.");
46697
46695
  }
46698
- return Math.floor((timestamp - signal.timestamp) / (1000 * 60));
46696
+ if (await RecentBacktest.getLatestSignal(symbol, context.strategyName, context.exchangeName, context.frameName, true)) {
46697
+ const timestamp = await backtest.timeMetaService.getTimestamp(symbol, context, true);
46698
+ const signal = await this.getLatestSignal(symbol, context);
46699
+ if (!signal) {
46700
+ return null;
46701
+ }
46702
+ return Math.floor((timestamp - signal.timestamp) / (1000 * 60));
46703
+ }
46704
+ if (await RecentLive.getLatestSignal(symbol, context.strategyName, context.exchangeName, context.frameName, false)) {
46705
+ const timestamp = await backtest.timeMetaService.getTimestamp(symbol, context, false);
46706
+ const signal = await this.getLatestSignal(symbol, context);
46707
+ if (!signal) {
46708
+ return null;
46709
+ }
46710
+ return Math.floor((timestamp - signal.timestamp) / (1000 * 60));
46711
+ }
46712
+ return null;
46699
46713
  };
46700
46714
  }
46701
46715
  }
@@ -46788,8 +46802,7 @@ async function getMinutesSinceLatestSignalCreated(symbol) {
46788
46802
  throw new Error("getMinutesSinceLatestSignalCreated requires a method context");
46789
46803
  }
46790
46804
  const { exchangeName, frameName, strategyName } = backtest.methodContextService.context;
46791
- const { when } = backtest.executionContextService.context;
46792
- return await Recent.getMinutesSinceLatestSignalCreated(when.getTime(), symbol, { exchangeName, frameName, strategyName });
46805
+ return await Recent.getMinutesSinceLatestSignalCreated(symbol, { exchangeName, frameName, strategyName });
46793
46806
  }
46794
46807
 
46795
46808
  const DEFAULT_BM25_K1 = 1.5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backtest-kit",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "A TypeScript library for trading system backtest",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -20976,7 +20976,7 @@ declare class RecentAdapter {
20976
20976
  * @returns Whole minutes since the latest signal was created, or null if no signal found
20977
20977
  * @throws Error if RecentAdapter is not enabled
20978
20978
  */
20979
- getMinutesSinceLatestSignalCreated: (timestamp: number, symbol: string, context: {
20979
+ getMinutesSinceLatestSignalCreated: (symbol: string, context: {
20980
20980
  strategyName: StrategyName;
20981
20981
  exchangeName: ExchangeName;
20982
20982
  frameName: FrameName;