@tradejs/cli 1.0.5 → 1.0.8

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.
Files changed (34) hide show
  1. package/README.md +4 -1
  2. package/dist/cli.js +13791 -7652
  3. package/dist/lib/aiTrainMetrics.js +173 -0
  4. package/dist/lib/candlesProviderMigration.js +266 -0
  5. package/dist/lib/cliArgs.js +40 -0
  6. package/dist/lib/derivativesContextBackfill.js +487 -0
  7. package/dist/lib/researchAgent.js +195 -0
  8. package/dist/lib/runtimeParity.js +234 -0
  9. package/dist/lib/telegramReports.js +91 -0
  10. package/dist/lib/timeWindow.js +101 -0
  11. package/dist/scripts/agentRun.js +895 -0
  12. package/dist/scripts/aiExport.js +192 -0
  13. package/dist/scripts/aiExportSelect.js +135 -0
  14. package/dist/scripts/aiTrain.js +2321 -0
  15. package/dist/scripts/backtest.js +998 -111
  16. package/dist/scripts/candlesMigrateProvider.js +5302 -0
  17. package/dist/scripts/continuity.js +1 -1
  18. package/dist/scripts/derivativesIngest.js +5 -0
  19. package/dist/scripts/derivativesIngestCoinalyzeAll.js +21 -12
  20. package/dist/scripts/migration.js +1 -1
  21. package/dist/scripts/mlExport.js +112 -13
  22. package/dist/scripts/mlExportSelect.js +43 -9
  23. package/dist/scripts/mlTrainLatestSelect.js +4 -3
  24. package/dist/scripts/researchAuto.js +845 -0
  25. package/dist/scripts/resolveExportStrategy.js +133 -0
  26. package/dist/scripts/results.js +46 -22
  27. package/dist/scripts/runtimeParity.js +1651 -0
  28. package/dist/scripts/selectStrategy.js +4 -3
  29. package/dist/scripts/signals.js +799 -62
  30. package/dist/scripts/signalsSummary.js +655 -0
  31. package/dist/scripts/spawnSiblingScript.js +71 -0
  32. package/dist/scripts/user-add.js +0 -9
  33. package/dist/workers/testerWorker.js +13 -2
  34. package/package.json +18 -12
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/scripts/resolveExportStrategy.ts
31
+ var resolveExportStrategy_exports = {};
32
+ __export(resolveExportStrategy_exports, {
33
+ resolveExportStrategy: () => resolveExportStrategy
34
+ });
35
+ module.exports = __toCommonJS(resolveExportStrategy_exports);
36
+
37
+ // src/scripts/selectStrategy.ts
38
+ var import_readline = __toESM(require("readline"));
39
+ var import_chalk = __toESM(require("chalk"));
40
+ var import_strategies = require("@tradejs/node/strategies");
41
+ var defaultStrategy = "TrendLine";
42
+ var projectRoot = String(process.env.PROJECT_CWD || process.cwd()).trim() || process.cwd();
43
+ var getStrategyChoices = async () => {
44
+ try {
45
+ const loaded = await (0, import_strategies.getAvailableStrategyNames)(projectRoot);
46
+ if (loaded.length) {
47
+ return loaded;
48
+ }
49
+ } catch (error) {
50
+ console.warn(`Failed to load strategy list: ${String(error)}`);
51
+ }
52
+ return [
53
+ "Breakout",
54
+ "MaStrategy",
55
+ "AdaptiveMomentumRibbon",
56
+ "TrendLine",
57
+ "VolumeDivergence"
58
+ ];
59
+ };
60
+ var selectStrategy = async (promptLabel = "Select strategy", options) => {
61
+ const strategies = options?.strategies && options.strategies.length ? options.strategies : await getStrategyChoices();
62
+ const preferredDefault = options?.defaultStrategy || defaultStrategy;
63
+ const fallbackStrategy = strategies.includes(preferredDefault) ? preferredDefault : strategies[0];
64
+ if (!process.stdin.isTTY) {
65
+ return fallbackStrategy;
66
+ }
67
+ console.log(import_chalk.default.cyan("Available strategies:"));
68
+ strategies.forEach((name, index) => {
69
+ const isDefault = name === defaultStrategy;
70
+ const label = isDefault ? import_chalk.default.green(name) : name;
71
+ const suffix = isDefault ? import_chalk.default.gray(" (default)") : "";
72
+ console.log(` ${import_chalk.default.yellow(String(index + 1))}) ${label}${suffix}`);
73
+ });
74
+ const rl = import_readline.default.createInterface({
75
+ input: process.stdin,
76
+ output: process.stdout
77
+ });
78
+ const question = (text) => new Promise((resolve) => rl.question(text, resolve));
79
+ const answer = await question(
80
+ `${promptLabel} [${import_chalk.default.green(fallbackStrategy)}]: `
81
+ );
82
+ rl.close();
83
+ const trimmed = answer.trim();
84
+ if (!trimmed) {
85
+ return fallbackStrategy;
86
+ }
87
+ const asNumber = Number(trimmed);
88
+ if (Number.isFinite(asNumber) && asNumber >= 1 && asNumber <= strategies.length) {
89
+ return strategies[asNumber - 1];
90
+ }
91
+ const byName = strategies.find(
92
+ (name) => name.toLowerCase() === trimmed.toLowerCase()
93
+ );
94
+ if (byName) {
95
+ return byName;
96
+ }
97
+ console.warn(`Unknown strategy "${trimmed}", using ${fallbackStrategy}.`);
98
+ return fallbackStrategy;
99
+ };
100
+
101
+ // src/scripts/resolveExportStrategy.ts
102
+ var resolveExportStrategy = async ({
103
+ explicitStrategy,
104
+ outDir,
105
+ datasetLabel,
106
+ promptLabel,
107
+ listStrategies
108
+ }) => {
109
+ const raw = String(explicitStrategy || "").trim();
110
+ if (raw) {
111
+ return raw;
112
+ }
113
+ const availableStrategies = await listStrategies({ outDir });
114
+ if (!availableStrategies.length) {
115
+ return null;
116
+ }
117
+ if (availableStrategies.length === 1) {
118
+ return availableStrategies[0];
119
+ }
120
+ if (!process.stdin.isTTY) {
121
+ throw new Error(
122
+ `Multiple ${datasetLabel} chunk strategies found in ${outDir}: ${availableStrategies.join(", ")}. Pass --strategy.`
123
+ );
124
+ }
125
+ return selectStrategy(promptLabel, {
126
+ strategies: availableStrategies,
127
+ defaultStrategy: availableStrategies[0]
128
+ });
129
+ };
130
+ // Annotate the CommonJS export names for ESM import in node:
131
+ 0 && (module.exports = {
132
+ resolveExportStrategy
133
+ });
@@ -502,19 +502,21 @@ var require_supports_color = __commonJS({
502
502
  var tty = require("tty");
503
503
  var hasFlag = require_has_flag();
504
504
  var { env } = process;
505
- var forceColor;
505
+ var flagForceColor;
506
506
  if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
507
- forceColor = 0;
507
+ flagForceColor = 0;
508
508
  } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
509
- forceColor = 1;
509
+ flagForceColor = 1;
510
510
  }
