@tradejs/infra 2.0.18 → 2.0.19

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.
Files changed (53) hide show
  1. package/dist/ai.js +3 -54
  2. package/dist/ai.mjs +1 -54
  3. package/dist/chunk-2CZREG43.mjs +112 -0
  4. package/dist/chunk-DFMKDB2R.mjs +1285 -0
  5. package/dist/chunk-I2J6YDBD.mjs +910 -0
  6. package/dist/chunk-NWXFWTWU.mjs +1114 -0
  7. package/dist/chunk-SZQB7ER5.mjs +492 -0
  8. package/dist/chunk-YVIHTUV5.mjs +286 -0
  9. package/dist/internal-2coHaaos.d.mts +26 -0
  10. package/dist/internal-2coHaaos.d.ts +26 -0
  11. package/dist/runtimeDeployments.d.mts +10 -0
  12. package/dist/runtimeDeployments.d.ts +10 -0
  13. package/dist/runtimeDeployments.js +447 -0
  14. package/dist/runtimeDeployments.mjs +81 -0
  15. package/dist/runtimeStrategyConfigs.d.mts +28 -0
  16. package/dist/runtimeStrategyConfigs.d.ts +28 -0
  17. package/dist/runtimeStrategyConfigs.js +425 -0
  18. package/dist/runtimeStrategyConfigs.mjs +89 -0
  19. package/dist/timescale/candles.d.mts +38 -0
  20. package/dist/timescale/candles.d.ts +38 -0
  21. package/dist/timescale/candles.js +408 -0
  22. package/dist/timescale/candles.mjs +21 -0
  23. package/dist/timescale/client.d.mts +4 -0
  24. package/dist/timescale/client.d.ts +4 -0
  25. package/dist/timescale/client.js +109 -0
  26. package/dist/timescale/client.mjs +12 -0
  27. package/dist/timescale/derivatives.d.mts +90 -0
  28. package/dist/timescale/derivatives.d.ts +90 -0
  29. package/dist/timescale/derivatives.js +1270 -0
  30. package/dist/timescale/derivatives.mjs +26 -0
  31. package/dist/timescale/hyperliquidWhales.d.mts +149 -0
  32. package/dist/timescale/hyperliquidWhales.d.ts +149 -0
  33. package/dist/timescale/hyperliquidWhales.js +1893 -0
  34. package/dist/timescale/hyperliquidWhales.mjs +30 -0
  35. package/dist/timescale/marketContext.d.mts +188 -0
  36. package/dist/timescale/marketContext.d.ts +188 -0
  37. package/dist/timescale/marketContext.js +2091 -0
  38. package/dist/timescale/marketContext.mjs +60 -0
  39. package/dist/timescale/spread.d.mts +11 -0
  40. package/dist/timescale/spread.d.ts +11 -0
  41. package/dist/timescale/spread.js +215 -0
  42. package/dist/timescale/spread.mjs +11 -0
  43. package/dist/timescale.d.mts +9 -476
  44. package/dist/timescale.d.ts +9 -476
  45. package/dist/timescale.js +2121 -2112
  46. package/dist/timescale.mjs +73 -4070
  47. package/dist/tradingAccounts.d.mts +2 -8
  48. package/dist/tradingAccounts.d.ts +2 -8
  49. package/dist/tradingAccounts.js +0 -71
  50. package/dist/tradingAccounts.mjs +0 -65
  51. package/dist/values-BrvcmnfM.d.mts +6 -0
  52. package/dist/values-BrvcmnfM.d.ts +6 -0
  53. package/package.json +43 -2
package/dist/ai.js CHANGED
@@ -55,58 +55,7 @@ var import_promises2 = __toESM(require("fs/promises"));
55
55
  var import_path2 = __toESM(require("path"));
56
56
  var import_node_fs = require("fs");
57
57
  var import_node_readline2 = __toESM(require("readline"));
