@tradejs/node 2.0.1 → 2.0.2
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/dist/backtest.js +20 -11
- package/dist/backtest.mjs +1 -1
- package/dist/{chunk-2XFDY6AT.mjs → chunk-2DZCHRP6.mjs} +22 -12
- package/dist/strategies.js +22 -13
- package/dist/strategies.mjs +1 -1
- package/package.json +4 -4
package/dist/backtest.js
CHANGED
|
@@ -1838,11 +1838,12 @@ var enrichSignalWithCoinMarketCapContext = async (params) => {
|
|
|
1838
1838
|
|
|
1839
1839
|
// src/strategyHelpers/derivativesContext.ts
|
|
1840
1840
|
var import_indicators2 = require("@tradejs/core/indicators");
|
|
1841
|
+
var import_data = require("@tradejs/core/data");
|
|
1841
1842
|
var import_strategies3 = require("@tradejs/core/strategies");
|
|
1842
1843
|
var import_constants = require("@tradejs/core/constants");
|
|
1843
1844
|
var import_timescale3 = require("@tradejs/infra/timescale");
|
|
1844
1845
|
var import_logger5 = require("@tradejs/infra/logger");
|
|
1845
|
-
var
|
|
1846
|
+
var STORED_INTERVALS = ["15m", "1h"];
|
|
1846
1847
|
var CONTEXT_INTERVALS = ["15m", "1h"];
|
|
1847
1848
|
var DEFAULT_LOOKBACK_HOURS = 48;
|
|
1848
1849
|
var PRIMARY_DERIVATIVES_REFERENCE_SYMBOL = import_constants.DERIVATIVES_CONTEXT_BASE_REFERENCE_SYMBOLS[0];
|
|
@@ -1868,9 +1869,12 @@ var parseLookbackMs = () => {
|
|
|
1868
1869
|
const normalizedHours = Number.isFinite(hours) && hours > 0 ? hours : DEFAULT_LOOKBACK_HOURS;
|
|
1869
1870
|
return normalizedHours * 60 * 60 * 1e3;
|
|
1870
1871
|
};
|
|
1871
|
-
var
|
|
1872
|
+
var withHourlyFallbackRows = (rowsByInterval) => ({
|
|
1872
1873
|
"15m": rowsByInterval["15m"] ?? [],
|
|
1873
|
-
"1h": (0, import_indicators2.
|
|
1874
|
+
"1h": (0, import_indicators2.buildCoinalyzeHourlyRowsWithFallback)({
|
|
1875
|
+
rows15m: rowsByInterval["15m"],
|
|
1876
|
+
fallbackRows1h: rowsByInterval["1h"]
|
|
1877
|
+
})
|
|
1874
1878
|
});
|
|
1875
1879
|
var getDerivativesContextReferenceSymbols = () => [
|
|
1876
1880
|
...(0, import_constants.resolveDerivativesContextReferenceSymbols)(
|
|
@@ -1994,12 +1998,17 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
1994
1998
|
const referenceSymbols = getDerivativesContextReferenceSymbols();
|
|
1995
1999
|
const targetSymbol = normalizeSymbol(signal.symbol);
|
|
1996
2000
|
const lookbackMs = parseLookbackMs();
|
|
2001
|
+
const decisionTimeMs = signal.timestamp + (0, import_data.intervalToMs)(signal.interval);
|
|
2002
|
+
const derivativesEndMs = (0, import_indicators2.getLastClosedDerivativesBarStartMs)(
|
|
2003
|
+
decisionTimeMs,
|
|
2004
|
+
"15m"
|
|
2005
|
+
);
|
|
1997
2006
|
const contexts = await Promise.all(
|
|
1998
2007
|
referenceSymbols.map(async (symbol) => {
|
|
1999
2008
|
const rowsByInterval = await (0, import_timescale3.getDerivativesWindow)({
|
|
2000
2009
|
symbol,
|
|
2001
|
-
intervals:
|
|
2002
|
-
endMs:
|
|
2010
|
+
intervals: STORED_INTERVALS,
|
|
2011
|
+
endMs: derivativesEndMs,
|
|
2003
2012
|
lookbackMs
|
|
2004
2013
|
});
|
|
2005
2014
|
return [
|
|
@@ -2007,8 +2016,8 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
2007
2016
|
(0, import_indicators2.buildDerivativesContext)({
|
|
2008
2017
|
symbol,
|
|
2009
2018
|
direction: signal.direction,
|
|
2010
|
-
timestamp:
|
|
2011
|
-
rowsByInterval:
|
|
2019
|
+
timestamp: derivativesEndMs,
|
|
2020
|
+
rowsByInterval: withHourlyFallbackRows(rowsByInterval),
|
|
2012
2021
|
priceChangePct1h: getSignalPriceChangePct1h(signal),
|
|
2013
2022
|
intervals: CONTEXT_INTERVALS
|
|
2014
2023
|
})
|
|
@@ -2026,15 +2035,15 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
2026
2035
|
const fetchedTargetContext = shouldFetchTargetContext ? await (async () => {
|
|
2027
2036
|
const rowsByInterval = await (0, import_timescale3.getDerivativesWindow)({
|
|
2028
2037
|
symbol: targetSymbol,
|
|
2029
|
-
intervals:
|
|
2030
|
-
endMs:
|
|
2038
|
+
intervals: STORED_INTERVALS,
|
|
2039
|
+
endMs: derivativesEndMs,
|
|
2031
2040
|
lookbackMs
|
|
2032
2041
|
});
|
|
2033
2042
|
const context = (0, import_indicators2.buildDerivativesContext)({
|
|
2034
2043
|
symbol: targetSymbol,
|
|
2035
2044
|
direction: signal.direction,
|
|
2036
|
-
timestamp:
|
|
2037
|
-
rowsByInterval:
|
|
2045
|
+
timestamp: derivativesEndMs,
|
|
2046
|
+
rowsByInterval: withHourlyFallbackRows(rowsByInterval),
|
|
2038
2047
|
priceChangePct1h: getSignalPriceChangePct1h(signal),
|
|
2039
2048
|
intervals: CONTEXT_INTERVALS
|
|
2040
2049
|
});
|
package/dist/backtest.mjs
CHANGED
|
@@ -747,8 +747,10 @@ var enrichSignalWithCoinMarketCapContext = async (params) => {
|
|
|
747
747
|
// src/strategyHelpers/derivativesContext.ts
|
|
748
748
|
import {
|
|
749
749
|
buildDerivativesContext,
|
|
750
|
-
|
|
750
|
+
buildCoinalyzeHourlyRowsWithFallback,
|
|
751
|
+
getLastClosedDerivativesBarStartMs
|
|
751
752
|
} from "@tradejs/core/indicators";
|
|
753
|
+
import { intervalToMs } from "@tradejs/core/data";
|
|
752
754
|
import { refreshSignalBaseContextGateFeatures as refreshSignalBaseContextGateFeatures3 } from "@tradejs/core/strategies";
|
|
753
755
|
import {
|
|
754
756
|
DERIVATIVES_CONTEXT_BASE_REFERENCE_SYMBOLS,
|
|
@@ -756,7 +758,7 @@ import {
|
|
|
756
758
|
} from "@tradejs/core/constants";
|
|
757
759
|
import { getDerivativesWindow } from "@tradejs/infra/timescale";
|
|
758
760
|
import { logger as logger3 } from "@tradejs/infra/logger";
|
|
759
|
-
var
|
|
761
|
+
var STORED_INTERVALS = ["15m", "1h"];
|
|
760
762
|
var CONTEXT_INTERVALS = ["15m", "1h"];
|
|
761
763
|
var DEFAULT_LOOKBACK_HOURS = 48;
|
|
762
764
|
var PRIMARY_DERIVATIVES_REFERENCE_SYMBOL = DERIVATIVES_CONTEXT_BASE_REFERENCE_SYMBOLS[0];
|
|
@@ -782,9 +784,12 @@ var parseLookbackMs = () => {
|
|
|
782
784
|
const normalizedHours = Number.isFinite(hours) && hours > 0 ? hours : DEFAULT_LOOKBACK_HOURS;
|
|
783
785
|
return normalizedHours * 60 * 60 * 1e3;
|
|
784
786
|
};
|
|
785
|
-
var
|
|
787
|
+
var withHourlyFallbackRows = (rowsByInterval) => ({
|
|
786
788
|
"15m": rowsByInterval["15m"] ?? [],
|
|
787
|
-
"1h":
|
|
789
|
+
"1h": buildCoinalyzeHourlyRowsWithFallback({
|
|
790
|
+
rows15m: rowsByInterval["15m"],
|
|
791
|
+
fallbackRows1h: rowsByInterval["1h"]
|
|
792
|
+
})
|
|
788
793
|
});
|
|
789
794
|
var getDerivativesContextReferenceSymbols = () => [
|
|
790
795
|
...resolveDerivativesContextReferenceSymbols(
|
|
@@ -908,12 +913,17 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
908
913
|
const referenceSymbols = getDerivativesContextReferenceSymbols();
|
|
909
914
|
const targetSymbol = normalizeSymbol(signal.symbol);
|
|
910
915
|
const lookbackMs = parseLookbackMs();
|
|
916
|
+
const decisionTimeMs = signal.timestamp + intervalToMs(signal.interval);
|
|
917
|
+
const derivativesEndMs = getLastClosedDerivativesBarStartMs(
|
|
918
|
+
decisionTimeMs,
|
|
919
|
+
"15m"
|
|
920
|
+
);
|
|
911
921
|
const contexts = await Promise.all(
|
|
912
922
|
referenceSymbols.map(async (symbol) => {
|
|
913
923
|
const rowsByInterval = await getDerivativesWindow({
|
|
914
924
|
symbol,
|
|
915
|
-
intervals:
|
|
916
|
-
endMs:
|
|
925
|
+
intervals: STORED_INTERVALS,
|
|
926
|
+
endMs: derivativesEndMs,
|
|
917
927
|
lookbackMs
|
|
918
928
|
});
|
|
919
929
|
return [
|
|
@@ -921,8 +931,8 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
921
931
|
buildDerivativesContext({
|
|
922
932
|
symbol,
|
|
923
933
|
direction: signal.direction,
|
|
924
|
-
timestamp:
|
|
925
|
-
rowsByInterval:
|
|
934
|
+
timestamp: derivativesEndMs,
|
|
935
|
+
rowsByInterval: withHourlyFallbackRows(rowsByInterval),
|
|
926
936
|
priceChangePct1h: getSignalPriceChangePct1h(signal),
|
|
927
937
|
intervals: CONTEXT_INTERVALS
|
|
928
938
|
})
|
|
@@ -940,15 +950,15 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
940
950
|
const fetchedTargetContext = shouldFetchTargetContext ? await (async () => {
|
|
941
951
|
const rowsByInterval = await getDerivativesWindow({
|
|
942
952
|
symbol: targetSymbol,
|
|
943
|
-
intervals:
|
|
944
|
-
endMs:
|
|
953
|
+
intervals: STORED_INTERVALS,
|
|
954
|
+
endMs: derivativesEndMs,
|
|
945
955
|
lookbackMs
|
|
946
956
|
});
|
|
947
957
|
const context = buildDerivativesContext({
|
|
948
958
|
symbol: targetSymbol,
|
|
949
959
|
direction: signal.direction,
|
|
950
|
-
timestamp:
|
|
951
|
-
rowsByInterval:
|
|
960
|
+
timestamp: derivativesEndMs,
|
|
961
|
+
rowsByInterval: withHourlyFallbackRows(rowsByInterval),
|
|
952
962
|
priceChangePct1h: getSignalPriceChangePct1h(signal),
|
|
953
963
|
intervals: CONTEXT_INTERVALS
|
|
954
964
|
});
|
package/dist/strategies.js
CHANGED
|
@@ -7196,7 +7196,7 @@ var askAI = async (signal, options = {}) => {
|
|
|
7196
7196
|
// src/strategyRuntime.ts
|
|
7197
7197
|
var import_node_path2 = __toESM(require("path"));
|
|
7198
7198
|
var import_constants4 = require("@tradejs/core/constants");
|
|
7199
|
-
var
|
|
7199
|
+
var import_data2 = require("@tradejs/core/data");
|
|
7200
7200
|
var import_strategies4 = require("@tradejs/core/strategies");
|
|
7201
7201
|
var import_logger8 = require("@tradejs/infra/logger");
|
|
7202
7202
|
|
|
@@ -7424,11 +7424,12 @@ var markRuntimeTradeClosed = async (params) => {
|
|
|
7424
7424
|
|
|
7425
7425
|
// src/strategyHelpers/derivativesContext.ts
|
|
7426
7426
|
var import_indicators2 = require("@tradejs/core/indicators");
|
|
7427
|
+
var import_data = require("@tradejs/core/data");
|
|
7427
7428
|
var import_strategies = require("@tradejs/core/strategies");
|
|
7428
7429
|
var import_constants2 = require("@tradejs/core/constants");
|
|
7429
7430
|
var import_timescale = require("@tradejs/infra/timescale");
|
|
7430
7431
|
var import_logger4 = require("@tradejs/infra/logger");
|
|
7431
|
-
var
|
|
7432
|
+
var STORED_INTERVALS = ["15m", "1h"];
|
|
7432
7433
|
var CONTEXT_INTERVALS = ["15m", "1h"];
|
|
7433
7434
|
var DEFAULT_LOOKBACK_HOURS = 48;
|
|
7434
7435
|
var PRIMARY_DERIVATIVES_REFERENCE_SYMBOL = import_constants2.DERIVATIVES_CONTEXT_BASE_REFERENCE_SYMBOLS[0];
|
|
@@ -7454,9 +7455,12 @@ var parseLookbackMs = () => {
|
|
|
7454
7455
|
const normalizedHours = Number.isFinite(hours) && hours > 0 ? hours : DEFAULT_LOOKBACK_HOURS;
|
|
7455
7456
|
return normalizedHours * 60 * 60 * 1e3;
|
|
7456
7457
|
};
|
|
7457
|
-
var
|
|
7458
|
+
var withHourlyFallbackRows = (rowsByInterval) => ({
|
|
7458
7459
|
"15m": rowsByInterval["15m"] ?? [],
|
|
7459
|
-
"1h": (0, import_indicators2.
|
|
7460
|
+
"1h": (0, import_indicators2.buildCoinalyzeHourlyRowsWithFallback)({
|
|
7461
|
+
rows15m: rowsByInterval["15m"],
|
|
7462
|
+
fallbackRows1h: rowsByInterval["1h"]
|
|
7463
|
+
})
|
|
7460
7464
|
});
|
|
7461
7465
|
var getDerivativesContextReferenceSymbols = () => [
|
|
7462
7466
|
...(0, import_constants2.resolveDerivativesContextReferenceSymbols)(
|
|
@@ -7580,12 +7584,17 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
7580
7584
|
const referenceSymbols = getDerivativesContextReferenceSymbols();
|
|
7581
7585
|
const targetSymbol = normalizeSymbol(signal.symbol);
|
|
7582
7586
|
const lookbackMs = parseLookbackMs();
|
|
7587
|
+
const decisionTimeMs = signal.timestamp + (0, import_data.intervalToMs)(signal.interval);
|
|
7588
|
+
const derivativesEndMs = (0, import_indicators2.getLastClosedDerivativesBarStartMs)(
|
|
7589
|
+
decisionTimeMs,
|
|
7590
|
+
"15m"
|
|
7591
|
+
);
|
|
7583
7592
|
const contexts = await Promise.all(
|
|
7584
7593
|
referenceSymbols.map(async (symbol) => {
|
|
7585
7594
|
const rowsByInterval = await (0, import_timescale.getDerivativesWindow)({
|
|
7586
7595
|
symbol,
|
|
7587
|
-
intervals:
|
|
7588
|
-
endMs:
|
|
7596
|
+
intervals: STORED_INTERVALS,
|
|
7597
|
+
endMs: derivativesEndMs,
|
|
7589
7598
|
lookbackMs
|
|
7590
7599
|
});
|
|
7591
7600
|
return [
|
|
@@ -7593,8 +7602,8 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
7593
7602
|
(0, import_indicators2.buildDerivativesContext)({
|
|
7594
7603
|
symbol,
|
|
7595
7604
|
direction: signal.direction,
|
|
7596
|
-
timestamp:
|
|
7597
|
-
rowsByInterval:
|
|
7605
|
+
timestamp: derivativesEndMs,
|
|
7606
|
+
rowsByInterval: withHourlyFallbackRows(rowsByInterval),
|
|
7598
7607
|
priceChangePct1h: getSignalPriceChangePct1h(signal),
|
|
7599
7608
|
intervals: CONTEXT_INTERVALS
|
|
7600
7609
|
})
|
|
@@ -7612,15 +7621,15 @@ var enrichSignalWithDerivativesContext = async (params) => {
|
|
|
7612
7621
|
const fetchedTargetContext = shouldFetchTargetContext ? await (async () => {
|
|
7613
7622
|
const rowsByInterval = await (0, import_timescale.getDerivativesWindow)({
|
|
7614
7623
|
symbol: targetSymbol,
|
|
7615
|
-
intervals:
|
|
7616
|
-
endMs:
|
|
7624
|
+
intervals: STORED_INTERVALS,
|
|
7625
|
+
endMs: derivativesEndMs,
|
|
7617
7626
|
lookbackMs
|
|
7618
7627
|
});
|
|
7619
7628
|
const context = (0, import_indicators2.buildDerivativesContext)({
|
|
7620
7629
|
symbol: targetSymbol,
|
|
7621
7630
|
direction: signal.direction,
|
|
7622
|
-
timestamp:
|
|
7623
|
-
rowsByInterval:
|
|
7631
|
+
timestamp: derivativesEndMs,
|
|
7632
|
+
rowsByInterval: withHourlyFallbackRows(rowsByInterval),
|
|
7624
7633
|
priceChangePct1h: getSignalPriceChangePct1h(signal),
|
|
7625
7634
|
intervals: CONTEXT_INTERVALS
|
|
7626
7635
|
});
|
|
@@ -8983,7 +8992,7 @@ var resolveBacktestExecutionDelayMs = (value, fallbackDelayMs) => {
|
|
|
8983
8992
|
};
|
|
8984
8993
|
var safeIntervalToMs = (interval) => {
|
|
8985
8994
|
try {
|
|
8986
|
-
return (0,
|
|
8995
|
+
return (0, import_data2.intervalToMs)(interval);
|
|
8987
8996
|
} catch {
|
|
8988
8997
|
return null;
|
|
8989
8998
|
}
|
package/dist/strategies.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/node",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Node-only runtime for the TradeJS TypeScript framework: strategies, backtests, Pine strategy loading, and plugin registries.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@langchain/core": "^1.1.42",
|
|
69
69
|
"@langchain/openai": "^1.4.5",
|
|
70
|
-
"@tradejs/core": "^2.0.
|
|
71
|
-
"@tradejs/infra": "^2.0.
|
|
72
|
-
"@tradejs/types": "^2.0.
|
|
70
|
+
"@tradejs/core": "^2.0.2",
|
|
71
|
+
"@tradejs/infra": "^2.0.2",
|
|
72
|
+
"@tradejs/types": "^2.0.2",
|
|
73
73
|
"chalk": "4.1.2",
|
|
74
74
|
"ioredis": "5.8.0",
|
|
75
75
|
"pinets": "0.8.12",
|