dexbot 1.6.11 → 1.6.13
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 +67 -4
- package/README.md +2 -1
- package/analysis/README.md +11 -11
- package/analysis/ama_fitting/README.md +5 -3
- package/analysis/tradingview/README.md +1 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
- package/claw/README.md +1 -0
- package/claw/docs/AI_BOT_LIBRARY_API.md +2 -0
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_bridge.ts +0 -3
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/claw_skill_md.ts +1 -0
- package/claw/modules/launcher_mode_detector.ts +9 -2
- package/claw/package.json +3 -3
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/tsconfig.json +2 -2
- 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 +3 -21
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +55 -45
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -8
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +45 -24
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +34 -78
- package/dist/analysis/analyze_args.d.ts +43 -0
- package/dist/analysis/analyze_args.js +61 -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 +221 -28
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +23 -103
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +32 -150
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
- package/dist/analysis/bot_fitting/shared_utils.d.ts +77 -9
- package/dist/analysis/bot_fitting/shared_utils.js +125 -9
- 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 +35 -3
- package/dist/analysis/chart_ui.js +43 -4
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +4 -24
- package/dist/analysis/fills_cache.js +3 -84
- package/dist/analysis/fills_source.d.ts +33 -3
- package/dist/analysis/fills_source.js +83 -13
- package/dist/analysis/grid_correction_check.d.ts +2 -24
- package/dist/analysis/grid_correction_check.js +27 -69
- package/dist/analysis/math_utils.d.ts +91 -6
- package/dist/analysis/math_utils.js +119 -7
- package/dist/analysis/pnl_report.js +29 -29
- package/dist/analysis/price_sources.d.ts +30 -9
- package/dist/analysis/price_sources.js +28 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -1
- package/dist/analysis/resolve_source.js +31 -10
- package/dist/analysis/trade_profitability.d.ts +29 -2
- package/dist/analysis/trade_profitability.js +73 -147
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +3 -8
- package/dist/analysis/tradingview/analyze_tradingview.js +7 -6
- 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 +20 -34
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +26 -84
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +16 -41
- 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/analysis/trend_detection/volatility_chart_generator.js +9 -10
- package/dist/analysis/worker_pool.d.ts +38 -0
- package/dist/analysis/worker_pool.js +67 -0
- package/dist/credential-daemon.js +34 -20
- package/dist/dexbot.js +78 -59
- package/dist/market_adapter/ama_signal_runner.js +21 -54
- package/dist/market_adapter/candle_utils.d.ts +29 -19
- package/dist/market_adapter/candle_utils.js +35 -21
- package/dist/market_adapter/cli_args.d.ts +22 -0
- package/dist/market_adapter/cli_args.js +30 -0
- 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/config_normalizers.js +11 -6
- package/dist/market_adapter/core/kibana_candles.d.ts +56 -19
- package/dist/market_adapter/core/kibana_candles.js +12 -9
- 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 +320 -153
- package/dist/market_adapter/core/market_adapter_service.js +228 -269
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
- package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
- 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 -2
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +160 -332
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +50 -8
- package/dist/market_adapter/inputs/fetch_lp_data.js +47 -22
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +26 -41
- 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 +93 -156
- package/dist/market_adapter/inputs/window_cache.js +59 -184
- package/dist/market_adapter/interval_utils.d.ts +15 -5
- package/dist/market_adapter/interval_utils.js +16 -1
- 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 +10 -7
- package/dist/market_adapter/lp_chart_runner.js +37 -19
- 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 +94 -120
- 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 +49 -2
- package/dist/market_adapter/utils/data_discovery.js +220 -27
- 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/month_shards.d.ts +84 -0
- package/dist/market_adapter/utils/month_shards.js +237 -0
- 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 +578 -21
- package/dist/modules/account_bots.js +272 -267
- package/dist/modules/account_orders.d.ts +79 -30
- package/dist/modules/account_orders.js +60 -64
- 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 +39 -4
- package/dist/modules/bitshares-native/chain_client.js +59 -59
- 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/resolvers.js +22 -25
- 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 +73 -108
- 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 +8 -16
- 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 +4 -3
- 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 +94 -60
- package/dist/modules/chain_orders.js +81 -118
- package/dist/modules/cli_start_onboarding.d.ts +2 -1
- package/dist/modules/constants.d.ts +534 -32
- package/dist/modules/constants.js +35 -48
- package/dist/modules/cr_planner.d.ts +41 -3
- package/dist/modules/cr_planner.js +1 -5
- 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 +43 -6
- package/dist/modules/credit_pricing.js +70 -60
- package/dist/modules/credit_runtime.d.ts +283 -118
- package/dist/modules/credit_runtime.js +500 -231
- 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/daemon_node_health.d.ts +4 -3
- package/dist/modules/dexbot_class.d.ts +213 -146
- package/dist/modules/dexbot_class.js +183 -86
- package/dist/modules/dexbot_cow_runtime.d.ts +160 -87
- package/dist/modules/dexbot_cow_runtime.js +302 -234
- package/dist/modules/dexbot_credential_client.d.ts +19 -18
- package/dist/modules/dexbot_credential_client.js +1 -2
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -49
- package/dist/modules/dexbot_fill_runtime.js +53 -47
- package/dist/modules/dexbot_maintenance_runtime.d.ts +127 -71
- package/dist/modules/dexbot_maintenance_runtime.js +187 -147
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -11
- package/dist/modules/dexbot_startup_runtime.js +56 -57
- 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 +19 -13
- 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 -7
- 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/lazy_shim.d.ts +11 -0
- package/dist/modules/lazy_shim.js +16 -0
- package/dist/modules/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- package/dist/modules/node_connect_policy.d.ts +3 -2
- package/dist/modules/node_failure_ledger.d.ts +6 -5
- 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 +16 -7
- package/dist/modules/order/format.js +15 -3
- package/dist/modules/order/genesis_policy.d.ts +24 -21
- package/dist/modules/order/genesis_policy.js +17 -10
- package/dist/modules/order/grid.d.ts +144 -36
- package/dist/modules/order/grid.js +226 -145
- 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 +264 -1
- package/dist/modules/order/logger.d.ts +46 -19
- package/dist/modules/order/logger.js +38 -49
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +232 -191
- package/dist/modules/order/manager.js +110 -130
- 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 +153 -126
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +156 -26
- package/dist/modules/order/utils/system.js +103 -71
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +26 -24
- package/dist/modules/order/utils/withPoolRef.d.ts +6 -4
- 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 +33 -61
- 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 +14 -11
- 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 +9 -5
- 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 +1090 -6
- 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 +24 -4
- 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 +23 -11
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +28 -27
- package/dist/pm2.js +61 -40
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- package/dist/scripts/analyze-git.js +2 -15
- 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 +15 -13
- package/dist/scripts/check_any.d.ts +22 -0
- package/dist/scripts/check_any.js +158 -0
- package/dist/scripts/diagnose-pool-history.js +13 -13
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -8
- package/dist/scripts/runner.js +1 -1
- package/dist/scripts/sync-version.js +0 -10
- 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 +10 -12
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -2
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +10 -8
- 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/WORKFLOW.md +1 -0
- package/docs/architecture.md +31 -19
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +12 -5
- package/modules/README.md +4 -1
- package/package.json +9 -9
- package/scripts/README.md +43 -38
- package/tests/README.md +25 -10
- package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
- package/dist/scripts/diagnose-kibana-candles.js +0 -82
- package/scripts/git-viewer.sh +0 -489
- package/scripts/postinstall.js +0 -16
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
declare function toIntervalLabel(intervalSeconds:
|
|
1
|
+
declare function toIntervalLabel(intervalSeconds: number): string;
|
|
2
2
|
/**
|
|
3
3
|
* Filename-safe slug: lowercase, non-alphanumerics collapsed to a single
|
|
4
4
|
* underscore, no leading/trailing underscores. Single home for the helper
|
|
5
5
|
* previously copied into fetch_lp_data.ts, kibana_feed_source.ts,
|
|
6
6
|
* fetch_book_data.ts and scripts/chart_command.ts.
|
|
7
7
|
*/
|
|
8
|
-
declare function slugPart(value:
|
|
8
|
+
declare function slugPart(value: unknown): string;
|
|
9
9
|
/**
|
|
10
10
|
* Start of the interval bucket that contains `nowMs` (floor on the bucket
|
|
11
11
|
* grid), or null when the interval or clock is unusable.
|
|
@@ -16,12 +16,22 @@ declare function slugPart(value: any): string;
|
|
|
16
16
|
* gate and the startup sleep must agree on "the newest closed bucket" by
|
|
17
17
|
* construction, not by two copies happening to match.
|
|
18
18
|
*/
|
|
19
|
-
declare function bucketStartMs(nowMs:
|
|
19
|
+
declare function bucketStartMs(nowMs: number, intervalSeconds: number): number | null;
|
|
20
20
|
/**
|
|
21
21
|
* Start of the newest FULLY CLOSED bucket as of `nowMs` — the bucket just
|
|
22
22
|
* before the one that contains `nowMs`. Null when `bucketStartMs` cannot
|
|
23
23
|
* evaluate the interval/clock.
|
|
24
24
|
*/
|
|
25
|
-
declare function latestClosedBucketStartMs(nowMs:
|
|
26
|
-
|
|
25
|
+
declare function latestClosedBucketStartMs(nowMs: number, intervalSeconds: number): number | null;
|
|
26
|
+
/**
|
|
27
|
+
* Parse a BitShares chain timestamp (e.g. `block_time`) to epoch ms.
|
|
28
|
+
*
|
|
29
|
+
* Chain timestamps are ISO-8601 without a trailing `Z`; `Date.parse` treats
|
|
30
|
+
* them as local time, so append `Z` unless present. Single home for the helper
|
|
31
|
+
* previously copied into market_adapter.ts, kibana_candles.ts,
|
|
32
|
+
* kibana_feed_source.ts, scripts/diagnose-pool-history.ts and
|
|
33
|
+
* scripts/chart_command.ts. Returns `NaN` for empty/unparseable input.
|
|
34
|
+
*/
|
|
35
|
+
declare function parseChainTimeToMs(timeStr: unknown): number;
|
|
36
|
+
export { toIntervalLabel, slugPart, bucketStartMs, latestClosedBucketStartMs, parseChainTimeToMs };
|
|
27
37
|
//# sourceMappingURL=interval_utils.d.ts.map
|
|
@@ -51,5 +51,20 @@ function latestClosedBucketStartMs(nowMs, intervalSeconds) {
|
|
|
51
51
|
return null;
|
|
52
52
|
return currentBucketStart - Number(intervalSeconds) * 1000;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Parse a BitShares chain timestamp (e.g. `block_time`) to epoch ms.
|
|
56
|
+
*
|
|
57
|
+
* Chain timestamps are ISO-8601 without a trailing `Z`; `Date.parse` treats
|
|
58
|
+
* them as local time, so append `Z` unless present. Single home for the helper
|
|
59
|
+
* previously copied into market_adapter.ts, kibana_candles.ts,
|
|
60
|
+
* kibana_feed_source.ts, scripts/diagnose-pool-history.ts and
|
|
61
|
+
* scripts/chart_command.ts. Returns `NaN` for empty/unparseable input.
|
|
62
|
+
*/
|
|
63
|
+
function parseChainTimeToMs(timeStr) {
|
|
64
|
+
if (!timeStr)
|
|
65
|
+
return Number.NaN;
|
|
66
|
+
const s = String(timeStr);
|
|
67
|
+
return Date.parse(s.endsWith('Z') ? s : `${s}Z`);
|
|
68
|
+
}
|
|
69
|
+
export { toIntervalLabel, slugPart, bucketStartMs, latestClosedBucketStartMs, parseChainTimeToMs };
|
|
55
70
|
//# sourceMappingURL=interval_utils.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare function formatLogPercent(value:
|
|
2
|
-
declare function buildWeightSummary(weights:
|
|
3
|
-
declare function buildDynamicWeightInputsLog(meta:
|
|
4
|
-
declare function buildDynamicWeightTuningLog(meta:
|
|
5
|
-
declare function buildAsymmetricBoundsLog(meta:
|
|
6
|
-
declare function buildStartupDefaultsLog(defaultAma:
|
|
1
|
+
declare function formatLogPercent(value: unknown, digits?: number): string;
|
|
2
|
+
declare function buildWeightSummary(weights: unknown): string;
|
|
3
|
+
declare function buildDynamicWeightInputsLog(meta: unknown, amaConfig: unknown): string;
|
|
4
|
+
declare function buildDynamicWeightTuningLog(meta: unknown): string;
|
|
5
|
+
declare function buildAsymmetricBoundsLog(meta: unknown): string;
|
|
6
|
+
declare function buildStartupDefaultsLog(defaultAma: unknown, defaultConfig: unknown, marketAdapterCfg: unknown): string;
|
|
7
7
|
export { formatLogPercent, buildWeightSummary, buildDynamicWeightInputsLog, buildDynamicWeightTuningLog, buildAsymmetricBoundsLog, buildStartupDefaultsLog };
|
|
8
8
|
//# sourceMappingURL=log_format.d.ts.map
|
|
@@ -18,47 +18,54 @@ function formatLogPair(first, second, digits = 2) {
|
|
|
18
18
|
function formatAmaTuple(ama) {
|
|
19
19
|
if (!ama)
|
|
20
20
|
return 'n/a';
|
|
21
|
-
|
|
21
|
+
const a = ama;
|
|
22
|
+
return `${formatLogNumber(a.erPeriod, 0)}/${formatLogNumber(a.fastPeriod, 1)}/${formatLogNumber(a.slowPeriod, 1)}`;
|
|
22
23
|
}
|
|
23
24
|
function formatAsymmetryFactor(value, digits = 1) {
|
|
24
25
|
return Number.isFinite(value) ? `${(Number(value) * 100).toFixed(digits)}%` : 'n/a';
|
|
25
26
|
}
|
|
26
27
|
function buildWeightSummary(weights) {
|
|
27
|
-
|
|
28
|
+
const w = weights;
|
|
29
|
+
return w ? ` weights(sell/buy)=${formatLogPair(w.sell, w.buy, 2)}` : '';
|
|
28
30
|
}
|
|
29
31
|
function buildDynamicWeightInputsLog(meta, amaConfig) {
|
|
32
|
+
const m = meta;
|
|
30
33
|
return [
|
|
31
34
|
`ama=${formatAmaTuple(amaConfig)}`,
|
|
32
|
-
`base=${formatLogPair(
|
|
33
|
-
`clamp=${formatLogPair(
|
|
34
|
-
`atr=${formatLogNumber(
|
|
35
|
-
`confirm=${Number.isFinite(
|
|
35
|
+
`base=${formatLogPair(m?.staticSell, m?.staticBuy, 2)}`,
|
|
36
|
+
`clamp=${formatLogPair(m?.maxSlopeOffset, m?.maxVolatilityOffset, 2)}`,
|
|
37
|
+
`atr=${formatLogNumber(m?.atrPeriod, 0)}`,
|
|
38
|
+
`confirm=${Number.isFinite(Number(m?.signalConfirmBars)) ? Math.round(Number(m?.signalConfirmBars)) : 'n/a'}`,
|
|
36
39
|
].join(' | ');
|
|
37
40
|
}
|
|
38
41
|
function buildDynamicWeightTuningLog(meta) {
|
|
42
|
+
const m = meta;
|
|
39
43
|
return [
|
|
40
|
-
`slopeMax=${formatAdaptiveLogNumber(
|
|
41
|
-
`kalmanMax=${formatLogNumber(
|
|
42
|
-
`alpha=${formatLogNumber(
|
|
43
|
-
`dw=${formatLogNumber(
|
|
44
|
-
`gain=${formatLogNumber(
|
|
45
|
-
`vol(thr/exp/x)=${formatLogNumber(
|
|
46
|
-
`clip=${formatLogPercent(
|
|
47
|
-
`nz=${formatAdaptiveLogNumber(
|
|
48
|
-
`minOut=${formatLogNumber(
|
|
49
|
-
`reg(sens/abs)=${formatLogNumber(
|
|
50
|
-
`kalman(sm/disp/th/span)=${formatLogNumber(
|
|
44
|
+
`slopeMax=${formatAdaptiveLogNumber(m?.amaSlope?.maxSlopePct, 2, 4)}`,
|
|
45
|
+
`kalmanMax=${formatLogNumber(m?.kalmanSlope?.maxSlopePct, 2)}`,
|
|
46
|
+
`alpha=${formatLogNumber(m?.alpha, 2)}`,
|
|
47
|
+
`dw=${formatLogNumber(m?.dw, 2)}`,
|
|
48
|
+
`gain=${formatLogNumber(m?.gain, 2)}`,
|
|
49
|
+
`vol(thr/exp/x)=${formatLogNumber(m?.volatilityThreshold, 2)}/${formatLogNumber(m?.volatilityExponent, 2)}/${formatLogNumber(m?.volatilityScaleX, 2)}`,
|
|
50
|
+
`clip=${formatLogPercent(m?.clipPercentile, 0)}`,
|
|
51
|
+
`nz=${formatAdaptiveLogNumber(m?.neutralZonePct, 2, 4)}`,
|
|
52
|
+
`minOut=${formatLogNumber(m?.minOutputThreshold, 2)}`,
|
|
53
|
+
`reg(sens/abs)=${formatLogNumber(m?.regimeSensitivity, 2)}/${formatLogNumber(m?.absoluteThreshold, 2)}`,
|
|
54
|
+
`kalman(sm/disp/th/span)=${formatLogNumber(m?.kalmanSmoothPct, 2)}/${formatLogNumber(m?.kalmanDispScaleMult, 2)}/${formatLogNumber(m?.kalmanDispThresholdMult, 2)}/${formatLogNumber(m?.kalmanSmoothSpanPct, 2)}`,
|
|
51
55
|
].join(' | ');
|
|
52
56
|
}
|
|
53
57
|
function buildAsymmetricBoundsLog(meta) {
|
|
54
|
-
|
|
58
|
+
const m = meta;
|
|
59
|
+
return `raw=${formatAsymmetryFactor(m?.rawAsymmetryFactor, 2)}, applied=${formatAsymmetryFactor(m?.appliedAsymmetryFactor, 2)}, maxAsym=${formatAsymmetryFactor(m?.maxAsymmetryFactor, 0)}`;
|
|
55
60
|
}
|
|
56
61
|
function buildStartupDefaultsLog(defaultAma, defaultConfig, marketAdapterCfg) {
|
|
62
|
+
const c = defaultConfig;
|
|
63
|
+
const cfg = marketAdapterCfg;
|
|
57
64
|
return ` defaults: ama=${formatAmaTuple(defaultAma)} | `
|
|
58
|
-
+ `weightFallback=${formatLogPair(
|
|
65
|
+
+ `weightFallback=${formatLogPair(c?.weightDistribution?.sell, c?.weightDistribution?.buy, 2)} | `
|
|
59
66
|
+ `dynamicBase=explicit-only | `
|
|
60
|
-
+ `clamp=${formatLogPair(
|
|
61
|
-
+ `asymCap=${formatAsymmetryFactor(
|
|
67
|
+
+ `clamp=${formatLogPair(cfg?.DYNAMIC_WEIGHT_ASYMMETRIC_OFFSET_CLAMP, cfg?.DYNAMIC_WEIGHT_SYMMETRIC_SHIFT_CLAMP, 2)} | `
|
|
68
|
+
+ `asymCap=${formatAsymmetryFactor(cfg?.ASYMMETRIC_BOUNDS_MAX_ASYMMETRY_FACTOR, 0)}`;
|
|
62
69
|
}
|
|
63
70
|
export { formatLogPercent, buildWeightSummary, buildDynamicWeightInputsLog, buildDynamicWeightTuningLog, buildAsymmetricBoundsLog, buildStartupDefaultsLog };
|
|
64
71
|
//# sourceMappingURL=log_format.js.map
|
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
interface ChartMeta {
|
|
2
|
+
assetA?: unknown;
|
|
3
|
+
assetB?: unknown;
|
|
4
|
+
intervalSeconds?: unknown;
|
|
5
|
+
fetchedAt?: unknown;
|
|
6
|
+
pool?: unknown;
|
|
7
|
+
thresholds?: Array<{
|
|
8
|
+
quantile: number;
|
|
9
|
+
multiplier: unknown;
|
|
10
|
+
}>;
|
|
11
|
+
sigmaAmaDelta?: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface AmaResult {
|
|
14
|
+
values?: unknown[];
|
|
15
|
+
erPeriod?: unknown;
|
|
16
|
+
name?: unknown;
|
|
17
|
+
color?: unknown;
|
|
18
|
+
lineWidth?: number;
|
|
19
|
+
fastPeriod?: unknown;
|
|
20
|
+
slowPeriod?: unknown;
|
|
21
|
+
}
|
|
22
|
+
declare function generateHTML(meta: ChartMeta | null, candles: unknown, amaResults: AmaResult[]): string;
|
|
2
23
|
export { generateHTML };
|
|
3
24
|
//# sourceMappingURL=lp_chart_core.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
import { toIntervalLabel } from './interval_utils.js';
|
|
3
|
-
import { escapeHtml, serializeJsonForScript, uplotInlineTags } from '../analysis/chart_utils.js';
|
|
3
|
+
import { escapeHtml, serializeJsonForScript, UPLOT_SHARED_SCRIPT, uplotInlineTags } from '../analysis/chart_utils.js';
|
|
4
|
+
import { makeCursorConfig, bindHoverStateFn, zoomResetScript } from '../analysis/chart_ui.js';
|
|
4
5
|
import { fixedTo, roundTo, roundToDecimals } from '../modules/order/utils/math.js';
|
|
5
6
|
function formatPct(v) {
|
|
6
7
|
const num = Number(v);
|
|
@@ -9,17 +10,19 @@ function formatPct(v) {
|
|
|
9
10
|
return `${num >= 0 ? '+' : ''}${num.toFixed(2)}%`;
|
|
10
11
|
}
|
|
11
12
|
function padRange(min, max, lower = 0.04, upper = 0.04) {
|
|
12
|
-
|
|
13
|
+
const lo = Number(min);
|
|
14
|
+
const hi = Number(max);
|
|
15
|
+
if (!Number.isFinite(lo) || !Number.isFinite(hi))
|
|
13
16
|
return null;
|
|
14
|
-
if (
|
|
15
|
-
const delta = Math.abs(
|
|
16
|
-
return [
|
|
17
|
+
if (lo === hi) {
|
|
18
|
+
const delta = Math.abs(lo) * 0.03 || 1;
|
|
19
|
+
return [lo - delta, hi + delta];
|
|
17
20
|
}
|
|
18
|
-
const span =
|
|
19
|
-
return [
|
|
21
|
+
const span = hi - lo;
|
|
22
|
+
return [lo - span * lower, hi + span * upper];
|
|
20
23
|
}
|
|
21
24
|
function generateHTML(meta, candles, amaResults) {
|
|
22
|
-
const { assetA = {}, assetB = {}, intervalSeconds, fetchedAt, pool, thresholds = [], sigmaAmaDelta } = meta || {};
|
|
25
|
+
const { assetA = {}, assetB = {}, intervalSeconds, fetchedAt, pool, thresholds = [], sigmaAmaDelta } = (meta || {});
|
|
23
26
|
if (!Array.isArray(candles) || candles.length === 0) {
|
|
24
27
|
throw new Error('No candles supplied to LP uPlot renderer');
|
|
25
28
|
}
|
|
@@ -29,22 +32,23 @@ function generateHTML(meta, candles, amaResults) {
|
|
|
29
32
|
const poolLabel = pool
|
|
30
33
|
? `Pool ${String(pool).replace('1.19.', '')}`
|
|
31
34
|
: `${assetA.symbol || '?'} / ${assetB.symbol || '?'}`;
|
|
32
|
-
const intervalLabel = toIntervalLabel(intervalSeconds);
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
35
|
+
const intervalLabel = toIntervalLabel(Number(intervalSeconds));
|
|
36
|
+
const candleRows = candles;
|
|
37
|
+
const ts = candleRows.map((c) => Math.round(Number(c[0]) / 1000));
|
|
38
|
+
const closes = candleRows.map((c) => roundToDecimals(Number(c[4]), 6));
|
|
39
|
+
const volumes = candleRows.map((c) => roundToDecimals(Number(c[5] ?? 0), 4));
|
|
36
40
|
const primary = amaResults[0];
|
|
37
41
|
const primaryValues = Array.isArray(primary.values) ? primary.values : [];
|
|
38
|
-
const primarySkip = Number
|
|
42
|
+
const primarySkip = Number(primary.erPeriod) || 0;
|
|
39
43
|
const validCloses = closes.slice(primarySkip);
|
|
40
44
|
const validPrimary = primaryValues.slice(primarySkip);
|
|
41
45
|
const maxDev = validCloses.length && validPrimary.length
|
|
42
|
-
? Math.max(...validCloses.map((p, i) => Math.abs((p -
|
|
46
|
+
? Math.max(...validCloses.map((p, i) => { const vp = Number(validPrimary[i]); return vp === 0 ? 0 : Math.abs((p - vp) / vp) * 100; }))
|
|
43
47
|
: 0;
|
|
44
48
|
const lastPrice = closes[closes.length - 1];
|
|
45
49
|
const amaStats = amaResults.map((a) => {
|
|
46
50
|
const values = Array.isArray(a.values) ? a.values : [];
|
|
47
|
-
const lastVal = values[values.length - 1];
|
|
51
|
+
const lastVal = Number(values[values.length - 1]);
|
|
48
52
|
const dev = Number.isFinite(lastVal) && lastVal !== 0
|
|
49
53
|
? ((lastPrice - lastVal) / lastVal) * 100
|
|
50
54
|
: 0;
|
|
@@ -186,7 +190,7 @@ function generateHTML(meta, candles, amaResults) {
|
|
|
186
190
|
<div id="header">
|
|
187
191
|
<h1><span style="color:#fb8c00">${escapeHtml(poolLabel)}</span> LP Swap Price</h1>
|
|
188
192
|
<span class="sub">BitShares DEX · ${escapeHtml(intervalLabel)} buckets · ${amaResults.length} AMAs</span>
|
|
189
|
-
<span class="sub" style="margin-left:auto">Fetched: ${fetchedAt ? escapeHtml(new Date(fetchedAt).toLocaleString()) : 'n/a'}</span>
|
|
193
|
+
<span class="sub" style="margin-left:auto">Fetched: ${fetchedAt ? escapeHtml(new Date(String(fetchedAt)).toLocaleString()) : 'n/a'}</span>
|
|
190
194
|
</div>
|
|
191
195
|
|
|
192
196
|
<div id="right-panel">
|
|
@@ -331,15 +335,7 @@ function makeYAxis(show, formatter, size = 58) {
|
|
|
331
335
|
}
|
|
332
336
|
|
|
333
337
|
function makeCursor() {
|
|
334
|
-
return {
|
|
335
|
-
show: true,
|
|
336
|
-
x: true,
|
|
337
|
-
y: true,
|
|
338
|
-
points: { show: false },
|
|
339
|
-
drag: { x: false, y: false, setScale: false },
|
|
340
|
-
sync: { key: chartGroupId, setSeries: false, scales: ['x', null] },
|
|
341
|
-
focus: { prox: -1 },
|
|
342
|
-
};
|
|
338
|
+
return ${makeCursorConfig('chartGroupId')};
|
|
343
339
|
}
|
|
344
340
|
|
|
345
341
|
function makePlotBase(showX, yFormatter, yScale, yRange, extraHooks = {}) {
|
|
@@ -565,7 +561,7 @@ priceChart = initChart('price-chart', {
|
|
|
565
561
|
padding: [8, 8, 12, 8],
|
|
566
562
|
series: [
|
|
567
563
|
{ label: 'Time' },
|
|
568
|
-
lineSeries('${escapeHtml(assetA.symbol || '?')}/${escapeHtml(assetB.symbol || '?')} VWAP', '#5c9ee6', 1.5),
|
|
564
|
+
lineSeries('${escapeHtml(String(assetA.symbol || '?'))}/${escapeHtml(String(assetB.symbol || '?'))} VWAP', '#5c9ee6', 1.5),
|
|
569
565
|
...amaMeta.map((cfg) => lineSeries(cfg.name, cfg.color, cfg.lineWidth || 1.5)),
|
|
570
566
|
],
|
|
571
567
|
}, priceData);
|
|
@@ -614,7 +610,7 @@ volChart = initChart('vol-chart', {
|
|
|
614
610
|
series: [
|
|
615
611
|
{ label: 'Time' },
|
|
616
612
|
{
|
|
617
|
-
label: 'Volume (' + ${JSON.stringify(escapeHtml(assetA.symbol || '?'))} + ')',
|
|
613
|
+
label: 'Volume (' + ${JSON.stringify(escapeHtml(String(assetA.symbol || '?')))} + ')',
|
|
618
614
|
stroke: 'rgba(92,158,230,1)',
|
|
619
615
|
fill: 'rgba(92,158,230,1)',
|
|
620
616
|
width: 1,
|
|
@@ -634,167 +630,9 @@ const [xMin, xMax] = [ts[0], ts[ts.length - 1]];
|
|
|
634
630
|
let pendingRange = null;
|
|
635
631
|
let pendingRangeRaf = 0;
|
|
636
632
|
|
|
637
|
-
|
|
638
|
-
let nextMin = min;
|
|
639
|
-
let nextMax = max;
|
|
640
|
-
const span = nextMax - nextMin;
|
|
641
|
-
if (!Number.isFinite(span) || span <= 0) {
|
|
642
|
-
return { min: xMin, max: xMax };
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
if (nextMin < xMin) {
|
|
646
|
-
nextMax += xMin - nextMin;
|
|
647
|
-
nextMin = xMin;
|
|
648
|
-
}
|
|
649
|
-
if (nextMax > xMax) {
|
|
650
|
-
nextMin -= nextMax - xMax;
|
|
651
|
-
nextMax = xMax;
|
|
652
|
-
}
|
|
653
|
-
if (nextMin < xMin) nextMin = xMin;
|
|
654
|
-
if (nextMax > xMax) nextMax = xMax;
|
|
655
|
-
if (nextMax <= nextMin) {
|
|
656
|
-
return { min: xMin, max: xMax };
|
|
657
|
-
}
|
|
658
|
-
return { min: nextMin, max: nextMax };
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
function syncXRange(min, max) {
|
|
662
|
-
pendingRange = clampXRange(min, max);
|
|
663
|
-
if (pendingRangeRaf) return;
|
|
664
|
-
|
|
665
|
-
const rafSync = window.requestAnimationFrame
|
|
666
|
-
? window.requestAnimationFrame.bind(window)
|
|
667
|
-
: (fn) => setTimeout(fn, 0);
|
|
668
|
-
|
|
669
|
-
pendingRangeRaf = rafSync(() => {
|
|
670
|
-
const next = pendingRange;
|
|
671
|
-
pendingRange = null;
|
|
672
|
-
pendingRangeRaf = 0;
|
|
673
|
-
if (!next) return;
|
|
674
|
-
charts.forEach((chart) => {
|
|
675
|
-
chart.batch(() => {
|
|
676
|
-
chart.setScale('x', next);
|
|
677
|
-
});
|
|
678
|
-
});
|
|
679
|
-
});
|
|
680
|
-
}
|
|
633
|
+
${UPLOT_SHARED_SCRIPT}
|
|
681
634
|
|
|
682
|
-
|
|
683
|
-
const onWheel = (e) => {
|
|
684
|
-
if (!e) return;
|
|
685
|
-
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
686
|
-
e.preventDefault();
|
|
687
|
-
e.stopPropagation();
|
|
688
|
-
|
|
689
|
-
const rect = chart.root.getBoundingClientRect();
|
|
690
|
-
|
|
691
|
-
// Correctly calculate plot-relative 'left' for accurate centering
|
|
692
|
-
const left = e.clientX - rect.left - (chart.bbox.left / (chart.pxRatio || 1));
|
|
693
|
-
const center = chart.posToVal(left, 'x');
|
|
694
|
-
|
|
695
|
-
const xScale = chart.scales.x || {};
|
|
696
|
-
const currMin = Number.isFinite(xScale.min) ? xScale.min : xMin;
|
|
697
|
-
const currMax = Number.isFinite(xScale.max) ? xScale.max : xMax;
|
|
698
|
-
const span = currMax - currMin;
|
|
699
|
-
if (!Number.isFinite(span) || span <= 0) return;
|
|
700
|
-
|
|
701
|
-
const factor = e.deltaY < 0 ? 0.85 : 1.15;
|
|
702
|
-
const nextSpan = Math.max(1, Math.min(xMax - xMin, span * factor));
|
|
703
|
-
const ratio = (center - currMin) / span;
|
|
704
|
-
const nextMin = center - nextSpan * ratio;
|
|
705
|
-
const nextMax = nextMin + nextSpan;
|
|
706
|
-
|
|
707
|
-
syncXRange(nextMin, nextMax);
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
chart.root.addEventListener('wheel', onWheel, { passive: false });
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
function bindPan(chart) {
|
|
714
|
-
let dragging = false;
|
|
715
|
-
let startClientX = 0;
|
|
716
|
-
let startClientY = 0;
|
|
717
|
-
let startMin = xMin;
|
|
718
|
-
let startMax = xMax;
|
|
719
|
-
let xUnitsPerPx = 0;
|
|
720
|
-
|
|
721
|
-
const getCurrentScale = () => {
|
|
722
|
-
const xScale = chart.scales.x || {};
|
|
723
|
-
const currMin = Number.isFinite(xScale.min) ? xScale.min : xMin;
|
|
724
|
-
const currMax = Number.isFinite(xScale.max) ? xScale.max : xMax;
|
|
725
|
-
return { currMin, currMax };
|
|
726
|
-
};
|
|
727
|
-
|
|
728
|
-
const onMouseMove = (e) => {
|
|
729
|
-
if (!dragging) return;
|
|
730
|
-
|
|
731
|
-
// Ignore if vertical movement is dominant (likely scrolling)
|
|
732
|
-
if (Math.abs(e.clientY - startClientY) > 20) return;
|
|
733
|
-
|
|
734
|
-
e.preventDefault();
|
|
735
|
-
const deltaPx = e.clientX - startClientX;
|
|
736
|
-
const deltaVal = deltaPx * xUnitsPerPx;
|
|
737
|
-
|
|
738
|
-
syncXRange(startMin - deltaVal, startMax - deltaVal);
|
|
739
|
-
};
|
|
740
|
-
|
|
741
|
-
const endDrag = () => {
|
|
742
|
-
if (!dragging) return;
|
|
743
|
-
dragging = false;
|
|
744
|
-
document.body.style.cursor = '';
|
|
745
|
-
window.removeEventListener('mousemove', onMouseMove);
|
|
746
|
-
window.removeEventListener('mouseup', endDrag);
|
|
747
|
-
};
|
|
748
|
-
|
|
749
|
-
const onMouseDown = (e) => {
|
|
750
|
-
if (!e || e.button !== 0) return;
|
|
751
|
-
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
752
|
-
|
|
753
|
-
const rect = chart.root.getBoundingClientRect();
|
|
754
|
-
const inside = e.clientX >= rect.left && e.clientX <= rect.right && e.clientY >= rect.top && e.clientY <= rect.bottom;
|
|
755
|
-
if (!inside) return;
|
|
756
|
-
|
|
757
|
-
e.preventDefault();
|
|
758
|
-
e.stopPropagation();
|
|
759
|
-
|
|
760
|
-
dragging = true;
|
|
761
|
-
startClientX = e.clientX;
|
|
762
|
-
startClientY = e.clientY;
|
|
763
|
-
const current = getCurrentScale();
|
|
764
|
-
startMin = current.currMin;
|
|
765
|
-
startMax = current.currMax;
|
|
766
|
-
|
|
767
|
-
// Calculate units per pixel once at start of drag to avoid sliding bug
|
|
768
|
-
// chart.bbox.width is in device pixels; divide by pxRatio for CSS pixels
|
|
769
|
-
xUnitsPerPx = (current.currMax - current.currMin) / (chart.bbox.width / (chart.pxRatio || 1));
|
|
770
|
-
|
|
771
|
-
document.body.style.cursor = 'grabbing';
|
|
772
|
-
window.addEventListener('mousemove', onMouseMove);
|
|
773
|
-
window.addEventListener('mouseup', endDrag, { once: true });
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
chart.root.addEventListener('mousedown', onMouseDown);
|
|
777
|
-
chart.root.addEventListener('mouseleave', () => {
|
|
778
|
-
if (!dragging) return;
|
|
779
|
-
document.body.style.cursor = 'grabbing';
|
|
780
|
-
});
|
|
781
|
-
window.addEventListener('blur', endDrag);
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
function bindHoverState(chart) {
|
|
785
|
-
const root = chart.root;
|
|
786
|
-
root.addEventListener('mouseenter', () => {
|
|
787
|
-
root.classList.add('is-hovered');
|
|
788
|
-
});
|
|
789
|
-
root.addEventListener('mouseleave', () => {
|
|
790
|
-
root.classList.remove('is-hovered');
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
function resetZoom() {
|
|
795
|
-
pendingRange = null;
|
|
796
|
-
syncXRange(xMin, xMax);
|
|
797
|
-
}
|
|
635
|
+
${bindHoverStateFn()}
|
|
798
636
|
|
|
799
637
|
function sizeCharts() {
|
|
800
638
|
applyChartHeights();
|
|
@@ -807,11 +645,7 @@ function sizeCharts() {
|
|
|
807
645
|
}
|
|
808
646
|
|
|
809
647
|
window.addEventListener('resize', sizeCharts);
|
|
810
|
-
|
|
811
|
-
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === '0') {
|
|
812
|
-
resetZoom();
|
|
813
|
-
}
|
|
814
|
-
});
|
|
648
|
+
${zoomResetScript()}
|
|
815
649
|
|
|
816
650
|
charts.forEach((chart) => {
|
|
817
651
|
bindWheelZoom(chart);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { findLatestLpData } from './utils/data_discovery.js';
|
|
2
2
|
declare const DEFAULT_COMPARISON_STRATEGIES: {
|
|
3
|
-
name:
|
|
4
|
-
erPeriod:
|
|
5
|
-
fastPeriod:
|
|
6
|
-
slowPeriod:
|
|
3
|
+
name: string;
|
|
4
|
+
erPeriod: number;
|
|
5
|
+
fastPeriod: number;
|
|
6
|
+
slowPeriod: number;
|
|
7
7
|
color: string;
|
|
8
8
|
dash: string;
|
|
9
9
|
}[];
|
|
@@ -52,8 +52,9 @@ interface CliArgOptions {
|
|
|
52
52
|
}
|
|
53
53
|
interface MarketChartOptions {
|
|
54
54
|
dataFile?: string;
|
|
55
|
+
dataBundle?: LpDataBundle;
|
|
55
56
|
logger?: {
|
|
56
|
-
log: (...args:
|
|
57
|
+
log: (...args: unknown[]) => void;
|
|
57
58
|
};
|
|
58
59
|
profilesFile?: string;
|
|
59
60
|
outFile?: string;
|
|
@@ -61,8 +62,9 @@ interface MarketChartOptions {
|
|
|
61
62
|
}
|
|
62
63
|
interface ComparisonChartOptions {
|
|
63
64
|
dataFile?: string;
|
|
65
|
+
dataBundle?: LpDataBundle;
|
|
64
66
|
logger?: {
|
|
65
|
-
log: (...args:
|
|
67
|
+
log: (...args: unknown[]) => void;
|
|
66
68
|
};
|
|
67
69
|
defaultStrategies?: AmaConfig[];
|
|
68
70
|
profilesFile?: string | null;
|
|
@@ -71,8 +73,9 @@ interface ComparisonChartOptions {
|
|
|
71
73
|
}
|
|
72
74
|
interface BundleChartOptions {
|
|
73
75
|
dataFile?: string;
|
|
76
|
+
dataBundle?: LpDataBundle;
|
|
74
77
|
logger?: {
|
|
75
|
-
log: (...args:
|
|
78
|
+
log: (...args: unknown[]) => void;
|
|
76
79
|
};
|
|
77
80
|
profilesFile?: string;
|
|
78
81
|
defaultStrategies?: AmaConfig[];
|
|
@@ -7,7 +7,7 @@ import { calculateAMA } from './core/strategies/ama.js';
|
|
|
7
7
|
import { MARKET_ADAPTER } from '../modules/constants.js';
|
|
8
8
|
import { generateHTML } from './lp_chart_core.js';
|
|
9
9
|
import { loadStrategiesForLpChart } from './lp_chart_strategy_loader.js';
|
|
10
|
-
import { findLatestLpData } from './utils/data_discovery.js';
|
|
10
|
+
import { findLatestLpData, loadLatestLpSeries, loadLpSeriesFromPath } from './utils/data_discovery.js';
|
|
11
11
|
import { PATHS } from '../modules/paths.js';
|
|
12
12
|
/**
|
|
13
13
|
* LP CHART RUNNER — Shared LP chart orchestration
|
|
@@ -30,7 +30,7 @@ import { PATHS } from '../modules/paths.js';
|
|
|
30
30
|
* - fetch/export of LP data (`market_adapter/inputs/fetch_lp_data.ts`)
|
|
31
31
|
*/
|
|
32
32
|
const storage = getStorage();
|
|
33
|
-
const { ensureDir
|
|
33
|
+
const { ensureDir } = storage;
|
|
34
34
|
const ANALYSIS_CHARTS_DIR = PATHS.ANALYSIS.CHARTS_DIR;
|
|
35
35
|
const AMA_PROFILES_FILE = PATHS.PROFILES.MARKET_PROFILES_JSON;
|
|
36
36
|
const DEFAULT_COMPARISON_COLORS = ['#26a69a', '#fb8c00', '#5c9ee6', '#ef5350'];
|
|
@@ -100,7 +100,11 @@ function normalizeLpCandle(candle, index) {
|
|
|
100
100
|
throw new Error(`Invalid candle row at index ${index}: unsupported format`);
|
|
101
101
|
}
|
|
102
102
|
function resolveLpDataFile(dataFile) {
|
|
103
|
-
|
|
103
|
+
// Explicit path wins. Otherwise resolve through the assembling loader so a
|
|
104
|
+
// shard-only cache yields a representative source path instead of null.
|
|
105
|
+
const resolved = dataFile
|
|
106
|
+
? path.resolve(dataFile)
|
|
107
|
+
: (loadLatestLpSeries()?.path ?? findLatestLpData());
|
|
104
108
|
if (!resolved) {
|
|
105
109
|
throw new Error('No LP data file found. Use --data <path> or run the fetch step first.');
|
|
106
110
|
}
|
|
@@ -109,16 +113,9 @@ function resolveLpDataFile(dataFile) {
|
|
|
109
113
|
}
|
|
110
114
|
return resolved;
|
|
111
115
|
}
|
|
112
|
-
function
|
|
113
|
-
const resolved = resolveLpDataFile(dataFile);
|
|
114
|
-
const raw = readJSON(resolved);
|
|
115
|
-
const meta = (raw.meta ?? null);
|
|
116
|
-
const candles = Array.isArray(raw?.candles) ? raw.candles : (Array.isArray(raw) ? raw : []);
|
|
117
|
-
if (!Array.isArray(candles) || candles.length === 0) {
|
|
118
|
-
throw new Error('No candles in data file.');
|
|
119
|
-
}
|
|
116
|
+
function bundleFrom(dataFile, meta, candles) {
|
|
120
117
|
return {
|
|
121
|
-
dataFile
|
|
118
|
+
dataFile,
|
|
122
119
|
meta,
|
|
123
120
|
candleArrays: candles.map((c, index) => normalizeLpCandle(c, index)),
|
|
124
121
|
candleObjects: candles.map((c, index) => {
|
|
@@ -134,6 +131,24 @@ function loadLpDataFile(dataFile) {
|
|
|
134
131
|
}),
|
|
135
132
|
};
|
|
136
133
|
}
|
|
134
|
+
function loadLpDataFile(dataFile) {
|
|
135
|
+
// Explicit path: read the file as before. Auto-discovery: assemble the
|
|
136
|
+
// complete series (merging month shards when they are the newest source),
|
|
137
|
+
// so a shard-only cache charts the whole history, not one month.
|
|
138
|
+
if (!dataFile) {
|
|
139
|
+
const series = loadLatestLpSeries();
|
|
140
|
+
if (!series || series.candles.length === 0) {
|
|
141
|
+
throw new Error('No LP data found. Use --data <path> or run the fetch step first.');
|
|
142
|
+
}
|
|
143
|
+
return bundleFrom(series.path, series.meta, series.candles);
|
|
144
|
+
}
|
|
145
|
+
const resolved = resolveLpDataFile(dataFile);
|
|
146
|
+
const series = loadLpSeriesFromPath(resolved);
|
|
147
|
+
if (!series || series.candles.length === 0) {
|
|
148
|
+
throw new Error('No candles in data file.');
|
|
149
|
+
}
|
|
150
|
+
return bundleFrom(series.path, series.meta, series.candles);
|
|
151
|
+
}
|
|
137
152
|
function openInBrowser(filePath) {
|
|
138
153
|
const url = `file://${filePath}`;
|
|
139
154
|
const cmd = process.platform === 'darwin'
|
|
@@ -203,7 +218,7 @@ function writeChartHtml({ meta, candleArrays, amaResults, outFile }) {
|
|
|
203
218
|
}
|
|
204
219
|
function generateMarketLpChart(options = {}) {
|
|
205
220
|
const logger = options.logger ?? console;
|
|
206
|
-
const { dataFile, meta, candleArrays } = loadLpDataFile(options.dataFile);
|
|
221
|
+
const { dataFile, meta, candleArrays } = options.dataBundle ?? loadLpDataFile(options.dataFile);
|
|
207
222
|
logger.log(`Reading: ${path.relative(process.cwd(), dataFile)}`);
|
|
208
223
|
const poolLabel = meta?.pool ? `pool ${meta.pool}` : `${meta?.assetA?.symbol || '?'}\/${meta?.assetB?.symbol || '?'}`;
|
|
209
224
|
logger.log(` ${candleArrays.length} candles · ${poolLabel}`);
|
|
@@ -241,7 +256,7 @@ function generateMarketLpChart(options = {}) {
|
|
|
241
256
|
}
|
|
242
257
|
function generateComparisonLpChart(options = {}) {
|
|
243
258
|
const logger = options.logger ?? console;
|
|
244
|
-
const { dataFile, meta, candleArrays, candleObjects } = loadLpDataFile(options.dataFile);
|
|
259
|
+
const { dataFile, meta, candleArrays, candleObjects } = options.dataBundle ?? loadLpDataFile(options.dataFile);
|
|
245
260
|
const defaultStrategies = options.defaultStrategies ?? DEFAULT_COMPARISON_STRATEGIES;
|
|
246
261
|
const strategies = loadStrategiesForLpChart({
|
|
247
262
|
dataFile,
|
|
@@ -284,23 +299,26 @@ function generateComparisonLpChart(options = {}) {
|
|
|
284
299
|
}
|
|
285
300
|
function generateLpChartBundle(options = {}) {
|
|
286
301
|
const logger = options.logger ?? console;
|
|
287
|
-
|
|
288
|
-
|
|
302
|
+
// Resolve/assemble ONCE, then hand the same loaded bundle to both charts —
|
|
303
|
+
// auto-discovery over shards would otherwise re-read and re-merge the whole
|
|
304
|
+
// family for each sub-chart.
|
|
305
|
+
const bundle = options.dataBundle ?? loadLpDataFile(options.dataFile);
|
|
306
|
+
logger.log(`Generating LP charts from ${path.relative(process.cwd(), bundle.dataFile)}`);
|
|
289
307
|
const marketChart = generateMarketLpChart({
|
|
290
|
-
|
|
308
|
+
dataBundle: bundle,
|
|
291
309
|
noOpen: options.noOpen,
|
|
292
310
|
logger,
|
|
293
311
|
profilesFile: options.profilesFile,
|
|
294
312
|
});
|
|
295
313
|
const comparisonChart = generateComparisonLpChart({
|
|
296
|
-
|
|
314
|
+
dataBundle: bundle,
|
|
297
315
|
noOpen: options.openComparison === true ? !!options.noOpen : true,
|
|
298
316
|
logger,
|
|
299
317
|
defaultStrategies: options.defaultStrategies ?? DEFAULT_COMPARISON_STRATEGIES,
|
|
300
318
|
profilesFile: options.comparisonProfilesFile ?? null,
|
|
301
319
|
});
|
|
302
320
|
return {
|
|
303
|
-
dataFile,
|
|
321
|
+
dataFile: bundle.dataFile,
|
|
304
322
|
marketChart,
|
|
305
323
|
comparisonChart,
|
|
306
324
|
};
|