dexbot 1.6.17 → 1.7.0
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/CHANGELOG.md +58 -0
- package/README.md +24 -18
- package/analysis/README.md +105 -12
- package/analysis/ama_fitting/README.md +2 -2
- package/analysis/bot_fitting/README.md +3 -3
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/analyze_args.d.ts +2 -1
- package/dist/analysis/analyze_dynamic_weight.js +2 -1
- package/dist/analysis/analyze_kalman.js +3 -2
- package/dist/analysis/analyze_liquidity.d.ts +17 -0
- package/dist/analysis/analyze_liquidity.js +325 -0
- package/dist/analysis/analyze_regime.js +3 -2
- package/dist/analysis/analyze_regime_windows.js +3 -2
- package/dist/analysis/analyze_volatility.js +3 -2
- package/dist/analysis/fills_source.d.ts +1 -8
- package/dist/analysis/fills_source.js +1 -1
- package/dist/analysis/grid_correction_check.d.ts +9 -6
- package/dist/analysis/grid_correction_check.js +56 -64
- package/dist/analysis/liquidity/liquidity_chain.d.ts +66 -0
- package/dist/analysis/liquidity/liquidity_chain.js +178 -0
- package/dist/analysis/liquidity/liquidity_chart_generator.d.ts +19 -0
- package/dist/analysis/liquidity/liquidity_chart_generator.js +523 -0
- package/dist/analysis/liquidity/liquidity_depth_model.d.ts +141 -0
- package/dist/analysis/liquidity/liquidity_depth_model.js +230 -0
- package/dist/analysis/liquidity/liquidity_view.d.ts +38 -0
- package/dist/analysis/liquidity/liquidity_view.js +55 -0
- package/dist/analysis/math_utils.d.ts +1 -1
- package/dist/analysis/trade_profitability.d.ts +1 -1
- package/dist/analysis/trade_profitability.js +2 -1
- package/dist/analysis/tradingview/analyze_tradingview.js +2 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +3 -3
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +4 -3
- package/dist/dexbot.js +74 -169
- package/dist/market_adapter/cli_args.d.ts +6 -1
- package/dist/market_adapter/cli_args.js +16 -2
- package/dist/market_adapter/core/kibana_candles.d.ts +5 -1
- package/dist/market_adapter/core/kibana_candles.js +3 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +7 -1
- package/dist/market_adapter/core/strategies/regime_gate.js +3 -1
- package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +7 -2
- package/dist/market_adapter/inputs/cex_candle_parsing.js +3 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts +7 -1
- package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -11
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +26 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +62 -52
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +14 -2
- package/dist/market_adapter/inputs/kibana_feed_source.js +14 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +14 -3
- package/dist/market_adapter/inputs/window_cache.js +14 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +12 -9
- package/dist/market_adapter/lp_chart_runner.js +3 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +5 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js +3 -1
- package/dist/market_adapter/market_adapter.d.ts +10 -2
- package/dist/market_adapter/market_adapter.js +10 -11
- package/dist/market_adapter/utils/chain.d.ts +2 -3
- package/dist/market_adapter/utils/file_json_cache.d.ts +5 -1
- package/dist/market_adapter/utils/file_json_cache.js +3 -1
- package/dist/market_adapter/utils/file_lock.js +1 -1
- package/dist/market_adapter/utils/native_history.d.ts +7 -3
- package/dist/market_adapter/utils/native_history.js +3 -1
- package/dist/market_adapter/utils/pair_orientation.d.ts +2 -2
- package/dist/modules/asset_lookup.d.ts +25 -0
- package/dist/modules/asset_lookup.js +75 -0
- package/dist/modules/bots_file_lock.d.ts +2 -2
- package/dist/modules/bots_file_lock.js +2 -2
- package/dist/modules/chain_scan.d.ts +64 -0
- package/dist/modules/chain_scan.js +80 -0
- package/dist/modules/cli_colors.d.ts +5 -0
- package/dist/modules/cli_colors.js +7 -0
- package/dist/modules/cli_progress.d.ts +51 -0
- package/dist/modules/cli_progress.js +113 -0
- package/dist/modules/constants.js +6 -3
- package/dist/modules/dexbot_class.d.ts +8 -0
- package/dist/modules/dexbot_class.js +10 -0
- package/dist/modules/dexbot_cow_runtime.d.ts +62 -1
- package/dist/modules/dexbot_cow_runtime.js +475 -47
- package/dist/modules/dexbot_credential_client.d.ts +5 -0
- package/dist/modules/dexbot_fill_runtime.js +20 -0
- package/dist/modules/dexbot_maintenance_runtime.js +71 -9
- package/dist/modules/dexbot_startup_runtime.js +7 -1
- package/dist/modules/graceful_shutdown.d.ts +2 -2
- package/dist/modules/graceful_shutdown.js +2 -2
- package/dist/modules/launcher/runtime_entry.d.ts +21 -1
- package/dist/modules/launcher/runtime_entry.js +36 -1
- package/dist/modules/launcher/runtime_mode.d.ts +4 -3
- package/dist/modules/liquidity_pool_ref.d.ts +32 -0
- package/dist/modules/liquidity_pool_ref.js +116 -0
- package/dist/modules/node_manager.d.ts +1 -1
- package/dist/modules/node_manager.js +1 -1
- package/dist/modules/order/accounting.js +2 -1
- package/dist/modules/order/export.d.ts +2 -2
- package/dist/modules/order/export.js +2 -2
- package/dist/modules/order/grid.d.ts +19 -14
- package/dist/modules/order/grid.js +269 -61
- package/dist/modules/order/grid_reconcile.js +27 -2
- package/dist/modules/order/grid_reconcile_internal.js +94 -15
- package/dist/modules/order/index.d.ts +24 -4
- package/dist/modules/order/manager.d.ts +12 -0
- package/dist/modules/order/manager.js +44 -11
- package/dist/modules/order/strategy.js +22 -2
- package/dist/modules/order/sync_engine.d.ts +32 -1
- package/dist/modules/order/sync_engine.js +209 -26
- package/dist/modules/order/utils/math.d.ts +26 -10
- package/dist/modules/order/utils/math.js +54 -14
- package/dist/modules/order/utils/order.d.ts +158 -11
- package/dist/modules/order/utils/order.js +434 -21
- package/dist/modules/order/utils/system.d.ts +136 -30
- package/dist/modules/order/utils/system.js +465 -63
- package/dist/modules/order/utils/validate.d.ts +1 -0
- package/dist/modules/order/utils/validate.js +37 -3
- package/dist/modules/storage/index.d.ts +3 -2
- package/dist/modules/storage/index.js +3 -2
- package/dist/modules/types.d.ts +14 -0
- package/dist/modules/utils/asset_symbols.d.ts +13 -2
- package/dist/modules/utils/asset_symbols.js +21 -2
- package/dist/scripts/analysis_runner.d.ts +10 -0
- package/dist/scripts/analysis_runner.js +33 -0
- package/dist/scripts/analyze-orders.js +2 -1
- package/dist/scripts/asset.d.ts +26 -0
- package/dist/scripts/asset.js +165 -0
- package/dist/scripts/bts_distribution.d.ts +1 -0
- package/dist/scripts/bts_distribution.js +194 -142
- package/dist/scripts/chart_command.d.ts +1 -1
- package/dist/scripts/chart_command.js +60 -86
- package/dist/scripts/chart_targets.d.ts +18 -0
- package/dist/scripts/chart_targets.js +52 -0
- package/dist/scripts/dw.js +1 -1
- package/dist/scripts/liquid.d.ts +24 -0
- package/dist/scripts/liquid.js +134 -0
- package/dist/scripts/rich_list.js +12 -16
- package/dist/scripts/token_distribution.d.ts +2 -0
- package/dist/scripts/token_distribution.js +132 -108
- package/dist/scripts/tv.js +1 -1
- package/dist/scripts/verify-browser-bundle.js +18 -0
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
- package/docs/COW_INVARIANTS.md +21 -11
- package/docs/DEXBOT_COMPARISON.md +6 -6
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +11 -11
- package/docs/GRID_PRICE_INVARIANT.md +28 -5
- package/docs/GRID_RECONCILE.md +25 -5
- package/docs/LIFECYCLE.md +11 -11
- package/docs/LOGGING.md +37 -2
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +124 -36
- package/docs/README.md +1 -1
- package/docs/WORKFLOW.md +3 -1
- package/docs/architecture.md +115 -13
- package/docs/developer_guide.md +12 -0
- package/market_adapter/README.md +9 -4
- package/modules/README.md +23 -15
- package/package.json +6 -3
- package/scripts/README.md +23 -7
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const DEFAULT_STEPS = 400;
|
|
3
|
+
function isFinitePositive(value) {
|
|
4
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0;
|
|
5
|
+
}
|
|
6
|
+
function toPositiveNumber(value) {
|
|
7
|
+
const n = typeof value === 'number' ? value : Number(value);
|
|
8
|
+
return Number.isFinite(n) && n > 0 ? n : null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Convert the raw `get_order_book` payload into real bid/ask sides and display
|
|
12
|
+
* prices (quote per base). Invalid orders (missing/zero amounts) are skipped.
|
|
13
|
+
* See the module header for why the on-chain `bids` list becomes real asks.
|
|
14
|
+
*/
|
|
15
|
+
function normalizeOrderBook(rawBook) {
|
|
16
|
+
const bids = [];
|
|
17
|
+
const asks = [];
|
|
18
|
+
const collect = (list, target) => {
|
|
19
|
+
if (!Array.isArray(list))
|
|
20
|
+
return;
|
|
21
|
+
for (const entry of list) {
|
|
22
|
+
const base = toPositiveNumber(entry?.base);
|
|
23
|
+
const quote = toPositiveNumber(entry?.quote);
|
|
24
|
+
if (base == null || quote == null)
|
|
25
|
+
continue;
|
|
26
|
+
target.push({ price: quote / base, quote, base });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
// On-chain `bids` sell the base asset => real asks.
|
|
30
|
+
collect(rawBook?.bids, asks);
|
|
31
|
+
// On-chain `asks` sell the quote asset => real bids.
|
|
32
|
+
collect(rawBook?.asks, bids);
|
|
33
|
+
bids.sort((a, b) => b.price - a.price);
|
|
34
|
+
asks.sort((a, b) => a.price - b.price);
|
|
35
|
+
return { bids, asks };
|
|
36
|
+
}
|
|
37
|
+
function computePoolPrice(pool) {
|
|
38
|
+
if (!pool)
|
|
39
|
+
return null;
|
|
40
|
+
if (!isFinitePositive(pool.baseReserve) || !isFinitePositive(pool.quoteReserve))
|
|
41
|
+
return null;
|
|
42
|
+
return pool.quoteReserve / pool.baseReserve;
|
|
43
|
+
}
|
|
44
|
+
function computeBookStats(sides) {
|
|
45
|
+
const bestBid = sides.bids.length ? sides.bids[0].price : null;
|
|
46
|
+
const bestAsk = sides.asks.length ? sides.asks[0].price : null;
|
|
47
|
+
const mid = bestBid != null && bestAsk != null
|
|
48
|
+
? (bestBid + bestAsk) / 2
|
|
49
|
+
: bestBid ?? bestAsk ?? null;
|
|
50
|
+
const spreadPercent = bestBid != null && bestAsk != null && bestAsk > 0
|
|
51
|
+
? ((bestAsk - bestBid) / bestAsk) * 100
|
|
52
|
+
: null;
|
|
53
|
+
return {
|
|
54
|
+
bestBid,
|
|
55
|
+
bestAsk,
|
|
56
|
+
mid,
|
|
57
|
+
spreadPercent,
|
|
58
|
+
bidOrders: sides.bids.length,
|
|
59
|
+
askOrders: sides.asks.length,
|
|
60
|
+
bidQuoteTotal: sides.bids.reduce((sum, o) => sum + o.quote, 0),
|
|
61
|
+
askQuoteTotal: sides.asks.reduce((sum, o) => sum + o.quote, 0),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Symmetric linear window around the pool price (or the book mid when there is
|
|
66
|
+
* no pool), e.g. range 0.5 => [0.5 * center, 1.5 * center].
|
|
67
|
+
*/
|
|
68
|
+
function resolvePriceWindow(center, range) {
|
|
69
|
+
if (!isFinitePositive(center)) {
|
|
70
|
+
throw new Error('resolvePriceWindow: center price must be a positive finite number');
|
|
71
|
+
}
|
|
72
|
+
if (!Number.isFinite(range) || range <= 0 || range >= 0.95) {
|
|
73
|
+
throw new Error('resolvePriceWindow: range must be between 0 (exclusive) and 0.95 (exclusive)');
|
|
74
|
+
}
|
|
75
|
+
return { min: center * (1 - range), max: center * (1 + range) };
|
|
76
|
+
}
|
|
77
|
+
function lowerBound(values, target) {
|
|
78
|
+
let lo = 0, hi = values.length;
|
|
79
|
+
while (lo < hi) {
|
|
80
|
+
const mid = (lo + hi) >> 1;
|
|
81
|
+
if (values[mid] < target)
|
|
82
|
+
lo = mid + 1;
|
|
83
|
+
else
|
|
84
|
+
hi = mid;
|
|
85
|
+
}
|
|
86
|
+
return lo;
|
|
87
|
+
}
|
|
88
|
+
function upperBound(values, target) {
|
|
89
|
+
let lo = 0, hi = values.length;
|
|
90
|
+
while (lo < hi) {
|
|
91
|
+
const mid = (lo + hi) >> 1;
|
|
92
|
+
if (values[mid] <= target)
|
|
93
|
+
lo = mid + 1;
|
|
94
|
+
else
|
|
95
|
+
hi = mid;
|
|
96
|
+
}
|
|
97
|
+
return lo;
|
|
98
|
+
}
|
|
99
|
+
function buildPriceGrid(input, poolPrice) {
|
|
100
|
+
const { window } = input;
|
|
101
|
+
const steps = Math.max(2, Math.floor(input.steps ?? DEFAULT_STEPS));
|
|
102
|
+
const span = window.max - window.min;
|
|
103
|
+
const eps = Math.max(span * 1e-9, Number.MIN_VALUE);
|
|
104
|
+
const values = [];
|
|
105
|
+
for (let i = 0; i < steps; i++) {
|
|
106
|
+
values.push(window.min + (span * i) / (steps - 1));
|
|
107
|
+
}
|
|
108
|
+
// Duplicate each book level with a tiny offset so the cumulative step is
|
|
109
|
+
// drawn as a near-vertical jump instead of a diagonal ramp between samples.
|
|
110
|
+
// Bids: depth excludes the level once price moves above it (p + eps).
|
|
111
|
+
// Asks: depth excludes the level once price moves below it (p - eps).
|
|
112
|
+
for (const order of input.bids) {
|
|
113
|
+
values.push(order.price, order.price + eps);
|
|
114
|
+
}
|
|
115
|
+
for (const order of input.asks) {
|
|
116
|
+
values.push(order.price, order.price - eps);
|
|
117
|
+
}
|
|
118
|
+
if (poolPrice != null)
|
|
119
|
+
values.push(poolPrice);
|
|
120
|
+
const inWindow = values.filter((v) => Number.isFinite(v) && v > 0 && v >= window.min && v <= window.max);
|
|
121
|
+
inWindow.sort((a, b) => a - b);
|
|
122
|
+
const deduped = [];
|
|
123
|
+
for (const v of inWindow) {
|
|
124
|
+
if (deduped.length === 0 || v !== deduped[deduped.length - 1])
|
|
125
|
+
deduped.push(v);
|
|
126
|
+
}
|
|
127
|
+
return deduped;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build cumulative book depth lookup tables. Bids are stored ascending with a
|
|
131
|
+
* suffix sum (depth at p = sum of bids priced >= p); asks ascending with a
|
|
132
|
+
* prefix sum (depth at p = sum of asks priced <= p).
|
|
133
|
+
*/
|
|
134
|
+
function buildBookLookups(sides) {
|
|
135
|
+
const bidAsc = [...sides.bids].sort((a, b) => a.price - b.price);
|
|
136
|
+
const bidPrices = bidAsc.map((o) => o.price);
|
|
137
|
+
const bidSuffix = new Array(bidPrices.length + 1).fill(0);
|
|
138
|
+
const bidSuffixBase = new Array(bidPrices.length + 1).fill(0);
|
|
139
|
+
for (let i = bidAsc.length - 1; i >= 0; i--) {
|
|
140
|
+
bidSuffix[i] = bidSuffix[i + 1] + bidAsc[i].quote;
|
|
141
|
+
bidSuffixBase[i] = bidSuffixBase[i + 1] + bidAsc[i].base;
|
|
142
|
+
}
|
|
143
|
+
const askAsc = [...sides.asks].sort((a, b) => a.price - b.price);
|
|
144
|
+
const askPrices = askAsc.map((o) => o.price);
|
|
145
|
+
const askPrefix = new Array(askPrices.length + 1).fill(0);
|
|
146
|
+
const askPrefixBase = new Array(askPrices.length + 1).fill(0);
|
|
147
|
+
for (let i = 0; i < askAsc.length; i++) {
|
|
148
|
+
askPrefix[i + 1] = askPrefix[i] + askAsc[i].quote;
|
|
149
|
+
askPrefixBase[i + 1] = askPrefixBase[i] + askAsc[i].base;
|
|
150
|
+
}
|
|
151
|
+
return { bidPrices, bidSuffix, bidSuffixBase, askPrices, askPrefix, askPrefixBase };
|
|
152
|
+
}
|
|
153
|
+
function poolBidDepth(price, poolPrice, quoteReserve) {
|
|
154
|
+
if (!(price < poolPrice))
|
|
155
|
+
return 0;
|
|
156
|
+
return quoteReserve * (1 - Math.sqrt(price / poolPrice));
|
|
157
|
+
}
|
|
158
|
+
function poolAskDepth(price, poolPrice, quoteReserve) {
|
|
159
|
+
if (!(price > poolPrice))
|
|
160
|
+
return 0;
|
|
161
|
+
return quoteReserve * (Math.sqrt(price / poolPrice) - 1);
|
|
162
|
+
}
|
|
163
|
+
function poolBidBaseDepth(price, poolPrice, baseReserve) {
|
|
164
|
+
if (!(price < poolPrice))
|
|
165
|
+
return 0;
|
|
166
|
+
return baseReserve * (Math.sqrt(poolPrice / price) - 1);
|
|
167
|
+
}
|
|
168
|
+
function poolAskBaseDepth(price, poolPrice, baseReserve) {
|
|
169
|
+
if (!(price > poolPrice))
|
|
170
|
+
return 0;
|
|
171
|
+
return baseReserve * (1 - Math.sqrt(poolPrice / price));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Sample the two liquidity sources independently over a price window. The
|
|
175
|
+
* returned arrays are all the same length and share the `prices` axis.
|
|
176
|
+
*
|
|
177
|
+
* Book depth and pool depth are deliberately NOT summed: an on-chain order and
|
|
178
|
+
* an AMM reserve are different claims on liquidity, so the chart shows them
|
|
179
|
+
* side by side at each price instead of collapsing them into one stacked total.
|
|
180
|
+
*/
|
|
181
|
+
function buildDepthSeries(input) {
|
|
182
|
+
const { window } = input;
|
|
183
|
+
if (!isFinitePositive(window.min) || !isFinitePositive(window.max) || window.max <= window.min) {
|
|
184
|
+
throw new Error('buildDepthSeries: window must be positive with max > min');
|
|
185
|
+
}
|
|
186
|
+
const poolPrice = computePoolPrice(input.pool);
|
|
187
|
+
const quoteReserve = poolPrice != null && input.pool ? input.pool.quoteReserve : 0;
|
|
188
|
+
const prices = buildPriceGrid(input, poolPrice);
|
|
189
|
+
if (prices.length === 0)
|
|
190
|
+
throw new Error('buildDepthSeries: empty price grid');
|
|
191
|
+
const { bidPrices, bidSuffix, bidSuffixBase, askPrices, askPrefix, askPrefixBase } = buildBookLookups({
|
|
192
|
+
bids: input.bids,
|
|
193
|
+
asks: input.asks,
|
|
194
|
+
});
|
|
195
|
+
const baseReserve = poolPrice != null && input.pool ? input.pool.baseReserve : 0;
|
|
196
|
+
const series = {
|
|
197
|
+
prices,
|
|
198
|
+
bookBid: [],
|
|
199
|
+
poolBid: [],
|
|
200
|
+
bookAsk: [],
|
|
201
|
+
poolAsk: [],
|
|
202
|
+
bookBidBase: [],
|
|
203
|
+
poolBidBase: [],
|
|
204
|
+
bookAskBase: [],
|
|
205
|
+
poolAskBase: [],
|
|
206
|
+
poolPrice,
|
|
207
|
+
priceCount: prices.length,
|
|
208
|
+
};
|
|
209
|
+
for (const price of prices) {
|
|
210
|
+
const bookBid = bidSuffix[lowerBound(bidPrices, price)] ?? 0;
|
|
211
|
+
const bookAsk = askPrefix[upperBound(askPrices, price)] ?? 0;
|
|
212
|
+
const bookBidBase = bidSuffixBase[lowerBound(bidPrices, price)] ?? 0;
|
|
213
|
+
const bookAskBase = askPrefixBase[upperBound(askPrices, price)] ?? 0;
|
|
214
|
+
const poolBid = poolPrice != null ? poolBidDepth(price, poolPrice, quoteReserve) : 0;
|
|
215
|
+
const poolAsk = poolPrice != null ? poolAskDepth(price, poolPrice, quoteReserve) : 0;
|
|
216
|
+
const poolBidBase = poolPrice != null ? poolBidBaseDepth(price, poolPrice, baseReserve) : 0;
|
|
217
|
+
const poolAskBase = poolPrice != null ? poolAskBaseDepth(price, poolPrice, baseReserve) : 0;
|
|
218
|
+
series.bookBid.push(bookBid);
|
|
219
|
+
series.poolBid.push(poolBid);
|
|
220
|
+
series.bookAsk.push(bookAsk);
|
|
221
|
+
series.poolAsk.push(poolAsk);
|
|
222
|
+
series.bookBidBase.push(bookBidBase);
|
|
223
|
+
series.poolBidBase.push(poolBidBase);
|
|
224
|
+
series.bookAskBase.push(bookAskBase);
|
|
225
|
+
series.poolAskBase.push(poolAskBase);
|
|
226
|
+
}
|
|
227
|
+
return series;
|
|
228
|
+
}
|
|
229
|
+
export { DEFAULT_STEPS, normalizeOrderBook, computePoolPrice, computeBookStats, resolvePriceWindow, buildDepthSeries, poolBidDepth, poolAskDepth, poolBidBaseDepth, poolAskBaseDepth, };
|
|
230
|
+
//# sourceMappingURL=liquidity_depth_model.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LIQUIDITY CHART VIEW TRANSFORM (pure, shared by Node tests and the chart)
|
|
3
|
+
*
|
|
4
|
+
* The browser chart can show four combinations of price orientation and depth
|
|
5
|
+
* asset. This function is the single source of truth for that transform; the
|
|
6
|
+
* generated HTML embeds the exact same source via embedFunctionSources(), so
|
|
7
|
+
* the Node tests exercise the code the chart actually runs.
|
|
8
|
+
*
|
|
9
|
+
* orientation 'normal' price = quote per base (B/A)
|
|
10
|
+
* orientation 'inverted' price = base per quote (A/B) = 1 / price
|
|
11
|
+
*
|
|
12
|
+
* Inversion swaps bid/ask roles: a bid for the old base is an ask for the new
|
|
13
|
+
* base. `depthMode` selects the asset the cumulative depth is measured in,
|
|
14
|
+
* relative to the current orientation ('quote' or 'base').
|
|
15
|
+
*/
|
|
16
|
+
import type { DepthSeries, PriceWindow } from './liquidity_depth_model.js';
|
|
17
|
+
interface DepthView {
|
|
18
|
+
prices: number[];
|
|
19
|
+
bookBid: number[];
|
|
20
|
+
poolBid: number[];
|
|
21
|
+
bookAsk: number[];
|
|
22
|
+
poolAsk: number[];
|
|
23
|
+
poolPrice: number | null;
|
|
24
|
+
mid: number | null;
|
|
25
|
+
min: number;
|
|
26
|
+
max: number;
|
|
27
|
+
}
|
|
28
|
+
interface DepthViewOptions {
|
|
29
|
+
orientation: 'normal' | 'inverted';
|
|
30
|
+
depthMode: 'quote' | 'base';
|
|
31
|
+
poolPrice: number | null;
|
|
32
|
+
mid: number | null;
|
|
33
|
+
window: PriceWindow;
|
|
34
|
+
}
|
|
35
|
+
declare function buildDepthView(series: DepthSeries, options: DepthViewOptions): DepthView;
|
|
36
|
+
export { buildDepthView };
|
|
37
|
+
export type { DepthView, DepthViewOptions };
|
|
38
|
+
//# sourceMappingURL=liquidity_view.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
function buildDepthView(series, options) {
|
|
3
|
+
const useQuote = options.depthMode === 'quote';
|
|
4
|
+
if (options.orientation === 'normal') {
|
|
5
|
+
return {
|
|
6
|
+
prices: series.prices,
|
|
7
|
+
bookBid: useQuote ? series.bookBid : series.bookBidBase,
|
|
8
|
+
poolBid: useQuote ? series.poolBid : series.poolBidBase,
|
|
9
|
+
bookAsk: useQuote ? series.bookAsk : series.bookAskBase,
|
|
10
|
+
poolAsk: useQuote ? series.poolAsk : series.poolAskBase,
|
|
11
|
+
poolPrice: options.poolPrice,
|
|
12
|
+
mid: options.mid,
|
|
13
|
+
min: options.window.min,
|
|
14
|
+
max: options.window.max,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const n = series.prices.length;
|
|
18
|
+
const prices = new Array(n);
|
|
19
|
+
const bookBid = new Array(n);
|
|
20
|
+
const poolBid = new Array(n);
|
|
21
|
+
const bookAsk = new Array(n);
|
|
22
|
+
const poolAsk = new Array(n);
|
|
23
|
+
// 1/p reverses ordering, so walk the source backwards to keep the output
|
|
24
|
+
// ascending (uPlot requires an ascending x axis).
|
|
25
|
+
for (let out = 0, i = n - 1; i >= 0; i--, out++) {
|
|
26
|
+
prices[out] = 1 / series.prices[i];
|
|
27
|
+
bookBid[out] = useQuote ? series.bookAskBase[i] : series.bookAsk[i];
|
|
28
|
+
poolBid[out] = useQuote ? series.poolAskBase[i] : series.poolAsk[i];
|
|
29
|
+
bookAsk[out] = useQuote ? series.bookBidBase[i] : series.bookBid[i];
|
|
30
|
+
poolAsk[out] = useQuote ? series.poolBidBase[i] : series.poolBid[i];
|
|
31
|
+
}
|
|
32
|
+
// Keep the market center visually centered: a linearly symmetric window in
|
|
33
|
+
// normal price becomes an asymmetric window under 1/p, so rebuild the
|
|
34
|
+
// inverted view as a symmetric window around the reciprocal center instead
|
|
35
|
+
// of simply reciprocating the edges. The server samples a wider price range
|
|
36
|
+
// (up to p0 / (1 - range)) so this window is fully covered by data.
|
|
37
|
+
const span = options.window.max - options.window.min;
|
|
38
|
+
const range = span / (options.window.max + options.window.min);
|
|
39
|
+
const center = options.poolPrice != null ? options.poolPrice : options.mid;
|
|
40
|
+
const qCenter = center != null && center > 0 ? 1 / center : 1 / ((options.window.min + options.window.max) / 2);
|
|
41
|
+
const validRange = Number.isFinite(range) && range > 0 && range < 1;
|
|
42
|
+
return {
|
|
43
|
+
prices,
|
|
44
|
+
bookBid,
|
|
45
|
+
poolBid,
|
|
46
|
+
bookAsk,
|
|
47
|
+
poolAsk,
|
|
48
|
+
poolPrice: options.poolPrice != null ? 1 / options.poolPrice : null,
|
|
49
|
+
mid: options.mid != null ? 1 / options.mid : null,
|
|
50
|
+
min: validRange ? qCenter * (1 - range) : 1 / options.window.max,
|
|
51
|
+
max: validRange ? qCenter * (1 + range) : 1 / options.window.min,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export { buildDepthView };
|
|
55
|
+
//# sourceMappingURL=liquidity_view.js.map
|
|
@@ -72,7 +72,7 @@ declare function geometricRange(min: number, max: number, count: number, { decim
|
|
|
72
72
|
* Parse a candle JSON file with format detection:
|
|
73
73
|
* flat array → {candles: [...]} → {data: [...]}
|
|
74
74
|
*/
|
|
75
|
-
|
|
75
|
+
interface CandleFile {
|
|
76
76
|
candles: Record<string, unknown>[];
|
|
77
77
|
meta: Record<string, unknown> | null;
|
|
78
78
|
}
|
|
@@ -146,5 +146,5 @@ declare function computeMetrics(pair: PairAnalysis, window?: WindowRange): Tradi
|
|
|
146
146
|
/** Auto-named report file: bot/account + pair filter + requested range. */
|
|
147
147
|
declare function reportFileName(opts: TradeProfitabilityOptions, accountRef: string, botName: string | null): string;
|
|
148
148
|
declare function run(argv?: string[]): Promise<void>;
|
|
149
|
-
export { analyzePair, classifyFills, computeMetrics, parseArgs, run, reportFileName, TradeFill, FillRecord,
|
|
149
|
+
export { analyzePair, classifyFills, computeMetrics, parseArgs, run, reportFileName, TradeFill, FillRecord, PairAnalysis, TradingMetrics };
|
|
150
150
|
//# sourceMappingURL=trade_profitability.d.ts.map
|
|
@@ -9,6 +9,7 @@ import { writePnlReport } from './pnl_report.js';
|
|
|
9
9
|
import { percentile } from './math_utils.js';
|
|
10
10
|
import { fetchFillsCached } from './fills_cache.js';
|
|
11
11
|
import { toFileUrl } from './chart_utils.js';
|
|
12
|
+
import { CLI_TAGS, savedLine } from '../modules/cli_progress.js';
|
|
12
13
|
import { PATHS } from '../modules/paths.js';
|
|
13
14
|
import { sanitizeKey } from '../modules/utils/sanitize_key.js';
|
|
14
15
|
import { monthsToHours } from '../modules/utils/time_range.js';
|
|
@@ -1175,7 +1176,7 @@ async function run(argv = process.argv.slice(2)) {
|
|
|
1175
1176
|
assetFilter: opts.asset,
|
|
1176
1177
|
pairs: analyses.map(pair => ({ pair, metrics: computeMetrics(pair, reportWindow) })),
|
|
1177
1178
|
}, reportPath);
|
|
1178
|
-
console.log(
|
|
1179
|
+
console.log(savedLine(CLI_TAGS.pnl, 'PnL report', toFileUrl(reportPath), 'report'));
|
|
1179
1180
|
}
|
|
1180
1181
|
else {
|
|
1181
1182
|
// Output: summaries → grand total → per-match detail
|
|
@@ -12,6 +12,7 @@ import { toIntervalLabel } from '../../market_adapter/interval_utils.js';
|
|
|
12
12
|
import { loadBotMeta } from '../bot_key_utils.js';
|
|
13
13
|
import { resolveSource, listAvailableBots } from '../resolve_source.js';
|
|
14
14
|
import { writeChartFile, toFileUrl } from '../chart_utils.js';
|
|
15
|
+
import { CLI_TAGS, savedLine } from '../../modules/cli_progress.js';
|
|
15
16
|
import { PATHS } from '../../modules/paths.js';
|
|
16
17
|
const DEFAULT_CHART_DIR = PATHS.ANALYSIS.CHARTS_DIR;
|
|
17
18
|
const DEFAULT_CHART_FILE = path.join(DEFAULT_CHART_DIR, 'tradingview_chart.html');
|
|
@@ -316,7 +317,7 @@ async function main() {
|
|
|
316
317
|
}, title);
|
|
317
318
|
writeChartFile(config.chartFile, html);
|
|
318
319
|
if (!config.quiet)
|
|
319
|
-
console.log(
|
|
320
|
+
console.log(savedLine(CLI_TAGS.tradingView, 'Chart', toFileUrl(config.chartFile)));
|
|
320
321
|
}
|
|
321
322
|
catch (err) {
|
|
322
323
|
console.error(`[TradingView] Error: ${getErrorMessage(err)}`);
|
|
@@ -3480,7 +3480,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
3480
3480
|
document.getElementById('ama-init-offset').disabled = !currentAmaInitOffsetEnabled;
|
|
3481
3481
|
document.getElementById('ama-init-offset-val').textContent = currentAmaInitOffset + '%';
|
|
3482
3482
|
currentVwapEnabled = document.getElementById('vwap-toggle').checked;
|
|
3483
|
-
currentVwapBars = clamp(Math.round(Number(document.getElementById('vwap-bars').value) || 500),
|
|
3483
|
+
currentVwapBars = clamp(Math.round(Number(document.getElementById('vwap-bars').value) || 500), 10, 2000);
|
|
3484
3484
|
currentRangeEnabled = document.getElementById('range-toggle').checked;
|
|
3485
3485
|
currentRangeScaleEnabled = document.getElementById('range-scale-toggle').checked;
|
|
3486
3486
|
currentRangeSpan = Math.min(${RANGE_SPAN_MAX}, Math.max(${RANGE_SPAN_MIN}, Math.round((Number(document.getElementById('range-span').value) || ${RANGE_SPAN_DEFAULT}) * 20) / 20));
|
|
@@ -3609,8 +3609,8 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
3609
3609
|
addHold(dec, -1);
|
|
3610
3610
|
addHold(inc, 1);
|
|
3611
3611
|
}
|
|
3612
|
-
makeStepper('sma-period',
|
|
3613
|
-
makeStepper('vwap-bars',
|
|
3612
|
+
makeStepper('sma-period', 10, 10, 0);
|
|
3613
|
+
makeStepper('vwap-bars', 10, 10, 0);
|
|
3614
3614
|
makeStepper('ama-er', 10, 1, 0);
|
|
3615
3615
|
makeStepper('ama-fast', 0.1, 0.1, 1);
|
|
3616
3616
|
makeStepper('ama-slow', 1, 0.1, 1);
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
export type HuberScaleMode = 'none' | 'df' | 'mscale';
|
|
2
2
|
/** One-bar diagnostic snapshot returned alongside the slope. */
|
|
3
|
-
|
|
3
|
+
interface HuberDiagnostics {
|
|
4
4
|
slopePct: number;
|
|
5
5
|
scale: number;
|
|
6
6
|
outlierFraction: number;
|
|
7
7
|
}
|
|
8
8
|
/** Accumulated stats attached to an estimator built by {@link createHuberEstimator}. */
|
|
9
|
-
|
|
9
|
+
interface HuberEstimatorStats {
|
|
10
10
|
calls: number;
|
|
11
11
|
outlierFractionSum: number;
|
|
12
12
|
scaleSum: number;
|
|
13
13
|
}
|
|
14
14
|
/** Estimator function shape accepted by simulateGridResetSeries (cfg.slopeEstimator). */
|
|
15
|
-
|
|
15
|
+
interface HuberConsts {
|
|
16
16
|
C?: number;
|
|
17
17
|
ITERATIONS?: number;
|
|
18
18
|
SCALE_FLOOR?: number;
|
|
@@ -37,4 +37,5 @@ export declare function huberSlopeCore(amaValues: unknown, index: number, lookba
|
|
|
37
37
|
* accumulating the mean outlier fraction and scale across calls in `.stats`.
|
|
38
38
|
*/
|
|
39
39
|
export declare function createHuberEstimator(mode?: HuberScaleMode, hub?: HuberConsts): HuberEstimator;
|
|
40
|
+
export {};
|
|
40
41
|
//# sourceMappingURL=huber_scale_variants.d.ts.map
|