dexbot 1.6.6 → 1.6.8
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 +89 -1
- package/README.md +8 -5
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- 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/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +44 -15
- package/dist/market_adapter/core/market_adapter_service.js +14 -2
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/market_adapter.d.ts +8 -1
- package/dist/market_adapter/market_adapter.js +22 -4
- package/dist/modules/account_bots.js +20 -9
- package/dist/modules/account_orders.d.ts +44 -4
- package/dist/modules/account_orders.js +104 -7
- package/dist/modules/bitshares-native/chain_client.d.ts +10 -0
- package/dist/modules/bitshares-native/chain_client.js +197 -28
- package/dist/modules/bitshares-native/subscriptions.js +312 -10
- package/dist/modules/bitshares-native/transport.d.ts +1 -0
- package/dist/modules/bitshares-native/transport.js +97 -3
- package/dist/modules/bitshares_client.d.ts +20 -0
- package/dist/modules/bitshares_client.js +29 -0
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/chain_keys.d.ts +37 -22
- package/dist/modules/chain_keys.js +145 -44
- package/dist/modules/cli_start_onboarding.d.ts +10 -0
- package/dist/modules/cli_start_onboarding.js +15 -0
- package/dist/modules/cli_start_output.d.ts +6 -0
- package/dist/modules/cli_start_output.js +8 -0
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.js +1 -0
- package/dist/modules/constants.d.ts +23 -2
- package/dist/modules/constants.js +196 -15
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +53 -96
- package/dist/modules/dexbot_fill_runtime.d.ts +6 -1
- package/dist/modules/dexbot_fill_runtime.js +22 -3
- package/dist/modules/dexbot_maintenance_runtime.d.ts +38 -1
- package/dist/modules/dexbot_maintenance_runtime.js +103 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +34 -1
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +109 -135
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +13 -2
- package/dist/modules/order/logger.d.ts +12 -2
- package/dist/modules/order/logger.js +29 -7
- package/dist/modules/order/manager.d.ts +53 -0
- package/dist/modules/order/manager.js +86 -25
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +302 -194
- package/dist/modules/order/utils/system.d.ts +97 -0
- package/dist/modules/order/utils/system.js +282 -3
- package/dist/modules/paths.d.ts +8 -1
- package/dist/modules/paths.js +11 -3
- package/dist/modules/utils/text_width.d.ts +19 -0
- package/dist/modules/utils/text_width.js +97 -0
- package/dist/modules/version_notice.d.ts +165 -0
- package/dist/modules/version_notice.js +364 -0
- package/dist/pm2.js +104 -18
- package/dist/scripts/update.js +62 -13
- package/dist/unlock.d.ts +14 -2
- package/dist/unlock.js +101 -4
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +11 -2
- package/docs/CREDENTIAL_SECURITY.md +26 -0
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +20 -18
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +204 -31
- package/docs/GRID_RECALCULATION.md +12 -0
- package/docs/LOGGING.md +17 -2
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +6 -7
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +1 -1
- package/modules/README.md +18 -1
- package/package.json +14 -6
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
/**
|
|
4
|
-
* TRADE HEATMAP ANALYZER
|
|
5
|
-
*
|
|
6
|
-
* Generates an HTML heatmap showing where trade volume concentrates relative
|
|
7
|
-
* to AMA deviation. Produces a 2D grid (time slices × deviation buckets) and
|
|
8
|
-
* a summed volume histogram with threshold annotations.
|
|
9
|
-
*
|
|
10
|
-
* Usage:
|
|
11
|
-
* node dist/analysis/analyze_trade_heatmap.js --source market_adapter --bot-key <key> [options]
|
|
12
|
-
* node dist/analysis/analyze_trade_heatmap.js --file <path> [options]
|
|
13
|
-
*
|
|
14
|
-
* Output:
|
|
15
|
-
* Self-contained HTML file with inline CSS (no JS dependencies).
|
|
16
|
-
*/
|
|
17
|
-
import path from 'node:path';
|
|
18
|
-
import { calculateAMA } from '../market_adapter/core/strategies/ama.js';
|
|
19
|
-
import { MARKET_ADAPTER } from '../modules/constants.js';
|
|
20
|
-
import { calcStdDev, getCandleClose } from './math_utils.js';
|
|
21
|
-
import { writeChartFile } from './chart_utils.js';
|
|
22
|
-
import { resolveSource, listAvailableBots, type SourceConfig } from './resolve_source.js';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function parseArgs() {
|
|
26
|
-
const args = process.argv.slice(2);
|
|
27
|
-
const config: {
|
|
28
|
-
source: { type: string; config: SourceConfig };
|
|
29
|
-
ama: string;
|
|
30
|
-
output: string;
|
|
31
|
-
buckets: number | null;
|
|
32
|
-
maxNeg: number | null;
|
|
33
|
-
maxPos: number | null;
|
|
34
|
-
warmup: number | null;
|
|
35
|
-
binSize: number;
|
|
36
|
-
sliceMonths: number;
|
|
37
|
-
thresholds: number[];
|
|
38
|
-
quiet: boolean;
|
|
39
|
-
listBots: boolean;
|
|
40
|
-
} = {
|
|
41
|
-
source: { type: 'market_adapter', config: { botKey: '' } },
|
|
42
|
-
ama: 'AMA3',
|
|
43
|
-
output: 'analysis/charts/trade_heatmap.html',
|
|
44
|
-
buckets: null,
|
|
45
|
-
maxNeg: null,
|
|
46
|
-
maxPos: null,
|
|
47
|
-
warmup: null,
|
|
48
|
-
binSize: 5,
|
|
49
|
-
sliceMonths: 12,
|
|
50
|
-
thresholds: [1, 2, 3, 5, 10, 20],
|
|
51
|
-
quiet: false,
|
|
52
|
-
listBots: false,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
for (let i = 0; i < args.length; i++) {
|
|
56
|
-
const arg = args[i];
|
|
57
|
-
if (arg === '--source') config.source.type = args[++i];
|
|
58
|
-
else if (arg === '--bot-key') config.source.config.botKey = args[++i];
|
|
59
|
-
else if (arg === '--file') {
|
|
60
|
-
config.source.config.filePath = args[++i];
|
|
61
|
-
config.source.type = 'json';
|
|
62
|
-
}
|
|
63
|
-
else if (arg === '--ama') config.ama = args[++i];
|
|
64
|
-
else if (arg === '--output') config.output = args[++i];
|
|
65
|
-
else if (arg === '--buckets') config.buckets = parseInt(args[++i], 10);
|
|
66
|
-
else if (arg === '--max-neg') config.maxNeg = parseFloat(args[++i]);
|
|
67
|
-
else if (arg === '--max-pos') config.maxPos = parseFloat(args[++i]);
|
|
68
|
-
else if (arg === '--warmup') config.warmup = parseInt(args[++i], 10);
|
|
69
|
-
else if (arg === '--bin-size') config.binSize = parseFloat(args[++i]);
|
|
70
|
-
else if (arg === '--slice-months') config.sliceMonths = parseInt(args[++i], 10);
|
|
71
|
-
else if (arg === '--thresholds') config.thresholds = args[++i].split(',').map(Number);
|
|
72
|
-
else if (arg === '--list-bots') config.listBots = true;
|
|
73
|
-
else if (arg === '--quiet') config.quiet = true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return config;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async function main() {
|
|
80
|
-
try {
|
|
81
|
-
const cfg = parseArgs();
|
|
82
|
-
|
|
83
|
-
if (cfg.listBots) {
|
|
84
|
-
listAvailableBots();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const { source } = resolveSource({ ...cfg.source.config, type: cfg.source.type }, { quiet: cfg.quiet });
|
|
89
|
-
if (!cfg.quiet) console.log(`[TradeHeatmap] Loading candles from ${source.name}...`);
|
|
90
|
-
|
|
91
|
-
const candles = await source.fetchCandles();
|
|
92
|
-
if (!Array.isArray(candles) || candles.length === 0) {
|
|
93
|
-
throw new Error('No candles returned from source');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const amaCfg = MARKET_ADAPTER.AMAS[cfg.ama as keyof typeof MARKET_ADAPTER.AMAS];
|
|
97
|
-
if (!amaCfg) {
|
|
98
|
-
throw new Error(`Unknown AMA preset: ${cfg.ama}. Choose: ${Object.keys(MARKET_ADAPTER.AMAS).join(', ')}`);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const closes = candles.map(c => getCandleClose(c) ?? Number(c?.close ?? c?.[4] ?? 0));
|
|
102
|
-
const volumes = candles.map(c => Number(c?.volume ?? c?.[5] ?? 0) || 0);
|
|
103
|
-
const timestamps = candles.map(c => Number(c?.timestamp ?? c?.[0] ?? 0));
|
|
104
|
-
|
|
105
|
-
if (cfg.warmup === null) {
|
|
106
|
-
cfg.warmup = Math.ceil(amaCfg.erPeriod);
|
|
107
|
-
}
|
|
108
|
-
if (!cfg.quiet) console.log(`[TradeHeatmap] Computing ${cfg.ama} on ${closes.length} candles (warmup=${cfg.warmup})...`);
|
|
109
|
-
|
|
110
|
-
const amaValues = calculateAMA(closes, amaCfg);
|
|
111
|
-
const records: any[] = [];
|
|
112
|
-
for (let i = cfg.warmup; i < closes.length; i++) {
|
|
113
|
-
const ama = amaValues[i];
|
|
114
|
-
if (!Number.isFinite(ama) || ama === 0) continue;
|
|
115
|
-
const devPct = ((closes[i] - ama) / ama) * 100;
|
|
116
|
-
const vol = volumes[i];
|
|
117
|
-
if (vol <= 0) continue;
|
|
118
|
-
records.push({ devPct, vol, ts: timestamps[i] });
|
|
119
|
-
}
|
|
120
|
-
if (records.length === 0) {
|
|
121
|
-
throw new Error('No valid records after filtering');
|
|
122
|
-
}
|
|
123
|
-
if (!cfg.quiet) console.log(`[TradeHeatmap] ${records.length} volume-bearing candles after warmup`);
|
|
124
|
-
|
|
125
|
-
const devs = records.map(r => r.devPct);
|
|
126
|
-
const vols = records.map(r => r.vol);
|
|
127
|
-
const totalVol = vols.reduce((a, b) => a + b, 0);
|
|
128
|
-
const meanDev = devs.reduce((a, b) => a + b, 0) / devs.length;
|
|
129
|
-
const stdDev = calcStdDev(devs);
|
|
130
|
-
const sortedDevs = devs.slice().sort((a, b) => a - b);
|
|
131
|
-
const medianDev = sortedDevs[Math.floor(sortedDevs.length / 2)];
|
|
132
|
-
let weightedSum = 0;
|
|
133
|
-
for (let i = 0; i < devs.length; i++) weightedSum += devs[i] * vols[i];
|
|
134
|
-
const volWeightedMeanDev = weightedSum / totalVol;
|
|
135
|
-
const binSize = cfg.binSize;
|
|
136
|
-
let leftBins, rightBins;
|
|
137
|
-
if (cfg.buckets !== null) {
|
|
138
|
-
const half = Math.floor(cfg.buckets / 2);
|
|
139
|
-
leftBins = half;
|
|
140
|
-
rightBins = half;
|
|
141
|
-
} else {
|
|
142
|
-
leftBins = Math.ceil((cfg.maxNeg !== null ? cfg.maxNeg : binSize * 10) / binSize);
|
|
143
|
-
rightBins = Math.ceil((cfg.maxPos !== null ? cfg.maxPos : binSize * 10) / binSize);
|
|
144
|
-
}
|
|
145
|
-
const maxNegDev = leftBins * binSize;
|
|
146
|
-
const maxPosDev = rightBins * binSize;
|
|
147
|
-
const binLabels: string[] = [];
|
|
148
|
-
for (let i = -leftBins; i <= rightBins; i++) {
|
|
149
|
-
binLabels.push((i * binSize).toFixed(1));
|
|
150
|
-
}
|
|
151
|
-
const nBins = binLabels.length;
|
|
152
|
-
const binKey = (dev: number) => {
|
|
153
|
-
const idx = Math.round(dev / binSize) + leftBins;
|
|
154
|
-
return Math.max(0, Math.min(nBins - 1, idx));
|
|
155
|
-
};
|
|
156
|
-
const minTs = timestamps[cfg.warmup];
|
|
157
|
-
const maxTs = timestamps[timestamps.length - 1];
|
|
158
|
-
const minDate = new Date(minTs);
|
|
159
|
-
const maxDate = new Date(maxTs);
|
|
160
|
-
const sliceMonths = cfg.sliceMonths;
|
|
161
|
-
const slices: any[] = [];
|
|
162
|
-
let sliceStart = new Date(minDate.getFullYear(), minDate.getMonth(), 1);
|
|
163
|
-
while (sliceStart <= maxDate) {
|
|
164
|
-
const sliceEnd = new Date(sliceStart);
|
|
165
|
-
sliceEnd.setMonth(sliceEnd.getMonth() + sliceMonths);
|
|
166
|
-
slices.push({
|
|
167
|
-
label: `${sliceStart.getFullYear()}-${String(sliceStart.getMonth() + 1).padStart(2, '0')}`,
|
|
168
|
-
start: sliceStart.getTime(),
|
|
169
|
-
end: sliceEnd.getTime(),
|
|
170
|
-
});
|
|
171
|
-
sliceStart = sliceEnd;
|
|
172
|
-
}
|
|
173
|
-
const sliceBuckets = slices.map(() => new Array(nBins).fill(0));
|
|
174
|
-
const sliceTotals = new Array(slices.length).fill(0);
|
|
175
|
-
for (const r of records) {
|
|
176
|
-
const si = slices.findIndex(s => r.ts >= s.start && r.ts < s.end);
|
|
177
|
-
if (si === -1) continue;
|
|
178
|
-
const bi = binKey(r.devPct);
|
|
179
|
-
sliceBuckets[si][bi] += r.vol;
|
|
180
|
-
sliceTotals[si] += r.vol;
|
|
181
|
-
}
|
|
182
|
-
while (slices.length > 0 && sliceTotals[sliceTotals.length - 1] === 0) {
|
|
183
|
-
slices.pop();
|
|
184
|
-
sliceBuckets.pop();
|
|
185
|
-
sliceTotals.pop();
|
|
186
|
-
}
|
|
187
|
-
const totalBins = new Array(nBins).fill(0);
|
|
188
|
-
for (const r of records) {
|
|
189
|
-
totalBins[binKey(r.devPct)] += r.vol;
|
|
190
|
-
}
|
|
191
|
-
const maxBinVol = Math.max(...totalBins);
|
|
192
|
-
const pctWithin = cfg.thresholds.map(t => {
|
|
193
|
-
const volIn = records.filter(r => Math.abs(r.devPct) <= t).reduce((s, r) => s + r.vol, 0);
|
|
194
|
-
return (volIn / totalVol * 100).toFixed(2);
|
|
195
|
-
});
|
|
196
|
-
const peakBinIdx = totalBins.indexOf(maxBinVol);
|
|
197
|
-
const peakDev = binLabels[peakBinIdx];
|
|
198
|
-
const allCellPcts: number[] = [];
|
|
199
|
-
for (let si = 0; si < slices.length; si++) {
|
|
200
|
-
for (let bi = 0; bi < nBins; bi++) {
|
|
201
|
-
if (sliceTotals[si] > 0) {
|
|
202
|
-
allCellPcts.push((sliceBuckets[si][bi] / sliceTotals[si]) * 100);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
allCellPcts.sort((a, b) => a - b);
|
|
207
|
-
const colorCap = allCellPcts.length > 0
|
|
208
|
-
? allCellPcts[Math.floor(allCellPcts.length * 0.95)]
|
|
209
|
-
: 30;
|
|
210
|
-
function heatColor(pct: number) {
|
|
211
|
-
if (pct <= 0) return '#0d1117';
|
|
212
|
-
const n = Math.min(pct / colorCap, 1);
|
|
213
|
-
const r = Math.round(13 + n * (255 - 13));
|
|
214
|
-
const g = Math.round(17 + n * (160 - 17));
|
|
215
|
-
const b = Math.round(23 + n * (70 - 23));
|
|
216
|
-
return `rgb(${r},${g},${b})`;
|
|
217
|
-
}
|
|
218
|
-
function histColor(pct: number, maxPct: number) {
|
|
219
|
-
const n = maxPct > 0 ? pct / maxPct : 0;
|
|
220
|
-
const r = Math.round(56 + n * (255 - 56));
|
|
221
|
-
const g = Math.round(178 + n * (160 - 178));
|
|
222
|
-
const b = Math.round(73 + n * (70 - 73));
|
|
223
|
-
return `rgb(${r},${g},${b})`;
|
|
224
|
-
}
|
|
225
|
-
const heatRows = slices.map((sl, si) => {
|
|
226
|
-
const rowPcts = sliceBuckets[si].map(v => sliceTotals[si] > 0 ? (v / sliceTotals[si]) * 100 : 0);
|
|
227
|
-
const cells = rowPcts.map((p, bi) => {
|
|
228
|
-
const pctStr = p > 0 ? p.toFixed(1) : '';
|
|
229
|
-
return `<td class="hm-cell" style="background:${heatColor(p)}" title="dev=${binLabels[bi]}% vol=${(sliceBuckets[si][bi]).toFixed(2)} (${p.toFixed(1)}% of ${sl.label})">${pctStr}</td>`;
|
|
230
|
-
}).join('');
|
|
231
|
-
return `<tr><td class="yl">${sl.label}</td>${cells}</tr>`;
|
|
232
|
-
}).join('\n');
|
|
233
|
-
const maxBarPct = Math.max(...totalBins);
|
|
234
|
-
const barRows = totalBins.map((v, i) => {
|
|
235
|
-
const barPct = maxBarPct > 0 ? (v / maxBarPct) * 100 : 0;
|
|
236
|
-
const color = histColor(v, maxBarPct);
|
|
237
|
-
const barH = Math.max(barPct * 0.7, 0.5);
|
|
238
|
-
return `<div class="bar" style="height:${barH}px;background:${color}" title="Deviation: ${binLabels[i]}% Volume: ${v.toFixed(2)}"></div>`;
|
|
239
|
-
}).join('');
|
|
240
|
-
const xLabelInterval = Math.max(1, Math.floor(nBins / 11));
|
|
241
|
-
const xLabelsHtml = binLabels.map((l, i) => {
|
|
242
|
-
if (i === 0 || i === nBins - 1 || i % xLabelInterval === 0) {
|
|
243
|
-
return `<span>${l}%</span>`;
|
|
244
|
-
}
|
|
245
|
-
return '<span></span>';
|
|
246
|
-
}).join('');
|
|
247
|
-
const threshHtml = cfg.thresholds.map(t => {
|
|
248
|
-
const pct = ((leftBins + t / binSize) / nBins) * 100;
|
|
249
|
-
return `<div class="thresh-line" style="left:${Math.min(Math.max(pct, 0), 100)}%"><span class="thresh-label">±${t}%</span></div>`;
|
|
250
|
-
}).join('');
|
|
251
|
-
const sourceLabel = cfg.source.config.botKey || path.basename(cfg.source.config.filePath || 'data');
|
|
252
|
-
const html = `<!DOCTYPE html>
|
|
253
|
-
<html lang="en">
|
|
254
|
-
<head>
|
|
255
|
-
<meta charset="UTF-8">
|
|
256
|
-
<title>Trade Heatmap — ${cfg.ama} Deviation</title>
|
|
257
|
-
<style>
|
|
258
|
-
* { box-sizing: border-box; }
|
|
259
|
-
body { background: #0b0e14; color: #d1d5db; font-family: 'Segoe UI', sans-serif; margin: 0; padding: 24px; }
|
|
260
|
-
h1 { color: #fff; font-size: 18px; margin: 0 0 2px 0; }
|
|
261
|
-
.subtitle { color: #8b949e; font-size: 12px; margin: 0 0 16px 0; }
|
|
262
|
-
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 24px; }
|
|
263
|
-
.stat-card { background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 10px 12px; }
|
|
264
|
-
.stat-card .lbl { color: #8b949e; font-size: 9px; text-transform: uppercase; letter-spacing: 0.8px; }
|
|
265
|
-
.stat-card .val { color: #f0f6fc; font-size: 16px; font-weight: bold; margin-top: 2px; }
|
|
266
|
-
.stat-card .val.green { color: #3fb950; }
|
|
267
|
-
.stat-card .val.orange { color: #f08c00; }
|
|
268
|
-
.stat-card .val.blue { color: #58a6ff; }
|
|
269
|
-
.hm-wrap { overflow-x: auto; margin-bottom: 28px; }
|
|
270
|
-
table.heatmap { border-collapse: collapse; font-size: 10px; }
|
|
271
|
-
table.heatmap th { color: #8b949e; font-size: 9px; font-weight: normal; padding: 2px 0; min-width: 32px; text-align: center; }
|
|
272
|
-
table.heatmap td.hm-cell { width: 30px; height: 22px; text-align: center; font-size: 8px; color: rgba(255,255,255,0.6); cursor: default; border: 1px solid #161b22; border-radius: 1px; }
|
|
273
|
-
table.heatmap td.yl { color: #8b949e; font-size: 10px; text-align: right; padding-right: 8px; white-space: nowrap; }
|
|
274
|
-
.legend-row { display: flex; align-items: center; gap: 12px; font-size: 10px; color: #8b949e; margin-bottom: 20px; }
|
|
275
|
-
.legend-bar { width: 160px; height: 8px; border-radius: 3px; background: linear-gradient(to right, #0d1117, #1f6f2f, #3fb950, #ffa03e, #f85149); }
|
|
276
|
-
.section-title { color: #8b949e; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; margin: 0 0 10px 0; border-bottom: 1px solid #30363d; padding-bottom: 4px; }
|
|
277
|
-
.hist-wrap { position: relative; margin-bottom: 36px; }
|
|
278
|
-
.hist-bar-container { display: flex; align-items: flex-end; gap: 1px; height: 180px; }
|
|
279
|
-
.hist-bar-container .bar { flex: 1; min-height: 1px; border-radius: 1px; cursor: pointer; transition: opacity 0.15s; }
|
|
280
|
-
.hist-bar-container .bar:hover { opacity: 0.8; }
|
|
281
|
-
.hist-overlay { position: absolute; top: 0; left: 0; right: 0; height: 180px; pointer-events: none; }
|
|
282
|
-
.thresh-line { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed rgba(248,81,73,0.5); }
|
|
283
|
-
.thresh-label { position: absolute; top: 2px; left: 50%; transform: translateX(-50%); font-size: 8px; color: #f85149; white-space: nowrap; background: rgba(11,14,20,0.8); padding: 0 3px; line-height: 12px; }
|
|
284
|
-
.x-labels { display: flex; font-size: 9px; color: #8b949e; margin-top: 4px; }
|
|
285
|
-
.x-labels span { flex: 1; text-align: center; white-space: nowrap; }
|
|
286
|
-
.pct-table { font-size: 11px; color: #8b949e; margin-bottom: 24px; }
|
|
287
|
-
.pct-table td { padding: 3px 12px 3px 0; }
|
|
288
|
-
.pct-table td:first-child { color: #d1d5db; }
|
|
289
|
-
.pct-table .val-col { text-align: right; font-weight: bold; color: #3fb950; font-family: monospace; }
|
|
290
|
-
.bottom { display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap; margin-top: 8px; }
|
|
291
|
-
.params-table { font-size: 11px; color: #8b949e; }
|
|
292
|
-
.params-table td { padding: 2px 16px 2px 0; }
|
|
293
|
-
.params-table td:first-child { color: #555; }
|
|
294
|
-
</style>
|
|
295
|
-
</head>
|
|
296
|
-
<body>
|
|
297
|
-
<h1>Trade Heatmap — ${cfg.ama} Deviation</h1>
|
|
298
|
-
<p class="subtitle">
|
|
299
|
-
${closes.length} candles · ${records.length} with volume ·
|
|
300
|
-
${(totalVol).toFixed(1)} total volume units ·
|
|
301
|
-
${binSize}% bins ·
|
|
302
|
-
${slices.length} time slices ·
|
|
303
|
-
${sourceLabel}
|
|
304
|
-
</p>
|
|
305
|
-
<div class="stats-grid">
|
|
306
|
-
<div class="stat-card"><div class="lbl">Mean Deviation</div><div class="val">${meanDev.toFixed(2)}%</div></div>
|
|
307
|
-
<div class="stat-card"><div class="lbl">Median Deviation</div><div class="val">${medianDev.toFixed(2)}%</div></div>
|
|
308
|
-
<div class="stat-card"><div class="lbl">Std Deviation</div><div class="val blue">${stdDev.toFixed(2)}%</div></div>
|
|
309
|
-
<div class="stat-card"><div class="lbl">Vol-Weighted Mean</div><div class="val">${volWeightedMeanDev.toFixed(2)}%</div></div>
|
|
310
|
-
<div class="stat-card"><div class="lbl">Peak Bucket</div><div class="val green">${peakDev}%</div></div>
|
|
311
|
-
<div class="stat-card"><div class="lbl">Max |Dev|</div><div class="val orange">${Math.max(...devs.map(Math.abs)).toFixed(2)}%</div></div>
|
|
312
|
-
</div>
|
|
313
|
-
<div class="section-title">Volume Distribution by Time Slice — % of slice volume per deviation bucket</div>
|
|
314
|
-
<div class="hm-wrap">
|
|
315
|
-
<table class="heatmap">
|
|
316
|
-
<thead><tr><th></th>${binLabels.map(l => `<th>${l}</th>`).join('')}</tr></thead>
|
|
317
|
-
<tbody>${heatRows}</tbody>
|
|
318
|
-
</table>
|
|
319
|
-
</div>
|
|
320
|
-
<div class="legend-row">
|
|
321
|
-
<span>0%</span>
|
|
322
|
-
<div class="legend-bar"></div>
|
|
323
|
-
<span>≥${colorCap.toFixed(0)}% of slice</span>
|
|
324
|
-
</div>
|
|
325
|
-
<div class="section-title">Summed Volume Distribution — total volume per deviation bucket</div>
|
|
326
|
-
<div class="hist-wrap">
|
|
327
|
-
<div class="hist-bar-container">
|
|
328
|
-
${cfg.thresholds.length > 0 ? `<div class="hist-overlay">${threshHtml}</div>` : ''}
|
|
329
|
-
${barRows}
|
|
330
|
-
</div>
|
|
331
|
-
<div class="x-labels">${xLabelsHtml}</div>
|
|
332
|
-
</div>
|
|
333
|
-
<div class="section-title">Volume Concentration</div>
|
|
334
|
-
<table class="pct-table">
|
|
335
|
-
${cfg.thresholds.map((t, i) =>
|
|
336
|
-
`<tr><td>Within ±${t}% of AMA</td><td class="val-col">${pctWithin[i]}%</td></tr>`
|
|
337
|
-
).join('')}
|
|
338
|
-
</table>
|
|
339
|
-
<div class="bottom">
|
|
340
|
-
<table class="params-table">
|
|
341
|
-
<tr><td>AMA Preset</td><td>${cfg.ama}</td></tr>
|
|
342
|
-
<tr><td>ER Period</td><td>${amaCfg.erPeriod}</td></tr>
|
|
343
|
-
<tr><td>Fast SC (period)</td><td>${amaCfg.fastPeriod}</td></tr>
|
|
344
|
-
<tr><td>Slow SC (period)</td><td>${amaCfg.slowPeriod}</td></tr>
|
|
345
|
-
<tr><td>Bin size</td><td>${binSize}%</td></tr>
|
|
346
|
-
<tr><td>Total bins</td><td>${nBins} (${(-maxNegDev).toFixed(0)}% to +${maxPosDev.toFixed(0)}%)</td></tr>
|
|
347
|
-
<tr><td>Warmup bars skipped</td><td>${cfg.warmup}</td></tr>
|
|
348
|
-
<tr><td>Slice months</td><td>${cfg.sliceMonths}</td></tr>
|
|
349
|
-
<tr><td>Data range</td><td>${minDate.toISOString().split('T')[0]} – ${maxDate.toISOString().split('T')[0]}</td></tr>
|
|
350
|
-
</table>
|
|
351
|
-
</div>
|
|
352
|
-
</body>
|
|
353
|
-
</html>`;
|
|
354
|
-
writeChartFile(cfg.output, html);
|
|
355
|
-
if (!cfg.quiet) console.log(`[TradeHeatmap] ✓ Heatmap saved to ${cfg.output}`);
|
|
356
|
-
} catch (err: any) {
|
|
357
|
-
console.error(`[TradeHeatmap] Error: ${err?.message ?? err}`);
|
|
358
|
-
process.exit(1);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
main().catch((err: unknown) => { console.error(err); process.exit(1); });
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* VOLATILITY / SYMMETRIC SHIFT RESEARCH TOOL
|
|
6
|
-
*
|
|
7
|
-
* Computes the symmetric volatility shift used by the market adapter.
|
|
8
|
-
*
|
|
9
|
-
* Signal path:
|
|
10
|
-
* ATR(period, default 14) -> weightVariance = atr / amaPrice
|
|
11
|
-
* rawSymmetricDelta = -pow(weightVariance, volatilityExponent) * volatilityScaleX
|
|
12
|
-
* clampedRawDelta = clamp(rawSymmetricDelta, -DYNAMIC_WEIGHT_SYMMETRIC_SHIFT_CLAMP, 0)
|
|
13
|
-
* symmetricDelta = |clampedRawDelta| < volatilityThreshold ? 0 : clampedRawDelta
|
|
14
|
-
*
|
|
15
|
-
* The live adapter adds this penalty to both sides after the trend term is built.
|
|
16
|
-
* This runner intentionally omits the directional trend branch so the volatility
|
|
17
|
-
* effect can be researched in isolation.
|
|
18
|
-
*
|
|
19
|
-
* Usage:
|
|
20
|
-
* node dist/analysis/analyze_volatility.js \
|
|
21
|
-
* --file market_adapter/data/lp/<path>/<to>/<lp-candles>.json
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
|
|
26
|
-
import { calculateAMA } from '../market_adapter/core/strategies/ama.js';
|
|
27
|
-
import { computeATRSeries } from '../market_adapter/core/strategies/atr/calculator.js';
|
|
28
|
-
import { normalizeAtrPeriod } from '../market_adapter/core/config_normalizers.js';
|
|
29
|
-
import { computeVolatilityShift } from '../market_adapter/core/strategies/volatility_shift.js';
|
|
30
|
-
import { generateHTML } from './trend_detection/volatility_chart_generator.js';
|
|
31
|
-
import { MARKET_ADAPTER } from '../modules/constants.js';
|
|
32
|
-
import { PATHS } from '../modules/paths.js';
|
|
33
|
-
import { getCandleClose } from './math_utils.js';
|
|
34
|
-
import { writeChartFile } from './chart_utils.js';
|
|
35
|
-
import { resolveSource, listAvailableBots, type SourceConfig } from './resolve_source.js';
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const DEFAULT_ATR_PERIOD = MARKET_ADAPTER.DYNAMIC_WEIGHT_ATR_PERIOD_DEFAULT;
|
|
39
|
-
const MIN_WEIGHT = MARKET_ADAPTER.DYNAMIC_WEIGHT_MIN_WEIGHT;
|
|
40
|
-
const MAX_WEIGHT = MARKET_ADAPTER.DYNAMIC_WEIGHT_MAX_WEIGHT;
|
|
41
|
-
const DEFAULT_THRESHOLD = MARKET_ADAPTER.DYNAMIC_WEIGHT_SYMMETRIC_SHIFT_THRESHOLD;
|
|
42
|
-
const DEFAULT_CLAMP = MARKET_ADAPTER.DYNAMIC_WEIGHT_SYMMETRIC_SHIFT_CLAMP;
|
|
43
|
-
const DEFAULT_CHART_DIR = PATHS.ANALYSIS.CHARTS_DIR;
|
|
44
|
-
const DEFAULT_CHART_FILE = path.join(DEFAULT_CHART_DIR, 'volatility_chart.html');
|
|
45
|
-
|
|
46
|
-
function computeATRSeriesNormalized(candles: any[], period = DEFAULT_ATR_PERIOD) {
|
|
47
|
-
return computeATRSeries(candles, normalizeAtrPeriod(period));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function parseArgs() {
|
|
51
|
-
const args = process.argv.slice(2);
|
|
52
|
-
const config: {
|
|
53
|
-
source: { type: string; config: SourceConfig };
|
|
54
|
-
chartFile: string;
|
|
55
|
-
threshold: number;
|
|
56
|
-
atrPeriod: number;
|
|
57
|
-
exponent: number;
|
|
58
|
-
scaleX: number;
|
|
59
|
-
clamp: number;
|
|
60
|
-
quiet: boolean;
|
|
61
|
-
listBots: boolean;
|
|
62
|
-
} = {
|
|
63
|
-
source: { type: 'market_adapter', config: { botKey: '' } },
|
|
64
|
-
chartFile: DEFAULT_CHART_FILE,
|
|
65
|
-
threshold: DEFAULT_THRESHOLD,
|
|
66
|
-
atrPeriod: DEFAULT_ATR_PERIOD,
|
|
67
|
-
exponent: MARKET_ADAPTER.DYNAMIC_WEIGHT_VOLATILITY_EXPONENT,
|
|
68
|
-
scaleX: MARKET_ADAPTER.DYNAMIC_WEIGHT_VOLATILITY_SCALE_X_DEFAULT,
|
|
69
|
-
clamp: DEFAULT_CLAMP,
|
|
70
|
-
quiet: false,
|
|
71
|
-
listBots: false,
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
for (let i = 0; i < args.length; i++) {
|
|
75
|
-
const arg = args[i];
|
|
76
|
-
if (arg === '--source') config.source.type = args[++i];
|
|
77
|
-
else if (arg === '--bot-key') config.source.config.botKey = args[++i];
|
|
78
|
-
else if (arg === '--file') {
|
|
79
|
-
config.source.config.filePath = args[++i];
|
|
80
|
-
config.source.type = 'json';
|
|
81
|
-
}
|
|
82
|
-
else if (arg === '--chart') config.chartFile = args[++i];
|
|
83
|
-
else if (arg === '--threshold') config.threshold = parseFloat(args[++i]);
|
|
84
|
-
else if (arg === '--atr-period') {
|
|
85
|
-
const next = parseInt(args[++i], 10);
|
|
86
|
-
if (Number.isFinite(next)) config.atrPeriod = normalizeAtrPeriod(next);
|
|
87
|
-
}
|
|
88
|
-
else if (arg === '--exp') config.exponent = parseFloat(args[++i]);
|
|
89
|
-
else if (arg === '--scale-x') config.scaleX = parseFloat(args[++i]);
|
|
90
|
-
else if (arg === '--clamp') config.clamp = parseFloat(args[++i]);
|
|
91
|
-
else if (arg === '--list-bots') config.listBots = true;
|
|
92
|
-
else if (arg === '--quiet') config.quiet = true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return config;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function computeShift(weightVariance: number, exponent: number, scaleX: number, threshold: number, clampValue: number) {
|
|
99
|
-
const shift = computeVolatilityShift(weightVariance, {
|
|
100
|
-
exponent,
|
|
101
|
-
scaleX,
|
|
102
|
-
threshold,
|
|
103
|
-
clampValue,
|
|
104
|
-
minWeight: MIN_WEIGHT,
|
|
105
|
-
maxWeight: MAX_WEIGHT,
|
|
106
|
-
});
|
|
107
|
-
return {
|
|
108
|
-
rawSymmetricDelta: shift.rawSymmetricDelta,
|
|
109
|
-
symmetricDelta: shift.symmetricDelta,
|
|
110
|
-
effectiveWeight: shift.effectiveWeight,
|
|
111
|
-
sellW: shift.sellW,
|
|
112
|
-
buyW: shift.buyW,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async function main() {
|
|
117
|
-
try {
|
|
118
|
-
const config = parseArgs();
|
|
119
|
-
|
|
120
|
-
if (config.listBots) {
|
|
121
|
-
listAvailableBots();
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const { source, amaConfig } = resolveSource({ ...config.source.config, type: config.source.type }, { quiet: config.quiet });
|
|
126
|
-
if (!config.quiet) console.log(`[Volatility] Loading candles from ${source.name}...`);
|
|
127
|
-
|
|
128
|
-
const candles = await source.fetchCandles();
|
|
129
|
-
if (!Array.isArray(candles) || candles.length === 0) {
|
|
130
|
-
throw new Error('No candles returned from source');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const closes = candles.map(c => getCandleClose(c) ?? 0);
|
|
134
|
-
const ama3Values = calculateAMA(closes, amaConfig);
|
|
135
|
-
const atrPeriod = normalizeAtrPeriod(config.atrPeriod);
|
|
136
|
-
const atrs = computeATRSeriesNormalized(candles, atrPeriod);
|
|
137
|
-
|
|
138
|
-
const allResults: any[] = [];
|
|
139
|
-
for (let i = 0; i < candles.length; i++) {
|
|
140
|
-
const { marketPrice, timestamp } = source.extractMarketPrice(candles[i]);
|
|
141
|
-
const amaPrice = ama3Values[i] ?? null;
|
|
142
|
-
const atr = atrs[i] ?? 0;
|
|
143
|
-
const weightVariance = amaPrice > 0 ? atr / amaPrice : 0;
|
|
144
|
-
const shift = computeShift(weightVariance, config.exponent, config.scaleX, config.threshold, config.clamp);
|
|
145
|
-
|
|
146
|
-
allResults.push({
|
|
147
|
-
timestamp,
|
|
148
|
-
price: marketPrice,
|
|
149
|
-
ama3Price: amaPrice,
|
|
150
|
-
atr,
|
|
151
|
-
weightVariance,
|
|
152
|
-
rawSymmetricDelta: shift.rawSymmetricDelta,
|
|
153
|
-
symmetricDelta: shift.symmetricDelta,
|
|
154
|
-
effectiveWeight: shift.effectiveWeight,
|
|
155
|
-
sellW: shift.sellW,
|
|
156
|
-
buyW: shift.buyW,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const html = generateHTML({
|
|
161
|
-
allResults,
|
|
162
|
-
candles,
|
|
163
|
-
volatilityThreshold: config.threshold,
|
|
164
|
-
volatilityExponent: config.exponent,
|
|
165
|
-
volatilityScaleX: config.scaleX,
|
|
166
|
-
volatilityClamp: config.clamp,
|
|
167
|
-
atrPeriod,
|
|
168
|
-
minWeight: MIN_WEIGHT,
|
|
169
|
-
maxWeight: MAX_WEIGHT,
|
|
170
|
-
marketAdapter: MARKET_ADAPTER,
|
|
171
|
-
}, 'ATR Volatility Research');
|
|
172
|
-
|
|
173
|
-
writeChartFile(config.chartFile, html);
|
|
174
|
-
|
|
175
|
-
if (!config.quiet) console.log(`[Volatility] ✓ Chart saved to ${config.chartFile}`);
|
|
176
|
-
} catch (err: unknown) {
|
|
177
|
-
console.error(`[Volatility] Error: ${(err as any)?.message ?? err}`);
|
|
178
|
-
process.exit(1);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
main().catch((err: unknown) => { console.error(err); process.exit(1); });
|