@tradejs/infra 2.0.21 → 3.0.1
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-YVIHTUV5.mjs → chunk-OLB6NQRG.mjs} +1 -1
- package/dist/{chunk-I2J6YDBD.mjs → chunk-ZXU7OYFU.mjs} +65 -38
- package/dist/internal-BuHqoCCV.d.mts +9 -0
- package/dist/internal-q48Torp4.d.ts +9 -0
- package/dist/ml.mjs +3 -3
- package/dist/query-tkHVD4Xo.d.mts +12 -0
- package/dist/query-tkHVD4Xo.d.ts +12 -0
- package/dist/timescale/candles.js +6 -4
- package/dist/timescale/candles.mjs +2 -2
- package/dist/timescale/client.d.mts +3 -2
- package/dist/timescale/client.d.ts +3 -2
- package/dist/timescale/client.js +40 -15
- package/dist/timescale/client.mjs +2 -2
- package/dist/timescale/derivatives.d.mts +4 -2
- package/dist/timescale/derivatives.d.ts +4 -2
- package/dist/timescale/derivatives.js +20 -12
- package/dist/timescale/derivatives.mjs +479 -13
- package/dist/timescale/hyperliquidWhales.d.mts +29 -25
- package/dist/timescale/hyperliquidWhales.d.ts +29 -25
- package/dist/timescale/hyperliquidWhales.js +84 -71
- package/dist/timescale/hyperliquidWhales.mjs +1103 -14
- package/dist/timescale/marketContext.d.mts +15 -11
- package/dist/timescale/marketContext.d.ts +15 -11
- package/dist/timescale/marketContext.js +67 -57
- package/dist/timescale/marketContext.mjs +1259 -28
- package/dist/timescale/spread.js +6 -4
- package/dist/timescale/spread.mjs +105 -5
- package/dist/userSettings.js +3 -316
- package/dist/userSettings.mjs +3 -21
- package/package.json +2 -22
- package/dist/aiEndpoints.d.mts +0 -10
- package/dist/aiEndpoints.d.ts +0 -10
- package/dist/aiEndpoints.js +0 -159
- package/dist/aiEndpoints.mjs +0 -12
- package/dist/aiLanguages.d.mts +0 -11
- package/dist/aiLanguages.d.ts +0 -11
- package/dist/aiLanguages.js +0 -71
- package/dist/aiLanguages.mjs +0 -12
- package/dist/aiModels.d.mts +0 -12
- package/dist/aiModels.d.ts +0 -12
- package/dist/aiModels.js +0 -272
- package/dist/aiModels.mjs +0 -17
- package/dist/chunk-2CZREG43.mjs +0 -112
- package/dist/chunk-CCC7DX2T.mjs +0 -44
- package/dist/chunk-DFMKDB2R.mjs +0 -1285
- package/dist/chunk-DTCLZIBM.mjs +0 -163
- package/dist/chunk-NWXFWTWU.mjs +0 -1114
- package/dist/chunk-SZQB7ER5.mjs +0 -492
- package/dist/chunk-XQ3YBULV.mjs +0 -132
- package/dist/internal-2coHaaos.d.mts +0 -26
- package/dist/internal-2coHaaos.d.ts +0 -26
- package/dist/timescale.d.mts +0 -9
- package/dist/timescale.d.ts +0 -9
- package/dist/timescale.js +0 -4228
- package/dist/timescale.mjs +0 -138
package/dist/chunk-SZQB7ER5.mjs
DELETED
|
@@ -1,492 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ensureDerivativesSchema,
|
|
3
|
-
getPool,
|
|
4
|
-
normalizeCandleSymbol,
|
|
5
|
-
prepareMarketContextSchemaForRead,
|
|
6
|
-
queryMarketContext
|
|
7
|
-
} from "./chunk-I2J6YDBD.mjs";
|
|
8
|
-
|
|
9
|
-
// src/timescale/derivatives.ts
|
|
10
|
-
async function upsertDerivatives(rows) {
|
|
11
|
-
if (!rows.length) return;
|
|
12
|
-
await ensureDerivativesSchema();
|
|
13
|
-
const pool = getPool();
|
|
14
|
-
const cols = [
|
|
15
|
-
"symbol",
|
|
16
|
-
"interval",
|
|
17
|
-
"ts",
|
|
18
|
-
"open_interest",
|
|
19
|
-
"funding_rate",
|
|
20
|
-
"liq_long",
|
|
21
|
-
"liq_short",
|
|
22
|
-
"liq_total",
|
|
23
|
-
"source"
|
|
24
|
-
];
|
|
25
|
-
const maxRows = Math.floor(65535 / cols.length);
|
|
26
|
-
if (rows.length > maxRows) {
|
|
27
|
-
for (let i = 0; i < rows.length; i += maxRows) {
|
|
28
|
-
await upsertDerivatives(rows.slice(i, i + maxRows));
|
|
29
|
-
}
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const valuesSql = rows.map(
|
|
33
|
-
(_, i) => `(${cols.map((__, j) => `$${i * cols.length + j + 1}`).join(",")})`
|
|
34
|
-
).join(",");
|
|
35
|
-
const flat = rows.flatMap((row) => [
|
|
36
|
-
row.symbol,
|
|
37
|
-
row.interval,
|
|
38
|
-
row.ts,
|
|
39
|
-
row.openInterest ?? null,
|
|
40
|
-
row.fundingRate ?? null,
|
|
41
|
-
row.liqLong ?? null,
|
|
42
|
-
row.liqShort ?? null,
|
|
43
|
-
row.liqTotal ?? null,
|
|
44
|
-
row.source ?? null
|
|
45
|
-
]);
|
|
46
|
-
const sql = `
|
|
47
|
-
INSERT INTO derivatives_market (${cols.join(",")})
|
|
48
|
-
VALUES ${valuesSql}
|
|
49
|
-
ON CONFLICT (symbol, interval, ts) DO UPDATE SET
|
|
50
|
-
open_interest = COALESCE(EXCLUDED.open_interest, derivatives_market.open_interest),
|
|
51
|
-
funding_rate = COALESCE(EXCLUDED.funding_rate, derivatives_market.funding_rate),
|
|
52
|
-
liq_long = COALESCE(EXCLUDED.liq_long, derivatives_market.liq_long),
|
|
53
|
-
liq_short = COALESCE(EXCLUDED.liq_short, derivatives_market.liq_short),
|
|
54
|
-
liq_total = COALESCE(EXCLUDED.liq_total, derivatives_market.liq_total),
|
|
55
|
-
source = COALESCE(EXCLUDED.source, derivatives_market.source),
|
|
56
|
-
ingested_at = now()
|
|
57
|
-
`;
|
|
58
|
-
await pool.query(sql, flat);
|
|
59
|
-
}
|
|
60
|
-
async function getDerivativesRangeForSymbols(symbols, interval, startMs, endMs) {
|
|
61
|
-
if (!symbols.length)
|
|
62
|
-
return [];
|
|
63
|
-
await ensureDerivativesSchema();
|
|
64
|
-
const pool = getPool();
|
|
65
|
-
const sql = `
|
|
66
|
-
SELECT symbol, interval, ts, open_interest, funding_rate, liq_long, liq_short, liq_total
|
|
67
|
-
FROM derivatives_market
|
|
68
|
-
WHERE symbol = ANY($1)
|
|
69
|
-
AND interval = $2
|
|
70
|
-
AND ts >= to_timestamp($3/1000.0)
|
|
71
|
-
AND ts <= to_timestamp($4/1000.0)
|
|
72
|
-
ORDER BY symbol ASC, ts ASC
|
|
73
|
-
`;
|
|
74
|
-
const res = await pool.query(sql, [symbols, interval, startMs, endMs]);
|
|
75
|
-
return res.rows;
|
|
76
|
-
}
|
|
77
|
-
async function getDerivativesDataEdgesForSymbols(symbols, interval) {
|
|
78
|
-
const normalizedSymbols = [
|
|
79
|
-
...new Set(
|
|
80
|
-
symbols.map(
|
|
81
|
-
(symbol) => String(symbol || "").trim().toUpperCase()
|
|
82
|
-
).filter(Boolean)
|
|
83
|
-
)
|
|
84
|
-
];
|
|
85
|
-
const edges = /* @__PURE__ */ new Map();
|
|
86
|
-
if (!normalizedSymbols.length) return edges;
|
|
87
|
-
await ensureDerivativesSchema();
|
|
88
|
-
const pool = getPool();
|
|
89
|
-
const sql = `
|
|
90
|
-
SELECT
|
|
91
|
-
symbol,
|
|
92
|
-
extract(epoch from MIN(ts))*1000 AS min,
|
|
93
|
-
extract(epoch from MAX(ts))*1000 AS max
|
|
94
|
-
FROM derivatives_market
|
|
95
|
-
WHERE symbol = ANY($1)
|
|
96
|
-
AND interval = $2
|
|
97
|
-
GROUP BY symbol
|
|
98
|
-
`;
|
|
99
|
-
const res = await pool.query(sql, [normalizedSymbols, interval]);
|
|
100
|
-
for (const row of res.rows) {
|
|
101
|
-
const min = Number(row.min);
|
|
102
|
-
const max = Number(row.max);
|
|
103
|
-
edges.set(String(row.symbol).toUpperCase(), {
|
|
104
|
-
min: Number.isFinite(min) ? min : void 0,
|
|
105
|
-
max: Number.isFinite(max) ? max : void 0
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return edges;
|
|
109
|
-
}
|
|
110
|
-
async function getDerivativesBackfillCoverage(params) {
|
|
111
|
-
const normalizedSource = String(params.source || "").trim().toLowerCase();
|
|
112
|
-
const normalizedSymbols = [
|
|
113
|
-
...new Set(
|
|
114
|
-
params.symbols.map(
|
|
115
|
-
(symbol) => String(symbol || "").trim().toUpperCase()
|
|
116
|
-
).filter(Boolean)
|
|
117
|
-
)
|
|
118
|
-
];
|
|
119
|
-
if (!normalizedSource || !normalizedSymbols.length) {
|
|
120
|
-
return [];
|
|
121
|
-
}
|
|
122
|
-
await ensureDerivativesSchema();
|
|
123
|
-
const pool = getPool();
|
|
124
|
-
const res = await pool.query(
|
|
125
|
-
`
|
|
126
|
-
SELECT
|
|
127
|
-
symbol,
|
|
128
|
-
interval,
|
|
129
|
-
extract(epoch from from_ts)*1000 AS from_ms,
|
|
130
|
-
extract(epoch from to_ts)*1000 AS to_ms,
|
|
131
|
-
rows_count
|
|
132
|
-
FROM derivatives_backfill_coverage
|
|
133
|
-
WHERE source = $1
|
|
134
|
-
AND symbol = ANY($2)
|
|
135
|
-
AND interval = $3
|
|
136
|
-
AND from_ts <= to_timestamp($5/1000.0)
|
|
137
|
-
AND to_ts >= to_timestamp($4/1000.0)
|
|
138
|
-
`,
|
|
139
|
-
[
|
|
140
|
-
normalizedSource,
|
|
141
|
-
normalizedSymbols,
|
|
142
|
-
params.interval,
|
|
143
|
-
params.fromMs,
|
|
144
|
-
params.toMs
|
|
145
|
-
]
|
|
146
|
-
);
|
|
147
|
-
return res.rows.map((row) => ({
|
|
148
|
-
symbol: String(row.symbol).toUpperCase(),
|
|
149
|
-
interval: row.interval,
|
|
150
|
-
fromMs: Number(row.from_ms),
|
|
151
|
-
toMs: Number(row.to_ms),
|
|
152
|
-
rowsCount: Number(row.rows_count ?? 0)
|
|
153
|
-
}));
|
|
154
|
-
}
|
|
155
|
-
async function upsertDerivativesBackfillCoverage(rows) {
|
|
156
|
-
if (!rows.length) return;
|
|
157
|
-
await ensureDerivativesSchema();
|
|
158
|
-
const pool = getPool();
|
|
159
|
-
const cols = [
|
|
160
|
-
"source",
|
|
161
|
-
"symbol",
|
|
162
|
-
"interval",
|
|
163
|
-
"from_ts",
|
|
164
|
-
"to_ts",
|
|
165
|
-
"rows_count"
|
|
166
|
-
];
|
|
167
|
-
const valuesSql = rows.map(
|
|
168
|
-
(_, i) => `(${cols.map((__, j) => `$${i * cols.length + j + 1}`).join(",")})`
|
|
169
|
-
).join(",");
|
|
170
|
-
const flat = rows.flatMap((row) => [
|
|
171
|
-
String(row.source || "").trim().toLowerCase(),
|
|
172
|
-
String(row.symbol || "").trim().toUpperCase(),
|
|
173
|
-
row.interval,
|
|
174
|
-
new Date(row.fromMs),
|
|
175
|
-
new Date(row.toMs),
|
|
176
|
-
Math.max(0, Math.trunc(row.rowsCount))
|
|
177
|
-
]);
|
|
178
|
-
await pool.query(
|
|
179
|
-
`
|
|
180
|
-
INSERT INTO derivatives_backfill_coverage (${cols.join(",")})
|
|
181
|
-
VALUES ${valuesSql}
|
|
182
|
-
ON CONFLICT (source, symbol, interval, from_ts, to_ts) DO UPDATE SET
|
|
183
|
-
rows_count = EXCLUDED.rows_count,
|
|
184
|
-
checked_at = now()
|
|
185
|
-
`,
|
|
186
|
-
flat
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
async function getDerivativesMetricCoverage(params) {
|
|
190
|
-
const normalizedSource = String(params.source || "").trim().toLowerCase();
|
|
191
|
-
const normalizedSymbols = [
|
|
192
|
-
...new Set(
|
|
193
|
-
params.symbols.map(
|
|
194
|
-
(symbol) => String(symbol || "").trim().toUpperCase()
|
|
195
|
-
).filter(Boolean)
|
|
196
|
-
)
|
|
197
|
-
];
|
|
198
|
-
if (!normalizedSource || !normalizedSymbols.length) {
|
|
199
|
-
return [];
|
|
200
|
-
}
|
|
201
|
-
await ensureDerivativesSchema();
|
|
202
|
-
const pool = getPool();
|
|
203
|
-
const res = await pool.query(
|
|
204
|
-
`
|
|
205
|
-
SELECT
|
|
206
|
-
symbol,
|
|
207
|
-
interval,
|
|
208
|
-
extract(epoch from from_ts)*1000 AS from_ms,
|
|
209
|
-
extract(epoch from to_ts)*1000 AS to_ms,
|
|
210
|
-
event_rows_count,
|
|
211
|
-
zero_rows_count
|
|
212
|
-
FROM derivatives_metric_coverage
|
|
213
|
-
WHERE source = $1
|
|
214
|
-
AND metric = $2
|
|
215
|
-
AND symbol = ANY($3)
|
|
216
|
-
AND interval = $4
|
|
217
|
-
AND from_ts <= to_timestamp($6/1000.0)
|
|
218
|
-
AND to_ts >= to_timestamp($5/1000.0)
|
|
219
|
-
`,
|
|
220
|
-
[
|
|
221
|
-
normalizedSource,
|
|
222
|
-
params.metric,
|
|
223
|
-
normalizedSymbols,
|
|
224
|
-
params.interval,
|
|
225
|
-
params.fromMs,
|
|
226
|
-
params.toMs
|
|
227
|
-
]
|
|
228
|
-
);
|
|
229
|
-
return res.rows.map((row) => ({
|
|
230
|
-
symbol: String(row.symbol).toUpperCase(),
|
|
231
|
-
interval: row.interval,
|
|
232
|
-
fromMs: Number(row.from_ms),
|
|
233
|
-
toMs: Number(row.to_ms),
|
|
234
|
-
eventRowsCount: Number(row.event_rows_count ?? 0),
|
|
235
|
-
zeroRowsCount: Number(row.zero_rows_count ?? 0)
|
|
236
|
-
}));
|
|
237
|
-
}
|
|
238
|
-
async function applyDerivativesMetricCoverage(rows) {
|
|
239
|
-
if (!rows.length)
|
|
240
|
-
return [];
|
|
241
|
-
await ensureDerivativesSchema();
|
|
242
|
-
const pool = getPool();
|
|
243
|
-
const client = await pool.connect();
|
|
244
|
-
const results = [];
|
|
245
|
-
try {
|
|
246
|
-
await client.query("BEGIN");
|
|
247
|
-
for (const row of rows) {
|
|
248
|
-
const source = String(row.source || "").trim().toLowerCase();
|
|
249
|
-
const symbol = String(row.symbol || "").trim().toUpperCase();
|
|
250
|
-
const fromMs = Math.trunc(row.fromMs);
|
|
251
|
-
const toMs = Math.trunc(row.toMs);
|
|
252
|
-
if (!source || !symbol || fromMs > toMs) continue;
|
|
253
|
-
await client.query(
|
|
254
|
-
`
|
|
255
|
-
UPDATE derivatives_market
|
|
256
|
-
SET
|
|
257
|
-
liq_long = 0,
|
|
258
|
-
liq_short = 0,
|
|
259
|
-
liq_total = 0,
|
|
260
|
-
ingested_at = now()
|
|
261
|
-
WHERE symbol = $1
|
|
262
|
-
AND interval = $2
|
|
263
|
-
AND ts >= to_timestamp($3/1000.0)
|
|
264
|
-
AND ts <= to_timestamp($4/1000.0)
|
|
265
|
-
AND liq_long IS NULL
|
|
266
|
-
AND liq_short IS NULL
|
|
267
|
-
AND liq_total IS NULL
|
|
268
|
-
`,
|
|
269
|
-
[symbol, row.interval, fromMs, toMs]
|
|
270
|
-
);
|
|
271
|
-
const zeroCountResult = await client.query(
|
|
272
|
-
`
|
|
273
|
-
SELECT COUNT(*)::integer AS count
|
|
274
|
-
FROM derivatives_market
|
|
275
|
-
WHERE symbol = $1
|
|
276
|
-
AND interval = $2
|
|
277
|
-
AND ts >= to_timestamp($3/1000.0)
|
|
278
|
-
AND ts <= to_timestamp($4/1000.0)
|
|
279
|
-
AND liq_long = 0
|
|
280
|
-
AND liq_short = 0
|
|
281
|
-
AND liq_total = 0
|
|
282
|
-
`,
|
|
283
|
-
[symbol, row.interval, fromMs, toMs]
|
|
284
|
-
);
|
|
285
|
-
const zeroRowsCount = Math.max(
|
|
286
|
-
0,
|
|
287
|
-
Number(zeroCountResult.rows[0]?.count ?? 0)
|
|
288
|
-
);
|
|
289
|
-
await client.query(
|
|
290
|
-
`
|
|
291
|
-
INSERT INTO derivatives_metric_coverage (
|
|
292
|
-
source,
|
|
293
|
-
metric,
|
|
294
|
-
symbol,
|
|
295
|
-
interval,
|
|
296
|
-
from_ts,
|
|
297
|
-
to_ts,
|
|
298
|
-
event_rows_count,
|
|
299
|
-
zero_rows_count
|
|
300
|
-
)
|
|
301
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
302
|
-
ON CONFLICT (source, metric, symbol, interval, from_ts, to_ts)
|
|
303
|
-
DO UPDATE SET
|
|
304
|
-
event_rows_count = EXCLUDED.event_rows_count,
|
|
305
|
-
zero_rows_count = EXCLUDED.zero_rows_count,
|
|
306
|
-
checked_at = now()
|
|
307
|
-
`,
|
|
308
|
-
[
|
|
309
|
-
source,
|
|
310
|
-
row.metric,
|
|
311
|
-
symbol,
|
|
312
|
-
row.interval,
|
|
313
|
-
new Date(fromMs),
|
|
314
|
-
new Date(toMs),
|
|
315
|
-
Math.max(0, Math.trunc(row.eventRowsCount)),
|
|
316
|
-
zeroRowsCount
|
|
317
|
-
]
|
|
318
|
-
);
|
|
319
|
-
results.push({ symbol, zeroRowsCount });
|
|
320
|
-
}
|
|
321
|
-
await client.query("COMMIT");
|
|
322
|
-
return results;
|
|
323
|
-
} catch (error) {
|
|
324
|
-
await client.query("ROLLBACK");
|
|
325
|
-
throw error;
|
|
326
|
-
} finally {
|
|
327
|
-
client.release();
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
async function getDerivativesWindow(params) {
|
|
331
|
-
const { symbol, intervals, endMs, lookbackMs } = params;
|
|
332
|
-
const normalizedSymbol = String(symbol || "").trim().toUpperCase();
|
|
333
|
-
const normalizedIntervals = [...new Set(intervals)].filter(Boolean);
|
|
334
|
-
if (!normalizedSymbol || !normalizedIntervals.length) {
|
|
335
|
-
return {};
|
|
336
|
-
}
|
|
337
|
-
await prepareMarketContextSchemaForRead("derivatives");
|
|
338
|
-
const startMs = endMs - Math.max(0, lookbackMs);
|
|
339
|
-
const sql = `
|
|
340
|
-
SELECT symbol, interval, ts, open_interest, funding_rate, liq_long, liq_short, liq_total, source
|
|
341
|
-
FROM derivatives_market
|
|
342
|
-
WHERE symbol = $1
|
|
343
|
-
AND interval = ANY($2)
|
|
344
|
-
AND ts >= to_timestamp($3/1000.0)
|
|
345
|
-
AND ts <= to_timestamp($4/1000.0)
|
|
346
|
-
ORDER BY interval ASC, ts ASC
|
|
347
|
-
`;
|
|
348
|
-
const res = await queryMarketContext(
|
|
349
|
-
sql,
|
|
350
|
-
[normalizedSymbol, normalizedIntervals, startMs, endMs],
|
|
351
|
-
params
|
|
352
|
-
);
|
|
353
|
-
const rowsByInterval = {};
|
|
354
|
-
for (const row of res.rows) {
|
|
355
|
-
const interval = row.interval;
|
|
356
|
-
rowsByInterval[interval] ??= [];
|
|
357
|
-
rowsByInterval[interval]?.push({
|
|
358
|
-
symbol: row.symbol,
|
|
359
|
-
interval,
|
|
360
|
-
ts: row.ts,
|
|
361
|
-
openInterest: row.open_interest,
|
|
362
|
-
fundingRate: row.funding_rate,
|
|
363
|
-
liqLong: row.liq_long,
|
|
364
|
-
liqShort: row.liq_short,
|
|
365
|
-
liqTotal: row.liq_total,
|
|
366
|
-
source: row.source
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
return rowsByInterval;
|
|
370
|
-
}
|
|
371
|
-
async function getDerivativesSummary(hours = 24, limit = 500, symbols) {
|
|
372
|
-
await ensureDerivativesSchema();
|
|
373
|
-
const pool = getPool();
|
|
374
|
-
const cappedHours = Math.max(1, Math.min(24 * 90, hours));
|
|
375
|
-
const cappedLimit = Math.max(10, Math.min(1e3, limit));
|
|
376
|
-
const normalizedSymbols = Array.isArray(symbols) ? [...new Set(symbols.map(normalizeCandleSymbol).filter(Boolean))] : [];
|
|
377
|
-
const symbolsFilterSql = normalizedSymbols.length ? "AND symbol = ANY($3)" : "";
|
|
378
|
-
const summaryQ = await pool.query(
|
|
379
|
-
`
|
|
380
|
-
WITH filtered AS (
|
|
381
|
-
SELECT
|
|
382
|
-
symbol,
|
|
383
|
-
interval,
|
|
384
|
-
ts,
|
|
385
|
-
open_interest,
|
|
386
|
-
funding_rate,
|
|
387
|
-
liq_long,
|
|
388
|
-
liq_short,
|
|
389
|
-
liq_total
|
|
390
|
-
FROM derivatives_market
|
|
391
|
-
WHERE ts >= now() - ($1 || ' hours')::interval
|
|
392
|
-
${symbolsFilterSql}
|
|
393
|
-
),
|
|
394
|
-
latest AS (
|
|
395
|
-
SELECT DISTINCT ON (symbol, interval)
|
|
396
|
-
symbol,
|
|
397
|
-
interval,
|
|
398
|
-
ts AS last_ts,
|
|
399
|
-
open_interest AS latest_open_interest,
|
|
400
|
-
funding_rate AS latest_funding_rate
|
|
401
|
-
FROM filtered
|
|
402
|
-
ORDER BY symbol ASC, interval ASC, ts DESC
|
|
403
|
-
),
|
|
404
|
-
first AS (
|
|
405
|
-
SELECT DISTINCT ON (symbol, interval)
|
|
406
|
-
symbol,
|
|
407
|
-
interval,
|
|
408
|
-
ts AS first_ts,
|
|
409
|
-
open_interest AS first_open_interest,
|
|
410
|
-
funding_rate AS first_funding_rate
|
|
411
|
-
FROM filtered
|
|
412
|
-
ORDER BY symbol ASC, interval ASC, ts ASC
|
|
413
|
-
),
|
|
414
|
-
aggregated AS (
|
|
415
|
-
SELECT
|
|
416
|
-
symbol,
|
|
417
|
-
interval,
|
|
418
|
-
COUNT(*)::int AS points,
|
|
419
|
-
SUM(COALESCE(liq_long, 0)) AS sum_liq_long,
|
|
420
|
-
SUM(COALESCE(liq_short, 0)) AS sum_liq_short,
|
|
421
|
-
SUM(COALESCE(liq_total, 0)) AS sum_liq_total
|
|
422
|
-
FROM filtered
|
|
423
|
-
GROUP BY symbol, interval
|
|
424
|
-
)
|
|
425
|
-
SELECT
|
|
426
|
-
aggregated.symbol,
|
|
427
|
-
aggregated.interval,
|
|
428
|
-
aggregated.points,
|
|
429
|
-
latest.last_ts,
|
|
430
|
-
first.first_ts,
|
|
431
|
-
latest.latest_open_interest,
|
|
432
|
-
first.first_open_interest,
|
|
433
|
-
latest.latest_funding_rate,
|
|
434
|
-
first.first_funding_rate,
|
|
435
|
-
aggregated.sum_liq_long,
|
|
436
|
-
aggregated.sum_liq_short,
|
|
437
|
-
aggregated.sum_liq_total
|
|
438
|
-
FROM aggregated
|
|
439
|
-
JOIN latest
|
|
440
|
-
ON latest.symbol = aggregated.symbol
|
|
441
|
-
AND latest.interval = aggregated.interval
|
|
442
|
-
JOIN first
|
|
443
|
-
ON first.symbol = aggregated.symbol
|
|
444
|
-
AND first.interval = aggregated.interval
|
|
445
|
-
ORDER BY aggregated.sum_liq_total DESC, aggregated.symbol ASC
|
|
446
|
-
LIMIT $2
|
|
447
|
-
`,
|
|
448
|
-
normalizedSymbols.length ? [String(cappedHours), cappedLimit, normalizedSymbols] : [String(cappedHours), cappedLimit]
|
|
449
|
-
);
|
|
450
|
-
const items = summaryQ.rows.map((row) => {
|
|
451
|
-
const latestOpenInterest = row.latest_open_interest == null ? null : Number(row.latest_open_interest);
|
|
452
|
-
const firstOpenInterest = row.first_open_interest == null ? null : Number(row.first_open_interest);
|
|
453
|
-
const latestFundingRate = row.latest_funding_rate == null ? null : Number(row.latest_funding_rate);
|
|
454
|
-
const firstFundingRate = row.first_funding_rate == null ? null : Number(row.first_funding_rate);
|
|
455
|
-
const oiChange = latestOpenInterest != null && firstOpenInterest != null ? latestOpenInterest - firstOpenInterest : null;
|
|
456
|
-
const oiChangePct = oiChange != null && firstOpenInterest != null && Number.isFinite(firstOpenInterest) && Math.abs(firstOpenInterest) > 0 ? oiChange / Math.abs(firstOpenInterest) * 100 : null;
|
|
457
|
-
const fundingChange = latestFundingRate != null && firstFundingRate != null ? latestFundingRate - firstFundingRate : null;
|
|
458
|
-
return {
|
|
459
|
-
symbol: row.symbol,
|
|
460
|
-
interval: row.interval,
|
|
461
|
-
points: Number(row.points || 0),
|
|
462
|
-
last_ts: row.last_ts,
|
|
463
|
-
first_ts: row.first_ts,
|
|
464
|
-
latest_open_interest: latestOpenInterest,
|
|
465
|
-
first_open_interest: firstOpenInterest,
|
|
466
|
-
oi_change: oiChange,
|
|
467
|
-
oi_change_pct: oiChangePct,
|
|
468
|
-
latest_funding_rate: latestFundingRate,
|
|
469
|
-
first_funding_rate: firstFundingRate,
|
|
470
|
-
funding_change: fundingChange,
|
|
471
|
-
sum_liq_long: row.sum_liq_long == null ? null : Number(row.sum_liq_long),
|
|
472
|
-
sum_liq_short: row.sum_liq_short == null ? null : Number(row.sum_liq_short),
|
|
473
|
-
sum_liq_total: row.sum_liq_total == null ? null : Number(row.sum_liq_total)
|
|
474
|
-
};
|
|
475
|
-
});
|
|
476
|
-
return {
|
|
477
|
-
hours: cappedHours,
|
|
478
|
-
items
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
export {
|
|
483
|
-
upsertDerivatives,
|
|
484
|
-
getDerivativesRangeForSymbols,
|
|
485
|
-
getDerivativesDataEdgesForSymbols,
|
|
486
|
-
getDerivativesBackfillCoverage,
|
|
487
|
-
upsertDerivativesBackfillCoverage,
|
|
488
|
-
getDerivativesMetricCoverage,
|
|
489
|
-
applyDerivativesMetricCoverage,
|
|
490
|
-
getDerivativesWindow,
|
|
491
|
-
getDerivativesSummary
|
|
492
|
-
};
|
package/dist/chunk-XQ3YBULV.mjs
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// src/aiEndpoints.ts
|
|
2
|
-
var AI_CUSTOM_ENDPOINT_VALUE = "__custom__";
|
|
3
|
-
var AI_ENDPOINT_OPTIONS = [
|
|
4
|
-
{
|
|
5
|
-
label: "OpenAI",
|
|
6
|
-
value: "https://api.openai.com/v1"
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
label: "Claude",
|
|
10
|
-
value: "https://api.anthropic.com/v1"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
label: "OpenRouter",
|
|
14
|
-
value: "https://openrouter.ai/api/v1"
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
label: "Gemini",
|
|
18
|
-
value: "https://generativelanguage.googleapis.com/v1beta/openai"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
label: "Together AI",
|
|
22
|
-
value: "https://api.together.xyz/v1"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
label: "Groq",
|
|
26
|
-
value: "https://api.groq.com/openai/v1"
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
label: "DeepInfra",
|
|
30
|
-
value: "https://api.deepinfra.com/v1/openai"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
label: "xAI",
|
|
34
|
-
value: "https://api.x.ai/v1"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
label: "Qwen (DashScope Intl)",
|
|
38
|
-
value: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
label: "Qwen (DashScope CN)",
|
|
42
|
-
value: "https://dashscope.aliyuncs.com/compatible-mode/v1"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
label: "Qwen (DashScope US)",
|
|
46
|
-
value: "https://dashscope-us.aliyuncs.com/compatible-mode/v1"
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
label: "Perplexity",
|
|
50
|
-
value: "https://api.perplexity.ai"
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
label: "Fireworks",
|
|
54
|
-
value: "https://api.fireworks.ai/inference/v1"
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
label: "SambaNova",
|
|
58
|
-
value: "https://api.sambanova.ai/v1"
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
label: "Hyperbolic",
|
|
62
|
-
value: "https://api.hyperbolic.xyz/v1"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
label: "Kimi",
|
|
66
|
-
value: "https://api.moonshot.ai/v1"
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
label: "ProxyAPI",
|
|
70
|
-
value: "https://openai.api.proxyapi.ru/v1"
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
label: "Custom",
|
|
74
|
-
value: AI_CUSTOM_ENDPOINT_VALUE
|
|
75
|
-
}
|
|
76
|
-
];
|
|
77
|
-
var KNOWN_AI_ENDPOINTS = new Set(
|
|
78
|
-
AI_ENDPOINT_OPTIONS.map((option) => option.value).filter(
|
|
79
|
-
(value) => value !== AI_CUSTOM_ENDPOINT_VALUE
|
|
80
|
-
)
|
|
81
|
-
);
|
|
82
|
-
var normalizeUrl = (value) => value.replace(/\/+$/, "");
|
|
83
|
-
var isIpv4Address = (value) => /^(?:\d{1,3}\.){3}\d{1,3}$/.test(value.trim());
|
|
84
|
-
var parseIpv4Address = (value) => value.trim().split(".").map((part) => Number(part));
|
|
85
|
-
var isPrivateIpv4Address = (value) => {
|
|
86
|
-
if (!isIpv4Address(value)) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
const [a, b, c, d] = parseIpv4Address(value);
|
|
90
|
-
if ([a, b, c, d].some(
|
|
91
|
-
(part) => !Number.isInteger(part) || part < 0 || part > 255
|
|
92
|
-
)) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
return a === 10 || a === 127 || a === 0 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168;
|
|
96
|
-
};
|
|
97
|
-
var isPrivateHostname = (hostname) => {
|
|
98
|
-
const normalized = hostname.trim().toLowerCase();
|
|
99
|
-
if (!normalized) {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
return normalized === "localhost" || normalized.endsWith(".localhost") || normalized.endsWith(".local") || normalized.endsWith(".internal") || normalized.endsWith(".lan") || normalized === "::1" || normalized === "[::1]" || isPrivateIpv4Address(normalized);
|
|
103
|
-
};
|
|
104
|
-
var isValidAiEndpointUrl = (value) => {
|
|
105
|
-
try {
|
|
106
|
-
const url = new URL(value);
|
|
107
|
-
return url.protocol === "https:" && !isPrivateHostname(url.hostname);
|
|
108
|
-
} catch {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
var normalizeAiEndpoint = (value) => {
|
|
113
|
-
if (typeof value !== "string") {
|
|
114
|
-
return "";
|
|
115
|
-
}
|
|
116
|
-
const trimmed = normalizeUrl(value.trim());
|
|
117
|
-
if (!trimmed) {
|
|
118
|
-
return "";
|
|
119
|
-
}
|
|
120
|
-
if (KNOWN_AI_ENDPOINTS.has(trimmed)) {
|
|
121
|
-
return trimmed;
|
|
122
|
-
}
|
|
123
|
-
return isValidAiEndpointUrl(trimmed) ? trimmed : "";
|
|
124
|
-
};
|
|
125
|
-
var isKnownAiEndpoint = (value) => KNOWN_AI_ENDPOINTS.has(normalizeAiEndpoint(value));
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
AI_CUSTOM_ENDPOINT_VALUE,
|
|
129
|
-
AI_ENDPOINT_OPTIONS,
|
|
130
|
-
normalizeAiEndpoint,
|
|
131
|
-
isKnownAiEndpoint
|
|
132
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
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 };
|
|
@@ -1,26 +0,0 @@
|
|
|
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/timescale.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { T as TimescaleMarketContextQueryOptions, a as TimescaleMarketContextSource, c as closeTimescalePool, b as configureTimescaleMarketContextSchemaMode, e as ensureBinanceMarketSchema, d as ensureCoinMarketCapContextSchema, f as ensureDerivativesSchema, g as ensureHyperliquidWhaleSchema, h as ensureMarketContextSchemas } from './internal-2coHaaos.mjs';
|
|
2
|
-
export { CandleRow, deleteCandles, findContinuityGap, getCandlesRange, getDataEdges, getDataEdgesForSymbols, toRows, upsertCandles, waitForDbReady } from './timescale/candles.mjs';
|
|
3
|
-
export { DerivativesMetricCoverageMetric, applyDerivativesMetricCoverage, getDerivativesBackfillCoverage, getDerivativesDataEdgesForSymbols, getDerivativesMetricCoverage, getDerivativesRangeForSymbols, getDerivativesSummary, getDerivativesWindow, upsertDerivatives, upsertDerivativesBackfillCoverage } from './timescale/derivatives.mjs';
|
|
4
|
-
export { getSpreadRangeForSymbols, getSpreadSummary, upsertSpreadRows } from './timescale/spread.mjs';
|
|
5
|
-
export { DeprecatedMarketContextCleanupItem, cleanupDeprecatedMarketContext, getLatestMarketBreadth, getLatestMarketCmcExchangeLiquidityContext, getLatestMarketCmcFearGreedContext, getLatestMarketCmcIndexContexts, getLatestMarketGlobalContext, getLatestMarketReferenceAssetContexts, getLatestMarketTradeFlow, getMarketBreadthCoverage, getMarketCmcExchangeLiquidityContextCoverage, getMarketCmcFearGreedContextCoverage, getMarketCmcIndexContextCoverage, getMarketContextBackfillCoverage, getMarketGlobalContextCoverage, getMarketReferenceAssetContextCoverage, getMarketTradeFlowCoverage, upsertMarketBreadthRows, upsertMarketCmcExchangeLiquidityContextRows, upsertMarketCmcFearGreedContextRows, upsertMarketCmcIndexContextRows, upsertMarketContextBackfillCoverage, upsertMarketGlobalContextRows, upsertMarketReferenceAssetContextRows, upsertMarketTradeFlowRows } from './timescale/marketContext.mjs';
|
|
6
|
-
export { HyperliquidWhaleCoverageRebuildProgress, HyperliquidWhaleCoverageSeriesRow, HyperliquidWhaleFlowAggregate, HyperliquidWhaleFlowSeriesRow, HyperliquidWhaleWalletCoverageStatus, getHyperliquidWhaleCoverageSeriesRows, getHyperliquidWhaleFlowAggregate, getHyperliquidWhaleFlowSeriesRows, getHyperliquidWhaleWalletCoverage, hasHyperliquidWhaleBackfillCoverage, rebuildHyperliquidWhaleCoverageRows, rebuildHyperliquidWhaleFlowRows, upsertHyperliquidWhaleCoverageRows, upsertHyperliquidWhaleFlowRows, upsertHyperliquidWhaleTradeEvents, upsertHyperliquidWhaleWalletCoverage } from './timescale/hyperliquidWhales.mjs';
|
|
7
|
-
export { M as MarketFeatureAsOf } from './values-BrvcmnfM.mjs';
|
|
8
|
-
import 'pg';
|
|
9
|
-
import '@tradejs/types';
|