511
- if ("FORCE_COLOR" in env) {
512
- if (env.FORCE_COLOR === "true") {
513
- forceColor = 1;
514
- } else if (env.FORCE_COLOR === "false") {
515
- forceColor = 0;
516
- } else {
517
- forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
511
+ function envForceColor() {
512
+ if ("FORCE_COLOR" in env) {
513
+ if (env.FORCE_COLOR === "true") {
514
+ return 1;
515
+ }
516
+ if (env.FORCE_COLOR === "false") {
517
+ return 0;
518
+ }
519
+ return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
518
520
  }
519
521
  }
520
522
  function translateLevel(level) {
@@ -528,15 +530,22 @@ var require_supports_color = __commonJS({
528
530
  has16m: level >= 3
529
531
  };
530
532
  }
531
- function supportsColor(haveStream, streamIsTTY) {
533
+ function supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
534
+ const noFlagForceColor = envForceColor();
535
+ if (noFlagForceColor !== void 0) {
536
+ flagForceColor = noFlagForceColor;
537
+ }
538
+ const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
532
539
  if (forceColor === 0) {
533
540
  return 0;
534
541
  }
535
- if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
536
- return 3;
537
- }
538
- if (hasFlag("color=256")) {
539
- return 2;
542
+ if (sniffFlags) {
543
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
544
+ return 3;
545
+ }
546
+ if (hasFlag("color=256")) {
547
+ return 2;
548
+ }
540
549
  }
541
550
  if (haveStream && !streamIsTTY && forceColor === void 0) {
542
551
  return 0;
@@ -553,7 +562,7 @@ var require_supports_color = __commonJS({
553
562
  return 1;
554
563
  }
555
564
  if ("CI" in env) {
556
- if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
565
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
557
566
  return 1;
558
567
  }
559
568
  return min;
@@ -565,7 +574,7 @@ var require_supports_color = __commonJS({
565
574
  return 3;
566
575
  }
567
576
  if ("TERM_PROGRAM" in env) {
568
- const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
577
+ const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
569
578
  switch (env.TERM_PROGRAM) {
570
579
  case "iTerm.app":
571
580
  return version >= 3 ? 3 : 2;
@@ -584,14 +593,17 @@ var require_supports_color = __commonJS({
584
593
  }
585
594
  return min;
586
595
  }
587
- function getSupportLevel(stream) {
588
- const level = supportsColor(stream, stream && stream.isTTY);
596
+ function getSupportLevel(stream, options = {}) {
597
+ const level = supportsColor(stream, {
598
+ streamIsTTY: stream && stream.isTTY,
599
+ ...options
600
+ });
589
601
  return translateLevel(level);
590
602
  }
591
603
  module2.exports = {
592
604
  supportsColor: getSupportLevel,
593
- stdout: translateLevel(supportsColor(true, tty.isatty(1))),
594
- stderr: translateLevel(supportsColor(true, tty.isatty(2)))
605
+ stdout: getSupportLevel({ isTTY: tty.isatty(1) }),
606
+ stderr: getSupportLevel({ isTTY: tty.isatty(2) })
595
607
  };
596
608
  }
597
609
  });
@@ -1664,6 +1676,18 @@ var toStrategyResults = (rows) => Object.fromEntries(
1664
1676
  [...rows].map((row) => [row.symbol, toStrategyResultEntry(row)])
1665
1677
  );
1666
1678
  var getTestConfigs = async (userName) => {
1679
+ const testSummariesKey = typeof import_redis.redisKeys.testSummaries === "function" ? import_redis.redisKeys.testSummaries(userName) : null;
1680
+ const indexedItems = testSummariesKey ? await (0, import_redis.getData)(testSummariesKey, null) : null;
1681
+ if (Array.isArray(indexedItems) && indexedItems.length) {
1682
+ return indexedItems.map((item) => {
1683
+ const testName = typeof item?.value === "string" ? item.value : null;
1684
+ const strategyName = typeof item?.data?.strategyName === "string" ? item.data.strategyName : null;
1685
+ if (!testName || !strategyName) {
1686
+ return null;
1687
+ }
1688
+ return { strategyName, testName };
1689
+ }).filter(Boolean);
1690
+ }
1667
1691
  const testsPrefix = import_redis.redisKeys.tests(userName);
1668
1692
  const keys = await (0, import_redis.getKeys)(testsPrefix);
1669
1693
  const configKeys = keys.filter((key) => key.endsWith(":config"));