@tradejs/core 1.0.5 → 1.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/dist/backtest.mjs +2 -2
- package/dist/{chunk-PXLXXXLA.mjs → chunk-BHIX34VS.mjs} +1 -1
- package/dist/{chunk-4F73AYK6.mjs → chunk-JE3ACOXJ.mjs} +10 -4
- package/dist/{chunk-JG2QPVAV.mjs → chunk-KQQUP2YF.mjs} +2 -0
- package/dist/constants.d.mts +2 -1
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +3 -0
- package/dist/constants.mjs +3 -1
- package/dist/indicators.js +8 -2
- package/dist/indicators.mjs +3 -3
- package/dist/strategies.js +24 -0
- package/dist/strategies.mjs +27 -3
- package/dist/time.mjs +2 -2
- package/package.json +2 -2
package/dist/backtest.mjs
CHANGED
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
compactOrderLog,
|
|
14
14
|
getTimeline,
|
|
15
15
|
getTimestamp
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-BHIX34VS.mjs";
|
|
17
17
|
import {
|
|
18
18
|
BACKTEST_PRELOAD_DAYS,
|
|
19
19
|
TestThresholdsConfig
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-KQQUP2YF.mjs";
|
|
21
21
|
|
|
22
22
|
// src/utils/grid.ts
|
|
23
23
|
import _ from "lodash";
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
} from "./chunk-AYC2QVKI.mjs";
|
|
4
4
|
import {
|
|
5
5
|
toMs
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-BHIX34VS.mjs";
|
|
7
7
|
import {
|
|
8
8
|
CORRELATION_WINDOW,
|
|
9
9
|
ML_BASE_CANDLES_WINDOW,
|
|
10
10
|
TRENDLINE_DEFAULTS
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KQQUP2YF.mjs";
|
|
12
12
|
import {
|
|
13
13
|
cloneArrayValues
|
|
14
14
|
} from "./chunk-M7QGVZ3J.mjs";
|
|
@@ -1522,8 +1522,14 @@ var createTrendlineEngine = (initialCandles, options) => {
|
|
|
1522
1522
|
return result;
|
|
1523
1523
|
};
|
|
1524
1524
|
const nextMany = (candles) => {
|
|
1525
|
-
|
|
1526
|
-
|
|
1525
|
+
for (const candle of candles) {
|
|
1526
|
+
appendCandle(candle);
|
|
1527
|
+
}
|
|
1528
|
+
let result = buildResult();
|
|
1529
|
+
if (opts.capture && result.length === 0 && rawExtremaPoints.length) {
|
|
1530
|
+
rebuildCandidatesLikeBatch();
|
|
1531
|
+
result = buildResult();
|
|
1532
|
+
}
|
|
1527
1533
|
return result;
|
|
1528
1534
|
};
|
|
1529
1535
|
const getLines = () => buildResult();
|
|
@@ -4,6 +4,7 @@ var CORRELATION_WINDOW = 50;
|
|
|
4
4
|
var SPREAD_WINDOW = 50;
|
|
5
5
|
var PRELOAD_DAYS = 200;
|
|
6
6
|
var SIGNALS_PRELOAD_DAYS = 60;
|
|
7
|
+
var SIGNALS_CLI_PRELOAD_DAYS = 10;
|
|
7
8
|
var BACKTEST_PRELOAD_DAYS = 160;
|
|
8
9
|
var DASHBOARD_PRELOAD_DAYS = 160;
|
|
9
10
|
var BOT_PRELOAD_DAYS = 160;
|
|
@@ -169,6 +170,7 @@ export {
|
|
|
169
170
|
SPREAD_WINDOW,
|
|
170
171
|
PRELOAD_DAYS,
|
|
171
172
|
SIGNALS_PRELOAD_DAYS,
|
|
173
|
+
SIGNALS_CLI_PRELOAD_DAYS,
|
|
172
174
|
BACKTEST_PRELOAD_DAYS,
|
|
173
175
|
DASHBOARD_PRELOAD_DAYS,
|
|
174
176
|
BOT_PRELOAD_DAYS,
|
package/dist/constants.d.mts
CHANGED
|
@@ -5,6 +5,7 @@ declare const CORRELATION_WINDOW = 50;
|
|
|
5
5
|
declare const SPREAD_WINDOW = 50;
|
|
6
6
|
declare const PRELOAD_DAYS = 200;
|
|
7
7
|
declare const SIGNALS_PRELOAD_DAYS = 60;
|
|
8
|
+
declare const SIGNALS_CLI_PRELOAD_DAYS = 10;
|
|
8
9
|
declare const BACKTEST_PRELOAD_DAYS = 160;
|
|
9
10
|
declare const DASHBOARD_PRELOAD_DAYS = 160;
|
|
10
11
|
declare const BOT_PRELOAD_DAYS = 160;
|
|
@@ -38,4 +39,4 @@ declare const TRENDLINE_DEFAULTS: {
|
|
|
38
39
|
};
|
|
39
40
|
declare const TestThresholdsConfig: TestThresholds;
|
|
40
41
|
|
|
41
|
-
export { BACKTEST_PRELOAD_DAYS, BOT_PRELOAD_DAYS, CORRELATION_WINDOW, DASHBOARD_PRELOAD_DAYS, FEE_PERCENT, MARKET_CATEGORY, ML_BASE_CANDLES_WINDOW, ML_CANDLE_FEATURE_WINDOW, PRELOAD_DAYS, PRELOAD_FALLBACK_DAYS, SIGNALS_PRELOAD_DAYS, SPREAD_WINDOW, TESTS_LIMIT, TESTS_ORDERS_MIN_LIMIT, TESTS_TOP_LIMIT, TRENDLINE_DEFAULTS, TTL_12H, TTL_1D, TTL_1H, TTL_1M, TTL_3H, TTL_3M, TestThresholdsConfig };
|
|
42
|
+
export { BACKTEST_PRELOAD_DAYS, BOT_PRELOAD_DAYS, CORRELATION_WINDOW, DASHBOARD_PRELOAD_DAYS, FEE_PERCENT, MARKET_CATEGORY, ML_BASE_CANDLES_WINDOW, ML_CANDLE_FEATURE_WINDOW, PRELOAD_DAYS, PRELOAD_FALLBACK_DAYS, SIGNALS_CLI_PRELOAD_DAYS, SIGNALS_PRELOAD_DAYS, SPREAD_WINDOW, TESTS_LIMIT, TESTS_ORDERS_MIN_LIMIT, TESTS_TOP_LIMIT, TRENDLINE_DEFAULTS, TTL_12H, TTL_1D, TTL_1H, TTL_1M, TTL_3H, TTL_3M, TestThresholdsConfig };
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare const CORRELATION_WINDOW = 50;
|
|
|
5
5
|
declare const SPREAD_WINDOW = 50;
|
|
6
6
|
declare const PRELOAD_DAYS = 200;
|
|
7
7
|
declare const SIGNALS_PRELOAD_DAYS = 60;
|
|
8
|
+
declare const SIGNALS_CLI_PRELOAD_DAYS = 10;
|
|
8
9
|
declare const BACKTEST_PRELOAD_DAYS = 160;
|
|
9
10
|
declare const DASHBOARD_PRELOAD_DAYS = 160;
|
|
10
11
|
declare const BOT_PRELOAD_DAYS = 160;
|
|
@@ -38,4 +39,4 @@ declare const TRENDLINE_DEFAULTS: {
|
|
|
38
39
|
};
|
|
39
40
|
declare const TestThresholdsConfig: TestThresholds;
|
|
40
41
|
|
|
41
|
-
export { BACKTEST_PRELOAD_DAYS, BOT_PRELOAD_DAYS, CORRELATION_WINDOW, DASHBOARD_PRELOAD_DAYS, FEE_PERCENT, MARKET_CATEGORY, ML_BASE_CANDLES_WINDOW, ML_CANDLE_FEATURE_WINDOW, PRELOAD_DAYS, PRELOAD_FALLBACK_DAYS, SIGNALS_PRELOAD_DAYS, SPREAD_WINDOW, TESTS_LIMIT, TESTS_ORDERS_MIN_LIMIT, TESTS_TOP_LIMIT, TRENDLINE_DEFAULTS, TTL_12H, TTL_1D, TTL_1H, TTL_1M, TTL_3H, TTL_3M, TestThresholdsConfig };
|
|
42
|
+
export { BACKTEST_PRELOAD_DAYS, BOT_PRELOAD_DAYS, CORRELATION_WINDOW, DASHBOARD_PRELOAD_DAYS, FEE_PERCENT, MARKET_CATEGORY, ML_BASE_CANDLES_WINDOW, ML_CANDLE_FEATURE_WINDOW, PRELOAD_DAYS, PRELOAD_FALLBACK_DAYS, SIGNALS_CLI_PRELOAD_DAYS, SIGNALS_PRELOAD_DAYS, SPREAD_WINDOW, TESTS_LIMIT, TESTS_ORDERS_MIN_LIMIT, TESTS_TOP_LIMIT, TRENDLINE_DEFAULTS, TTL_12H, TTL_1D, TTL_1H, TTL_1M, TTL_3H, TTL_3M, TestThresholdsConfig };
|
package/dist/constants.js
CHANGED
|
@@ -30,6 +30,7 @@ __export(constants_exports, {
|
|
|
30
30
|
ML_CANDLE_FEATURE_WINDOW: () => ML_CANDLE_FEATURE_WINDOW,
|
|
31
31
|
PRELOAD_DAYS: () => PRELOAD_DAYS,
|
|
32
32
|
PRELOAD_FALLBACK_DAYS: () => PRELOAD_FALLBACK_DAYS,
|
|
33
|
+
SIGNALS_CLI_PRELOAD_DAYS: () => SIGNALS_CLI_PRELOAD_DAYS,
|
|
33
34
|
SIGNALS_PRELOAD_DAYS: () => SIGNALS_PRELOAD_DAYS,
|
|
34
35
|
SPREAD_WINDOW: () => SPREAD_WINDOW,
|
|
35
36
|
TESTS_LIMIT: () => TESTS_LIMIT,
|
|
@@ -52,6 +53,7 @@ var CORRELATION_WINDOW = 50;
|
|
|
52
53
|
var SPREAD_WINDOW = 50;
|
|
53
54
|
var PRELOAD_DAYS = 200;
|
|
54
55
|
var SIGNALS_PRELOAD_DAYS = 60;
|
|
56
|
+
var SIGNALS_CLI_PRELOAD_DAYS = 10;
|
|
55
57
|
var BACKTEST_PRELOAD_DAYS = 160;
|
|
56
58
|
var DASHBOARD_PRELOAD_DAYS = 160;
|
|
57
59
|
var BOT_PRELOAD_DAYS = 160;
|
|
@@ -222,6 +224,7 @@ var TestThresholdsConfig = {
|
|
|
222
224
|
ML_CANDLE_FEATURE_WINDOW,
|
|
223
225
|
PRELOAD_DAYS,
|
|
224
226
|
PRELOAD_FALLBACK_DAYS,
|
|
227
|
+
SIGNALS_CLI_PRELOAD_DAYS,
|
|
225
228
|
SIGNALS_PRELOAD_DAYS,
|
|
226
229
|
SPREAD_WINDOW,
|
|
227
230
|
TESTS_LIMIT,
|
package/dist/constants.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ML_CANDLE_FEATURE_WINDOW,
|
|
10
10
|
PRELOAD_DAYS,
|
|
11
11
|
PRELOAD_FALLBACK_DAYS,
|
|
12
|
+
SIGNALS_CLI_PRELOAD_DAYS,
|
|
12
13
|
SIGNALS_PRELOAD_DAYS,
|
|
13
14
|
SPREAD_WINDOW,
|
|
14
15
|
TESTS_LIMIT,
|
|
@@ -22,7 +23,7 @@ import {
|
|
|
22
23
|
TTL_3H,
|
|
23
24
|
TTL_3M,
|
|
24
25
|
TestThresholdsConfig
|
|
25
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-KQQUP2YF.mjs";
|
|
26
27
|
export {
|
|
27
28
|
BACKTEST_PRELOAD_DAYS,
|
|
28
29
|
BOT_PRELOAD_DAYS,
|
|
@@ -34,6 +35,7 @@ export {
|
|
|
34
35
|
ML_CANDLE_FEATURE_WINDOW,
|
|
35
36
|
PRELOAD_DAYS,
|
|
36
37
|
PRELOAD_FALLBACK_DAYS,
|
|
38
|
+
SIGNALS_CLI_PRELOAD_DAYS,
|
|
37
39
|
SIGNALS_PRELOAD_DAYS,
|
|
38
40
|
SPREAD_WINDOW,
|
|
39
41
|
TESTS_LIMIT,
|
package/dist/indicators.js
CHANGED
|
@@ -1608,8 +1608,14 @@ var createTrendlineEngine = (initialCandles, options) => {
|
|
|
1608
1608
|
return result;
|
|
1609
1609
|
};
|
|
1610
1610
|
const nextMany = (candles) => {
|
|
1611
|
-
|
|
1612
|
-
|
|
1611
|
+
for (const candle of candles) {
|
|
1612
|
+
appendCandle(candle);
|
|
1613
|
+
}
|
|
1614
|
+
let result = buildResult();
|
|
1615
|
+
if (opts.capture && result.length === 0 && rawExtremaPoints.length) {
|
|
1616
|
+
rebuildCandidatesLikeBatch();
|
|
1617
|
+
result = buildResult();
|
|
1618
|
+
}
|
|
1613
1619
|
return result;
|
|
1614
1620
|
};
|
|
1615
1621
|
const getLines = () => buildResult();
|
package/dist/indicators.mjs
CHANGED
|
@@ -28,10 +28,10 @@ import {
|
|
|
28
28
|
toArrayData,
|
|
29
29
|
toCoinalyzeTimestampMs,
|
|
30
30
|
toFiniteNumber
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-JE3ACOXJ.mjs";
|
|
32
32
|
import "./chunk-AYC2QVKI.mjs";
|
|
33
|
-
import "./chunk-
|
|
34
|
-
import "./chunk-
|
|
33
|
+
import "./chunk-BHIX34VS.mjs";
|
|
34
|
+
import "./chunk-KQQUP2YF.mjs";
|
|
35
35
|
import "./chunk-M7QGVZ3J.mjs";
|
|
36
36
|
export {
|
|
37
37
|
alignSortedCandlesByTimestamp,
|
package/dist/strategies.js
CHANGED
|
@@ -970,6 +970,8 @@ var buildEntrySignalDecision = ({
|
|
|
970
970
|
});
|
|
971
971
|
var isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
972
972
|
var toDefaultEntryCode = (strategy, direction) => `${strategy.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase()}_${direction}_ENTRY`;
|
|
973
|
+
var toDefaultExitCode = (strategy, direction) => `${strategy.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase()}_${direction}_EXIT`;
|
|
974
|
+
var toDefaultProtectCode = (strategy, direction) => `${strategy.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase()}_${direction}_PROTECT`;
|
|
973
975
|
var resolveTakeProfitPrice = ({
|
|
974
976
|
direction,
|
|
975
977
|
takeProfits
|
|
@@ -1074,6 +1076,28 @@ var createStrategyAPI = ({
|
|
|
1074
1076
|
runtime
|
|
1075
1077
|
});
|
|
1076
1078
|
},
|
|
1079
|
+
exit: async ({
|
|
1080
|
+
code,
|
|
1081
|
+
direction,
|
|
1082
|
+
price,
|
|
1083
|
+
timestamp
|
|
1084
|
+
}) => {
|
|
1085
|
+
const marketData = await getMarketData();
|
|
1086
|
+
return {
|
|
1087
|
+
kind: "exit",
|
|
1088
|
+
code: code ?? toDefaultExitCode(String(strategy), direction),
|
|
1089
|
+
closePlan: {
|
|
1090
|
+
price: price ?? marketData.currentPrice,
|
|
1091
|
+
timestamp: timestamp ?? marketData.timestamp,
|
|
1092
|
+
direction
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
},
|
|
1096
|
+
protect: ({ code, protectPlan }) => ({
|
|
1097
|
+
kind: "protect",
|
|
1098
|
+
code: code ?? toDefaultProtectCode(String(strategy), protectPlan.direction),
|
|
1099
|
+
protectPlan
|
|
1100
|
+
}),
|
|
1077
1101
|
getMarketData,
|
|
1078
1102
|
nextIndicators: (candle, btcCandle) => indicatorsState?.next(candle, btcCandle),
|
|
1079
1103
|
getCurrentPosition,
|
package/dist/strategies.mjs
CHANGED
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
} from "./chunk-NQ7D3T4E.mjs";
|
|
4
4
|
import {
|
|
5
5
|
createIndicators
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-JE3ACOXJ.mjs";
|
|
7
7
|
import "./chunk-AYC2QVKI.mjs";
|
|
8
8
|
import {
|
|
9
9
|
getTimestamp
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-BHIX34VS.mjs";
|
|
11
11
|
import {
|
|
12
12
|
FEE_PERCENT
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-KQQUP2YF.mjs";
|
|
14
14
|
import "./chunk-M7QGVZ3J.mjs";
|
|
15
15
|
|
|
16
16
|
// src/utils/strategyHelpers/indicators.ts
|
|
@@ -263,6 +263,8 @@ var buildEntrySignalDecision = ({
|
|
|
263
263
|
});
|
|
264
264
|
var isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
265
265
|
var toDefaultEntryCode = (strategy, direction) => `${strategy.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase()}_${direction}_ENTRY`;
|
|
266
|
+
var toDefaultExitCode = (strategy, direction) => `${strategy.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase()}_${direction}_EXIT`;
|
|
267
|
+
var toDefaultProtectCode = (strategy, direction) => `${strategy.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^a-zA-Z0-9]+/g, "_").toUpperCase()}_${direction}_PROTECT`;
|
|
266
268
|
var resolveTakeProfitPrice = ({
|
|
267
269
|
direction,
|
|
268
270
|
takeProfits
|
|
@@ -367,6 +369,28 @@ var createStrategyAPI = ({
|
|
|
367
369
|
runtime
|
|
368
370
|
});
|
|
369
371
|
},
|
|
372
|
+
exit: async ({
|
|
373
|
+
code,
|
|
374
|
+
direction,
|
|
375
|
+
price,
|
|
376
|
+
timestamp
|
|
377
|
+
}) => {
|
|
378
|
+
const marketData = await getMarketData();
|
|
379
|
+
return {
|
|
380
|
+
kind: "exit",
|
|
381
|
+
code: code ?? toDefaultExitCode(String(strategy), direction),
|
|
382
|
+
closePlan: {
|
|
383
|
+
price: price ?? marketData.currentPrice,
|
|
384
|
+
timestamp: timestamp ?? marketData.timestamp,
|
|
385
|
+
direction
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
},
|
|
389
|
+
protect: ({ code, protectPlan }) => ({
|
|
390
|
+
kind: "protect",
|
|
391
|
+
code: code ?? toDefaultProtectCode(String(strategy), protectPlan.direction),
|
|
392
|
+
protectPlan
|
|
393
|
+
}),
|
|
370
394
|
getMarketData,
|
|
371
395
|
nextIndicators: (candle, btcCandle) => indicatorsState?.next(candle, btcCandle),
|
|
372
396
|
getCurrentPosition,
|
package/dist/time.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Browser-safe public API for the TradeJS open-source framework: config, strategy authoring, indicators, figures, and shared helpers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@tradejs/types": "^1.0.
|
|
89
|
+
"@tradejs/types": "^1.0.6",
|
|
90
90
|
"date-fns": "^3.3.1",
|
|
91
91
|
"klinecharts": "10.0.0-alpha9",
|
|
92
92
|
"lodash": "^4.17.21",
|