dexbot 1.4.17 → 1.4.19
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 +17 -0
- package/README.md +1 -0
- package/analysis/README.md +43 -43
- package/analysis/ama_fitting/README.md +8 -8
- package/analysis/ama_fitting/package.json +1 -1
- package/analysis/bot_fitting/README.md +4 -4
- package/analysis/bot_fitting/backtest_ama_sweep.ts +1 -1
- package/analysis/bot_usage/discover_bot_accounts.ts +11 -11
- package/analysis/tradingview/README.md +4 -4
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +2 -2
- package/analysis/trend_detection/SIGNAL_DOCUMENTATION.md +1 -1
- package/analysis/trend_detection/package.json +1 -1
- package/claw/README.md +45 -45
- package/claw/docs/AI_BOT_LIBRARY_API.md +6 -6
- package/claw/examples/short_mpa_bts_strategy.ts +3 -3
- package/claw/package.json +21 -21
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/scripts/claw_bridge.ts +2 -2
- package/claw/scripts/claw_skill_md.ts +1 -1
- package/claw/skills/launcher-ops/references/launcher-workflow.md +5 -5
- package/claw/skills/margin-trading/references/honest-asset-list.md +1 -1
- package/claw/skills/memu-memory/SKILL.md +3 -3
- package/claw/tests/test_claw_mcp_transport.ts +2 -2
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +3 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +148 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +12 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +389 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +3 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +200 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +3 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +213 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +25 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +247 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +1 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +35 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +782 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -0
- package/dist/analysis/analyze_derivatives.d.ts +86 -0
- package/dist/analysis/analyze_derivatives.d.ts.map +1 -0
- package/dist/analysis/analyze_derivatives.js +285 -0
- package/dist/analysis/analyze_derivatives.js.map +1 -0
- package/dist/analysis/analyze_dynamic_weight.d.ts +14 -0
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +1 -0
- package/dist/analysis/analyze_dynamic_weight.js +197 -0
- package/dist/analysis/analyze_dynamic_weight.js.map +1 -0
- package/dist/analysis/analyze_kalman.d.ts +13 -0
- package/dist/analysis/analyze_kalman.d.ts.map +1 -0
- package/dist/analysis/analyze_kalman.js +118 -0
- package/dist/analysis/analyze_kalman.js.map +1 -0
- package/dist/analysis/analyze_regime.d.ts +20 -0
- package/dist/analysis/analyze_regime.d.ts.map +1 -0
- package/dist/analysis/analyze_regime.js +139 -0
- package/dist/analysis/analyze_regime.js.map +1 -0
- package/dist/analysis/analyze_regime_windows.d.ts +19 -0
- package/dist/analysis/analyze_regime_windows.d.ts.map +1 -0
- package/dist/analysis/analyze_regime_windows.js +414 -0
- package/dist/analysis/analyze_regime_windows.js.map +1 -0
- package/dist/analysis/analyze_risk_profile.d.ts +3 -0
- package/dist/analysis/analyze_risk_profile.d.ts.map +1 -0
- package/dist/analysis/analyze_risk_profile.js +186 -0
- package/dist/analysis/analyze_risk_profile.js.map +1 -0
- package/dist/analysis/analyze_trade_heatmap.d.ts +3 -0
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +1 -0
- package/dist/analysis/analyze_trade_heatmap.js +358 -0
- package/dist/analysis/analyze_trade_heatmap.js.map +1 -0
- package/dist/analysis/analyze_volatility.d.ts +22 -0
- package/dist/analysis/analyze_volatility.d.ts.map +1 -0
- package/dist/analysis/analyze_volatility.js +165 -0
- package/dist/analysis/analyze_volatility.js.map +1 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +91 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +792 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +2 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +380 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts +26 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/shared_utils.js +42 -0
- package/dist/analysis/bot_fitting/shared_utils.js.map +1 -0
- package/dist/analysis/bot_key_utils.d.ts +11 -0
- package/dist/analysis/bot_key_utils.d.ts.map +1 -0
- package/dist/analysis/bot_key_utils.js +153 -0
- package/dist/analysis/bot_key_utils.js.map +1 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +3 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +1 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.js +499 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +531 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.js +399 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -0
- package/dist/analysis/chart_css.d.ts +17 -0
- package/dist/analysis/chart_css.d.ts.map +1 -0
- package/dist/analysis/chart_css.js +49 -0
- package/dist/analysis/chart_css.js.map +1 -0
- package/dist/analysis/chart_ui.d.ts +45 -0
- package/dist/analysis/chart_ui.d.ts.map +1 -0
- package/dist/analysis/chart_ui.js +97 -0
- package/dist/analysis/chart_ui.js.map +1 -0
- package/dist/analysis/chart_utils.d.ts +27 -0
- package/dist/analysis/chart_utils.d.ts.map +1 -0
- package/dist/analysis/chart_utils.js +153 -0
- package/dist/analysis/chart_utils.js.map +1 -0
- package/dist/analysis/derivative_chart_generator.d.ts +12 -0
- package/dist/analysis/derivative_chart_generator.d.ts.map +1 -0
- package/dist/analysis/derivative_chart_generator.js +891 -0
- package/dist/analysis/derivative_chart_generator.js.map +1 -0
- package/dist/analysis/math_utils.d.ts +22 -0
- package/dist/analysis/math_utils.d.ts.map +1 -0
- package/dist/analysis/math_utils.js +43 -0
- package/dist/analysis/math_utils.js.map +1 -0
- package/dist/analysis/price_sources.d.ts +40 -0
- package/dist/analysis/price_sources.d.ts.map +1 -0
- package/dist/analysis/price_sources.js +94 -0
- package/dist/analysis/price_sources.js.map +1 -0
- package/dist/analysis/resolve_source.d.ts +25 -0
- package/dist/analysis/resolve_source.d.ts.map +1 -0
- package/dist/analysis/resolve_source.js +69 -0
- package/dist/analysis/resolve_source.js.map +1 -0
- package/dist/analysis/trade_profitability.d.ts +115 -0
- package/dist/analysis/trade_profitability.d.ts.map +1 -0
- package/dist/analysis/trade_profitability.js +1240 -0
- package/dist/analysis/trade_profitability.js.map +1 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +31 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +146 -0
- package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +5 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +1714 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts +247 -0
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/derivative_analyzer.js +901 -0
- package/dist/analysis/trend_detection/derivative_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +3 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +1361 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts +6 -0
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/hurst_analyzer.js +7 -0
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +3 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.js +360 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +8 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +8 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +6 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +7 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +6 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +7 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +3 -0
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js +310 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +2 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +128 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +2 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +37 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +1 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +3 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.js +646 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -0
- package/dist/bot.js +1 -1
- package/dist/bot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +1 -1
- package/dist/market_adapter/ama_signal_runner.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +1 -1
- package/dist/modules/account_bots.d.ts +1 -0
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +27 -5
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/constants.d.ts +1 -0
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +12 -3
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +22 -0
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +27 -1
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +48 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +168 -4
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +6 -27
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/strategy.d.ts.map +1 -1
- package/dist/modules/order/strategy.js +6 -15
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +29 -1
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +46 -1
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +2 -0
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +30 -2
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts +1 -0
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +13 -2
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/scripts/generate_lp_chart.js +1 -1
- package/dist/scripts/test-credit-renewal.js +1 -1
- package/docs/DEXBOT_COMPARISON.md +3 -3
- package/docs/EVOLUTION.md +26 -95
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_RECALCULATION.md +2 -2
- package/docs/LIFECYCLE.md +207 -0
- package/docs/README.md +9 -1
- package/docs/developer_guide.md +4 -3
- package/market_adapter/README.md +23 -23
- package/package.json +18 -21
- package/scripts/README.md +12 -12
- package/scripts/bots +5 -7
- package/scripts/clear-market-adapter.sh +1 -1
- package/scripts/dexbot +5 -7
- package/scripts/keys +5 -7
- package/scripts/pm2 +5 -7
- package/scripts/unlock +5 -7
- package/scripts/update.js +6 -7
- package/scripts/repo-stats.html +0 -480
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KIBANA BOT QUERIES
|
|
3
|
+
*
|
|
4
|
+
* Elasticsearch query builders for analyzing DEXBot / DEXBot2 order activity
|
|
5
|
+
* on the BitShares blockchain via the public Kibana instance.
|
|
6
|
+
*
|
|
7
|
+
* Data source:
|
|
8
|
+
* https://kibana.bitshares.dev / bitshares-* index
|
|
9
|
+
* Time field: block_data.block_time
|
|
10
|
+
*
|
|
11
|
+
* BitShares operation types used here:
|
|
12
|
+
* 1 = limit_order_create (field: op_object.seller)
|
|
13
|
+
* 2 = limit_order_cancel (field: op_object.fee_paying_account)
|
|
14
|
+
* 4 = fill_order (field: op_object.account_id)
|
|
15
|
+
*
|
|
16
|
+
* Relevant ES field paths:
|
|
17
|
+
* limit_order_create:
|
|
18
|
+
* op_object.seller — account that placed the order
|
|
19
|
+
* op_object.amount_to_sell.amount — integer sell amount
|
|
20
|
+
* op_object.amount_to_sell.asset_id — sell asset ID (e.g. '1.3.0' = BTS)
|
|
21
|
+
* op_object.min_to_receive.amount — integer min-receive (= limit price numerator)
|
|
22
|
+
* op_object.min_to_receive.asset_id — receive asset ID
|
|
23
|
+
* op_object.expiration — ISO datetime
|
|
24
|
+
*
|
|
25
|
+
* fill_order:
|
|
26
|
+
* op_object.account_id — whose order was filled
|
|
27
|
+
* op_object.pays.amount / .asset_id — what was paid
|
|
28
|
+
* op_object.receives.amount / .asset_id — what was received
|
|
29
|
+
* op_object.order_id — the limit order that filled
|
|
30
|
+
*
|
|
31
|
+
* limit_order_cancel:
|
|
32
|
+
* op_object.fee_paying_account — account that cancelled
|
|
33
|
+
* op_object.order — the order ID cancelled
|
|
34
|
+
*/
|
|
35
|
+
import { toIntervalLabel } from '../../market_adapter/interval_utils.js';
|
|
36
|
+
import { kibanaSearch, DEFAULT_CONFIG as BASE_CONFIG } from '../../market_adapter/core/kibana_client.js';
|
|
37
|
+
'use strict';
|
|
38
|
+
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
39
|
+
const OP_LIMIT_ORDER_CREATE = 1;
|
|
40
|
+
const OP_LIMIT_ORDER_CANCEL = 2;
|
|
41
|
+
const OP_FILL_ORDER = 4;
|
|
42
|
+
const DEFAULT_CONFIG = {
|
|
43
|
+
...BASE_CONFIG,
|
|
44
|
+
timeout: 25000,
|
|
45
|
+
};
|
|
46
|
+
// ─── Aggregation query builders (size:0, for counts & timelines) ───────────────
|
|
47
|
+
/**
|
|
48
|
+
* Time-bucketed count of limit_order_create ops for an account.
|
|
49
|
+
* Optionally filtered to orders selling a specific asset.
|
|
50
|
+
*/
|
|
51
|
+
function buildOrderCreateQuery(accountId, lookbackHours, intervalSeconds = 3600, sellAssetId = null) {
|
|
52
|
+
const filters = [
|
|
53
|
+
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
54
|
+
{ term: { 'operation_history.op_object.seller.keyword': accountId } },
|
|
55
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
56
|
+
];
|
|
57
|
+
if (sellAssetId) {
|
|
58
|
+
filters.push({ term: { 'operation_history.op_object.amount_to_sell.asset_id.keyword': sellAssetId } });
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
size: 0,
|
|
62
|
+
query: { bool: { filter: filters } },
|
|
63
|
+
aggs: {
|
|
64
|
+
by_time: {
|
|
65
|
+
date_histogram: {
|
|
66
|
+
field: 'block_data.block_time',
|
|
67
|
+
fixed_interval: toIntervalLabel(intervalSeconds),
|
|
68
|
+
min_doc_count: 1,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
total: { value_count: { field: 'operation_type' } },
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Time-bucketed count of fill_order ops for an account.
|
|
77
|
+
* Optionally filtered to fills where account pays a specific asset.
|
|
78
|
+
*/
|
|
79
|
+
function buildFillOrderQuery(accountId, lookbackHours, intervalSeconds = 3600, paysAssetId = null) {
|
|
80
|
+
const filters = [
|
|
81
|
+
{ term: { operation_type: OP_FILL_ORDER } },
|
|
82
|
+
{ term: { 'operation_history.op_object.account_id.keyword': accountId } },
|
|
83
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
84
|
+
];
|
|
85
|
+
if (paysAssetId) {
|
|
86
|
+
filters.push({ term: { 'operation_history.op_object.pays.asset_id.keyword': paysAssetId } });
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
size: 0,
|
|
90
|
+
query: { bool: { filter: filters } },
|
|
91
|
+
aggs: {
|
|
92
|
+
by_time: {
|
|
93
|
+
date_histogram: {
|
|
94
|
+
field: 'block_data.block_time',
|
|
95
|
+
fixed_interval: toIntervalLabel(intervalSeconds),
|
|
96
|
+
min_doc_count: 1,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
total: { value_count: { field: 'operation_type' } },
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Time-bucketed count of limit_order_cancel ops for an account.
|
|
105
|
+
*/
|
|
106
|
+
function buildOrderCancelQuery(accountId, lookbackHours, intervalSeconds = 3600) {
|
|
107
|
+
return {
|
|
108
|
+
size: 0,
|
|
109
|
+
query: {
|
|
110
|
+
bool: {
|
|
111
|
+
filter: [
|
|
112
|
+
{ term: { operation_type: OP_LIMIT_ORDER_CANCEL } },
|
|
113
|
+
{ term: { 'operation_history.op_object.fee_paying_account.keyword': accountId } },
|
|
114
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
aggs: {
|
|
119
|
+
by_time: {
|
|
120
|
+
date_histogram: {
|
|
121
|
+
field: 'block_data.block_time',
|
|
122
|
+
fixed_interval: toIntervalLabel(intervalSeconds),
|
|
123
|
+
min_doc_count: 1,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
total: { value_count: { field: 'operation_type' } },
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Daily activity breakdown by operation type for an account.
|
|
132
|
+
* Merges creates (by seller), fills (by account_id), cancels (by fee_paying_account)
|
|
133
|
+
* into one aggregation using a filter per op type.
|
|
134
|
+
*/
|
|
135
|
+
function buildDailyActivityQuery(accountId, lookbackHours) {
|
|
136
|
+
return {
|
|
137
|
+
size: 0,
|
|
138
|
+
query: {
|
|
139
|
+
bool: {
|
|
140
|
+
filter: [
|
|
141
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
aggs: {
|
|
146
|
+
creates: {
|
|
147
|
+
filter: {
|
|
148
|
+
bool: {
|
|
149
|
+
filter: [
|
|
150
|
+
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
151
|
+
{ term: { 'operation_history.op_object.seller.keyword': accountId } },
|
|
152
|
+
],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
aggs: {
|
|
156
|
+
by_day: {
|
|
157
|
+
date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
fills: {
|
|
162
|
+
filter: {
|
|
163
|
+
bool: {
|
|
164
|
+
filter: [
|
|
165
|
+
{ term: { operation_type: OP_FILL_ORDER } },
|
|
166
|
+
{ term: { 'operation_history.op_object.account_id.keyword': accountId } },
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
aggs: {
|
|
171
|
+
by_day: {
|
|
172
|
+
date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
cancels: {
|
|
177
|
+
filter: {
|
|
178
|
+
bool: {
|
|
179
|
+
filter: [
|
|
180
|
+
{ term: { operation_type: OP_LIMIT_ORDER_CANCEL } },
|
|
181
|
+
{ term: { 'operation_history.op_object.fee_paying_account.keyword': accountId } },
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
aggs: {
|
|
186
|
+
by_day: {
|
|
187
|
+
date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
// ─── Raw document query builders (size>0, for price/grid analysis) ────────────
|
|
195
|
+
/**
|
|
196
|
+
* Fetch raw limit_order_create documents for grid spacing analysis.
|
|
197
|
+
* Returns the price-relevant fields plus timestamps.
|
|
198
|
+
*
|
|
199
|
+
* @param {string} accountId
|
|
200
|
+
* @param {number} lookbackHours
|
|
201
|
+
* @param {string} [sellAssetId] - optional: filter to one sell-side asset
|
|
202
|
+
* @param {number} [maxResults]
|
|
203
|
+
* @returns {Object} Elasticsearch query object
|
|
204
|
+
*/
|
|
205
|
+
function buildOrderPriceQuery(accountId, lookbackHours, sellAssetId = null, maxResults = 1000) {
|
|
206
|
+
const filters = [
|
|
207
|
+
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
208
|
+
{ term: { 'operation_history.op_object.seller.keyword': accountId } },
|
|
209
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
210
|
+
];
|
|
211
|
+
if (sellAssetId) {
|
|
212
|
+
filters.push({ term: { 'operation_history.op_object.amount_to_sell.asset_id.keyword': sellAssetId } });
|
|
213
|
+
}
|
|
214
|
+
return {
|
|
215
|
+
size: maxResults,
|
|
216
|
+
_source: [
|
|
217
|
+
'block_data.block_time',
|
|
218
|
+
'operation_history.op_object.amount_to_sell',
|
|
219
|
+
'operation_history.op_object.min_to_receive',
|
|
220
|
+
'operation_history.op_object.expiration',
|
|
221
|
+
],
|
|
222
|
+
query: { bool: { filter: filters } },
|
|
223
|
+
sort: [{ 'block_data.block_time': { order: 'desc' } }],
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Fetch raw fill_order documents for fill-price analysis.
|
|
228
|
+
*
|
|
229
|
+
* @param {string} accountId
|
|
230
|
+
* @param {number} lookbackHours
|
|
231
|
+
* @param {string} [paysAssetId]
|
|
232
|
+
* @param {number} [maxResults]
|
|
233
|
+
* @returns {Object} Elasticsearch query object
|
|
234
|
+
*/
|
|
235
|
+
function buildFillPriceQuery(accountId, lookbackHours, paysAssetId = null, maxResults = 500) {
|
|
236
|
+
const filters = [
|
|
237
|
+
{ term: { operation_type: OP_FILL_ORDER } },
|
|
238
|
+
{ term: { 'operation_history.op_object.account_id.keyword': accountId } },
|
|
239
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
240
|
+
];
|
|
241
|
+
if (paysAssetId) {
|
|
242
|
+
filters.push({ term: { 'operation_history.op_object.pays.asset_id.keyword': paysAssetId } });
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
size: maxResults,
|
|
246
|
+
_source: [
|
|
247
|
+
'block_data.block_time',
|
|
248
|
+
'operation_history.op_object.pays',
|
|
249
|
+
'operation_history.op_object.receives',
|
|
250
|
+
'operation_history.op_object.order_id',
|
|
251
|
+
],
|
|
252
|
+
query: { bool: { filter: filters } },
|
|
253
|
+
sort: [{ 'block_data.block_time': { order: 'desc' } }],
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Discover which asset pairs an account trades by aggregating the sell asset IDs.
|
|
258
|
+
* Returns top asset IDs by order count.
|
|
259
|
+
*/
|
|
260
|
+
function buildAssetDiscoveryQuery(accountId, lookbackHours) {
|
|
261
|
+
return {
|
|
262
|
+
size: 0,
|
|
263
|
+
query: {
|
|
264
|
+
bool: {
|
|
265
|
+
filter: [
|
|
266
|
+
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
267
|
+
{ term: { 'operation_history.op_object.seller.keyword': accountId } },
|
|
268
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
269
|
+
],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
aggs: {
|
|
273
|
+
sell_assets: {
|
|
274
|
+
terms: {
|
|
275
|
+
field: 'operation_history.op_object.amount_to_sell.asset_id.keyword',
|
|
276
|
+
size: 10,
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
recv_assets: {
|
|
280
|
+
terms: {
|
|
281
|
+
field: 'operation_history.op_object.min_to_receive.asset_id.keyword',
|
|
282
|
+
size: 10,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
// ─── Fetch helpers ────────────────────────────────────────────────────────────
|
|
289
|
+
async function fetchOrderCreate(accountId, lookbackHours, config = {}, sellAssetId = null, intervalSeconds = 3600) {
|
|
290
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
291
|
+
return kibanaSearch(cfg, buildOrderCreateQuery(accountId, lookbackHours, intervalSeconds, sellAssetId));
|
|
292
|
+
}
|
|
293
|
+
async function fetchFillOrder(accountId, lookbackHours, config = {}, paysAssetId = null, intervalSeconds = 3600) {
|
|
294
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
295
|
+
return kibanaSearch(cfg, buildFillOrderQuery(accountId, lookbackHours, intervalSeconds, paysAssetId));
|
|
296
|
+
}
|
|
297
|
+
async function fetchOrderCancel(accountId, lookbackHours, config = {}, intervalSeconds = 3600) {
|
|
298
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
299
|
+
return kibanaSearch(cfg, buildOrderCancelQuery(accountId, lookbackHours, intervalSeconds));
|
|
300
|
+
}
|
|
301
|
+
async function fetchOrderPrices(accountId, lookbackHours, config = {}, sellAssetId = null, maxResults = 1000) {
|
|
302
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
303
|
+
return kibanaSearch(cfg, buildOrderPriceQuery(accountId, lookbackHours, sellAssetId, maxResults));
|
|
304
|
+
}
|
|
305
|
+
async function fetchFillPrices(accountId, lookbackHours, config = {}, paysAssetId = null, maxResults = 500) {
|
|
306
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
307
|
+
return kibanaSearch(cfg, buildFillPriceQuery(accountId, lookbackHours, paysAssetId, maxResults));
|
|
308
|
+
}
|
|
309
|
+
async function fetchDailyActivity(accountId, lookbackHours, config = {}) {
|
|
310
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
311
|
+
return kibanaSearch(cfg, buildDailyActivityQuery(accountId, lookbackHours));
|
|
312
|
+
}
|
|
313
|
+
async function fetchAssetDiscovery(accountId, lookbackHours, config = {}) {
|
|
314
|
+
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
315
|
+
return kibanaSearch(cfg, buildAssetDiscoveryQuery(accountId, lookbackHours));
|
|
316
|
+
}
|
|
317
|
+
// ─── Discovery query builders ─────────────────────────────────────────────────
|
|
318
|
+
/**
|
|
319
|
+
* Top N accounts by limit_order_create count (seller field).
|
|
320
|
+
* Use this to discover the most active order-placing accounts.
|
|
321
|
+
*/
|
|
322
|
+
function buildTopSellerAccountsQuery(lookbackHours, topN = 100, minCreates = 10) {
|
|
323
|
+
return {
|
|
324
|
+
size: 0,
|
|
325
|
+
query: {
|
|
326
|
+
bool: {
|
|
327
|
+
filter: [
|
|
328
|
+
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
329
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
330
|
+
],
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
aggs: {
|
|
334
|
+
by_account: {
|
|
335
|
+
terms: {
|
|
336
|
+
field: 'operation_history.op_object.seller.keyword',
|
|
337
|
+
size: topN,
|
|
338
|
+
min_doc_count: minCreates,
|
|
339
|
+
order: { _count: 'desc' },
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Top N accounts by limit_order_cancel count (fee_paying_account field).
|
|
347
|
+
*/
|
|
348
|
+
function buildTopCancellerAccountsQuery(lookbackHours, topN = 100, minCancels = 5) {
|
|
349
|
+
return {
|
|
350
|
+
size: 0,
|
|
351
|
+
query: {
|
|
352
|
+
bool: {
|
|
353
|
+
filter: [
|
|
354
|
+
{ term: { operation_type: OP_LIMIT_ORDER_CANCEL } },
|
|
355
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
aggs: {
|
|
360
|
+
by_account: {
|
|
361
|
+
terms: {
|
|
362
|
+
field: 'operation_history.op_object.fee_paying_account.keyword',
|
|
363
|
+
size: topN,
|
|
364
|
+
min_doc_count: minCancels,
|
|
365
|
+
order: { _count: 'desc' },
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Top N accounts by fill_order count (account_id field).
|
|
373
|
+
*/
|
|
374
|
+
function buildTopFilledAccountsQuery(lookbackHours, topN = 100, minFills = 3) {
|
|
375
|
+
return {
|
|
376
|
+
size: 0,
|
|
377
|
+
query: {
|
|
378
|
+
bool: {
|
|
379
|
+
filter: [
|
|
380
|
+
{ term: { operation_type: OP_FILL_ORDER } },
|
|
381
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
aggs: {
|
|
386
|
+
by_account: {
|
|
387
|
+
terms: {
|
|
388
|
+
field: 'operation_history.op_object.account_id.keyword',
|
|
389
|
+
size: topN,
|
|
390
|
+
min_doc_count: minFills,
|
|
391
|
+
order: { _count: 'desc' },
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
// ─── Exports ──────────────────────────────────────────────────────────────────
|
|
398
|
+
export { OP_LIMIT_ORDER_CREATE, OP_LIMIT_ORDER_CANCEL, OP_FILL_ORDER, DEFAULT_CONFIG, kibanaSearch, buildOrderCreateQuery, buildFillOrderQuery, buildOrderCancelQuery, buildDailyActivityQuery, buildAssetDiscoveryQuery, buildOrderPriceQuery, buildFillPriceQuery, fetchOrderCreate, fetchFillOrder, fetchOrderCancel, fetchOrderPrices, fetchFillPrices, fetchDailyActivity, fetchAssetDiscovery, buildTopSellerAccountsQuery, buildTopCancellerAccountsQuery, buildTopFilledAccountsQuery };
|
|
399
|
+
//# sourceMappingURL=kibana_bot_queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kibana_bot_queries.js","sourceRoot":"","sources":["../../../analysis/bot_usage/kibana_bot_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAi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AED;;GAEG;AACH,SAAS,2BAA2B,CAAC,aAAqB,EAAE,OAAe,GAAG,EAAE,WAAmB,CAAC;IAChG,OAAO;QACH,IAAI,EAAE,CAAC;QACP,KAAK,EAAE;YACH,IAAI,EAAE;gBACF,MAAM,EAAE;oBACJ,EAAE,IAAI,EAAG,EAAE,cAAc,EAAE,aAAa,EAAE,EAAE;oBAC5C,EAAE,KAAK,EAAE,EAAE,uBAAuB,EAAE,EAAE,GAAG,EAAE,OAAO,aAAa,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE;iBACvF;aACJ;SACJ;QACD,IAAI,EAAE;YACF,UAAU,EAAE;gBACR,KAAK,EAAE;oBACH,KAAK,EAAU,gDAAgD;oBAC/D,IAAI,EAAW,IAAI;oBACnB,aAAa,EAAE,QAAQ;oBACvB,KAAK,EAAU,EAAE,MAAM,EAAE,MAAM,EAAE;iBACpC;aACJ;SACJ;KACJ,CAAC;AACN,CAAC;AAED,iFAAiF;AAEjF,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,8BAA8B,EAAE,2BAA2B,EAAE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared CSS fragments for uPlot chart generators.
|
|
3
|
+
*
|
|
4
|
+
* All functions return raw CSS strings for interpolation into HTML template
|
|
5
|
+
* literals. Consumers compose these fragments inside their `<style>` blocks.
|
|
6
|
+
*/
|
|
7
|
+
declare function baseResetCSS(): string;
|
|
8
|
+
declare function headerCSS(height?: number): string;
|
|
9
|
+
declare function panelsCSS(headerHeight?: number): string;
|
|
10
|
+
declare function uplotBgCSS(): string;
|
|
11
|
+
declare function dotCSS(): string;
|
|
12
|
+
declare function cursorCSS(): string;
|
|
13
|
+
declare function sectionLabelCSS(): string;
|
|
14
|
+
declare function legendCSS(): string;
|
|
15
|
+
declare function sharedChartCSS(): string;
|
|
16
|
+
export { baseResetCSS, headerCSS, panelsCSS, uplotBgCSS, dotCSS, cursorCSS, sectionLabelCSS, legendCSS, sharedChartCSS };
|
|
17
|
+
//# sourceMappingURL=chart_css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart_css.d.ts","sourceRoot":"","sources":["../../analysis/chart_css.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,iBAAS,YAAY,IAAI,MAAM,CAG9B;AAED,iBAAS,SAAS,CAAC,MAAM,SAAK,GAAG,MAAM,CAEtC;AAED,iBAAS,SAAS,CAAC,YAAY,SAAK,GAAG,MAAM,CAE5C;AAED,iBAAS,UAAU,IAAI,MAAM,CAE5B;AAED,iBAAS,MAAM,IAAI,MAAM,CAExB;AAED,iBAAS,SAAS,IAAI,MAAM,CAI3B;AAED,iBAAS,eAAe,IAAI,MAAM,CAEjC;AAED,iBAAS,SAAS,IAAI,MAAM,CAG3B;AAED,iBAAS,cAAc,IAAI,MAAM,CAWhC;AAED,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Shared CSS fragments for uPlot chart generators.
|
|
4
|
+
*
|
|
5
|
+
* All functions return raw CSS strings for interpolation into HTML template
|
|
6
|
+
* literals. Consumers compose these fragments inside their `<style>` blocks.
|
|
7
|
+
*/
|
|
8
|
+
function baseResetCSS() {
|
|
9
|
+
return `* { box-sizing: border-box; }
|
|
10
|
+
body { background: #0b0e14; color: #d1d5db; font-family: 'Segoe UI', sans-serif; margin: 0; padding: 0; overflow: hidden; }`;
|
|
11
|
+
}
|
|
12
|
+
function headerCSS(height = 45) {
|
|
13
|
+
return `#header { padding: 10px 20px; background: #161b22; border-bottom: 1px solid #30363d; display: flex; align-items: center; justify-content: space-between; height: ${height}px; z-index: 100; }`;
|
|
14
|
+
}
|
|
15
|
+
function panelsCSS(headerHeight = 45) {
|
|
16
|
+
return `#panels { display: flex; flex-direction: column; height: calc(100vh - ${headerHeight}px); width: 100vw; }`;
|
|
17
|
+
}
|
|
18
|
+
function uplotBgCSS() {
|
|
19
|
+
return `.uplot { background: #0b0e14; }`;
|
|
20
|
+
}
|
|
21
|
+
function dotCSS() {
|
|
22
|
+
return `.dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }`;
|
|
23
|
+
}
|
|
24
|
+
function cursorCSS() {
|
|
25
|
+
return `.u-cursor-x { border-left: 1px dashed rgba(255,255,255,0.3) !important; }
|
|
26
|
+
.u-cursor-y { border-top: 1px dashed rgba(255,255,255,0.3) !important; display: none; }
|
|
27
|
+
.is-hovered .u-cursor-y { display: block; }`;
|
|
28
|
+
}
|
|
29
|
+
function sectionLabelCSS() {
|
|
30
|
+
return `.section-label { position: absolute; top: 8px; right: 12px; font-size: 9px; color: #30363d; text-transform: uppercase; letter-spacing: 1px; z-index: 10; pointer-events: none; }`;
|
|
31
|
+
}
|
|
32
|
+
function legendCSS() {
|
|
33
|
+
return `.legend { position: absolute; top: 8px; left: 12px; font-size: 11px; pointer-events: none; z-index: 10; display: flex; gap: 14px; color: #adbac7; white-space: nowrap; align-items: center; }
|
|
34
|
+
.legend-item { display: flex; align-items: center; gap: 5px; }`;
|
|
35
|
+
}
|
|
36
|
+
function sharedChartCSS() {
|
|
37
|
+
return [
|
|
38
|
+
baseResetCSS(),
|
|
39
|
+
headerCSS(),
|
|
40
|
+
panelsCSS(),
|
|
41
|
+
uplotBgCSS(),
|
|
42
|
+
dotCSS(),
|
|
43
|
+
cursorCSS(),
|
|
44
|
+
sectionLabelCSS(),
|
|
45
|
+
legendCSS(),
|
|
46
|
+
].join('\n ');
|
|
47
|
+
}
|
|
48
|
+
export { baseResetCSS, headerCSS, panelsCSS, uplotBgCSS, dotCSS, cursorCSS, sectionLabelCSS, legendCSS, sharedChartCSS };
|
|
49
|
+
//# sourceMappingURL=chart_css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart_css.js","sourceRoot":"","sources":["../../analysis/chart_css.ts"],"names":[],"mappings":"AACA,YAAY,CAAC;AAEb;;;;;GAKG;AAEH,SAAS,YAAY;IACjB,OAAO;oIACyH,CAAC;AACrI,CAAC;AAED,SAAS,SAAS,CAAC,MAAM,GAAG,EAAE;IAC1B,OAAO,oKAAoK,MAAM,qBAAqB,CAAC;AAC3M,CAAC;AAED,SAAS,SAAS,CAAC,YAAY,GAAG,EAAE;IAChC,OAAO,yEAAyE,YAAY,sBAAsB,CAAC;AACvH,CAAC;AAED,SAAS,UAAU;IACf,OAAO,iCAAiC,CAAC;AAC7C,CAAC;AAED,SAAS,MAAM;IACX,OAAO,yEAAyE,CAAC;AACrF,CAAC;AAED,SAAS,SAAS;IACd,OAAO;;oDAEyC,CAAC;AACrD,CAAC;AAED,SAAS,eAAe;IACpB,OAAO,kLAAkL,CAAC;AAC9L,CAAC;AAED,SAAS,SAAS;IACd,OAAO;uEAC4D,CAAC;AACxE,CAAC;AAED,SAAS,cAAc;IACnB,OAAO;QACH,YAAY,EAAE;QACd,SAAS,EAAE;QACX,SAAS,EAAE;QACX,UAAU,EAAE;QACZ,MAAM,EAAE;QACR,SAAS,EAAE;QACX,eAAe,EAAE;QACjB,SAAS,EAAE;KACd,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACzB,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,SAAS,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared browser-side JavaScript helpers for uPlot chart generators.
|
|
3
|
+
*
|
|
4
|
+
* All functions return raw JS code strings for interpolation into inline
|
|
5
|
+
* `<script>` template literals. Consumers embed these alongside their own
|
|
6
|
+
* chart-specific logic.
|
|
7
|
+
*/
|
|
8
|
+
declare const Y_AXIS_SIZE = 58;
|
|
9
|
+
/**
|
|
10
|
+
* Return the uPlot cursor config object literal.
|
|
11
|
+
* Consumers must define `SYNC_KEY` before calling this.
|
|
12
|
+
*/
|
|
13
|
+
declare function makeCursorConfig(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Return the `bindHoverState(chart)` function definition.
|
|
16
|
+
*/
|
|
17
|
+
declare function bindHoverStateFn(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Return the `fmtDate(ts)` browser-side function definition.
|
|
20
|
+
*/
|
|
21
|
+
declare function fmtDateFn(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Return the chart event wiring loop that binds mousemove, mouseleave,
|
|
24
|
+
* hover-state, wheelZoom, and pan on each chart.
|
|
25
|
+
*
|
|
26
|
+
* @param chartsVar JS variable name holding the charts array (e.g. `'charts'`)
|
|
27
|
+
* @param updateFn name of the legend update function (e.g. `'updateLegend'`)
|
|
28
|
+
* @param fallback expression for the mouseleave fallback index
|
|
29
|
+
* (e.g. `'lastLiveIdx'`, `'null'`, or `'shiftChart.cursor.idx ?? data.realBarCount - 1'`)
|
|
30
|
+
*/
|
|
31
|
+
declare function wireChartEvents(chartsVar: string, updateFn: string, fallback: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Return the Ctrl+0 zoom-reset keyboard shortcut handler.
|
|
34
|
+
* Consumers must define `xMin`, `xMax`, and `syncXRange` before calling this.
|
|
35
|
+
*/
|
|
36
|
+
declare function zoomResetScript(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Return the `sizeCharts()` function definition.
|
|
39
|
+
*
|
|
40
|
+
* @param pairs array of [chartVariableName, panelDomId] pairs
|
|
41
|
+
* e.g. `[['priceChart', 'price-panel'], ['kalmanChart', 'kalman-panel']]`
|
|
42
|
+
*/
|
|
43
|
+
declare function sizeChartsFn(pairs: Array<[string, string]>): string;
|
|
44
|
+
export { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, fmtDateFn, wireChartEvents, zoomResetScript, sizeChartsFn };
|
|
45
|
+
//# sourceMappingURL=chart_ui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart_ui.d.ts","sourceRoot":"","sources":["../../analysis/chart_ui.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AAEH,QAAA,MAAM,WAAW,KAAK,CAAC;AAEvB;;;GAGG;AACH,iBAAS,gBAAgB,IAAI,MAAM,CAUlC;AAED;;GAEG;AACH,iBAAS,gBAAgB,IAAI,MAAM,CAMlC;AAED;;GAEG;AACH,iBAAS,SAAS,IAAI,MAAM,CAO3B;AAED;;;;;;;;GAQG;AACH,iBAAS,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CActF;AAED;;;GAGG;AACH,iBAAS,eAAe,IAAI,MAAM,CAIjC;AAED;;;;;GAKG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAU5D;AAED,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Shared browser-side JavaScript helpers for uPlot chart generators.
|
|
4
|
+
*
|
|
5
|
+
* All functions return raw JS code strings for interpolation into inline
|
|
6
|
+
* `<script>` template literals. Consumers embed these alongside their own
|
|
7
|
+
* chart-specific logic.
|
|
8
|
+
*/
|
|
9
|
+
const Y_AXIS_SIZE = 58;
|
|
10
|
+
/**
|
|
11
|
+
* Return the uPlot cursor config object literal.
|
|
12
|
+
* Consumers must define `SYNC_KEY` before calling this.
|
|
13
|
+
*/
|
|
14
|
+
function makeCursorConfig() {
|
|
15
|
+
return `{
|
|
16
|
+
show: true,
|
|
17
|
+
x: true,
|
|
18
|
+
y: true,
|
|
19
|
+
points: { show: false },
|
|
20
|
+
drag: { x: false, y: false, setScale: false },
|
|
21
|
+
sync: { key: SYNC_KEY, setSeries: false, scales: ['x', null] },
|
|
22
|
+
focus: { prox: -1 },
|
|
23
|
+
}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Return the `bindHoverState(chart)` function definition.
|
|
27
|
+
*/
|
|
28
|
+
function bindHoverStateFn() {
|
|
29
|
+
return `function bindHoverState(chart) {
|
|
30
|
+
const root = chart.root;
|
|
31
|
+
root.addEventListener('mouseenter', () => root.classList.add('is-hovered'));
|
|
32
|
+
root.addEventListener('mouseleave', () => root.classList.remove('is-hovered'));
|
|
33
|
+
}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Return the `fmtDate(ts)` browser-side function definition.
|
|
37
|
+
*/
|
|
38
|
+
function fmtDateFn() {
|
|
39
|
+
return `function fmtDate(ts) {
|
|
40
|
+
if (ts == null) return '-';
|
|
41
|
+
const d = new Date(ts * 1000);
|
|
42
|
+
return d.toLocaleDateString('en-GB', { day: '2-digit', month: 'short', year: '2-digit' })
|
|
43
|
+
+ ' ' + d.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' });
|
|
44
|
+
}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Return the chart event wiring loop that binds mousemove, mouseleave,
|
|
48
|
+
* hover-state, wheelZoom, and pan on each chart.
|
|
49
|
+
*
|
|
50
|
+
* @param chartsVar JS variable name holding the charts array (e.g. `'charts'`)
|
|
51
|
+
* @param updateFn name of the legend update function (e.g. `'updateLegend'`)
|
|
52
|
+
* @param fallback expression for the mouseleave fallback index
|
|
53
|
+
* (e.g. `'lastLiveIdx'`, `'null'`, or `'shiftChart.cursor.idx ?? data.realBarCount - 1'`)
|
|
54
|
+
*/
|
|
55
|
+
function wireChartEvents(chartsVar, updateFn, fallback) {
|
|
56
|
+
return `let leavePending = null;
|
|
57
|
+
${chartsVar}.forEach(chart => {
|
|
58
|
+
chart.over.addEventListener('mousemove', () => {
|
|
59
|
+
if (leavePending !== null) { clearTimeout(leavePending); leavePending = null; }
|
|
60
|
+
${updateFn}(chart.cursor.idx);
|
|
61
|
+
});
|
|
62
|
+
chart.over.addEventListener('mouseleave', () => {
|
|
63
|
+
leavePending = setTimeout(() => { leavePending = null; ${updateFn}(${fallback}); }, 60);
|
|
64
|
+
});
|
|
65
|
+
bindHoverState(chart);
|
|
66
|
+
bindWheelZoom(chart);
|
|
67
|
+
bindPan(chart);
|
|
68
|
+
});`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Return the Ctrl+0 zoom-reset keyboard shortcut handler.
|
|
72
|
+
* Consumers must define `xMin`, `xMax`, and `syncXRange` before calling this.
|
|
73
|
+
*/
|
|
74
|
+
function zoomResetScript() {
|
|
75
|
+
return `window.addEventListener('keydown', (e) => {
|
|
76
|
+
if ((e.ctrlKey || e.metaKey) && e.key === '0') syncXRange(xMin, xMax);
|
|
77
|
+
});`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Return the `sizeCharts()` function definition.
|
|
81
|
+
*
|
|
82
|
+
* @param pairs array of [chartVariableName, panelDomId] pairs
|
|
83
|
+
* e.g. `[['priceChart', 'price-panel'], ['kalmanChart', 'kalman-panel']]`
|
|
84
|
+
*/
|
|
85
|
+
function sizeChartsFn(pairs) {
|
|
86
|
+
const entries = pairs.map(([chartVar, panelId]) => `[${chartVar}, '${panelId}']`).join(', ');
|
|
87
|
+
const nullCheck = pairs.map(([chartVar]) => `!${chartVar}`).join(' || ');
|
|
88
|
+
return `function sizeCharts() {
|
|
89
|
+
if (${nullCheck}) return;
|
|
90
|
+
[${entries}].forEach(([chart, id]) => {
|
|
91
|
+
const el = document.getElementById(id);
|
|
92
|
+
chart.setSize({ width: el.offsetWidth, height: el.offsetHeight });
|
|
93
|
+
});
|
|
94
|
+
}`;
|
|
95
|
+
}
|
|
96
|
+
export { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, fmtDateFn, wireChartEvents, zoomResetScript, sizeChartsFn };
|
|
97
|
+
//# sourceMappingURL=chart_ui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart_ui.js","sourceRoot":"","sources":["../../analysis/chart_ui.ts"],"names":[],"mappings":"AACA,YAAY,CAAC;AAEb;;;;;;GAMG;AAEH,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;GAGG;AACH,SAAS,gBAAgB;IACrB,OAAO;;;;;;;;UAQD,CAAC;AACX,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB;IACrB,OAAO;;;;UAID,CAAC;AACX,CAAC;AAED;;GAEG;AACH,SAAS,SAAS;IACd,OAAO;;;;;UAKD,CAAC;AACX,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,SAAiB,EAAE,QAAgB,EAAE,QAAgB;IAC1E,OAAO;cACG,SAAS;;;sBAGD,QAAQ;;;6EAG+C,QAAQ,IAAI,QAAQ;;;;;gBAKjF,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,SAAS,eAAe;IACpB,OAAO;;YAEC,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,KAA8B;IAChD,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,IAAI,QAAQ,MAAM,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CA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