@clonegod/ttd-core 3.1.43 → 3.1.44
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/analyze/index.js +20 -1
- package/dist/analyze/ws_client.d.ts +11 -1
- package/dist/analyze/ws_client.js +11 -1
- package/package.json +1 -1
package/dist/analyze/index.js
CHANGED
|
@@ -71,10 +71,29 @@ function getWsClient() {
|
|
|
71
71
|
return null;
|
|
72
72
|
if (!_wsClient) {
|
|
73
73
|
const url = `ws://${host}:${service_ports_1.SERVICE_PORT.TRADE_ANALYZE_HTTP}/trade/analyze/ws/ingest`;
|
|
74
|
-
_wsClient = new ws_client_1.AnalyzeWsClient(url);
|
|
74
|
+
_wsClient = new ws_client_1.AnalyzeWsClient(url, () => buildHello());
|
|
75
75
|
}
|
|
76
76
|
return _wsClient;
|
|
77
77
|
}
|
|
78
|
+
function buildHello() {
|
|
79
|
+
let env = {};
|
|
80
|
+
try {
|
|
81
|
+
env = (0, core_env_1.getCoreEnv)() || {};
|
|
82
|
+
}
|
|
83
|
+
catch (_a) { }
|
|
84
|
+
const hasQuotePool = !!(env.quote_pool_address || env.quote_pool_name);
|
|
85
|
+
const hasGroup = !!env.group_id;
|
|
86
|
+
const kind = hasQuotePool ? 'QUOTE' : hasGroup ? 'TRADE' : 'OTHER';
|
|
87
|
+
return {
|
|
88
|
+
kind,
|
|
89
|
+
app_id: process.env.name || env.app_name || '',
|
|
90
|
+
pair: env.pair || '',
|
|
91
|
+
dex_id: env.dex_id || '',
|
|
92
|
+
group_id: env.group_id || '',
|
|
93
|
+
pool_name: env.quote_pool_name || '',
|
|
94
|
+
fee_rate: env.quote_pool_fee_rate ? Number(env.quote_pool_fee_rate) : undefined,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
78
97
|
const WS_TYPES = new Set([
|
|
79
98
|
'PreTradeEvent',
|
|
80
99
|
'PriceMessageType',
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
export interface AnalyzeWsHello {
|
|
2
|
+
kind: 'QUOTE' | 'TRADE' | 'OTHER';
|
|
3
|
+
app_id?: string;
|
|
4
|
+
pair?: string;
|
|
5
|
+
dex_id?: string;
|
|
6
|
+
group_id?: string;
|
|
7
|
+
pool_name?: string;
|
|
8
|
+
fee_rate?: number;
|
|
9
|
+
}
|
|
1
10
|
export declare class AnalyzeWsClient {
|
|
2
11
|
private readonly url;
|
|
12
|
+
private readonly helloFn?;
|
|
3
13
|
private ws;
|
|
4
14
|
private reconnectTimer;
|
|
5
15
|
private connected;
|
|
@@ -7,7 +17,7 @@ export declare class AnalyzeWsClient {
|
|
|
7
17
|
private readonly MAX_QUEUE;
|
|
8
18
|
private droppedCount;
|
|
9
19
|
private lastDroppedLogAt;
|
|
10
|
-
constructor(url: string);
|
|
20
|
+
constructor(url: string, helloFn?: () => AnalyzeWsHello);
|
|
11
21
|
private connect;
|
|
12
22
|
private scheduleReconnect;
|
|
13
23
|
private flushQueue;
|
|
@@ -7,8 +7,9 @@ exports.AnalyzeWsClient = void 0;
|
|
|
7
7
|
const ws_1 = __importDefault(require("ws"));
|
|
8
8
|
const index_1 = require("../index");
|
|
9
9
|
class AnalyzeWsClient {
|
|
10
|
-
constructor(url) {
|
|
10
|
+
constructor(url, helloFn) {
|
|
11
11
|
this.url = url;
|
|
12
|
+
this.helloFn = helloFn;
|
|
12
13
|
this.ws = null;
|
|
13
14
|
this.reconnectTimer = null;
|
|
14
15
|
this.connected = false;
|
|
@@ -24,6 +25,15 @@ class AnalyzeWsClient {
|
|
|
24
25
|
this.ws.on('open', () => {
|
|
25
26
|
this.connected = true;
|
|
26
27
|
(0, index_1.log_info)(`[AnalyzeWs] connected: ${this.url}`);
|
|
28
|
+
if (this.helloFn) {
|
|
29
|
+
try {
|
|
30
|
+
const hello = this.helloFn();
|
|
31
|
+
this.ws.send(JSON.stringify({ type: 'HELLO', data: hello }));
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
(0, index_1.log_debug)(`[AnalyzeWs] hello send failed: ${e.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
27
37
|
this.flushQueue();
|
|
28
38
|
});
|
|
29
39
|
this.ws.on('close', () => {
|