58
-
59
- // ../../node_modules/date-fns/toDate.mjs
60
- function toDate(argument) {
61
- const argStr = Object.prototype.toString.call(argument);
62
- if (argument instanceof Date || typeof argument === "object" && argStr === "[object Date]") {
63
- return new argument.constructor(+argument);
64
- } else if (typeof argument === "number" || argStr === "[object Number]" || typeof argument === "string" || argStr === "[object String]") {
65
- return new Date(argument);
66
- } else {
67
- return /* @__PURE__ */ new Date(NaN);
68
- }
69
- }
70
-
71
- // ../../node_modules/date-fns/constructFrom.mjs
72
- function constructFrom(date, value) {
73
- if (date instanceof Date) {
74
- return new date.constructor(value);
75
- } else {
76
- return new Date(value);
77
- }
78
- }
79
-
80
- // ../../node_modules/date-fns/addMonths.mjs
81
- function addMonths(date, amount) {
82
- const _date = toDate(date);
83
- if (isNaN(amount)) return constructFrom(date, NaN);
84
- if (!amount) {
85
- return _date;
86
- }
87
- const dayOfMonth = _date.getDate();
88
- const endOfDesiredMonth = constructFrom(date, _date.getTime());
89
- endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
90
- const daysInMonth = endOfDesiredMonth.getDate();
91
- if (dayOfMonth >= daysInMonth) {
92
- return endOfDesiredMonth;
93
- } else {
94
- _date.setFullYear(
95
- endOfDesiredMonth.getFullYear(),
96
- endOfDesiredMonth.getMonth(),
97
- dayOfMonth
98
- );
99
- return _date;
100
- }
101
- }
102
-
103
- // ../../node_modules/date-fns/startOfMonth.mjs
104
- function startOfMonth(date) {
105
- const _date = toDate(date);
106
- _date.setDate(1);
107
- _date.setHours(0, 0, 0, 0);
108
- return _date;
109
- }
58
+ var import_date_fns = require("date-fns");
110
59
 
111
60
  // src/mlDatasetFile.ts
112
61
  var import_events = require("events");
@@ -570,8 +519,8 @@ var getAiDatasetPartPath = (filePath, partIndex) => {
570
519
  return import_path2.default.join(parsed.dir, `${parsed.name}-part${partIndex}${parsed.ext}`);
571
520
  };
572
521
  var getPartWindowEndExclusive = (timestamp, monthsPerPart) => {
573
- const partStart = startOfMonth(new Date(timestamp));
574
- return addMonths(partStart, Math.max(1, monthsPerPart)).getTime();
522
+ const partStart = (0, import_date_fns.startOfMonth)(new Date(timestamp));
523
+ return (0, import_date_fns.addMonths)(partStart, Math.max(1, monthsPerPart)).getTime();
575
524
  };
