dexbot 1.6.11 → 1.6.12
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 +35 -4
- package/README.md +2 -1
- package/analysis/README.md +2 -0
- package/analysis/tradingview/README.md +1 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/launcher_mode_detector.ts +9 -2
- 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/account_resolver.d.ts +1 -1
- package/dist/analysis/account_resolver.js +2 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -7
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
- package/dist/analysis/analyze_args.d.ts +31 -0
- package/dist/analysis/analyze_args.js +41 -0
- package/dist/analysis/analyze_dynamic_weight.js +7 -17
- package/dist/analysis/analyze_kalman.js +7 -17
- package/dist/analysis/analyze_regime.js +7 -17
- package/dist/analysis/analyze_regime_windows.js +8 -18
- package/dist/analysis/analyze_risk_profile.js +8 -18
- package/dist/analysis/analyze_trade_heatmap.js +7 -17
- package/dist/analysis/analyze_volatility.js +7 -17
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +220 -12
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +6 -5
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +11 -63
- package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
- package/dist/analysis/bot_fitting/shared_utils.js +2 -2
- package/dist/analysis/bot_key_utils.d.ts +18 -10
- package/dist/analysis/bot_key_utils.js +7 -4
- package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
- package/dist/analysis/chain_pool.d.ts +3 -1
- package/dist/analysis/chart_ui.d.ts +5 -2
- package/dist/analysis/chart_ui.js +6 -3
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +1 -1
- package/dist/analysis/fills_source.d.ts +2 -2
- package/dist/analysis/fills_source.js +14 -12
- package/dist/analysis/grid_correction_check.d.ts +1 -1
- package/dist/analysis/grid_correction_check.js +12 -11
- package/dist/analysis/math_utils.d.ts +7 -6
- package/dist/analysis/math_utils.js +5 -8
- package/dist/analysis/pnl_report.js +29 -29
- package/dist/analysis/price_sources.d.ts +8 -8
- package/dist/analysis/price_sources.js +5 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -1
- package/dist/analysis/trade_profitability.d.ts +23 -2
- package/dist/analysis/trade_profitability.js +50 -50
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
- package/dist/analysis/tradingview/analyze_tradingview.js +6 -5
- package/dist/analysis/tradingview/grid_reset_config.d.ts +41 -32
- package/dist/analysis/tradingview/grid_reset_config.js +23 -11
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -9
- package/dist/analysis/tradingview/grid_reset_sim.js +4 -3
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +18 -19
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -1
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +5 -5
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +5 -4
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +9 -3
- package/dist/analysis/trend_detection/huber_scale_variants.js +4 -4
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
- package/dist/credential-daemon.js +34 -20
- package/dist/dexbot.js +11 -11
- package/dist/market_adapter/candle_utils.d.ts +22 -18
- package/dist/market_adapter/candle_utils.js +24 -20
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
- package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
- package/dist/market_adapter/core/kibana_candles.d.ts +53 -18
- package/dist/market_adapter/core/kibana_candles.js +9 -7
- package/dist/market_adapter/core/kibana_client.d.ts +9 -1
- package/dist/market_adapter/core/kibana_client.js +8 -7
- package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +284 -117
- package/dist/market_adapter/core/market_adapter_service.js +137 -113
- package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
- package/dist/market_adapter/core/strategies/ama.js +2 -4
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
- package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +34 -6
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +7 -7
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
- package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
- package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
- package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
- package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
- package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
- package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
- package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +96 -224
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
- package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
- package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
- package/dist/market_adapter/inputs/kibana_source.js +2 -2
- package/dist/market_adapter/inputs/window_cache.d.ts +99 -94
- package/dist/market_adapter/inputs/window_cache.js +8 -8
- package/dist/market_adapter/interval_utils.d.ts +4 -4
- package/dist/market_adapter/log_format.d.ts +6 -6
- package/dist/market_adapter/log_format.js +28 -21
- package/dist/market_adapter/lp_chart_core.d.ts +22 -1
- package/dist/market_adapter/lp_chart_core.js +26 -192
- package/dist/market_adapter/lp_chart_runner.d.ts +7 -7
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
- package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
- package/dist/market_adapter/market_adapter.d.ts +94 -32
- package/dist/market_adapter/market_adapter.js +67 -48
- package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
- package/dist/market_adapter/utils/adapter_client.js +2 -2
- package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
- package/dist/market_adapter/utils/chain.d.ts +50 -41
- package/dist/market_adapter/utils/chain.js +40 -46
- package/dist/market_adapter/utils/data_discovery.d.ts +4 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
- package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
- package/dist/market_adapter/utils/file_lock.d.ts +28 -14
- package/dist/market_adapter/utils/file_lock.js +36 -32
- package/dist/market_adapter/utils/native_history.d.ts +9 -2
- package/dist/market_adapter/utils/native_history.js +35 -28
- package/dist/modules/account_bots.d.ts +577 -21
- package/dist/modules/account_bots.js +182 -158
- package/dist/modules/account_orders.d.ts +66 -30
- package/dist/modules/account_orders.js +22 -20
- package/dist/modules/authority_resolver.d.ts +12 -2
- package/dist/modules/authority_resolver.js +15 -8
- package/dist/modules/bitshares-native/chain_client.d.ts +38 -3
- package/dist/modules/bitshares-native/chain_client.js +45 -46
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
- package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
- package/dist/modules/bitshares-native/index.d.ts +1 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
- package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
- package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
- package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
- package/dist/modules/bitshares-native/serial/serializer.js +7 -13
- package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
- package/dist/modules/bitshares-native/serial/types.js +55 -62
- package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
- package/dist/modules/bitshares-native/signing_client.js +19 -14
- package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
- package/dist/modules/bitshares-native/subscriptions.js +12 -12
- package/dist/modules/bitshares-native/transport.d.ts +5 -4
- package/dist/modules/bitshares-native/transport.js +5 -4
- package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
- package/dist/modules/bitshares-native/tx/builder.js +4 -3
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
- package/dist/modules/bitshares_client.d.ts +45 -13
- package/dist/modules/bitshares_client.js +28 -19
- package/dist/modules/bot_defaults.d.ts +6 -15
- package/dist/modules/bot_defaults.js +1 -5
- package/dist/modules/bot_settings.d.ts +44 -10
- package/dist/modules/bot_settings.js +11 -8
- package/dist/modules/bots_file_lock.d.ts +6 -6
- package/dist/modules/bots_file_lock.js +16 -12
- package/dist/modules/broadcast_failure.d.ts +2 -2
- package/dist/modules/broadcast_failure.js +5 -4
- package/dist/modules/chain_keys.d.ts +42 -40
- package/dist/modules/chain_keys.js +53 -45
- package/dist/modules/chain_orders.d.ts +93 -59
- package/dist/modules/chain_orders.js +31 -23
- package/dist/modules/constants.d.ts +527 -31
- package/dist/modules/constants.js +15 -47
- package/dist/modules/cr_planner.d.ts +40 -2
- package/dist/modules/credential_policy.d.ts +68 -8
- package/dist/modules/credential_policy.js +37 -31
- package/dist/modules/credential_session_cache.d.ts +2 -2
- package/dist/modules/credit_pricing.d.ts +42 -6
- package/dist/modules/credit_pricing.js +44 -30
- package/dist/modules/credit_runtime.d.ts +276 -118
- package/dist/modules/credit_runtime.js +462 -165
- package/dist/modules/crypto/browser_provider.js +6 -4
- package/dist/modules/crypto/node_provider.js +1 -1
- package/dist/modules/crypto/pure_scrypt.js +35 -4
- package/dist/modules/crypto/pure_secp256k1.js +72 -26
- package/dist/modules/crypto/sync.d.ts +9 -9
- package/dist/modules/crypto/sync.js +16 -9
- package/dist/modules/dexbot_class.d.ts +195 -139
- package/dist/modules/dexbot_class.js +78 -28
- package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
- package/dist/modules/dexbot_cow_runtime.js +248 -206
- package/dist/modules/dexbot_credential_client.d.ts +19 -11
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
- package/dist/modules/dexbot_fill_runtime.js +48 -41
- package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
- package/dist/modules/dexbot_maintenance_runtime.js +108 -83
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
- package/dist/modules/dexbot_startup_runtime.js +43 -43
- package/dist/modules/dexbot_state_recovery.d.ts +13 -12
- package/dist/modules/dexbot_state_recovery.js +18 -13
- package/dist/modules/fund_registry.d.ts +4 -2
- package/dist/modules/fund_registry.js +10 -10
- package/dist/modules/general_settings.d.ts +30 -4
- package/dist/modules/graceful_shutdown.d.ts +3 -3
- package/dist/modules/graceful_shutdown.js +2 -2
- package/dist/modules/grid_price_source.d.ts +1 -1
- package/dist/modules/key_store.d.ts +14 -8
- package/dist/modules/key_store.js +7 -6
- package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
- package/dist/modules/launcher/adapter_requirement.js +5 -5
- package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
- package/dist/modules/launcher/bot_supervisor.js +12 -11
- package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +1 -1
- package/dist/modules/launcher/credential_daemon.d.ts +4 -4
- package/dist/modules/launcher/credential_daemon.js +2 -2
- package/dist/modules/launcher/credential_secret.d.ts +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
- package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
- package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
- package/dist/modules/launcher/status_reporting.d.ts +22 -14
- package/dist/modules/launcher/supervisor_control.d.ts +8 -1
- package/dist/modules/launcher/supervisor_control.js +4 -2
- package/dist/modules/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- package/dist/modules/node_manager.d.ts +41 -11
- package/dist/modules/node_manager.js +5 -4
- package/dist/modules/order/accounting.d.ts +53 -24
- package/dist/modules/order/accounting.js +16 -15
- package/dist/modules/order/async_lock.d.ts +5 -2
- package/dist/modules/order/async_lock.js +1 -1
- package/dist/modules/order/export.d.ts +7 -6
- package/dist/modules/order/export.js +1 -7
- package/dist/modules/order/format.d.ts +4 -4
- package/dist/modules/order/genesis_policy.d.ts +21 -18
- package/dist/modules/order/genesis_policy.js +12 -8
- package/dist/modules/order/grid.d.ts +142 -36
- package/dist/modules/order/grid.js +148 -123
- package/dist/modules/order/grid_reconcile.d.ts +21 -20
- package/dist/modules/order/grid_reconcile.js +13 -12
- package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
- package/dist/modules/order/grid_reconcile_internal.js +28 -19
- package/dist/modules/order/index.d.ts +263 -1
- package/dist/modules/order/logger.d.ts +45 -11
- package/dist/modules/order/logger.js +38 -40
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +225 -180
- package/dist/modules/order/manager.js +80 -83
- package/dist/modules/order/processed_fill_store.d.ts +18 -3
- package/dist/modules/order/processed_fill_store.js +16 -27
- package/dist/modules/order/strategy.d.ts +21 -13
- package/dist/modules/order/strategy.js +5 -6
- package/dist/modules/order/sync_engine.d.ts +91 -33
- package/dist/modules/order/sync_engine.js +84 -53
- package/dist/modules/order/utils/math.d.ts +157 -102
- package/dist/modules/order/utils/math.js +77 -38
- package/dist/modules/order/utils/order.d.ts +310 -110
- package/dist/modules/order/utils/order.js +122 -99
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +176 -26
- package/dist/modules/order/utils/system.js +86 -69
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +24 -22
- package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
- package/dist/modules/order/utils/withPoolRef.js +18 -12
- package/dist/modules/order/working_grid.d.ts +14 -13
- package/dist/modules/paths.d.ts +1 -4
- package/dist/modules/paths.js +1 -27
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.js +2 -1
- package/dist/modules/runtime.d.ts +7 -3
- package/dist/modules/runtime.js +4 -3
- package/dist/modules/runtime_settings.d.ts +15 -10
- package/dist/modules/runtime_settings.js +30 -24
- package/dist/modules/settings_merge.d.ts +29 -3
- package/dist/modules/settings_merge.js +56 -78
- package/dist/modules/socket_json_client.d.ts +7 -4
- package/dist/modules/storage/browser_adapter.d.ts +38 -53
- package/dist/modules/storage/browser_adapter.js +7 -30
- package/dist/modules/storage/index.d.ts +1 -1
- package/dist/modules/storage/node_adapter.d.ts +45 -27
- package/dist/modules/storage/node_adapter.js +9 -9
- package/dist/modules/storage/types.d.ts +5 -4
- package/dist/modules/types.d.ts +1071 -2
- package/dist/modules/types.js +4 -1
- package/dist/modules/utils/asset_symbols.d.ts +2 -1
- package/dist/modules/utils/asset_symbols.js +2 -1
- package/dist/modules/utils/errors.d.ts +9 -0
- package/dist/modules/utils/errors.js +23 -1
- package/dist/modules/utils/time_range.d.ts +1 -12
- package/dist/modules/utils/time_range.js +1 -1
- package/dist/modules/validate_profiles.js +53 -43
- package/dist/modules/version_notice.d.ts +14 -3
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +29 -27
- package/dist/pm2.js +5 -5
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- package/dist/scripts/analyze-orders.d.ts +77 -9
- package/dist/scripts/analyze-orders.js +65 -40
- package/dist/scripts/chart_command.d.ts +27 -18
- package/dist/scripts/chart_command.js +13 -11
- package/dist/scripts/check_any.d.ts +18 -0
- package/dist/scripts/check_any.js +126 -0
- package/dist/scripts/diagnose-pool-history.js +12 -7
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -7
- package/dist/scripts/runner.js +1 -1
- package/dist/scripts/test-credit-renewal.js +30 -21
- package/dist/scripts/update.d.ts +10 -5
- package/dist/scripts/update.js +168 -103
- package/dist/scripts/update_dist_freshness.js +1 -0
- package/dist/scripts/update_layout.d.ts +61 -0
- package/dist/scripts/update_layout.js +180 -0
- package/dist/scripts/validate_bots.js +2 -1
- package/dist/scripts/verify-browser-bundle.js +8 -0
- package/dist/unlock.d.ts +28 -3
- package/dist/unlock.js +63 -35
- package/docs/BITSHARES_ONBOARDING.md +2 -0
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +10 -9
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
- package/docs/GRID_RECALCULATION.md +4 -2
- package/docs/GRID_RECONCILE.md +14 -3
- package/docs/LIFECYCLE.md +11 -11
- package/docs/MPA_CREDIT_USAGE.md +22 -3
- package/docs/README.md +14 -3
- package/docs/architecture.md +12 -9
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +6 -1
- package/modules/README.md +4 -1
- package/package.json +4 -1
|
@@ -93,8 +93,11 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
93
93
|
// ── 2. market_adapter_settings.json (globals → pair → bot)
|
|
94
94
|
const botCfg = bot ? resolveBotCfg(bot, baseCfg) : baseCfg;
|
|
95
95
|
const settings = loadMarketAdapterSettings();
|
|
96
|
-
const pair = bot ? findPairForBot(bot, settings?.pairs) : null;
|
|
97
|
-
const
|
|
96
|
+
const pair = bot ? findPairForBot(bot, Array.isArray(settings?.pairs) ? settings.pairs : []) : null;
|
|
97
|
+
const pairObj = pair;
|
|
98
|
+
const botOverride = pairObj?.botOverrides
|
|
99
|
+
? (pairObj.botOverrides[String(bot?.name)] || null)
|
|
100
|
+
: null;
|
|
98
101
|
const layers = [
|
|
99
102
|
{ name: SOURCE_ADAPTER_BOT, value: botOverride, keys: [['deltaThresholdPercent']] },
|
|
100
103
|
{ name: SOURCE_ADAPTER_PAIR, value: pair?.marketAdapterSettings, keys: [['deltaThresholdPercent']] },
|
|
@@ -147,12 +150,21 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
147
150
|
// adapter service so the chart replay fires the same Δs resets production
|
|
148
151
|
// does. Per-bot override wins; else the global enable + value; else legacy 1.
|
|
149
152
|
const resolveSlopePersistBars = () => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
// Mirror resolveAmaSlopePersistBars (market_adapter_service): explicit
|
|
154
|
+
// `persistBars >= 1` wins, `0` disables, and `persistEnabled: false` is a
|
|
155
|
+
// real tri-state override that must beat the global `true`.
|
|
156
|
+
const rawBars = botCfg?.amaSlope?.persistBars ?? botCfg?.amaSlopePersistBars;
|
|
157
|
+
const explicit = (rawBars === null || rawBars === undefined) ? NaN : Number(rawBars);
|
|
158
|
+
if (Number.isFinite(explicit)) {
|
|
159
|
+
if (explicit >= 1)
|
|
160
|
+
return Math.round(explicit);
|
|
161
|
+
if (explicit === 0)
|
|
162
|
+
return 1;
|
|
163
|
+
}
|
|
164
|
+
const override = botCfg?.amaSlope?.persistEnabled ?? botCfg?.amaSlopePersistEnabled;
|
|
165
|
+
const enabled = override === false ? false
|
|
166
|
+
: override === true ? true
|
|
167
|
+
: MARKET_ADAPTER.AMA_SLOPE_PERSIST_ENABLED === true;
|
|
156
168
|
if (!enabled)
|
|
157
169
|
return 1;
|
|
158
170
|
const bars = Number(MARKET_ADAPTER.AMA_SLOPE_PERSIST_BARS);
|
|
@@ -177,7 +189,7 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
177
189
|
return null;
|
|
178
190
|
try {
|
|
179
191
|
const bound = resolveConfiguredPriceBound(raw, fallback, 1, mode);
|
|
180
|
-
return Number.isFinite(bound) && bound > 0 ? Number(bound) : null;
|
|
192
|
+
return bound != null && Number.isFinite(bound) && bound > 0 ? Number(bound) : null;
|
|
181
193
|
}
|
|
182
194
|
catch (_err) {
|
|
183
195
|
return null;
|
|
@@ -198,7 +210,7 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
198
210
|
slopePersistBars: resolveSlopePersistBars(),
|
|
199
211
|
maxSlopePct: firstPositive([botCfg?.amaSlope?.maxSlopePct], MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_MAX_SLOPE_PCT),
|
|
200
212
|
neutralZonePct: Number.isFinite(Number(botCfg?.amaSlope?.neutralZonePct))
|
|
201
|
-
? Number(botCfg
|
|
213
|
+
? Number(botCfg?.amaSlope?.neutralZonePct)
|
|
202
214
|
: MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_NEUTRAL_ZONE_PCT,
|
|
203
215
|
maxSlopeOffset: firstPositive([botCfg?.maxSlopeOffset], MARKET_ADAPTER.DYNAMIC_WEIGHT_ASYMMETRIC_OFFSET_CLAMP),
|
|
204
216
|
clipPercentile: Number.isFinite(Number(botCfg?.clipPercentile))
|
|
@@ -206,7 +218,7 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
206
218
|
: MARKET_ADAPTER.DYNAMIC_WEIGHT_CLIP_PERCENTILE,
|
|
207
219
|
maxAsymmetryFactor: firstPositive([bot?.asymmetricBounds?.maxAsymmetryFactor, botCfg?.asymmetricBounds?.maxAsymmetryFactor], MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MAX_ASYMMETRY_FACTOR),
|
|
208
220
|
minScaleSlots: firstPositive([botCfg?.asymmetricBounds?.minScaleSlots], MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MIN_SCALE_SLOTS),
|
|
209
|
-
incrementPercent: Number.isFinite(Number(bot?.incrementPercent)) ? Number(bot
|
|
221
|
+
incrementPercent: Number.isFinite(Number(bot?.incrementPercent)) ? Number(bot?.incrementPercent) : null,
|
|
210
222
|
erPeriod: Math.ceil(erPeriod),
|
|
211
223
|
warmupBars,
|
|
212
224
|
warmupBarsOverride: Number.isFinite(Number(opts.warmupBars)) && Number(opts.warmupBars) >= 0 ? Math.ceil(Number(opts.warmupBars)) : null,
|
|
@@ -1,16 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Grid-reset simulation for the TradingView exporter.
|
|
3
|
+
*
|
|
4
|
+
* Replays the market adapter's two grid-recentering triggers over the chart's
|
|
5
|
+
* AMA series, exactly as `market_adapter/core/market_adapter_service.ts`
|
|
6
|
+
* decides them per cycle (see docs/GRID_RECALCULATION.md §3 and §4):
|
|
7
|
+
*
|
|
8
|
+
* A — AMA price delta (`market_adapter_delta_threshold`): the accepted
|
|
9
|
+
* center ratchets only when the AMA moves
|
|
10
|
+
* `|AMA − gridCenterPrice| / gridCenterPrice × 100 >= deltaThresholdPercent`
|
|
11
|
+
* (`deltaThresholdPercent` in the resolved adapter cfg).
|
|
12
|
+
*
|
|
13
|
+
* B — AMA slope delta (`market_adapter_ama_slope_delta_threshold`): gated
|
|
14
|
+
* behind the per-bot `asymmetricBounds` whitelist, fires when
|
|
15
|
+
* `|slopePct − gridRangeScalingAmaSlope.slopePct| >= amaSlopeThresholdPercent`
|
|
16
|
+
* (per-bar %, see `buildAmaSlopeResetDetails`).
|
|
17
|
+
*
|
|
18
|
+
* Ratchet semantics (both triggers): on a reset the accepted center moves to
|
|
19
|
+
* the current AMA **and** the accepted slope baseline is re-seeded to the
|
|
20
|
+
* current slope — the `advanceTriggeredBotState` chain in the service. The
|
|
21
|
+
* price trigger is evaluated first and the slope trigger only runs when no
|
|
22
|
+
* price trigger fired in the same bar, matching the service's if/if-else
|
|
23
|
+
* ordering. This is the same model the OHLC backtest uses
|
|
24
|
+
* (analysis/bot_fitting/backtest_bot_fitting.ts, `simulateForParams`).
|
|
25
|
+
*
|
|
26
|
+
* Deliberate scope limits (the chart replays the *decision*, not the runtime):
|
|
27
|
+
* - one evaluation per 1h bar, no staleness/gap/candle-count suppression
|
|
28
|
+
* gates (fresh closed candles are the norm in a candle file);
|
|
29
|
+
* - the accepted center is the value the grid would be built around, so the
|
|
30
|
+
* simulated range band is frozen between resets and re-tilts from the
|
|
31
|
+
* accepted slope at every reset;
|
|
32
|
+
* - the band is a faithful replay of the grid-build *bounds pipeline*
|
|
33
|
+
* (applyAsymmetricBounds → applyNarrowingSideGuard), but the narrowing
|
|
34
|
+
* guard is centered on the accepted AMA center rather than the live
|
|
35
|
+
* market/start price the runtime uses; the gap is bounded by the reset
|
|
36
|
+
* threshold and only shifts the tightening side by its slot floor;
|
|
37
|
+
* - RMS divergence, available-funds resizes and manual triggers are not
|
|
38
|
+
* simulated (out of scope for a candle chart).
|
|
39
|
+
*
|
|
40
|
+
* The functions below are embedded verbatim into the generated HTML via
|
|
41
|
+
* `embedFunctionSources`, so they may only reference module imports that are
|
|
42
|
+
* embedded alongside them (`computeAverageAmaSlopePct`,
|
|
43
|
+
* `createAmaSlopeClipTracker`, `percentileFromSorted`, `clamp`).
|
|
44
|
+
*/
|
|
45
|
+
import { computeHuberWindowSlopePct } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
|
|
1
46
|
declare const GRID_RESET_NONE = 0;
|
|
2
47
|
declare const GRID_RESET_BOOTSTRAP = 1;
|
|
48
|
+
interface GridResetEvent {
|
|
49
|
+
index: number;
|
|
50
|
+
reason?: unknown;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
interface GridSimCfg {
|
|
54
|
+
clampMin?: number | null;
|
|
55
|
+
clampMax?: number | null;
|
|
56
|
+
clipPercentile?: number | null;
|
|
57
|
+
erPeriod?: number;
|
|
58
|
+
lookbackBars?: number;
|
|
59
|
+
maxSlopeOffset?: number;
|
|
60
|
+
maxSlopePct?: number;
|
|
61
|
+
neutralZonePct?: number;
|
|
62
|
+
priceDeltaThresholdPercent?: number;
|
|
63
|
+
slopeDeltaThresholdPercent?: number;
|
|
64
|
+
slopeEnabled?: boolean;
|
|
65
|
+
slopePersistBars?: number;
|
|
66
|
+
warmupBars?: number;
|
|
67
|
+
slopeEstimator?: ((amaValues: unknown, index: number, lookbackBars: unknown) => number | null) | null;
|
|
68
|
+
}
|
|
3
69
|
declare const GRID_RESET_PRICE = 2;
|
|
4
70
|
declare const GRID_RESET_SLOPE = 3;
|
|
5
|
-
declare function gridSimPositiveNumber(value:
|
|
6
|
-
declare function gridSimNonNegativeInt(value:
|
|
71
|
+
declare function gridSimPositiveNumber(value: unknown, fallback: number): number;
|
|
72
|
+
declare function gridSimNonNegativeInt(value: unknown, fallback: number): number;
|
|
7
73
|
/**
|
|
8
74
|
* Average AMA slope in %/bar plus the trend/offset the grid build would use
|
|
9
75
|
* for that bar, mirroring `computeAmaSlopeWeights` steps 2b–3 (percentile clip
|
|
10
76
|
* → neutral zone → trend → slopeOffset). The delta trigger itself compares the
|
|
11
77
|
* UNCLIPPED `slopePct`; the clipped value only feeds the range tilt.
|
|
12
78
|
*/
|
|
13
|
-
declare function gridSimSlopeSignal(slopePct:
|
|
79
|
+
declare function gridSimSlopeSignal(slopePct: unknown, clipThreshold: unknown, cfg: GridSimCfg): {
|
|
14
80
|
slopePct: null;
|
|
15
81
|
clippedSlopePct: null;
|
|
16
82
|
trend: null;
|
|
@@ -35,7 +101,7 @@ declare function gridSimSlopeSignal(slopePct: any, clipThreshold: any, cfg: any)
|
|
|
35
101
|
* model without touching this module — it takes the whole series plus the index
|
|
36
102
|
* because windowed estimators need the window, not just the two endpoints.
|
|
37
103
|
*/
|
|
38
|
-
declare function gridSimResolveSlopeEstimator(cfg:
|
|
104
|
+
declare function gridSimResolveSlopeEstimator(cfg: GridSimCfg): typeof computeHuberWindowSlopePct;
|
|
39
105
|
/**
|
|
40
106
|
* Replay the two market-adapter grid-recentering triggers over `amaSeries`
|
|
41
107
|
* (the chart's 1h AMA series, already in display orientation).
|
|
@@ -47,7 +113,7 @@ declare function gridSimResolveSlopeEstimator(cfg: any): any;
|
|
|
47
113
|
* maxSlopeOffset, clipPercentile, clampMin, clampMax.
|
|
48
114
|
* @returns per-bar series (same length as `amaSeries`) + `events` + `stats`.
|
|
49
115
|
*/
|
|
50
|
-
declare function simulateGridResetSeries(amaSeries:
|
|
116
|
+
declare function simulateGridResetSeries(amaSeries: unknown, cfg: GridSimCfg): {
|
|
51
117
|
center: any[];
|
|
52
118
|
reason: any[];
|
|
53
119
|
driftPct: any[];
|
|
@@ -56,21 +122,21 @@ declare function simulateGridResetSeries(amaSeries: any, cfg: any): {
|
|
|
56
122
|
acceptedSlopePct: any[];
|
|
57
123
|
acceptedSlopeOffset: any[];
|
|
58
124
|
acceptedTrend: any[];
|
|
59
|
-
events:
|
|
125
|
+
events: GridResetEvent[];
|
|
60
126
|
stats: {
|
|
61
127
|
bars: number;
|
|
62
128
|
resets: number;
|
|
63
129
|
resetsTotal: number;
|
|
64
130
|
priceResets: number;
|
|
65
131
|
slopeResets: number;
|
|
66
|
-
bootstrapIndex:
|
|
132
|
+
bootstrapIndex: number | null;
|
|
67
133
|
lastResetIndex: number | null;
|
|
68
134
|
barsSinceLastReset: number | null;
|
|
69
135
|
avgBarsBetweenResets: number | null;
|
|
70
|
-
warmupBars:
|
|
136
|
+
warmupBars: number;
|
|
71
137
|
priceDeltaThresholdPercent: number | null;
|
|
72
138
|
slopeDeltaThresholdPercent: number | null;
|
|
73
|
-
slopePersistBars:
|
|
139
|
+
slopePersistBars: number;
|
|
74
140
|
slopeTriggerArmed: boolean;
|
|
75
141
|
};
|
|
76
142
|
};
|
|
@@ -120,7 +120,8 @@ function gridSimResolveSlopeEstimator(cfg) {
|
|
|
120
120
|
* @returns per-bar series (same length as `amaSeries`) + `events` + `stats`.
|
|
121
121
|
*/
|
|
122
122
|
function simulateGridResetSeries(amaSeries, cfg) {
|
|
123
|
-
const
|
|
123
|
+
const amaArr = Array.isArray(amaSeries) ? amaSeries : [];
|
|
124
|
+
const n = amaArr.length;
|
|
124
125
|
const priceThreshold = Number(cfg?.priceDeltaThresholdPercent);
|
|
125
126
|
const priceTriggerArmed = Number.isFinite(priceThreshold) && priceThreshold > 0;
|
|
126
127
|
const slopeThreshold = Number(cfg?.slopeDeltaThresholdPercent);
|
|
@@ -198,7 +199,7 @@ function simulateGridResetSeries(amaSeries, cfg) {
|
|
|
198
199
|
let slopePersistCount = 0;
|
|
199
200
|
let slopePersistDir = 0;
|
|
200
201
|
for (let i = 0; i < n; i++) {
|
|
201
|
-
const ama = Number(
|
|
202
|
+
const ama = Number(amaArr[i]);
|
|
202
203
|
const hasAma = Number.isFinite(ama) && ama > 0;
|
|
203
204
|
// Feed the clip tracker every bar (non-finite values keep their slot,
|
|
204
205
|
// exactly like the batch threshold). The chart's AMA is computed over
|
|
@@ -210,7 +211,7 @@ function simulateGridResetSeries(amaSeries, cfg) {
|
|
|
210
211
|
const clipThreshold = clipTracker.push(hasAma ? ama : NaN);
|
|
211
212
|
let slopePct = null;
|
|
212
213
|
if (hasAma && i >= readyBars) {
|
|
213
|
-
const s = estimateSlope(
|
|
214
|
+
const s = estimateSlope(amaArr, i, lookbackBars);
|
|
214
215
|
if (Number.isFinite(s))
|
|
215
216
|
slopePct = s;
|
|
216
217
|
}
|
|
@@ -1,9 +1,74 @@
|
|
|
1
1
|
import { normalizeCandle } from '../math_utils.js';
|
|
2
|
-
|
|
2
|
+
interface MarketMeta {
|
|
3
|
+
intervalSeconds?: unknown;
|
|
4
|
+
pool?: unknown;
|
|
5
|
+
poolId?: unknown;
|
|
6
|
+
feed?: unknown;
|
|
7
|
+
assetA?: {
|
|
8
|
+
symbol?: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
};
|
|
11
|
+
assetB?: {
|
|
12
|
+
symbol?: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
interface AmaDefaultsInput {
|
|
17
|
+
amaDefaults?: {
|
|
18
|
+
erPeriod?: unknown;
|
|
19
|
+
fastPeriod?: unknown;
|
|
20
|
+
slowPeriod?: unknown;
|
|
21
|
+
} | null;
|
|
22
|
+
amaErPeriod?: unknown;
|
|
23
|
+
amaFastPeriod?: unknown;
|
|
24
|
+
amaSlowPeriod?: unknown;
|
|
25
|
+
}
|
|
26
|
+
declare function loadMarketProfiles(filePath?: string | null | undefined): {
|
|
27
|
+
profiles?: Array<Record<string, unknown>>;
|
|
28
|
+
} | null;
|
|
3
29
|
declare const TRADINGVIEW_PREFS_KEY_PREFIX = "dexbot2-tradingview-uplot-v3";
|
|
4
30
|
declare const TRADINGVIEW_SYNC_KEY = "dexbot2-tradingview-sync";
|
|
5
|
-
declare function sanitizeStorageComponent(value:
|
|
6
|
-
declare function resolveChartStorageKey(meta?:
|
|
7
|
-
|
|
31
|
+
declare function sanitizeStorageComponent(value: unknown, fallback: string): string;
|
|
32
|
+
declare function resolveChartStorageKey(meta?: MarketMeta, baseIntervalSeconds?: number): string;
|
|
33
|
+
interface TvChartInput extends AmaDefaultsInput {
|
|
34
|
+
candles?: unknown[];
|
|
35
|
+
meta?: MarketMeta;
|
|
36
|
+
defaultTimeframe?: string;
|
|
37
|
+
marketProfiles?: unknown;
|
|
38
|
+
smaPeriod?: number;
|
|
39
|
+
smaEnabled?: boolean;
|
|
40
|
+
amaEnabled?: boolean;
|
|
41
|
+
vwapEnabled?: boolean;
|
|
42
|
+
vwapBars?: number;
|
|
43
|
+
priceScale?: string;
|
|
44
|
+
rangeWidthPct?: number;
|
|
45
|
+
rangeSpan?: number;
|
|
46
|
+
grid?: {
|
|
47
|
+
minPrice?: unknown;
|
|
48
|
+
maxPrice?: unknown;
|
|
49
|
+
incrementPercent?: number | null;
|
|
50
|
+
maxAsymmetryFactor?: number | null;
|
|
51
|
+
minScaleSlots?: number | null;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
} | null;
|
|
54
|
+
gridSim?: {
|
|
55
|
+
enabled?: boolean;
|
|
56
|
+
[key: string]: unknown;
|
|
57
|
+
} | null;
|
|
58
|
+
gridBounds?: {
|
|
59
|
+
low?: unknown;
|
|
60
|
+
high?: unknown;
|
|
61
|
+
};
|
|
62
|
+
orders?: {
|
|
63
|
+
buys?: unknown[];
|
|
64
|
+
sells?: unknown[];
|
|
65
|
+
};
|
|
66
|
+
storageKey?: string;
|
|
67
|
+
defaultPairMode?: string;
|
|
68
|
+
updateMarkerTsSec?: number | null;
|
|
69
|
+
updateMarkerNewBars?: number | null;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
declare function generateHTML(data: TvChartInput, title?: string): string;
|
|
8
73
|
export { generateHTML, normalizeCandle, loadMarketProfiles, resolveChartStorageKey, sanitizeStorageComponent, TRADINGVIEW_PREFS_KEY_PREFIX, TRADINGVIEW_SYNC_KEY };
|
|
9
74
|
//# sourceMappingURL=tradingview_uplot_chart_generator.d.ts.map
|
|
@@ -23,10 +23,11 @@ const RANGE_SPAN_DEFAULT = 1.55;
|
|
|
23
23
|
function inferBaseIntervalSeconds(candles, fallback = 3600) {
|
|
24
24
|
if (!Array.isArray(candles) || candles.length < 2)
|
|
25
25
|
return fallback;
|
|
26
|
+
const rows = candles;
|
|
26
27
|
const deltas = [];
|
|
27
|
-
for (let i = 1; i <
|
|
28
|
-
const prev = Number(
|
|
29
|
-
const curr = Number(
|
|
28
|
+
for (let i = 1; i < rows.length; i++) {
|
|
29
|
+
const prev = Number(rows[i - 1]?.time);
|
|
30
|
+
const curr = Number(rows[i]?.time);
|
|
30
31
|
if (!Number.isFinite(prev) || !Number.isFinite(curr))
|
|
31
32
|
continue;
|
|
32
33
|
const d = curr - prev;
|
|
@@ -52,29 +53,31 @@ function loadMarketProfiles(filePath = PATHS.PROFILES.MARKET_PROFILES_JSON) {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
function findMarketProfile(profiles, meta = {}) {
|
|
55
|
-
const
|
|
56
|
+
const container = profiles;
|
|
57
|
+
const entries = Array.isArray(container?.profiles) ? container.profiles : [];
|
|
56
58
|
if (!entries.length)
|
|
57
59
|
return null;
|
|
58
60
|
const assetA = meta.assetA?.symbol || meta.assetA?.id || meta.assetA;
|
|
59
61
|
const assetB = meta.assetB?.symbol || meta.assetB?.id || meta.assetB;
|
|
60
62
|
const intervalSeconds = Number(meta.intervalSeconds);
|
|
61
|
-
return entries.find((entry) => {
|
|
63
|
+
return (entries.find((entry) => {
|
|
62
64
|
if (!entry || typeof entry !== 'object')
|
|
63
65
|
return false;
|
|
66
|
+
const e = entry;
|
|
64
67
|
if (assetA && assetB) {
|
|
65
|
-
const matchesPair = (String(
|
|
66
|
-
&& (String(
|
|
68
|
+
const matchesPair = (String(e.assetA) === String(assetA) || String(e.assetAId) === String(assetA))
|
|
69
|
+
&& (String(e.assetB) === String(assetB) || String(e.assetBId) === String(assetB));
|
|
67
70
|
if (!matchesPair)
|
|
68
71
|
return false;
|
|
69
72
|
}
|
|
70
73
|
else {
|
|
71
74
|
return false;
|
|
72
75
|
}
|
|
73
|
-
if (Number.isFinite(intervalSeconds) && intervalSeconds > 0 && Number(
|
|
76
|
+
if (Number.isFinite(intervalSeconds) && intervalSeconds > 0 && Number(e.intervalSeconds) !== intervalSeconds) {
|
|
74
77
|
return false;
|
|
75
78
|
}
|
|
76
79
|
return true;
|
|
77
|
-
}) || null;
|
|
80
|
+
}) || null);
|
|
78
81
|
}
|
|
79
82
|
function resolveAmaDefaults({ meta, data, marketProfiles } = {}) {
|
|
80
83
|
const amaDefaultsSource = MARKET_ADAPTER.AMAS.AMA3;
|
|
@@ -82,15 +85,15 @@ function resolveAmaDefaults({ meta, data, marketProfiles } = {}) {
|
|
|
82
85
|
const profileAmaKey = profile?.defaultAma && profile.amas && profile.amas[profile.defaultAma]
|
|
83
86
|
? profile.defaultAma
|
|
84
87
|
: null;
|
|
85
|
-
const profileAma = profileAmaKey ? profile.amas[profileAmaKey] : null;
|
|
88
|
+
const profileAma = profileAmaKey && profile?.amas ? profile.amas[profileAmaKey] : null;
|
|
86
89
|
const source = data?.amaDefaults || profileAma || amaDefaultsSource;
|
|
87
90
|
return {
|
|
88
91
|
erPeriod: Math.max(1, Math.round(Number(data?.amaErPeriod ?? source.erPeriod))),
|
|
89
92
|
fastPeriod: Number.isFinite(Number(data?.amaFastPeriod))
|
|
90
|
-
? Number(data
|
|
93
|
+
? Number(data?.amaFastPeriod)
|
|
91
94
|
: Number(source.fastPeriod),
|
|
92
95
|
slowPeriod: Number.isFinite(Number(data?.amaSlowPeriod))
|
|
93
|
-
? Number(data
|
|
96
|
+
? Number(data?.amaSlowPeriod)
|
|
94
97
|
: Number(source.slowPeriod),
|
|
95
98
|
};
|
|
96
99
|
}
|
|
@@ -123,7 +126,6 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
123
126
|
? Number(meta.intervalSeconds)
|
|
124
127
|
: inferBaseIntervalSeconds(candles, 3600);
|
|
125
128
|
const timeframes = [
|
|
126
|
-
{ label: '1h', seconds: 3600 },
|
|
127
129
|
{ label: '4h', seconds: 14400 },
|
|
128
130
|
{ label: '1d', seconds: 86400 },
|
|
129
131
|
{ label: '1w', seconds: 604800 },
|
|
@@ -230,8 +232,8 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
230
232
|
orderBuys: Array.isArray(data.orders?.buys) ? data.orders.buys.map(Number).filter(Number.isFinite) : [],
|
|
231
233
|
orderSells: Array.isArray(data.orders?.sells) ? data.orders.sells.map(Number).filter(Number.isFinite) : [],
|
|
232
234
|
gridBounds: {
|
|
233
|
-
low: Number.isFinite(Number(data.gridBounds?.low)) && Number(data.gridBounds
|
|
234
|
-
high: Number.isFinite(Number(data.gridBounds?.high)) && Number(data.gridBounds
|
|
235
|
+
low: Number.isFinite(Number(data.gridBounds?.low)) && Number(data.gridBounds?.low) > 0 ? Number(data.gridBounds?.low) : null,
|
|
236
|
+
high: Number.isFinite(Number(data.gridBounds?.high)) && Number(data.gridBounds?.high) > 0 ? Number(data.gridBounds?.high) : null,
|
|
235
237
|
},
|
|
236
238
|
updateMarkerTsSec: Number(data.updateMarkerTsSec) > 0 ? Number(data.updateMarkerTsSec) : null,
|
|
237
239
|
updateMarkerNewBars: Number(data.updateMarkerNewBars) || null,
|
|
@@ -246,7 +248,7 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
246
248
|
poolLabel,
|
|
247
249
|
intervalLabel,
|
|
248
250
|
amaDefaultsSource: marketProfiles ? 'market_profiles' : 'constants',
|
|
249
|
-
volumeIsCount: !!
|
|
251
|
+
volumeIsCount: !!meta?.feed,
|
|
250
252
|
};
|
|
251
253
|
return `<!doctype html>
|
|
252
254
|
<html lang="en">
|
|
@@ -1002,9 +1004,6 @@ function generateHTML(data, title = 'TradingView Style Research') {
|
|
|
1002
1004
|
const d = new Date(ts * 1000);
|
|
1003
1005
|
return d.toLocaleString(undefined, { year: 'numeric', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' });
|
|
1004
1006
|
}
|
|
1005
|
-
function pad2(n) {
|
|
1006
|
-
return String(n).padStart(2, '0');
|
|
1007
|
-
}
|
|
1008
1007
|
function formatTimeLabel(tsSec, spanSec) {
|
|
1009
1008
|
const d = new Date(tsSec * 1000);
|
|
1010
1009
|
if (!Number.isFinite(spanSec)) spanSec = 0;
|
|
@@ -223,7 +223,7 @@ function loadCandles(input) {
|
|
|
223
223
|
const byTime = new Map();
|
|
224
224
|
let meta = null;
|
|
225
225
|
for (const file of files) {
|
|
226
|
-
let raw;
|
|
226
|
+
let raw = null;
|
|
227
227
|
try {
|
|
228
228
|
raw = readJSON(file);
|
|
229
229
|
}
|
|
@@ -435,7 +435,7 @@ function analyzeLookback(closes, amaValues, lookbackBars, amaDef, cfg, truthArr,
|
|
|
435
435
|
const rev = reversalLag(slopeSeries, truthArr, revMaxLag, confirmPct);
|
|
436
436
|
// ── Reset metrics ───────────────────────────────────────────────────────
|
|
437
437
|
const resetEvents = sim.events.filter((e) => e.reason !== GRID_RESET_BOOTSTRAP);
|
|
438
|
-
const resetIdx = resetEvents.map((e) => e.index);
|
|
438
|
+
const resetIdx = resetEvents.map((e) => Number(e.index));
|
|
439
439
|
const gaps = [];
|
|
440
440
|
for (let k = 1; k < resetIdx.length; k++)
|
|
441
441
|
gaps.push(resetIdx[k] - resetIdx[k - 1]);
|
|
@@ -451,7 +451,7 @@ function analyzeLookback(closes, amaValues, lookbackBars, amaDef, cfg, truthArr,
|
|
|
451
451
|
const forwardWindowBars = Number.isFinite(forwardWindowCfg) && forwardWindowCfg > 0
|
|
452
452
|
? Math.round(forwardWindowCfg)
|
|
453
453
|
: Math.max(1, lookbackBars);
|
|
454
|
-
const eventIdx = new Set(sim.events.map((e) => e.index));
|
|
454
|
+
const eventIdx = new Set(sim.events.map((e) => Number(e.index)));
|
|
455
455
|
let curAppliedDir = 0;
|
|
456
456
|
let evaluatedBars = 0, tiltActiveBars = 0, wrongWayBars = 0;
|
|
457
457
|
let curWrongStreak = 0;
|
|
@@ -597,7 +597,7 @@ function run() {
|
|
|
597
597
|
console.log(' AMA-SLOPE-HUBER LOOKBACK BACKTEST');
|
|
598
598
|
console.log('================================================================================');
|
|
599
599
|
console.log(` Data: ${path.resolve(cfg.dataPath)}`);
|
|
600
|
-
console.log(` ${files} file(s), ${n} candles, ${((n * (meta?.intervalSeconds ?? 3600)) / 86400).toFixed(0)} days`);
|
|
600
|
+
console.log(` ${files} file(s), ${n} candles, ${((n * Number(meta?.intervalSeconds ?? 3600)) / 86400).toFixed(0)} days`);
|
|
601
601
|
console.log(` AMA: ${amaDef.name} (er=${amaDef.er}, fast=${amaDef.fast}, slow=${amaDef.slow}), warmup ${warmupBars} bars`);
|
|
602
602
|
console.log(` Lookbacks: ${cfg.lookbacks.join(', ')} bars (${cfg.lookbacks.length} windows)`);
|
|
603
603
|
console.log(` Resets: drift >= ${cfg.priceThresholdPct}% | slope delta >= ${fmt((cfg.slopeThresholdFactor / 100) * MA.DYNAMIC_WEIGHT_AMA_MAX_SLOPE_PCT, 4)}%/bar` +
|
|
@@ -666,7 +666,7 @@ function run() {
|
|
|
666
666
|
`${fmt(r.p90AdverseMoveWhileWrongPct, 2).padStart(10)}`);
|
|
667
667
|
}
|
|
668
668
|
// ── Sweet spot (heuristic) ──────────────────────────────────────────────
|
|
669
|
-
const ranked = results.slice().sort((a, b) => b.compositeScore - a.compositeScore);
|
|
669
|
+
const ranked = results.slice().sort((a, b) => (b.compositeScore ?? 0) - (a.compositeScore ?? 0));
|
|
670
670
|
const winner = ranked[0];
|
|
671
671
|
console.log('\n================================================================================');
|
|
672
672
|
console.log(' HEURISTIC SWEET SPOT');
|
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
interface DynamicWeightRow {
|
|
2
|
+
timestamp: string | number;
|
|
3
|
+
price: number;
|
|
4
|
+
hurst?: number | null;
|
|
5
|
+
pe?: number | null;
|
|
6
|
+
hurstSegment?: number | null;
|
|
7
|
+
peSegment?: number | null;
|
|
8
|
+
amaSlopePct?: number | null;
|
|
9
|
+
velocityRawPct?: number | null;
|
|
10
|
+
velocityPct?: number | null;
|
|
11
|
+
displacementRawPct?: number | null;
|
|
12
|
+
displacementPct?: number | null;
|
|
13
|
+
isReady?: boolean;
|
|
14
|
+
signal?: string | null;
|
|
15
|
+
ama3Price?: number | null;
|
|
16
|
+
}
|
|
17
|
+
interface DynWeightCfg {
|
|
18
|
+
alpha?: number;
|
|
19
|
+
gain?: number;
|
|
20
|
+
dispWeight?: number;
|
|
21
|
+
neutralZonePct?: number;
|
|
22
|
+
amaNeutralZonePct?: number;
|
|
23
|
+
lookbackBars?: number;
|
|
24
|
+
amaLookbackBars?: number;
|
|
25
|
+
amaMaxSlopePct?: number;
|
|
26
|
+
kalmanMaxSlopePct?: number;
|
|
27
|
+
clipPercentile?: number;
|
|
28
|
+
minOutputThreshold?: number;
|
|
29
|
+
outputClamp?: number;
|
|
30
|
+
dispScaleMinPct?: number;
|
|
31
|
+
regimeSensitivity?: number;
|
|
32
|
+
absoluteThreshold?: number;
|
|
33
|
+
}
|
|
34
|
+
interface DynamicWeightChartInput {
|
|
35
|
+
allResults?: DynamicWeightRow[];
|
|
36
|
+
marketAdapter?: DynWeightCfg;
|
|
37
|
+
amaWeightConfig?: DynWeightCfg;
|
|
38
|
+
amaConfig?: {
|
|
39
|
+
erPeriod?: number;
|
|
40
|
+
fastPeriod?: number;
|
|
41
|
+
slowPeriod?: number;
|
|
42
|
+
};
|
|
43
|
+
alpha?: number;
|
|
44
|
+
gain?: number;
|
|
45
|
+
dispWeight?: number;
|
|
46
|
+
clipPct?: number;
|
|
47
|
+
minOutputThreshold?: number;
|
|
48
|
+
outputClamp?: number;
|
|
49
|
+
absoluteThreshold?: number;
|
|
50
|
+
lookbackBars?: number;
|
|
51
|
+
neutralZonePct?: number;
|
|
52
|
+
amaMaxSlopePct?: number;
|
|
53
|
+
kalmanMaxSlopePct?: number;
|
|
54
|
+
dispScaleMinPct?: number;
|
|
55
|
+
regimeSensitivity?: number;
|
|
56
|
+
signalConfirmBars?: number;
|
|
57
|
+
kalmanSmoothPct?: number;
|
|
58
|
+
kalmanDispScaleMult?: number;
|
|
59
|
+
kalmanDispThresholdMult?: number;
|
|
60
|
+
kalmanSmoothSpanPct?: number;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
declare function generateHTML(data: DynamicWeightChartInput, title?: string): string;
|
|
2
64
|
export { generateHTML };
|
|
3
65
|
//# sourceMappingURL=dynamic_weight_chart_generator.d.ts.map
|
|
@@ -27,10 +27,10 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
27
27
|
throw new Error('No analysis results in input');
|
|
28
28
|
// Slider ranges — single source of truth for HTML attrs, tooltips,
|
|
29
29
|
// payload transport, and client paste-clamp bounds.
|
|
30
|
-
const LB_MIN =
|
|
30
|
+
const LB_MIN = 4, LB_MAX = 32;
|
|
31
31
|
const GAIN_MIN = 0.5, GAIN_MAX = 2.0;
|
|
32
32
|
const AMA_MS_MIN = 0.06, AMA_MS_MAX = 0.12;
|
|
33
|
-
const KAL_MS_MIN = 0.
|
|
33
|
+
const KAL_MS_MIN = 0.75, KAL_MS_MAX = 1.5;
|
|
34
34
|
const CLIP_PCT_MAX = 20;
|
|
35
35
|
const TH_MIN = 0, TH_MAX = 0.5;
|
|
36
36
|
const KF_MIN = 0, KF_MAX = 200;
|
|
@@ -172,8 +172,9 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
172
172
|
const safeStartIndex = Math.max(0, Math.min(realBarCount, Math.ceil(startIndex)));
|
|
173
173
|
const sorted = [];
|
|
174
174
|
for (let i = safeStartIndex; i < realBarCount; i++) {
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
const v = arr[i];
|
|
176
|
+
if (v != null)
|
|
177
|
+
sorted.push(Math.abs(v));
|
|
177
178
|
}
|
|
178
179
|
sorted.sort((a, b) => a - b);
|
|
179
180
|
// Empty pool → Infinity: the live percentile lookup treats an empty
|
|
@@ -12,7 +12,13 @@ export interface HuberEstimatorStats {
|
|
|
12
12
|
scaleSum: number;
|
|
13
13
|
}
|
|
14
14
|
/** Estimator function shape accepted by simulateGridResetSeries (cfg.slopeEstimator). */
|
|
15
|
-
export
|
|
15
|
+
export interface HuberConsts {
|
|
16
|
+
C?: number;
|
|
17
|
+
ITERATIONS?: number;
|
|
18
|
+
SCALE_FLOOR?: number;
|
|
19
|
+
ZERO_EPSILON?: number;
|
|
20
|
+
}
|
|
21
|
+
export type HuberEstimator = ((amaValues: unknown, index: number, lookbackBars: unknown) => number | null) & {
|
|
16
22
|
stats: HuberEstimatorStats;
|
|
17
23
|
};
|
|
18
24
|
/**
|
|
@@ -25,10 +31,10 @@ export declare function huberConsistencyConstant(c: number): number;
|
|
|
25
31
|
* `mode='none'`; the other modes change only the scale estimate fed to the
|
|
26
32
|
* Huber weight `min(1, C*s/|r|)`.
|
|
27
33
|
*/
|
|
28
|
-
export declare function huberSlopeCore(amaValues:
|
|
34
|
+
export declare function huberSlopeCore(amaValues: unknown, index: number, lookbackBars: unknown, mode?: HuberScaleMode, hub?: HuberConsts): HuberDiagnostics | null;
|
|
29
35
|
/**
|
|
30
36
|
* Build the `(series, index, lookbackBars)` estimator the reset replay expects,
|
|
31
37
|
* accumulating the mean outlier fraction and scale across calls in `.stats`.
|
|
32
38
|
*/
|
|
33
|
-
export declare function createHuberEstimator(mode?: HuberScaleMode, hub?:
|
|
39
|
+
export declare function createHuberEstimator(mode?: HuberScaleMode, hub?: HuberConsts): HuberEstimator;
|
|
34
40
|
//# sourceMappingURL=huber_scale_variants.d.ts.map
|
|
@@ -100,10 +100,10 @@ export function huberSlopeCore(amaValues, index, lookbackBars, mode = 'none', hu
|
|
|
100
100
|
y.push(Math.log(v));
|
|
101
101
|
}
|
|
102
102
|
const n = y.length;
|
|
103
|
-
const c = Number.isFinite(hub?.C) ? hub.C : 1.345;
|
|
104
|
-
const iterations = Number.isFinite(hub?.ITERATIONS) ? hub.ITERATIONS : 5;
|
|
105
|
-
const scaleFloor = Number.isFinite(hub?.SCALE_FLOOR) ? hub.SCALE_FLOOR : 1e-6;
|
|
106
|
-
const zeroEpsilon = Number.isFinite(hub?.ZERO_EPSILON) ? hub.ZERO_EPSILON : 1e-9;
|
|
103
|
+
const c = Number.isFinite(Number(hub?.C)) ? Number(hub.C) : 1.345;
|
|
104
|
+
const iterations = Number.isFinite(Number(hub?.ITERATIONS)) ? Number(hub.ITERATIONS) : 5;
|
|
105
|
+
const scaleFloor = Number.isFinite(Number(hub?.SCALE_FLOOR)) ? Number(hub.SCALE_FLOOR) : 1e-6;
|
|
106
|
+
const zeroEpsilon = Number.isFinite(Number(hub?.ZERO_EPSILON)) ? Number(hub.ZERO_EPSILON) : 1e-9;
|
|
107
107
|
const xMean = (n - 1) / 2;
|
|
108
108
|
const wls = (w) => {
|
|
109
109
|
let sw = 0, swx = 0, swy = 0, swxx = 0, swxy = 0;
|
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
interface KalmanRow {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
timestamp: string | number;
|
|
4
|
+
price: number;
|
|
5
|
+
kalmanPrice?: number | null;
|
|
6
|
+
modalPrice?: number | null;
|
|
7
|
+
signal?: string | null;
|
|
8
|
+
velocity?: number | null;
|
|
9
|
+
velocityFilteredPct?: number | null;
|
|
10
|
+
velocityPct?: number | null;
|
|
11
|
+
displacementRawPct?: number | null;
|
|
12
|
+
displacementPct?: number | null;
|
|
13
|
+
isReady?: boolean;
|
|
14
|
+
amaWeightOffset?: number | null;
|
|
15
|
+
beams?: Array<{
|
|
16
|
+
originX: number;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
interface KalmanChartInput {
|
|
20
|
+
allResults?: KalmanRow[];
|
|
21
|
+
amaConfig?: {
|
|
22
|
+
erPeriod?: number;
|
|
23
|
+
fastPeriod?: number;
|
|
24
|
+
slowPeriod?: number;
|
|
25
|
+
};
|
|
26
|
+
clipPct?: number;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
declare function generateHTML(data: KalmanChartInput, title?: string): string;
|
|
2
30
|
export { generateHTML };
|
|
31
|
+
export type { KalmanRow };
|
|
3
32
|
//# sourceMappingURL=kalman_chart_generator.d.ts.map
|
|
@@ -72,10 +72,10 @@ function generateHTML(data, title = 'Kalman Trajectory Analysis') {
|
|
|
72
72
|
if (idx % 15 === 0 || (r.beams && r.beams.length > 0 && r.beams[r.beams.length - 1].originX === idx)) {
|
|
73
73
|
allBeams.push({
|
|
74
74
|
x: dates[idx],
|
|
75
|
-
y: r.kalmanPrice,
|
|
76
|
-
v: r.velocity,
|
|
75
|
+
y: (r.kalmanPrice ?? 0),
|
|
76
|
+
v: (r.velocity ?? 0),
|
|
77
77
|
endX: dates[idx] + (150 * interval),
|
|
78
|
-
endY: r.kalmanPrice + (r.velocity * 150
|
|
78
|
+
endY: (r.kalmanPrice ?? 0) + (r.velocity ?? 0) * 150
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
});
|