@tradejs/cli 1.0.9 → 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/cli.js +29497 -13537
- package/dist/lib/aiPocketSearch.js +1316 -0
- package/dist/lib/aiTrainCharts.js +711 -0
- package/dist/lib/aiTrainDataset.js +40 -0
- package/dist/lib/aiTrainEvaluationDump.js +76 -0
- package/dist/lib/aiTrainMetrics.js +148 -8
- package/dist/lib/aiTrainOptions.js +130 -0
- package/dist/lib/aiTrainQuarantine.js +199 -0
- package/dist/lib/aiTrainResearch.js +467 -0
- package/dist/lib/binanceMarketContextBackfill.js +841 -0
- package/dist/lib/binanceMarketData.js +392 -0
- package/dist/lib/coinMarketCapContextBackfill.js +1088 -0
- package/dist/lib/continuity.js +60 -0
- package/dist/lib/derivativesContextBackfill.js +490 -77
- package/dist/lib/executionCalibration.js +705 -0
- package/dist/lib/marketContextPrepare.js +4403 -0
- package/dist/lib/paritySummary.js +101 -0
- package/dist/lib/runBot.js +1 -0
- package/dist/lib/runEnvironment.js +2254 -0
- package/dist/lib/runFormatting.js +1657 -0
- package/dist/lib/runtimeDebugEvidence.js +526 -0
- package/dist/lib/runtimeModeConfig.js +53 -0
- package/dist/lib/runtimeParity.js +88 -11
- package/dist/lib/runtimeParityDetails.js +751 -0
- package/dist/lib/runtimeRedis.js +157 -0
- package/dist/lib/runtimeSignalsLoader.js +40 -6
- package/dist/lib/runtimeSignalsStorage.js +45 -22
- package/dist/lib/runtimeStrategyBacktest.js +134 -0
- package/dist/lib/runtimeTradeSync.js +263 -0
- package/dist/lib/telegramReports.js +9 -0
- package/dist/lib/tickerUniverseCache.js +116 -0
- package/dist/lib/timeWindow.js +3 -3
- package/dist/scripts/agentRun.js +14 -8
- package/dist/scripts/aiExport.js +1721 -7
- package/dist/scripts/aiExportSelect.js +16 -4
- package/dist/scripts/aiPocketSearch.js +4190 -0
- package/dist/scripts/aiTrain.js +1866 -87
- package/dist/scripts/backtest.js +4509 -818
- package/dist/scripts/binanceMarketIngest.js +565 -0
- package/dist/scripts/bot.js +16 -2
- package/dist/scripts/candlesMigrateProvider.js +32 -22
- package/dist/scripts/cleanDir.js +15 -2
- package/dist/scripts/cleanRedis.js +15 -2
- package/dist/scripts/cleanTests.js +38 -2
- package/dist/scripts/cleanupMarketContext.js +69 -0
- package/dist/scripts/continuity.js +148 -67
- package/dist/scripts/derivativesIngest.js +14 -4
- package/dist/scripts/derivativesIngestCoinalyzeAll.js +14 -4
- package/dist/scripts/doctor.js +14 -4
- package/dist/scripts/executionCalibration.js +792 -0
- package/dist/scripts/infraCommon.js +10 -0
- package/dist/scripts/infraDown.js +14 -4
- package/dist/scripts/infraInit.js +24 -4
- package/dist/scripts/infraUp.js +14 -4
- package/dist/scripts/marketWs.js +222 -0
- package/dist/scripts/migration.js +15 -2
- package/dist/scripts/mlExport.js +1698 -10
- package/dist/scripts/mlExportSelect.js +16 -4
- package/dist/scripts/mlInspect.js +13 -3
- package/dist/scripts/mlTrainLatestSelect.js +14 -4
- package/dist/scripts/replay.js +8824 -0
- package/dist/scripts/replayRunner.js +8827 -0
- package/dist/scripts/replayRuntimeEvidence.js +868 -0
- package/dist/scripts/researchAuto.js +286 -59
- package/dist/scripts/results.js +3 -3
- package/dist/scripts/runtimeEvidence.js +605 -0
- package/dist/scripts/runtimeParity.js +6362 -1043
- package/dist/scripts/serverHealth.js +588 -0
- package/dist/scripts/signals.js +5590 -511
- package/dist/scripts/signalsDaemon.js +6167 -0
- package/dist/scripts/signalsSummary.js +833 -248
- package/dist/scripts/test-ml.js +25 -3
- package/dist/scripts/test.js +26 -1
- package/dist/scripts/user-add.js +15 -2
- package/dist/workers/testerWorker.js +130 -21
- package/package.json +18 -12
|
@@ -67,6 +67,14 @@ var DEV_COMPOSE_TEMPLATE = `services:
|
|
|
67
67
|
POSTGRES_DB: \${PG_DB:-app}
|
|
68
68
|
ports:
|
|
69
69
|
- "5432:5432"
|
|
70
|
+
command:
|
|
71
|
+
- postgres
|
|
72
|
+
- -c
|
|
73
|
+
- max_wal_size=16GB
|
|
74
|
+
- -c
|
|
75
|
+
- min_wal_size=2GB
|
|
76
|
+
- -c
|
|
77
|
+
- checkpoint_completion_target=0.9
|
|
70
78
|
volumes:
|
|
71
79
|
- tradejs_pgdata:/var/lib/postgresql/data
|
|
72
80
|
healthcheck:
|
|
@@ -79,6 +87,8 @@ var DEV_COMPOSE_TEMPLATE = `services:
|
|
|
79
87
|
redis:
|
|
80
88
|
image: redis/redis-stack:latest
|
|
81
89
|
container_name: tradejs-redis
|
|
90
|
+
environment:
|
|
91
|
+
REDIS_ARGS: --save "" --appendonly no --stop-writes-on-bgsave-error no
|
|
82
92
|
ports:
|
|
83
93
|
- "6379:6379"
|
|
84
94
|
- "5540:8001"
|
|
@@ -5,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
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
|
+
};
|
|
8
12
|
var __copyProps = (to, from, except, desc) => {
|
|
9
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -21,8 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
29
|
|
|
25
30
|
// src/scripts/infraDown.ts
|
|
31
|
+
var infraDown_exports = {};
|
|
32
|
+
__export(infraDown_exports, {
|
|
33
|
+
main: () => main
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(infraDown_exports);
|
|
26
36
|
var import_chalk2 = __toESM(require("chalk"));
|
|
27
37
|
|
|
28
38
|
// src/scripts/infraCommon.ts
|
|
@@ -70,13 +80,13 @@ var runDockerCompose = (composePath, args) => {
|
|
|
70
80
|
};
|
|
71
81
|
|
|
72
82
|
// src/scripts/infraDown.ts
|
|
73
|
-
var
|
|
83
|
+
var main = async () => {
|
|
74
84
|
const composePath = requireDevComposeFile();
|
|
75
85
|
console.log(import_chalk2.default.cyan("Stopping dev infra (timescale, redis)..."));
|
|
76
86
|
runDockerCompose(composePath, ["stop", "timescale", "redis"]);
|
|
77
87
|
console.log(import_chalk2.default.green("Dev infra is stopped."));
|
|
78
88
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
main
|
|
82
92
|
});
|
|
@@ -5,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
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
|
+
};
|
|
8
12
|
var __copyProps = (to, from, except, desc) => {
|
|
9
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -21,8 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
29
|
|
|
25
30
|
// src/scripts/infraInit.ts
|
|
31
|
+
var infraInit_exports = {};
|
|
32
|
+
__export(infraInit_exports, {
|
|
33
|
+
main: () => main
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(infraInit_exports);
|
|
26
36
|
var import_chalk2 = __toESM(require("chalk"));
|
|
27
37
|
|
|
28
38
|
// src/scripts/infraCommon.ts
|
|
@@ -57,6 +67,14 @@ var DEV_COMPOSE_TEMPLATE = `services:
|
|
|
57
67
|
POSTGRES_DB: \${PG_DB:-app}
|
|
58
68
|
ports:
|
|
59
69
|
- "5432:5432"
|
|
70
|
+
command:
|
|
71
|
+
- postgres
|
|
72
|
+
- -c
|
|
73
|
+
- max_wal_size=16GB
|
|
74
|
+
- -c
|
|
75
|
+
- min_wal_size=2GB
|
|
76
|
+
- -c
|
|
77
|
+
- checkpoint_completion_target=0.9
|
|
60
78
|
volumes:
|
|
61
79
|
- tradejs_pgdata:/var/lib/postgresql/data
|
|
62
80
|
healthcheck:
|
|
@@ -69,6 +87,8 @@ var DEV_COMPOSE_TEMPLATE = `services:
|
|
|
69
87
|
redis:
|
|
70
88
|
image: redis/redis-stack:latest
|
|
71
89
|
container_name: tradejs-redis
|
|
90
|
+
environment:
|
|
91
|
+
REDIS_ARGS: --save "" --appendonly no --stop-writes-on-bgsave-error no
|
|
72
92
|
ports:
|
|
73
93
|
- "6379:6379"
|
|
74
94
|
- "5540:8001"
|
|
@@ -97,11 +117,11 @@ var initDevComposeFile = () => {
|
|
|
97
117
|
};
|
|
98
118
|
|
|
99
119
|
// src/scripts/infraInit.ts
|
|
100
|
-
var
|
|
120
|
+
var main = async () => {
|
|
101
121
|
initDevComposeFile();
|
|
102
122
|
console.log(import_chalk2.default.green("Dev infra files are initialized."));
|
|
103
123
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
124
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
+
0 && (module.exports = {
|
|
126
|
+
main
|
|
107
127
|
});
|
package/dist/scripts/infraUp.js
CHANGED
|
@@ -5,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
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
|
+
};
|
|
8
12
|
var __copyProps = (to, from, except, desc) => {
|
|
9
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -21,8 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
29
|
|
|
25
30
|
// src/scripts/infraUp.ts
|
|
31
|
+
var infraUp_exports = {};
|
|
32
|
+
__export(infraUp_exports, {
|
|
33
|
+
main: () => main
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(infraUp_exports);
|
|
26
36
|
var import_chalk2 = __toESM(require("chalk"));
|
|
27
37
|
|
|
28
38
|
// src/scripts/infraCommon.ts
|
|
@@ -70,13 +80,13 @@ var runDockerCompose = (composePath, args) => {
|
|
|
70
80
|
};
|
|
71
81
|
|
|
72
82
|
// src/scripts/infraUp.ts
|
|
73
|
-
var
|
|
83
|
+
var main = async () => {
|
|
74
84
|
const composePath = requireDevComposeFile();
|
|
75
85
|
console.log(import_chalk2.default.cyan("Starting dev infra (timescale, redis)..."));
|
|
76
86
|
runDockerCompose(composePath, ["up", "-d", "timescale", "redis"]);
|
|
77
87
|
console.log(import_chalk2.default.green("Dev infra is up."));
|
|
78
88
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
main
|
|
82
92
|
});
|
|
@@ -0,0 +1,222 @@
|
|
|
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/scripts/marketWs.ts
|
|
31
|
+
var marketWs_exports = {};
|
|
32
|
+
__export(marketWs_exports, {
|
|
33
|
+
main: () => main
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(marketWs_exports);
|
|
36
|
+
|
|
37
|
+
// src/lib/marketData/marketWsGateway.ts
|
|
38
|
+
var import_http = __toESM(require("http"));
|
|
39
|
+
var import_ws = require("ws");
|
|
40
|
+
var import_logger = require("@tradejs/infra/logger");
|
|
41
|
+
|
|
42
|
+
// src/lib/marketData/klineEvents.ts
|
|
43
|
+
var import_ioredis = __toESM(require("ioredis"));
|
|
44
|
+
var import_redis = require("@tradejs/infra/redis");
|
|
45
|
+
var MARKET_KLINE_CHANNEL = "tradejs:market:kline";
|
|
46
|
+
var positiveInt = (value, fallback) => {
|
|
47
|
+
const parsed = Number(value);
|
|
48
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
49
|
+
};
|
|
50
|
+
var redisOptions = () => ({
|
|
51
|
+
host: process.env.REDIS_HOST || "127.0.0.1",
|
|
52
|
+
port: positiveInt(process.env.REDIS_PORT, 6379),
|
|
53
|
+
connectTimeout: positiveInt(process.env.REDIS_CONNECT_TIMEOUT_MS, 3e3),
|
|
54
|
+
maxRetriesPerRequest: null,
|
|
55
|
+
retryStrategy: (attempt) => Math.min(attempt * 200, 2e3)
|
|
56
|
+
});
|
|
57
|
+
var buildMarketKlineTopic = (event) => [
|
|
58
|
+
event.provider,
|
|
59
|
+
event.universe,
|
|
60
|
+
event.symbol.trim().toUpperCase(),
|
|
61
|
+
event.interval
|
|
62
|
+
].join(":");
|
|
63
|
+
var createMarketKlineSubscriber = () => new import_ioredis.default(redisOptions());
|
|
64
|
+
var parseMarketKlineEvent = (payload) => {
|
|
65
|
+
try {
|
|
66
|
+
const event = JSON.parse(payload);
|
|
67
|
+
if (!event || typeof event.provider !== "string" || typeof event.universe !== "string" || typeof event.symbol !== "string" || typeof event.interval !== "string" || typeof event.confirm !== "boolean" || !event.candle || !Number.isFinite(event.candle.timestamp)) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return event;
|
|
71
|
+
} catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/lib/marketData/marketWsGateway.ts
|
|
77
|
+
var MAX_TOPICS_PER_CLIENT = 20;
|
|
78
|
+
var TOPIC_PATTERN = /^(bybit|binance|coinbase):(crypto|tradfi):[A-Z0-9._-]+:(1|3|5|15|30|60|120|240|360|720|D|W|M)$/;
|
|
79
|
+
var parseSubscriptionCommand = (payload) => {
|
|
80
|
+
try {
|
|
81
|
+
const value = JSON.parse(payload);
|
|
82
|
+
if (value.op !== "subscribe" && value.op !== "unsubscribe" || !Array.isArray(value.topics)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const topics = [
|
|
86
|
+
...new Set(
|
|
87
|
+
value.topics.map((topic) => String(topic).trim()).filter((topic) => TOPIC_PATTERN.test(topic))
|
|
88
|
+
)
|
|
89
|
+
];
|
|
90
|
+
return topics.length ? { op: value.op, topics } : null;
|
|
91
|
+
} catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
var applySubscriptionCommand = (current, command) => {
|
|
96
|
+
const next = new Set(current);
|
|
97
|
+
if (command.op === "unsubscribe") {
|
|
98
|
+
for (const topic of command.topics) next.delete(topic);
|
|
99
|
+
return next;
|
|
100
|
+
}
|
|
101
|
+
for (const topic of command.topics) {
|
|
102
|
+
if (next.size >= MAX_TOPICS_PER_CLIENT) break;
|
|
103
|
+
next.add(topic);
|
|
104
|
+
}
|
|
105
|
+
return next;
|
|
106
|
+
};
|
|
107
|
+
var startMarketWsGateway = async ({
|
|
108
|
+
host = process.env.MARKET_WS_HOST || "0.0.0.0",
|
|
109
|
+
port = Number(process.env.MARKET_WS_PORT || 3001)
|
|
110
|
+
} = {}) => {
|
|
111
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
112
|
+
const alive = /* @__PURE__ */ new WeakSet();
|
|
113
|
+
const server = import_http.default.createServer((request, response) => {
|
|
114
|
+
if (request.url === "/health") {
|
|
115
|
+
response.writeHead(200, { "content-type": "application/json" });
|
|
116
|
+
response.end(JSON.stringify({ status: "ok" }));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
response.writeHead(404).end();
|
|
120
|
+
});
|
|
121
|
+
const wsServer = new import_ws.WebSocketServer({ noServer: true });
|
|
122
|
+
const subscriber = createMarketKlineSubscriber();
|
|
123
|
+
server.on("upgrade", (request, socket, head) => {
|
|
124
|
+
if (request.url !== "/ws/market") {
|
|
125
|
+
socket.destroy();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
wsServer.handleUpgrade(request, socket, head, (client) => {
|
|
129
|
+
wsServer.emit("connection", client, request);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
wsServer.on("connection", (client) => {
|
|
133
|
+
subscriptions.set(client, /* @__PURE__ */ new Set());
|
|
134
|
+
alive.add(client);
|
|
135
|
+
client.on("pong", () => alive.add(client));
|
|
136
|
+
client.on("message", (raw) => {
|
|
137
|
+
const command = parseSubscriptionCommand(raw.toString());
|
|
138
|
+
if (!command) {
|
|
139
|
+
client.send(JSON.stringify({ type: "error", error: "bad_command" }));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
subscriptions.set(
|
|
143
|
+
client,
|
|
144
|
+
applySubscriptionCommand(
|
|
145
|
+
subscriptions.get(client) ?? /* @__PURE__ */ new Set(),
|
|
146
|
+
command
|
|
147
|
+
)
|
|
148
|
+
);
|
|
149
|
+
client.send(
|
|
150
|
+
JSON.stringify({
|
|
151
|
+
type: "subscribed",
|
|
152
|
+
topics: [...subscriptions.get(client) ?? []]
|
|
153
|
+
})
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
client.on("close", () => subscriptions.delete(client));
|
|
157
|
+
});
|
|
158
|
+
const heartbeat = setInterval(() => {
|
|
159
|
+
for (const client of subscriptions.keys()) {
|
|
160
|
+
if (!alive.has(client)) {
|
|
161
|
+
client.terminate();
|
|
162
|
+
subscriptions.delete(client);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
alive.delete(client);
|
|
166
|
+
client.ping();
|
|
167
|
+
}
|
|
168
|
+
}, 3e4);
|
|
169
|
+
subscriber.on("message", (channel, payload) => {
|
|
170
|
+
if (channel !== MARKET_KLINE_CHANNEL) return;
|
|
171
|
+
const event = parseMarketKlineEvent(payload);
|
|
172
|
+
if (!event) return;
|
|
173
|
+
const topic = buildMarketKlineTopic(event);
|
|
174
|
+
const message = JSON.stringify({ type: "kline", topic, event });
|
|
175
|
+
for (const [client, topics] of subscriptions) {
|
|
176
|
+
if (client.readyState === import_ws.WebSocket.OPEN && topics.has(topic)) {
|
|
177
|
+
client.send(message);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
await subscriber.subscribe(MARKET_KLINE_CHANNEL);
|
|
182
|
+
await new Promise((resolve, reject) => {
|
|
183
|
+
server.once("error", reject);
|
|
184
|
+
server.listen(port, host, () => {
|
|
185
|
+
server.removeListener("error", reject);
|
|
186
|
+
resolve();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
import_logger.logger.info("market websocket gateway listening on %s:%s", host, port);
|
|
190
|
+
return {
|
|
191
|
+
close: async () => {
|
|
192
|
+
clearInterval(heartbeat);
|
|
193
|
+
for (const client of subscriptions.keys()) client.close();
|
|
194
|
+
subscriptions.clear();
|
|
195
|
+
await subscriber.unsubscribe(MARKET_KLINE_CHANNEL);
|
|
196
|
+
subscriber.disconnect();
|
|
197
|
+
await new Promise((resolve) => wsServer.close(() => resolve()));
|
|
198
|
+
await new Promise((resolve) => server.close(() => resolve()));
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// src/scripts/marketWs.ts
|
|
204
|
+
var main = async () => {
|
|
205
|
+
const gateway = await startMarketWsGateway();
|
|
206
|
+
const abortController = new AbortController();
|
|
207
|
+
const stop = () => abortController.abort();
|
|
208
|
+
process.once("SIGINT", stop);
|
|
209
|
+
process.once("SIGTERM", stop);
|
|
210
|
+
await new Promise(
|
|
211
|
+
(resolve) => abortController.signal.addEventListener("abort", () => resolve(), {
|
|
212
|
+
once: true
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
process.removeListener("SIGINT", stop);
|
|
216
|
+
process.removeListener("SIGTERM", stop);
|
|
217
|
+
await gateway.close();
|
|
218
|
+
};
|
|
219
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
220
|
+
0 && (module.exports = {
|
|
221
|
+
main
|
|
222
|
+
});
|
|
@@ -5,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
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
|
+
};
|
|
8
12
|
var __copyProps = (to, from, except, desc) => {
|
|
9
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -21,8 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
29
|
|
|
25
30
|
// src/scripts/migration.ts
|
|
31
|
+
var migration_exports = {};
|
|
32
|
+
__export(migration_exports, {
|
|
33
|
+
main: () => main
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(migration_exports);
|
|
26
36
|
var import_progress = __toESM(require("progress"));
|
|
27
37
|
var import_chalk = __toESM(require("chalk"));
|
|
28
38
|
var import_logger = require("@tradejs/infra/logger");
|
|
@@ -48,7 +58,7 @@ var migrateFile = async (file) => {
|
|
|
48
58
|
await (0, import_timescale.upsertCandles)(rows.slice(i, i + BATCH));
|
|
49
59
|
}
|
|
50
60
|
};
|
|
51
|
-
var
|
|
61
|
+
var main = async () => {
|
|
52
62
|
const files = await (0, import_files.getFiles)(DIR, projectRoot);
|
|
53
63
|
const bar = new import_progress.default(
|
|
54
64
|
":current/:total [:bar][:percent] :eta(s) :file",
|
|
@@ -70,4 +80,7 @@ var migration = async () => {
|
|
|
70
80
|
}
|
|
71
81
|
process.exit();
|
|
72
82
|
};
|
|
73
|
-
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
main
|
|
86
|
+
});
|