@clonegod/ttd-core 3.1.1 → 3.1.3
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.
|
@@ -16,4 +16,19 @@ export interface PoolDepthData {
|
|
|
16
16
|
tickMove?: string;
|
|
17
17
|
}>;
|
|
18
18
|
}
|
|
19
|
-
export
|
|
19
|
+
export interface QuoteResponseOptions {
|
|
20
|
+
appConfig: AppConfig;
|
|
21
|
+
poolInfo: StandardPoolInfoType;
|
|
22
|
+
quoteAmountUsd: number;
|
|
23
|
+
streamTime: number;
|
|
24
|
+
quoteStartTime: number;
|
|
25
|
+
blockNumber: number;
|
|
26
|
+
quotes: [QuoteResultType, QuoteResultType];
|
|
27
|
+
txid: string;
|
|
28
|
+
pushPriceMessage?: boolean;
|
|
29
|
+
source?: string;
|
|
30
|
+
depth?: PoolDepthData;
|
|
31
|
+
tickLiquidity?: any;
|
|
32
|
+
}
|
|
33
|
+
export declare function on_quote_response(opts: QuoteResponseOptions): void;
|
|
34
|
+
export declare function on_quote_respose(appConfig: AppConfig, pool_info: StandardPoolInfoType, quote_amount_usd: number, _execution_price: number, stream_time: number, quote_start_time: number, slot_info: string, result: [QuoteResultType, QuoteResultType, number], txid: string, push_price_message?: boolean, source?: string, depth?: PoolDepthData): void;
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.on_quote_response = on_quote_response;
|
|
3
4
|
exports.on_quote_respose = on_quote_respose;
|
|
4
5
|
const analyze_1 = require("../analyze");
|
|
5
6
|
const log_quote_price_1 = require("./log_quote_price");
|
|
6
7
|
const publish_quote_price_1 = require("./publish_quote_price");
|
|
7
8
|
const to_price_message_1 = require("./to_price_message");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
9
|
+
const TICK_LIQUIDITY_INTERVAL_MS = parseInt(process.env.TICK_CACHE_FORCE_FULL_REFRESH_INTERVAL || '60000', 10);
|
|
10
|
+
const _tickLiquidityLastPush = new Map();
|
|
11
|
+
function on_quote_response(opts) {
|
|
12
|
+
const { appConfig, poolInfo, quoteAmountUsd, streamTime, quoteStartTime, blockNumber, quotes, txid, pushPriceMessage = true, source = '', depth, tickLiquidity, } = opts;
|
|
13
|
+
const quoteEndTime = Date.now();
|
|
14
|
+
const quoteAskPrice = Number(quotes[0].price);
|
|
15
|
+
const quoteBidPrice = Number(quotes[1].price);
|
|
16
|
+
const priceTime = Date.now();
|
|
14
17
|
const time = {
|
|
15
|
-
block_time,
|
|
16
|
-
stream_time,
|
|
17
|
-
quote_start_time,
|
|
18
|
-
quote_end_time,
|
|
19
|
-
price_time,
|
|
20
|
-
total_quote_time:
|
|
18
|
+
block_time: 0,
|
|
19
|
+
stream_time: streamTime,
|
|
20
|
+
quote_start_time: quoteStartTime,
|
|
21
|
+
quote_end_time: quoteEndTime,
|
|
22
|
+
price_time: priceTime,
|
|
23
|
+
total_quote_time: priceTime - streamTime
|
|
21
24
|
};
|
|
22
|
-
(0, to_price_message_1.to_price_message)(appConfig,
|
|
25
|
+
(0, to_price_message_1.to_price_message)(appConfig, quoteAmountUsd, 0, quoteAskPrice, quoteBidPrice, poolInfo, time, String(blockNumber), source, depth)
|
|
23
26
|
.then((price_msg) => {
|
|
24
|
-
if (
|
|
27
|
+
if (pushPriceMessage) {
|
|
25
28
|
(0, publish_quote_price_1.publish_quote_price)(appConfig, price_msg);
|
|
26
29
|
}
|
|
27
|
-
(0, log_quote_price_1.log_quote_price)(
|
|
28
|
-
(0, analyze_1.report_trade_analyze_data)('PriceMessageType', Object.assign(Object.assign({}, price_msg), { quote_source: { slot:
|
|
30
|
+
(0, log_quote_price_1.log_quote_price)(String(blockNumber), price_msg, txid);
|
|
31
|
+
(0, analyze_1.report_trade_analyze_data)('PriceMessageType', Object.assign(Object.assign({}, price_msg), { quote_source: { slot: String(blockNumber), block: null, txid } }));
|
|
29
32
|
if (depth) {
|
|
30
33
|
(0, analyze_1.report_trade_analyze_data)('DepthLevels', {
|
|
31
34
|
price_id: price_msg.price_id,
|
|
@@ -34,8 +37,34 @@ function on_quote_respose(appConfig, pool_info, quote_amount_usd, execution_pric
|
|
|
34
37
|
depth
|
|
35
38
|
});
|
|
36
39
|
}
|
|
40
|
+
if (tickLiquidity) {
|
|
41
|
+
const poolAddr = price_msg.pool_id || '';
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
const lastPush = _tickLiquidityLastPush.get(poolAddr) || 0;
|
|
44
|
+
if (now - lastPush >= TICK_LIQUIDITY_INTERVAL_MS) {
|
|
45
|
+
_tickLiquidityLastPush.set(poolAddr, now);
|
|
46
|
+
tickLiquidity.pair = price_msg.pair;
|
|
47
|
+
tickLiquidity.protocolId = price_msg.dex_id;
|
|
48
|
+
(0, analyze_1.report_trade_analyze_data)('TickLiquidity', tickLiquidity);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
37
51
|
})
|
|
38
52
|
.catch(err => {
|
|
39
53
|
console.error(`[on_quote_response] error: ${(err === null || err === void 0 ? void 0 : err.message) || err}`);
|
|
40
54
|
});
|
|
41
55
|
}
|
|
56
|
+
function on_quote_respose(appConfig, pool_info, quote_amount_usd, _execution_price, stream_time, quote_start_time, slot_info, result, txid, push_price_message = true, source = "", depth) {
|
|
57
|
+
on_quote_response({
|
|
58
|
+
appConfig,
|
|
59
|
+
poolInfo: pool_info,
|
|
60
|
+
quoteAmountUsd: quote_amount_usd,
|
|
61
|
+
streamTime: stream_time,
|
|
62
|
+
quoteStartTime: quote_start_time,
|
|
63
|
+
blockNumber: parseInt(slot_info, 10) || 0,
|
|
64
|
+
quotes: [result[0], result[1]],
|
|
65
|
+
txid,
|
|
66
|
+
pushPriceMessage: push_price_message,
|
|
67
|
+
source,
|
|
68
|
+
depth,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -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 analyze_1 = require("../analyze");
|
|
14
15
|
const logger = (0, __1.createLogger)(__filename);
|
|
15
16
|
const trade_context_1 = require("./trade_context");
|
|
16
17
|
const check_parse_order_msg = (appConfig, order_msg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -108,10 +109,13 @@ const handle_order_message = (trade_appconfig, trade_instance, tx_result_checker
|
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
finally {
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
const order_msg_with_result = Object.assign(Object.assign({}, order_msg), { order_submit_result });
|
|
113
|
+
trade_appconfig.arb_cache.cache_order_message(order_msg_with_result)
|
|
114
|
+
.then(() => { })
|
|
115
|
+
.catch(err => {
|
|
113
116
|
logger.warn('cache order submit result, error!', { order_msg, order_submit_result, err });
|
|
114
117
|
});
|
|
118
|
+
(0, analyze_1.report_trade_analyze_data)('OrderMessageType', order_msg_with_result);
|
|
115
119
|
}
|
|
116
120
|
});
|
|
117
121
|
exports.handle_order_message = handle_order_message;
|