@clonegod/ttd-core 3.0.10 → 3.0.11
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/cache/arb_event_pub.js +3 -3
- package/dist/index.d.ts +7 -0
- package/dist/index.js +32 -11
- package/dist/trade/handle_order_message.js +16 -12
- package/package.json +1 -1
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ArbEventPublisher = void 0;
|
|
13
13
|
const index_1 = require("../index");
|
|
14
|
+
const logger = (0, index_1.createLogger)(__filename);
|
|
14
15
|
class ArbEventPublisher {
|
|
15
16
|
constructor(arb_cache) {
|
|
16
17
|
this.arb_cache = arb_cache;
|
|
@@ -35,11 +36,10 @@ class ArbEventPublisher {
|
|
|
35
36
|
}
|
|
36
37
|
publish_order_event(group_id, pair, dex_id, message) {
|
|
37
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a;
|
|
38
40
|
const channel = (0, index_1.get_order_channel_name)(group_id, pair, dex_id);
|
|
39
41
|
yield this.redis_cmd.publish(channel, JSON.stringify(message));
|
|
40
|
-
|
|
41
|
-
channel, message
|
|
42
|
-
});
|
|
42
|
+
logger.info(`publish_order_event`, { channel, trace_id: (_a = message.data) === null || _a === void 0 ? void 0 : _a.order_trace_id });
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
publish_wallet_raw_tx_event(group_id, wallet, message) {
|
package/dist/index.d.ts
CHANGED
|
@@ -202,6 +202,13 @@ export declare function log_info(msg: string, data?: {}, traceId?: string, calle
|
|
|
202
202
|
export declare function log_error(msg: string, err: Error, traceId?: string, caller?: {
|
|
203
203
|
module: string;
|
|
204
204
|
}): void;
|
|
205
|
+
export declare function createLogger(filename: string): {
|
|
206
|
+
trace(msg: string, data?: any, traceId?: string): void;
|
|
207
|
+
debug(msg: string, data?: any, traceId?: string): void;
|
|
208
|
+
info(msg: string, data?: any, traceId?: string): void;
|
|
209
|
+
warn(msg: string, data?: any, traceId?: string): void;
|
|
210
|
+
error(msg: string, err: any, traceId?: string): void;
|
|
211
|
+
};
|
|
205
212
|
export declare function new_line(lines?: number): void;
|
|
206
213
|
export declare const generateRandomNumber: (min: number, max: number) => number;
|
|
207
214
|
export declare class DecimalUtil {
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,7 @@ exports.log_debug = log_debug;
|
|
|
56
56
|
exports.log_warn = log_warn;
|
|
57
57
|
exports.log_info = log_info;
|
|
58
58
|
exports.log_error = log_error;
|
|
59
|
+
exports.createLogger = createLogger;
|
|
59
60
|
exports.new_line = new_line;
|
|
60
61
|
exports.getCurDateTime = getCurDateTime;
|
|
61
62
|
exports.getCurTimeShort = getCurTimeShort;
|
|
@@ -349,17 +350,16 @@ var REDIS_EVENT_TYPE_TRADE_INSTANCE_CHANGE;
|
|
|
349
350
|
REDIS_EVENT_TYPE_TRADE_INSTANCE_CHANGE["TRADE_INSTANCE_EXIT"] = "TRADE_INSTANCE_EXIT";
|
|
350
351
|
})(REDIS_EVENT_TYPE_TRADE_INSTANCE_CHANGE || (exports.REDIS_EVENT_TYPE_TRADE_INSTANCE_CHANGE = REDIS_EVENT_TYPE_TRADE_INSTANCE_CHANGE = {}));
|
|
351
352
|
function _caller() {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
353
|
+
const obj = {};
|
|
354
|
+
Error.captureStackTrace(obj, _caller);
|
|
355
|
+
const stack = obj.stack;
|
|
356
|
+
const lines = stack.split('\n');
|
|
357
|
+
const line = lines[2] || lines[1] || '';
|
|
358
|
+
const module = (line.substring(line.lastIndexOf(path_1.default.sep) + 1, line.indexOf(':')).replace('.js', ''));
|
|
359
|
+
return {
|
|
360
|
+
method: '',
|
|
361
|
+
module
|
|
362
|
+
};
|
|
363
363
|
}
|
|
364
364
|
var LOG_LEVEL;
|
|
365
365
|
(function (LOG_LEVEL) {
|
|
@@ -428,6 +428,27 @@ function log_error(msg, err, traceId = '', caller = undefined) {
|
|
|
428
428
|
console.error(`${getCurDateTime()} - [5] - [${caller.module}] - ${traceId} - ${msg}`, err);
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
|
+
function createLogger(filename) {
|
|
432
|
+
const module = path_1.default.basename(filename).replace(/\.(js|ts)$/, '');
|
|
433
|
+
const caller = { method: '', module };
|
|
434
|
+
return {
|
|
435
|
+
trace(msg, data = {}, traceId = '') {
|
|
436
|
+
log_info(msg, data, traceId, caller, LOG_LEVEL.TRACE);
|
|
437
|
+
},
|
|
438
|
+
debug(msg, data = {}, traceId = '') {
|
|
439
|
+
log_info(msg, data, traceId, caller, LOG_LEVEL.DEBUG);
|
|
440
|
+
},
|
|
441
|
+
info(msg, data = {}, traceId = '') {
|
|
442
|
+
log_info(msg, data, traceId, caller, LOG_LEVEL.INFO);
|
|
443
|
+
},
|
|
444
|
+
warn(msg, data = {}, traceId = '') {
|
|
445
|
+
log_info(`!!! ${msg}`, data, traceId, caller, LOG_LEVEL.WARN);
|
|
446
|
+
},
|
|
447
|
+
error(msg, err, traceId = '') {
|
|
448
|
+
log_error(msg, err, traceId, caller);
|
|
449
|
+
},
|
|
450
|
+
};
|
|
451
|
+
}
|
|
431
452
|
function new_line(lines = 2) {
|
|
432
453
|
for (let i = 0; i < lines; i++) {
|
|
433
454
|
console.log('>');
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.handle_order_message = exports.try_lock_order_msg = void 0;
|
|
13
13
|
const __1 = require("..");
|
|
14
|
+
const logger = (0, __1.createLogger)(__filename);
|
|
14
15
|
const trade_context_1 = require("./trade_context");
|
|
15
16
|
const check_parse_order_msg = (appConfig, order_msg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
17
|
let { unique_orderbook_id, price_id, group_id, unique_order_msg_id } = order_msg;
|
|
@@ -58,21 +59,25 @@ const try_lock_order_msg = (appConfig, order_msg) => __awaiter(void 0, void 0, v
|
|
|
58
59
|
exports.try_lock_order_msg = try_lock_order_msg;
|
|
59
60
|
const order_trace_id_set = new Set();
|
|
60
61
|
const handle_order_message = (trade_appconfig, trade_instance, tx_result_checker_factory, recv_order_msg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
-
(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
(
|
|
62
|
+
console.log(`\n================================== NEW ORDER ==================================`);
|
|
63
|
+
let order_event_message;
|
|
64
|
+
try {
|
|
65
|
+
order_event_message = JSON.parse(recv_order_msg);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
logger.error(`handle_order_message, JSON parse failed!`, err);
|
|
69
|
+
logger.info(`handle_order_message, raw message: `, recv_order_msg);
|
|
70
|
+
return;
|
|
69
71
|
}
|
|
70
72
|
let { event_time, event_type, group_id, data: order_msg } = order_event_message;
|
|
73
|
+
logger.info(`[NEW ORDER] ${order_msg === null || order_msg === void 0 ? void 0 : order_msg.order_trace_id} | ${order_msg === null || order_msg === void 0 ? void 0 : order_msg.pair} ${(order_msg === null || order_msg === void 0 ? void 0 : order_msg.aToB) ? 'SELL' : 'BUY'} ${order_msg === null || order_msg === void 0 ? void 0 : order_msg.amount}`, {
|
|
74
|
+
group_id, price_id: order_msg === null || order_msg === void 0 ? void 0 : order_msg.price_id, dex: order_msg === null || order_msg === void 0 ? void 0 : order_msg.unique_orderbook_id
|
|
75
|
+
});
|
|
71
76
|
let { price_msg, id_parts } = yield check_parse_order_msg(trade_appconfig, order_msg);
|
|
72
77
|
let { order_trace_id } = order_msg;
|
|
73
78
|
let { chain_id, dex_id, pool_id, fee_rate } = id_parts;
|
|
74
79
|
if (order_trace_id_set.has(order_trace_id)) {
|
|
75
|
-
|
|
80
|
+
logger.warn(`order_trace_id already processed, skip`, { order_trace_id });
|
|
76
81
|
return;
|
|
77
82
|
}
|
|
78
83
|
order_trace_id_set.add(order_trace_id);
|
|
@@ -95,7 +100,7 @@ const handle_order_message = (trade_appconfig, trade_instance, tx_result_checker
|
|
|
95
100
|
trade_appconfig.subscribe_wallet_raw_txn_event();
|
|
96
101
|
}
|
|
97
102
|
catch (err) {
|
|
98
|
-
|
|
103
|
+
logger.error(`handle_order_message error!`, err);
|
|
99
104
|
order_submit_result = {
|
|
100
105
|
success: false,
|
|
101
106
|
msg: (err === null || err === void 0 ? void 0 : err.message) || 'FAILED',
|
|
@@ -105,8 +110,7 @@ const handle_order_message = (trade_appconfig, trade_instance, tx_result_checker
|
|
|
105
110
|
finally {
|
|
106
111
|
trade_appconfig.arb_cache.cache_order_message(Object.assign(Object.assign({}, order_msg), { order_submit_result })).then(res => {
|
|
107
112
|
}).catch(err => {
|
|
108
|
-
|
|
109
|
-
console.log(err);
|
|
113
|
+
logger.warn('cache order submit result, error!', { order_msg, order_submit_result, err });
|
|
110
114
|
});
|
|
111
115
|
}
|
|
112
116
|
});
|