@tradejs/cli 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 +5 -2
- package/dist/cli.js +2047 -929
- package/dist/lib/aiTrainMetrics.js +150 -0
- package/dist/scripts/aiExport.js +192 -0
- package/dist/scripts/aiExportSelect.js +135 -0
- package/dist/scripts/aiTrain.js +2239 -0
- package/dist/scripts/backtest.js +218 -32
- package/dist/scripts/derivativesIngest.js +5 -0
- package/dist/scripts/derivativesIngestCoinalyzeAll.js +21 -12
- package/dist/scripts/mlExport.js +112 -13
- package/dist/scripts/mlExportSelect.js +43 -9
- package/dist/scripts/mlTrainLatestSelect.js +4 -3
- package/dist/scripts/resolveExportStrategy.js +133 -0
- package/dist/scripts/selectStrategy.js +4 -3
- package/dist/scripts/signals.js +238 -133
- package/dist/scripts/spawnSiblingScript.js +71 -0
- package/dist/workers/testerWorker.js +13 -2
- package/package.json +20 -10
|
@@ -22,9 +22,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
|
|
25
|
-
// src/scripts/mlExportSelect.ts
|
|
26
|
-
var import_child_process = require("child_process");
|
|
27
|
-
|
|
28
25
|
// src/scripts/selectStrategy.ts
|
|
29
26
|
var import_readline = __toESM(require("readline"));
|
|
30
27
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -48,9 +45,10 @@ var getStrategyChoices = async () => {
|
|
|
48
45
|
"VolumeDivergence"
|
|
49
46
|
];
|
|
50
47
|
};
|
|
51
|
-
var selectStrategy = async (promptLabel = "Select strategy") => {
|
|
52
|
-
const strategies = await getStrategyChoices();
|
|
53
|
-
const
|
|
48
|
+
var selectStrategy = async (promptLabel = "Select strategy", options) => {
|
|
49
|
+
const strategies = options?.strategies && options.strategies.length ? options.strategies : await getStrategyChoices();
|
|
50
|
+
const preferredDefault = options?.defaultStrategy || defaultStrategy;
|
|
51
|
+
const fallbackStrategy = strategies.includes(preferredDefault) ? preferredDefault : strategies[0];
|
|
54
52
|
if (!process.stdin.isTTY) {
|
|
55
53
|
return fallbackStrategy;
|
|
56
54
|
}
|
|
@@ -88,12 +86,48 @@ var selectStrategy = async (promptLabel = "Select strategy") => {
|
|
|
88
86
|
return fallbackStrategy;
|
|
89
87
|
};
|
|
90
88
|
|
|
89
|
+
// src/scripts/spawnSiblingScript.ts
|
|
90
|
+
var import_fs = __toESM(require("fs"));
|
|
91
|
+
var import_path = __toESM(require("path"));
|
|
92
|
+
var import_child_process = require("child_process");
|
|
93
|
+
var spawnSiblingScript = (currentDir, scriptBaseName, extraArgs) => {
|
|
94
|
+
const searchDirs = [currentDir, import_path.default.resolve(currentDir, "scripts")];
|
|
95
|
+
const candidates = searchDirs.flatMap((dir) => [
|
|
96
|
+
import_path.default.resolve(dir, `${scriptBaseName}.js`),
|
|
97
|
+
import_path.default.resolve(dir, `${scriptBaseName}.ts`)
|
|
98
|
+
]);
|
|
99
|
+
const scriptPath = candidates.find((candidate) => import_fs.default.existsSync(candidate));
|
|
100
|
+
if (!scriptPath) {
|
|
101
|
+
throw new Error(
|
|
102
|
+
`Script "${scriptBaseName}" not found. Checked: ${candidates.join(", ")}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const commandArgs = scriptPath.endsWith(".ts") ? [
|
|
106
|
+
"-r",
|
|
107
|
+
"ts-node/register",
|
|
108
|
+
"-r",
|
|
109
|
+
"tsconfig-paths/register",
|
|
110
|
+
scriptPath,
|
|
111
|
+
...extraArgs
|
|
112
|
+
] : [scriptPath, ...extraArgs];
|
|
113
|
+
const result = (0, import_child_process.spawnSync)(process.execPath, commandArgs, {
|
|
114
|
+
env: process.env,
|
|
115
|
+
stdio: "inherit"
|
|
116
|
+
});
|
|
117
|
+
if (result.error) {
|
|
118
|
+
throw result.error;
|
|
119
|
+
}
|
|
120
|
+
return result.status ?? 1;
|
|
121
|
+
};
|
|
122
|
+
|
|
91
123
|
// src/scripts/mlExportSelect.ts
|
|
92
124
|
var run = async () => {
|
|
93
125
|
const selected = await selectStrategy();
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
126
|
+
const status = spawnSiblingScript(__dirname, "mlExport", [
|
|
127
|
+
"--strategy",
|
|
128
|
+
selected
|
|
129
|
+
]);
|
|
130
|
+
process.exit(status);
|
|
97
131
|
};
|
|
98
132
|
run().catch((err) => {
|
|
99
133
|
console.error("Failed to select strategy:", err);
|
|
@@ -56,9 +56,10 @@ var getStrategyChoices = async () => {
|
|
|
56
56
|
"VolumeDivergence"
|
|
57
57
|
];
|
|
58
58
|
};
|
|
59
|
-
var selectStrategy = async (promptLabel = "Select strategy") => {
|
|
60
|
-
const strategies = await getStrategyChoices();
|
|
61
|
-
const
|
|
59
|
+
var selectStrategy = async (promptLabel = "Select strategy", options) => {
|
|
60
|
+
const strategies = options?.strategies && options.strategies.length ? options.strategies : await getStrategyChoices();
|
|
61
|
+
const preferredDefault = options?.defaultStrategy || defaultStrategy;
|
|
62
|
+
const fallbackStrategy = strategies.includes(preferredDefault) ? preferredDefault : strategies[0];
|
|
62
63
|
if (!process.stdin.isTTY) {
|
|
63
64
|
return fallbackStrategy;
|
|
64
65
|
}
|
|
@@ -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
|
+
});
|
|
@@ -55,9 +55,10 @@ var getStrategyChoices = async () => {
|
|
|
55
55
|
"VolumeDivergence"
|
|
56
56
|
];
|
|
57
57
|
};
|
|
58
|
-
var selectStrategy = async (promptLabel = "Select strategy") => {
|
|
59
|
-
const strategies = await getStrategyChoices();
|
|
60
|
-
const
|
|
58
|
+
var selectStrategy = async (promptLabel = "Select strategy", options) => {
|
|
59
|
+
const strategies = options?.strategies && options.strategies.length ? options.strategies : await getStrategyChoices();
|
|
60
|
+
const preferredDefault = options?.defaultStrategy || defaultStrategy;
|
|
61
|
+
const fallbackStrategy = strategies.includes(preferredDefault) ? preferredDefault : strategies[0];
|
|
61
62
|
if (!process.stdin.isTTY) {
|
|
62
63
|
return fallbackStrategy;
|
|
63
64
|
}
|