@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,286 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureCandlesSchema,
|
|
3
|
+
getPool,
|
|
4
|
+
normalizeCandleProvider,
|
|
5
|
+
normalizeCandleSymbol
|
|
6
|
+
} from "./chunk-I2J6YDBD.mjs";
|
|
7
|
+
|
|
8
|
+
// src/timescale/candles.ts
|
|
9
|
+
var toRows = (provider, symbol, interval, data) => {
|
|
10
|
+
const normalizedProvider = normalizeCandleProvider(provider);
|
|
11
|
+
if (!normalizedProvider) {
|
|
12
|
+
throw new Error("Candle provider is required");
|
|
13
|
+
}
|
|
14
|
+
const normalizedSymbol = normalizeCandleSymbol(symbol);
|
|
15
|
+
return data.map((i) => ({
|
|
16
|
+
provider: normalizedProvider,
|
|
17
|
+
symbol: normalizedSymbol,
|
|
18
|
+
interval,
|
|
19
|
+
ts: new Date(i.timestamp),
|
|
20
|
+
// ms -> Date
|
|
21
|
+
open: i.open,
|
|
22
|
+
high: i.high,
|
|
23
|
+
low: i.low,
|
|
24
|
+
close: i.close,
|
|
25
|
+
volume: i.volume ?? null,
|
|
26
|
+
turnover: i.turnover ?? null,
|
|
27
|
+
takerBuyBaseVolume: i.takerBuyBaseVolume ?? null,
|
|
28
|
+
takerBuyQuoteVolume: i.takerBuyQuoteVolume ?? null,
|
|
29
|
+
takerSellBaseVolume: i.takerSellBaseVolume ?? null,
|
|
30
|
+
takerSellQuoteVolume: i.takerSellQuoteVolume ?? null
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
async function upsertCandles(rows) {
|
|
34
|
+
if (!rows.length) return;
|
|
35
|
+
await ensureCandlesSchema();
|
|
36
|
+
const pool = getPool();
|
|
37
|
+
const cols = [
|
|
38
|
+
"provider",
|
|
39
|
+
"symbol",
|
|
40
|
+
"interval",
|
|
41
|
+
"ts",
|
|
42
|
+
"open",
|
|
43
|
+
"high",
|
|
44
|
+
"low",
|
|
45
|
+
"close",
|
|
46
|
+
"volume",
|
|
47
|
+
"turnover",
|
|
48
|
+
"taker_buy_base_volume",
|
|
49
|
+
"taker_buy_quote_volume",
|
|
50
|
+
"taker_sell_base_volume",
|
|
51
|
+
"taker_sell_quote_volume"
|
|
52
|
+
];
|
|
53
|
+
const maxRows = Math.floor(65535 / cols.length);
|
|
54
|
+
if (rows.length > maxRows) {
|
|
55
|
+
for (let i = 0; i < rows.length; i += maxRows) {
|
|
56
|
+
await upsertCandles(rows.slice(i, i + maxRows));
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const valuesSql = rows.map(
|
|
61
|
+
(_, i) => `(${cols.map((__, j) => `$${i * cols.length + j + 1}`).join(",")})`
|
|
62
|
+
).join(",");
|
|
63
|
+
const flat = rows.flatMap((r) => [
|
|
64
|
+
normalizeCandleProvider(r.provider),
|
|
65
|
+
normalizeCandleSymbol(r.symbol),
|
|
66
|
+
r.interval,
|
|
67
|
+
r.ts,
|
|
68
|
+
r.open,
|
|
69
|
+
r.high,
|
|
70
|
+
r.low,
|
|
71
|
+
r.close,
|
|
72
|
+
r.volume ?? null,
|
|
73
|
+
r.turnover ?? null,
|
|
74
|
+
r.takerBuyBaseVolume ?? null,
|
|
75
|
+
r.takerBuyQuoteVolume ?? null,
|
|
76
|
+
r.takerSellBaseVolume ?? null,
|
|
77
|
+
r.takerSellQuoteVolume ?? null
|
|
78
|
+
]);
|
|
79
|
+
const sql = `
|
|
80
|
+
INSERT INTO candles (${cols.join(",")})
|
|
81
|
+
VALUES ${valuesSql}
|
|
82
|
+
ON CONFLICT (provider, symbol, interval, ts) DO UPDATE SET
|
|
83
|
+
open = EXCLUDED.open,
|
|
84
|
+
high = EXCLUDED.high,
|
|
85
|
+
low = EXCLUDED.low,
|
|
86
|
+
close = EXCLUDED.close,
|
|
87
|
+
volume = COALESCE(EXCLUDED.volume, candles.volume),
|
|
88
|
+
turnover = COALESCE(EXCLUDED.turnover, candles.turnover),
|
|
89
|
+
taker_buy_base_volume = COALESCE(EXCLUDED.taker_buy_base_volume, candles.taker_buy_base_volume),
|
|
90
|
+
taker_buy_quote_volume = COALESCE(EXCLUDED.taker_buy_quote_volume, candles.taker_buy_quote_volume),
|
|
91
|
+
taker_sell_base_volume = COALESCE(EXCLUDED.taker_sell_base_volume, candles.taker_sell_base_volume),
|
|
92
|
+
taker_sell_quote_volume = COALESCE(EXCLUDED.taker_sell_quote_volume, candles.taker_sell_quote_volume)
|
|
93
|
+
`;
|
|
94
|
+
const client = await pool.connect();
|
|
95
|
+
try {
|
|
96
|
+
await client.query("BEGIN");
|
|
97
|
+
await client.query(sql, flat);
|
|
98
|
+
await client.query("COMMIT");
|
|
99
|
+
} catch (e) {
|
|
100
|
+
await client.query("ROLLBACK");
|
|
101
|
+
throw e;
|
|
102
|
+
} finally {
|
|
103
|
+
client.release();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function getCandlesRange(provider, symbol, interval, startMs, endMs) {
|
|
107
|
+
await ensureCandlesSchema();
|
|
108
|
+
const pool = getPool();
|
|
109
|
+
const normalizedProvider = normalizeCandleProvider(provider);
|
|
110
|
+
const normalizedSymbol = normalizeCandleSymbol(symbol);
|
|
111
|
+
const sql = `
|
|
112
|
+
SELECT symbol, interval, ts,
|
|
113
|
+
open, high, low, close, volume, turnover,
|
|
114
|
+
taker_buy_base_volume AS "takerBuyBaseVolume",
|
|
115
|
+
taker_buy_quote_volume AS "takerBuyQuoteVolume",
|
|
116
|
+
taker_sell_base_volume AS "takerSellBaseVolume",
|
|
117
|
+
taker_sell_quote_volume AS "takerSellQuoteVolume"
|
|
118
|
+
FROM candles
|
|
119
|
+
WHERE provider = $1 AND symbol = $2 AND interval = $3
|
|
120
|
+
AND ts >= to_timestamp($4/1000.0)
|
|
121
|
+
AND ts <= to_timestamp($5/1000.0)
|
|
122
|
+
ORDER BY ts ASC
|
|
123
|
+
`;
|
|
124
|
+
const res = await pool.query(sql, [
|
|
125
|
+
normalizedProvider,
|
|
126
|
+
normalizedSymbol,
|
|
127
|
+
interval,
|
|
128
|
+
startMs,
|
|
129
|
+
endMs
|
|
130
|
+
]);
|
|
131
|
+
return res.rows;
|
|
132
|
+
}
|
|
133
|
+
async function getDataEdges(provider, symbol, interval) {
|
|
134
|
+
await ensureCandlesSchema();
|
|
135
|
+
const pool = getPool();
|
|
136
|
+
const normalizedProvider = normalizeCandleProvider(provider);
|
|
137
|
+
const normalizedSymbol = normalizeCandleSymbol(symbol);
|
|
138
|
+
const sqlMin = `
|
|
139
|
+
SELECT extract(epoch from ts)*1000 AS ms
|
|
140
|
+
FROM candles
|
|
141
|
+
WHERE provider=$1 AND symbol=$2 AND interval=$3
|
|
142
|
+
ORDER BY ts ASC
|
|
143
|
+
LIMIT 1
|
|
144
|
+
`;
|
|
145
|
+
const sqlMax = `
|
|
146
|
+
SELECT extract(epoch from ts)*1000 AS ms
|
|
147
|
+
FROM candles
|
|
148
|
+
WHERE provider=$1 AND symbol=$2 AND interval=$3
|
|
149
|
+
ORDER BY ts DESC
|
|
150
|
+
LIMIT 1
|
|
151
|
+
`;
|
|
152
|
+
const [minQ, maxQ] = await Promise.all([
|
|
153
|
+
pool.query(sqlMin, [normalizedProvider, normalizedSymbol, interval]),
|
|
154
|
+
pool.query(sqlMax, [normalizedProvider, normalizedSymbol, interval])
|
|
155
|
+
]);
|
|
156
|
+
const minRaw = minQ.rows[0]?.ms;
|
|
157
|
+
const maxRaw = maxQ.rows[0]?.ms;
|
|
158
|
+
const min = Number.isFinite(Number(minRaw)) ? Number(minRaw) : void 0;
|
|
159
|
+
const max = Number.isFinite(Number(maxRaw)) ? Number(maxRaw) : void 0;
|
|
160
|
+
return { min, max };
|
|
161
|
+
}
|
|
162
|
+
async function getDataEdgesForSymbols(provider, symbols, interval) {
|
|
163
|
+
const normalizedSymbols = [
|
|
164
|
+
...new Set(symbols.map(normalizeCandleSymbol).filter(Boolean))
|
|
165
|
+
];
|
|
166
|
+
const result = /* @__PURE__ */ new Map();
|
|
167
|
+
for (const symbol of normalizedSymbols) {
|
|
168
|
+
result.set(symbol, {});
|
|
169
|
+
}
|
|
170
|
+
if (!normalizedSymbols.length) {
|
|
171
|
+
return result;
|
|
172
|
+
}
|
|
173
|
+
await ensureCandlesSchema();
|
|
174
|
+
const pool = getPool();
|
|
175
|
+
const normalizedProvider = normalizeCandleProvider(provider);
|
|
176
|
+
const sql = `
|
|
177
|
+
WITH requested(symbol) AS (
|
|
178
|
+
SELECT unnest($2::text[])
|
|
179
|
+
)
|
|
180
|
+
SELECT
|
|
181
|
+
r.symbol,
|
|
182
|
+
(
|
|
183
|
+
SELECT extract(epoch from c.ts)*1000
|
|
184
|
+
FROM candles c
|
|
185
|
+
WHERE c.provider = $1 AND c.symbol = r.symbol AND c.interval = $3
|
|
186
|
+
ORDER BY c.ts ASC
|
|
187
|
+
LIMIT 1
|
|
188
|
+
) AS min_ms,
|
|
189
|
+
(
|
|
190
|
+
SELECT extract(epoch from c.ts)*1000
|
|
191
|
+
FROM candles c
|
|
192
|
+
WHERE c.provider = $1 AND c.symbol = r.symbol AND c.interval = $3
|
|
193
|
+
ORDER BY c.ts DESC
|
|
194
|
+
LIMIT 1
|
|
195
|
+
) AS max_ms
|
|
196
|
+
FROM requested r
|
|
197
|
+
`;
|
|
198
|
+
const response = await pool.query(sql, [
|
|
199
|
+
normalizedProvider,
|
|
200
|
+
normalizedSymbols,
|
|
201
|
+
interval
|
|
202
|
+
]);
|
|
203
|
+
for (const row of response.rows) {
|
|
204
|
+
const symbol = normalizeCandleSymbol(String(row.symbol || ""));
|
|
205
|
+
if (!symbol) continue;
|
|
206
|
+
const min = row.min_ms == null ? NaN : Number(row.min_ms);
|
|
207
|
+
const max = row.max_ms == null ? NaN : Number(row.max_ms);
|
|
208
|
+
result.set(symbol, {
|
|
209
|
+
...Number.isFinite(min) ? { min } : {},
|
|
210
|
+
...Number.isFinite(max) ? { max } : {}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
async function waitForDbReady(attempts = 20, delayMs = 1e3) {
|
|
216
|
+
const pool = getPool();
|
|
217
|
+
let lastError;
|
|
218
|
+
for (let i = 0; i < attempts; i++) {
|
|
219
|
+
try {
|
|
220
|
+
await pool.query("SELECT 1");
|
|
221
|
+
return;
|
|
222
|
+
} catch (e) {
|
|
223
|
+
lastError = e;
|
|
224
|
+
await new Promise((r) => setTimeout(r, delayMs));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
throw lastError;
|
|
228
|
+
}
|
|
229
|
+
async function deleteCandles(provider, symbol, interval) {
|
|
230
|
+
const pool = getPool();
|
|
231
|
+
const normalizedProvider = normalizeCandleProvider(provider);
|
|
232
|
+
const normalizedSymbol = normalizeCandleSymbol(symbol);
|
|
233
|
+
const sql = `
|
|
234
|
+
DELETE FROM candles
|
|
235
|
+
WHERE provider = $1 AND symbol = $2 AND interval = $3
|
|
236
|
+
`;
|
|
237
|
+
await pool.query(sql, [normalizedProvider, normalizedSymbol, interval]);
|
|
238
|
+
}
|
|
239
|
+
async function findContinuityGap(provider, symbol, interval) {
|
|
240
|
+
const pool = getPool();
|
|
241
|
+
const normalizedProvider = normalizeCandleProvider(provider);
|
|
242
|
+
const normalizedSymbol = normalizeCandleSymbol(symbol);
|
|
243
|
+
const expectedSeconds = interval * 60;
|
|
244
|
+
const sql = `
|
|
245
|
+
WITH ordered AS (
|
|
246
|
+
SELECT
|
|
247
|
+
ts,
|
|
248
|
+
LAG(ts) OVER (ORDER BY ts) AS prev_ts
|
|
249
|
+
FROM candles
|
|
250
|
+
WHERE provider = $1 AND symbol = $2 AND interval = $3
|
|
251
|
+
)
|
|
252
|
+
SELECT
|
|
253
|
+
ts,
|
|
254
|
+
prev_ts,
|
|
255
|
+
EXTRACT(EPOCH FROM (ts - prev_ts))::int AS diff_seconds
|
|
256
|
+
FROM ordered
|
|
257
|
+
WHERE prev_ts IS NOT NULL
|
|
258
|
+
AND EXTRACT(EPOCH FROM (ts - prev_ts))::int <> $4
|
|
259
|
+
ORDER BY ts ASC
|
|
260
|
+
LIMIT 1
|
|
261
|
+
`;
|
|
262
|
+
const res = await pool.query(sql, [
|
|
263
|
+
normalizedProvider,
|
|
264
|
+
normalizedSymbol,
|
|
265
|
+
interval,
|
|
266
|
+
expectedSeconds
|
|
267
|
+
]);
|
|
268
|
+
const row = res.rows[0];
|
|
269
|
+
if (!row) return null;
|
|
270
|
+
return {
|
|
271
|
+
ts: new Date(row.ts).getTime(),
|
|
272
|
+
prevTs: new Date(row.prev_ts).getTime(),
|
|
273
|
+
diffSeconds: row.diff_seconds
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export {
|
|
278
|
+
toRows,
|
|
279
|
+
upsertCandles,
|
|
280
|
+
getCandlesRange,
|
|
281
|
+
getDataEdges,
|
|
282
|
+
getDataEdgesForSymbols,
|
|
283
|
+
waitForDbReady,
|
|
284
|
+
deleteCandles,
|
|
285
|
+
findContinuityGap
|
|
286
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CoreResearchTraceEvent } from '@tradejs/types';
|
|
2
|
+
|
|
3
|
+
declare const getCoreResearchTraceFilePath: (params: {
|
|
4
|
+
strategyName: string;
|
|
5
|
+
chunkId: string;
|
|
6
|
+
outDir?: string;
|
|
7
|
+
}) => string;
|
|
8
|
+
declare const listCoreResearchTraceFiles: (params: {
|
|
9
|
+
strategyName: string;
|
|
10
|
+
runId: string;
|
|
11
|
+
outDir?: string;
|
|
12
|
+
}) => Promise<string[]>;
|
|
13
|
+
declare const appendCoreResearchTraceEvent: (params: {
|
|
14
|
+
strategyName: string;
|
|
15
|
+
chunkId: string;
|
|
16
|
+
event: CoreResearchTraceEvent;
|
|
17
|
+
outDir?: string;
|
|
18
|
+
}) => Promise<string>;
|
|
19
|
+
|
|
20
|
+
export { appendCoreResearchTraceEvent, getCoreResearchTraceFilePath, listCoreResearchTraceFiles };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CoreResearchTraceEvent } from '@tradejs/types';
|
|
2
|
+
|
|
3
|
+
declare const getCoreResearchTraceFilePath: (params: {
|
|
4
|
+
strategyName: string;
|
|
5
|
+
chunkId: string;
|
|
6
|
+
outDir?: string;
|
|
7
|
+
}) => string;
|
|
8
|
+
declare const listCoreResearchTraceFiles: (params: {
|
|
9
|
+
strategyName: string;
|
|
10
|
+
runId: string;
|
|
11
|
+
outDir?: string;
|
|
12
|
+
}) => Promise<string[]>;
|
|
13
|
+
declare const appendCoreResearchTraceEvent: (params: {
|
|
14
|
+
strategyName: string;
|
|
15
|
+
chunkId: string;
|
|
16
|
+
event: CoreResearchTraceEvent;
|
|
17
|
+
outDir?: string;
|
|
18
|
+
}) => Promise<string>;
|
|
19
|
+
|
|
20
|
+
export { appendCoreResearchTraceEvent, getCoreResearchTraceFilePath, listCoreResearchTraceFiles };
|
|
@@ -0,0 +1,89 @@
|
|
|
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/coreResearch.ts
|
|
31
|
+
var coreResearch_exports = {};
|
|
32
|
+
__export(coreResearch_exports, {
|
|
33
|
+
appendCoreResearchTraceEvent: () => appendCoreResearchTraceEvent,
|
|
34
|
+
getCoreResearchTraceFilePath: () => getCoreResearchTraceFilePath,
|
|
35
|
+
listCoreResearchTraceFiles: () => listCoreResearchTraceFiles
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(coreResearch_exports);
|
|
38
|
+
|
|
39
|
+
// src/coreResearchTraceFile.ts
|
|
40
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
41
|
+
var import_node_path = __toESM(require("path"));
|
|
42
|
+
|
|
43
|
+
// src/mlDatasetFile.ts
|
|
44
|
+
var import_node_readline = __toESM(require("readline"));
|
|
45
|
+
var toFileToken = (value) => value.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, "_").replace(/^_+|_+$/g, "") || "any";
|
|
46
|
+
|
|
47
|
+
// src/coreResearchTraceFile.ts
|
|
48
|
+
var DEFAULT_DIR = "data/research/core/trace";
|
|
49
|
+
var queueByPath = /* @__PURE__ */ new Map();
|
|
50
|
+
var getCoreResearchTraceFilePath = (params) => import_node_path.default.join(
|
|
51
|
+
params.outDir ?? DEFAULT_DIR,
|
|
52
|
+
`core-research-trace-${toFileToken(params.strategyName)}-chunk-${toFileToken(params.chunkId)}.jsonl`
|
|
53
|
+
);
|
|
54
|
+
var listCoreResearchTraceFiles = async (params) => {
|
|
55
|
+
const outDir = import_node_path.default.resolve(params.outDir ?? DEFAULT_DIR);
|
|
56
|
+
let names = [];
|
|
57
|
+
try {
|
|
58
|
+
names = await import_promises.default.readdir(outDir);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error.code === "ENOENT") return [];
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
const prefix = `core-research-trace-${toFileToken(params.strategyName)}-chunk-`;
|
|
64
|
+
return names.filter(
|
|
65
|
+
(name) => name.startsWith(prefix) && name.includes(toFileToken(params.runId)) && name.endsWith(".jsonl")
|
|
66
|
+
).sort((left, right) => left < right ? -1 : left > right ? 1 : 0).map((name) => import_node_path.default.join(outDir, name));
|
|
67
|
+
};
|
|
68
|
+
var appendCoreResearchTraceEvent = async (params) => {
|
|
69
|
+
const filePath = getCoreResearchTraceFilePath(params);
|
|
70
|
+
const previous = queueByPath.get(filePath) ?? Promise.resolve();
|
|
71
|
+
const next = previous.then(async () => {
|
|
72
|
+
await import_promises.default.mkdir(import_node_path.default.dirname(filePath), { recursive: true });
|
|
73
|
+
await import_promises.default.appendFile(filePath, `${JSON.stringify(params.event)}
|
|
74
|
+
`, "utf8");
|
|
75
|
+
});
|
|
76
|
+
queueByPath.set(filePath, next);
|
|
77
|
+
try {
|
|
78
|
+
await next;
|
|
79
|
+
} finally {
|
|
80
|
+
if (queueByPath.get(filePath) === next) queueByPath.delete(filePath);
|
|
81
|
+
}
|
|
82
|
+
return filePath;
|
|
83
|
+
};
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
appendCoreResearchTraceEvent,
|
|
87
|
+
getCoreResearchTraceFilePath,
|
|
88
|
+
listCoreResearchTraceFiles
|
|
89
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toFileToken
|
|
3
|
+
} from "./chunk-RQP5VSTH.mjs";
|
|
4
|
+
|
|
5
|
+
// src/coreResearchTraceFile.ts
|
|
6
|
+
import fs from "fs/promises";
|
|
7
|
+
import path from "path";
|
|
8
|
+
var DEFAULT_DIR = "data/research/core/trace";
|
|
9
|
+
var queueByPath = /* @__PURE__ */ new Map();
|
|
10
|
+
var getCoreResearchTraceFilePath = (params) => path.join(
|
|
11
|
+
params.outDir ?? DEFAULT_DIR,
|
|
12
|
+
`core-research-trace-${toFileToken(params.strategyName)}-chunk-${toFileToken(params.chunkId)}.jsonl`
|
|
13
|
+
);
|
|
14
|
+
var listCoreResearchTraceFiles = async (params) => {
|
|
15
|
+
const outDir = path.resolve(params.outDir ?? DEFAULT_DIR);
|
|
16
|
+
let names = [];
|
|
17
|
+
try {
|
|
18
|
+
names = await fs.readdir(outDir);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
if (error.code === "ENOENT") return [];
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
const prefix = `core-research-trace-${toFileToken(params.strategyName)}-chunk-`;
|
|
24
|
+
return names.filter(
|
|
25
|
+
(name) => name.startsWith(prefix) && name.includes(toFileToken(params.runId)) && name.endsWith(".jsonl")
|
|
26
|
+
).sort((left, right) => left < right ? -1 : left > right ? 1 : 0).map((name) => path.join(outDir, name));
|
|
27
|
+
};
|
|
28
|
+
var appendCoreResearchTraceEvent = async (params) => {
|
|
29
|
+
const filePath = getCoreResearchTraceFilePath(params);
|
|
30
|
+
const previous = queueByPath.get(filePath) ?? Promise.resolve();
|
|
31
|
+
const next = previous.then(async () => {
|
|
32
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
33
|
+
await fs.appendFile(filePath, `${JSON.stringify(params.event)}
|
|
34
|
+
`, "utf8");
|
|
35
|
+
});
|
|
36
|
+
queueByPath.set(filePath, next);
|
|
37
|
+
try {
|
|
38
|
+
await next;
|
|
39
|
+
} finally {
|
|
40
|
+
if (queueByPath.get(filePath) === next) queueByPath.delete(filePath);
|
|
41
|
+
}
|
|
42
|
+
return filePath;
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
appendCoreResearchTraceEvent,
|
|
46
|
+
getCoreResearchTraceFilePath,
|
|
47
|
+
listCoreResearchTraceFiles
|
|
48
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Pool } from 'pg';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
var __pgPool__: Pool | undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type TimescaleMarketContextQueryOptions = {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type TimescaleMarketContextSource = 'binance' | 'coinmarketcap' | 'derivatives' | 'hyperliquidWhales';
|
|
13
|
+
declare const configureTimescaleMarketContextSchemaMode: (mode: "ensure" | "verify") => void;
|
|
14
|
+
declare const closeTimescalePool: () => Promise<void>;
|
|
15
|
+
declare const ensureDerivativesSchema: () => Promise<void>;
|
|
16
|
+
declare const ensureBinanceMarketSchema: () => Promise<void>;
|
|
17
|
+
declare const ensureHyperliquidWhaleSchema: () => Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* CoinMarketCap tables currently share the historical market-context migration
|
|
20
|
+
* with the Binance tables. Keeping a source-specific entrypoint lets process
|
|
21
|
+
* composition own schema preparation without exposing that storage detail.
|
|
22
|
+
*/
|
|
23
|
+
declare const ensureCoinMarketCapContextSchema: () => Promise<void>;
|
|
24
|
+
declare const ensureMarketContextSchemas: (sources: Iterable<TimescaleMarketContextSource>) => Promise<void>;
|
|
25
|
+
|
|
26
|
+
export { type TimescaleMarketContextQueryOptions as T, type TimescaleMarketContextSource as a, configureTimescaleMarketContextSchemaMode as b, closeTimescalePool as c, ensureCoinMarketCapContextSchema as d, ensureBinanceMarketSchema as e, ensureDerivativesSchema as f, ensureHyperliquidWhaleSchema as g, ensureMarketContextSchemas as h };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Pool } from 'pg';
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
var __pgPool__: Pool | undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type TimescaleMarketContextQueryOptions = {
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type TimescaleMarketContextSource = 'binance' | 'coinmarketcap' | 'derivatives' | 'hyperliquidWhales';
|
|
13
|
+
declare const configureTimescaleMarketContextSchemaMode: (mode: "ensure" | "verify") => void;
|
|
14
|
+
declare const closeTimescalePool: () => Promise<void>;
|
|
15
|
+
declare const ensureDerivativesSchema: () => Promise<void>;
|
|
16
|
+
declare const ensureBinanceMarketSchema: () => Promise<void>;
|
|
17
|
+
declare const ensureHyperliquidWhaleSchema: () => Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* CoinMarketCap tables currently share the historical market-context migration
|
|
20
|
+
* with the Binance tables. Keeping a source-specific entrypoint lets process
|
|
21
|
+
* composition own schema preparation without exposing that storage detail.
|
|
22
|
+
*/
|
|
23
|
+
declare const ensureCoinMarketCapContextSchema: () => Promise<void>;
|
|
24
|
+
declare const ensureMarketContextSchemas: (sources: Iterable<TimescaleMarketContextSource>) => Promise<void>;
|
|
25
|
+
|
|
26
|
+
export { type TimescaleMarketContextQueryOptions as T, type TimescaleMarketContextSource as a, configureTimescaleMarketContextSchemaMode as b, closeTimescalePool as c, ensureCoinMarketCapContextSchema as d, ensureBinanceMarketSchema as e, ensureDerivativesSchema as f, ensureHyperliquidWhaleSchema as g, ensureMarketContextSchemas as h };
|
package/dist/ml.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
logger
|
|
3
|
+
} from "./chunk-LNFUOXDW.mjs";
|
|
1
4
|
import {
|
|
2
5
|
appendMlDatasetRow,
|
|
3
6
|
closeAllMlDatasetWriters,
|
|
@@ -10,9 +13,6 @@ import {
|
|
|
10
13
|
mergeJsonlFiles,
|
|
11
14
|
toFileToken
|
|
12
15
|
} from "./chunk-RQP5VSTH.mjs";
|
|
13
|
-
import {
|
|
14
|
-
logger
|
|
15
|
-
} from "./chunk-LNFUOXDW.mjs";
|
|
16
16
|
|
|
17
17
|
// src/mlGrpc.ts
|
|
18
18
|
import path from "path";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RuntimeDeployment, RuntimeDeploymentHeartbeat } from '@tradejs/types';
|
|
2
|
+
|
|
3
|
+
declare const listRuntimeDeployments: (userName: string) => Promise<RuntimeDeployment[]>;
|
|
4
|
+
declare const getRuntimeDeployment: (userName: string, deploymentId: string) => Promise<RuntimeDeployment | null>;
|
|
5
|
+
declare const saveRuntimeDeployment: (userName: string, deployment: RuntimeDeployment) => Promise<RuntimeDeployment>;
|
|
6
|
+
declare const deleteRuntimeDeployment: (userName: string, deploymentId: string) => Promise<void>;
|
|
7
|
+
declare const getRuntimeDeploymentHeartbeat: (userName: string, deploymentId: string) => Promise<RuntimeDeploymentHeartbeat | null>;
|
|
8
|
+
declare const saveRuntimeDeploymentHeartbeat: (userName: string, heartbeat: RuntimeDeploymentHeartbeat) => Promise<RuntimeDeploymentHeartbeat>;
|
|
9
|
+
|
|
10
|
+
export { deleteRuntimeDeployment, getRuntimeDeployment, getRuntimeDeploymentHeartbeat, listRuntimeDeployments, saveRuntimeDeployment, saveRuntimeDeploymentHeartbeat };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RuntimeDeployment, RuntimeDeploymentHeartbeat } from '@tradejs/types';
|
|
2
|
+
|
|
3
|
+
declare const listRuntimeDeployments: (userName: string) => Promise<RuntimeDeployment[]>;
|
|
4
|
+
declare const getRuntimeDeployment: (userName: string, deploymentId: string) => Promise<RuntimeDeployment | null>;
|
|
5
|
+
declare const saveRuntimeDeployment: (userName: string, deployment: RuntimeDeployment) => Promise<RuntimeDeployment>;
|
|
6
|
+
declare const deleteRuntimeDeployment: (userName: string, deploymentId: string) => Promise<void>;
|
|
7
|
+
declare const getRuntimeDeploymentHeartbeat: (userName: string, deploymentId: string) => Promise<RuntimeDeploymentHeartbeat | null>;
|
|
8
|
+
declare const saveRuntimeDeploymentHeartbeat: (userName: string, heartbeat: RuntimeDeploymentHeartbeat) => Promise<RuntimeDeploymentHeartbeat>;
|
|
9
|
+
|
|
10
|
+
export { deleteRuntimeDeployment, getRuntimeDeployment, getRuntimeDeploymentHeartbeat, listRuntimeDeployments, saveRuntimeDeployment, saveRuntimeDeploymentHeartbeat };
|