@backtest-kit/pinets 3.0.11 → 3.0.13
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 +62 -12
- package/build/index.mjs +62 -13
- package/package.json +2 -2
- package/types.d.ts +9 -3
package/build/index.cjs
CHANGED
|
@@ -647,7 +647,7 @@ function usePine(ctor) {
|
|
|
647
647
|
}
|
|
648
648
|
|
|
649
649
|
const METHOD_NAME_RUN$2 = "run.run";
|
|
650
|
-
const GET_SOURCE_FN$
|
|
650
|
+
const GET_SOURCE_FN$2 = async (source) => {
|
|
651
651
|
if (File.isFile(source)) {
|
|
652
652
|
const code = await pine.pineCacheService.readFile(source.path, source.baseDir);
|
|
653
653
|
return Code.fromString(code);
|
|
@@ -657,14 +657,14 @@ const GET_SOURCE_FN$1 = async (source) => {
|
|
|
657
657
|
}
|
|
658
658
|
throw new Error("Source must be a File or Code instance");
|
|
659
659
|
};
|
|
660
|
-
const BASE_RUNNER_FN = async (script, symbol, timeframe, limit) => await pine.pineJobService.run(script, symbol, timeframe, limit);
|
|
661
|
-
const VALIDATE_NO_TRADING_FN =
|
|
660
|
+
const BASE_RUNNER_FN$1 = async (script, symbol, timeframe, limit) => await pine.pineJobService.run(script, symbol, timeframe, limit);
|
|
661
|
+
const VALIDATE_NO_TRADING_FN$1 = () => {
|
|
662
662
|
if (backtestKit.ExecutionContextService.hasContext()) {
|
|
663
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
664
|
}
|
|
665
665
|
};
|
|
666
|
-
const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
667
|
-
let fn = () => BASE_RUNNER_FN(script, symbol, timeframe, limit);
|
|
666
|
+
const CREATE_INFERENCE_FN$1 = (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
667
|
+
let fn = () => BASE_RUNNER_FN$1(script, symbol, timeframe, limit);
|
|
668
668
|
if (exchangeName) {
|
|
669
669
|
fn = ExchangeContextService.runWithContext(fn, { exchangeName });
|
|
670
670
|
}
|
|
@@ -677,11 +677,11 @@ const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, whe
|
|
|
677
677
|
}
|
|
678
678
|
return fn;
|
|
679
679
|
};
|
|
680
|
-
const RUN_INFERENCE_FN = async (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
680
|
+
const RUN_INFERENCE_FN$1 = async (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
681
681
|
if (when) {
|
|
682
|
-
VALIDATE_NO_TRADING_FN();
|
|
682
|
+
VALIDATE_NO_TRADING_FN$1();
|
|
683
683
|
}
|
|
684
|
-
const inference = CREATE_INFERENCE_FN(script, symbol, timeframe, limit, exchangeName, when);
|
|
684
|
+
const inference = CREATE_INFERENCE_FN$1(script, symbol, timeframe, limit, exchangeName, when);
|
|
685
685
|
return await inference();
|
|
686
686
|
};
|
|
687
687
|
async function run(source, { symbol, timeframe, limit }, exchangeName, when) {
|
|
@@ -691,8 +691,8 @@ async function run(source, { symbol, timeframe, limit }, exchangeName, when) {
|
|
|
691
691
|
timeframe,
|
|
692
692
|
limit,
|
|
693
693
|
});
|
|
694
|
-
const script = await GET_SOURCE_FN$
|
|
695
|
-
const { plots } = await RUN_INFERENCE_FN(script, symbol, timeframe, limit, exchangeName, when);
|
|
694
|
+
const script = await GET_SOURCE_FN$2(source);
|
|
695
|
+
const { plots } = await RUN_INFERENCE_FN$1(script, symbol, timeframe, limit, exchangeName, when);
|
|
696
696
|
return plots;
|
|
697
697
|
}
|
|
698
698
|
|
|
@@ -740,7 +740,7 @@ function toSignalDto(id, data, priceOpen = data.priceOpen) {
|
|
|
740
740
|
|
|
741
741
|
const METHOD_NAME_RUN = "strategy.getSignal";
|
|
742
742
|
const DEFAULT_ESTIMATED_TIME = 240;
|
|
743
|
-
const GET_SOURCE_FN = async (source) => {
|
|
743
|
+
const GET_SOURCE_FN$1 = async (source) => {
|
|
744
744
|
if (File.isFile(source)) {
|
|
745
745
|
const code = await pine.pineCacheService.readFile(source.path, source.baseDir);
|
|
746
746
|
return Code.fromString(code);
|
|
@@ -767,7 +767,7 @@ async function getSignal(source, { symbol, timeframe, limit }) {
|
|
|
767
767
|
timeframe,
|
|
768
768
|
limit,
|
|
769
769
|
});
|
|
770
|
-
const { plots } = await pine.pineJobService.run(await GET_SOURCE_FN(source), symbol, timeframe, limit);
|
|
770
|
+
const { plots } = await pine.pineJobService.run(await GET_SOURCE_FN$1(source), symbol, timeframe, limit);
|
|
771
771
|
const resultId = functoolsKit.randomString();
|
|
772
772
|
const data = pine.pineDataService.extract(plots, SIGNAL_SCHEMA);
|
|
773
773
|
return toSignalDto(resultId, data);
|
|
@@ -785,6 +785,44 @@ async function dumpPlotData(signalId, plots, mapping, taName, outputDir = `./dum
|
|
|
785
785
|
}
|
|
786
786
|
|
|
787
787
|
const TO_MARKDOWN_METHOD_NAME = "markdown.toMarkdown";
|
|
788
|
+
const MARKDOWN_METHOD_NAME = "markdown.markdown";
|
|
789
|
+
const GET_SOURCE_FN = async (source) => {
|
|
790
|
+
if (File.isFile(source)) {
|
|
791
|
+
const code = await pine.pineCacheService.readFile(source.path, source.baseDir);
|
|
792
|
+
return Code.fromString(code);
|
|
793
|
+
}
|
|
794
|
+
if (Code.isCode(source)) {
|
|
795
|
+
return source;
|
|
796
|
+
}
|
|
797
|
+
throw new Error("Source must be a File or Code instance");
|
|
798
|
+
};
|
|
799
|
+
const BASE_RUNNER_FN = async (script, symbol, timeframe, limit) => await pine.pineJobService.run(script, symbol, timeframe, limit);
|
|
800
|
+
const VALIDATE_NO_TRADING_FN = () => {
|
|
801
|
+
if (backtestKit.ExecutionContextService.hasContext()) {
|
|
802
|
+
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."));
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
806
|
+
let fn = () => BASE_RUNNER_FN(script, symbol, timeframe, limit);
|
|
807
|
+
if (exchangeName) {
|
|
808
|
+
fn = ExchangeContextService.runWithContext(fn, { exchangeName });
|
|
809
|
+
}
|
|
810
|
+
if (when) {
|
|
811
|
+
fn = backtestKit.ExecutionContextService.runWithContext(fn, {
|
|
812
|
+
when,
|
|
813
|
+
symbol,
|
|
814
|
+
backtest: true,
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
return fn;
|
|
818
|
+
};
|
|
819
|
+
const RUN_INFERENCE_FN = async (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
820
|
+
if (when) {
|
|
821
|
+
VALIDATE_NO_TRADING_FN();
|
|
822
|
+
}
|
|
823
|
+
const inference = CREATE_INFERENCE_FN(script, symbol, timeframe, limit, exchangeName, when);
|
|
824
|
+
return await inference();
|
|
825
|
+
};
|
|
788
826
|
async function toMarkdown(signalId, plots, mapping, limit = Number.POSITIVE_INFINITY) {
|
|
789
827
|
pine.loggerService.log(TO_MARKDOWN_METHOD_NAME, {
|
|
790
828
|
signalId,
|
|
@@ -794,6 +832,17 @@ async function toMarkdown(signalId, plots, mapping, limit = Number.POSITIVE_INFI
|
|
|
794
832
|
});
|
|
795
833
|
return await pine.pineMarkdownService.getReport(signalId, plots, mapping, limit);
|
|
796
834
|
}
|
|
835
|
+
async function markdown(signalId, source, { symbol, timeframe, limit }, mapping, exchangeName, when) {
|
|
836
|
+
pine.loggerService.log(MARKDOWN_METHOD_NAME, {
|
|
837
|
+
signalId,
|
|
838
|
+
mapping,
|
|
839
|
+
limit,
|
|
840
|
+
exchangeName,
|
|
841
|
+
when,
|
|
842
|
+
});
|
|
843
|
+
const { plots } = await RUN_INFERENCE_FN(await GET_SOURCE_FN(source), symbol, timeframe, limit, exchangeName, when);
|
|
844
|
+
return await pine.pineMarkdownService.getReport(signalId, plots, mapping, Number.POSITIVE_INFINITY);
|
|
845
|
+
}
|
|
797
846
|
|
|
798
847
|
exports.AXIS_SYMBOL = AXIS_SYMBOL;
|
|
799
848
|
exports.Code = Code;
|
|
@@ -802,6 +851,7 @@ exports.dumpPlotData = dumpPlotData;
|
|
|
802
851
|
exports.extract = extract;
|
|
803
852
|
exports.getSignal = getSignal;
|
|
804
853
|
exports.lib = pine;
|
|
854
|
+
exports.markdown = markdown;
|
|
805
855
|
exports.run = run;
|
|
806
856
|
exports.setLogger = setLogger;
|
|
807
857
|
exports.toMarkdown = toMarkdown;
|
package/build/index.mjs
CHANGED
|
@@ -644,7 +644,7 @@ function usePine(ctor) {
|
|
|
644
644
|
}
|
|
645
645
|
|
|
646
646
|
const METHOD_NAME_RUN$2 = "run.run";
|
|
647
|
-
const GET_SOURCE_FN$
|
|
647
|
+
const GET_SOURCE_FN$2 = async (source) => {
|
|
648
648
|
if (File.isFile(source)) {
|
|
649
649
|
const code = await pine.pineCacheService.readFile(source.path, source.baseDir);
|
|
650
650
|
return Code.fromString(code);
|
|
@@ -654,14 +654,14 @@ const GET_SOURCE_FN$1 = async (source) => {
|
|
|
654
654
|
}
|
|
655
655
|
throw new Error("Source must be a File or Code instance");
|
|
656
656
|
};
|
|
657
|
-
const BASE_RUNNER_FN = async (script, symbol, timeframe, limit) => await pine.pineJobService.run(script, symbol, timeframe, limit);
|
|
658
|
-
const VALIDATE_NO_TRADING_FN =
|
|
657
|
+
const BASE_RUNNER_FN$1 = async (script, symbol, timeframe, limit) => await pine.pineJobService.run(script, symbol, timeframe, limit);
|
|
658
|
+
const VALIDATE_NO_TRADING_FN$1 = () => {
|
|
659
659
|
if (ExecutionContextService.hasContext()) {
|
|
660
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
661
|
}
|
|
662
662
|
};
|
|
663
|
-
const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
664
|
-
let fn = () => BASE_RUNNER_FN(script, symbol, timeframe, limit);
|
|
663
|
+
const CREATE_INFERENCE_FN$1 = (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
664
|
+
let fn = () => BASE_RUNNER_FN$1(script, symbol, timeframe, limit);
|
|
665
665
|
if (exchangeName) {
|
|
666
666
|
fn = ExchangeContextService.runWithContext(fn, { exchangeName });
|
|
667
667
|
}
|
|
@@ -674,11 +674,11 @@ const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, whe
|
|
|
674
674
|
}
|
|
675
675
|
return fn;
|
|
676
676
|
};
|
|
677
|
-
const RUN_INFERENCE_FN = async (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
677
|
+
const RUN_INFERENCE_FN$1 = async (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
678
678
|
if (when) {
|
|
679
|
-
VALIDATE_NO_TRADING_FN();
|
|
679
|
+
VALIDATE_NO_TRADING_FN$1();
|
|
680
680
|
}
|
|
681
|
-
const inference = CREATE_INFERENCE_FN(script, symbol, timeframe, limit, exchangeName, when);
|
|
681
|
+
const inference = CREATE_INFERENCE_FN$1(script, symbol, timeframe, limit, exchangeName, when);
|
|
682
682
|
return await inference();
|
|
683
683
|
};
|
|
684
684
|
async function run(source, { symbol, timeframe, limit }, exchangeName, when) {
|
|
@@ -688,8 +688,8 @@ async function run(source, { symbol, timeframe, limit }, exchangeName, when) {
|
|
|
688
688
|
timeframe,
|
|
689
689
|
limit,
|
|
690
690
|
});
|
|
691
|
-
const script = await GET_SOURCE_FN$
|
|
692
|
-
const { plots } = await RUN_INFERENCE_FN(script, symbol, timeframe, limit, exchangeName, when);
|
|
691
|
+
const script = await GET_SOURCE_FN$2(source);
|
|
692
|
+
const { plots } = await RUN_INFERENCE_FN$1(script, symbol, timeframe, limit, exchangeName, when);
|
|
693
693
|
return plots;
|
|
694
694
|
}
|
|
695
695
|
|
|
@@ -737,7 +737,7 @@ function toSignalDto(id, data, priceOpen = data.priceOpen) {
|
|
|
737
737
|
|
|
738
738
|
const METHOD_NAME_RUN = "strategy.getSignal";
|
|
739
739
|
const DEFAULT_ESTIMATED_TIME = 240;
|
|
740
|
-
const GET_SOURCE_FN = async (source) => {
|
|
740
|
+
const GET_SOURCE_FN$1 = async (source) => {
|
|
741
741
|
if (File.isFile(source)) {
|
|
742
742
|
const code = await pine.pineCacheService.readFile(source.path, source.baseDir);
|
|
743
743
|
return Code.fromString(code);
|
|
@@ -764,7 +764,7 @@ async function getSignal(source, { symbol, timeframe, limit }) {
|
|
|
764
764
|
timeframe,
|
|
765
765
|
limit,
|
|
766
766
|
});
|
|
767
|
-
const { plots } = await pine.pineJobService.run(await GET_SOURCE_FN(source), symbol, timeframe, limit);
|
|
767
|
+
const { plots } = await pine.pineJobService.run(await GET_SOURCE_FN$1(source), symbol, timeframe, limit);
|
|
768
768
|
const resultId = randomString();
|
|
769
769
|
const data = pine.pineDataService.extract(plots, SIGNAL_SCHEMA);
|
|
770
770
|
return toSignalDto(resultId, data);
|
|
@@ -782,6 +782,44 @@ async function dumpPlotData(signalId, plots, mapping, taName, outputDir = `./dum
|
|
|
782
782
|
}
|
|
783
783
|
|
|
784
784
|
const TO_MARKDOWN_METHOD_NAME = "markdown.toMarkdown";
|
|
785
|
+
const MARKDOWN_METHOD_NAME = "markdown.markdown";
|
|
786
|
+
const GET_SOURCE_FN = async (source) => {
|
|
787
|
+
if (File.isFile(source)) {
|
|
788
|
+
const code = await pine.pineCacheService.readFile(source.path, source.baseDir);
|
|
789
|
+
return Code.fromString(code);
|
|
790
|
+
}
|
|
791
|
+
if (Code.isCode(source)) {
|
|
792
|
+
return source;
|
|
793
|
+
}
|
|
794
|
+
throw new Error("Source must be a File or Code instance");
|
|
795
|
+
};
|
|
796
|
+
const BASE_RUNNER_FN = async (script, symbol, timeframe, limit) => await pine.pineJobService.run(script, symbol, timeframe, limit);
|
|
797
|
+
const VALIDATE_NO_TRADING_FN = () => {
|
|
798
|
+
if (ExecutionContextService.hasContext()) {
|
|
799
|
+
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."));
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
const CREATE_INFERENCE_FN = (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
803
|
+
let fn = () => BASE_RUNNER_FN(script, symbol, timeframe, limit);
|
|
804
|
+
if (exchangeName) {
|
|
805
|
+
fn = ExchangeContextService.runWithContext(fn, { exchangeName });
|
|
806
|
+
}
|
|
807
|
+
if (when) {
|
|
808
|
+
fn = ExecutionContextService.runWithContext(fn, {
|
|
809
|
+
when,
|
|
810
|
+
symbol,
|
|
811
|
+
backtest: true,
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
return fn;
|
|
815
|
+
};
|
|
816
|
+
const RUN_INFERENCE_FN = async (script, symbol, timeframe, limit, exchangeName, when) => {
|
|
817
|
+
if (when) {
|
|
818
|
+
VALIDATE_NO_TRADING_FN();
|
|
819
|
+
}
|
|
820
|
+
const inference = CREATE_INFERENCE_FN(script, symbol, timeframe, limit, exchangeName, when);
|
|
821
|
+
return await inference();
|
|
822
|
+
};
|
|
785
823
|
async function toMarkdown(signalId, plots, mapping, limit = Number.POSITIVE_INFINITY) {
|
|
786
824
|
pine.loggerService.log(TO_MARKDOWN_METHOD_NAME, {
|
|
787
825
|
signalId,
|
|
@@ -791,5 +829,16 @@ async function toMarkdown(signalId, plots, mapping, limit = Number.POSITIVE_INFI
|
|
|
791
829
|
});
|
|
792
830
|
return await pine.pineMarkdownService.getReport(signalId, plots, mapping, limit);
|
|
793
831
|
}
|
|
832
|
+
async function markdown(signalId, source, { symbol, timeframe, limit }, mapping, exchangeName, when) {
|
|
833
|
+
pine.loggerService.log(MARKDOWN_METHOD_NAME, {
|
|
834
|
+
signalId,
|
|
835
|
+
mapping,
|
|
836
|
+
limit,
|
|
837
|
+
exchangeName,
|
|
838
|
+
when,
|
|
839
|
+
});
|
|
840
|
+
const { plots } = await RUN_INFERENCE_FN(await GET_SOURCE_FN(source), symbol, timeframe, limit, exchangeName, when);
|
|
841
|
+
return await pine.pineMarkdownService.getReport(signalId, plots, mapping, Number.POSITIVE_INFINITY);
|
|
842
|
+
}
|
|
794
843
|
|
|
795
|
-
export { AXIS_SYMBOL, Code, File, dumpPlotData, extract, getSignal, pine as lib, run, setLogger, toMarkdown, toSignalDto, usePine };
|
|
844
|
+
export { AXIS_SYMBOL, Code, File, dumpPlotData, extract, getSignal, pine as lib, markdown, 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.
|
|
3
|
+
"version": "3.0.13",
|
|
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",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"worker-testbed": "1.0.12"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"backtest-kit": "^3.0.
|
|
75
|
+
"backtest-kit": "^3.0.17",
|
|
76
76
|
"pinets": "^0.8.6",
|
|
77
77
|
"typescript": "^5.0.0"
|
|
78
78
|
},
|
package/types.d.ts
CHANGED
|
@@ -47,12 +47,12 @@ interface IExchangeContext {
|
|
|
47
47
|
exchangeName: ExchangeName;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
interface IRunParams {
|
|
50
|
+
interface IRunParams$1 {
|
|
51
51
|
symbol: string;
|
|
52
52
|
timeframe: CandleInterval;
|
|
53
53
|
limit: number;
|
|
54
54
|
}
|
|
55
|
-
declare function run(source: File | Code, { symbol, timeframe, limit }: IRunParams, exchangeName?: ExchangeName, when?: Date): Promise<PlotModel>;
|
|
55
|
+
declare function run(source: File | Code, { symbol, timeframe, limit }: IRunParams$1, exchangeName?: ExchangeName, when?: Date): Promise<PlotModel>;
|
|
56
56
|
|
|
57
57
|
type PlotExtractConfig<T = number> = {
|
|
58
58
|
plot: string;
|
|
@@ -92,7 +92,13 @@ 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
|
+
interface IRunParams {
|
|
96
|
+
symbol: string;
|
|
97
|
+
timeframe: CandleInterval;
|
|
98
|
+
limit: number;
|
|
99
|
+
}
|
|
95
100
|
declare function toMarkdown<M extends PlotMapping>(signalId: ResultId$2, plots: PlotModel, mapping: M, limit?: number): Promise<string>;
|
|
101
|
+
declare function markdown<M extends PlotMapping>(signalId: ResultId$2, source: File | Code, { symbol, timeframe, limit }: IRunParams, mapping: M, exchangeName?: ExchangeName, when?: Date): Promise<string>;
|
|
96
102
|
|
|
97
103
|
type ResultId$1 = string | number;
|
|
98
104
|
interface SignalData {
|
|
@@ -199,4 +205,4 @@ declare const pine: {
|
|
|
199
205
|
};
|
|
200
206
|
};
|
|
201
207
|
|
|
202
|
-
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, toMarkdown, toSignalDto, usePine };
|
|
208
|
+
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, markdown, run, setLogger, toMarkdown, toSignalDto, usePine };
|