@tradejs/infra 1.0.10 → 1.0.12
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/{chunk-DXG2UDNA.mjs → chunk-XZQ6COOV.mjs} +2 -0
- package/dist/redis.d.mts +2 -0
- package/dist/redis.d.ts +2 -0
- package/dist/redis.js +2 -0
- package/dist/redis.mjs +1 -1
- package/dist/timescale.d.mts +1 -0
- package/dist/timescale.d.ts +1 -0
- package/dist/timescale.js +48 -9
- package/dist/timescale.mjs +48 -9
- package/dist/tradingAccounts.js +2 -0
- package/dist/tradingAccounts.mjs +1 -1
- package/dist/userSettings.js +2 -0
- package/dist/userSettings.mjs +1 -1
- package/package.json +2 -2
|
@@ -490,6 +490,8 @@ var redisKeys = {
|
|
|
490
490
|
analysis: (symbol, signalId) => `analysis:${symbol}:${signalId}`,
|
|
491
491
|
screenshotSessionToken: (token) => `auth:screenshot:${token}`,
|
|
492
492
|
backtestResults: (userName, config, timestamp) => `users:${userName}:backtests:results:${config}:${timestamp}`,
|
|
493
|
+
backtestJobs: (userName) => `users:${userName}:backtests:jobs:`,
|
|
494
|
+
backtestJob: (userName, jobId) => `users:${userName}:backtests:jobs:${jobId}`,
|
|
493
495
|
backtestRuns: (userName) => `users:${userName}:backtests:runs:`,
|
|
494
496
|
backtestRun: (userName, runId) => `users:${userName}:backtests:runs:${runId}`,
|
|
495
497
|
backtestRunResults: (userName, runId) => `users:${userName}:backtests:runs:${runId}:results`,
|
package/dist/redis.d.mts
CHANGED
|
@@ -76,6 +76,8 @@ declare const redisKeys: {
|
|
|
76
76
|
analysis: (symbol: string, signalId: string) => string;
|
|
77
77
|
screenshotSessionToken: (token: string) => string;
|
|
78
78
|
backtestResults: (userName: string, config: string, timestamp: string) => string;
|
|
79
|
+
backtestJobs: (userName: string) => string;
|
|
80
|
+
backtestJob: (userName: string, jobId: string) => string;
|
|
79
81
|
backtestRuns: (userName: string) => string;
|
|
80
82
|
backtestRun: (userName: string, runId: string) => string;
|
|
81
83
|
backtestRunResults: (userName: string, runId: string) => string;
|
package/dist/redis.d.ts
CHANGED
|
@@ -76,6 +76,8 @@ declare const redisKeys: {
|
|
|
76
76
|
analysis: (symbol: string, signalId: string) => string;
|
|
77
77
|
screenshotSessionToken: (token: string) => string;
|
|
78
78
|
backtestResults: (userName: string, config: string, timestamp: string) => string;
|
|
79
|
+
backtestJobs: (userName: string) => string;
|
|
80
|
+
backtestJob: (userName: string, jobId: string) => string;
|
|
79
81
|
backtestRuns: (userName: string) => string;
|
|
80
82
|
backtestRun: (userName: string, runId: string) => string;
|
|
81
83
|
backtestRunResults: (userName: string, runId: string) => string;
|
package/dist/redis.js
CHANGED
|
@@ -539,6 +539,8 @@ var redisKeys = {
|
|
|
539
539
|
analysis: (symbol, signalId) => `analysis:${symbol}:${signalId}`,
|
|
540
540
|
screenshotSessionToken: (token) => `auth:screenshot:${token}`,
|
|
541
541
|
backtestResults: (userName, config, timestamp) => `users:${userName}:backtests:results:${config}:${timestamp}`,
|
|
542
|
+
backtestJobs: (userName) => `users:${userName}:backtests:jobs:`,
|
|
543
|
+
backtestJob: (userName, jobId) => `users:${userName}:backtests:jobs:${jobId}`,
|
|
542
544
|
backtestRuns: (userName) => `users:${userName}:backtests:runs:`,
|
|
543
545
|
backtestRun: (userName, runId) => `users:${userName}:backtests:runs:${runId}`,
|
|
544
546
|
backtestRunResults: (userName, runId) => `users:${userName}:backtests:runs:${runId}:results`,
|
package/dist/redis.mjs
CHANGED
package/dist/timescale.d.mts
CHANGED
package/dist/timescale.d.ts
CHANGED
package/dist/timescale.js
CHANGED
|
@@ -141,6 +141,38 @@ var ensureCandlesSchema = async () => {
|
|
|
141
141
|
CANDLES_SCHEMA_LOCK_KEY,
|
|
142
142
|
async () => {
|
|
143
143
|
const pool = getPool();
|
|
144
|
+
await pool.query("CREATE EXTENSION IF NOT EXISTS timescaledb");
|
|
145
|
+
await pool.query(`
|
|
146
|
+
CREATE TABLE IF NOT EXISTS candles (
|
|
147
|
+
provider text NOT NULL DEFAULT 'bybit',
|
|
148
|
+
symbol text NOT NULL,
|
|
149
|
+
interval integer NOT NULL,
|
|
150
|
+
ts timestamptz NOT NULL,
|
|
151
|
+
open double precision NOT NULL,
|
|
152
|
+
high double precision NOT NULL,
|
|
153
|
+
low double precision NOT NULL,
|
|
154
|
+
close double precision NOT NULL,
|
|
155
|
+
volume double precision,
|
|
156
|
+
turnover double precision,
|
|
157
|
+
taker_buy_base_volume double precision,
|
|
158
|
+
taker_buy_quote_volume double precision,
|
|
159
|
+
taker_sell_base_volume double precision,
|
|
160
|
+
taker_sell_quote_volume double precision,
|
|
161
|
+
PRIMARY KEY (provider, symbol, interval, ts)
|
|
162
|
+
)
|
|
163
|
+
`);
|
|
164
|
+
await pool.query(`
|
|
165
|
+
SELECT create_hypertable(
|
|
166
|
+
'candles',
|
|
167
|
+
'ts',
|
|
168
|
+
if_not_exists => TRUE,
|
|
169
|
+
chunk_time_interval => interval '7 days'
|
|
170
|
+
)
|
|
171
|
+
`);
|
|
172
|
+
await pool.query(`
|
|
173
|
+
CREATE INDEX IF NOT EXISTS candles_provider_symbol_interval_ts_idx
|
|
174
|
+
ON candles (provider, symbol, interval, ts DESC)
|
|
175
|
+
`);
|
|
144
176
|
await pool.query(`
|
|
145
177
|
ALTER TABLE candles
|
|
146
178
|
ADD COLUMN IF NOT EXISTS taker_buy_base_volume double precision,
|
|
@@ -1490,7 +1522,8 @@ async function getMarketContextBackfillCoverage(params) {
|
|
|
1490
1522
|
interval,
|
|
1491
1523
|
extract(epoch from from_ts)*1000 AS from_ms,
|
|
1492
1524
|
extract(epoch from to_ts)*1000 AS to_ms,
|
|
1493
|
-
rows_count
|
|
1525
|
+
rows_count,
|
|
1526
|
+
extract(epoch from checked_at)*1000 AS checked_at_ms
|
|
1494
1527
|
FROM market_context_backfill_coverage
|
|
1495
1528
|
WHERE source = $1
|
|
1496
1529
|
AND scope = ANY($2)
|
|
@@ -1500,14 +1533,18 @@ async function getMarketContextBackfillCoverage(params) {
|
|
|
1500
1533
|
`,
|
|
1501
1534
|
[source, scopes, interval, params.fromMs, params.toMs]
|
|
1502
1535
|
);
|
|
1503
|
-
return res.rows.map((row) =>
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1536
|
+
return res.rows.map((row) => {
|
|
1537
|
+
const checkedAtMs = Number(row.checked_at_ms);
|
|
1538
|
+
return {
|
|
1539
|
+
source: String(row.source).toLowerCase(),
|
|
1540
|
+
scope: String(row.scope).toLowerCase(),
|
|
1541
|
+
interval: String(row.interval).toLowerCase(),
|
|
1542
|
+
fromMs: Number(row.from_ms),
|
|
1543
|
+
toMs: Number(row.to_ms),
|
|
1544
|
+
rowsCount: Number(row.rows_count ?? 0),
|
|
1545
|
+
...Number.isFinite(checkedAtMs) ? { checkedAtMs } : {}
|
|
1546
|
+
};
|
|
1547
|
+
});
|
|
1511
1548
|
}
|
|
1512
1549
|
async function upsertMarketContextBackfillCoverage(rows) {
|
|
1513
1550
|
const normalizedRows = rows.map((row) => ({
|
|
@@ -2321,6 +2358,7 @@ async function getCandlesRange(provider, symbol, interval, startMs, endMs) {
|
|
|
2321
2358
|
return res.rows;
|
|
2322
2359
|
}
|
|
2323
2360
|
async function getDataEdges(provider, symbol, interval) {
|
|
2361
|
+
await ensureCandlesSchema();
|
|
2324
2362
|
const pool = getPool();
|
|
2325
2363
|
const normalizedProvider = normalizeCandleProvider(provider);
|
|
2326
2364
|
const normalizedSymbol = normalizeCandleSymbol(symbol);
|
|
@@ -2359,6 +2397,7 @@ async function getDataEdgesForSymbols(provider, symbols, interval) {
|
|
|
2359
2397
|
if (!normalizedSymbols.length) {
|
|
2360
2398
|
return result;
|
|
2361
2399
|
}
|
|
2400
|
+
await ensureCandlesSchema();
|
|
2362
2401
|
const pool = getPool();
|
|
2363
2402
|
const normalizedProvider = normalizeCandleProvider(provider);
|
|
2364
2403
|
const sql = `
|
package/dist/timescale.mjs
CHANGED
|
@@ -75,6 +75,38 @@ var ensureCandlesSchema = async () => {
|
|
|
75
75
|
CANDLES_SCHEMA_LOCK_KEY,
|
|
76
76
|
async () => {
|
|
77
77
|
const pool = getPool();
|
|
78
|
+
await pool.query("CREATE EXTENSION IF NOT EXISTS timescaledb");
|
|
79
|
+
await pool.query(`
|
|
80
|
+
CREATE TABLE IF NOT EXISTS candles (
|
|
81
|
+
provider text NOT NULL DEFAULT 'bybit',
|
|
82
|
+
symbol text NOT NULL,
|
|
83
|
+
interval integer NOT NULL,
|
|
84
|
+
ts timestamptz NOT NULL,
|
|
85
|
+
open double precision NOT NULL,
|
|
86
|
+
high double precision NOT NULL,
|
|
87
|
+
low double precision NOT NULL,
|
|
88
|
+
close double precision NOT NULL,
|
|
89
|
+
volume double precision,
|
|
90
|
+
turnover double precision,
|
|
91
|
+
taker_buy_base_volume double precision,
|
|
92
|
+
taker_buy_quote_volume double precision,
|
|
93
|
+
taker_sell_base_volume double precision,
|
|
94
|
+
taker_sell_quote_volume double precision,
|
|
95
|
+
PRIMARY KEY (provider, symbol, interval, ts)
|
|
96
|
+
)
|
|
97
|
+
`);
|
|
98
|
+
await pool.query(`
|
|
99
|
+
SELECT create_hypertable(
|
|
100
|
+
'candles',
|
|
101
|
+
'ts',
|
|
102
|
+
if_not_exists => TRUE,
|
|
103
|
+
chunk_time_interval => interval '7 days'
|
|
104
|
+
)
|
|
105
|
+
`);
|
|
106
|
+
await pool.query(`
|
|
107
|
+
CREATE INDEX IF NOT EXISTS candles_provider_symbol_interval_ts_idx
|
|
108
|
+
ON candles (provider, symbol, interval, ts DESC)
|
|
109
|
+
`);
|
|
78
110
|
await pool.query(`
|
|
79
111
|
ALTER TABLE candles
|
|
80
112
|
ADD COLUMN IF NOT EXISTS taker_buy_base_volume double precision,
|
|
@@ -1424,7 +1456,8 @@ async function getMarketContextBackfillCoverage(params) {
|
|
|
1424
1456
|
interval,
|
|
1425
1457
|
extract(epoch from from_ts)*1000 AS from_ms,
|
|
1426
1458
|
extract(epoch from to_ts)*1000 AS to_ms,
|
|
1427
|
-
rows_count
|
|
1459
|
+
rows_count,
|
|
1460
|
+
extract(epoch from checked_at)*1000 AS checked_at_ms
|
|
1428
1461
|
FROM market_context_backfill_coverage
|
|
1429
1462
|
WHERE source = $1
|
|
1430
1463
|
AND scope = ANY($2)
|
|
@@ -1434,14 +1467,18 @@ async function getMarketContextBackfillCoverage(params) {
|
|
|
1434
1467
|
`,
|
|
1435
1468
|
[source, scopes, interval, params.fromMs, params.toMs]
|
|
1436
1469
|
);
|
|
1437
|
-
return res.rows.map((row) =>
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1470
|
+
return res.rows.map((row) => {
|
|
1471
|
+
const checkedAtMs = Number(row.checked_at_ms);
|
|
1472
|
+
return {
|
|
1473
|
+
source: String(row.source).toLowerCase(),
|
|
1474
|
+
scope: String(row.scope).toLowerCase(),
|
|
1475
|
+
interval: String(row.interval).toLowerCase(),
|
|
1476
|
+
fromMs: Number(row.from_ms),
|
|
1477
|
+
toMs: Number(row.to_ms),
|
|
1478
|
+
rowsCount: Number(row.rows_count ?? 0),
|
|
1479
|
+
...Number.isFinite(checkedAtMs) ? { checkedAtMs } : {}
|
|
1480
|
+
};
|
|
1481
|
+
});
|
|
1445
1482
|
}
|
|
1446
1483
|
async function upsertMarketContextBackfillCoverage(rows) {
|
|
1447
1484
|
const normalizedRows = rows.map((row) => ({
|
|
@@ -2255,6 +2292,7 @@ async function getCandlesRange(provider, symbol, interval, startMs, endMs) {
|
|
|
2255
2292
|
return res.rows;
|
|
2256
2293
|
}
|
|
2257
2294
|
async function getDataEdges(provider, symbol, interval) {
|
|
2295
|
+
await ensureCandlesSchema();
|
|
2258
2296
|
const pool = getPool();
|
|
2259
2297
|
const normalizedProvider = normalizeCandleProvider(provider);
|
|
2260
2298
|
const normalizedSymbol = normalizeCandleSymbol(symbol);
|
|
@@ -2293,6 +2331,7 @@ async function getDataEdgesForSymbols(provider, symbols, interval) {
|
|
|
2293
2331
|
if (!normalizedSymbols.length) {
|
|
2294
2332
|
return result;
|
|
2295
2333
|
}
|
|
2334
|
+
await ensureCandlesSchema();
|
|
2296
2335
|
const pool = getPool();
|
|
2297
2336
|
const normalizedProvider = normalizeCandleProvider(provider);
|
|
2298
2337
|
const sql = `
|
package/dist/tradingAccounts.js
CHANGED
|
@@ -356,6 +356,8 @@ var redisKeys = {
|
|
|
356
356
|
analysis: (symbol, signalId) => `analysis:${symbol}:${signalId}`,
|
|
357
357
|
screenshotSessionToken: (token) => `auth:screenshot:${token}`,
|
|
358
358
|
backtestResults: (userName, config, timestamp) => `users:${userName}:backtests:results:${config}:${timestamp}`,
|
|
359
|
+
backtestJobs: (userName) => `users:${userName}:backtests:jobs:`,
|
|
360
|
+
backtestJob: (userName, jobId) => `users:${userName}:backtests:jobs:${jobId}`,
|
|
359
361
|
backtestRuns: (userName) => `users:${userName}:backtests:runs:`,
|
|
360
362
|
backtestRun: (userName, runId) => `users:${userName}:backtests:runs:${runId}`,
|
|
361
363
|
backtestRunResults: (userName, runId) => `users:${userName}:backtests:runs:${runId}:results`,
|
package/dist/tradingAccounts.mjs
CHANGED
package/dist/userSettings.js
CHANGED
|
@@ -588,6 +588,8 @@ var redisKeys = {
|
|
|
588
588
|
analysis: (symbol, signalId) => `analysis:${symbol}:${signalId}`,
|
|
589
589
|
screenshotSessionToken: (token) => `auth:screenshot:${token}`,
|
|
590
590
|
backtestResults: (userName, config, timestamp) => `users:${userName}:backtests:results:${config}:${timestamp}`,
|
|
591
|
+
backtestJobs: (userName) => `users:${userName}:backtests:jobs:`,
|
|
592
|
+
backtestJob: (userName, jobId) => `users:${userName}:backtests:jobs:${jobId}`,
|
|
591
593
|
backtestRuns: (userName) => `users:${userName}:backtests:runs:`,
|
|
592
594
|
backtestRun: (userName, runId) => `users:${userName}:backtests:runs:${runId}`,
|
|
593
595
|
backtestRunResults: (userName, runId) => `users:${userName}:backtests:runs:${runId}:results`,
|
package/dist/userSettings.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/infra",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Server-only infrastructure adapters for the TradeJS open-source framework: Redis, Timescale, ML, logging, and IO.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"dependencies": {
|
|
94
94
|
"@grpc/grpc-js": "^1.10.7",
|
|
95
95
|
"@grpc/proto-loader": "^0.8.0",
|
|
96
|
-
"@tradejs/types": "^1.0.
|
|
96
|
+
"@tradejs/types": "^1.0.12",
|
|
97
97
|
"chalk": "4.1.2",
|
|
98
98
|
"ioredis": "5.8.0",
|
|
99
99
|
"pg": "8.16.3",
|