@tradejs/infra 2.0.18 → 2.0.20
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/ai.js +39 -74
- package/dist/ai.mjs +37 -74
- package/dist/chunk-2CZREG43.mjs +112 -0
- package/dist/chunk-DFMKDB2R.mjs +1285 -0
- package/dist/chunk-I2J6YDBD.mjs +910 -0
- package/dist/chunk-NWXFWTWU.mjs +1114 -0
- package/dist/chunk-SZQB7ER5.mjs +492 -0
- package/dist/chunk-YVIHTUV5.mjs +286 -0
- package/dist/coreResearch.d.mts +20 -0
- package/dist/coreResearch.d.ts +20 -0
- package/dist/coreResearch.js +89 -0
- package/dist/coreResearch.mjs +48 -0
- package/dist/internal-2coHaaos.d.mts +26 -0
- package/dist/internal-2coHaaos.d.ts +26 -0
- package/dist/ml.mjs +3 -3
- package/dist/runtimeDeployments.d.mts +10 -0
- package/dist/runtimeDeployments.d.ts +10 -0
- package/dist/runtimeDeployments.js +447 -0
- package/dist/runtimeDeployments.mjs +81 -0
- package/dist/runtimeStrategyConfigs.d.mts +28 -0
- package/dist/runtimeStrategyConfigs.d.ts +28 -0
- package/dist/runtimeStrategyConfigs.js +425 -0
- package/dist/runtimeStrategyConfigs.mjs +89 -0
- package/dist/strategyReleaseEvidence.d.mts +12 -0
- package/dist/strategyReleaseEvidence.d.ts +12 -0
- package/dist/strategyReleaseEvidence.js +120 -0
- package/dist/strategyReleaseEvidence.mjs +90 -0
- package/dist/timescale/candles.d.mts +38 -0
- package/dist/timescale/candles.d.ts +38 -0
- package/dist/timescale/candles.js +408 -0
- package/dist/timescale/candles.mjs +21 -0
- package/dist/timescale/client.d.mts +4 -0
- package/dist/timescale/client.d.ts +4 -0
- package/dist/timescale/client.js +109 -0
- package/dist/timescale/client.mjs +12 -0
- package/dist/timescale/derivatives.d.mts +90 -0
- package/dist/timescale/derivatives.d.ts +90 -0
- package/dist/timescale/derivatives.js +1270 -0
- package/dist/timescale/derivatives.mjs +26 -0
- package/dist/timescale/hyperliquidWhales.d.mts +149 -0
- package/dist/timescale/hyperliquidWhales.d.ts +149 -0
- package/dist/timescale/hyperliquidWhales.js +1893 -0
- package/dist/timescale/hyperliquidWhales.mjs +30 -0
- package/dist/timescale/marketContext.d.mts +188 -0
- package/dist/timescale/marketContext.d.ts +188 -0
- package/dist/timescale/marketContext.js +2091 -0
- package/dist/timescale/marketContext.mjs +60 -0
- package/dist/timescale/spread.d.mts +11 -0
- package/dist/timescale/spread.d.ts +11 -0
- package/dist/timescale/spread.js +215 -0
- package/dist/timescale/spread.mjs +11 -0
- package/dist/timescale.d.mts +9 -476
- package/dist/timescale.d.ts +9 -476
- package/dist/timescale.js +2121 -2112
- package/dist/timescale.mjs +73 -4070
- package/dist/tradingAccounts.d.mts +2 -8
- package/dist/tradingAccounts.d.ts +2 -8
- package/dist/tradingAccounts.js +0 -71
- package/dist/tradingAccounts.mjs +0 -65
- package/dist/values-BrvcmnfM.d.mts +6 -0
- package/dist/values-BrvcmnfM.d.ts +6 -0
- package/package.json +53 -2
|
@@ -0,0 +1,447 @@
|
|
|
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/runtimeDeployments.ts
|
|
31
|
+
var runtimeDeployments_exports = {};
|
|
32
|
+
__export(runtimeDeployments_exports, {
|
|
33
|
+
deleteRuntimeDeployment: () => deleteRuntimeDeployment,
|
|
34
|
+
getRuntimeDeployment: () => getRuntimeDeployment,
|
|
35
|
+
getRuntimeDeploymentHeartbeat: () => getRuntimeDeploymentHeartbeat,
|
|
36
|
+
listRuntimeDeployments: () => listRuntimeDeployments,
|
|
37
|
+
saveRuntimeDeployment: () => saveRuntimeDeployment,
|
|
38
|
+
saveRuntimeDeploymentHeartbeat: () => saveRuntimeDeploymentHeartbeat
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(runtimeDeployments_exports);
|
|
41
|
+
|
|
42
|
+
// src/redis.ts
|
|
43
|
+
var import_ioredis = __toESM(require("ioredis"));
|
|
44
|
+
var TTL_1D = 86400;
|
|
45
|
+
var SCREENSHOT_TOKEN_TTL_SECONDS = 15 * 60;
|
|
46
|
+
var toJson = (value) => JSON.stringify(value);
|
|
47
|
+
var logger = {
|
|
48
|
+
log: (level, message, ...args) => {
|
|
49
|
+
const method = level === "error" ? "error" : level === "warn" ? "warn" : "log";
|
|
50
|
+
console[method](`[infra:redis] ${message}`, ...args);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var redisConnectionWarningShown = false;
|
|
54
|
+
var redisUnavailable = false;
|
|
55
|
+
var isRedisConnectivityError = (error) => {
|
|
56
|
+
const errorText = [error.name, error.message, String(error)].join(" ");
|
|
57
|
+
return /ECONNREFUSED|ECONNRESET|ECONNABORTED|EPIPE|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|MaxRetriesPerRequestError|Connection is closed|Stream isn't writeable/i.test(
|
|
58
|
+
errorText
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
var toNonNegativeInt = (value, fallback) => {
|
|
62
|
+
const parsed = Number.parseInt(String(value ?? ""), 10);
|
|
63
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
64
|
+
};
|
|
65
|
+
var toPositiveInt = (value, fallback) => {
|
|
66
|
+
const parsed = Number.parseInt(String(value ?? ""), 10);
|
|
67
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
68
|
+
};
|
|
69
|
+
var markRedisUnavailable = (error) => {
|
|
70
|
+
redisUnavailable = true;
|
|
71
|
+
if (redisConnectionWarningShown) return;
|
|
72
|
+
redisConnectionWarningShown = true;
|
|
73
|
+
logger.log(
|
|
74
|
+
"warn",
|
|
75
|
+
"Redis is unavailable: %s. Cache-dependent features are temporarily disabled.",
|
|
76
|
+
error.message
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
var getRedis = () => {
|
|
80
|
+
if (!global.__redis__) {
|
|
81
|
+
const host = process.env.REDIS_HOST || "127.0.0.1";
|
|
82
|
+
const port = toPositiveInt(process.env.REDIS_PORT, 6379);
|
|
83
|
+
const connectTimeout = toPositiveInt(
|
|
84
|
+
process.env.REDIS_CONNECT_TIMEOUT_MS,
|
|
85
|
+
3e3
|
|
86
|
+
);
|
|
87
|
+
const maxRetriesPerRequest = toNonNegativeInt(
|
|
88
|
+
process.env.REDIS_MAX_RETRIES_PER_REQUEST,
|
|
89
|
+
1
|
|
90
|
+
);
|
|
91
|
+
global.__redis__ = new import_ioredis.default({
|
|
92
|
+
host,
|
|
93
|
+
port,
|
|
94
|
+
connectTimeout,
|
|
95
|
+
maxRetriesPerRequest,
|
|
96
|
+
enableOfflineQueue: false,
|
|
97
|
+
retryStrategy: (attempt) => Math.min(attempt * 200, 2e3)
|
|
98
|
+
});
|
|
99
|
+
global.__redis__.on("error", (error) => {
|
|
100
|
+
if (isRedisConnectivityError(error)) {
|
|
101
|
+
markRedisUnavailable(error);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
logger.log("error", "Redis client error: %s", String(error));
|
|
105
|
+
});
|
|
106
|
+
global.__redis__.on("ready", () => {
|
|
107
|
+
redisUnavailable = false;
|
|
108
|
+
if (redisConnectionWarningShown) {
|
|
109
|
+
redisConnectionWarningShown = false;
|
|
110
|
+
logger.log("info", "Redis connection restored");
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return global.__redis__;
|
|
115
|
+
};
|
|
116
|
+
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
117
|
+
var getRedisStatus = (redis) => String(redis.status ?? "ready");
|
|
118
|
+
var waitForRedisReady = async (redis) => {
|
|
119
|
+
if (getRedisStatus(redis) === "ready") {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
const readyTimeoutMs = toPositiveInt(
|
|
123
|
+
process.env.REDIS_READY_TIMEOUT_MS,
|
|
124
|
+
toPositiveInt(process.env.REDIS_CONNECT_TIMEOUT_MS, 3e3)
|
|
125
|
+
);
|
|
126
|
+
const startedAt = Date.now();
|
|
127
|
+
while (Date.now() - startedAt < readyTimeoutMs) {
|
|
128
|
+
if (getRedisStatus(redis) === "ready") {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
if (getRedisStatus(redis) === "end") {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
await sleep(50);
|
|
135
|
+
}
|
|
136
|
+
return getRedisStatus(redis) === "ready";
|
|
137
|
+
};
|
|
138
|
+
var getReadyRedis = async () => {
|
|
139
|
+
if (redisUnavailable) return null;
|
|
140
|
+
const redis = getRedis();
|
|
141
|
+
const ready = await waitForRedisReady(redis);
|
|
142
|
+
if (ready) {
|
|
143
|
+
return redis;
|
|
144
|
+
}
|
|
145
|
+
markRedisUnavailable(
|
|
146
|
+
new Error(`Redis is not ready (status=${getRedisStatus(redis)})`)
|
|
147
|
+
);
|
|
148
|
+
return null;
|
|
149
|
+
};
|
|
150
|
+
var toResultString = (result) => {
|
|
151
|
+
if (result == null) return null;
|
|
152
|
+
if (typeof result === "string") return result;
|
|
153
|
+
if (Buffer.isBuffer(result)) return result.toString("utf8");
|
|
154
|
+
return String(result);
|
|
155
|
+
};
|
|
156
|
+
var DEFAULT_OPTIONS = {
|
|
157
|
+
expire: TTL_1D
|
|
158
|
+
};
|
|
159
|
+
var parseJsonOrDeleteKey = async (redis, key, raw, fallback) => {
|
|
160
|
+
try {
|
|
161
|
+
return JSON.parse(raw);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
logger.log("error", "failed JSON.parse(%s): %s", key, String(e));
|
|
164
|
+
await redis.del(key);
|
|
165
|
+
return fallback;
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
var getKeys = async (prefix) => {
|
|
169
|
+
if (redisUnavailable) return [];
|
|
170
|
+
const redis = await getReadyRedis();
|
|
171
|
+
if (!redis) return [];
|
|
172
|
+
const keys = [];
|
|
173
|
+
try {
|
|
174
|
+
let cursor = "0";
|
|
175
|
+
do {
|
|
176
|
+
const [nextCursor, batch] = await redis.scan(
|
|
177
|
+
cursor,
|
|
178
|
+
"MATCH",
|
|
179
|
+
`${prefix}*`,
|
|
180
|
+
"COUNT",
|
|
181
|
+
"200"
|
|
182
|
+
);
|
|
183
|
+
cursor = nextCursor;
|
|
184
|
+
for (const key of batch) {
|
|
185
|
+
if (key.startsWith(prefix)) {
|
|
186
|
+
keys.push(key);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} while (cursor !== "0");
|
|
190
|
+
} catch (e) {
|
|
191
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
192
|
+
markRedisUnavailable(e);
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
logger.log("warn", "failed SCAN for %s: %s", prefix, String(e));
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
return keys;
|
|
199
|
+
};
|
|
200
|
+
var getData = async (key, fallback = []) => {
|
|
201
|
+
if (redisUnavailable) return fallback;
|
|
202
|
+
const redis = await getReadyRedis();
|
|
203
|
+
if (!redis) return fallback;
|
|
204
|
+
try {
|
|
205
|
+
const rawJson = await redis.call("JSON.GET", key);
|
|
206
|
+
const raw = toResultString(rawJson);
|
|
207
|
+
if (raw == null) return fallback;
|
|
208
|
+
return parseJsonOrDeleteKey(redis, key, raw, fallback);
|
|
209
|
+
} catch (e) {
|
|
210
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
211
|
+
markRedisUnavailable(e);
|
|
212
|
+
return fallback;
|
|
213
|
+
}
|
|
214
|
+
logger.log(
|
|
215
|
+
"error",
|
|
216
|
+
"failed JSON.GET %s: %s (fallback to GET)",
|
|
217
|
+
key,
|
|
218
|
+
String(e)
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
const raw = await redis.get(key);
|
|
223
|
+
if (raw == null) return fallback;
|
|
224
|
+
return parseJsonOrDeleteKey(redis, key, raw, fallback);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
227
|
+
markRedisUnavailable(e);
|
|
228
|
+
return fallback;
|
|
229
|
+
}
|
|
230
|
+
logger.log("error", "failed GET %s: %s", key, String(e));
|
|
231
|
+
return fallback;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var delKey = async (key) => {
|
|
235
|
+
return delKeyWithOptions(key);
|
|
236
|
+
};
|
|
237
|
+
var RedisWriteBlockedError = class extends Error {
|
|
238
|
+
constructor(message) {
|
|
239
|
+
super(message);
|
|
240
|
+
this.name = "RedisWriteBlockedError";
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var delKeyWithOptions = async (key, options = {}) => {
|
|
244
|
+
if (redisUnavailable) return false;
|
|
245
|
+
const { raiseOnMisconf = false } = options;
|
|
246
|
+
const redis = await getReadyRedis();
|
|
247
|
+
if (!redis) return false;
|
|
248
|
+
try {
|
|
249
|
+
const result = await redis.del(key);
|
|
250
|
+
if (result === 1) {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
} catch (e) {
|
|
255
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
256
|
+
markRedisUnavailable(e);
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
const msg = String(e);
|
|
260
|
+
if (raiseOnMisconf && msg.includes("MISCONF")) {
|
|
261
|
+
throw new RedisWriteBlockedError(msg);
|
|
262
|
+
}
|
|
263
|
+
logger.log("error", "failed DEL %s: %s", key, String(e));
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
var setData = async (key, data, options = {}) => {
|
|
268
|
+
if (redisUnavailable) return;
|
|
269
|
+
const { expire } = { ...DEFAULT_OPTIONS, ...options };
|
|
270
|
+
const redis = await getReadyRedis();
|
|
271
|
+
if (!redis) return;
|
|
272
|
+
const value = toJson(data);
|
|
273
|
+
try {
|
|
274
|
+
await redis.call("JSON.SET", key, "$", value);
|
|
275
|
+
if (expire) {
|
|
276
|
+
await redis.expire(key, expire);
|
|
277
|
+
}
|
|
278
|
+
} catch (e) {
|
|
279
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
280
|
+
markRedisUnavailable(e);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
logger.log(
|
|
284
|
+
"error",
|
|
285
|
+
"failed JSON.SET %s: %s (fallback to SET)",
|
|
286
|
+
key,
|
|
287
|
+
String(e)
|
|
288
|
+
);
|
|
289
|
+
try {
|
|
290
|
+
if (expire) {
|
|
291
|
+
await redis.set(key, value, "EX", expire);
|
|
292
|
+
} else {
|
|
293
|
+
await redis.set(key, value);
|
|
294
|
+
}
|
|
295
|
+
} catch (e2) {
|
|
296
|
+
if (e2 instanceof Error && isRedisConnectivityError(e2)) {
|
|
297
|
+
markRedisUnavailable(e2);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
logger.log("error", "failed SET %s: %s", key, String(e2));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
var redisKeys = {
|
|
305
|
+
users: () => "users:index:",
|
|
306
|
+
user: (userName) => `users:index:${userName}`,
|
|
307
|
+
tradingAccounts: (userName) => `users:${userName}:trading-accounts:`,
|
|
308
|
+
tradingAccount: (userName, accountId) => `users:${userName}:trading-accounts:${accountId}`,
|
|
309
|
+
runtimeDeployments: (userName) => `users:${userName}:runtime:deployments:`,
|
|
310
|
+
runtimeDeployment: (userName, deploymentId) => `users:${userName}:runtime:deployments:${deploymentId}`,
|
|
311
|
+
runtimeDeploymentHeartbeat: (userName, deploymentId) => `users:${userName}:runtime:deployments:${deploymentId}:heartbeat`,
|
|
312
|
+
bots: (userName) => `users:${userName}:bots`,
|
|
313
|
+
botsPrefix: () => "users:",
|
|
314
|
+
bot: (userName, botId) => `users:${userName}:bots:${botId}`,
|
|
315
|
+
backtestConfig: (userName, config) => `users:${userName}:backtests:configs:${config}`,
|
|
316
|
+
strategies: (userName) => `users:${userName}:strategies`,
|
|
317
|
+
strategyConfig: (userName, strategyName, configId = "config") => `users:${userName}:strategies:${strategyName}:${configId}`,
|
|
318
|
+
strategyResults: (userName, strategyName) => `users:${userName}:strategies:${strategyName}:results`,
|
|
319
|
+
strategyCharts: (userName, mode) => `users:${userName}:strategies:charts:${mode}`,
|
|
320
|
+
strategyChartCards: (userName, mode) => `users:${userName}:strategies:charts:${mode}:cards:`,
|
|
321
|
+
strategyChartCard: (userName, mode, cardId) => `users:${userName}:strategies:charts:${mode}:cards:${cardId}`,
|
|
322
|
+
tests: (userName, strategyName) => strategyName ? `users:${userName}:tests:${strategyName}` : `users:${userName}:tests:`,
|
|
323
|
+
testOrders: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:orders`,
|
|
324
|
+
testConfig: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:config`,
|
|
325
|
+
testStat: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:stat`,
|
|
326
|
+
testSummaries: (userName) => `users:${userName}:tests:index:summary`,
|
|
327
|
+
cacheChunk: (userName, chunkId) => `users:${userName}:cache:tests:chunks:${chunkId}`,
|
|
328
|
+
cacheOrders: (userName, orderLogId) => `users:${userName}:cache:tests:orders:${orderLogId}`,
|
|
329
|
+
cachePositions: (userName, orderLogId) => `users:${userName}:cache:tests:positions:${orderLogId}`,
|
|
330
|
+
tickerUniverse: (userName, connectorName, universe, accountId) => universe || accountId ? `users:${userName}:cache:tickers:${connectorName}:${universe ?? "crypto"}:${accountId ?? "default"}` : `users:${userName}:cache:tickers:${connectorName}`,
|
|
331
|
+
signal: (symbol, signalId) => `signals:${symbol}:${signalId}`,
|
|
332
|
+
signalsBySymbol: (symbol) => `signals:${symbol}:`,
|
|
333
|
+
storeSignal: (symbol, signalId) => `store:signals:${symbol}:${signalId}`,
|
|
334
|
+
runtimeSignals: (userName) => `users:${userName}:runtime:signals:`,
|
|
335
|
+
runtimeSignal: (userName, signalId) => `users:${userName}:runtime:signals:${signalId}`,
|
|
336
|
+
runtimeSignalBuckets: (userName) => `users:${userName}:runtime:signals:days:`,
|
|
337
|
+
runtimeSignalBucket: (userName, dayKey, strategyName) => `users:${userName}:runtime:signals:days:${dayKey}:${strategyName}`,
|
|
338
|
+
runtimeSignalEvaluations: (userName) => `users:${userName}:runtime:signal-evaluations:`,
|
|
339
|
+
runtimeSignalEvaluation: (userName, evaluationId) => `users:${userName}:runtime:signal-evaluations:${evaluationId}`,
|
|
340
|
+
runtimeSignalEvaluationBuckets: (userName) => `users:${userName}:runtime:signal-evaluations:days:`,
|
|
341
|
+
runtimeSignalEvaluationBucket: (userName, dayKey, strategyName) => `users:${userName}:runtime:signal-evaluations:days:${dayKey}:${strategyName}`,
|
|
342
|
+
runtimeSignalEvaluationStatsBuckets: (userName) => `users:${userName}:runtime:signal-evaluation-stats:days:`,
|
|
343
|
+
runtimeSignalEvaluationStatsBucket: (userName, dayKey, strategyName) => `users:${userName}:runtime:signal-evaluation-stats:days:${dayKey}:${strategyName}`,
|
|
344
|
+
runtimeLineageScopeBucket: (userName, dayKey) => `users:${userName}:runtime:lineage-scopes:days:${dayKey}`,
|
|
345
|
+
runtimeTrades: (userName) => `users:${userName}:runtime:trade-records:`,
|
|
346
|
+
runtimeTrade: (userName, orderId) => `users:${userName}:runtime:trade-records:${orderId}`,
|
|
347
|
+
runtimeTradeBuckets: (userName) => `users:${userName}:runtime:trade-records:days:`,
|
|
348
|
+
runtimeTradeBucket: (userName, dayKey) => `users:${userName}:runtime:trade-records:days:${dayKey}`,
|
|
349
|
+
runtimeClosedTradeBuckets: (userName) => `users:${userName}:runtime:closed-trade-records:days:`,
|
|
350
|
+
runtimeClosedTradeBucket: (userName, dayKey) => `users:${userName}:runtime:closed-trade-records:days:${dayKey}`,
|
|
351
|
+
runtimeActiveTrades: (userName) => `users:${userName}:runtime:active-trades:`,
|
|
352
|
+
runtimeActiveTrade: (userName, symbol, scopeId) => scopeId ? `users:${userName}:runtime:active-trades:${scopeId}:${symbol}` : `users:${userName}:runtime:active-trades:${symbol}`,
|
|
353
|
+
aiChatHistory: (userName, symbolKey) => `users:${userName}:ai:chats:${symbolKey}`,
|
|
354
|
+
analysis: (symbol, signalId) => `analysis:${symbol}:${signalId}`,
|
|
355
|
+
screenshotSessionToken: (token) => `auth:screenshot:${token}`,
|
|
356
|
+
backtestResults: (userName, config, timestamp) => `users:${userName}:backtests:results:${config}:${timestamp}`,
|
|
357
|
+
backtestJobs: (userName) => `users:${userName}:backtests:jobs:`,
|
|
358
|
+
backtestJob: (userName, jobId) => `users:${userName}:backtests:jobs:${jobId}`,
|
|
359
|
+
backtestRuns: (userName) => `users:${userName}:backtests:runs:`,
|
|
360
|
+
backtestRun: (userName, runId) => `users:${userName}:backtests:runs:${runId}`,
|
|
361
|
+
backtestRunResults: (userName, runId) => `users:${userName}:backtests:runs:${runId}:results`,
|
|
362
|
+
backtestLatestRun: (userName, config) => `users:${userName}:backtests:latest:${config}`,
|
|
363
|
+
researchRuns: (userName) => `users:${userName}:research:runs:`,
|
|
364
|
+
researchRun: (userName, runId) => `users:${userName}:research:runs:${runId}`,
|
|
365
|
+
researchLatestRun: (userName, strategyName) => `users:${userName}:research:latest:${strategyName}`,
|
|
366
|
+
mlSignalsByStrategy: (strategyName) => `ml:${strategyName}:signals:`,
|
|
367
|
+
mlSignals: () => "ml:",
|
|
368
|
+
mlSignal: (strategyName, signalId) => `ml:${strategyName}:signals:${signalId}`,
|
|
369
|
+
mlResultsByStrategy: (strategyName) => `ml:${strategyName}:results:`,
|
|
370
|
+
mlResults: () => "ml:",
|
|
371
|
+
mlResult: (strategyName, signalId) => `ml:${strategyName}:results:${signalId}`
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
// src/runtimeDeployments.ts
|
|
375
|
+
var normalizeId = (value, label) => {
|
|
376
|
+
const normalized = value.trim().toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
377
|
+
if (!normalized) throw new Error(`${label} is required`);
|
|
378
|
+
return normalized;
|
|
379
|
+
};
|
|
380
|
+
var isRuntimeDeployment = (value) => Boolean(
|
|
381
|
+
value && typeof value === "object" && typeof value.id === "string" && typeof value.accountId === "string"
|
|
382
|
+
);
|
|
383
|
+
var listRuntimeDeployments = async (userName) => {
|
|
384
|
+
const keys = await getKeys(redisKeys.runtimeDeployments(userName));
|
|
385
|
+
const values = await Promise.all(keys.map((key) => getData(key, null)));
|
|
386
|
+
return values.filter(isRuntimeDeployment).sort((left, right) => left.label.localeCompare(right.label));
|
|
387
|
+
};
|
|
388
|
+
var getRuntimeDeployment = async (userName, deploymentId) => {
|
|
389
|
+
const normalizedId = normalizeId(deploymentId, "Deployment id");
|
|
390
|
+
const value = await getData(
|
|
391
|
+
redisKeys.runtimeDeployment(userName, normalizedId),
|
|
392
|
+
null
|
|
393
|
+
);
|
|
394
|
+
return isRuntimeDeployment(value) ? value : null;
|
|
395
|
+
};
|
|
396
|
+
var saveRuntimeDeployment = async (userName, deployment) => {
|
|
397
|
+
const normalized = {
|
|
398
|
+
...deployment,
|
|
399
|
+
id: normalizeId(deployment.id, "Deployment id"),
|
|
400
|
+
label: deployment.label.trim(),
|
|
401
|
+
provider: deployment.provider.trim().toLowerCase(),
|
|
402
|
+
accountId: normalizeId(deployment.accountId, "Account id")
|
|
403
|
+
};
|
|
404
|
+
await setData(
|
|
405
|
+
redisKeys.runtimeDeployment(userName, normalized.id),
|
|
406
|
+
normalized,
|
|
407
|
+
{ expire: 0 }
|
|
408
|
+
);
|
|
409
|
+
return normalized;
|
|
410
|
+
};
|
|
411
|
+
var deleteRuntimeDeployment = async (userName, deploymentId) => {
|
|
412
|
+
const normalizedId = normalizeId(deploymentId, "Deployment id");
|
|
413
|
+
await Promise.all([
|
|
414
|
+
delKey(redisKeys.runtimeDeployment(userName, normalizedId)),
|
|
415
|
+
delKey(redisKeys.runtimeDeploymentHeartbeat(userName, normalizedId))
|
|
416
|
+
]);
|
|
417
|
+
};
|
|
418
|
+
var getRuntimeDeploymentHeartbeat = async (userName, deploymentId) => {
|
|
419
|
+
const value = await getData(
|
|
420
|
+
redisKeys.runtimeDeploymentHeartbeat(
|
|
421
|
+
userName,
|
|
422
|
+
normalizeId(deploymentId, "Deployment id")
|
|
423
|
+
),
|
|
424
|
+
null
|
|
425
|
+
);
|
|
426
|
+
return value && typeof value === "object" ? value : null;
|
|
427
|
+
};
|
|
428
|
+
var saveRuntimeDeploymentHeartbeat = async (userName, heartbeat) => {
|
|
429
|
+
await setData(
|
|
430
|
+
redisKeys.runtimeDeploymentHeartbeat(
|
|
431
|
+
userName,
|
|
432
|
+
normalizeId(heartbeat.deploymentId, "Deployment id")
|
|
433
|
+
),
|
|
434
|
+
heartbeat,
|
|
435
|
+
{ expire: 0 }
|
|
436
|
+
);
|
|
437
|
+
return heartbeat;
|
|
438
|
+
};
|
|
439
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
440
|
+
0 && (module.exports = {
|
|
441
|
+
deleteRuntimeDeployment,
|
|
442
|
+
getRuntimeDeployment,
|
|
443
|
+
getRuntimeDeploymentHeartbeat,
|
|
444
|
+
listRuntimeDeployments,
|
|
445
|
+
saveRuntimeDeployment,
|
|
446
|
+
saveRuntimeDeploymentHeartbeat
|
|
447
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
delKey,
|
|
3
|
+
getData,
|
|
4
|
+
getKeys,
|
|
5
|
+
redisKeys,
|
|
6
|
+
setData
|
|
7
|
+
} from "./chunk-6ZKAUA4Q.mjs";
|
|
8
|
+
|
|
9
|
+
// src/runtimeDeployments.ts
|
|
10
|
+
var normalizeId = (value, label) => {
|
|
11
|
+
const normalized = value.trim().toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
12
|
+
if (!normalized) throw new Error(`${label} is required`);
|
|
13
|
+
return normalized;
|
|
14
|
+
};
|
|
15
|
+
var isRuntimeDeployment = (value) => Boolean(
|
|
16
|
+
value && typeof value === "object" && typeof value.id === "string" && typeof value.accountId === "string"
|
|
17
|
+
);
|
|
18
|
+
var listRuntimeDeployments = async (userName) => {
|
|
19
|
+
const keys = await getKeys(redisKeys.runtimeDeployments(userName));
|
|
20
|
+
const values = await Promise.all(keys.map((key) => getData(key, null)));
|
|
21
|
+
return values.filter(isRuntimeDeployment).sort((left, right) => left.label.localeCompare(right.label));
|
|
22
|
+
};
|
|
23
|
+
var getRuntimeDeployment = async (userName, deploymentId) => {
|
|
24
|
+
const normalizedId = normalizeId(deploymentId, "Deployment id");
|
|
25
|
+
const value = await getData(
|
|
26
|
+
redisKeys.runtimeDeployment(userName, normalizedId),
|
|
27
|
+
null
|
|
28
|
+
);
|
|
29
|
+
return isRuntimeDeployment(value) ? value : null;
|
|
30
|
+
};
|
|
31
|
+
var saveRuntimeDeployment = async (userName, deployment) => {
|
|
32
|
+
const normalized = {
|
|
33
|
+
...deployment,
|
|
34
|
+
id: normalizeId(deployment.id, "Deployment id"),
|
|
35
|
+
label: deployment.label.trim(),
|
|
36
|
+
provider: deployment.provider.trim().toLowerCase(),
|
|
37
|
+
accountId: normalizeId(deployment.accountId, "Account id")
|
|
38
|
+
};
|
|
39
|
+
await setData(
|
|
40
|
+
redisKeys.runtimeDeployment(userName, normalized.id),
|
|
41
|
+
normalized,
|
|
42
|
+
{ expire: 0 }
|
|
43
|
+
);
|
|
44
|
+
return normalized;
|
|
45
|
+
};
|
|
46
|
+
var deleteRuntimeDeployment = async (userName, deploymentId) => {
|
|
47
|
+
const normalizedId = normalizeId(deploymentId, "Deployment id");
|
|
48
|
+
await Promise.all([
|
|
49
|
+
delKey(redisKeys.runtimeDeployment(userName, normalizedId)),
|
|
50
|
+
delKey(redisKeys.runtimeDeploymentHeartbeat(userName, normalizedId))
|
|
51
|
+
]);
|
|
52
|
+
};
|
|
53
|
+
var getRuntimeDeploymentHeartbeat = async (userName, deploymentId) => {
|
|
54
|
+
const value = await getData(
|
|
55
|
+
redisKeys.runtimeDeploymentHeartbeat(
|
|
56
|
+
userName,
|
|
57
|
+
normalizeId(deploymentId, "Deployment id")
|
|
58
|
+
),
|
|
59
|
+
null
|
|
60
|
+
);
|
|
61
|
+
return value && typeof value === "object" ? value : null;
|
|
62
|
+
};
|
|
63
|
+
var saveRuntimeDeploymentHeartbeat = async (userName, heartbeat) => {
|
|
64
|
+
await setData(
|
|
65
|
+
redisKeys.runtimeDeploymentHeartbeat(
|
|
66
|
+
userName,
|
|
67
|
+
normalizeId(heartbeat.deploymentId, "Deployment id")
|
|
68
|
+
),
|
|
69
|
+
heartbeat,
|
|
70
|
+
{ expire: 0 }
|
|
71
|
+
);
|
|
72
|
+
return heartbeat;
|
|
73
|
+
};
|
|
74
|
+
export {
|
|
75
|
+
deleteRuntimeDeployment,
|
|
76
|
+
getRuntimeDeployment,
|
|
77
|
+
getRuntimeDeploymentHeartbeat,
|
|
78
|
+
listRuntimeDeployments,
|
|
79
|
+
saveRuntimeDeployment,
|
|
80
|
+
saveRuntimeDeploymentHeartbeat
|
|
81
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { StrategyConfig } from '@tradejs/types';
|
|
2
|
+
|
|
3
|
+
interface RuntimeStrategyConfigRecord {
|
|
4
|
+
key: string;
|
|
5
|
+
strategyName: string;
|
|
6
|
+
configId: string;
|
|
7
|
+
strategyConfig: StrategyConfig;
|
|
8
|
+
}
|
|
9
|
+
declare const resolveStrategyConfigIdentityByKey: (userName: string, key: string) => {
|
|
10
|
+
strategyName: string;
|
|
11
|
+
configId: string;
|
|
12
|
+
} | null;
|
|
13
|
+
declare const resolveStrategyNameByConfigKey: (userName: string, key: string) => string | null;
|
|
14
|
+
declare const getRuntimeStrategyConfigKeys: (userName: string) => Promise<string[]>;
|
|
15
|
+
declare const loadRuntimeStrategyConfigs: (userName: string, { onInvalidConfig, }?: {
|
|
16
|
+
onInvalidConfig?: (key: string) => void;
|
|
17
|
+
}) => Promise<RuntimeStrategyConfigRecord[]>;
|
|
18
|
+
declare const loadRuntimeStrategyNames: (userName: string) => Promise<string[]>;
|
|
19
|
+
declare const getRuntimeStrategyConfig: (userName: string, strategyName: string, configId?: string) => Promise<StrategyConfig | null>;
|
|
20
|
+
declare const saveRuntimeStrategyConfig: ({ userName, strategyName, configId, strategyConfig, }: {
|
|
21
|
+
userName: string;
|
|
22
|
+
strategyName: string;
|
|
23
|
+
configId: string;
|
|
24
|
+
strategyConfig: StrategyConfig;
|
|
25
|
+
}) => Promise<RuntimeStrategyConfigRecord>;
|
|
26
|
+
declare const getRuntimeStrategyResultConfig: (userName: string, strategyName: string, symbol: string) => Promise<StrategyConfig | null>;
|
|
27
|
+
|
|
28
|
+
export { type RuntimeStrategyConfigRecord, getRuntimeStrategyConfig, getRuntimeStrategyConfigKeys, getRuntimeStrategyResultConfig, loadRuntimeStrategyConfigs, loadRuntimeStrategyNames, resolveStrategyConfigIdentityByKey, resolveStrategyNameByConfigKey, saveRuntimeStrategyConfig };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { StrategyConfig } from '@tradejs/types';
|
|
2
|
+
|
|
3
|
+
interface RuntimeStrategyConfigRecord {
|
|
4
|
+
key: string;
|
|
5
|
+
strategyName: string;
|
|
6
|
+
configId: string;
|
|
7
|
+
strategyConfig: StrategyConfig;
|
|
8
|
+
}
|
|
9
|
+
declare const resolveStrategyConfigIdentityByKey: (userName: string, key: string) => {
|
|
10
|
+
strategyName: string;
|
|
11
|
+
configId: string;
|
|
12
|
+
} | null;
|
|
13
|
+
declare const resolveStrategyNameByConfigKey: (userName: string, key: string) => string | null;
|
|
14
|
+
declare const getRuntimeStrategyConfigKeys: (userName: string) => Promise<string[]>;
|
|
15
|
+
declare const loadRuntimeStrategyConfigs: (userName: string, { onInvalidConfig, }?: {
|
|
16
|
+
onInvalidConfig?: (key: string) => void;
|
|
17
|
+
}) => Promise<RuntimeStrategyConfigRecord[]>;
|
|
18
|
+
declare const loadRuntimeStrategyNames: (userName: string) => Promise<string[]>;
|
|
19
|
+
declare const getRuntimeStrategyConfig: (userName: string, strategyName: string, configId?: string) => Promise<StrategyConfig | null>;
|
|
20
|
+
declare const saveRuntimeStrategyConfig: ({ userName, strategyName, configId, strategyConfig, }: {
|
|
21
|
+
userName: string;
|
|
22
|
+
strategyName: string;
|
|
23
|
+
configId: string;
|
|
24
|
+
strategyConfig: StrategyConfig;
|
|
25
|
+
}) => Promise<RuntimeStrategyConfigRecord>;
|
|
26
|
+
declare const getRuntimeStrategyResultConfig: (userName: string, strategyName: string, symbol: string) => Promise<StrategyConfig | null>;
|
|
27
|
+
|
|
28
|
+
export { type RuntimeStrategyConfigRecord, getRuntimeStrategyConfig, getRuntimeStrategyConfigKeys, getRuntimeStrategyResultConfig, loadRuntimeStrategyConfigs, loadRuntimeStrategyNames, resolveStrategyConfigIdentityByKey, resolveStrategyNameByConfigKey, saveRuntimeStrategyConfig };
|