@backtest-kit/pinets 0.0.4 → 0.0.6

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
@@ -501,7 +501,7 @@ function extractRowAtIndex(plots, keys, index) {
501
501
  }
502
502
  function isRowWarmedUp(row, keys) {
503
503
  for (const key of keys) {
504
- if (!row[key]) {
504
+ if (isUnsafe(row[key])) {
505
505
  return false;
506
506
  }
507
507
  }
@@ -690,6 +690,30 @@ function setLogger(logger) {
690
690
  pine.loggerService.setLogger(logger);
691
691
  }
692
692
 
693
+ function toSignalDto(id, data) {
694
+ if (data.position === 1) {
695
+ return {
696
+ id: String(id),
697
+ position: "long",
698
+ priceOpen: data.priceOpen,
699
+ priceTakeProfit: data.priceTakeProfit,
700
+ priceStopLoss: data.priceStopLoss,
701
+ minuteEstimatedTime: data.minuteEstimatedTime,
702
+ };
703
+ }
704
+ if (data.position === -1) {
705
+ return {
706
+ id: String(id),
707
+ position: "short",
708
+ priceOpen: data.priceOpen,
709
+ priceTakeProfit: data.priceTakeProfit,
710
+ priceStopLoss: data.priceStopLoss,
711
+ minuteEstimatedTime: data.minuteEstimatedTime,
712
+ };
713
+ }
714
+ return null;
715
+ }
716
+
693
717
  const METHOD_NAME_RUN = "strategy.getSignal";
694
718
  const DEFAULT_ESTIMATED_TIME = 240;
695
719
  const GET_SOURCE_FN = async (source) => {
@@ -712,29 +736,6 @@ const SIGNAL_SCHEMA = {
712
736
  transform: (v) => v || DEFAULT_ESTIMATED_TIME,
713
737
  },
714
738
  };
715
- function toSignalDto(data) {
716
- if (data.position === 1) {
717
- return {
718
- id: functoolsKit.randomString(),
719
- position: "long",
720
- priceOpen: data.priceOpen,
721
- priceTakeProfit: data.priceTakeProfit,
722
- priceStopLoss: data.priceStopLoss,
723
- minuteEstimatedTime: data.minuteEstimatedTime,
724
- };
725
- }
726
- if (data.position === -1) {
727
- return {
728
- id: functoolsKit.randomString(),
729
- position: "short",
730
- priceOpen: data.priceOpen,
731
- priceTakeProfit: data.priceTakeProfit,
732
- priceStopLoss: data.priceStopLoss,
733
- minuteEstimatedTime: data.minuteEstimatedTime,
734
- };
735
- }
736
- return null;
737
- }
738
739
  async function getSignal(source, { symbol, timeframe, limit }) {
739
740
  pine.loggerService.info(METHOD_NAME_RUN, {
740
741
  source,
@@ -743,8 +744,9 @@ async function getSignal(source, { symbol, timeframe, limit }) {
743
744
  limit,
744
745
  });
745
746
  const { plots } = await pine.pineJobService.run(await GET_SOURCE_FN(source), symbol, timeframe, limit);
747
+ const resultId = functoolsKit.randomString();
746
748
  const data = pine.pineDataService.extract(plots, SIGNAL_SCHEMA);
747
- return toSignalDto(data);
749
+ return toSignalDto(resultId, data);
748
750
  }
749
751
 
750
752
  const DUMP_SIGNAL_METHOD_NAME = "dump.dumpSignal";
@@ -766,4 +768,5 @@ exports.getSignal = getSignal;
766
768
  exports.lib = pine;
767
769
  exports.run = run;
768
770
  exports.setLogger = setLogger;
771
+ exports.toSignalDto = toSignalDto;
769
772
  exports.usePine = usePine;
package/build/index.mjs CHANGED
@@ -498,7 +498,7 @@ function extractRowAtIndex(plots, keys, index) {
498
498
  }
499
499
  function isRowWarmedUp(row, keys) {
500
500
  for (const key of keys) {
501
- if (!row[key]) {
501
+ if (isUnsafe(row[key])) {
502
502
  return false;
503
503
  }
504
504
  }
@@ -687,6 +687,30 @@ function setLogger(logger) {
687
687
  pine.loggerService.setLogger(logger);
688
688
  }
689
689
 
690
+ function toSignalDto(id, data) {
691
+ if (data.position === 1) {
692
+ return {
693
+ id: String(id),
694
+ position: "long",
695
+ priceOpen: data.priceOpen,
696
+ priceTakeProfit: data.priceTakeProfit,
697
+ priceStopLoss: data.priceStopLoss,
698
+ minuteEstimatedTime: data.minuteEstimatedTime,
699
+ };
700
+ }
701
+ if (data.position === -1) {
702
+ return {
703
+ id: String(id),
704
+ position: "short",
705
+ priceOpen: data.priceOpen,
706
+ priceTakeProfit: data.priceTakeProfit,
707
+ priceStopLoss: data.priceStopLoss,
708
+ minuteEstimatedTime: data.minuteEstimatedTime,
709
+ };
710
+ }
711
+ return null;
712
+ }
713
+
690
714
  const METHOD_NAME_RUN = "strategy.getSignal";
691
715
  const DEFAULT_ESTIMATED_TIME = 240;
692
716
  const GET_SOURCE_FN = async (source) => {
@@ -709,29 +733,6 @@ const SIGNAL_SCHEMA = {
709
733
  transform: (v) => v || DEFAULT_ESTIMATED_TIME,
710
734
  },
711
735
  };
712
- function toSignalDto(data) {
713
- if (data.position === 1) {
714
- return {
715
- id: randomString(),
716
- position: "long",
717
- priceOpen: data.priceOpen,
718
- priceTakeProfit: data.priceTakeProfit,
719
- priceStopLoss: data.priceStopLoss,
720
- minuteEstimatedTime: data.minuteEstimatedTime,
721
- };
722
- }
723
- if (data.position === -1) {
724
- return {
725
- id: randomString(),
726
- position: "short",
727
- priceOpen: data.priceOpen,
728
- priceTakeProfit: data.priceTakeProfit,
729
- priceStopLoss: data.priceStopLoss,
730
- minuteEstimatedTime: data.minuteEstimatedTime,
731
- };
732
- }
733
- return null;
734
- }
735
736
  async function getSignal(source, { symbol, timeframe, limit }) {
736
737
  pine.loggerService.info(METHOD_NAME_RUN, {
737
738
  source,
@@ -740,8 +741,9 @@ async function getSignal(source, { symbol, timeframe, limit }) {
740
741
  limit,
741
742
  });
742
743
  const { plots } = await pine.pineJobService.run(await GET_SOURCE_FN(source), symbol, timeframe, limit);
744
+ const resultId = randomString();
743
745
  const data = pine.pineDataService.extract(plots, SIGNAL_SCHEMA);
744
- return toSignalDto(data);
746
+ return toSignalDto(resultId, data);
745
747
  }
746
748
 
747
749
  const DUMP_SIGNAL_METHOD_NAME = "dump.dumpSignal";
@@ -754,4 +756,4 @@ async function dumpPlotData(signalId, plots, taName, outputDir = "./dump/ta") {
754
756
  return await pine.pineMarkdownService.dump(signalId, plots, taName, outputDir);
755
757
  }
756
758
 
757
- export { AXIS_SYMBOL, Code, File, dumpPlotData, extract, getSignal, pine as lib, run, setLogger, usePine };
759
+ export { AXIS_SYMBOL, Code, File, dumpPlotData, extract, getSignal, pine as lib, run, setLogger, toSignalDto, usePine };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backtest-kit/pinets",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
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
@@ -83,8 +83,21 @@ interface IParams {
83
83
  }
84
84
  declare function getSignal(source: File | Code, { symbol, timeframe, limit }: IParams): Promise<ISignalDto | null>;
85
85
 
86
+ type ResultId$2 = string | number;
87
+ declare function dumpPlotData(signalId: ResultId$2, plots: PlotModel, taName: string, outputDir?: string): Promise<void>;
88
+
86
89
  type ResultId$1 = string | number;
87
- declare function dumpPlotData(signalId: ResultId$1, plots: PlotModel, taName: string, outputDir?: string): Promise<void>;
90
+ interface SignalData {
91
+ position: number;
92
+ priceOpen: number;
93
+ priceTakeProfit: number;
94
+ priceStopLoss: number;
95
+ minuteEstimatedTime: number;
96
+ }
97
+ interface Signal extends ISignalDto {
98
+ id: string;
99
+ }
100
+ declare function toSignalDto(id: ResultId$1, data: SignalData): Signal | null;
88
101
 
89
102
  interface CandleModel {
90
103
  openTime: number;
@@ -172,4 +185,4 @@ declare const pine: {
172
185
  loggerService: LoggerService;
173
186
  };
174
187
 
175
- export { AXIS_SYMBOL, type CandleModel, Code, File, type ILogger, type IPine, type IProvider, type PlotExtractConfig, type PlotMapping, type PlotModel, type PlotRecord, type SymbolInfoModel, type TPineCtor, dumpPlotData, extract, getSignal, pine as lib, run, setLogger, usePine };
188
+ export { AXIS_SYMBOL, type CandleModel, Code, File, type ILogger, type IPine, type IProvider, type PlotExtractConfig, type PlotMapping, type PlotModel, type PlotRecord, type SymbolInfoModel, type TPineCtor, dumpPlotData, extract, getSignal, pine as lib, run, setLogger, toSignalDto, usePine };