@clonegod/ttd-core 3.1.42 → 3.1.43
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 +21 -17
- package/package.json +1 -1
package/dist/analyze/index.js
CHANGED
|
@@ -53,25 +53,26 @@ const index_1 = require("../index");
|
|
|
53
53
|
const service_ports_1 = require("../constants/service_ports");
|
|
54
54
|
const ws_client_1 = require("./ws_client");
|
|
55
55
|
Object.defineProperty(exports, "AnalyzeWsClient", { enumerable: true, get: function () { return ws_client_1.AnalyzeWsClient; } });
|
|
56
|
-
const
|
|
56
|
+
const httpHeaders = { 'Content-Type': 'application/json' };
|
|
57
|
+
const httpAgent = new http.Agent({ keepAlive: true, maxSockets: 10 });
|
|
58
|
+
function getAnalyzeHost() {
|
|
59
|
+
var _a;
|
|
57
60
|
try {
|
|
58
|
-
return (0, core_env_1.getCoreEnv)();
|
|
61
|
+
return ((_a = (0, core_env_1.getCoreEnv)()) === null || _a === void 0 ? void 0 : _a.trade_analyze_host) || '';
|
|
59
62
|
}
|
|
60
|
-
catch (
|
|
61
|
-
return
|
|
63
|
+
catch (_b) {
|
|
64
|
+
return '';
|
|
62
65
|
}
|
|
63
|
-
}
|
|
64
|
-
const ANALYZE_HOST = (_env === null || _env === void 0 ? void 0 : _env.trade_analyze_host) || '';
|
|
65
|
-
const ANALYZE_HTTP_BASE = ANALYZE_HOST ? `http://${ANALYZE_HOST}:${service_ports_1.SERVICE_PORT.TRADE_ANALYZE_HTTP}/trade/analyze` : '';
|
|
66
|
-
const ANALYZE_WS_URL = ANALYZE_HOST ? `ws://${ANALYZE_HOST}:${service_ports_1.SERVICE_PORT.TRADE_ANALYZE_HTTP}/trade/analyze/ws/ingest` : '';
|
|
67
|
-
const httpHeaders = { 'Content-Type': 'application/json' };
|
|
68
|
-
const httpAgent = new http.Agent({ keepAlive: true, maxSockets: 10 });
|
|
66
|
+
}
|
|
69
67
|
let _wsClient = null;
|
|
70
68
|
function getWsClient() {
|
|
71
|
-
|
|
69
|
+
const host = getAnalyzeHost();
|
|
70
|
+
if (!host)
|
|
72
71
|
return null;
|
|
73
|
-
if (!_wsClient)
|
|
74
|
-
|
|
72
|
+
if (!_wsClient) {
|
|
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);
|
|
75
|
+
}
|
|
75
76
|
return _wsClient;
|
|
76
77
|
}
|
|
77
78
|
const WS_TYPES = new Set([
|
|
@@ -85,7 +86,8 @@ const HTTP_PATH = {
|
|
|
85
86
|
TradeResultType: '/ingest/trade-result',
|
|
86
87
|
};
|
|
87
88
|
const report_data_to_analyze = (type, data) => {
|
|
88
|
-
|
|
89
|
+
const host = getAnalyzeHost();
|
|
90
|
+
if (!host)
|
|
89
91
|
return;
|
|
90
92
|
if (WS_TYPES.has(type)) {
|
|
91
93
|
const client = getWsClient();
|
|
@@ -99,7 +101,8 @@ const report_data_to_analyze = (type, data) => {
|
|
|
99
101
|
return;
|
|
100
102
|
}
|
|
101
103
|
try {
|
|
102
|
-
|
|
104
|
+
const url = `http://${host}:${service_ports_1.SERVICE_PORT.TRADE_ANALYZE_HTTP}/trade/analyze${path}`;
|
|
105
|
+
axios_1.default.post(url, data, { headers: httpHeaders, timeout: 3000, httpAgent })
|
|
103
106
|
.then(() => (0, index_1.log_trace)(`[analyze] report ${type} ok`))
|
|
104
107
|
.catch(err => (0, index_1.log_warn)(`[analyze] report ${type} fail: ${err.message}`));
|
|
105
108
|
}
|
|
@@ -109,10 +112,11 @@ const report_data_to_analyze = (type, data) => {
|
|
|
109
112
|
};
|
|
110
113
|
exports.report_data_to_analyze = report_data_to_analyze;
|
|
111
114
|
const get_pool_latest_quote_price = (unique_orderbook_id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
|
-
|
|
115
|
+
const host = getAnalyzeHost();
|
|
116
|
+
if (!host || (0, index_1.isEmpty)(unique_orderbook_id))
|
|
113
117
|
return null;
|
|
114
118
|
try {
|
|
115
|
-
const url =
|
|
119
|
+
const url = `http://${host}:${service_ports_1.SERVICE_PORT.TRADE_ANALYZE_HTTP}/trade/analyze/quote/price-msg?unique_orderbook_id=${unique_orderbook_id}`;
|
|
116
120
|
const res = (yield axios_1.default.get(url, { headers: httpHeaders, timeout: 3000, httpAgent })).data;
|
|
117
121
|
return res.data;
|
|
118
122
|
}
|