@tradejs/infra 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.
@@ -0,0 +1,24 @@
1
+ declare const toFileToken: (value: string) => string;
2
+ declare const getMlChunkFilePath: (strategyName: string, chunkId: string, outDir?: string) => string;
3
+ declare const appendMlDatasetRow: (params: {
4
+ strategyName: string;
5
+ chunkId: string;
6
+ row: Record<string, number | string | null>;
7
+ outDir?: string;
8
+ }) => Promise<string>;
9
+ declare const flushMlDatasetWriter: (filePath: string) => Promise<void>;
10
+ declare const closeMlDatasetWriter: (filePath: string) => Promise<void>;
11
+ declare const closeAllMlDatasetWriters: () => Promise<void>;
12
+ declare const listMlChunkFiles: (params: {
13
+ strategyName: string;
14
+ outDir?: string;
15
+ }) => Promise<string[]>;
16
+ declare const listMlChunkStrategies: (params?: {
17
+ outDir?: string;
18
+ }) => Promise<string[]>;
19
+ declare const mergeJsonlFiles: (params: {
20
+ filePaths: string[];
21
+ outPath: string;
22
+ }) => Promise<void>;
23
+
24
+ export { appendMlDatasetRow as a, closeMlDatasetWriter as b, closeAllMlDatasetWriters as c, listMlChunkStrategies as d, flushMlDatasetWriter as f, getMlChunkFilePath as g, listMlChunkFiles as l, mergeJsonlFiles as m, toFileToken as t };
@@ -0,0 +1,24 @@
1
+ declare const toFileToken: (value: string) => string;
2
+ declare const getMlChunkFilePath: (strategyName: string, chunkId: string, outDir?: string) => string;
3
+ declare const appendMlDatasetRow: (params: {
4
+ strategyName: string;
5
+ chunkId: string;
6
+ row: Record<string, number | string | null>;
7
+ outDir?: string;
8
+ }) => Promise<string>;
9
+ declare const flushMlDatasetWriter: (filePath: string) => Promise<void>;
10
+ declare const closeMlDatasetWriter: (filePath: string) => Promise<void>;
11
+ declare const closeAllMlDatasetWriters: () => Promise<void>;
12
+ declare const listMlChunkFiles: (params: {
13
+ strategyName: string;
14
+ outDir?: string;
15
+ }) => Promise<string[]>;
16
+ declare const listMlChunkStrategies: (params?: {
17
+ outDir?: string;
18
+ }) => Promise<string[]>;
19
+ declare const mergeJsonlFiles: (params: {
20
+ filePaths: string[];
21
+ outPath: string;
22
+ }) => Promise<void>;
23
+
24
+ export { appendMlDatasetRow as a, closeMlDatasetWriter as b, closeAllMlDatasetWriters as c, listMlChunkStrategies as d, flushMlDatasetWriter as f, getMlChunkFilePath as g, listMlChunkFiles as l, mergeJsonlFiles as m, toFileToken as t };
package/dist/redis.d.mts CHANGED
@@ -17,6 +17,8 @@ declare class RedisWriteBlockedError extends Error {
17
17
  }
18
18
  declare const delKeyWithOptions: (key: string, options?: DelKeyOptions) => Promise<boolean>;
19
19
  declare const setData: <T>(key: string, data: T, options?: Options) => Promise<void>;
