dexbot 1.4.19 → 1.4.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.
- package/CHANGELOG.md +36 -0
- package/README.md +22 -12
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +2 -2
- package/analysis/ama_fitting/calibrate_convergence_er.ts +1 -1
- package/analysis/ama_fitting/optimizer_high_resolution.ts +2 -1
- package/analysis/ama_fitting/package.json +1 -1
- package/analysis/analyze_derivatives.ts +4 -2
- package/analysis/analyze_dynamic_weight.ts +3 -1
- package/analysis/analyze_kalman.ts +3 -1
- package/analysis/analyze_regime.ts +3 -1
- package/analysis/analyze_regime_windows.ts +3 -1
- package/analysis/analyze_volatility.ts +2 -2
- package/analysis/bot_fitting/backtest_ama_sweep.ts +2 -1
- package/analysis/bot_fitting/backtest_bot_fitting.ts +17 -12
- package/analysis/bot_fitting/shared_utils.ts +1 -1
- package/analysis/bot_key_utils.ts +1 -5
- package/analysis/bot_usage/kibana_bot_queries.ts +1 -256
- package/analysis/chart_css.ts +1 -1
- package/analysis/chart_utils.ts +24 -0
- package/analysis/derivative_chart_generator.ts +3 -2
- package/analysis/math_utils.ts +1 -8
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +91 -55
- package/analysis/trend_detection/package.json +1 -1
- package/claw/ecosystem.config.cjs +2 -3
- package/claw/examples/claw_profiles_example.ts +4 -1
- package/claw/examples/memu_integration_example.ts +17 -17
- package/claw/modules/chain_actions.ts +51 -54
- package/claw/modules/chain_broadcast.ts +66 -104
- package/claw/modules/claw_bridge.ts +60 -80
- package/claw/modules/claw_catalog.ts +48 -17
- package/claw/modules/claw_infra.ts +1 -5
- package/claw/modules/claw_launcher.ts +47 -49
- package/claw/modules/claw_skill_md.ts +14 -16
- package/claw/modules/credit_runtime_adapter.ts +2 -18
- package/claw/modules/decision_loop.ts +4 -0
- package/claw/modules/dexbot_bridge.ts +1 -1
- package/claw/modules/dexbot_profiles.ts +8 -22
- package/claw/modules/honest_ecosystem.ts +24 -8
- package/claw/modules/launcher_paths.ts +4 -2
- package/claw/modules/liquidity_pools.ts +10 -3
- package/claw/modules/mcp_utils.ts +109 -0
- package/claw/modules/memu_bridge.ts +76 -54
- package/claw/modules/mpa_utils.ts +26 -3
- package/claw/modules/position_discovery.ts +16 -27
- package/claw/modules/position_manager.ts +32 -41
- package/claw/modules/position_manager_watch.ts +3 -2
- package/claw/modules/short_mpa_strategy.ts +1 -9
- package/claw/modules/skill_utils.ts +5 -3
- package/claw/modules/utils.ts +9 -1
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/index.ts +27 -10
- 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 +1 -1
- package/claw/scripts/claw_mcp_server.ts +19 -78
- package/claw/scripts/honest_assets_report.ts +19 -84
- package/claw/scripts/memu_mcp_server.ts +57 -155
- package/claw/tests/test_claw_bridge.ts +6 -2
- package/claw/tests/test_claw_mcp_transport.ts +2 -2
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -2
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +1 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +2 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -1
- package/dist/analysis/analyze_derivatives.d.ts.map +1 -1
- package/dist/analysis/analyze_derivatives.js +4 -2
- package/dist/analysis/analyze_derivatives.js.map +1 -1
- package/dist/analysis/analyze_dynamic_weight.js +3 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +1 -1
- package/dist/analysis/analyze_kalman.js +3 -1
- package/dist/analysis/analyze_kalman.js.map +1 -1
- package/dist/analysis/analyze_regime.js +3 -1
- package/dist/analysis/analyze_regime.js.map +1 -1
- package/dist/analysis/analyze_regime_windows.js +3 -1
- package/dist/analysis/analyze_regime_windows.js.map +1 -1
- package/dist/analysis/analyze_volatility.js +2 -2
- package/dist/analysis/analyze_volatility.js.map +1 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +2 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +18 -13
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts +1 -12
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -1
- package/dist/analysis/bot_fitting/shared_utils.js +1 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +1 -1
- package/dist/analysis/bot_key_utils.d.ts +1 -1
- package/dist/analysis/bot_key_utils.d.ts.map +1 -1
- package/dist/analysis/bot_key_utils.js +1 -5
- package/dist/analysis/bot_key_utils.js.map +1 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -337
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js +1 -241
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -1
- package/dist/analysis/chart_css.d.ts +1 -15
- package/dist/analysis/chart_css.d.ts.map +1 -1
- package/dist/analysis/chart_css.js +1 -1
- package/dist/analysis/chart_css.js.map +1 -1
- package/dist/analysis/chart_utils.d.ts +0 -3
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +25 -0
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/derivative_chart_generator.d.ts.map +1 -1
- package/dist/analysis/derivative_chart_generator.js +3 -2
- package/dist/analysis/derivative_chart_generator.js.map +1 -1
- package/dist/analysis/math_utils.d.ts +3 -5
- package/dist/analysis/math_utils.d.ts.map +1 -1
- package/dist/analysis/math_utils.js +3 -5
- package/dist/analysis/math_utils.js.map +1 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +82 -50
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -1
- package/dist/bot.js +2 -2
- package/dist/bot.js.map +1 -1
- package/dist/credential-daemon.js +1 -1
- package/dist/credential-daemon.js.map +1 -1
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +20 -17
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +3 -3
- package/dist/market_adapter/core/kibana_client.d.ts +1 -3
- package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_client.js +1 -1
- package/dist/market_adapter/core/kibana_client.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts +1 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +9 -4
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +1 -2
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.js +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -2
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +5 -5
- package/dist/market_adapter/inputs/fetch_lp_data.js +5 -5
- package/dist/market_adapter/inputs/kibana_source.d.ts +1 -2
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.js +1 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +1 -2
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js +4 -4
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
- package/dist/market_adapter/market_adapter.d.ts.map +1 -1
- package/dist/market_adapter/market_adapter.js +2 -1
- package/dist/market_adapter/market_adapter.js.map +1 -1
- package/dist/modules/account_bots.d.ts +3 -0
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +156 -46
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +1 -7
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +9 -17
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts +2 -14
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +22 -31
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.js +1 -1
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/chain_keys.js +2 -2
- package/dist/modules/chain_keys.js.map +1 -1
- package/dist/modules/chain_orders.d.ts +2 -3
- package/dist/modules/chain_orders.d.ts.map +1 -1
- package/dist/modules/chain_orders.js +8 -25
- package/dist/modules/chain_orders.js.map +1 -1
- package/dist/modules/config.d.ts +2 -0
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +6 -1
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +0 -1
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +1 -5
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/credential_policy.js +1 -1
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +3 -2
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +0 -7
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +95 -0
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
- package/dist/modules/dexbot_state_recovery.js +22 -2
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/fund_registry.d.ts.map +1 -1
- package/dist/modules/fund_registry.js +5 -2
- package/dist/modules/fund_registry.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +6 -7
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +6 -0
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts +2 -3
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js +7 -15
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +1 -0
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +1 -2
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +1 -4
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/order/accounting.js +2 -2
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/format.d.ts +0 -8
- package/dist/modules/order/format.d.ts.map +1 -1
- package/dist/modules/order/format.js +0 -8
- package/dist/modules/order/format.js.map +1 -1
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +146 -32
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/logger.js +1 -1
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/logger_state.d.ts +1 -13
- package/dist/modules/order/logger_state.d.ts.map +1 -1
- package/dist/modules/order/logger_state.js +1 -11
- package/dist/modules/order/logger_state.js.map +1 -1
- package/dist/modules/order/manager.d.ts +13 -0
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +75 -2
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/processed_fill_store.d.ts +0 -5
- package/dist/modules/order/processed_fill_store.d.ts.map +1 -1
- package/dist/modules/order/processed_fill_store.js +1 -12
- package/dist/modules/order/processed_fill_store.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +10 -3
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +80 -1
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +138 -2
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +10 -2
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/paths.d.ts +26 -1
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +39 -6
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/runtime_settings.js +3 -1
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/modules/settings_merge.d.ts.map +1 -1
- package/dist/modules/settings_merge.js +3 -1
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/storage/browser_adapter.d.ts +8 -3
- package/dist/modules/storage/browser_adapter.d.ts.map +1 -1
- package/dist/modules/storage/browser_adapter.js +53 -4
- package/dist/modules/storage/browser_adapter.js.map +1 -1
- package/dist/modules/utils/sanitize_key.d.ts +7 -0
- package/dist/modules/utils/sanitize_key.d.ts.map +1 -0
- package/dist/modules/utils/sanitize_key.js +15 -0
- package/dist/modules/utils/sanitize_key.js.map +1 -0
- package/dist/pm2.js +6 -6
- package/dist/pm2.js.map +1 -1
- package/dist/scripts/analyze-git.js +2 -1
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/analyze-orders.d.ts +2 -2
- package/dist/scripts/analyze-orders.d.ts.map +1 -1
- package/dist/scripts/analyze-orders.js +6 -14
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/runner.js +1 -1
- package/dist/scripts/runner.js.map +1 -1
- package/dist/scripts/update.js +1 -1
- package/dist/scripts/update.js.map +1 -1
- package/docs/BITSHARES_ONBOARDING.md +63 -18
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +5 -14
- package/docs/COW_INVARIANTS.md +4 -4
- package/docs/CREDENTIAL_SECURITY.md +0 -11
- package/docs/DEXBOT_COMPARISON.md +11 -11
- package/docs/EVOLUTION.md +12 -10
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +27 -83
- package/docs/GRID_RECALCULATION.md +1 -13
- package/docs/GRID_RECONCILE.md +24 -24
- package/docs/LIFECYCLE.md +4 -4
- package/docs/LOGGING.md +1 -1
- package/docs/MPA_CREDIT_USAGE.md +3 -3
- package/docs/README.md +2 -2
- package/docs/WORKFLOW.md +2 -2
- package/docs/architecture.md +43 -38
- package/docs/developer_guide.md +16 -18
- package/market_adapter/README.md +0 -2
- package/modules/README.md +2 -1
- package/package.json +2 -3
- package/scripts/README.md +1 -1
- package/scripts/lib/dexbot-paths.sh +20 -11
- package/claw/openclaw.plugin.json +0 -13
- package/dist/market_adapter/merge_lp_data.d.ts +0 -3
- package/dist/market_adapter/merge_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/merge_lp_data.js +0 -125
- package/dist/market_adapter/merge_lp_data.js.map +0 -1
- package/dist/market_adapter/utils/paths.d.ts +0 -3
- package/dist/market_adapter/utils/paths.d.ts.map +0 -1
- package/dist/market_adapter/utils/paths.js +0 -5
- package/dist/market_adapter/utils/paths.js.map +0 -1
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
import { toIntervalLabel } from '../../market_adapter/interval_utils.js';
|
|
38
37
|
import { kibanaSearch, DEFAULT_CONFIG as BASE_CONFIG } from '../../market_adapter/core/kibana_client.js';
|
|
39
38
|
'use strict';
|
|
40
39
|
|
|
@@ -49,159 +48,6 @@ const DEFAULT_CONFIG = {
|
|
|
49
48
|
timeout: 25000,
|
|
50
49
|
};
|
|
51
50
|
|
|
52
|
-
// ─── Aggregation query builders (size:0, for counts & timelines) ───────────────
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Time-bucketed count of limit_order_create ops for an account.
|
|
56
|
-
* Optionally filtered to orders selling a specific asset.
|
|
57
|
-
*/
|
|
58
|
-
function buildOrderCreateQuery(accountId: string, lookbackHours: number, intervalSeconds: number = 3600, sellAssetId: string | null = null) {
|
|
59
|
-
const filters = [
|
|
60
|
-
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
61
|
-
{ term: { 'operation_history.op_object.seller.keyword': accountId } },
|
|
62
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
63
|
-
];
|
|
64
|
-
if (sellAssetId) {
|
|
65
|
-
filters.push({ term: { 'operation_history.op_object.amount_to_sell.asset_id.keyword': sellAssetId } } as any);
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
size: 0,
|
|
69
|
-
query: { bool: { filter: filters } },
|
|
70
|
-
aggs: {
|
|
71
|
-
by_time: {
|
|
72
|
-
date_histogram: {
|
|
73
|
-
field: 'block_data.block_time',
|
|
74
|
-
fixed_interval: toIntervalLabel(intervalSeconds),
|
|
75
|
-
min_doc_count: 1,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
total: { value_count: { field: 'operation_type' } },
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Time-bucketed count of fill_order ops for an account.
|
|
85
|
-
* Optionally filtered to fills where account pays a specific asset.
|
|
86
|
-
*/
|
|
87
|
-
function buildFillOrderQuery(accountId: string, lookbackHours: number, intervalSeconds: number = 3600, paysAssetId: string | null = null) {
|
|
88
|
-
const filters = [
|
|
89
|
-
{ term: { operation_type: OP_FILL_ORDER } },
|
|
90
|
-
{ term: { 'operation_history.op_object.account_id.keyword': accountId } },
|
|
91
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
92
|
-
];
|
|
93
|
-
if (paysAssetId) {
|
|
94
|
-
filters.push({ term: { 'operation_history.op_object.pays.asset_id.keyword': paysAssetId } } as any);
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
size: 0,
|
|
98
|
-
query: { bool: { filter: filters } },
|
|
99
|
-
aggs: {
|
|
100
|
-
by_time: {
|
|
101
|
-
date_histogram: {
|
|
102
|
-
field: 'block_data.block_time',
|
|
103
|
-
fixed_interval: toIntervalLabel(intervalSeconds),
|
|
104
|
-
min_doc_count: 1,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
total: { value_count: { field: 'operation_type' } },
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Time-bucketed count of limit_order_cancel ops for an account.
|
|
114
|
-
*/
|
|
115
|
-
function buildOrderCancelQuery(accountId: string, lookbackHours: number, intervalSeconds: number = 3600) {
|
|
116
|
-
return {
|
|
117
|
-
size: 0,
|
|
118
|
-
query: {
|
|
119
|
-
bool: {
|
|
120
|
-
filter: [
|
|
121
|
-
{ term: { operation_type: OP_LIMIT_ORDER_CANCEL } },
|
|
122
|
-
{ term: { 'operation_history.op_object.fee_paying_account.keyword': accountId } },
|
|
123
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
124
|
-
],
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
aggs: {
|
|
128
|
-
by_time: {
|
|
129
|
-
date_histogram: {
|
|
130
|
-
field: 'block_data.block_time',
|
|
131
|
-
fixed_interval: toIntervalLabel(intervalSeconds),
|
|
132
|
-
min_doc_count: 1,
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
total: { value_count: { field: 'operation_type' } },
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Daily activity breakdown by operation type for an account.
|
|
142
|
-
* Merges creates (by seller), fills (by account_id), cancels (by fee_paying_account)
|
|
143
|
-
* into one aggregation using a filter per op type.
|
|
144
|
-
*/
|
|
145
|
-
function buildDailyActivityQuery(accountId: string, lookbackHours: number) {
|
|
146
|
-
return {
|
|
147
|
-
size: 0,
|
|
148
|
-
query: {
|
|
149
|
-
bool: {
|
|
150
|
-
filter: [
|
|
151
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
152
|
-
],
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
aggs: {
|
|
156
|
-
creates: {
|
|
157
|
-
filter: {
|
|
158
|
-
bool: {
|
|
159
|
-
filter: [
|
|
160
|
-
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
161
|
-
{ term: { 'operation_history.op_object.seller.keyword': accountId } },
|
|
162
|
-
],
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
aggs: {
|
|
166
|
-
by_day: {
|
|
167
|
-
date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
fills: {
|
|
172
|
-
filter: {
|
|
173
|
-
bool: {
|
|
174
|
-
filter: [
|
|
175
|
-
{ term: { operation_type: OP_FILL_ORDER } },
|
|
176
|
-
{ term: { 'operation_history.op_object.account_id.keyword': accountId } },
|
|
177
|
-
],
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
aggs: {
|
|
181
|
-
by_day: {
|
|
182
|
-
date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
cancels: {
|
|
187
|
-
filter: {
|
|
188
|
-
bool: {
|
|
189
|
-
filter: [
|
|
190
|
-
{ term: { operation_type: OP_LIMIT_ORDER_CANCEL } },
|
|
191
|
-
{ term: { 'operation_history.op_object.fee_paying_account.keyword': accountId } },
|
|
192
|
-
],
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
aggs: {
|
|
196
|
-
by_day: {
|
|
197
|
-
date_histogram: { field: 'block_data.block_time', fixed_interval: '1d', min_doc_count: 1 },
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
51
|
// ─── Raw document query builders (size>0, for price/grid analysis) ────────────
|
|
206
52
|
|
|
207
53
|
/**
|
|
@@ -236,107 +82,6 @@ function buildOrderPriceQuery(accountId: string, lookbackHours: number, sellAsse
|
|
|
236
82
|
};
|
|
237
83
|
}
|
|
238
84
|
|
|
239
|
-
/**
|
|
240
|
-
* Fetch raw fill_order documents for fill-price analysis.
|
|
241
|
-
*
|
|
242
|
-
* @param {string} accountId
|
|
243
|
-
* @param {number} lookbackHours
|
|
244
|
-
* @param {string} [paysAssetId]
|
|
245
|
-
* @param {number} [maxResults]
|
|
246
|
-
* @returns {Object} Elasticsearch query object
|
|
247
|
-
*/
|
|
248
|
-
function buildFillPriceQuery(accountId: string, lookbackHours: number, paysAssetId: string | null = null, maxResults: number = 500) {
|
|
249
|
-
const filters = [
|
|
250
|
-
{ term: { operation_type: OP_FILL_ORDER } },
|
|
251
|
-
{ term: { 'operation_history.op_object.account_id.keyword': accountId } },
|
|
252
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
253
|
-
];
|
|
254
|
-
if (paysAssetId) {
|
|
255
|
-
filters.push({ term: { 'operation_history.op_object.pays.asset_id.keyword': paysAssetId } } as any);
|
|
256
|
-
}
|
|
257
|
-
return {
|
|
258
|
-
size: maxResults,
|
|
259
|
-
_source: [
|
|
260
|
-
'block_data.block_time',
|
|
261
|
-
'operation_history.op_object.pays',
|
|
262
|
-
'operation_history.op_object.receives',
|
|
263
|
-
'operation_history.op_object.order_id',
|
|
264
|
-
],
|
|
265
|
-
query: { bool: { filter: filters } },
|
|
266
|
-
sort: [{ 'block_data.block_time': { order: 'desc' } }],
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Discover which asset pairs an account trades by aggregating the sell asset IDs.
|
|
272
|
-
* Returns top asset IDs by order count.
|
|
273
|
-
*/
|
|
274
|
-
function buildAssetDiscoveryQuery(accountId: string, lookbackHours: number) {
|
|
275
|
-
return {
|
|
276
|
-
size: 0,
|
|
277
|
-
query: {
|
|
278
|
-
bool: {
|
|
279
|
-
filter: [
|
|
280
|
-
{ term: { operation_type: OP_LIMIT_ORDER_CREATE } },
|
|
281
|
-
{ term: { 'operation_history.op_object.seller.keyword': accountId } },
|
|
282
|
-
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
283
|
-
],
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
aggs: {
|
|
287
|
-
sell_assets: {
|
|
288
|
-
terms: {
|
|
289
|
-
field: 'operation_history.op_object.amount_to_sell.asset_id.keyword',
|
|
290
|
-
size: 10,
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
recv_assets: {
|
|
294
|
-
terms: {
|
|
295
|
-
field: 'operation_history.op_object.min_to_receive.asset_id.keyword',
|
|
296
|
-
size: 10,
|
|
297
|
-
},
|
|
298
|
-
},
|
|
299
|
-
},
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// ─── Fetch helpers ────────────────────────────────────────────────────────────
|
|
304
|
-
|
|
305
|
-
async function fetchOrderCreate(accountId: string, lookbackHours: number, config: any = {}, sellAssetId: string | null = null, intervalSeconds: number = 3600) {
|
|
306
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
307
|
-
return kibanaSearch(cfg, buildOrderCreateQuery(accountId, lookbackHours, intervalSeconds, sellAssetId));
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
async function fetchFillOrder(accountId: string, lookbackHours: number, config: any = {}, paysAssetId: string | null = null, intervalSeconds: number = 3600) {
|
|
311
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
312
|
-
return kibanaSearch(cfg, buildFillOrderQuery(accountId, lookbackHours, intervalSeconds, paysAssetId));
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async function fetchOrderCancel(accountId: string, lookbackHours: number, config: any = {}, intervalSeconds: number = 3600) {
|
|
316
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
317
|
-
return kibanaSearch(cfg, buildOrderCancelQuery(accountId, lookbackHours, intervalSeconds));
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
async function fetchOrderPrices(accountId: string, lookbackHours: number, config: any = {}, sellAssetId: string | null = null, maxResults: number = 1000) {
|
|
321
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
322
|
-
return kibanaSearch(cfg, buildOrderPriceQuery(accountId, lookbackHours, sellAssetId, maxResults));
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
async function fetchFillPrices(accountId: string, lookbackHours: number, config: any = {}, paysAssetId: string | null = null, maxResults: number = 500) {
|
|
326
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
327
|
-
return kibanaSearch(cfg, buildFillPriceQuery(accountId, lookbackHours, paysAssetId, maxResults));
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
async function fetchDailyActivity(accountId: string, lookbackHours: number, config: any = {}) {
|
|
331
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
332
|
-
return kibanaSearch(cfg, buildDailyActivityQuery(accountId, lookbackHours));
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
async function fetchAssetDiscovery(accountId: string, lookbackHours: number, config: any = {}) {
|
|
336
|
-
const cfg = { ...DEFAULT_CONFIG, ...config };
|
|
337
|
-
return kibanaSearch(cfg, buildAssetDiscoveryQuery(accountId, lookbackHours));
|
|
338
|
-
}
|
|
339
|
-
|
|
340
85
|
// ─── Discovery query builders ─────────────────────────────────────────────────
|
|
341
86
|
|
|
342
87
|
/**
|
|
@@ -423,5 +168,5 @@ function buildTopFilledAccountsQuery(lookbackHours: number, topN: number = 100,
|
|
|
423
168
|
|
|
424
169
|
// ─── Exports ──────────────────────────────────────────────────────────────────
|
|
425
170
|
|
|
426
|
-
export {
|
|
171
|
+
export { DEFAULT_CONFIG, kibanaSearch, buildOrderPriceQuery, buildTopSellerAccountsQuery, buildTopCancellerAccountsQuery, buildTopFilledAccountsQuery }
|
|
427
172
|
|
package/analysis/chart_css.ts
CHANGED
package/analysis/chart_utils.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { getStorage } from '../modules/storage/index.js';
|
|
5
|
+
import { PATHS } from '../modules/paths.js';
|
|
5
6
|
const { ensureDir } = getStorage();
|
|
6
7
|
'use strict';
|
|
7
8
|
|
|
@@ -9,6 +10,28 @@ const { ensureDir } = getStorage();
|
|
|
9
10
|
* Chart utilities for analysis HTML generators.
|
|
10
11
|
*/
|
|
11
12
|
|
|
13
|
+
// Runtime assets every generated chart references as ../uplot/* relative to
|
|
14
|
+
// its own directory (charts live in <root>/charts, assets in <root>/uplot).
|
|
15
|
+
const UPLOT_RUNTIME_FILES = ['uPlot.iife.min.js', 'uPlot.min.css'];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Generated HTML loads uPlot from a sibling `uplot/` dir next to the charts
|
|
19
|
+
* dir. In a source checkout that dir is the vendored original; anywhere else
|
|
20
|
+
* (relocated analysis root under npm/home profiles, or a custom --chart path)
|
|
21
|
+
* materialize a copy so the relative refs keep resolving.
|
|
22
|
+
*/
|
|
23
|
+
function ensureSiblingUplotAssets(chartDir: any) {
|
|
24
|
+
const targetDir = path.join(path.dirname(path.resolve(chartDir)), 'uplot');
|
|
25
|
+
const sourceDir = PATHS.ANALYSIS.ASSETS_DIR;
|
|
26
|
+
if (targetDir === path.resolve(sourceDir)) return;
|
|
27
|
+
if (UPLOT_RUNTIME_FILES.every((f) => fs.existsSync(path.join(targetDir, f)))) return;
|
|
28
|
+
if (!fs.existsSync(sourceDir)) return;
|
|
29
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
30
|
+
for (const f of UPLOT_RUNTIME_FILES) {
|
|
31
|
+
fs.copyFileSync(path.join(sourceDir, f), path.join(targetDir, f));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
12
35
|
|
|
13
36
|
function escapeHtml(str: string) {
|
|
14
37
|
const map: Record<string, string> = {
|
|
@@ -34,6 +57,7 @@ function toEpochSeconds(ts: any, fallbackIdx: any) {
|
|
|
34
57
|
function writeChartFile(filePath: any, html: any) {
|
|
35
58
|
const chartDir = path.dirname(filePath);
|
|
36
59
|
if (!fs.existsSync(chartDir)) ensureDir(chartDir);
|
|
60
|
+
ensureSiblingUplotAssets(chartDir);
|
|
37
61
|
fs.writeFileSync(filePath, html, 'utf8');
|
|
38
62
|
}
|
|
39
63
|
|
|
@@ -8,11 +8,12 @@ import { getStorage } from '../modules/storage/index.js';
|
|
|
8
8
|
const { ensureDir, readJSON } = getStorage();
|
|
9
9
|
import { fixedTo } from '../modules/order/utils/math.js';
|
|
10
10
|
import { bindHoverStateFn, zoomResetScript } from './chart_ui.js';
|
|
11
|
+
import { PATHS } from '../modules/paths.js';
|
|
11
12
|
'use strict';
|
|
12
13
|
function parseArgs(argv = process.argv.slice(2)) {
|
|
13
14
|
const cfg: { inputFile: string | null; outputFile: string; title: string; quiet: boolean } = {
|
|
14
15
|
inputFile: null,
|
|
15
|
-
outputFile: '
|
|
16
|
+
outputFile: path.join(PATHS.ANALYSIS.CHARTS_DIR, 'derivative_chart.html'),
|
|
16
17
|
title: 'Derivative Trend Analysis',
|
|
17
18
|
quiet: false,
|
|
18
19
|
};
|
|
@@ -40,7 +41,7 @@ Derivative Chart Generator (uPlot)
|
|
|
40
41
|
Usage:
|
|
41
42
|
tsx analysis/derivative_chart_generator.ts --input <file.json> [options]
|
|
42
43
|
Options:
|
|
43
|
-
--output FILE Output HTML (default: analysis
|
|
44
|
+
--output FILE Output HTML (default: <analysis charts dir>/derivative_chart.html)
|
|
44
45
|
--title TEXT Chart title
|
|
45
46
|
--quiet Suppress output
|
|
46
47
|
`);
|
package/analysis/math_utils.ts
CHANGED
|
@@ -5,19 +5,15 @@ import { getStorage } from '../modules/storage/index.js';
|
|
|
5
5
|
const { readJSON } = getStorage();
|
|
6
6
|
import {
|
|
7
7
|
getCandleClose,
|
|
8
|
-
getCandleHigh,
|
|
9
|
-
getCandleLow,
|
|
10
8
|
getCandleTimestamp,
|
|
11
9
|
normalizeCandle,
|
|
12
10
|
} from '../market_adapter/candle_utils.js';
|
|
13
|
-
import { computeATRSeries } from '../market_adapter/core/strategies/atr/calculator.js';
|
|
14
11
|
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* Math utilities for analysis scripts.
|
|
18
15
|
*
|
|
19
|
-
* Candle accessors
|
|
20
|
-
* market_adapter (candle_utils.ts / strategies/atr/calculator.ts) and
|
|
16
|
+
* Candle accessors are centralized in market_adapter (candle_utils.ts) and
|
|
21
17
|
* re-exported here so analysis tooling shares one logic path with the
|
|
22
18
|
* live adapter and the browser-embedded chart scripts.
|
|
23
19
|
*/
|
|
@@ -50,10 +46,7 @@ function loadCandleFile(filePath: any) {
|
|
|
50
46
|
export {
|
|
51
47
|
range,
|
|
52
48
|
calcStdDev,
|
|
53
|
-
computeATRSeries,
|
|
54
49
|
getCandleClose,
|
|
55
|
-
getCandleHigh,
|
|
56
|
-
getCandleLow,
|
|
57
50
|
getCandleTimestamp,
|
|
58
51
|
normalizeCandle,
|
|
59
52
|
loadCandleFile,
|
|
@@ -160,7 +160,7 @@ All panels share aligned vertical time grid lines, and the bottom output panel s
|
|
|
160
160
|
| **nz%** | 0–1 | 0.00 | Neutral zone: dead-band below which offset is forced to 0 |
|
|
161
161
|
| **lb** | 1–32 | 9 | Logarithmic. Lookback bars for AMA slope calculation |
|
|
162
162
|
| **amaS%** | 0.04–0.12 | 0.085 | Logarithmic. Gear ratio for average per-bar AMA slope saturation |
|
|
163
|
-
| **kalS%** | 0.
|
|
163
|
+
| **kalS%** | 0.5–1.5 | 1.0 | Logarithmic. Gear ratio for Kalman composite saturation |
|
|
164
164
|
| **clip%** | 0–55 | 10 | Percentile clip: filters extreme inputs (0 = off) |
|
|
165
165
|
|
|
166
166
|
### Output Controls
|