@clonegod/ttd-core 3.0.13 → 3.0.14
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.
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { StandardPoolInfoType, QuoteResultType } from "../../types";
|
|
2
2
|
import { AppConfig } from "../app_config";
|
|
3
|
-
export
|
|
3
|
+
export interface PoolDepthData {
|
|
4
|
+
ask: Record<number, {
|
|
5
|
+
amount: number;
|
|
6
|
+
amountUsd: number;
|
|
7
|
+
}>;
|
|
8
|
+
bid: Record<number, {
|
|
9
|
+
amount: number;
|
|
10
|
+
amountUsd: number;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
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;
|
|
@@ -5,7 +5,7 @@ const analyze_1 = require("../analyze");
|
|
|
5
5
|
const log_quote_price_1 = require("./log_quote_price");
|
|
6
6
|
const publish_quote_price_1 = require("./publish_quote_price");
|
|
7
7
|
const to_price_message_1 = require("./to_price_message");
|
|
8
|
-
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 = "") {
|
|
8
|
+
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) {
|
|
9
9
|
const quote_end_time = new Date().getTime();
|
|
10
10
|
const quote_ask_price = Number(result[0].price);
|
|
11
11
|
const quote_bid_price = Number(result[1].price);
|
|
@@ -19,7 +19,7 @@ function on_quote_respose(appConfig, pool_info, quote_amount_usd, execution_pric
|
|
|
19
19
|
price_time,
|
|
20
20
|
total_quote_time: price_time - stream_time
|
|
21
21
|
};
|
|
22
|
-
(0, to_price_message_1.to_price_message)(appConfig, quote_amount_usd, execution_price, quote_ask_price, quote_bid_price, pool_info, time, slot_info, source)
|
|
22
|
+
(0, to_price_message_1.to_price_message)(appConfig, quote_amount_usd, execution_price, quote_ask_price, quote_bid_price, pool_info, time, slot_info, source, depth)
|
|
23
23
|
.then((price_msg) => {
|
|
24
24
|
if (push_price_message) {
|
|
25
25
|
(0, publish_quote_price_1.publish_quote_price)(appConfig, price_msg);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StandardPoolInfoType, QuoteTimeInfoType, PriceMessageType } from '../../types';
|
|
2
2
|
import { AppConfig } from '../app_config';
|
|
3
|
+
import { PoolDepthData } from './on_quote_response';
|
|
3
4
|
export declare const get_quote_token_decimals: (pool_info: StandardPoolInfoType) => number;
|
|
4
|
-
export declare function to_price_message(appConfig: AppConfig, quote_amount_usd: number, tx_price: number, quote_ask_price: number, quote_bid_price: number, pool_info: StandardPoolInfoType, time: QuoteTimeInfoType, slot?: string, source?: string): Promise<PriceMessageType>;
|
|
5
|
+
export declare function to_price_message(appConfig: AppConfig, quote_amount_usd: number, tx_price: number, quote_ask_price: number, quote_bid_price: number, pool_info: StandardPoolInfoType, time: QuoteTimeInfoType, slot?: string, source?: string, depth?: PoolDepthData): Promise<PriceMessageType>;
|
|
5
6
|
export declare function normalize_pair_name(priceMessage: PriceMessageType): void;
|
|
@@ -31,7 +31,7 @@ const get_quote_token_decimals = (pool_info) => {
|
|
|
31
31
|
};
|
|
32
32
|
exports.get_quote_token_decimals = get_quote_token_decimals;
|
|
33
33
|
function to_price_message(appConfig_1, quote_amount_usd_1, tx_price_1, quote_ask_price_1, quote_bid_price_1, pool_info_1, time_1, slot_1) {
|
|
34
|
-
return __awaiter(this, arguments, void 0, function* (appConfig, quote_amount_usd, tx_price, quote_ask_price, quote_bid_price, pool_info, time, slot, source = "") {
|
|
34
|
+
return __awaiter(this, arguments, void 0, function* (appConfig, quote_amount_usd, tx_price, quote_ask_price, quote_bid_price, pool_info, time, slot, source = "", depth) {
|
|
35
35
|
let { pool_address, tokenA, tokenB } = pool_info;
|
|
36
36
|
let { dex_id, pool_name, fee_rate, is_reverse_token } = yield appConfig.arb_cache.get_one_pool_info(pool_address);
|
|
37
37
|
let _dex_id = dex_id;
|
|
@@ -42,6 +42,24 @@ function to_price_message(appConfig_1, quote_amount_usd_1, tx_price_1, quote_ask
|
|
|
42
42
|
let fee_rate_bps = fee_rate / 100100;
|
|
43
43
|
let ask_price = getAskPrice(new decimal_js_1.default(quote_ask_price), fee_rate_bps * 0);
|
|
44
44
|
let bid_price = getBidPrice(new decimal_js_1.default(quote_bid_price), fee_rate_bps * 0);
|
|
45
|
+
const askData = {
|
|
46
|
+
price: ask_price,
|
|
47
|
+
quantity: quote_amount_usd
|
|
48
|
+
};
|
|
49
|
+
const bidData = {
|
|
50
|
+
price: bid_price,
|
|
51
|
+
quantity: quote_amount_usd
|
|
52
|
+
};
|
|
53
|
+
if (depth) {
|
|
54
|
+
for (const [bps, data] of Object.entries(depth.ask)) {
|
|
55
|
+
askData[`depth_${bps}`] = data.amount.toFixed(6);
|
|
56
|
+
askData[`depth_${bps}_usd`] = data.amountUsd.toFixed(2);
|
|
57
|
+
}
|
|
58
|
+
for (const [bps, data] of Object.entries(depth.bid)) {
|
|
59
|
+
bidData[`depth_${bps}`] = data.amount.toFixed(6);
|
|
60
|
+
bidData[`depth_${bps}_usd`] = data.amountUsd.toFixed(2);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
45
63
|
let price_message = {
|
|
46
64
|
chain_id,
|
|
47
65
|
dex_id,
|
|
@@ -70,14 +88,8 @@ function to_price_message(appConfig_1, quote_amount_usd_1, tx_price_1, quote_ask
|
|
|
70
88
|
},
|
|
71
89
|
tx_price: tx_price === null || tx_price === void 0 ? void 0 : tx_price.toFixed(12),
|
|
72
90
|
quote_amount_usd,
|
|
73
|
-
ask:
|
|
74
|
-
|
|
75
|
-
quantity: quote_amount_usd
|
|
76
|
-
},
|
|
77
|
-
bid: {
|
|
78
|
-
price: bid_price,
|
|
79
|
-
quantity: quote_amount_usd
|
|
80
|
-
},
|
|
91
|
+
ask: askData,
|
|
92
|
+
bid: bidData,
|
|
81
93
|
time,
|
|
82
94
|
slot,
|
|
83
95
|
blockNumber: slot ? parseInt(slot, 10) || undefined : undefined,
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -316,6 +316,8 @@ export interface UniqueOrderbookIdType {
|
|
|
316
316
|
export interface PriceType {
|
|
317
317
|
price: string
|
|
318
318
|
quantity: number // ask: baseToken的挂单数量 bid: quoteToken的挂单数量
|
|
319
|
+
/** 动态深度字段:depth_{bps} = token 数量, depth_{bps}_usd = USD 估值 */
|
|
320
|
+
[key: string]: any
|
|
319
321
|
}
|
|
320
322
|
|
|
321
323
|
export interface QuoteTimeInfoType {
|
|
@@ -349,7 +351,7 @@ export interface Ladder {
|
|
|
349
351
|
// 区块号
|
|
350
352
|
blockNumber?: string
|
|
351
353
|
|
|
352
|
-
//
|
|
354
|
+
// 价格来源: "rpc:v1" | "{provider_id}:v2" | "{provider_id}:v3"
|
|
353
355
|
source?: string
|
|
354
356
|
|
|
355
357
|
// unique_orderbook_id 价格更新时间
|