20
+ declare const createScreenshotSessionToken: (userName: string) => Promise<string | null>;
21
+ declare const consumeScreenshotSessionToken: (token: string) => Promise<string | null>;
20
22
  declare const redisKeys: {
21
23
  users: () => string;
22
24
  user: (userName: string) => string;
@@ -31,14 +33,28 @@ declare const redisKeys: {
31
33
  testOrders: (userName: string, strategyName: string, testName: string) => string;
32
34
  testConfig: (userName: string, strategyName: string, testName: string) => string;
33
35
  testStat: (userName: string, strategyName: string, testName: string) => string;
36
+ testSummaries: (userName: string) => string;
34
37
  cacheChunk: (userName: string, chunkId: string) => string;
35
38
  cacheOrders: (userName: string, orderLogId: string) => string;
36
39
  cachePositions: (userName: string, orderLogId: string) => string;
37
40
  signal: (symbol: string, signalId: string) => string;
38
41
  signalsBySymbol: (symbol: string) => string;
39
42
  storeSignal: (symbol: string, signalId: string) => string;
43
+ runtimeSignals: (userName: string) => string;
44
+ runtimeSignal: (userName: string, signalId: string) => string;
45
+ runtimeSignalEvaluations: (userName: string) => string;
46
+ runtimeSignalEvaluation: (userName: string, evaluationId: string) => string;
47
+ runtimeTrades: (userName: string) => string;
48
+ runtimeTrade: (userName: string, orderId: string) => string;
49
+ runtimeActiveTrades: (userName: string) => string;
50
+ runtimeActiveTrade: (userName: string, symbol: string) => string;
51
+ aiChatHistory: (userName: string, symbolKey: string) => string;
40
52
  analysis: (symbol: string, signalId: string) => string;
53
+ screenshotSessionToken: (token: string) => string;
41
54
  backtestResults: (userName: string, config: string, timestamp: string) => string;
55
+ researchRuns: (userName: string) => string;
56
+ researchRun: (userName: string, runId: string) => string;
57
+ researchLatestRun: (userName: string, strategyName: string) => string;
42
58
  mlSignalsByStrategy: (strategyName: string) => string;
43
59
  mlSignals: () => string;
44
60
  mlSignal: (strategyName: string, signalId: string) => string;
@@ -47,4 +63,4 @@ declare const redisKeys: {
47
63
  mlResult: (strategyName: string, signalId: string) => string;
48
64
  };
49
65
 
50
- export { RedisWriteBlockedError, delKey, delKeyWithOptions, getData, getKeys, redisKeys, setData };
66
+ export { RedisWriteBlockedError, consumeScreenshotSessionToken, createScreenshotSessionToken, delKey, delKeyWithOptions, getData, getKeys, redisKeys, setData };
package/dist/redis.d.ts CHANGED
@@ -17,6 +17,8 @@ declare class RedisWriteBlockedError extends Error {
17
17
  }
18
18
  declare const delKeyWithOptions: (key: string, options?: DelKeyOptions) => Promise<boolean>;
19
19
  declare const setData: <T>(key: string, data: T, options?: Options) => Promise<void>;
20
+ declare const createScreenshotSessionToken: (userName: string) => Promise<string | null>;
21
+ declare const consumeScreenshotSessionToken: (token: string) => Promise<string | null>;
20
22
  declare const redisKeys: {
21
23
  users: () => string;
22
24
  user: (userName: string) => string;
@@ -31,14 +33,28 @@ declare const redisKeys: {
31
33
  testOrders: (userName: string, strategyName: string, testName: string) => string;
32
34
  testConfig: (userName: string, strategyName: string, testName: string) => string;
33
35
  testStat: (userName: string, strategyName: string, testName: string) => string;
36
+ testSummaries: (userName: string) => string;
34
37
  cacheChunk: (userName: string, chunkId: string) => string;
35
38
  cacheOrders: (userName: string, orderLogId: string) => string;
36
39
  cachePositions: (userName: string, orderLogId: string) => string;
37
40
  signal: (symbol: string, signalId: string) => string;
38
41
  signalsBySymbol: (symbol: string) => string;
39
42
  storeSignal: (symbol: string, signalId: string) => string;
43
+ runtimeSignals: (userName: string) => string;
44
+ runtimeSignal: (userName: string, signalId: string) => string;
45
+ runtimeSignalEvaluations: (userName: string) => string;
46
+ runtimeSignalEvaluation: (userName: string, evaluationId: string) => string;
47
+ runtimeTrades: (userName: string) => string;
48
+ runtimeTrade: (userName: string, orderId: string) => string;
49
+ runtimeActiveTrades: (userName: string) => string;
50
+ runtimeActiveTrade: (userName: string, symbol: string) => string;
51
+ aiChatHistory: (userName: string, symbolKey: string) => string;
40
52
  analysis: (symbol: string, signalId: string) => string;
53
+ screenshotSessionToken: (token: string) => string;
41
54
  backtestResults: (userName: string, config: string, timestamp: string) => string;
55
+ researchRuns: (userName: string) => string;
56
+ researchRun: (userName: string, runId: string) => string;
57
+ researchLatestRun: (userName: string, strategyName: string) => string;
42
58
  mlSignalsByStrategy: (strategyName: string) => string;
43
59
  mlSignals: () => string;
44
60
  mlSignal: (strategyName: string, signalId: string) => string;
@@ -47,4 +63,4 @@ declare const redisKeys: {
47
63
  mlResult: (strategyName: string, signalId: string) => string;
48
64
  };
49
65
 
50
- export { RedisWriteBlockedError, delKey, delKeyWithOptions, getData, getKeys, redisKeys, setData };
66
+ export { RedisWriteBlockedError, consumeScreenshotSessionToken, createScreenshotSessionToken, delKey, delKeyWithOptions, getData, getKeys, redisKeys, setData };
package/dist/redis.js CHANGED
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var redis_exports = {};
32
32
  __export(redis_exports, {
33
33
  RedisWriteBlockedError: () => RedisWriteBlockedError,
34
+ consumeScreenshotSessionToken: () => consumeScreenshotSessionToken,
35
+ createScreenshotSessionToken: () => createScreenshotSessionToken,
34
36
  delKey: () => delKey,
35
37
  delKeyWithOptions: () => delKeyWithOptions,
36
38
  getData: () => getData,
@@ -39,8 +41,10 @@ __export(redis_exports, {
39
41
  setData: () => setData
40
42
  });
41
43
  module.exports = __toCommonJS(redis_exports);
44
+ var import_crypto = require("crypto");
42
45
  var import_ioredis = __toESM(require("ioredis"));
43
46
  var TTL_1D = 86400;
47
+ var SCREENSHOT_TOKEN_TTL_SECONDS = 15 * 60;
44
48
  var toJson = (value) => JSON.stringify(value);
45
49
  var logger = {
46
50
  log: (level, message, ...args) => {
@@ -296,6 +300,36 @@ var setData = async (key, data, options = {}) => {
296
300
  }
297
301
  }
298
302
  };
303
+ var createScreenshotSessionToken = async (userName) => {
304
+ const token = (0, import_crypto.randomBytes)(24).toString("hex");
305
+ await setData(
306
+ redisKeys.screenshotSessionToken(token),
307
+ {
308
+ userName,
309
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
310
+ },
311
+ {
312
+ expire: SCREENSHOT_TOKEN_TTL_SECONDS
313
+ }
314
+ );
315
+ return token;
316
+ };
317
+ var consumeScreenshotSessionToken = async (token) => {
318
+ const normalizedToken = token.trim();
319
+ if (!normalizedToken) {
320
+ return null;
321
+ }
322
+ const key = redisKeys.screenshotSessionToken(normalizedToken);
323
+ const payload = await getData(
324
+ key,
325
+ null
326
+ );
327
+ if (!payload?.userName) {
328
+ return null;
329
+ }
330
+ await delKey(key);
331
+ return payload.userName;
332
+ };
299
333
  var redisKeys = {
300
334
  users: () => "users:index:",
301
335
  user: (userName) => `users:index:${userName}`,
@@ -310,14 +344,28 @@ var redisKeys = {
310
344
  testOrders: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:orders`,
311
345
  testConfig: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:config`,
312
346
  testStat: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:stat`,
347
+ testSummaries: (userName) => `users:${userName}:tests:index:summary`,
313
348
  cacheChunk: (userName, chunkId) => `users:${userName}:cache:tests:chunks:${chunkId}`,
314
349
  cacheOrders: (userName, orderLogId) => `users:${userName}:cache:tests:orders:${orderLogId}`,
315
350
  cachePositions: (userName, orderLogId) => `users:${userName}:cache:tests:positions:${orderLogId}`,
316
351
  signal: (symbol, signalId) => `signals:${symbol}:${signalId}`,
317
352
  signalsBySymbol: (symbol) => `signals:${symbol}:`,
318
353
  storeSignal: (symbol, signalId) => `store:signals:${symbol}:${signalId}`,
354
+ runtimeSignals: (userName) => `users:${userName}:runtime:signals:`,
355
+ runtimeSignal: (userName, signalId) => `users:${userName}:runtime:signals:${signalId}`,
356
+ runtimeSignalEvaluations: (userName) => `users:${userName}:runtime:signal-evaluations:`,
357
+ runtimeSignalEvaluation: (userName, evaluationId) => `users:${userName}:runtime:signal-evaluations:${evaluationId}`,
358
+ runtimeTrades: (userName) => `users:${userName}:runtime:trade-records:`,
359
+ runtimeTrade: (userName, orderId) => `users:${userName}:runtime:trade-records:${orderId}`,
360
+ runtimeActiveTrades: (userName) => `users:${userName}:runtime:active-trades:`,
361
+ runtimeActiveTrade: (userName, symbol) => `users:${userName}:runtime:active-trades:${symbol}`,
362
+ aiChatHistory: (userName, symbolKey) => `users:${userName}:ai:chats:${symbolKey}`,
319
363
  analysis: (symbol, signalId) => `analysis:${symbol}:${signalId}`,
364
+ screenshotSessionToken: (token) => `auth:screenshot:${token}`,
320
365
  backtestResults: (userName, config, timestamp) => `users:${userName}:backtests:results:${config}:${timestamp}`,
366
+ researchRuns: (userName) => `users:${userName}:research:runs:`,
367
+ researchRun: (userName, runId) => `users:${userName}:research:runs:${runId}`,
368
+ researchLatestRun: (userName, strategyName) => `users:${userName}:research:latest:${strategyName}`,
321
369
  mlSignalsByStrategy: (strategyName) => `ml:${strategyName}:signals:`,
322
370
  mlSignals: () => "ml:",
323
371
  mlSignal: (strategyName, signalId) => `ml:${strategyName}:signals:${signalId}`,
@@ -328,6 +376,8 @@ var redisKeys = {
328
376
  // Annotate the CommonJS export names for ESM import in node:
329
377
  0 && (module.exports = {
330
378
  RedisWriteBlockedError,
379
+ consumeScreenshotSessionToken,
380
+ createScreenshotSessionToken,
331
381
  delKey,
332
382
  delKeyWithOptions,
333
383
  getData,
package/dist/redis.mjs CHANGED
@@ -1,292 +1,18 @@
1
- // src/redis.ts
2
- import Redis from "ioredis";
3
- var TTL_1D = 86400;
4
- var toJson = (value) => JSON.stringify(value);
5
- var logger = {
6
- log: (level, message, ...args) => {
7
- const method = level === "error" ? "error" : level === "warn" ? "warn" : "log";
8
- console[method](`[infra:redis] ${message}`, ...args);
9
- }
10
- };
11
- var redisConnectionWarningShown = false;
12
- var redisUnavailable = false;
13
- var isRedisConnectivityError = (error) => /ECONNREFUSED|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|MaxRetriesPerRequestError|Connection is closed|Stream isn't writeable/i.test(
14
- error.message
15
- );
16
- var toNonNegativeInt = (value, fallback) => {
17
- const parsed = Number.parseInt(String(value ?? ""), 10);
18
- return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
19
- };
20
- var toPositiveInt = (value, fallback) => {
21
- const parsed = Number.parseInt(String(value ?? ""), 10);
22
- return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
23
- };
24
- var markRedisUnavailable = (error) => {
25
- redisUnavailable = true;
26
- if (redisConnectionWarningShown) return;
27
- redisConnectionWarningShown = true;
28
- logger.log(
29
- "warn",
30
- "Redis is unavailable: %s. Cache-dependent features are temporarily disabled.",
31
- error.message
32
- );
33
- };
34
- var getRedis = () => {
35
- if (!global.__redis__) {
36
- const host = process.env.REDIS_HOST || "127.0.0.1";
37
- const port = toPositiveInt(process.env.REDIS_PORT, 6379);
38
- const connectTimeout = toPositiveInt(
39
- process.env.REDIS_CONNECT_TIMEOUT_MS,
40
- 3e3
41
- );
42
- const maxRetriesPerRequest = toNonNegativeInt(
43
- process.env.REDIS_MAX_RETRIES_PER_REQUEST,
44
- 1
45
- );
46
- global.__redis__ = new Redis({
47
- host,
48
- port,
49
- connectTimeout,
50
- maxRetriesPerRequest,
51
- enableOfflineQueue: false,
52
- retryStrategy: (attempt) => Math.min(attempt * 200, 2e3)
53
- });
54
- global.__redis__.on("error", (error) => {
55
- if (isRedisConnectivityError(error)) {
56
- markRedisUnavailable(error);
57
- return;
58
- }
59
- logger.log("error", "Redis client error: %s", String(error));
60
- });
61
- global.__redis__.on("ready", () => {
62
- redisUnavailable = false;
63
- if (redisConnectionWarningShown) {
64
- redisConnectionWarningShown = false;
65
- logger.log("info", "Redis connection restored");
66
- }
67
- });
68
- }
69
- return global.__redis__;
70
- };
71
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
72
- var getRedisStatus = (redis) => String(redis.status ?? "ready");
73
- var waitForRedisReady = async (redis) => {
74
- if (getRedisStatus(redis) === "ready") {
75
- return true;
76
- }
77
- const readyTimeoutMs = toPositiveInt(
78
- process.env.REDIS_READY_TIMEOUT_MS,
79
- toPositiveInt(process.env.REDIS_CONNECT_TIMEOUT_MS, 3e3)
80
- );
81
- const startedAt = Date.now();
82
- while (Date.now() - startedAt < readyTimeoutMs) {
83
- if (getRedisStatus(redis) === "ready") {
84
- return true;
85
- }
86
- if (getRedisStatus(redis) === "end") {
87
- return false;
88
- }
89
- await sleep(50);
90
- }
91
- return getRedisStatus(redis) === "ready";
92
- };
93
- var getReadyRedis = async () => {
94
- if (redisUnavailable) return null;
95
- const redis = getRedis();
96
- const ready = await waitForRedisReady(redis);
97
- if (ready) {
98
- return redis;
99
- }
100
- markRedisUnavailable(
101
- new Error(`Redis is not ready (status=${getRedisStatus(redis)})`)
102
- );
103
- return null;
104
- };
105
- var toResultString = (result) => {
106
- if (result == null) return null;
107
- if (typeof result === "string") return result;
108
- if (Buffer.isBuffer(result)) return result.toString("utf8");
109
- return String(result);
110
- };
111
- var DEFAULT_OPTIONS = {
112
- expire: TTL_1D
113
- };
114
- var parseJsonOrDeleteKey = async (redis, key, raw, fallback) => {
115
- try {
116
- return JSON.parse(raw);
117
- } catch (e) {
118
- logger.log("error", "failed JSON.parse(%s): %s", key, String(e));
119
- await redis.del(key);
120
- return fallback;
121
- }
122
- };
123
- var getKeys = async (prefix) => {
124
- if (redisUnavailable) return [];
125
- const redis = await getReadyRedis();
126
- if (!redis) return [];
127
- const keys = [];
128
- try {
129
- let cursor = "0";
130
- do {
131
- const [nextCursor, batch] = await redis.scan(
132
- cursor,
133
- "MATCH",
134
- `${prefix}*`,
135
- "COUNT",
136
- "200"
137
- );
138
- cursor = nextCursor;
139
- for (const key of batch) {
140
- if (key.startsWith(prefix)) {
141
- keys.push(key);
142
- }
143
- }
144
- } while (cursor !== "0");
145
- } catch (e) {
146
- if (e instanceof Error && isRedisConnectivityError(e)) {
147
- markRedisUnavailable(e);
148
- return [];
149
- }
150
- logger.log("warn", "failed SCAN for %s: %s", prefix, String(e));
151
- return [];
152
- }
153
- return keys;
154
- };
155
- var getData = async (key, fallback = []) => {
156
- if (redisUnavailable) return fallback;
157
- const redis = await getReadyRedis();
158
- if (!redis) return fallback;
159
- try {
160
- const rawJson = await redis.call("JSON.GET", key);
161
- const raw = toResultString(rawJson);
162
- if (raw == null) return fallback;
163
- return parseJsonOrDeleteKey(redis, key, raw, fallback);
164
- } catch (e) {
165
- if (e instanceof Error && isRedisConnectivityError(e)) {
166
- markRedisUnavailable(e);
167
- return fallback;
168
- }
169
- logger.log(
170
- "error",
171
- "failed JSON.GET %s: %s (fallback to GET)",
172
- key,
173
- String(e)
174
- );
175
- }
176
- try {
177
- const raw = await redis.get(key);
178
- if (raw == null) return fallback;
179
- return parseJsonOrDeleteKey(redis, key, raw, fallback);
180
- } catch (e) {
181
- if (e instanceof Error && isRedisConnectivityError(e)) {
182
- markRedisUnavailable(e);
183
- return fallback;
184
- }
185
- logger.log("error", "failed GET %s: %s", key, String(e));
186
- return fallback;
187
- }
188
- };
189
- var delKey = async (key) => {
190
- return delKeyWithOptions(key);
191
- };
192
- var RedisWriteBlockedError = class extends Error {
193
- constructor(message) {
194
- super(message);
195
- this.name = "RedisWriteBlockedError";
196
- }
197
- };
198
- var delKeyWithOptions = async (key, options = {}) => {
199
- if (redisUnavailable) return false;
200
- const { raiseOnMisconf = false } = options;
201
- const redis = await getReadyRedis();
202
- if (!redis) return false;
203
- try {
204
- const result = await redis.del(key);
205
- if (result === 1) {
206
- return true;
207
- }
208
- return false;
209
- } catch (e) {
210
- if (e instanceof Error && isRedisConnectivityError(e)) {
211
- markRedisUnavailable(e);
212
- return false;
213
- }
214
- const msg = String(e);
215
- if (raiseOnMisconf && msg.includes("MISCONF")) {
216
- throw new RedisWriteBlockedError(msg);
217
- }
218
- logger.log("error", "failed DEL %s: %s", key, String(e));
219
- return false;
220
- }
221
- };
222
- var setData = async (key, data, options = {}) => {
223
- if (redisUnavailable) return;
224
- const { expire } = { ...DEFAULT_OPTIONS, ...options };
225
- const redis = await getReadyRedis();
226
- if (!redis) return;
227
- const value = toJson(data);
228
- try {
229
- await redis.call("JSON.SET", key, "$", value);
230
- if (expire) {
231
- await redis.expire(key, expire);
232
- }
233
- } catch (e) {
234
- if (e instanceof Error && isRedisConnectivityError(e)) {
235
- markRedisUnavailable(e);
236
- return;
237
- }
238
- logger.log(
239
- "error",
240
- "failed JSON.SET %s: %s (fallback to SET)",
241
- key,
242
- String(e)
243
- );
244
- try {
245
- if (expire) {
246
- await redis.set(key, value, "EX", expire);
247
- } else {
248
- await redis.set(key, value);
249
- }
250
- } catch (e2) {
251
- if (e2 instanceof Error && isRedisConnectivityError(e2)) {
252
- markRedisUnavailable(e2);
253
- return;
254
- }
255
- logger.log("error", "failed SET %s: %s", key, String(e2));
256
- }
257
- }
258
- };
259
- var redisKeys = {
260
- users: () => "users:index:",
261
- user: (userName) => `users:index:${userName}`,
262
- bots: (userName) => `users:${userName}:bots`,
263
- botsPrefix: () => "users:",
264
- bot: (userName, botId) => `users:${userName}:bots:${botId}`,
265
- backtestConfig: (userName, config) => `users:${userName}:backtests:configs:${config}`,
266
- strategies: (userName) => `users:${userName}:strategies`,
267
- strategyConfig: (userName, strategyName) => `users:${userName}:strategies:${strategyName}:config`,
268
- strategyResults: (userName, strategyName) => `users:${userName}:strategies:${strategyName}:results`,
269
- tests: (userName, strategyName) => strategyName ? `users:${userName}:tests:${strategyName}` : `users:${userName}:tests:`,
270
- testOrders: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:orders`,
271
- testConfig: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:config`,
272
- testStat: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:stat`,
273
- cacheChunk: (userName, chunkId) => `users:${userName}:cache:tests:chunks:${chunkId}`,
274
- cacheOrders: (userName, orderLogId) => `users:${userName}:cache:tests:orders:${orderLogId}`,
275
- cachePositions: (userName, orderLogId) => `users:${userName}:cache:tests:positions:${orderLogId}`,
276
- signal: (symbol, signalId) => `signals:${symbol}:${signalId}`,
277
- signalsBySymbol: (symbol) => `signals:${symbol}:`,
278
- storeSignal: (symbol, signalId) => `store:signals:${symbol}:${signalId}`,
279
- analysis: (symbol, signalId) => `analysis:${symbol}:${signalId}`,
280
- backtestResults: (userName, config, timestamp) => `users:${userName}:backtests:results:${config}:${timestamp}`,
281
- mlSignalsByStrategy: (strategyName) => `ml:${strategyName}:signals:`,
282
- mlSignals: () => "ml:",
283
- mlSignal: (strategyName, signalId) => `ml:${strategyName}:signals:${signalId}`,
284
- mlResultsByStrategy: (strategyName) => `ml:${strategyName}:results:`,
285
- mlResults: () => "ml:",
286
- mlResult: (strategyName, signalId) => `ml:${strategyName}:results:${signalId}`
287
- };
1
+ import {
2
+ RedisWriteBlockedError,
3
+ consumeScreenshotSessionToken,
4
+ createScreenshotSessionToken,
5
+ delKey,
6
+ delKeyWithOptions,
7
+ getData,
8
+ getKeys,
9
+ redisKeys,
10
+ setData
11
+ } from "./chunk-DSTV67R5.mjs";
288
12
  export {
289
13
  RedisWriteBlockedError,
14
+ consumeScreenshotSessionToken,
15
+ createScreenshotSessionToken,
290
16
  delKey,
291
17
  delKeyWithOptions,
292
18
  getData,
@@ -1,10 +1,11 @@
1
1
  import { Pool } from 'pg';
2
- import { DerivativesInterval, KlineChartData, DerivativesRow, SpreadRow } from '@tradejs/types';
2
+ import { DerivativesInterval, DerivativesRow, KlineChartData, SpreadRow } from '@tradejs/types';
3
3
 
4
4
  declare global {
5
5
  var __pgPool__: Pool | undefined;
6
6
  }
7
7
  type CandleRow = {
8
+ provider: string;
8
9
  symbol: string;
9
10
  interval: number;
10
11
  ts: Date;
@@ -15,10 +16,20 @@ type CandleRow = {
15
16
  volume?: number | null;
16
17
  turnover?: number | null;
17
18
  };
18
- declare const toRows: (symbol: string, interval: number, data: KlineChartData) => CandleRow[];
19
+ declare const toRows: (provider: string, symbol: string, interval: number, data: KlineChartData) => CandleRow[];
19
20
  declare function upsertCandles(rows: CandleRow[]): Promise<void>;
20
21
  declare function upsertDerivatives(rows: DerivativesRow[]): Promise<void>;
21
22
  declare function getDerivativesRangeForSymbols(symbols: string[], interval: DerivativesInterval, startMs: number, endMs: number): Promise<any[]>;
23
+ declare function getDerivativesDataEdgesForSymbols(symbols: string[], interval: DerivativesInterval): Promise<Map<string, {
24
+ min?: number;
25
+ max?: number;
26
+ }>>;
27
+ declare function getDerivativesWindow(params: {
28
+ symbol: string;
29
+ intervals: DerivativesInterval[];
30
+ endMs: number;
31
+ lookbackMs: number;
32
+ }): Promise<Partial<Record<DerivativesInterval, DerivativesRow[]>>>;
22
33
  declare function getDerivativesSummary(hours?: number, limit?: number): Promise<{
23
34
  rows: any[];
24
35
  aggregates: any[];
@@ -31,17 +42,17 @@ declare function getSpreadSummary(hours?: number, limit?: number): Promise<{
31
42
  aggregates: any[];
32
43
  hours: number;
33
44
  }>;
34
- declare function getCandlesRange(symbol: string, interval: number, startMs: number, endMs: number): Promise<any[]>;
35
- declare function getDataEdges(symbol: string, interval: number): Promise<{
45
+ declare function getCandlesRange(provider: string, symbol: string, interval: number, startMs: number, endMs: number): Promise<any[]>;
46
+ declare function getDataEdges(provider: string, symbol: string, interval: number): Promise<{
36
47
  min: number | undefined;
37
48
  max: number | undefined;
38
49
  }>;
39
50
  declare function waitForDbReady(attempts?: number, delayMs?: number): Promise<void>;
40
- declare function deleteCandles(symbol: string, interval: number): Promise<void>;
41
- declare function findContinuityGap(symbol: string, interval: number): Promise<{
51
+ declare function deleteCandles(provider: string, symbol: string, interval: number): Promise<void>;
52
+ declare function findContinuityGap(provider: string, symbol: string, interval: number): Promise<{
42
53
  ts: number;
43
54
  prevTs: number;
44
55
  diffSeconds: number;
45
56
  } | null>;
46
57
 
47
- export { type CandleRow, deleteCandles, findContinuityGap, getCandlesRange, getDataEdges, getDerivativesRangeForSymbols, getDerivativesSummary, getSpreadRangeForSymbols, getSpreadSummary, toRows, upsertCandles, upsertDerivatives, upsertSpreadRows, waitForDbReady };
58
+ export { type CandleRow, deleteCandles, findContinuityGap, getCandlesRange, getDataEdges, getDerivativesDataEdgesForSymbols, getDerivativesRangeForSymbols, getDerivativesSummary, getDerivativesWindow, getSpreadRangeForSymbols, getSpreadSummary, toRows, upsertCandles, upsertDerivatives, upsertSpreadRows, waitForDbReady };
@@ -1,10 +1,11 @@
1
1
  import { Pool } from 'pg';
2
- import { DerivativesInterval, KlineChartData, DerivativesRow, SpreadRow } from '@tradejs/types';
2
+ import { DerivativesInterval, DerivativesRow, KlineChartData, SpreadRow } from '@tradejs/types';
3
3
 
4
4
  declare global {
5
5
  var __pgPool__: Pool | undefined;
6
6
  }
7
7
  type CandleRow = {
8
+ provider: string;
8
9
  symbol: string;
9
10
  interval: number;
10
11
  ts: Date;
@@ -15,10 +16,20 @@ type CandleRow = {
15
16
  volume?: number | null;
16
17
  turnover?: number | null;
17
18
  };
18
- declare const toRows: (symbol: string, interval: number, data: KlineChartData) => CandleRow[];
19
+ declare const toRows: (provider: string, symbol: string, interval: number, data: KlineChartData) => CandleRow[];
19
20
  declare function upsertCandles(rows: CandleRow[]): Promise<void>;
20
21
  declare function upsertDerivatives(rows: DerivativesRow[]): Promise<void>;
21
22
  declare function getDerivativesRangeForSymbols(symbols: string[], interval: DerivativesInterval, startMs: number, endMs: number): Promise<any[]>;
23
+ declare function getDerivativesDataEdgesForSymbols(symbols: string[], interval: DerivativesInterval): Promise<Map<string, {
24
+ min?: number;
25
+ max?: number;
26
+ }>>;
27
+ declare function getDerivativesWindow(params: {
28
+ symbol: string;
29
+ intervals: DerivativesInterval[];
30
+ endMs: number;
31
+ lookbackMs: number;
32
+ }): Promise<Partial<Record<DerivativesInterval, DerivativesRow[]>>>;
22
33
  declare function getDerivativesSummary(hours?: number, limit?: number): Promise<{
23
34
  rows: any[];
24
35
  aggregates: any[];
@@ -31,17 +42,17 @@ declare function getSpreadSummary(hours?: number, limit?: number): Promise<{
31
42
  aggregates: any[];
32
43
  hours: number;
33
44
  }>;
34
- declare function getCandlesRange(symbol: string, interval: number, startMs: number, endMs: number): Promise<any[]>;
35
- declare function getDataEdges(symbol: string, interval: number): Promise<{
45
+ declare function getCandlesRange(provider: string, symbol: string, interval: number, startMs: number, endMs: number): Promise<any[]>;
46
+ declare function getDataEdges(provider: string, symbol: string, interval: number): Promise<{
36
47
  min: number | undefined;
37
48
  max: number | undefined;
38
49
  }>;
39
50
  declare function waitForDbReady(attempts?: number, delayMs?: number): Promise<void>;
40
- declare function deleteCandles(symbol: string, interval: number): Promise<void>;
41
- declare function findContinuityGap(symbol: string, interval: number): Promise<{
51
+ declare function deleteCandles(provider: string, symbol: string, interval: number): Promise<void>;
52
+ declare function findContinuityGap(provider: string, symbol: string, interval: number): Promise<{
42
53
  ts: number;
43
54
  prevTs: number;
44
55
  diffSeconds: number;
45
56
  } | null>;
46
57
 
47
- export { type CandleRow, deleteCandles, findContinuityGap, getCandlesRange, getDataEdges, getDerivativesRangeForSymbols, getDerivativesSummary, getSpreadRangeForSymbols, getSpreadSummary, toRows, upsertCandles, upsertDerivatives, upsertSpreadRows, waitForDbReady };
58
+ export { type CandleRow, deleteCandles, findContinuityGap, getCandlesRange, getDataEdges, getDerivativesDataEdgesForSymbols, getDerivativesRangeForSymbols, getDerivativesSummary, getDerivativesWindow, getSpreadRangeForSymbols, getSpreadSummary, toRows, upsertCandles, upsertDerivatives, upsertSpreadRows, waitForDbReady };