@backtest-kit/pinets 3.0.5 → 3.0.7

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
@@ -514,7 +514,7 @@ function generateMarkdownTable(rows, keys, signalId) {
514
514
  class PineMarkdownService {
515
515
  constructor() {
516
516
  this.loggerService = inject(TYPES.loggerService);
517
- this.getData = (plots, mapping) => {
517
+ this.getData = (plots, mapping, limit = TABLE_ROWS_LIMIT) => {
518
518
  this.loggerService.log("pineMarkdownService getData", {
519
519
  plotCount: Object.keys(plots).length,
520
520
  });
@@ -543,15 +543,15 @@ class PineMarkdownService {
543
543
  rows.push(row);
544
544
  }
545
545
  }
546
- return rows.slice(-TABLE_ROWS_LIMIT);
546
+ return rows.slice(-limit);
547
547
  };
548
- this.getReport = (signalId, plots, mapping) => {
548
+ this.getReport = (signalId, plots, mapping, limit = TABLE_ROWS_LIMIT) => {
549
549
  this.loggerService.log("pineMarkdownService getReport", {
550
550
  signalId,
551
551
  plotCount: Object.keys(plots).length,
552
552
  });
553
553
  const keys = Object.keys(mapping);
554
- const rows = this.getData(plots, mapping);
554
+ const rows = this.getData(plots, mapping, limit);
555
555
  return generateMarkdownTable(rows, keys, signalId);
556
556
  };
557
557
  this.dump = async (signalId, plots, mapping, taName, outputDir = `./dump/ta/${taName}`) => {
@@ -658,6 +658,11 @@ const GET_SOURCE_FN$1 = async (source) => {
658
658
  throw new Error("Source must be a File or Code instance");
659
659
  };
660
660
  const BASE_RUNNER_FN = async (script, symbol, timeframe, limit) => await pine.pineJobService.run(script, symbol, timeframe, limit);
661
+ const VALIDATE_NO_TRADING_FN = async () => {
662
+ if (backtestKit.ExecutionContextService.hasContext()) {
663
+ throw new Error(functoolsKit.str.newline("Time overrides are not allowed when running scripts in a trading context.", "Please remove the 'when' parameter from the run function call."));
664
+ }
665
+ };
661
666
  const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, when) => {
662
667
  let fn = () => BASE_RUNNER_FN(script, symbol, timeframe, limit);
663
668
  if (exchangeName) {
@@ -673,6 +678,9 @@ const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, whe
673
678
  return fn;
674
679
  };
675
680
  const RUN_INFERENCE_FN = async (script, symbol, timeframe, limit, exchangeName, when) => {
681
+ if (when) {
682
+ VALIDATE_NO_TRADING_FN();
683
+ }
676
684
  const inference = CREATE_INFERENCE_FN(script, symbol, timeframe, limit, exchangeName, when);
677
685
  return await inference();
678
686
  };
@@ -777,13 +785,14 @@ async function dumpPlotData(signalId, plots, mapping, taName, outputDir = "./dum
777
785
  }
778
786
 
779
787
  const TO_MARKDOWN_METHOD_NAME = "markdown.toMarkdown";
780
- async function toMarkdown(signalId, plots, mapping) {
788
+ async function toMarkdown(signalId, plots, mapping, limit = Number.POSITIVE_INFINITY) {
781
789
  pine.loggerService.log(TO_MARKDOWN_METHOD_NAME, {
782
790
  signalId,
783
791
  plotCount: Object.keys(plots).length,
784
792
  mapping,
793
+ limit,
785
794
  });
786
- return await pine.pineMarkdownService.getReport(signalId, plots, mapping);
795
+ return await pine.pineMarkdownService.getReport(signalId, plots, mapping, limit);
787
796
  }
788
797
 
789
798
  exports.AXIS_SYMBOL = AXIS_SYMBOL;
package/build/index.mjs CHANGED
@@ -2,7 +2,7 @@ import { join } from 'path';
2
2
  import { getDate, Exchange, MethodContextService, ExecutionContextService, getRawCandles, Markdown, lib } from 'backtest-kit';
3
3
  import { createActivator } from 'di-kit';
4
4
  import { scoped } from 'di-scoped';
5
- import { singleshot, memoize, randomString } from 'functools-kit';
5
+ import { singleshot, memoize, str, randomString } from 'functools-kit';
6
6
  import fs from 'fs/promises';
7
7
  import { createRequire } from 'module';
8
8
 
@@ -511,7 +511,7 @@ function generateMarkdownTable(rows, keys, signalId) {
511
511
  class PineMarkdownService {
512
512
  constructor() {
513
513
  this.loggerService = inject(TYPES.loggerService);
514
- this.getData = (plots, mapping) => {
514
+ this.getData = (plots, mapping, limit = TABLE_ROWS_LIMIT) => {
515
515
  this.loggerService.log("pineMarkdownService getData", {
516
516
  plotCount: Object.keys(plots).length,
517
517
  });
@@ -540,15 +540,15 @@ class PineMarkdownService {
540
540
  rows.push(row);
541
541
  }
542
542
  }
543
- return rows.slice(-TABLE_ROWS_LIMIT);
543
+ return rows.slice(-limit);
544
544
  };
545
- this.getReport = (signalId, plots, mapping) => {
545
+ this.getReport = (signalId, plots, mapping, limit = TABLE_ROWS_LIMIT) => {
546
546
  this.loggerService.log("pineMarkdownService getReport", {
547
547
  signalId,
548
548
  plotCount: Object.keys(plots).length,
549
549
  });
550
550
  const keys = Object.keys(mapping);
551
- const rows = this.getData(plots, mapping);
551
+ const rows = this.getData(plots, mapping, limit);
552
552
  return generateMarkdownTable(rows, keys, signalId);
553
553
  };
554
554
  this.dump = async (signalId, plots, mapping, taName, outputDir = `./dump/ta/${taName}`) => {
@@ -655,6 +655,11 @@ const GET_SOURCE_FN$1 = async (source) => {
655
655
  throw new Error("Source must be a File or Code instance");
656
656
  };
657
657
  const BASE_RUNNER_FN = async (script, symbol, timeframe, limit) => await pine.pineJobService.run(script, symbol, timeframe, limit);
658
+ const VALIDATE_NO_TRADING_FN = async () => {
659
+ if (ExecutionContextService.hasContext()) {
660
+ throw new Error(str.newline("Time overrides are not allowed when running scripts in a trading context.", "Please remove the 'when' parameter from the run function call."));
661
+ }
662
+ };
658
663
  const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, when) => {
659
664
  let fn = () => BASE_RUNNER_FN(script, symbol, timeframe, limit);
660
665
  if (exchangeName) {
@@ -670,6 +675,9 @@ const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, whe
670
675
  return fn;
671
676
  };
672
677
  const RUN_INFERENCE_FN = async (script, symbol, timeframe, limit, exchangeName, when) => {
678
+ if (when) {
679
+ VALIDATE_NO_TRADING_FN();
680
+ }
673
681
  const inference = CREATE_INFERENCE_FN(script, symbol, timeframe, limit, exchangeName, when);
674
682
  return await inference();
675
683
  };
@@ -774,13 +782,14 @@ async function dumpPlotData(signalId, plots, mapping, taName, outputDir = "./dum
774
782
  }
775
783
 
776
784
  const TO_MARKDOWN_METHOD_NAME = "markdown.toMarkdown";
777
- async function toMarkdown(signalId, plots, mapping) {
785
+ async function toMarkdown(signalId, plots, mapping, limit = Number.POSITIVE_INFINITY) {
778
786
  pine.loggerService.log(TO_MARKDOWN_METHOD_NAME, {
779
787
  signalId,
780
788
  plotCount: Object.keys(plots).length,
781
789
  mapping,
790
+ limit,
782
791
  });
783
- return await pine.pineMarkdownService.getReport(signalId, plots, mapping);
792
+ return await pine.pineMarkdownService.getReport(signalId, plots, mapping, limit);
784
793
  }
785
794
 
786
795
  export { AXIS_SYMBOL, Code, File, dumpPlotData, extract, getSignal, pine as lib, run, setLogger, toMarkdown, toSignalDto, usePine };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backtest-kit/pinets",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Run TradingView Pine Script strategies in Node.js self hosted environment. Execute existing Pine Script indicators and generate trading signals with 1:1 syntax compatibility via PineTS runtime.",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -92,7 +92,7 @@ type ResultId$3 = string | number;
92
92
  declare function dumpPlotData<M extends PlotMapping>(signalId: ResultId$3, plots: PlotModel, mapping: M, taName: string, outputDir?: string): Promise<void>;
93
93
 
94
94
  type ResultId$2 = string | number;
95
- declare function toMarkdown<M extends PlotMapping>(signalId: ResultId$2, plots: PlotModel, mapping: M): Promise<string>;
95
+ declare function toMarkdown<M extends PlotMapping>(signalId: ResultId$2, plots: PlotModel, mapping: M, limit?: number): Promise<string>;
96
96
 
97
97
  type ResultId$1 = string | number;
98
98
  interface SignalData {
@@ -180,8 +180,8 @@ interface IPlotRow {
180
180
  }
181
181
  declare class PineMarkdownService {
182
182
  private readonly loggerService;
183
- getData: <M extends PlotMapping>(plots: PlotModel, mapping: M) => IPlotRow[];
184
- getReport: <M extends PlotMapping>(signalId: ResultId, plots: PlotModel, mapping: M) => string;
183
+ getData: <M extends PlotMapping>(plots: PlotModel, mapping: M, limit?: number) => IPlotRow[];
184
+ getReport: <M extends PlotMapping>(signalId: ResultId, plots: PlotModel, mapping: M, limit?: number) => string;
185
185
  dump: <M extends PlotMapping>(signalId: ResultId, plots: PlotModel, mapping: M, taName: string, outputDir?: string) => Promise<void>;
186
186
  }
187
187