576
525
  var splitAiMergedDatasetFile = async (params) => {
577
526
  const { filePath, monthsPerPart = 2 } = params;
package/dist/ai.mjs CHANGED
@@ -10,60 +10,7 @@ import fs from "fs/promises";
10
10
  import path from "path";
11
11
  import { createReadStream } from "fs";
12
12
  import readline from "readline";
13
-
14
- // ../../node_modules/date-fns/toDate.mjs
15
- function toDate(argument) {
16
- const argStr = Object.prototype.toString.call(argument);
17
- if (argument instanceof Date || typeof argument === "object" && argStr === "[object Date]") {
18
- return new argument.constructor(+argument);
19
- } else if (typeof argument === "number" || argStr === "[object Number]" || typeof argument === "string" || argStr === "[object String]") {
20
- return new Date(argument);
21
- } else {
22
- return /* @__PURE__ */ new Date(NaN);
23
- }
24
- }
25
-
26
- // ../../node_modules/date-fns/constructFrom.mjs
27
- function constructFrom(date, value) {
28
- if (date instanceof Date) {
29
- return new date.constructor(value);
30
- } else {
31
- return new Date(value);
32
- }
33
- }
34
-
35
- // ../../node_modules/date-fns/addMonths.mjs
36
- function addMonths(date, amount) {
37
- const _date = toDate(date);
38
- if (isNaN(amount)) return constructFrom(date, NaN);
39
- if (!amount) {
40
- return _date;
41
- }
42
- const dayOfMonth = _date.getDate();
43
- const endOfDesiredMonth = constructFrom(date, _date.getTime());
44
- endOfDesiredMonth.setMonth(_date.getMonth() + amount + 1, 0);
45
- const daysInMonth = endOfDesiredMonth.getDate();
46
- if (dayOfMonth >= daysInMonth) {
47
- return endOfDesiredMonth;
48
- } else {
49
- _date.setFullYear(
50
- endOfDesiredMonth.getFullYear(),
51
- endOfDesiredMonth.getMonth(),
52
- dayOfMonth
53
- );
54
- return _date;
55
- }
56
- }
57
-
58
- // ../../node_modules/date-fns/startOfMonth.mjs
59
- function startOfMonth(date) {
60
- const _date = toDate(date);
61
- _date.setDate(1);
62
- _date.setHours(0, 0, 0, 0);
63
- return _date;
64
- }
65
-
66
- // src/aiDatasetFile.ts
13
+ import { addMonths, startOfMonth } from "date-fns";
67
14
  var DEFAULT_DIR = "data/ai/export";
68
15
  var AI_DATASET_WRITE_BATCH_SIZE = 100;
69
16
  var AI_MERGE_SORT_RUN_MAX_ROWS = 2e3;
@@ -0,0 +1,112 @@
1
+ import {
2
+ ensureSpreadSchema,
3
+ getPool
4
+ } from "./chunk-I2J6YDBD.mjs";
5
+
6
+ // src/timescale/spread.ts
7
+ async function upsertSpreadRows(rows) {
8
+ if (!rows.length) return;
9
+ await ensureSpreadSchema();
10
+ const pool = getPool();
11
+ const cols = [
12
+ "symbol",
13
+ "interval",
14
+ "ts",
15
+ "binance_price",
16
+ "coinbase_price",
17
+ "spread",
18
+ "source"
19
+ ];
20
+ const maxRows = Math.floor(65535 / cols.length);
21
+ if (rows.length > maxRows) {
22
+ for (let i = 0; i < rows.length; i += maxRows) {
23
+ await upsertSpreadRows(rows.slice(i, i + maxRows));
24
+ }
25
+ return;
26
+ }
27
+ const valuesSql = rows.map(
28
+ (_, i) => `(${cols.map((__, j) => `$${i * cols.length + j + 1}`).join(",")})`
29
+ ).join(",");
30
+ const flat = rows.flatMap((row) => [
31
+ row.symbol,
32
+ row.interval,
33
+ row.ts,
34
+ row.binancePrice ?? null,
35
+ row.coinbasePrice ?? null,
36
+ row.spread ?? null,
37
+ row.source ?? null
38
+ ]);
39
+ const sql = `
40
+ INSERT INTO market_spread (${cols.join(",")})
41
+ VALUES ${valuesSql}
42
+ ON CONFLICT (symbol, interval, ts) DO UPDATE SET
43
+ binance_price = COALESCE(EXCLUDED.binance_price, market_spread.binance_price),
44
+ coinbase_price = COALESCE(EXCLUDED.coinbase_price, market_spread.coinbase_price),
45
+ spread = COALESCE(EXCLUDED.spread, market_spread.spread),
46
+ source = COALESCE(EXCLUDED.source, market_spread.source),
47
+ ingested_at = now()
48
+ `;
49
+ await pool.query(sql, flat);
50
+ }
51
+ async function getSpreadRangeForSymbols(symbols, interval, startMs, endMs) {
52
+ if (!symbols.length) {
53
+ return [];
54
+ }
55
+ await ensureSpreadSchema();
56
+ const pool = getPool();
57
+ const sql = `
58
+ SELECT symbol, interval, ts, binance_price, coinbase_price, spread
59
+ FROM market_spread
60
+ WHERE symbol = ANY($1)
61
+ AND interval = $2
62
+ AND ts >= to_timestamp($3/1000.0)
63
+ AND ts <= to_timestamp($4/1000.0)
64
+ ORDER BY symbol ASC, ts ASC
65
+ `;
66
+ const res = await pool.query(sql, [symbols, interval, startMs, endMs]);
67
+ return res.rows;
68
+ }
69
+ async function getSpreadSummary(hours = 24, limit = 500) {
70
+ await ensureSpreadSchema();
71
+ const pool = getPool();
72
+ const cappedHours = Math.max(1, Math.min(24 * 30, hours));
73
+ const cappedLimit = Math.max(50, Math.min(5e3, limit));
74
+ const rowsQ = await pool.query(
75
+ `
76
+ SELECT symbol, interval, ts, binance_price, coinbase_price, spread
77
+ FROM market_spread
78
+ WHERE ts >= now() - ($1 || ' hours')::interval
79
+ ORDER BY ts DESC
80
+ LIMIT $2
81
+ `,
82
+ [String(cappedHours), cappedLimit]
83
+ );
84
+ const aggQ = await pool.query(
85
+ `
86
+ SELECT
87
+ symbol,
88
+ interval,
89
+ COUNT(*)::int AS points,
90
+ MAX(ts) AS last_ts,
91
+ AVG(spread) AS avg_spread,
92
+ STDDEV_POP(spread) AS std_spread
93
+ FROM market_spread
94
+ WHERE ts >= now() - ($1 || ' hours')::interval
95
+ GROUP BY symbol, interval
96
+ ORDER BY points DESC, symbol ASC
97
+ LIMIT 500
98
+ `,
99
+ [String(cappedHours)]
100
+ );
101
+ return {
102
+ rows: rowsQ.rows,
103
+ aggregates: aggQ.rows,
104
+ hours: cappedHours
105
+ };
106
+ }
107
+
108
+ export {
109
+ upsertSpreadRows,
110
+ getSpreadRangeForSymbols,
111
+ getSpreadSummary
112
+ };