@tradejs/core 1.0.4 → 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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @tradejs/core
2
2
 
3
- Browser-safe TradeJS public API for config, strategy authoring helpers, indicators, figures, math, and shared utilities.
3
+ Browser-safe public API for the TradeJS open-source framework: config, strategy authoring helpers, indicators, figures, math, and shared utilities.
4
4
 
5
5
  - Homepage: https://tradejs.dev
6
6
  - Documentation: https://docs.tradejs.dev
package/dist/backtest.mjs CHANGED
@@ -13,11 +13,11 @@ import {
13
13
  compactOrderLog,
14
14
  getTimeline,
15
15
  getTimestamp
16
- } from "./chunk-PXLXXXLA.mjs";
16
+ } from "./chunk-BHIX34VS.mjs";
17
17
  import {
18
18
  BACKTEST_PRELOAD_DAYS,
19
19
  TestThresholdsConfig
20
- } from "./chunk-JG2QPVAV.mjs";
20
+ } from "./chunk-KQQUP2YF.mjs";
21
21
 
22
22
  // src/utils/grid.ts
23
23
  import _ from "lodash";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  BACKTEST_PRELOAD_DAYS
3
- } from "./chunk-JG2QPVAV.mjs";
3
+ } from "./chunk-KQQUP2YF.mjs";
4
4
 
5
5
  // src/utils/timestamp.ts
6
6
  import { format } from "date-fns";
@@ -3,12 +3,12 @@ import {
3
3
  } from "./chunk-AYC2QVKI.mjs";
4
4
  import {
5
5
  toMs
6
- } from "./chunk-PXLXXXLA.mjs";
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-JG2QPVAV.mjs";
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
- let result = [];
1526
- for (const candle of candles) result = next(candle);
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,
@@ -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 };
@@ -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,
@@ -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-JG2QPVAV.mjs";
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,
@@ -1608,8 +1608,14 @@ var createTrendlineEngine = (initialCandles, options) => {
1608
1608
  return result;
1609
1609
  };
1610
1610
  const nextMany = (candles) => {
1611
- let result = [];
1612
- for (const candle of candles) result = next(candle);
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();
@@ -28,10 +28,10 @@ import {
28
28
  toArrayData,
29
29
  toCoinalyzeTimestampMs,
30
30
  toFiniteNumber
31
- } from "./chunk-4F73AYK6.mjs";
31
+ } from "./chunk-JE3ACOXJ.mjs";
32
32
  import "./chunk-AYC2QVKI.mjs";
33
- import "./chunk-PXLXXXLA.mjs";
34
- import "./chunk-JG2QPVAV.mjs";
33
+ import "./chunk-BHIX34VS.mjs";
34
+ import "./chunk-KQQUP2YF.mjs";
35
35
  import "./chunk-M7QGVZ3J.mjs";
36
36
  export {
37
37
  alignSortedCandlesByTimestamp,
@@ -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,
@@ -3,14 +3,14 @@ import {
3
3
  } from "./chunk-NQ7D3T4E.mjs";
4
4
  import {
5
5
  createIndicators
6
- } from "./chunk-4F73AYK6.mjs";
6
+ } from "./chunk-JE3ACOXJ.mjs";
7
7
  import "./chunk-AYC2QVKI.mjs";
8
8
  import {
9
9
  getTimestamp
10
- } from "./chunk-PXLXXXLA.mjs";
10
+ } from "./chunk-BHIX34VS.mjs";
11
11
  import {
12
12
  FEE_PERCENT
13
- } from "./chunk-JG2QPVAV.mjs";
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
@@ -4,8 +4,8 @@ import {
4
4
  getItemTimestamp,
5
5
  getTimestamp,
6
6
  toMs
7
- } from "./chunk-PXLXXXLA.mjs";
8
- import "./chunk-JG2QPVAV.mjs";
7
+ } from "./chunk-BHIX34VS.mjs";
8
+ import "./chunk-KQQUP2YF.mjs";
9
9
  export {
10
10
  formatUnix,
11
11
  getDataTimestamp,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tradejs/core",
3
- "version": "1.0.4",
4
- "description": "Browser-safe TradeJS public API for config, strategy authoring, indicators, figures, and shared helpers.",
3
+ "version": "1.0.6",
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",
7
7
  "trading",
@@ -12,6 +12,14 @@
12
12
  "pine-script"
13
13
  ],
14
14
  "homepage": "https://tradejs.dev",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/tradejs-dev/tradejs.git",
18
+ "directory": "packages/core"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/tradejs-dev/tradejs/issues"
22
+ },
15
23
  "files": [
16
24
  "dist"
17
25
  ],
@@ -78,7 +86,7 @@
78
86
  }
79
87
  },
80
88
  "dependencies": {
81
- "@tradejs/types": "^1.0.4",
89
+ "@tradejs/types": "^1.0.6",
82
90
  "date-fns": "^3.3.1",
83
91
  "klinecharts": "10.0.0-alpha9",
84
92
  "lodash": "^4.17.21",