@tradejs/infra 1.0.8 → 1.0.10
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.d.mts +39 -3
- package/dist/ai.d.ts +39 -3
- package/dist/ai.js +404 -28
- package/dist/ai.mjs +372 -24
- package/dist/backtestArtifacts.d.mts +57 -0
- package/dist/backtestArtifacts.d.ts +57 -0
- package/dist/backtestArtifacts.js +255 -0
- package/dist/backtestArtifacts.mjs +211 -0
- package/dist/{chunk-DSTV67R5.mjs → chunk-DXG2UDNA.mjs} +185 -5
- package/dist/{chunk-KVEZORMS.mjs → chunk-RQP5VSTH.mjs} +54 -3
- package/dist/ml.d.mts +1 -1
- package/dist/ml.d.ts +1 -1
- package/dist/ml.js +55 -3
- package/dist/ml.mjs +3 -1
- package/dist/{mlDatasetFile-sRGWgR_o.d.mts → mlDatasetFile-Czx__g9M.d.mts} +7 -1
- package/dist/{mlDatasetFile-sRGWgR_o.d.ts → mlDatasetFile-Czx__g9M.d.ts} +7 -1
- package/dist/redis.d.mts +31 -3
- package/dist/redis.d.ts +31 -3
- package/dist/redis.js +194 -7
- package/dist/redis.mjs +17 -3
- package/dist/timescale.d.mts +220 -5
- package/dist/timescale.d.ts +220 -5
- package/dist/timescale.js +1983 -93
- package/dist/timescale.mjs +1955 -93
- package/dist/tradingAccounts.d.mts +20 -0
- package/dist/tradingAccounts.d.ts +20 -0
- package/dist/tradingAccounts.js +556 -0
- package/dist/tradingAccounts.mjs +190 -0
- package/dist/userSettings.d.mts +2 -0
- package/dist/userSettings.d.ts +2 -0
- package/dist/userSettings.js +30 -5
- package/dist/userSettings.mjs +2 -1
- package/package.json +13 -3
package/dist/redis.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ import Redis from 'ioredis';
|
|
|
3
3
|
declare global {
|
|
4
4
|
var __redis__: Redis | undefined;
|
|
5
5
|
}
|
|
6
|
+
declare const closeRedisConnection: () => Promise<void>;
|
|
6
7
|
interface Options {
|
|
7
8
|
expire?: number;
|
|
8
9
|
}
|
|
10
|
+
declare const publishData: (channel: string, value: unknown) => Promise<number>;
|
|
9
11
|
interface DelKeyOptions {
|
|
10
12
|
raiseOnMisconf?: boolean;
|
|
11
13
|
}
|
|
@@ -17,18 +19,31 @@ declare class RedisWriteBlockedError extends Error {
|
|
|
17
19
|
}
|
|
18
20
|
declare const delKeyWithOptions: (key: string, options?: DelKeyOptions) => Promise<boolean>;
|
|
19
21
|
declare const setData: <T>(key: string, data: T, options?: Options) => Promise<void>;
|
|
22
|
+
declare const setHashJsonField: <T>(key: string, field: string, data: T, options?: Options) => Promise<void>;
|
|
23
|
+
declare const getHashJsonField: <T>(key: string, field: string, fallback?: T | null) => Promise<T | null>;
|
|
24
|
+
declare const getHashJsonValues: <T>(key: string) => Promise<T[]>;
|
|
25
|
+
declare const incrHashFields: (key: string, increments: Record<string, number>, options?: Options) => Promise<void>;
|
|
26
|
+
declare const getHashData: (key: string) => Promise<Record<string, string>>;
|
|
20
27
|
declare const createScreenshotSessionToken: (userName: string) => Promise<string | null>;
|
|
21
28
|
declare const consumeScreenshotSessionToken: (token: string) => Promise<string | null>;
|
|
22
29
|
declare const redisKeys: {
|
|
23
30
|
users: () => string;
|
|
24
31
|
user: (userName: string) => string;
|
|
32
|
+
tradingAccounts: (userName: string) => string;
|
|
33
|
+
tradingAccount: (userName: string, accountId: string) => string;
|
|
34
|
+
runtimeDeployments: (userName: string) => string;
|
|
35
|
+
runtimeDeployment: (userName: string, deploymentId: string) => string;
|
|
36
|
+
runtimeDeploymentHeartbeat: (userName: string, deploymentId: string) => string;
|
|
25
37
|
bots: (userName: string) => string;
|
|
26
38
|
botsPrefix: () => string;
|
|
27
39
|
bot: (userName: string, botId: string) => string;
|
|
28
40
|
backtestConfig: (userName: string, config: string) => string;
|
|
29
41
|
strategies: (userName: string) => string;
|
|
30
|
-
strategyConfig: (userName: string, strategyName: string) => string;
|
|
42
|
+
strategyConfig: (userName: string, strategyName: string, configId?: string) => string;
|
|
31
43
|
strategyResults: (userName: string, strategyName: string) => string;
|
|
44
|
+
strategyCharts: (userName: string, mode: string) => string;
|
|
45
|
+
strategyChartCards: (userName: string, mode: string) => string;
|
|
46
|
+
strategyChartCard: (userName: string, mode: string, cardId: string) => string;
|
|
32
47
|
tests: (userName: string, strategyName?: string) => string;
|
|
33
48
|
testOrders: (userName: string, strategyName: string, testName: string) => string;
|
|
34
49
|
testConfig: (userName: string, strategyName: string, testName: string) => string;
|
|
@@ -37,21 +52,34 @@ declare const redisKeys: {
|
|
|
37
52
|
cacheChunk: (userName: string, chunkId: string) => string;
|
|
38
53
|
cacheOrders: (userName: string, orderLogId: string) => string;
|
|
39
54
|
cachePositions: (userName: string, orderLogId: string) => string;
|
|
55
|
+
tickerUniverse: (userName: string, connectorName: string, universe?: string, accountId?: string) => string;
|
|
40
56
|
signal: (symbol: string, signalId: string) => string;
|
|
41
57
|
signalsBySymbol: (symbol: string) => string;
|
|
42
58
|
storeSignal: (symbol: string, signalId: string) => string;
|
|
43
59
|
runtimeSignals: (userName: string) => string;
|
|
44
60
|
runtimeSignal: (userName: string, signalId: string) => string;
|
|
61
|
+
runtimeSignalBuckets: (userName: string) => string;
|
|
62
|
+
runtimeSignalBucket: (userName: string, dayKey: string, strategyName: string) => string;
|
|
45
63
|
runtimeSignalEvaluations: (userName: string) => string;
|
|
46
64
|
runtimeSignalEvaluation: (userName: string, evaluationId: string) => string;
|
|
65
|
+
runtimeSignalEvaluationBuckets: (userName: string) => string;
|
|
66
|
+
runtimeSignalEvaluationBucket: (userName: string, dayKey: string, strategyName: string) => string;
|
|
67
|
+
runtimeSignalEvaluationStatsBuckets: (userName: string) => string;
|
|
68
|
+
runtimeSignalEvaluationStatsBucket: (userName: string, dayKey: string, strategyName: string) => string;
|
|
47
69
|
runtimeTrades: (userName: string) => string;
|
|
48
70
|
runtimeTrade: (userName: string, orderId: string) => string;
|
|
71
|
+
runtimeTradeBuckets: (userName: string) => string;
|
|
72
|
+
runtimeTradeBucket: (userName: string, dayKey: string) => string;
|
|
49
73
|
runtimeActiveTrades: (userName: string) => string;
|
|
50
|
-
runtimeActiveTrade: (userName: string, symbol: string) => string;
|
|
74
|
+
runtimeActiveTrade: (userName: string, symbol: string, scopeId?: string) => string;
|
|
51
75
|
aiChatHistory: (userName: string, symbolKey: string) => string;
|
|
52
76
|
analysis: (symbol: string, signalId: string) => string;
|
|
53
77
|
screenshotSessionToken: (token: string) => string;
|
|
54
78
|
backtestResults: (userName: string, config: string, timestamp: string) => string;
|
|
79
|
+
backtestRuns: (userName: string) => string;
|
|
80
|
+
backtestRun: (userName: string, runId: string) => string;
|
|
81
|
+
backtestRunResults: (userName: string, runId: string) => string;
|
|
82
|
+
backtestLatestRun: (userName: string, config: string) => string;
|
|
55
83
|
researchRuns: (userName: string) => string;
|
|
56
84
|
researchRun: (userName: string, runId: string) => string;
|
|
57
85
|
researchLatestRun: (userName: string, strategyName: string) => string;
|
|
@@ -63,4 +91,4 @@ declare const redisKeys: {
|
|
|
63
91
|
mlResult: (strategyName: string, signalId: string) => string;
|
|
64
92
|
};
|
|
65
93
|
|
|
66
|
-
export { RedisWriteBlockedError, consumeScreenshotSessionToken, createScreenshotSessionToken, delKey, delKeyWithOptions, getData, getKeys, redisKeys, setData };
|
|
94
|
+
export { RedisWriteBlockedError, closeRedisConnection, consumeScreenshotSessionToken, createScreenshotSessionToken, delKey, delKeyWithOptions, getData, getHashData, getHashJsonField, getHashJsonValues, getKeys, incrHashFields, publishData, redisKeys, setData, setHashJsonField };
|
package/dist/redis.js
CHANGED
|
@@ -31,14 +31,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var redis_exports = {};
|
|
32
32
|
__export(redis_exports, {
|
|
33
33
|
RedisWriteBlockedError: () => RedisWriteBlockedError,
|
|
34
|
+
closeRedisConnection: () => closeRedisConnection,
|
|
34
35
|
consumeScreenshotSessionToken: () => consumeScreenshotSessionToken,
|
|
35
36
|
createScreenshotSessionToken: () => createScreenshotSessionToken,
|
|
36
37
|
delKey: () => delKey,
|
|
37
38
|
delKeyWithOptions: () => delKeyWithOptions,
|
|
38
39
|
getData: () => getData,
|
|
40
|
+
getHashData: () => getHashData,
|
|
41
|
+
getHashJsonField: () => getHashJsonField,
|
|
42
|
+
getHashJsonValues: () => getHashJsonValues,
|
|
39
43
|
getKeys: () => getKeys,
|
|
44
|
+
incrHashFields: () => incrHashFields,
|
|
45
|
+
publishData: () => publishData,
|
|
40
46
|
redisKeys: () => redisKeys,
|
|
41
|
-
setData: () => setData
|
|
47
|
+
setData: () => setData,
|
|
48
|
+
setHashJsonField: () => setHashJsonField
|
|
42
49
|
});
|
|
43
50
|
module.exports = __toCommonJS(redis_exports);
|
|
44
51
|
var import_crypto = require("crypto");
|
|
@@ -54,9 +61,12 @@ var logger = {
|
|
|
54
61
|
};
|
|
55
62
|
var redisConnectionWarningShown = false;
|
|
56
63
|
var redisUnavailable = false;
|
|
57
|
-
var isRedisConnectivityError = (error) =>
|
|
58
|
-
error.message
|
|
59
|
-
|
|
64
|
+
var isRedisConnectivityError = (error) => {
|
|
65
|
+
const errorText = [error.name, error.message, String(error)].join(" ");
|
|
66
|
+
return /ECONNREFUSED|ECONNRESET|ECONNABORTED|EPIPE|ENOTFOUND|EAI_AGAIN|ETIMEDOUT|MaxRetriesPerRequestError|Connection is closed|Stream isn't writeable/i.test(
|
|
67
|
+
errorText
|
|
68
|
+
);
|
|
69
|
+
};
|
|
60
70
|
var toNonNegativeInt = (value, fallback) => {
|
|
61
71
|
const parsed = Number.parseInt(String(value ?? ""), 10);
|
|
62
72
|
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
@@ -112,6 +122,16 @@ var getRedis = () => {
|
|
|
112
122
|
}
|
|
113
123
|
return global.__redis__;
|
|
114
124
|
};
|
|
125
|
+
var closeRedisConnection = async () => {
|
|
126
|
+
const redis = global.__redis__;
|
|
127
|
+
if (!redis) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
global.__redis__ = void 0;
|
|
131
|
+
redisUnavailable = false;
|
|
132
|
+
redisConnectionWarningShown = false;
|
|
133
|
+
redis.disconnect();
|
|
134
|
+
};
|
|
115
135
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
116
136
|
var getRedisStatus = (redis) => String(redis.status ?? "ready");
|
|
117
137
|
var waitForRedisReady = async (redis) => {
|
|
@@ -152,6 +172,11 @@ var toResultString = (result) => {
|
|
|
152
172
|
if (Buffer.isBuffer(result)) return result.toString("utf8");
|
|
153
173
|
return String(result);
|
|
154
174
|
};
|
|
175
|
+
var publishData = async (channel, value) => {
|
|
176
|
+
const redis = await getReadyRedis();
|
|
177
|
+
if (!redis) return 0;
|
|
178
|
+
return redis.publish(channel, toJson(value));
|
|
179
|
+
};
|
|
155
180
|
var DEFAULT_OPTIONS = {
|
|
156
181
|
expire: TTL_1D
|
|
157
182
|
};
|
|
@@ -164,6 +189,31 @@ var parseJsonOrDeleteKey = async (redis, key, raw, fallback) => {
|
|
|
164
189
|
return fallback;
|
|
165
190
|
}
|
|
166
191
|
};
|
|
192
|
+
var parseHashMap = (value) => {
|
|
193
|
+
if (!value) {
|
|
194
|
+
return {};
|
|
195
|
+
}
|
|
196
|
+
if (Array.isArray(value)) {
|
|
197
|
+
const result = {};
|
|
198
|
+
for (let index = 0; index < value.length; index += 2) {
|
|
199
|
+
const field = value[index];
|
|
200
|
+
const fieldValue = value[index + 1];
|
|
201
|
+
if (field == null || fieldValue == null) {
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
result[String(field)] = toResultString(fieldValue) ?? "";
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
if (typeof value === "object") {
|
|
209
|
+
return Object.fromEntries(
|
|
210
|
+
Object.entries(value).map(
|
|
211
|
+
([field, fieldValue]) => [field, toResultString(fieldValue) ?? ""]
|
|
212
|
+
)
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
return {};
|
|
216
|
+
};
|
|
167
217
|
var getKeys = async (prefix) => {
|
|
168
218
|
if (redisUnavailable) return [];
|
|
169
219
|
const redis = await getReadyRedis();
|
|
@@ -300,6 +350,115 @@ var setData = async (key, data, options = {}) => {
|
|
|
300
350
|
}
|
|
301
351
|
}
|
|
302
352
|
};
|
|
353
|
+
var setHashJsonField = async (key, field, data, options = {}) => {
|
|
354
|
+
if (redisUnavailable) return;
|
|
355
|
+
const { expire } = { ...DEFAULT_OPTIONS, ...options };
|
|
356
|
+
const redis = await getReadyRedis();
|
|
357
|
+
if (!redis) return;
|
|
358
|
+
try {
|
|
359
|
+
await redis.call("HSET", key, field, toJson(data));
|
|
360
|
+
if (expire) {
|
|
361
|
+
await redis.expire(key, expire);
|
|
362
|
+
}
|
|
363
|
+
} catch (e) {
|
|
364
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
365
|
+
markRedisUnavailable(e);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
logger.log("error", "failed HSET %s[%s]: %s", key, field, String(e));
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
var getHashJsonField = async (key, field, fallback = null) => {
|
|
372
|
+
if (redisUnavailable) return fallback;
|
|
373
|
+
const redis = await getReadyRedis();
|
|
374
|
+
if (!redis) return fallback;
|
|
375
|
+
try {
|
|
376
|
+
const value = await redis.call("HGET", key, field);
|
|
377
|
+
if (typeof value !== "string" || !value) {
|
|
378
|
+
return fallback;
|
|
379
|
+
}
|
|
380
|
+
return JSON.parse(value);
|
|
381
|
+
} catch (e) {
|
|
382
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
383
|
+
markRedisUnavailable(e);
|
|
384
|
+
return fallback;
|
|
385
|
+
}
|
|
386
|
+
logger.log("error", "failed HGET %s[%s]: %s", key, field, String(e));
|
|
387
|
+
return fallback;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var getHashJsonValues = async (key) => {
|
|
391
|
+
if (redisUnavailable) return [];
|
|
392
|
+
const redis = await getReadyRedis();
|
|
393
|
+
if (!redis) return [];
|
|
394
|
+
try {
|
|
395
|
+
const raw = await redis.call("HGETALL", key);
|
|
396
|
+
const values = Object.values(parseHashMap(raw));
|
|
397
|
+
const parsed = [];
|
|
398
|
+
for (const value of values) {
|
|
399
|
+
if (!value) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
try {
|
|
403
|
+
parsed.push(JSON.parse(value));
|
|
404
|
+
} catch (e) {
|
|
405
|
+
logger.log(
|
|
406
|
+
"error",
|
|
407
|
+
"failed JSON.parse(HGETALL %s value): %s",
|
|
408
|
+
key,
|
|
409
|
+
String(e)
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return parsed;
|
|
414
|
+
} catch (e) {
|
|
415
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
416
|
+
markRedisUnavailable(e);
|
|
417
|
+
return [];
|
|
418
|
+
}
|
|
419
|
+
logger.log("error", "failed HGETALL %s: %s", key, String(e));
|
|
420
|
+
return [];
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
var incrHashFields = async (key, increments, options = {}) => {
|
|
424
|
+
if (redisUnavailable) return;
|
|
425
|
+
const { expire } = { ...DEFAULT_OPTIONS, ...options };
|
|
426
|
+
const redis = await getReadyRedis();
|
|
427
|
+
if (!redis) return;
|
|
428
|
+
try {
|
|
429
|
+
for (const [field, increment] of Object.entries(increments)) {
|
|
430
|
+
if (!Number.isFinite(increment) || increment === 0) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
await redis.call("HINCRBY", key, field, Math.trunc(increment));
|
|
434
|
+
}
|
|
435
|
+
if (expire) {
|
|
436
|
+
await redis.expire(key, expire);
|
|
437
|
+
}
|
|
438
|
+
} catch (e) {
|
|
439
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
440
|
+
markRedisUnavailable(e);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
logger.log("error", "failed HINCRBY %s: %s", key, String(e));
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
var getHashData = async (key) => {
|
|
447
|
+
if (redisUnavailable) return {};
|
|
448
|
+
const redis = await getReadyRedis();
|
|
449
|
+
if (!redis) return {};
|
|
450
|
+
try {
|
|
451
|
+
const raw = await redis.call("HGETALL", key);
|
|
452
|
+
return parseHashMap(raw);
|
|
453
|
+
} catch (e) {
|
|
454
|
+
if (e instanceof Error && isRedisConnectivityError(e)) {
|
|
455
|
+
markRedisUnavailable(e);
|
|
456
|
+
return {};
|
|
457
|
+
}
|
|
458
|
+
logger.log("error", "failed HGETALL %s: %s", key, String(e));
|
|
459
|
+
return {};
|
|
460
|
+
}
|
|
461
|
+
};
|
|
303
462
|
var createScreenshotSessionToken = async (userName) => {
|
|
304
463
|
const token = (0, import_crypto.randomBytes)(24).toString("hex");
|
|
305
464
|
await setData(
|
|
@@ -333,13 +492,21 @@ var consumeScreenshotSessionToken = async (token) => {
|
|
|
333
492
|
var redisKeys = {
|
|
334
493
|
users: () => "users:index:",
|
|
335
494
|
user: (userName) => `users:index:${userName}`,
|
|
495
|
+
tradingAccounts: (userName) => `users:${userName}:trading-accounts:`,
|
|
496
|
+
tradingAccount: (userName, accountId) => `users:${userName}:trading-accounts:${accountId}`,
|
|
497
|
+
runtimeDeployments: (userName) => `users:${userName}:runtime:deployments:`,
|
|
498
|
+
runtimeDeployment: (userName, deploymentId) => `users:${userName}:runtime:deployments:${deploymentId}`,
|
|
499
|
+
runtimeDeploymentHeartbeat: (userName, deploymentId) => `users:${userName}:runtime:deployments:${deploymentId}:heartbeat`,
|
|
336
500
|
bots: (userName) => `users:${userName}:bots`,
|
|
337
501
|
botsPrefix: () => "users:",
|
|
338
502
|
bot: (userName, botId) => `users:${userName}:bots:${botId}`,
|
|
339
503
|
backtestConfig: (userName, config) => `users:${userName}:backtests:configs:${config}`,
|
|
340
504
|
strategies: (userName) => `users:${userName}:strategies`,
|
|
341
|
-
strategyConfig: (userName, strategyName) => `users:${userName}:strategies:${strategyName}
|
|
505
|
+
strategyConfig: (userName, strategyName, configId = "config") => `users:${userName}:strategies:${strategyName}:${configId}`,
|
|
342
506
|
strategyResults: (userName, strategyName) => `users:${userName}:strategies:${strategyName}:results`,
|
|
507
|
+
strategyCharts: (userName, mode) => `users:${userName}:strategies:charts:${mode}`,
|
|
508
|
+
strategyChartCards: (userName, mode) => `users:${userName}:strategies:charts:${mode}:cards:`,
|
|
509
|
+
strategyChartCard: (userName, mode, cardId) => `users:${userName}:strategies:charts:${mode}:cards:${cardId}`,
|
|
343
510
|
tests: (userName, strategyName) => strategyName ? `users:${userName}:tests:${strategyName}` : `users:${userName}:tests:`,
|
|
344
511
|
testOrders: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:orders`,
|
|
345
512
|
testConfig: (userName, strategyName, testName) => `users:${userName}:tests:${strategyName}:${testName}:config`,
|
|
@@ -348,21 +515,34 @@ var redisKeys = {
|
|
|
348
515
|
cacheChunk: (userName, chunkId) => `users:${userName}:cache:tests:chunks:${chunkId}`,
|
|
349
516
|
cacheOrders: (userName, orderLogId) => `users:${userName}:cache:tests:orders:${orderLogId}`,
|
|
350
517
|
cachePositions: (userName, orderLogId) => `users:${userName}:cache:tests:positions:${orderLogId}`,
|
|
518
|
+
tickerUniverse: (userName, connectorName, universe, accountId) => universe || accountId ? `users:${userName}:cache:tickers:${connectorName}:${universe ?? "crypto"}:${accountId ?? "default"}` : `users:${userName}:cache:tickers:${connectorName}`,
|
|
351
519
|
signal: (symbol, signalId) => `signals:${symbol}:${signalId}`,
|
|
352
520
|
signalsBySymbol: (symbol) => `signals:${symbol}:`,
|
|
353
521
|
storeSignal: (symbol, signalId) => `store:signals:${symbol}:${signalId}`,
|
|
354
522
|
runtimeSignals: (userName) => `users:${userName}:runtime:signals:`,
|
|
355
523
|
runtimeSignal: (userName, signalId) => `users:${userName}:runtime:signals:${signalId}`,
|
|
524
|
+
runtimeSignalBuckets: (userName) => `users:${userName}:runtime:signals:days:`,
|
|
525
|
+
runtimeSignalBucket: (userName, dayKey, strategyName) => `users:${userName}:runtime:signals:days:${dayKey}:${strategyName}`,
|
|
356
526
|
runtimeSignalEvaluations: (userName) => `users:${userName}:runtime:signal-evaluations:`,
|
|
357
527
|
runtimeSignalEvaluation: (userName, evaluationId) => `users:${userName}:runtime:signal-evaluations:${evaluationId}`,
|
|
528
|
+
runtimeSignalEvaluationBuckets: (userName) => `users:${userName}:runtime:signal-evaluations:days:`,
|
|
529
|
+
runtimeSignalEvaluationBucket: (userName, dayKey, strategyName) => `users:${userName}:runtime:signal-evaluations:days:${dayKey}:${strategyName}`,
|
|
530
|
+
runtimeSignalEvaluationStatsBuckets: (userName) => `users:${userName}:runtime:signal-evaluation-stats:days:`,
|
|
531
|
+
runtimeSignalEvaluationStatsBucket: (userName, dayKey, strategyName) => `users:${userName}:runtime:signal-evaluation-stats:days:${dayKey}:${strategyName}`,
|
|
358
532
|
runtimeTrades: (userName) => `users:${userName}:runtime:trade-records:`,
|
|
359
533
|
runtimeTrade: (userName, orderId) => `users:${userName}:runtime:trade-records:${orderId}`,
|
|
534
|
+
runtimeTradeBuckets: (userName) => `users:${userName}:runtime:trade-records:days:`,
|
|
535
|
+
runtimeTradeBucket: (userName, dayKey) => `users:${userName}:runtime:trade-records:days:${dayKey}`,
|
|
360
536
|
runtimeActiveTrades: (userName) => `users:${userName}:runtime:active-trades:`,
|
|
361
|
-
runtimeActiveTrade: (userName, symbol) => `users:${userName}:runtime:active-trades:${symbol}`,
|
|
537
|
+
runtimeActiveTrade: (userName, symbol, scopeId) => scopeId ? `users:${userName}:runtime:active-trades:${scopeId}:${symbol}` : `users:${userName}:runtime:active-trades:${symbol}`,
|
|
362
538
|
aiChatHistory: (userName, symbolKey) => `users:${userName}:ai:chats:${symbolKey}`,
|
|
363
539
|
analysis: (symbol, signalId) => `analysis:${symbol}:${signalId}`,
|
|
364
540
|
screenshotSessionToken: (token) => `auth:screenshot:${token}`,
|
|
365
541
|
backtestResults: (userName, config, timestamp) => `users:${userName}:backtests:results:${config}:${timestamp}`,
|
|
542
|
+
backtestRuns: (userName) => `users:${userName}:backtests:runs:`,
|
|
543
|
+
backtestRun: (userName, runId) => `users:${userName}:backtests:runs:${runId}`,
|
|
544
|
+
backtestRunResults: (userName, runId) => `users:${userName}:backtests:runs:${runId}:results`,
|
|
545
|
+
backtestLatestRun: (userName, config) => `users:${userName}:backtests:latest:${config}`,
|
|
366
546
|
researchRuns: (userName) => `users:${userName}:research:runs:`,
|
|
367
547
|
researchRun: (userName, runId) => `users:${userName}:research:runs:${runId}`,
|
|
368
548
|
researchLatestRun: (userName, strategyName) => `users:${userName}:research:latest:${strategyName}`,
|
|
@@ -376,12 +556,19 @@ var redisKeys = {
|
|
|
376
556
|
// Annotate the CommonJS export names for ESM import in node:
|
|
377
557
|
0 && (module.exports = {
|
|
378
558
|
RedisWriteBlockedError,
|
|
559
|
+
closeRedisConnection,
|
|
379
560
|
consumeScreenshotSessionToken,
|
|
380
561
|
createScreenshotSessionToken,
|
|
381
562
|
delKey,
|
|
382
563
|
delKeyWithOptions,
|
|
383
564
|
getData,
|
|
565
|
+
getHashData,
|
|
566
|
+
getHashJsonField,
|
|
567
|
+
getHashJsonValues,
|
|
384
568
|
getKeys,
|
|
569
|
+
incrHashFields,
|
|
570
|
+
publishData,
|
|
385
571
|
redisKeys,
|
|
386
|
-
setData
|
|
572
|
+
setData,
|
|
573
|
+
setHashJsonField
|
|
387
574
|
});
|
package/dist/redis.mjs
CHANGED
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RedisWriteBlockedError,
|
|
3
|
+
closeRedisConnection,
|
|
3
4
|
consumeScreenshotSessionToken,
|
|
4
5
|
createScreenshotSessionToken,
|
|
5
6
|
delKey,
|
|
6
7
|
delKeyWithOptions,
|
|
7
8
|
getData,
|
|
9
|
+
getHashData,
|
|
10
|
+
getHashJsonField,
|
|
11
|
+
getHashJsonValues,
|
|
8
12
|
getKeys,
|
|
13
|
+
incrHashFields,
|
|
14
|
+
publishData,
|
|
9
15
|
redisKeys,
|
|
10
|
-
setData
|
|
11
|
-
|
|
16
|
+
setData,
|
|
17
|
+
setHashJsonField
|
|
18
|
+
} from "./chunk-DXG2UDNA.mjs";
|
|
12
19
|
export {
|
|
13
20
|
RedisWriteBlockedError,
|
|
21
|
+
closeRedisConnection,
|
|
14
22
|
consumeScreenshotSessionToken,
|
|
15
23
|
createScreenshotSessionToken,
|
|
16
24
|
delKey,
|
|
17
25
|
delKeyWithOptions,
|
|
18
26
|
getData,
|
|
27
|
+
getHashData,
|
|
28
|
+
getHashJsonField,
|
|
29
|
+
getHashJsonValues,
|
|
19
30
|
getKeys,
|
|
31
|
+
incrHashFields,
|
|
32
|
+
publishData,
|
|
20
33
|
redisKeys,
|
|
21
|
-
setData
|
|
34
|
+
setData,
|
|
35
|
+
setHashJsonField
|
|
22
36
|
};
|
package/dist/timescale.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pool } from 'pg';
|
|
2
|
-
import { DerivativesInterval, DerivativesRow, KlineChartData, SpreadRow } from '@tradejs/types';
|
|
2
|
+
import { DerivativesInterval, DerivativesRow, MarketFeatureInterval, MarketBreadthRow, MarketCmcExchangeLiquidityContextRow, MarketCmcFearGreedContextRow, MarketCmcIndexContextRow, MarketGlobalContextRow, MarketReferenceAssetContextRow, MarketTradeFlowRow, KlineChartData, SpreadRow } from '@tradejs/types';
|
|
3
3
|
|
|
4
4
|
declare global {
|
|
5
5
|
var __pgPool__: Pool | undefined;
|
|
@@ -15,7 +15,12 @@ type CandleRow = {
|
|
|
15
15
|
close: number;
|
|
16
16
|
volume?: number | null;
|
|
17
17
|
turnover?: number | null;
|
|
18
|
+
takerBuyBaseVolume?: number | null;
|
|
19
|
+
takerBuyQuoteVolume?: number | null;
|
|
20
|
+
takerSellBaseVolume?: number | null;
|
|
21
|
+
takerSellQuoteVolume?: number | null;
|
|
18
22
|
};
|
|
23
|
+
declare const closeTimescalePool: () => Promise<void>;
|
|
19
24
|
declare const toRows: (provider: string, symbol: string, interval: number, data: KlineChartData) => CandleRow[];
|
|
20
25
|
declare function upsertCandles(rows: CandleRow[]): Promise<void>;
|
|
21
26
|
declare function upsertDerivatives(rows: DerivativesRow[]): Promise<void>;
|
|
@@ -24,18 +29,224 @@ declare function getDerivativesDataEdgesForSymbols(symbols: string[], interval:
|
|
|
24
29
|
min?: number;
|
|
25
30
|
max?: number;
|
|
26
31
|
}>>;
|
|
32
|
+
declare function getDerivativesBackfillCoverage(params: {
|
|
33
|
+
source: string;
|
|
34
|
+
symbols: string[];
|
|
35
|
+
interval: DerivativesInterval;
|
|
36
|
+
fromMs: number;
|
|
37
|
+
toMs: number;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
symbol: string;
|
|
40
|
+
interval: DerivativesInterval;
|
|
41
|
+
fromMs: number;
|
|
42
|
+
toMs: number;
|
|
43
|
+
rowsCount: number;
|
|
44
|
+
}[]>;
|
|
45
|
+
declare function upsertDerivativesBackfillCoverage(rows: Array<{
|
|
46
|
+
source: string;
|
|
47
|
+
symbol: string;
|
|
48
|
+
interval: DerivativesInterval;
|
|
49
|
+
fromMs: number;
|
|
50
|
+
toMs: number;
|
|
51
|
+
rowsCount: number;
|
|
52
|
+
}>): Promise<void>;
|
|
27
53
|
declare function getDerivativesWindow(params: {
|
|
28
54
|
symbol: string;
|
|
29
55
|
intervals: DerivativesInterval[];
|
|
30
56
|
endMs: number;
|
|
31
57
|
lookbackMs: number;
|
|
32
58
|
}): Promise<Partial<Record<DerivativesInterval, DerivativesRow[]>>>;
|
|
33
|
-
declare function getDerivativesSummary(hours?: number, limit?: number): Promise<{
|
|
34
|
-
rows: any[];
|
|
35
|
-
aggregates: any[];
|
|
59
|
+
declare function getDerivativesSummary(hours?: number, limit?: number, symbols?: string[]): Promise<{
|
|
36
60
|
hours: number;
|
|
61
|
+
items: {
|
|
62
|
+
symbol: string;
|
|
63
|
+
interval: string;
|
|
64
|
+
points: number;
|
|
65
|
+
last_ts: string | Date;
|
|
66
|
+
first_ts: string | Date;
|
|
67
|
+
latest_open_interest: number | null;
|
|
68
|
+
first_open_interest: number | null;
|
|
69
|
+
oi_change: number | null;
|
|
70
|
+
oi_change_pct: number | null;
|
|
71
|
+
latest_funding_rate: number | null;
|
|
72
|
+
first_funding_rate: number | null;
|
|
73
|
+
funding_change: number | null;
|
|
74
|
+
sum_liq_long: number | null;
|
|
75
|
+
sum_liq_short: number | null;
|
|
76
|
+
sum_liq_total: number | null;
|
|
77
|
+
}[];
|
|
37
78
|
}>;
|
|
38
79
|
declare function upsertSpreadRows(rows: SpreadRow[]): Promise<void>;
|
|
80
|
+
declare function upsertMarketTradeFlowRows(rows: MarketTradeFlowRow[]): Promise<void>;
|
|
81
|
+
declare function upsertMarketBreadthRows(rows: MarketBreadthRow[]): Promise<void>;
|
|
82
|
+
declare function upsertMarketGlobalContextRows(rows: MarketGlobalContextRow[]): Promise<void>;
|
|
83
|
+
declare function upsertMarketReferenceAssetContextRows(rows: MarketReferenceAssetContextRow[]): Promise<void>;
|
|
84
|
+
declare function upsertMarketCmcExchangeLiquidityContextRows(rows: MarketCmcExchangeLiquidityContextRow[]): Promise<void>;
|
|
85
|
+
declare function upsertMarketCmcFearGreedContextRows(rows: MarketCmcFearGreedContextRow[]): Promise<void>;
|
|
86
|
+
declare function upsertMarketCmcIndexContextRows(rows: MarketCmcIndexContextRow[]): Promise<void>;
|
|
87
|
+
declare function getMarketContextBackfillCoverage(params: {
|
|
88
|
+
source: string;
|
|
89
|
+
scopes: string[];
|
|
90
|
+
interval: string;
|
|
91
|
+
fromMs: number;
|
|
92
|
+
toMs: number;
|
|
93
|
+
}): Promise<Array<{
|
|
94
|
+
source: string;
|
|
95
|
+
scope: string;
|
|
96
|
+
interval: string;
|
|
97
|
+
fromMs: number;
|
|
98
|
+
toMs: number;
|
|
99
|
+
rowsCount: number;
|
|
100
|
+
}>>;
|
|
101
|
+
declare function upsertMarketContextBackfillCoverage(rows: Array<{
|
|
102
|
+
source: string;
|
|
103
|
+
scope: string;
|
|
104
|
+
interval: string;
|
|
105
|
+
fromMs: number;
|
|
106
|
+
toMs: number;
|
|
107
|
+
rowsCount: number;
|
|
108
|
+
}>): Promise<void>;
|
|
109
|
+
type MarketFeatureAsOf<T> = T & {
|
|
110
|
+
ageMs: number | null;
|
|
111
|
+
stale: boolean;
|
|
112
|
+
};
|
|
113
|
+
declare function getLatestMarketTradeFlow(params: {
|
|
114
|
+
symbol: string;
|
|
115
|
+
interval: MarketFeatureInterval;
|
|
116
|
+
atMs: number;
|
|
117
|
+
maxAgeMs?: number;
|
|
118
|
+
}): Promise<MarketFeatureAsOf<MarketTradeFlowRow> | null>;
|
|
119
|
+
declare function getLatestMarketBreadth(params: {
|
|
120
|
+
universe: string;
|
|
121
|
+
interval: MarketFeatureInterval;
|
|
122
|
+
atMs: number;
|
|
123
|
+
maxAgeMs?: number;
|
|
124
|
+
}): Promise<MarketFeatureAsOf<MarketBreadthRow> | null>;
|
|
125
|
+
declare function getLatestMarketGlobalContext(params: {
|
|
126
|
+
source?: MarketGlobalContextRow['source'];
|
|
127
|
+
atMs: number;
|
|
128
|
+
maxAgeMs?: number;
|
|
129
|
+
}): Promise<(MarketFeatureAsOf<MarketGlobalContextRow> & {
|
|
130
|
+
btcDominanceChange24hPct: number | null;
|
|
131
|
+
ethDominanceChange24hPct: number | null;
|
|
132
|
+
altMarketCapChange24hPct: number | null;
|
|
133
|
+
altVolumeChange24hPct: number | null;
|
|
134
|
+
}) | null>;
|
|
135
|
+
declare function getMarketGlobalContextCoverage(params: {
|
|
136
|
+
source: MarketGlobalContextRow['source'];
|
|
137
|
+
startMs: number;
|
|
138
|
+
endMs: number;
|
|
139
|
+
}): Promise<{
|
|
140
|
+
firstMs: number;
|
|
141
|
+
lastMs: number;
|
|
142
|
+
rows: number;
|
|
143
|
+
} | null>;
|
|
144
|
+
declare function getMarketReferenceAssetContextCoverage(params: {
|
|
145
|
+
source: MarketReferenceAssetContextRow['source'];
|
|
146
|
+
symbols: string[];
|
|
147
|
+
interval: MarketReferenceAssetContextRow['interval'];
|
|
148
|
+
startMs: number;
|
|
149
|
+
endMs: number;
|
|
150
|
+
}): Promise<Map<string, {
|
|
151
|
+
firstMs: number;
|
|
152
|
+
lastMs: number;
|
|
153
|
+
rows: number;
|
|
154
|
+
}>>;
|
|
155
|
+
declare function getLatestMarketReferenceAssetContexts(params: {
|
|
156
|
+
source?: MarketReferenceAssetContextRow['source'];
|
|
157
|
+
symbols: string[];
|
|
158
|
+
interval?: MarketReferenceAssetContextRow['interval'];
|
|
159
|
+
atMs: number;
|
|
160
|
+
maxAgeMs?: number;
|
|
161
|
+
}): Promise<Map<string, MarketFeatureAsOf<MarketReferenceAssetContextRow>>>;
|
|
162
|
+
declare function getLatestMarketCmcExchangeLiquidityContext(params: {
|
|
163
|
+
source?: MarketCmcExchangeLiquidityContextRow['source'];
|
|
164
|
+
interval?: MarketCmcExchangeLiquidityContextRow['interval'];
|
|
165
|
+
atMs: number;
|
|
166
|
+
maxAgeMs?: number;
|
|
167
|
+
}): Promise<(MarketFeatureAsOf<MarketCmcExchangeLiquidityContextRow> & {
|
|
168
|
+
totalVolumeChange24hPct: number | null;
|
|
169
|
+
}) | null>;
|
|
170
|
+
declare function getLatestMarketCmcIndexContexts(params: {
|
|
171
|
+
source?: MarketCmcIndexContextRow['source'];
|
|
172
|
+
indexSlugs: MarketCmcIndexContextRow['indexSlug'][];
|
|
173
|
+
interval?: MarketCmcIndexContextRow['interval'];
|
|
174
|
+
atMs: number;
|
|
175
|
+
maxAgeMs?: number;
|
|
176
|
+
}): Promise<Map<MarketCmcIndexContextRow['indexSlug'], MarketFeatureAsOf<MarketCmcIndexContextRow> & {
|
|
177
|
+
valueChange24hPct: number | null;
|
|
178
|
+
}>>;
|
|
179
|
+
declare function getLatestMarketCmcFearGreedContext(params: {
|
|
180
|
+
source?: MarketCmcFearGreedContextRow['source'];
|
|
181
|
+
interval?: MarketCmcFearGreedContextRow['interval'];
|
|
182
|
+
atMs: number;
|
|
183
|
+
maxAgeMs?: number;
|
|
184
|
+
}): Promise<(MarketFeatureAsOf<MarketCmcFearGreedContextRow> & {
|
|
185
|
+
valueChange24h: number | null;
|
|
186
|
+
valueChange7d: number | null;
|
|
187
|
+
}) | null>;
|
|
188
|
+
declare function getMarketCmcFearGreedContextCoverage(params: {
|
|
189
|
+
source: MarketCmcFearGreedContextRow['source'];
|
|
190
|
+
interval: MarketCmcFearGreedContextRow['interval'];
|
|
191
|
+
startMs: number;
|
|
192
|
+
endMs: number;
|
|
193
|
+
}): Promise<{
|
|
194
|
+
firstMs: number;
|
|
195
|
+
lastMs: number;
|
|
196
|
+
rows: number;
|
|
197
|
+
} | null>;
|
|
198
|
+
declare function getMarketCmcExchangeLiquidityContextCoverage(params: {
|
|
199
|
+
source: MarketCmcExchangeLiquidityContextRow['source'];
|
|
200
|
+
interval: MarketCmcExchangeLiquidityContextRow['interval'];
|
|
201
|
+
startMs: number;
|
|
202
|
+
endMs: number;
|
|
203
|
+
}): Promise<{
|
|
204
|
+
firstMs: number;
|
|
205
|
+
lastMs: number;
|
|
206
|
+
rows: number;
|
|
207
|
+
} | null>;
|
|
208
|
+
declare function getMarketCmcIndexContextCoverage(params: {
|
|
209
|
+
source: MarketCmcIndexContextRow['source'];
|
|
210
|
+
indexSlugs: MarketCmcIndexContextRow['indexSlug'][];
|
|
211
|
+
interval: MarketCmcIndexContextRow['interval'];
|
|
212
|
+
startMs: number;
|
|
213
|
+
endMs: number;
|
|
214
|
+
}): Promise<Map<MarketCmcIndexContextRow['indexSlug'], {
|
|
215
|
+
firstMs: number;
|
|
216
|
+
lastMs: number;
|
|
217
|
+
rows: number;
|
|
218
|
+
}>>;
|
|
219
|
+
declare function getMarketTradeFlowCoverage(params: {
|
|
220
|
+
symbols: string[];
|
|
221
|
+
interval: MarketFeatureInterval;
|
|
222
|
+
startMs: number;
|
|
223
|
+
endMs: number;
|
|
224
|
+
}): Promise<Map<string, {
|
|
225
|
+
firstMs: number;
|
|
226
|
+
lastMs: number;
|
|
227
|
+
rows: number;
|
|
228
|
+
}>>;
|
|
229
|
+
type DeprecatedMarketContextCleanupItem = {
|
|
230
|
+
kind: 'table' | 'rows';
|
|
231
|
+
name: string;
|
|
232
|
+
rows: number;
|
|
233
|
+
action: 'drop_table' | 'delete_rows';
|
|
234
|
+
applied: boolean;
|
|
235
|
+
};
|
|
236
|
+
declare function cleanupDeprecatedMarketContext(params?: {
|
|
237
|
+
apply?: boolean;
|
|
238
|
+
}): Promise<DeprecatedMarketContextCleanupItem[]>;
|
|
239
|
+
declare function getMarketBreadthCoverage(params: {
|
|
240
|
+
universe: string;
|
|
241
|
+
interval: MarketFeatureInterval;
|
|
242
|
+
startMs: number;
|
|
243
|
+
endMs: number;
|
|
244
|
+
}): Promise<{
|
|
245
|
+
firstMs: number;
|
|
246
|
+
lastMs: number;
|
|
247
|
+
rows: number;
|
|
248
|
+
btcAltMetricsRows: number;
|
|
249
|
+
} | null>;
|
|
39
250
|
declare function getSpreadRangeForSymbols(symbols: string[], interval: DerivativesInterval, startMs: number, endMs: number): Promise<any[]>;
|
|
40
251
|
declare function getSpreadSummary(hours?: number, limit?: number): Promise<{
|
|
41
252
|
rows: any[];
|
|
@@ -47,6 +258,10 @@ declare function getDataEdges(provider: string, symbol: string, interval: number
|
|
|
47
258
|
min: number | undefined;
|
|
48
259
|
max: number | undefined;
|
|
49
260
|
}>;
|
|
261
|
+
declare function getDataEdgesForSymbols(provider: string, symbols: string[], interval: number): Promise<Map<string, {
|
|
262
|
+
min?: number;
|
|
263
|
+
max?: number;
|
|
264
|
+
}>>;
|
|
50
265
|
declare function waitForDbReady(attempts?: number, delayMs?: number): Promise<void>;
|
|
51
266
|
declare function deleteCandles(provider: string, symbol: string, interval: number): Promise<void>;
|
|
52
267
|
declare function findContinuityGap(provider: string, symbol: string, interval: number): Promise<{
|
|
@@ -55,4 +270,4 @@ declare function findContinuityGap(provider: string, symbol: string, interval: n
|
|
|
55
270
|
diffSeconds: number;
|
|
56
271
|
} | null>;
|
|
57
272
|
|
|
58
|
-
export { type CandleRow, deleteCandles, findContinuityGap, getCandlesRange, getDataEdges, getDerivativesDataEdgesForSymbols, getDerivativesRangeForSymbols, getDerivativesSummary, getDerivativesWindow, getSpreadRangeForSymbols, getSpreadSummary, toRows, upsertCandles, upsertDerivatives, upsertSpreadRows, waitForDbReady };
|
|
273
|
+
export { type CandleRow, type DeprecatedMarketContextCleanupItem, type MarketFeatureAsOf, cleanupDeprecatedMarketContext, closeTimescalePool, deleteCandles, findContinuityGap, getCandlesRange, getDataEdges, getDataEdgesForSymbols, getDerivativesBackfillCoverage, getDerivativesDataEdgesForSymbols, getDerivativesRangeForSymbols, getDerivativesSummary, getDerivativesWindow, getLatestMarketBreadth, getLatestMarketCmcExchangeLiquidityContext, getLatestMarketCmcFearGreedContext, getLatestMarketCmcIndexContexts, getLatestMarketGlobalContext, getLatestMarketReferenceAssetContexts, getLatestMarketTradeFlow, getMarketBreadthCoverage, getMarketCmcExchangeLiquidityContextCoverage, getMarketCmcFearGreedContextCoverage, getMarketCmcIndexContextCoverage, getMarketContextBackfillCoverage, getMarketGlobalContextCoverage, getMarketReferenceAssetContextCoverage, getMarketTradeFlowCoverage, getSpreadRangeForSymbols, getSpreadSummary, toRows, upsertCandles, upsertDerivatives, upsertDerivativesBackfillCoverage, upsertMarketBreadthRows, upsertMarketCmcExchangeLiquidityContextRows, upsertMarketCmcFearGreedContextRows, upsertMarketCmcIndexContextRows, upsertMarketContextBackfillCoverage, upsertMarketGlobalContextRows, upsertMarketReferenceAssetContextRows, upsertMarketTradeFlowRows, upsertSpreadRows, waitForDbReady };
|