dexbot 1.6.10 → 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 +50 -3
- package/README.md +3 -1
- package/analysis/README.md +51 -11
- package/analysis/bot_fitting/README.md +12 -0
- package/analysis/tradingview/README.md +3 -3
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +11 -37
- package/analysis/trend_detection/README.md +31 -0
- 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 +15 -2
- 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 -20
- 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 +55 -10
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +72 -66
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.d.ts +21 -0
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +315 -0
- 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 +10 -17
- 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 +64 -0
- package/dist/analysis/fills_cache.js +254 -0
- package/dist/analysis/fills_source.d.ts +2 -2
- package/dist/analysis/fills_source.js +19 -14
- 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.d.ts +39 -0
- package/dist/analysis/pnl_report.js +325 -0
- 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 -2
- package/dist/analysis/trade_profitability.d.ts +32 -2
- package/dist/analysis/trade_profitability.js +232 -106
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
- package/dist/analysis/tradingview/analyze_tradingview.js +9 -10
- package/dist/analysis/tradingview/grid_reset_config.d.ts +42 -31
- package/dist/analysis/tradingview/grid_reset_config.js +35 -6
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -8
- package/dist/analysis/tradingview/grid_reset_sim.js +42 -5
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -20
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +102 -0
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +725 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +27 -112
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +40 -0
- package/dist/analysis/trend_detection/huber_scale_variants.js +176 -0
- 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 +17 -14
- 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 +297 -115
- package/dist/market_adapter/core/market_adapter_service.js +184 -101
- package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
- package/dist/market_adapter/core/strategies/ama.js +7 -32
- 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 +36 -8
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +9 -9
- 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 +97 -226
- 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 -22
- 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 -33
- package/dist/market_adapter/market_adapter.js +69 -75
- 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 +530 -32
- package/dist/modules/constants.js +52 -60
- 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 +117 -80
- 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 +40 -14
- 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 +39 -19
- package/dist/modules/order/format.js +62 -16
- 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 +226 -180
- package/dist/modules/order/manager.js +101 -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 +99 -54
- 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 +326 -106
- package/dist/modules/order/utils/order.js +200 -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 +3 -4
- package/dist/modules/paths.js +3 -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 +4 -0
- package/dist/modules/utils/time_range.js +18 -0
- 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 +66 -84
- package/dist/scripts/chart_command.d.ts +27 -18
- package/dist/scripts/chart_command.js +16 -15
- 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/pnl.d.ts +3 -0
- package/dist/scripts/pnl.js +40 -0
- 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 +72 -10
- 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 +12 -10
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
- package/docs/GRID_RECALCULATION.md +15 -16
- 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 +15 -4
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +12 -9
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +9 -26
- package/modules/README.md +4 -1
- package/package.json +4 -1
- package/scripts/README.md +14 -0
|
@@ -3,8 +3,8 @@ declare function parseArgs(): {
|
|
|
3
3
|
source: {
|
|
4
4
|
type: string;
|
|
5
5
|
config: {
|
|
6
|
-
filePath
|
|
7
|
-
botKey?:
|
|
6
|
+
filePath?: string;
|
|
7
|
+
botKey?: string;
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
chartFile: string;
|
|
@@ -30,11 +30,22 @@ declare function parseArgs(): {
|
|
|
30
30
|
quiet: boolean;
|
|
31
31
|
listBots: boolean;
|
|
32
32
|
};
|
|
33
|
-
declare function loadJsonMeta(filePath:
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
declare function loadJsonMeta(filePath: string | null | undefined): import("../math_utils.js").CandleFile | {
|
|
34
|
+
meta: null;
|
|
35
|
+
candles: null;
|
|
36
36
|
};
|
|
37
|
-
declare function inferTitle(meta:
|
|
37
|
+
declare function inferTitle(meta: {
|
|
38
|
+
pool?: unknown;
|
|
39
|
+
intervalSeconds?: unknown;
|
|
40
|
+
assetA?: {
|
|
41
|
+
symbol?: unknown;
|
|
42
|
+
id?: unknown;
|
|
43
|
+
};
|
|
44
|
+
assetB?: {
|
|
45
|
+
symbol?: unknown;
|
|
46
|
+
id?: unknown;
|
|
47
|
+
};
|
|
48
|
+
} | null | undefined, fallback: string): string;
|
|
38
49
|
declare function main(): Promise<void>;
|
|
39
50
|
export { main, parseArgs, loadJsonMeta, inferTitle };
|
|
40
51
|
//# sourceMappingURL=analyze_tradingview.d.ts.map
|
|
@@ -201,7 +201,7 @@ function inferTitle(meta, fallback) {
|
|
|
201
201
|
const b = meta?.assetB?.symbol || meta?.assetB?.id || null;
|
|
202
202
|
const pair = a && b ? `${a}/${b}` : fallback;
|
|
203
203
|
const label = pool || pair;
|
|
204
|
-
const interval = Number(meta?.intervalSeconds) > 0 ? toIntervalLabel(meta
|
|
204
|
+
const interval = Number(meta?.intervalSeconds) > 0 ? toIntervalLabel(Number(meta?.intervalSeconds)) : '1h';
|
|
205
205
|
return `${label} · ${interval} · TradingView`;
|
|
206
206
|
}
|
|
207
207
|
async function main() {
|
|
@@ -237,15 +237,16 @@ async function main() {
|
|
|
237
237
|
// Bot grid bounds for the range highlight: mirrors the runtime grid
|
|
238
238
|
// (center = AMA, min "Nx" = center/N, max "Nx" = center*N) with the
|
|
239
239
|
// live asymmetric tilt. Null when no bot key (width% fallback in-page).
|
|
240
|
+
const asym = botMeta?.asymmetricBounds;
|
|
240
241
|
const grid = botMeta?.minPrice != null && botMeta?.maxPrice != null ? {
|
|
241
242
|
minPrice: botMeta.minPrice,
|
|
242
243
|
maxPrice: botMeta.maxPrice,
|
|
243
244
|
incrementPercent: Number(botMeta.incrementPercent) > 0 ? Number(botMeta.incrementPercent) : null,
|
|
244
|
-
maxAsymmetryFactor: Number.isFinite(Number(
|
|
245
|
-
? Number(
|
|
245
|
+
maxAsymmetryFactor: Number.isFinite(Number(asym?.maxAsymmetryFactor))
|
|
246
|
+
? Number(asym?.maxAsymmetryFactor)
|
|
246
247
|
: null,
|
|
247
|
-
minScaleSlots: Number.isFinite(Number(
|
|
248
|
-
? Number(
|
|
248
|
+
minScaleSlots: Number.isFinite(Number(asym?.minScaleSlots))
|
|
249
|
+
? Number(asym?.minScaleSlots)
|
|
249
250
|
: null,
|
|
250
251
|
} : null;
|
|
251
252
|
// Order overlay (canonical profiles/orders/<botKey>.json; silent when absent)
|
|
@@ -286,11 +287,9 @@ async function main() {
|
|
|
286
287
|
},
|
|
287
288
|
smaPeriod: config.smaPeriod,
|
|
288
289
|
amaDefaults: {
|
|
289
|
-
//
|
|
290
|
-
// recomputation
|
|
291
|
-
// stays a plain candle chart.
|
|
292
|
-
// adapter are the mirrors of the full bot AMA config (incl.
|
|
293
|
-
// ama.erSmoothPeriod); the knob is inert by default (global 0).
|
|
290
|
+
// Canonical 3-param AMA (er/fast/slow). The in-page AMA
|
|
291
|
+
// recomputation mirrors the live adapter exactly; `dexbot tv`
|
|
292
|
+
// stays a plain candle chart.
|
|
294
293
|
erPeriod: config.amaErPeriod ?? amaConfig.erPeriod,
|
|
295
294
|
fastPeriod: config.amaFastPeriod ?? amaConfig.fastPeriod,
|
|
296
295
|
slowPeriod: config.amaSlowPeriod ?? amaConfig.slowPeriod,
|
|
@@ -5,22 +5,32 @@
|
|
|
5
5
|
* @param {Object|null} input.ama Resolved AMA config (er/fast/slow) the chart runs with.
|
|
6
6
|
* @param {Object} [input.overrides] CLI overrides {priceDeltaThresholdPercent, slopeDeltaThresholdPercent, enabled}.
|
|
7
7
|
*/
|
|
8
|
-
declare function resolveGridResetSimConfig({ botKey, bot, ama, overrides }?:
|
|
8
|
+
declare function resolveGridResetSimConfig({ botKey, bot, ama, overrides }?: {
|
|
9
|
+
botKey?: string | null;
|
|
10
|
+
bot?: Record<string, unknown> | null;
|
|
11
|
+
ama?: {
|
|
12
|
+
erPeriod?: number;
|
|
13
|
+
fastPeriod?: number;
|
|
14
|
+
slowPeriod?: number;
|
|
15
|
+
} | null;
|
|
16
|
+
overrides?: Record<string, unknown>;
|
|
17
|
+
}): {
|
|
9
18
|
enabled: boolean;
|
|
10
|
-
botKey:
|
|
11
|
-
priceDeltaThresholdPercent:
|
|
12
|
-
priceSource:
|
|
13
|
-
slopeDeltaThresholdPercent:
|
|
14
|
-
slopeSource:
|
|
19
|
+
botKey: string | null;
|
|
20
|
+
priceDeltaThresholdPercent: number;
|
|
21
|
+
priceSource: string;
|
|
22
|
+
slopeDeltaThresholdPercent: number;
|
|
23
|
+
slopeSource: string;
|
|
15
24
|
slopeEnabled: boolean;
|
|
16
25
|
dynamicWeightEnabled: boolean;
|
|
17
|
-
lookbackBars:
|
|
18
|
-
|
|
26
|
+
lookbackBars: number;
|
|
27
|
+
slopePersistBars: number;
|
|
28
|
+
maxSlopePct: number;
|
|
19
29
|
neutralZonePct: number;
|
|
20
|
-
maxSlopeOffset:
|
|
30
|
+
maxSlopeOffset: number;
|
|
21
31
|
clipPercentile: number;
|
|
22
|
-
maxAsymmetryFactor:
|
|
23
|
-
minScaleSlots:
|
|
32
|
+
maxAsymmetryFactor: number;
|
|
33
|
+
minScaleSlots: number;
|
|
24
34
|
incrementPercent: number | null;
|
|
25
35
|
erPeriod: number;
|
|
26
36
|
warmupBars: number;
|
|
@@ -33,29 +43,30 @@ declare function resolveGridResetSimConfig({ botKey, bot, ama, overrides }?: any
|
|
|
33
43
|
* Flatten the resolved config for the chart payload, dropping anything the page
|
|
34
44
|
* must not see (e.g. Infinity from a disabled threshold).
|
|
35
45
|
*/
|
|
36
|
-
declare function toGridSimPayload(cfg:
|
|
46
|
+
declare function toGridSimPayload(cfg: Record<string, unknown> | null): {
|
|
37
47
|
enabled: boolean;
|
|
38
|
-
botKey:
|
|
39
|
-
priceDeltaThresholdPercent:
|
|
40
|
-
priceSource:
|
|
41
|
-
slopeDeltaThresholdPercent:
|
|
42
|
-
slopeSource:
|
|
48
|
+
botKey: {} | null;
|
|
49
|
+
priceDeltaThresholdPercent: unknown;
|
|
50
|
+
priceSource: {};
|
|
51
|
+
slopeDeltaThresholdPercent: unknown;
|
|
52
|
+
slopeSource: {};
|
|
43
53
|
slopeEnabled: boolean;
|
|
44
54
|
dynamicWeightEnabled: boolean;
|
|
45
|
-
lookbackBars:
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
lookbackBars: unknown;
|
|
56
|
+
slopePersistBars: unknown;
|
|
57
|
+
maxSlopePct: unknown;
|
|
58
|
+
neutralZonePct: unknown;
|
|
59
|
+
maxSlopeOffset: unknown;
|
|
60
|
+
clipPercentile: unknown;
|
|
61
|
+
maxAsymmetryFactor: unknown;
|
|
62
|
+
minScaleSlots: unknown;
|
|
63
|
+
incrementPercent: unknown;
|
|
64
|
+
erPeriod: unknown;
|
|
65
|
+
warmupBars: unknown;
|
|
66
|
+
warmupBarsOverride: unknown;
|
|
67
|
+
clampMin: unknown;
|
|
68
|
+
clampMax: unknown;
|
|
69
|
+
notes: any[];
|
|
59
70
|
} | null;
|
|
60
71
|
export { resolveGridResetSimConfig, toGridSimPayload };
|
|
61
72
|
//# sourceMappingURL=grid_reset_config.d.ts.map
|
|
@@ -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']] },
|
|
@@ -143,9 +146,33 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
143
146
|
}
|
|
144
147
|
const erPeriod = firstPositive([ama?.erPeriod, botCfg?.erPeriod], MARKET_ADAPTER.AMAS.AMA3.erPeriod);
|
|
145
148
|
const lookbackBars = firstPositive([botCfg?.amaSlope?.lookbackBars], MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS);
|
|
149
|
+
// Slope-delta persistence gate: mirror resolveAmaSlopePersistBars in the
|
|
150
|
+
// adapter service so the chart replay fires the same Δs resets production
|
|
151
|
+
// does. Per-bot override wins; else the global enable + value; else legacy 1.
|
|
152
|
+
const resolveSlopePersistBars = () => {
|
|
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;
|
|
168
|
+
if (!enabled)
|
|
169
|
+
return 1;
|
|
170
|
+
const bars = Number(MARKET_ADAPTER.AMA_SLOPE_PERSIST_BARS);
|
|
171
|
+
return Number.isFinite(bars) && bars >= 1 ? Math.round(bars) : 1;
|
|
172
|
+
};
|
|
146
173
|
let warmupBars = 0;
|
|
147
174
|
try {
|
|
148
|
-
warmupBars = getAmaWarmupBars(erPeriod, firstPositive([ama?.slowPeriod], MARKET_ADAPTER.AMAS.AMA3.slowPeriod), lookbackBars, firstPositive([ama?.fastPeriod], MARKET_ADAPTER.AMAS.AMA3.fastPeriod)
|
|
175
|
+
warmupBars = getAmaWarmupBars(erPeriod, firstPositive([ama?.slowPeriod], MARKET_ADAPTER.AMAS.AMA3.slowPeriod), lookbackBars, firstPositive([ama?.fastPeriod], MARKET_ADAPTER.AMAS.AMA3.fastPeriod));
|
|
149
176
|
}
|
|
150
177
|
catch (_err) {
|
|
151
178
|
// getAmaWarmupBars validates strictly; a research-only AMA tweak must
|
|
@@ -162,7 +189,7 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
162
189
|
return null;
|
|
163
190
|
try {
|
|
164
191
|
const bound = resolveConfiguredPriceBound(raw, fallback, 1, mode);
|
|
165
|
-
return Number.isFinite(bound) && bound > 0 ? Number(bound) : null;
|
|
192
|
+
return bound != null && Number.isFinite(bound) && bound > 0 ? Number(bound) : null;
|
|
166
193
|
}
|
|
167
194
|
catch (_err) {
|
|
168
195
|
return null;
|
|
@@ -180,9 +207,10 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
180
207
|
slopeEnabled,
|
|
181
208
|
dynamicWeightEnabled,
|
|
182
209
|
lookbackBars,
|
|
210
|
+
slopePersistBars: resolveSlopePersistBars(),
|
|
183
211
|
maxSlopePct: firstPositive([botCfg?.amaSlope?.maxSlopePct], MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_MAX_SLOPE_PCT),
|
|
184
212
|
neutralZonePct: Number.isFinite(Number(botCfg?.amaSlope?.neutralZonePct))
|
|
185
|
-
? Number(botCfg
|
|
213
|
+
? Number(botCfg?.amaSlope?.neutralZonePct)
|
|
186
214
|
: MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_NEUTRAL_ZONE_PCT,
|
|
187
215
|
maxSlopeOffset: firstPositive([botCfg?.maxSlopeOffset], MARKET_ADAPTER.DYNAMIC_WEIGHT_ASYMMETRIC_OFFSET_CLAMP),
|
|
188
216
|
clipPercentile: Number.isFinite(Number(botCfg?.clipPercentile))
|
|
@@ -190,7 +218,7 @@ function resolveGridResetSimConfig({ botKey, bot, ama, overrides } = {}) {
|
|
|
190
218
|
: MARKET_ADAPTER.DYNAMIC_WEIGHT_CLIP_PERCENTILE,
|
|
191
219
|
maxAsymmetryFactor: firstPositive([bot?.asymmetricBounds?.maxAsymmetryFactor, botCfg?.asymmetricBounds?.maxAsymmetryFactor], MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MAX_ASYMMETRY_FACTOR),
|
|
192
220
|
minScaleSlots: firstPositive([botCfg?.asymmetricBounds?.minScaleSlots], MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MIN_SCALE_SLOTS),
|
|
193
|
-
incrementPercent: Number.isFinite(Number(bot?.incrementPercent)) ? Number(bot
|
|
221
|
+
incrementPercent: Number.isFinite(Number(bot?.incrementPercent)) ? Number(bot?.incrementPercent) : null,
|
|
194
222
|
erPeriod: Math.ceil(erPeriod),
|
|
195
223
|
warmupBars,
|
|
196
224
|
warmupBarsOverride: Number.isFinite(Number(opts.warmupBars)) && Number(opts.warmupBars) >= 0 ? Math.ceil(Number(opts.warmupBars)) : null,
|
|
@@ -216,6 +244,7 @@ function toGridSimPayload(cfg) {
|
|
|
216
244
|
slopeEnabled: cfg.slopeEnabled === true,
|
|
217
245
|
dynamicWeightEnabled: cfg.dynamicWeightEnabled === true,
|
|
218
246
|
lookbackBars: cfg.lookbackBars,
|
|
247
|
+
slopePersistBars: cfg.slopePersistBars,
|
|
219
248
|
maxSlopePct: cfg.maxSlopePct,
|
|
220
249
|
neutralZonePct: cfg.neutralZonePct,
|
|
221
250
|
maxSlopeOffset: cfg.maxSlopeOffset,
|
|
@@ -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,20 +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;
|
|
139
|
+
slopePersistBars: number;
|
|
73
140
|
slopeTriggerArmed: boolean;
|
|
74
141
|
};
|
|
75
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);
|
|
@@ -135,6 +136,10 @@ function simulateGridResetSeries(amaSeries, cfg) {
|
|
|
135
136
|
const clipPercentile = Number(cfg?.clipPercentile);
|
|
136
137
|
const clampMinValue = Number(cfg?.clampMin);
|
|
137
138
|
const clampMaxValue = Number(cfg?.clampMax);
|
|
139
|
+
// Persistence gate on the slope-delta trigger (trigger B): consecutive
|
|
140
|
+
// confirming bars required before it fires. 1 = legacy behavior (fire on the
|
|
141
|
+
// first threshold crossing); >1 filters short-lived slope excursions.
|
|
142
|
+
const slopePersistBars = gridSimNonNegativeInt(cfg?.slopePersistBars, 1);
|
|
138
143
|
// Mirrors clampGridPriceToBounds: only absolute bot bounds pin the center,
|
|
139
144
|
// and each side binds independently (a mixed absolute/"Nx" config clamps
|
|
140
145
|
// only on the absolute side).
|
|
@@ -174,6 +179,7 @@ function simulateGridResetSeries(amaSeries, cfg) {
|
|
|
174
179
|
warmupBars,
|
|
175
180
|
priceDeltaThresholdPercent: priceTriggerArmed ? priceThreshold : null,
|
|
176
181
|
slopeDeltaThresholdPercent: slopeTriggerArmed ? slopeThreshold : null,
|
|
182
|
+
slopePersistBars,
|
|
177
183
|
slopeTriggerArmed,
|
|
178
184
|
},
|
|
179
185
|
};
|
|
@@ -189,8 +195,11 @@ function simulateGridResetSeries(amaSeries, cfg) {
|
|
|
189
195
|
let resetCount = 0;
|
|
190
196
|
let priceResets = 0;
|
|
191
197
|
let slopeResets = 0;
|
|
198
|
+
// Persistence-gate state for trigger B.
|
|
199
|
+
let slopePersistCount = 0;
|
|
200
|
+
let slopePersistDir = 0;
|
|
192
201
|
for (let i = 0; i < n; i++) {
|
|
193
|
-
const ama = Number(
|
|
202
|
+
const ama = Number(amaArr[i]);
|
|
194
203
|
const hasAma = Number.isFinite(ama) && ama > 0;
|
|
195
204
|
// Feed the clip tracker every bar (non-finite values keep their slot,
|
|
196
205
|
// exactly like the batch threshold). The chart's AMA is computed over
|
|
@@ -202,7 +211,7 @@ function simulateGridResetSeries(amaSeries, cfg) {
|
|
|
202
211
|
const clipThreshold = clipTracker.push(hasAma ? ama : NaN);
|
|
203
212
|
let slopePct = null;
|
|
204
213
|
if (hasAma && i >= readyBars) {
|
|
205
|
-
const s = estimateSlope(
|
|
214
|
+
const s = estimateSlope(amaArr, i, lookbackBars);
|
|
206
215
|
if (Number.isFinite(s))
|
|
207
216
|
slopePct = s;
|
|
208
217
|
}
|
|
@@ -245,10 +254,37 @@ function simulateGridResetSeries(amaSeries, cfg) {
|
|
|
245
254
|
else if (priceTriggerArmed && driftPct[i] >= priceThreshold) {
|
|
246
255
|
fired = GRID_RESET_PRICE;
|
|
247
256
|
}
|
|
248
|
-
else
|
|
249
|
-
|
|
257
|
+
else {
|
|
258
|
+
// Trigger B, now persistence-gated: require the threshold to be
|
|
259
|
+
// crossed for `slopePersistBars` consecutive bars in the same
|
|
260
|
+
// direction before firing. A single-bar excursion never charges the
|
|
261
|
+
// counter; a sustained move is confirmed K bars after onset (up to
|
|
262
|
+
// K-1 bars later than the ungated trigger).
|
|
263
|
+
const delta = slopeDeltaPct[i];
|
|
264
|
+
const candidate = slopeTriggerArmed && delta != null && delta >= slopeThreshold;
|
|
265
|
+
if (!candidate) {
|
|
266
|
+
slopePersistCount = 0;
|
|
267
|
+
slopePersistDir = 0;
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
const dir = acceptedSlope != null && slopePct != null ? Math.sign(slopePct - acceptedSlope) : 0;
|
|
271
|
+
if (slopePersistBars <= 1) {
|
|
272
|
+
fired = GRID_RESET_SLOPE;
|
|
273
|
+
}
|
|
274
|
+
else if (dir !== 0 && dir === slopePersistDir) {
|
|
275
|
+
slopePersistCount++;
|
|
276
|
+
if (slopePersistCount >= slopePersistBars)
|
|
277
|
+
fired = GRID_RESET_SLOPE;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
slopePersistDir = dir;
|
|
281
|
+
slopePersistCount = 1;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
250
284
|
}
|
|
251
285
|
if (fired !== GRID_RESET_NONE) {
|
|
286
|
+
slopePersistCount = 0;
|
|
287
|
+
slopePersistDir = 0;
|
|
252
288
|
const previousCenter = acceptedCenter;
|
|
253
289
|
acceptedCenter = currentCenter;
|
|
254
290
|
// Re-seed the accepted slope on EVERY reset (price and slope alike),
|
|
@@ -312,6 +348,7 @@ function simulateGridResetSeries(amaSeries, cfg) {
|
|
|
312
348
|
warmupBars,
|
|
313
349
|
priceDeltaThresholdPercent: priceTriggerArmed ? priceThreshold : null,
|
|
314
350
|
slopeDeltaThresholdPercent: slopeTriggerArmed ? slopeThreshold : null,
|
|
351
|
+
slopePersistBars,
|
|
315
352
|
slopeTriggerArmed,
|
|
316
353
|
},
|
|
317
354
|
};
|
|
@@ -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
|