dexbot 1.6.7 → 1.6.9
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 +73 -1
- package/README.md +3 -3
- 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 +55 -16
- package/dist/market_adapter/core/market_adapter_service.d.ts +81 -1
- package/dist/market_adapter/core/market_adapter_service.js +239 -20
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +10 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js +40 -18
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +26 -2
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +132 -29
- 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/core/strategies/regime_gate.d.ts +61 -3
- package/dist/market_adapter/core/strategies/regime_gate.js +207 -7
- 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/interval_utils.d.ts +18 -1
- package/dist/market_adapter/interval_utils.js +31 -1
- package/dist/market_adapter/market_adapter.d.ts +158 -2
- package/dist/market_adapter/market_adapter.js +399 -65
- package/dist/market_adapter/test_helpers.d.ts +2 -2
- package/dist/market_adapter/test_helpers.js +2 -2
- package/dist/market_adapter/utils/file_json_cache.d.ts +29 -0
- package/dist/market_adapter/utils/file_json_cache.js +106 -0
- package/dist/modules/account_bots.js +10 -0
- package/dist/modules/account_orders.d.ts +24 -2
- package/dist/modules/account_orders.js +41 -4
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/config.d.ts +7 -0
- package/dist/modules/config.js +2 -0
- package/dist/modules/constants.d.ts +16 -4
- package/dist/modules/constants.js +144 -38
- 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 +4 -87
- package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
- package/dist/modules/dexbot_maintenance_runtime.js +59 -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 +21 -0
- 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 +172 -160
- 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 +2 -2
- package/dist/modules/order/manager.d.ts +4 -0
- package/dist/modules/order/manager.js +14 -1
- 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 +220 -197
- package/dist/modules/order/utils/system.js +8 -1
- package/dist/modules/paths.d.ts +1 -0
- package/dist/modules/paths.js +1 -0
- package/dist/modules/version_notice.d.ts +311 -0
- package/dist/modules/version_notice.js +709 -0
- package/dist/pm2.js +16 -0
- package/dist/unlock.js +28 -0
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +3 -2
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +22 -20
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +149 -31
- package/docs/GRID_RECALCULATION.md +18 -2
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +29 -1
- package/modules/README.md +18 -1
- package/package.json +13 -5
- 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/cli_start_onboarding.d.ts.map +0 -1
- package/dist/modules/cli_start_onboarding.js.map +0 -1
- package/dist/modules/cli_start_output.d.ts.map +0 -1
- package/dist/modules/cli_start_output.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/utils/text_width.d.ts.map +0 -1
- package/dist/modules/utils/text_width.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
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves the grid-reset simulation config for the TradingView exporter.
|
|
4
|
+
*
|
|
5
|
+
* The chart must answer one question: "with the thresholds the live adapter
|
|
6
|
+
* would actually use for this bot, when would the grid have recentered?" So
|
|
7
|
+
* every number here comes from the same resolution chain the running adapter
|
|
8
|
+
* uses (docs/GRID_RECALCULATION.md, "Configuration Priority"):
|
|
9
|
+
*
|
|
10
|
+
* 1. constants — market_adapter DEFAULTS (MARKET_ADAPTER.*)
|
|
11
|
+
* 2. general settings — profiles/general.settings.json
|
|
12
|
+
* → MARKET_ADAPTER.AMA_DELTA_THRESHOLD_PERCENT
|
|
13
|
+
* 3. market adapter cfg — profiles/market_adapter_settings.json
|
|
14
|
+
* → globals → pairs[].marketAdapterSettings
|
|
15
|
+
* → pairs[].botOverrides[<botName>]
|
|
16
|
+
*
|
|
17
|
+
* Steps 2 and 3 are applied through the production functions
|
|
18
|
+
* (`applyRuntimeDefaultsFromGeneralSettings`, `resolveBotCfg`,
|
|
19
|
+
* `calculateBotThreshold`, `MarketAdapterService.resolveAmaSlopeDeltaThresholdPercent`)
|
|
20
|
+
* instead of a re-implementation, so the chart cannot drift from the runtime.
|
|
21
|
+
* `describeThresholdSource` then walks the same layers in precedence order
|
|
22
|
+
* purely to LABEL where the effective value came from (shown in the chart's
|
|
23
|
+
* grid-reset panel).
|
|
24
|
+
*
|
|
25
|
+
* Node-only: pulls the market-adapter runner, which is marked node-only in the
|
|
26
|
+
* package.json "browser" field. The browser only ever sees the resulting
|
|
27
|
+
* plain object (payload.gridSim) and the pure replay in grid_reset_sim.ts.
|
|
28
|
+
*/
|
|
29
|
+
import { MARKET_ADAPTER, DEFAULT_CONFIG } from '../../modules/constants.js';
|
|
30
|
+
import { readGeneralSettings } from '../../modules/general_settings.js';
|
|
31
|
+
import { resolveConfiguredPriceBound } from '../../modules/order/utils/order.js';
|
|
32
|
+
import { parseRelativeMultiplier } from '../../modules/order/utils/math.js';
|
|
33
|
+
import { getAmaWarmupBars } from '../../market_adapter/core/strategies/ama.js';
|
|
34
|
+
import { MarketAdapterService } from '../../market_adapter/core/market_adapter_service.js';
|
|
35
|
+
import { DEFAULTS, applyRuntimeDefaultsFromGeneralSettings, resolveBotCfg, calculateBotThreshold, loadMarketAdapterSettings, findPairForBot, usesAmaGridPrice, isBotAsymmetricBoundsWhitelisted, isBotDynamicWeightWhitelisted, } from '../../market_adapter/market_adapter.js';
|
|
36
|
+
const SOURCE_CONSTANTS = 'constants';
|
|
37
|
+
const SOURCE_GENERAL = 'general.settings';
|
|
38
|
+
const SOURCE_ADAPTER_GLOBALS = 'market_adapter_settings:globals';
|
|
39
|
+
const SOURCE_ADAPTER_PAIR = 'market_adapter_settings:pair';
|
|
40
|
+
const SOURCE_ADAPTER_BOT = 'market_adapter_settings:bot';
|
|
41
|
+
const SOURCE_CLI = 'cli';
|
|
42
|
+
const SIM_SERVICE = new MarketAdapterService({});
|
|
43
|
+
function firstPositive(values, fallback) {
|
|
44
|
+
for (const v of values) {
|
|
45
|
+
const n = Number(v);
|
|
46
|
+
if (Number.isFinite(n) && n > 0)
|
|
47
|
+
return n;
|
|
48
|
+
}
|
|
49
|
+
return fallback;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Walk the config layers in precedence order and report which one defined the
|
|
53
|
+
* value that ended up in the resolved cfg. Each layer carries its own key
|
|
54
|
+
* path(s) because the layers name the same knob differently (the adapter cfg
|
|
55
|
+
* uses `deltaThresholdPercent`, general settings use
|
|
56
|
+
* `MARKET_ADAPTER.AMA_DELTA_THRESHOLD_PERCENT`). Display only — the effective
|
|
57
|
+
* numbers always come from the real resolution functions.
|
|
58
|
+
*/
|
|
59
|
+
function describeThresholdSource(layers, cliOverride) {
|
|
60
|
+
if (cliOverride != null)
|
|
61
|
+
return SOURCE_CLI;
|
|
62
|
+
const hasValue = (obj, path) => {
|
|
63
|
+
let node = obj;
|
|
64
|
+
for (const key of path) {
|
|
65
|
+
node = node?.[key];
|
|
66
|
+
if (node == null)
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return Number.isFinite(Number(node)) && Number(node) > 0;
|
|
70
|
+
};
|
|
71
|
+
for (const layer of layers) {
|
|
72
|
+
if (!layer || !layer.value)
|
|
73
|
+
continue;
|
|
74
|
+
const paths = Array.isArray(layer.keys) ? layer.keys : [];
|
|
75
|
+
if (paths.some((path) => hasValue(layer.value, path)))
|
|
76
|
+
return layer.name;
|
|
77
|
+
}
|
|
78
|
+
return SOURCE_CONSTANTS;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* @param {Object} input
|
|
82
|
+
* @param {string|null} input.botKey Bot key from profiles/bots.json.
|
|
83
|
+
* @param {Object|null} input.bot Raw bots.json entry (for cfg layering).
|
|
84
|
+
* @param {Object|null} input.ama Resolved AMA config (er/fast/slow) the chart runs with.
|
|
85
|
+
* @param {Object} [input.overrides] CLI overrides {priceDeltaThresholdPercent, slopeDeltaThresholdPercent, enabled}.
|
|
86
|
+
*/
|
|
87
|
+
function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
88
|
+
const opts = overrides && typeof overrides === 'object' ? overrides : {};
|
|
89
|
+
const notes = [];
|
|
90
|
+
// ── 1. constants + general settings (the DEFAULTS the runner boots with)
|
|
91
|
+
const generalSettings = readGeneralSettings({ fallback: null });
|
|
92
|
+
const baseCfg = applyRuntimeDefaultsFromGeneralSettings({ ...DEFAULTS, quiet: true }, {});
|
|
93
|
+
// ── 2. market_adapter_settings.json (globals → pair → bot)
|
|
94
|
+
const botCfg = bot ? resolveBotCfg(bot, baseCfg) : baseCfg;
|
|
95
|
+
const settings = loadMarketAdapterSettings();
|
|
96
|
+
const pair = bot ? findPairForBot(bot, settings?.pairs) : null;
|
|
97
|
+
const botOverride = pair?.botOverrides?.[bot?.name] || null;
|
|
98
|
+
const layers = [
|
|
99
|
+
{ name: SOURCE_ADAPTER_BOT, value: botOverride, keys: [['deltaThresholdPercent']] },
|
|
100
|
+
{ name: SOURCE_ADAPTER_PAIR, value: pair?.marketAdapterSettings, keys: [['deltaThresholdPercent']] },
|
|
101
|
+
{ name: SOURCE_ADAPTER_GLOBALS, value: settings?.globals, keys: [['deltaThresholdPercent']] },
|
|
102
|
+
{ name: SOURCE_GENERAL, value: generalSettings, keys: [['MARKET_ADAPTER', 'AMA_DELTA_THRESHOLD_PERCENT']] },
|
|
103
|
+
];
|
|
104
|
+
// ── 3. effective thresholds through the production resolvers
|
|
105
|
+
const resolvedPrice = calculateBotThreshold(botCfg);
|
|
106
|
+
const priceDeltaThresholdPercent = firstPositive([opts.priceDeltaThresholdPercent, resolvedPrice], MARKET_ADAPTER.AMA_DELTA_THRESHOLD_PERCENT);
|
|
107
|
+
if (resolvedPrice == null) {
|
|
108
|
+
notes.push('Adapter cfg had no deltaThresholdPercent; fell back to MARKET_ADAPTER.AMA_DELTA_THRESHOLD_PERCENT.');
|
|
109
|
+
}
|
|
110
|
+
const priceSource = describeThresholdSource(layers, opts.priceDeltaThresholdPercent);
|
|
111
|
+
// Slope threshold: explicit per-bar % wins, else (factor/100) × maxSlopePct
|
|
112
|
+
// (MarketAdapterService.resolveAmaSlopeDeltaThresholdPercent). Core
|
|
113
|
+
// semantics: a non-positive threshold DISABLES the trigger, so never
|
|
114
|
+
// substitute a synthetic fallback for it.
|
|
115
|
+
const resolvedSlope = SIM_SERVICE.resolveAmaSlopeDeltaThresholdPercent(botCfg);
|
|
116
|
+
const slopeDeltaThresholdPercent = firstPositive([opts.slopeDeltaThresholdPercent, resolvedSlope], 0);
|
|
117
|
+
const slopeSource = describeThresholdSource([
|
|
118
|
+
{ name: SOURCE_ADAPTER_BOT, value: botOverride, keys: [['amaSlopeDeltaThresholdPercent'], ['amaSlope', 'deltaThresholdPct']] },
|
|
119
|
+
{ name: SOURCE_ADAPTER_PAIR, value: pair?.marketAdapterSettings, keys: [['amaSlopeDeltaThresholdPercent'], ['amaSlope', 'deltaThresholdPct']] },
|
|
120
|
+
{ name: SOURCE_ADAPTER_GLOBALS, value: settings?.globals, keys: [['amaSlopeDeltaThresholdPercent'], ['amaSlope', 'deltaThresholdPct']] },
|
|
121
|
+
{ name: SOURCE_GENERAL, value: generalSettings, keys: [['MARKET_ADAPTER', 'AMA_SLOPE_DELTA_THRESHOLD_PERCENT']] },
|
|
122
|
+
], opts.slopeDeltaThresholdPercent);
|
|
123
|
+
if (!(Number.isFinite(slopeDeltaThresholdPercent) && slopeDeltaThresholdPercent > 0)) {
|
|
124
|
+
notes.push('No positive AMA-Slope Δ threshold resolved (factor/maxSlopePct missing); slope resets are disabled.');
|
|
125
|
+
}
|
|
126
|
+
// ── 4. gates and tuning the replay mirrors
|
|
127
|
+
const isAmaBot = bot ? usesAmaGridPrice(bot) : false;
|
|
128
|
+
// The adapter only computes the slope signal for AMA-grid bots that have an
|
|
129
|
+
// explicit weightDistribution (shouldComputeDynamicWeightSignal), so a
|
|
130
|
+
// whitelisted bot without weights never reaches the slope trigger.
|
|
131
|
+
const hasExplicitBaseWeights = !!bot
|
|
132
|
+
&& Number.isFinite(bot.weightDistribution?.sell)
|
|
133
|
+
&& Number.isFinite(bot.weightDistribution?.buy);
|
|
134
|
+
const asymWhitelisted = botKey ? isBotAsymmetricBoundsWhitelisted(botKey) : false;
|
|
135
|
+
const dynamicWeightEnabled = botKey ? isBotDynamicWeightWhitelisted(botKey) : false;
|
|
136
|
+
const slopeEnabled = isAmaBot && hasExplicitBaseWeights && asymWhitelisted
|
|
137
|
+
&& Number.isFinite(slopeDeltaThresholdPercent) && slopeDeltaThresholdPercent > 0;
|
|
138
|
+
if (botKey && !asymWhitelisted) {
|
|
139
|
+
notes.push('asymmetricBounds whitelist is off for this bot: AMA-Slope Δ resets are not simulated.');
|
|
140
|
+
}
|
|
141
|
+
else if (botKey && asymWhitelisted && !hasExplicitBaseWeights && isAmaBot) {
|
|
142
|
+
notes.push('Bot has no explicit weightDistribution; the adapter skips the slope signal, so AMA-Slope Δ resets are not simulated.');
|
|
143
|
+
}
|
|
144
|
+
const erPeriod = firstPositive([ama?.erPeriod, botCfg?.erPeriod], MARKET_ADAPTER.AMAS.AMA3.erPeriod);
|
|
145
|
+
const lookbackBars = firstPositive([botCfg?.amaSlope?.lookbackBars], MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS);
|
|
146
|
+
let warmupBars = 0;
|
|
147
|
+
try {
|
|
148
|
+
warmupBars = getAmaWarmupBars(erPeriod, firstPositive([ama?.slowPeriod], MARKET_ADAPTER.AMAS.AMA3.slowPeriod), lookbackBars, firstPositive([ama?.fastPeriod], MARKET_ADAPTER.AMAS.AMA3.fastPeriod), Number(ama?.erSmoothPeriod) > 0 ? Number(ama.erSmoothPeriod) : 0);
|
|
149
|
+
}
|
|
150
|
+
catch (_err) {
|
|
151
|
+
// getAmaWarmupBars validates strictly; a research-only AMA tweak must
|
|
152
|
+
// never break chart generation — fall back to the ER warmup floor.
|
|
153
|
+
warmupBars = Math.ceil(erPeriod) + lookbackBars;
|
|
154
|
+
}
|
|
155
|
+
// Absolute bot bounds pin the accepted center (clampGridPriceToBounds);
|
|
156
|
+
// "Nx" bounds resolve around the center and therefore never bind it. A
|
|
157
|
+
// mixed config (one absolute, one "Nx") still clamps on the absolute side,
|
|
158
|
+
// so resolve each side independently.
|
|
159
|
+
const resolveClampBound = (raw, fallback, mode) => {
|
|
160
|
+
const relative = parseRelativeMultiplier(raw);
|
|
161
|
+
if (relative != null && relative > 1)
|
|
162
|
+
return null;
|
|
163
|
+
try {
|
|
164
|
+
const bound = resolveConfiguredPriceBound(raw, fallback, 1, mode);
|
|
165
|
+
return Number.isFinite(bound) && bound > 0 ? Number(bound) : null;
|
|
166
|
+
}
|
|
167
|
+
catch (_err) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const clampMin = bot ? resolveClampBound(bot.minPrice, DEFAULT_CONFIG.minPrice, 'min') : null;
|
|
172
|
+
const clampMax = bot ? resolveClampBound(bot.maxPrice, DEFAULT_CONFIG.maxPrice, 'max') : null;
|
|
173
|
+
return {
|
|
174
|
+
enabled: isAmaBot,
|
|
175
|
+
botKey: botKey || null,
|
|
176
|
+
priceDeltaThresholdPercent,
|
|
177
|
+
priceSource,
|
|
178
|
+
slopeDeltaThresholdPercent,
|
|
179
|
+
slopeSource,
|
|
180
|
+
slopeEnabled,
|
|
181
|
+
dynamicWeightEnabled,
|
|
182
|
+
lookbackBars,
|
|
183
|
+
maxSlopePct: firstPositive([botCfg?.amaSlope?.maxSlopePct], MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_MAX_SLOPE_PCT),
|
|
184
|
+
neutralZonePct: Number.isFinite(Number(botCfg?.amaSlope?.neutralZonePct))
|
|
185
|
+
? Number(botCfg.amaSlope.neutralZonePct)
|
|
186
|
+
: MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_NEUTRAL_ZONE_PCT,
|
|
187
|
+
maxSlopeOffset: firstPositive([botCfg?.maxSlopeOffset], MARKET_ADAPTER.DYNAMIC_WEIGHT_ASYMMETRIC_OFFSET_CLAMP),
|
|
188
|
+
clipPercentile: Number.isFinite(Number(botCfg?.clipPercentile))
|
|
189
|
+
? Number(botCfg.clipPercentile)
|
|
190
|
+
: MARKET_ADAPTER.DYNAMIC_WEIGHT_CLIP_PERCENTILE,
|
|
191
|
+
maxAsymmetryFactor: firstPositive([bot?.asymmetricBounds?.maxAsymmetryFactor, botCfg?.asymmetricBounds?.maxAsymmetryFactor], MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MAX_ASYMMETRY_FACTOR),
|
|
192
|
+
minScaleSlots: firstPositive([botCfg?.asymmetricBounds?.minScaleSlots], MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MIN_SCALE_SLOTS),
|
|
193
|
+
incrementPercent: Number.isFinite(Number(bot?.incrementPercent)) ? Number(bot.incrementPercent) : null,
|
|
194
|
+
erPeriod: Math.ceil(erPeriod),
|
|
195
|
+
warmupBars,
|
|
196
|
+
warmupBarsOverride: Number.isFinite(Number(opts.warmupBars)) && Number(opts.warmupBars) >= 0 ? Math.ceil(Number(opts.warmupBars)) : null,
|
|
197
|
+
clampMin,
|
|
198
|
+
clampMax,
|
|
199
|
+
notes,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Flatten the resolved config for the chart payload, dropping anything the page
|
|
204
|
+
* must not see (e.g. Infinity from a disabled threshold).
|
|
205
|
+
*/
|
|
206
|
+
function toGridSimPayload(cfg) {
|
|
207
|
+
if (!cfg)
|
|
208
|
+
return null;
|
|
209
|
+
return {
|
|
210
|
+
enabled: cfg.enabled === true,
|
|
211
|
+
botKey: cfg.botKey ?? null,
|
|
212
|
+
priceDeltaThresholdPercent: Number.isFinite(cfg.priceDeltaThresholdPercent) ? cfg.priceDeltaThresholdPercent : null,
|
|
213
|
+
priceSource: cfg.priceSource ?? SOURCE_CONSTANTS,
|
|
214
|
+
slopeDeltaThresholdPercent: Number.isFinite(cfg.slopeDeltaThresholdPercent) ? cfg.slopeDeltaThresholdPercent : null,
|
|
215
|
+
slopeSource: cfg.slopeSource ?? SOURCE_CONSTANTS,
|
|
216
|
+
slopeEnabled: cfg.slopeEnabled === true,
|
|
217
|
+
dynamicWeightEnabled: cfg.dynamicWeightEnabled === true,
|
|
218
|
+
lookbackBars: cfg.lookbackBars,
|
|
219
|
+
maxSlopePct: cfg.maxSlopePct,
|
|
220
|
+
neutralZonePct: cfg.neutralZonePct,
|
|
221
|
+
maxSlopeOffset: cfg.maxSlopeOffset,
|
|
222
|
+
clipPercentile: cfg.clipPercentile,
|
|
223
|
+
maxAsymmetryFactor: cfg.maxAsymmetryFactor,
|
|
224
|
+
minScaleSlots: cfg.minScaleSlots,
|
|
225
|
+
incrementPercent: cfg.incrementPercent,
|
|
226
|
+
erPeriod: cfg.erPeriod,
|
|
227
|
+
warmupBars: cfg.warmupBars,
|
|
228
|
+
warmupBarsOverride: Number.isFinite(cfg.warmupBarsOverride) ? cfg.warmupBarsOverride : null,
|
|
229
|
+
clampMin: Number.isFinite(cfg.clampMin) ? cfg.clampMin : null,
|
|
230
|
+
clampMax: Number.isFinite(cfg.clampMax) ? cfg.clampMax : null,
|
|
231
|
+
notes: Array.isArray(cfg.notes) ? cfg.notes.slice(0, 4) : [],
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
export { resolveGridResetSimConfig, toGridSimPayload };
|
|
235
|
+
//# sourceMappingURL=grid_reset_config.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
declare const GRID_RESET_NONE = 0;
|
|
2
|
+
declare const GRID_RESET_BOOTSTRAP = 1;
|
|
3
|
+
declare const GRID_RESET_PRICE = 2;
|
|
4
|
+
declare const GRID_RESET_SLOPE = 3;
|
|
5
|
+
declare function gridSimPositiveNumber(value: any, fallback: any): any;
|
|
6
|
+
declare function gridSimNonNegativeInt(value: any, fallback: any): any;
|
|
7
|
+
/**
|
|
8
|
+
* Average AMA slope in %/bar plus the trend/offset the grid build would use
|
|
9
|
+
* for that bar, mirroring `computeAmaSlopeWeights` steps 2b–3 (percentile clip
|
|
10
|
+
* → neutral zone → trend → slopeOffset). The delta trigger itself compares the
|
|
11
|
+
* UNCLIPPED `slopePct`; the clipped value only feeds the range tilt.
|
|
12
|
+
*/
|
|
13
|
+
declare function gridSimSlopeSignal(slopePct: any, clipThreshold: any, cfg: any): {
|
|
14
|
+
slopePct: null;
|
|
15
|
+
clippedSlopePct: null;
|
|
16
|
+
trend: null;
|
|
17
|
+
slopeOffset: number;
|
|
18
|
+
} | {
|
|
19
|
+
slopePct: number;
|
|
20
|
+
clippedSlopePct: number;
|
|
21
|
+
trend: null;
|
|
22
|
+
slopeOffset: number;
|
|
23
|
+
} | {
|
|
24
|
+
slopePct: number;
|
|
25
|
+
clippedSlopePct: number;
|
|
26
|
+
trend: string;
|
|
27
|
+
slopeOffset: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Replay the two market-adapter grid-recentering triggers over `amaSeries`
|
|
31
|
+
* (the chart's 1h AMA series, already in display orientation).
|
|
32
|
+
*
|
|
33
|
+
* @param {Array<number|null>} amaSeries
|
|
34
|
+
* @param {Object} cfg Resolved sim config (see resolveGridResetSimConfig):
|
|
35
|
+
* priceDeltaThresholdPercent, slopeDeltaThresholdPercent, slopeEnabled,
|
|
36
|
+
* erPeriod, warmupBars, lookbackBars, maxSlopePct, neutralZonePct,
|
|
37
|
+
* maxSlopeOffset, clipPercentile, clampMin, clampMax.
|
|
38
|
+
* @returns per-bar series (same length as `amaSeries`) + `events` + `stats`.
|
|
39
|
+
*/
|
|
40
|
+
declare function simulateGridResetSeries(amaSeries: any, cfg: any): {
|
|
41
|
+
center: any[];
|
|
42
|
+
reason: any[];
|
|
43
|
+
driftPct: any[];
|
|
44
|
+
slopePct: any[];
|
|
45
|
+
slopeDeltaPct: any[];
|
|
46
|
+
acceptedSlopePct: any[];
|
|
47
|
+
acceptedSlopeOffset: any[];
|
|
48
|
+
acceptedTrend: any[];
|
|
49
|
+
events: any[];
|
|
50
|
+
stats: {
|
|
51
|
+
bars: number;
|
|
52
|
+
resets: number;
|
|
53
|
+
resetsTotal: number;
|
|
54
|
+
priceResets: number;
|
|
55
|
+
slopeResets: number;
|
|
56
|
+
bootstrapIndex: any;
|
|
57
|
+
lastResetIndex: number | null;
|
|
58
|
+
barsSinceLastReset: number | null;
|
|
59
|
+
avgBarsBetweenResets: number | null;
|
|
60
|
+
warmupBars: any;
|
|
61
|
+
priceDeltaThresholdPercent: number | null;
|
|
62
|
+
slopeDeltaThresholdPercent: number | null;
|
|
63
|
+
slopeTriggerArmed: boolean;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export { simulateGridResetSeries, gridSimSlopeSignal, gridSimPositiveNumber, gridSimNonNegativeInt, GRID_RESET_NONE, GRID_RESET_BOOTSTRAP, GRID_RESET_PRICE, GRID_RESET_SLOPE, };
|
|
67
|
+
//# sourceMappingURL=grid_reset_sim.d.ts.map
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* Grid-reset simulation for the TradingView exporter.
|
|
4
|
+
*
|
|
5
|
+
* Replays the market adapter's two grid-recentering triggers over the chart's
|
|
6
|
+
* AMA series, exactly as `market_adapter/core/market_adapter_service.ts`
|
|
7
|
+
* decides them per cycle (see docs/GRID_RECALCULATION.md §3 and §4):
|
|
8
|
+
*
|
|
9
|
+
* A — AMA price delta (`market_adapter_delta_threshold`): the accepted
|
|
10
|
+
* center ratchets only when the AMA moves
|
|
11
|
+
* `|AMA − gridCenterPrice| / gridCenterPrice × 100 >= deltaThresholdPercent`
|
|
12
|
+
* (`deltaThresholdPercent` in the resolved adapter cfg).
|
|
13
|
+
*
|
|
14
|
+
* B — AMA slope delta (`market_adapter_ama_slope_delta_threshold`): gated
|
|
15
|
+
* behind the per-bot `asymmetricBounds` whitelist, fires when
|
|
16
|
+
* `|slopePct − gridRangeScalingAmaSlope.slopePct| >= amaSlopeThresholdPercent`
|
|
17
|
+
* (per-bar %, see `buildAmaSlopeResetDetails`).
|
|
18
|
+
*
|
|
19
|
+
* Ratchet semantics (both triggers): on a reset the accepted center moves to
|
|
20
|
+
* the current AMA **and** the accepted slope baseline is re-seeded to the
|
|
21
|
+
* current slope — the `advanceTriggeredBotState` chain in the service. The
|
|
22
|
+
* price trigger is evaluated first and the slope trigger only runs when no
|
|
23
|
+
* price trigger fired in the same bar, matching the service's if/if-else
|
|
24
|
+
* ordering. This is the same model the OHLC backtest uses
|
|
25
|
+
* (analysis/bot_fitting/backtest_bot_fitting.ts, `simulateForParams`).
|
|
26
|
+
*
|
|
27
|
+
* Deliberate scope limits (the chart replays the *decision*, not the runtime):
|
|
28
|
+
* - one evaluation per 1h bar, no staleness/gap/candle-count suppression
|
|
29
|
+
* gates (fresh closed candles are the norm in a candle file);
|
|
30
|
+
* - the accepted center is the value the grid would be built around, so the
|
|
31
|
+
* simulated range band is frozen between resets and re-tilts from the
|
|
32
|
+
* accepted slope at every reset;
|
|
33
|
+
* - the band is a faithful replay of the grid-build *bounds pipeline*
|
|
34
|
+
* (applyAsymmetricBounds → applyNarrowingSideGuard), but the narrowing
|
|
35
|
+
* guard is centered on the accepted AMA center rather than the live
|
|
36
|
+
* market/start price the runtime uses; the gap is bounded by the reset
|
|
37
|
+
* threshold and only shifts the tightening side by its slot floor;
|
|
38
|
+
* - RMS divergence, available-funds resizes and manual triggers are not
|
|
39
|
+
* simulated (out of scope for a candle chart).
|
|
40
|
+
*
|
|
41
|
+
* The functions below are embedded verbatim into the generated HTML via
|
|
42
|
+
* `embedFunctionSources`, so they may only reference module imports that are
|
|
43
|
+
* embedded alongside them (`computeAverageAmaSlopePct`,
|
|
44
|
+
* `createAmaSlopeClipTracker`, `percentileFromSorted`, `clamp`).
|
|
45
|
+
*/
|
|
46
|
+
import { computeAverageAmaSlopePct, createAmaSlopeClipTracker, } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
|
|
47
|
+
import { clamp } from '../../modules/order/utils/math.js';
|
|
48
|
+
// Reset reason codes. NONE = the accepted center is carried over unchanged
|
|
49
|
+
// (this is the vast majority of bars); the other three are the runtime's
|
|
50
|
+
// trigger reasons from docs/GRID_RECALCULATION.md.
|
|
51
|
+
const GRID_RESET_NONE = 0;
|
|
52
|
+
const GRID_RESET_BOOTSTRAP = 1;
|
|
53
|
+
const GRID_RESET_PRICE = 2;
|
|
54
|
+
const GRID_RESET_SLOPE = 3;
|
|
55
|
+
// Prefixed helpers: these run inside the generated page, where every embedded
|
|
56
|
+
// function shares one scope with the chart's own code.
|
|
57
|
+
function gridSimPositiveNumber(value, fallback) {
|
|
58
|
+
const n = Number(value);
|
|
59
|
+
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
60
|
+
}
|
|
61
|
+
function gridSimNonNegativeInt(value, fallback) {
|
|
62
|
+
const n = Number(value);
|
|
63
|
+
return Number.isFinite(n) && n >= 0 ? Math.ceil(n) : fallback;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Average AMA slope in %/bar plus the trend/offset the grid build would use
|
|
67
|
+
* for that bar, mirroring `computeAmaSlopeWeights` steps 2b–3 (percentile clip
|
|
68
|
+
* → neutral zone → trend → slopeOffset). The delta trigger itself compares the
|
|
69
|
+
* UNCLIPPED `slopePct`; the clipped value only feeds the range tilt.
|
|
70
|
+
*/
|
|
71
|
+
function gridSimSlopeSignal(slopePct, clipThreshold, cfg) {
|
|
72
|
+
const maxSlopePct = gridSimPositiveNumber(cfg?.maxSlopePct, 0.09);
|
|
73
|
+
const neutralZonePct = Number.isFinite(Number(cfg?.neutralZonePct)) ? Number(cfg.neutralZonePct) : 0;
|
|
74
|
+
const maxSlopeOffset = gridSimPositiveNumber(cfg?.maxSlopeOffset, 0.5);
|
|
75
|
+
// null/undefined/NaN all mean "no slope this bar" (computeAmaSlopeWeights'
|
|
76
|
+
// notReady path), never a real 0 %/bar slope.
|
|
77
|
+
if (slopePct == null || !Number.isFinite(Number(slopePct))) {
|
|
78
|
+
return { slopePct: null, clippedSlopePct: null, trend: null, slopeOffset: 0 };
|
|
79
|
+
}
|
|
80
|
+
const slope = Number(slopePct);
|
|
81
|
+
const bound = Number.isFinite(Number(clipThreshold)) ? Number(clipThreshold) : Infinity;
|
|
82
|
+
const clipped = Math.max(-bound, Math.min(bound, slope));
|
|
83
|
+
// Inclusive boundary (<=) matches ama_slope_model so an exact-zero slope
|
|
84
|
+
// stays NEUTRAL instead of flipping to DOWN.
|
|
85
|
+
if (Math.abs(clipped) <= neutralZonePct) {
|
|
86
|
+
return { slopePct: slope, clippedSlopePct: clipped, trend: null, slopeOffset: 0 };
|
|
87
|
+
}
|
|
88
|
+
const trend = clipped > 0 ? 'UP' : 'DOWN';
|
|
89
|
+
return {
|
|
90
|
+
slopePct: slope,
|
|
91
|
+
clippedSlopePct: clipped,
|
|
92
|
+
trend,
|
|
93
|
+
slopeOffset: clamp(clipped / maxSlopePct, -1, 1) * maxSlopeOffset,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Replay the two market-adapter grid-recentering triggers over `amaSeries`
|
|
98
|
+
* (the chart's 1h AMA series, already in display orientation).
|
|
99
|
+
*
|
|
100
|
+
* @param {Array<number|null>} amaSeries
|
|
101
|
+
* @param {Object} cfg Resolved sim config (see resolveGridResetSimConfig):
|
|
102
|
+
* priceDeltaThresholdPercent, slopeDeltaThresholdPercent, slopeEnabled,
|
|
103
|
+
* erPeriod, warmupBars, lookbackBars, maxSlopePct, neutralZonePct,
|
|
104
|
+
* maxSlopeOffset, clipPercentile, clampMin, clampMax.
|
|
105
|
+
* @returns per-bar series (same length as `amaSeries`) + `events` + `stats`.
|
|
106
|
+
*/
|
|
107
|
+
function simulateGridResetSeries(amaSeries, cfg) {
|
|
108
|
+
const n = Array.isArray(amaSeries) ? amaSeries.length : 0;
|
|
109
|
+
const priceThreshold = Number(cfg?.priceDeltaThresholdPercent);
|
|
110
|
+
const priceTriggerArmed = Number.isFinite(priceThreshold) && priceThreshold > 0;
|
|
111
|
+
const slopeThreshold = Number(cfg?.slopeDeltaThresholdPercent);
|
|
112
|
+
// Trigger B is double-gated in production: the asymmetricBounds whitelist
|
|
113
|
+
// AND a usable threshold (explicit per-bar % or the maxSlopePct factor).
|
|
114
|
+
const slopeTriggerArmed = cfg?.slopeEnabled === true
|
|
115
|
+
&& Number.isFinite(slopeThreshold)
|
|
116
|
+
&& slopeThreshold > 0;
|
|
117
|
+
const erPeriod = gridSimNonNegativeInt(cfg?.erPeriod, 1);
|
|
118
|
+
const lookbackBars = gridSimNonNegativeInt(cfg?.lookbackBars, 0);
|
|
119
|
+
const warmupBars = gridSimNonNegativeInt(cfg?.warmupBars, 0);
|
|
120
|
+
const clipPercentile = Number(cfg?.clipPercentile);
|
|
121
|
+
const clampMinValue = Number(cfg?.clampMin);
|
|
122
|
+
const clampMaxValue = Number(cfg?.clampMax);
|
|
123
|
+
// Mirrors clampGridPriceToBounds: only absolute bot bounds pin the center,
|
|
124
|
+
// and each side binds independently (a mixed absolute/"Nx" config clamps
|
|
125
|
+
// only on the absolute side).
|
|
126
|
+
const hasClampMin = Number.isFinite(clampMinValue) && clampMinValue > 0;
|
|
127
|
+
const hasClampMax = Number.isFinite(clampMaxValue) && clampMaxValue > 0;
|
|
128
|
+
const hasClamp = hasClampMin || hasClampMax;
|
|
129
|
+
const center = new Array(n).fill(null);
|
|
130
|
+
const reason = new Array(n).fill(GRID_RESET_NONE);
|
|
131
|
+
const driftPct = new Array(n).fill(null);
|
|
132
|
+
const slopePctSeries = new Array(n).fill(null);
|
|
133
|
+
const slopeDeltaPct = new Array(n).fill(null);
|
|
134
|
+
const acceptedSlopePct = new Array(n).fill(null);
|
|
135
|
+
const acceptedSlopeOffset = new Array(n).fill(null);
|
|
136
|
+
const acceptedTrend = new Array(n).fill(null);
|
|
137
|
+
const events = [];
|
|
138
|
+
if (n === 0) {
|
|
139
|
+
return {
|
|
140
|
+
center,
|
|
141
|
+
reason,
|
|
142
|
+
driftPct,
|
|
143
|
+
slopePct: slopePctSeries,
|
|
144
|
+
slopeDeltaPct,
|
|
145
|
+
acceptedSlopePct,
|
|
146
|
+
acceptedSlopeOffset,
|
|
147
|
+
acceptedTrend,
|
|
148
|
+
events,
|
|
149
|
+
stats: {
|
|
150
|
+
bars: 0,
|
|
151
|
+
resets: 0,
|
|
152
|
+
resetsTotal: 0,
|
|
153
|
+
priceResets: 0,
|
|
154
|
+
slopeResets: 0,
|
|
155
|
+
bootstrapIndex: null,
|
|
156
|
+
lastResetIndex: null,
|
|
157
|
+
barsSinceLastReset: 0,
|
|
158
|
+
avgBarsBetweenResets: null,
|
|
159
|
+
warmupBars,
|
|
160
|
+
priceDeltaThresholdPercent: priceTriggerArmed ? priceThreshold : null,
|
|
161
|
+
slopeDeltaThresholdPercent: slopeTriggerArmed ? slopeThreshold : null,
|
|
162
|
+
slopeTriggerArmed,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const clipTracker = createAmaSlopeClipTracker(erPeriod, lookbackBars, clipPercentile);
|
|
167
|
+
const readyBars = erPeriod + lookbackBars;
|
|
168
|
+
let acceptedCenter = null;
|
|
169
|
+
let acceptedSlope = null;
|
|
170
|
+
let acceptedOffset = 0;
|
|
171
|
+
let acceptedDir = null;
|
|
172
|
+
let lastResetIndex = null;
|
|
173
|
+
let resetCount = 0;
|
|
174
|
+
let priceResets = 0;
|
|
175
|
+
let slopeResets = 0;
|
|
176
|
+
for (let i = 0; i < n; i++) {
|
|
177
|
+
const ama = Number(amaSeries[i]);
|
|
178
|
+
const hasAma = Number.isFinite(ama) && ama > 0;
|
|
179
|
+
// Feed the clip tracker every bar (non-finite values keep their slot,
|
|
180
|
+
// exactly like the batch threshold). The chart's AMA is computed over
|
|
181
|
+
// the full candle file, so a growing-prefix percentile is the clip
|
|
182
|
+
// analogue of that full-history series; the production adapter instead
|
|
183
|
+
// recomputes the percentile each cycle over its retained warmup window.
|
|
184
|
+
// Either way the trigger compares the UNCLIPPED slope, so this affects
|
|
185
|
+
// only the range tilt, never reset timing.
|
|
186
|
+
const clipThreshold = clipTracker.push(hasAma ? ama : NaN);
|
|
187
|
+
let slopePct = null;
|
|
188
|
+
if (i >= readyBars) {
|
|
189
|
+
const past = Number(amaSeries[i - lookbackBars]);
|
|
190
|
+
if (hasAma && Number.isFinite(past) && past !== 0) {
|
|
191
|
+
const s = computeAverageAmaSlopePct(ama, past, lookbackBars);
|
|
192
|
+
if (Number.isFinite(s))
|
|
193
|
+
slopePct = s;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
slopePctSeries[i] = slopePct;
|
|
197
|
+
// Bars before AMA warmup carry no accepted state (the adapter keeps
|
|
198
|
+
// only post-warmup candles, so it has no center to drift from yet).
|
|
199
|
+
if (!hasAma || i < warmupBars) {
|
|
200
|
+
// A bar without a usable AMA cannot trigger anything, but the
|
|
201
|
+
// accepted state still carries over — otherwise the step line and
|
|
202
|
+
// the band would show a hole at every non-finite bar.
|
|
203
|
+
if (acceptedCenter != null) {
|
|
204
|
+
center[i] = acceptedCenter;
|
|
205
|
+
acceptedSlopePct[i] = acceptedSlope;
|
|
206
|
+
acceptedSlopeOffset[i] = acceptedOffset;
|
|
207
|
+
acceptedTrend[i] = acceptedDir;
|
|
208
|
+
}
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const signal = gridSimSlopeSignal(slopePct, clipThreshold, cfg);
|
|
212
|
+
// The runtime measures drift against the CLAMPED current center
|
|
213
|
+
// (`clampGridPriceToBounds`), not the raw AMA. With absolute bot bounds
|
|
214
|
+
// this pins the center at the bound, so drift collapses to zero instead
|
|
215
|
+
// of growing without limit — and the grid does not re-reset every bar
|
|
216
|
+
// while the AMA sits outside the configured range.
|
|
217
|
+
const currentCenter = hasClamp
|
|
218
|
+
? Math.min(hasClampMax ? clampMaxValue : Infinity, Math.max(hasClampMin ? clampMinValue : -Infinity, ama))
|
|
219
|
+
: ama;
|
|
220
|
+
if (acceptedCenter != null) {
|
|
221
|
+
driftPct[i] = Math.abs((currentCenter - acceptedCenter) / acceptedCenter) * 100;
|
|
222
|
+
if (slopePct != null && acceptedSlope != null) {
|
|
223
|
+
slopeDeltaPct[i] = Math.abs(slopePct - acceptedSlope);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
let fired = GRID_RESET_NONE;
|
|
227
|
+
if (acceptedCenter == null) {
|
|
228
|
+
// No accepted center yet = the adapter's initial AMA snapshot
|
|
229
|
+
// (`market_adapter_bootstrap`): accept, persist, and trigger once.
|
|
230
|
+
fired = GRID_RESET_BOOTSTRAP;
|
|
231
|
+
}
|
|
232
|
+
else if (priceTriggerArmed && driftPct[i] >= priceThreshold) {
|
|
233
|
+
fired = GRID_RESET_PRICE;
|
|
234
|
+
}
|
|
235
|
+
else if (slopeTriggerArmed && slopeDeltaPct[i] != null && slopeDeltaPct[i] >= slopeThreshold) {
|
|
236
|
+
fired = GRID_RESET_SLOPE;
|
|
237
|
+
}
|
|
238
|
+
if (fired !== GRID_RESET_NONE) {
|
|
239
|
+
const previousCenter = acceptedCenter;
|
|
240
|
+
acceptedCenter = currentCenter;
|
|
241
|
+
// Re-seed the accepted slope on EVERY reset (price and slope alike),
|
|
242
|
+
// mirroring advanceTriggeredBotState's `amaSlope || previous` chain.
|
|
243
|
+
if (signal.slopePct != null) {
|
|
244
|
+
acceptedSlope = signal.slopePct;
|
|
245
|
+
acceptedOffset = signal.slopeOffset;
|
|
246
|
+
acceptedDir = signal.trend;
|
|
247
|
+
}
|
|
248
|
+
reason[i] = fired;
|
|
249
|
+
resetCount++;
|
|
250
|
+
if (fired === GRID_RESET_PRICE)
|
|
251
|
+
priceResets++;
|
|
252
|
+
if (fired === GRID_RESET_SLOPE)
|
|
253
|
+
slopeResets++;
|
|
254
|
+
events.push({
|
|
255
|
+
index: i,
|
|
256
|
+
reason: fired,
|
|
257
|
+
center: acceptedCenter,
|
|
258
|
+
previousCenter,
|
|
259
|
+
deltaPct: driftPct[i],
|
|
260
|
+
slopePct: signal.slopePct,
|
|
261
|
+
slopeDeltaPct: slopeDeltaPct[i],
|
|
262
|
+
acceptedSlopePct: acceptedSlope,
|
|
263
|
+
acceptedSlopeOffset: acceptedOffset,
|
|
264
|
+
acceptedTrend: acceptedDir,
|
|
265
|
+
});
|
|
266
|
+
lastResetIndex = i;
|
|
267
|
+
}
|
|
268
|
+
center[i] = acceptedCenter;
|
|
269
|
+
acceptedSlopePct[i] = acceptedSlope;
|
|
270
|
+
acceptedSlopeOffset[i] = acceptedOffset;
|
|
271
|
+
acceptedTrend[i] = acceptedDir;
|
|
272
|
+
}
|
|
273
|
+
const resetIndices = events.map((e) => e.index);
|
|
274
|
+
const gaps = [];
|
|
275
|
+
for (let k = 1; k < resetIndices.length; k++)
|
|
276
|
+
gaps.push(resetIndices[k] - resetIndices[k - 1]);
|
|
277
|
+
return {
|
|
278
|
+
center,
|
|
279
|
+
reason,
|
|
280
|
+
driftPct,
|
|
281
|
+
slopePct: slopePctSeries,
|
|
282
|
+
slopeDeltaPct,
|
|
283
|
+
acceptedSlopePct,
|
|
284
|
+
acceptedSlopeOffset,
|
|
285
|
+
acceptedTrend,
|
|
286
|
+
events,
|
|
287
|
+
stats: {
|
|
288
|
+
bars: n,
|
|
289
|
+
// The bootstrap is not a delta reset: report resets without it so
|
|
290
|
+
// "how often does this grid recenter" stays honest.
|
|
291
|
+
resets: resetCount - (events.length > 0 ? 1 : 0),
|
|
292
|
+
resetsTotal: resetCount,
|
|
293
|
+
priceResets,
|
|
294
|
+
slopeResets,
|
|
295
|
+
bootstrapIndex: resetIndices.length > 0 ? resetIndices[0] : null,
|
|
296
|
+
lastResetIndex,
|
|
297
|
+
barsSinceLastReset: lastResetIndex == null ? null : (n - 1 - lastResetIndex),
|
|
298
|
+
avgBarsBetweenResets: gaps.length > 0 ? (gaps.reduce((a, b) => a + b, 0) / gaps.length) : null,
|
|
299
|
+
warmupBars,
|
|
300
|
+
priceDeltaThresholdPercent: priceTriggerArmed ? priceThreshold : null,
|
|
301
|
+
slopeDeltaThresholdPercent: slopeTriggerArmed ? slopeThreshold : null,
|
|
302
|
+
slopeTriggerArmed,
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
export { simulateGridResetSeries, gridSimSlopeSignal, gridSimPositiveNumber, gridSimNonNegativeInt, GRID_RESET_NONE, GRID_RESET_BOOTSTRAP, GRID_RESET_PRICE, GRID_RESET_SLOPE, };
|
|
307
|
+
//# sourceMappingURL=grid_reset_sim.js.map
|