@tradejs/cli 3.1.28-beta.256 → 3.1.28-beta.258
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/cli.js +868 -701
- package/dist/lib/runtimeFeedbackNotification.js +412 -0
- package/dist/scripts/runtimeFeedbackNotify.js +438 -0
- package/package.json +8 -8
|
@@ -0,0 +1,438 @@
|
|
|
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/runtimeFeedbackNotify.ts
|
|
31
|
+
var runtimeFeedbackNotify_exports = {};
|
|
32
|
+
__export(runtimeFeedbackNotify_exports, {
|
|
33
|
+
main: () => main,
|
|
34
|
+
runtimeFeedbackNotify: () => runtimeFeedbackNotify
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(runtimeFeedbackNotify_exports);
|
|
37
|
+
var import_node_path4 = __toESM(require("path"));
|
|
38
|
+
var import_args = __toESM(require("args"));
|
|
39
|
+
var import_chalk = __toESM(require("chalk"));
|
|
40
|
+
|
|
41
|
+
// src/lib/runtimeFeedbackArtifacts.ts
|
|
42
|
+
var import_node_crypto3 = require("crypto");
|
|
43
|
+
var import_promises3 = __toESM(require("fs/promises"));
|
|
44
|
+
var import_node_path3 = __toESM(require("path"));
|
|
45
|
+
|
|
46
|
+
// src/lib/runtimeEvidenceDeployment.ts
|
|
47
|
+
var import_runtimeStrategies = require("@tradejs/node/runtimeStrategies");
|
|
48
|
+
var isRecord = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
49
|
+
var isNonEmptyString = (value) => typeof value === "string" && value.trim().length > 0;
|
|
50
|
+
var isPackageVersionMap = (value) => isRecord(value) && Object.keys(value).length > 0 && Object.entries(value).every(
|
|
51
|
+
([name, version]) => name.startsWith("@tradejs/") && isNonEmptyString(version)
|
|
52
|
+
);
|
|
53
|
+
var INTERVALS = /* @__PURE__ */ new Set([
|
|
54
|
+
"1",
|
|
55
|
+
"3",
|
|
56
|
+
"5",
|
|
57
|
+
"15",
|
|
58
|
+
"30",
|
|
59
|
+
"60",
|
|
60
|
+
"120",
|
|
61
|
+
"240",
|
|
62
|
+
"360",
|
|
63
|
+
"720",
|
|
64
|
+
"D",
|
|
65
|
+
"W",
|
|
66
|
+
"M"
|
|
67
|
+
]);
|
|
68
|
+
var UNIVERSES = /* @__PURE__ */ new Set(["crypto", "tradfi"]);
|
|
69
|
+
var isRuntimeStrategySelection = (value) => value === void 0 || isRecord(value) && Object.keys(value).length === 1 && Object.keys(value).every((key) => key === "tickers") && Array.isArray(value.tickers) && value.tickers.length > 0 && value.tickers.every((ticker) => isNonEmptyString(ticker));
|
|
70
|
+
var parseRuntimeEvidenceDeploymentSnapshot = (value) => {
|
|
71
|
+
if (!isRecord(value) || value.schemaVersion !== 2 || !isNonEmptyString(value.id) || !isNonEmptyString(value.deploymentCompositionId) || !/^dc1:[a-f0-9]{16}$/.test(value.deploymentCompositionId) || !isNonEmptyString(value.label) || !isNonEmptyString(value.connectorName) || !isNonEmptyString(value.provider) || !isNonEmptyString(value.accountId) || typeof value.enabled !== "boolean" || !Array.isArray(value.strategies)) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
"Runtime evidence deployment snapshot is missing or invalid"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const strategies = value.strategies.map((candidate) => {
|
|
77
|
+
if (!isRecord(candidate) || !isNonEmptyString(candidate.strategyName) || !isNonEmptyString(candidate.strategyRevision) || !/^sr1:[a-f0-9]{16}$/.test(candidate.strategyRevision) || typeof candidate.enabled !== "boolean" || !["active", "entries_paused"].includes(String(candidate.controlState)) || !INTERVALS.has(String(candidate.interval)) || !UNIVERSES.has(String(candidate.universe)) || !isNonEmptyString(candidate.strategyPackage) || !isNonEmptyString(candidate.strategyPackageVersion) || !isPackageVersionMap(candidate.strategyDependencyVersions) || !isNonEmptyString(candidate.runtimePackageVersion) || !isRecord(candidate.strategyConfig) || !isRuntimeStrategySelection(candidate.selection)) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
"Runtime evidence deployment strategy snapshot is invalid"
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (String(candidate.strategyConfig.INTERVAL) !== String(candidate.interval) || String(candidate.strategyConfig.UNIVERSE) !== String(candidate.universe)) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Runtime evidence strategy config does not match its scope: ${candidate.strategyName}`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
if (candidate.accountId != null && (!isNonEmptyString(candidate.accountId) || candidate.accountId !== value.accountId)) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Runtime evidence strategy account does not match deployment: ${candidate.strategyName}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
return candidate;
|
|
93
|
+
});
|
|
94
|
+
const identities = /* @__PURE__ */ new Set();
|
|
95
|
+
for (const strategy of strategies) {
|
|
96
|
+
if (identities.has(strategy.strategyName)) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Duplicate runtime evidence strategy: ${strategy.strategyName}`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
identities.add(strategy.strategyName);
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
...value,
|
|
105
|
+
strategies
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
var activeRuntimeEvidenceStrategies = (deployment) => deployment.enabled ? deployment.strategies.filter((strategy) => strategy.enabled) : [];
|
|
109
|
+
|
|
110
|
+
// src/lib/runtimeEvidenceArtifacts.ts
|
|
111
|
+
var import_node_crypto = require("crypto");
|
|
112
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
113
|
+
var import_node_path = __toESM(require("path"));
|
|
114
|
+
|
|
115
|
+
// src/lib/runtimeEvidenceProducer.ts
|
|
116
|
+
var import_node_crypto2 = require("crypto");
|
|
117
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
118
|
+
var import_node_path2 = __toESM(require("path"));
|
|
119
|
+
var isRecord2 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
120
|
+
var parseRuntimeEvidenceProducer = (value) => {
|
|
121
|
+
const producer = isRecord2(value) ? value : null;
|
|
122
|
+
const runtimePackageManifest = isRecord2(producer?.runtimePackageManifest) ? producer.runtimePackageManifest : null;
|
|
123
|
+
if (producer?.schemaVersion !== 1 || typeof producer.projectSha !== "string" || !/^[a-f0-9]{40}$/.test(producer.projectSha) || typeof producer.imageDigest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(producer.imageDigest) || runtimePackageManifest?.file !== "runtime-package-manifest.json" || typeof runtimePackageManifest.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(runtimePackageManifest.sha256)) {
|
|
124
|
+
throw new Error("Runtime evidence producer image identity is invalid");
|
|
125
|
+
}
|
|
126
|
+
return producer;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// src/lib/runtimeFeedbackArtifacts.ts
|
|
130
|
+
var RUNTIME_FEEDBACK_MANIFEST_FILE = "manifest.json";
|
|
131
|
+
var RUNTIME_FEEDBACK_REPLAY_FILE = "replay-runtime-evidence.json";
|
|
132
|
+
var RUNTIME_FEEDBACK_LOG_FILE = "replay.log";
|
|
133
|
+
var RUNTIME_FEEDBACK_COMPLETE_FILE = ".complete";
|
|
134
|
+
var isRecord3 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
135
|
+
var sha256 = (value) => (0, import_node_crypto3.createHash)("sha256").update(value).digest("hex");
|
|
136
|
+
var parsePayload = (value, expectedFile) => {
|
|
137
|
+
const payload = isRecord3(value) ? value : null;
|
|
138
|
+
if (payload?.file !== expectedFile || typeof payload.sha256 !== "string" || !/^[a-f0-9]{64}$/.test(payload.sha256) || typeof payload.bytes !== "number" || !Number.isFinite(payload.bytes) || payload.bytes < 0) {
|
|
139
|
+
throw new Error(`Invalid runtime feedback payload: ${expectedFile}`);
|
|
140
|
+
}
|
|
141
|
+
return payload;
|
|
142
|
+
};
|
|
143
|
+
var parseManifest = (value) => {
|
|
144
|
+
const manifest = isRecord3(value) ? value : null;
|
|
145
|
+
const window = isRecord3(manifest?.window) ? manifest.window : null;
|
|
146
|
+
const runtimeEvidence = isRecord3(manifest?.runtimeEvidence) ? manifest.runtimeEvidence : null;
|
|
147
|
+
const safety = isRecord3(manifest?.safety) ? manifest.safety : null;
|
|
148
|
+
const payloads = isRecord3(manifest?.payloads) ? manifest.payloads : null;
|
|
149
|
+
if (manifest?.schemaVersion !== 1 || manifest.reportType !== "runtime-feedback-replay" || typeof manifest.artifactId !== "string" || !manifest.artifactId.trim() || typeof manifest.runId !== "string" || !manifest.runId.trim() || typeof manifest.deploymentId !== "string" || !manifest.deploymentId.trim() || typeof manifest.deploymentCompositionId !== "string" || !/^dc1:[a-f0-9]{16}$/.test(manifest.deploymentCompositionId) || typeof manifest.userName !== "string" || !manifest.userName.trim() || typeof manifest.createdAt !== "number" || typeof window?.startTime !== "number" || typeof window.endTime !== "number" || typeof runtimeEvidence?.artifactId !== "string" || typeof runtimeEvidence.payloadSha256 !== "string" || !/^[a-f0-9]{64}$/.test(runtimeEvidence.payloadSha256) || !Array.isArray(manifest.activeStrategies) || manifest.activeStrategies.length === 0 || !manifest.activeStrategies.every(
|
|
150
|
+
(strategy) => typeof strategy === "string" && strategy.trim()
|
|
151
|
+
) || typeof manifest.cycleCount !== "number" || !Number.isFinite(manifest.cycleCount) || manifest.cycleCount <= 0 || safety?.cacheOnly !== true || safety.externalOrderPlacement !== false || safety.redis !== "isolated" || safety.timescale !== "read_only") {
|
|
152
|
+
throw new Error("Invalid runtime feedback replay manifest");
|
|
153
|
+
}
|
|
154
|
+
const replayEvidence = parsePayload(
|
|
155
|
+
payloads?.replayEvidence,
|
|
156
|
+
RUNTIME_FEEDBACK_REPLAY_FILE
|
|
157
|
+
);
|
|
158
|
+
const log = parsePayload(payloads?.log, RUNTIME_FEEDBACK_LOG_FILE);
|
|
159
|
+
return {
|
|
160
|
+
...manifest,
|
|
161
|
+
producer: parseRuntimeEvidenceProducer(manifest.producer),
|
|
162
|
+
payloads: {
|
|
163
|
+
replayEvidence: {
|
|
164
|
+
...replayEvidence,
|
|
165
|
+
file: RUNTIME_FEEDBACK_REPLAY_FILE
|
|
166
|
+
},
|
|
167
|
+
log: { ...log, file: RUNTIME_FEEDBACK_LOG_FILE }
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
var verifyRuntimeFeedbackReplayBundle = async (bundleDir) => {
|
|
172
|
+
const manifestPath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_MANIFEST_FILE);
|
|
173
|
+
const replayEvidencePath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_REPLAY_FILE);
|
|
174
|
+
const logPath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_LOG_FILE);
|
|
175
|
+
const completePath = import_node_path3.default.join(bundleDir, RUNTIME_FEEDBACK_COMPLETE_FILE);
|
|
176
|
+
const [manifestText, replayPayload, logPayload, completeText] = await Promise.all([
|
|
177
|
+
import_promises3.default.readFile(manifestPath, "utf8"),
|
|
178
|
+
import_promises3.default.readFile(replayEvidencePath),
|
|
179
|
+
import_promises3.default.readFile(logPath),
|
|
180
|
+
import_promises3.default.readFile(completePath, "utf8")
|
|
181
|
+
]);
|
|
182
|
+
const manifest = parseManifest(JSON.parse(manifestText));
|
|
183
|
+
if (completeText.trim() !== manifest.artifactId) {
|
|
184
|
+
throw new Error(`Invalid runtime feedback completion marker: ${bundleDir}`);
|
|
185
|
+
}
|
|
186
|
+
for (const [payload, descriptor] of [
|
|
187
|
+
[replayPayload, manifest.payloads.replayEvidence],
|
|
188
|
+
[logPayload, manifest.payloads.log]
|
|
189
|
+
]) {
|
|
190
|
+
if (payload.byteLength !== descriptor.bytes) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Runtime feedback payload size mismatch: ${descriptor.file}`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
if (sha256(payload) !== descriptor.sha256) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
`Runtime feedback payload checksum mismatch: ${descriptor.file}`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const replayEvidence = JSON.parse(replayPayload.toString("utf8"));
|
|
202
|
+
if (replayEvidence.reportType !== "replay-runtime-evidence") {
|
|
203
|
+
throw new Error("Invalid runtime feedback replay evidence payload");
|
|
204
|
+
}
|
|
205
|
+
const replayWindow = isRecord3(replayEvidence.window) ? replayEvidence.window : null;
|
|
206
|
+
const replay = isRecord3(replayEvidence.replay) ? replayEvidence.replay : null;
|
|
207
|
+
const replayDeployment = parseRuntimeEvidenceDeploymentSnapshot(
|
|
208
|
+
replayEvidence.deployment
|
|
209
|
+
);
|
|
210
|
+
const replayStrategies = activeRuntimeEvidenceStrategies(replayDeployment).map(({ strategyName }) => strategyName).sort();
|
|
211
|
+
if (replayEvidence.userName !== manifest.userName || replayWindow?.startTime !== manifest.window.startTime || replayWindow.endTime !== manifest.window.endTime || replayDeployment.id !== manifest.deploymentId || replayDeployment.deploymentCompositionId !== manifest.deploymentCompositionId || Number(replay?.cycleCount) !== manifest.cycleCount || JSON.stringify(replayStrategies) !== JSON.stringify([...manifest.activeStrategies].sort())) {
|
|
212
|
+
throw new Error("Runtime feedback replay payload does not match manifest");
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
bundleDir,
|
|
216
|
+
manifestPath,
|
|
217
|
+
replayEvidencePath,
|
|
218
|
+
logPath,
|
|
219
|
+
manifest,
|
|
220
|
+
replayEvidence
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/lib/telegramReports.ts
|
|
225
|
+
var import_cli = require("@tradejs/node/cli");
|
|
226
|
+
var TELEGRAM_REPORT_CHUNK_LIMIT = 3900;
|
|
227
|
+
var buildPartHeader = (index, total) => `\u{1F4E9} <b>Part ${index}/${total}</b>`;
|
|
228
|
+
var splitLongLine = (line, limit) => {
|
|
229
|
+
const chunks = [];
|
|
230
|
+
for (let index = 0; index < line.length; index += limit) {
|
|
231
|
+
chunks.push(line.slice(index, index + limit));
|
|
232
|
+
}
|
|
233
|
+
return chunks;
|
|
234
|
+
};
|
|
235
|
+
var splitTelegramReport = (message, limit = TELEGRAM_REPORT_CHUNK_LIMIT) => {
|
|
236
|
+
const normalizedLimit = Math.max(100, Math.floor(limit));
|
|
237
|
+
if (message.length <= normalizedLimit) {
|
|
238
|
+
return [message];
|
|
239
|
+
}
|
|
240
|
+
const chunks = [];
|
|
241
|
+
let current = "";
|
|
242
|
+
const flush = () => {
|
|
243
|
+
if (!current) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
chunks.push(current);
|
|
247
|
+
current = "";
|
|
248
|
+
};
|
|
249
|
+
for (const line of message.split("\n")) {
|
|
250
|
+
const next = current ? `${current}
|
|
251
|
+
${line}` : line;
|
|
252
|
+
if (next.length <= normalizedLimit) {
|
|
253
|
+
current = next;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
flush();
|
|
257
|
+
if (line.length <= normalizedLimit) {
|
|
258
|
+
current = line;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
chunks.push(...splitLongLine(line, normalizedLimit));
|
|
262
|
+
}
|
|
263
|
+
flush();
|
|
264
|
+
return chunks;
|
|
265
|
+
};
|
|
266
|
+
var sendTelegramReport = async (message, options = {}) => {
|
|
267
|
+
const chunks = splitTelegramReport(message);
|
|
268
|
+
const sendAttachments = async () => {
|
|
269
|
+
for (const attachment of options.attachments || []) {
|
|
270
|
+
await (0, import_cli.sendDocumentToTG)(attachment, {
|
|
271
|
+
userName: options.userName
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
if (chunks.length === 1) {
|
|
276
|
+
await (0, import_cli.sendTextToTG)(chunks[0], options);
|
|
277
|
+
await sendAttachments();
|
|
278
|
+
return chunks.length;
|
|
279
|
+
}
|
|
280
|
+
for (const [index, chunk] of chunks.entries()) {
|
|
281
|
+
const header = buildPartHeader(index + 1, chunks.length);
|
|
282
|
+
await (0, import_cli.sendTextToTG)(`${header}
|
|
283
|
+
|
|
284
|
+
${chunk}`, {
|
|
285
|
+
userName: options.userName,
|
|
286
|
+
markup: index === chunks.length - 1 ? options.markup : void 0
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
await sendAttachments();
|
|
290
|
+
return chunks.length;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// src/lib/runtimeFeedbackNotification.ts
|
|
294
|
+
var isRecord4 = (value) => value != null && typeof value === "object" && !Array.isArray(value);
|
|
295
|
+
var asRecord = (value) => isRecord4(value) ? value : {};
|
|
296
|
+
var asArray = (value) => Array.isArray(value) ? value.map(asRecord) : [];
|
|
297
|
+
var finiteNumber = (value, fallback = 0) => {
|
|
298
|
+
const number = Number(value);
|
|
299
|
+
return Number.isFinite(number) ? number : fallback;
|
|
300
|
+
};
|
|
301
|
+
var requiredTimestamp = (value, field) => {
|
|
302
|
+
const timestamp = Number(value);
|
|
303
|
+
if (!Number.isFinite(timestamp)) {
|
|
304
|
+
throw new Error(`Runtime feedback replay is missing ${field}`);
|
|
305
|
+
}
|
|
306
|
+
return timestamp;
|
|
307
|
+
};
|
|
308
|
+
var escapeHtml = (value) => value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
309
|
+
var formatMskDateTime = (timestamp) => new Intl.DateTimeFormat("ru-RU", {
|
|
310
|
+
timeZone: "Europe/Moscow",
|
|
311
|
+
year: "numeric",
|
|
312
|
+
month: "2-digit",
|
|
313
|
+
day: "2-digit",
|
|
314
|
+
hour: "2-digit",
|
|
315
|
+
minute: "2-digit",
|
|
316
|
+
hour12: false
|
|
317
|
+
}).format(new Date(timestamp));
|
|
318
|
+
var formatConnectorName = (value) => {
|
|
319
|
+
const connectorName = String(value ?? "unknown").trim() || "unknown";
|
|
320
|
+
return connectorName.toLowerCase() === "bybit" ? "ByBit" : connectorName;
|
|
321
|
+
};
|
|
322
|
+
var sumRows = (rows, field) => rows.reduce((total, row) => total + finiteNumber(row[field]), 0);
|
|
323
|
+
var buildRuntimeFeedbackTelegramMessage = (replayEvidence) => {
|
|
324
|
+
if (replayEvidence.reportType !== "replay-runtime-evidence") {
|
|
325
|
+
throw new Error("Invalid runtime feedback replay evidence payload");
|
|
326
|
+
}
|
|
327
|
+
const window = asRecord(replayEvidence.window);
|
|
328
|
+
const startTime = requiredTimestamp(window.startTime, "window.startTime");
|
|
329
|
+
const endTime = requiredTimestamp(window.endTime, "window.endTime");
|
|
330
|
+
const deployment = asRecord(replayEvidence.deployment);
|
|
331
|
+
const replay = asRecord(replayEvidence.replay);
|
|
332
|
+
if (!isRecord4(replay.runtimeComparison) || !isRecord4(replay.runtimeComparison.counts) || !Array.isArray(replay.runtimeComparison.rows) || !isRecord4(replay.runtimeComparison.lineage)) {
|
|
333
|
+
throw new Error("Runtime feedback replay comparison is missing");
|
|
334
|
+
}
|
|
335
|
+
const comparison = asRecord(replay.runtimeComparison);
|
|
336
|
+
const comparisonCounts = asRecord(comparison.counts);
|
|
337
|
+
const runtimeCounts = asRecord(asRecord(replayEvidence.runtime).counts);
|
|
338
|
+
const lineage = asRecord(comparison.lineage);
|
|
339
|
+
const rows = asArray(comparison.rows);
|
|
340
|
+
const matched = finiteNumber(comparisonCounts.matched);
|
|
341
|
+
const runtimeOnly = finiteNumber(comparisonCounts.runtimeOnly);
|
|
342
|
+
const backtestOnly = finiteNumber(comparisonCounts.backtestOnly);
|
|
343
|
+
const orderFailed = sumRows(rows, "orderFailed");
|
|
344
|
+
const runtimeEntries = sumRows(rows, "runtimeTrades");
|
|
345
|
+
const backtestEntries = sumRows(rows, "backtestEntries");
|
|
346
|
+
const replayScopes = finiteNumber(lineage.replayScopes);
|
|
347
|
+
const comparableScopes = finiteNumber(lineage.comparableScopes);
|
|
348
|
+
const excludedRuntimeTrades = finiteNumber(lineage.excludedRuntimeTrades);
|
|
349
|
+
const issueRows = rows.filter(
|
|
350
|
+
(row) => finiteNumber(row.runtimeOnly) > 0 || finiteNumber(row.backtestOnly) > 0 || finiteNumber(row.orderFailed) > 0
|
|
351
|
+
);
|
|
352
|
+
const lines = [
|
|
353
|
+
"\u{1F9EA} <b>TradeJS runtime parity</b>",
|
|
354
|
+
"",
|
|
355
|
+
"\u{1F552} <b>Window</b>",
|
|
356
|
+
`<b>${escapeHtml(formatMskDateTime(startTime))} - ${escapeHtml(formatMskDateTime(endTime))} MSK</b>`,
|
|
357
|
+
"",
|
|
358
|
+
`\u{1F50C} Connector: <b>${escapeHtml(formatConnectorName(deployment.connectorName ?? deployment.provider))}</b>`,
|
|
359
|
+
"\u{1F9EC} Source: <b>verified runtime feedback</b>",
|
|
360
|
+
`\u{1F4E6} Deployment: <b>${escapeHtml(String(deployment.id ?? "unknown"))}</b>`,
|
|
361
|
+
`\u{1F510} Composition: <code>${escapeHtml(String(deployment.deploymentCompositionId ?? "unknown"))}</code>`,
|
|
362
|
+
"",
|
|
363
|
+
"\u{1F4CC} <b>Overview</b>",
|
|
364
|
+
`\u2022 Runtime evidence: trades=<b>${finiteNumber(runtimeCounts.trades)}</b>, signals=<b>${finiteNumber(runtimeCounts.signals)}</b>, evaluations=<b>${finiteNumber(runtimeCounts.evaluations)}</b>`,
|
|
365
|
+
`\u2022 Comparable entries: runtime=<b>${runtimeEntries}</b> / backtest=<b>${backtestEntries}</b>`,
|
|
366
|
+
`\u2022 Matched: <b>${matched}</b> / order failed: <b>${orderFailed}</b>`,
|
|
367
|
+
`\u2022 Runtime only: <b>${runtimeOnly}</b> / Backtest only: <b>${backtestOnly}</b>`,
|
|
368
|
+
`\u2022 Lineage scopes: <b>${comparableScopes} / ${replayScopes}</b>`
|
|
369
|
+
];
|
|
370
|
+
if (excludedRuntimeTrades > 0) {
|
|
371
|
+
lines.push(
|
|
372
|
+
`\u2022 Excluded runtime trades outside comparable lineage: <b>${excludedRuntimeTrades}</b>`
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
if (issueRows.length) {
|
|
376
|
+
lines.push("", "\u{1F4CA} <b>Strategy issues</b>");
|
|
377
|
+
for (const row of issueRows.slice(0, 10)) {
|
|
378
|
+
const issues = [
|
|
379
|
+
finiteNumber(row.orderFailed) > 0 ? `orderFailed=${finiteNumber(row.orderFailed)}` : null,
|
|
380
|
+
finiteNumber(row.runtimeOnly) > 0 ? `runtimeOnly=${finiteNumber(row.runtimeOnly)}` : null,
|
|
381
|
+
finiteNumber(row.backtestOnly) > 0 ? `backtestOnly=${finiteNumber(row.backtestOnly)}` : null
|
|
382
|
+
].filter((value) => value != null);
|
|
383
|
+
lines.push(
|
|
384
|
+
`\u2022 ${escapeHtml(String(row.strategyName ?? "[unknown]"))}: ${issues.join(", ")}`
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
if (issueRows.length > 10) {
|
|
388
|
+
lines.push(`... <b>${issueRows.length - 10}</b> more`);
|
|
389
|
+
}
|
|
390
|
+
} else if (rows.length) {
|
|
391
|
+
lines.push(
|
|
392
|
+
"",
|
|
393
|
+
`\u{1F4CA} <b>Strategies</b>: clean <b>${rows.length}</b> / total <b>${rows.length}</b>`
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
return lines.join("\n");
|
|
397
|
+
};
|
|
398
|
+
var notifyRuntimeFeedbackBundle = async ({
|
|
399
|
+
bundleDir,
|
|
400
|
+
send = sendTelegramReport
|
|
401
|
+
}) => {
|
|
402
|
+
const verified = await verifyRuntimeFeedbackReplayBundle(bundleDir);
|
|
403
|
+
const message = buildRuntimeFeedbackTelegramMessage(verified.replayEvidence);
|
|
404
|
+
await send(message, { userName: verified.manifest.userName });
|
|
405
|
+
return {
|
|
406
|
+
artifactId: verified.manifest.artifactId,
|
|
407
|
+
userName: verified.manifest.userName,
|
|
408
|
+
message
|
|
409
|
+
};
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// src/scripts/runtimeFeedbackNotify.ts
|
|
413
|
+
import_args.default.option("bundle", "Verified runtime feedback replay bundle directory");
|
|
414
|
+
import_args.default.option("dryRun", "Verify and print the message without sending it", false);
|
|
415
|
+
var flags = import_args.default.parse(process.argv);
|
|
416
|
+
var projectRoot = String(process.env.PROJECT_CWD || process.cwd()).trim() || process.cwd();
|
|
417
|
+
var runtimeFeedbackNotify = async () => {
|
|
418
|
+
const bundle = String(flags.bundle ?? "").trim();
|
|
419
|
+
if (!bundle) {
|
|
420
|
+
throw new Error("Provide --bundle for runtime feedback notification.");
|
|
421
|
+
}
|
|
422
|
+
const bundleDir = import_node_path4.default.resolve(projectRoot, bundle);
|
|
423
|
+
if (flags.dryRun) {
|
|
424
|
+
const verified = await verifyRuntimeFeedbackReplayBundle(bundleDir);
|
|
425
|
+
console.log(buildRuntimeFeedbackTelegramMessage(verified.replayEvidence));
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const result = await notifyRuntimeFeedbackBundle({ bundleDir });
|
|
429
|
+
console.log(
|
|
430
|
+
import_chalk.default.green(`Runtime feedback notification sent: ${result.artifactId}`)
|
|
431
|
+
);
|
|
432
|
+
};
|
|
433
|
+
var main = runtimeFeedbackNotify;
|
|
434
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
435
|
+
0 && (module.exports = {
|
|
436
|
+
main,
|
|
437
|
+
runtimeFeedbackNotify
|
|
438
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/cli",
|
|
3
|
-
"version": "3.1.28-beta.
|
|
3
|
+
"version": "3.1.28-beta.258",
|
|
4
4
|
"description": "Official CLI for the TradeJS TypeScript framework: infra setup, backtests, signals, bots, and ML workflows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"tradejs": "dist/cli.js"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@tradejs/connectors": "^3.1.28-beta.
|
|
40
|
-
"@tradejs/core": "^3.1.28-beta.
|
|
41
|
-
"@tradejs/indicators": "^3.1.28-beta.
|
|
42
|
-
"@tradejs/infra": "^3.1.28-beta.
|
|
43
|
-
"@tradejs/node": "^3.1.28-beta.
|
|
44
|
-
"@tradejs/strategy-kit": "3.0.
|
|
45
|
-
"@tradejs/types": "^3.1.28-beta.
|
|
39
|
+
"@tradejs/connectors": "^3.1.28-beta.258",
|
|
40
|
+
"@tradejs/core": "^3.1.28-beta.258",
|
|
41
|
+
"@tradejs/indicators": "^3.1.28-beta.258",
|
|
42
|
+
"@tradejs/infra": "^3.1.28-beta.258",
|
|
43
|
+
"@tradejs/node": "^3.1.28-beta.258",
|
|
44
|
+
"@tradejs/strategy-kit": "3.0.6",
|
|
45
|
+
"@tradejs/types": "^3.1.28-beta.258",
|
|
46
46
|
"args": "^5.0.3",
|
|
47
47
|
"bcryptjs": "^2.4.3",
|
|
48
48
|
"chalk": "4.1.2",
|