@clonegod/ttd-core 3.0.19 → 3.0.21
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.
|
@@ -14,16 +14,51 @@ const __1 = require("..");
|
|
|
14
14
|
function log_quote_price(event_source, price_message, tx_hash) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const { unique_orderbook_id, pool_name, pair, fee_rate, price_id, quote_amount_usd, ask, bid, time } = price_message;
|
|
17
|
-
let
|
|
18
|
-
let price_time_str = (0, __1.parseToDateTime)(price_time);
|
|
17
|
+
let price_time_str = (0, __1.parseToDateTime)(new Date().getTime());
|
|
19
18
|
let times = [
|
|
20
19
|
time.quote_start_time - time.stream_time,
|
|
21
20
|
time.quote_end_time - time.quote_start_time,
|
|
22
21
|
time.price_time - time.stream_time,
|
|
23
22
|
];
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const source = (event_source || tx_hash)
|
|
24
|
+
? `> [${event_source}] - ${tx_hash}\n`
|
|
25
|
+
: '';
|
|
26
|
+
console.log(source +
|
|
27
|
+
price_time_str + ' - ' +
|
|
28
|
+
unique_orderbook_id + ' - ' +
|
|
29
|
+
String(price_id).padEnd(32) + ' - ' +
|
|
30
|
+
pool_name.padEnd(12) + ' - ' +
|
|
31
|
+
pair.padEnd(12) + ' - ' +
|
|
32
|
+
String(quote_amount_usd).padEnd(4) + ' - ' +
|
|
33
|
+
String(ask.price).padEnd(8) + ' - ' +
|
|
34
|
+
String(bid.price).padEnd(8) + ' - ' +
|
|
35
|
+
`${times.join(',')} ms`);
|
|
36
|
+
const depthLine = formatDepthLine(ask, bid);
|
|
37
|
+
if (depthLine) {
|
|
38
|
+
console.log(depthLine);
|
|
26
39
|
}
|
|
27
|
-
console.log(price_time_str, ' - ', unique_orderbook_id, ' - ', String(price_id).padEnd(32), ' - ', pool_name.padEnd(12), ' - ', pair.padEnd(12), ' - ', String(quote_amount_usd).padEnd(4), ' - ', String(ask.price).padEnd(8), ' - ', String(bid.price).padEnd(8), ' - ', `${times.join(',')} ms`, '\n');
|
|
28
40
|
});
|
|
29
41
|
}
|
|
42
|
+
function formatDepthLine(ask, bid) {
|
|
43
|
+
const bpsSet = new Set();
|
|
44
|
+
for (const key of Object.keys(ask)) {
|
|
45
|
+
const match = key.match(/^depth_(\d+)$/);
|
|
46
|
+
if (match)
|
|
47
|
+
bpsSet.add(Number(match[1]));
|
|
48
|
+
}
|
|
49
|
+
if (bpsSet.size === 0)
|
|
50
|
+
return null;
|
|
51
|
+
const parts = [];
|
|
52
|
+
for (const bps of [...bpsSet].sort((a, b) => a - b)) {
|
|
53
|
+
const askAmt = ask[`depth_${bps}`];
|
|
54
|
+
const askUsd = ask[`depth_${bps}_usd`];
|
|
55
|
+
const askTick = ask[`depth_${bps}_tick`] || '';
|
|
56
|
+
const bidAmt = bid[`depth_${bps}`];
|
|
57
|
+
const bidUsd = bid[`depth_${bps}_usd`];
|
|
58
|
+
const bidTick = bid[`depth_${bps}_tick`] || '';
|
|
59
|
+
const askTickStr = askTick ? ` ${askTick}` : '';
|
|
60
|
+
const bidTickStr = bidTick ? ` ${bidTick}` : '';
|
|
61
|
+
parts.push(`${bps}bps: ask=${askAmt}($${askUsd})${askTickStr} | bid=${bidAmt}($${bidUsd})${bidTickStr}`);
|
|
62
|
+
}
|
|
63
|
+
return ` ↳ [Depth] ${parts.join(' | ')}`;
|
|
64
|
+
}
|