dexbot 1.4.11 → 1.4.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/README.md +4 -4
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +9 -18
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/math_utils.d.ts.map +1 -1
- package/dist/analysis/math_utils.js +6 -16
- package/dist/analysis/math_utils.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +31 -38
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js +7 -10
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +10 -14
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +10 -15
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +7 -10
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +4 -12
- package/dist/bot.js.map +1 -1
- package/dist/credential-daemon.d.ts +0 -1
- package/dist/credential-daemon.d.ts.map +1 -1
- package/dist/credential-daemon.js +3 -123
- package/dist/credential-daemon.js.map +1 -1
- package/dist/dexbot.d.ts +0 -87
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +11 -14
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +8 -9
- package/dist/market_adapter/ama_signal_runner.js.map +1 -1
- package/dist/market_adapter/candle_utils.js +1 -7
- package/dist/market_adapter/candle_utils.js.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.js +1 -4
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
- package/dist/market_adapter/core/config_normalizers.js +5 -9
- package/dist/market_adapter/core/config_normalizers.js.map +1 -1
- package/dist/market_adapter/core/kibana_candles.js +8 -15
- package/dist/market_adapter/core/kibana_candles.js.map +1 -1
- package/dist/market_adapter/core/kibana_client.js +7 -13
- package/dist/market_adapter/core/kibana_client.js.map +1 -1
- package/dist/market_adapter/core/kibana_market_candles.js +6 -12
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +92 -102
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama.js +5 -10
- package/dist/market_adapter/core/strategies/ama.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +21 -24
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js +3 -5
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +4 -6
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.js +15 -22
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
- package/dist/market_adapter/index.d.ts +23 -23
- package/dist/market_adapter/index.d.ts.map +1 -1
- package/dist/market_adapter/index.js +24 -82
- package/dist/market_adapter/index.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +59 -98
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.js +11 -17
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
- package/dist/market_adapter/interval_utils.js +1 -2
- package/dist/market_adapter/interval_utils.js.map +1 -1
- package/dist/market_adapter/log_format.js +1 -7
- package/dist/market_adapter/log_format.js.map +1 -1
- package/dist/market_adapter/lp_chart_core.js +20 -22
- package/dist/market_adapter/lp_chart_core.js.map +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_runner.js +41 -57
- package/dist/market_adapter/lp_chart_runner.js.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js +30 -34
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
- package/dist/market_adapter/market_adapter.d.ts +2 -2
- package/dist/market_adapter/market_adapter.d.ts.map +1 -1
- package/dist/market_adapter/market_adapter.js +157 -221
- package/dist/market_adapter/market_adapter.js.map +1 -1
- package/dist/market_adapter/merge_lp_data.js +17 -18
- package/dist/market_adapter/merge_lp_data.js.map +1 -1
- package/dist/market_adapter/test_helpers.js +3 -14
- package/dist/market_adapter/test_helpers.js.map +1 -1
- package/dist/market_adapter/utils/adapter_client.js +7 -16
- package/dist/market_adapter/utils/adapter_client.js.map +1 -1
- package/dist/market_adapter/utils/atomic_write.js +3 -5
- package/dist/market_adapter/utils/atomic_write.js.map +1 -1
- package/dist/market_adapter/utils/chain.d.ts.map +1 -1
- package/dist/market_adapter/utils/chain.js +9 -17
- package/dist/market_adapter/utils/chain.js.map +1 -1
- package/dist/market_adapter/utils/data_discovery.js +8 -10
- package/dist/market_adapter/utils/data_discovery.js.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +11 -14
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
- package/dist/market_adapter/utils/file_lock.js +14 -19
- package/dist/market_adapter/utils/file_lock.js.map +1 -1
- package/dist/market_adapter/utils/native_history.js +8 -14
- package/dist/market_adapter/utils/native_history.js.map +1 -1
- package/dist/market_adapter/utils/paths.js +3 -6
- package/dist/market_adapter/utils/paths.js.map +1 -1
- package/dist/modules/account_bots.d.ts +1 -1
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +90 -97
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +0 -9
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +26 -121
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/authority_resolver.js +12 -18
- package/dist/modules/authority_resolver.js.map +1 -1
- package/dist/modules/bitshares-native/chain_client.js +16 -21
- package/dist/modules/bitshares-native/chain_client.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +12 -72
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -40
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +5 -6
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
- package/dist/modules/bitshares-native/index.d.ts +8 -8
- package/dist/modules/bitshares-native/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/index.js +11 -68
- package/dist/modules/bitshares-native/index.js.map +1 -1
- package/dist/modules/bitshares-native/lru_cache.js +3 -6
- package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
- package/dist/modules/bitshares-native/resolvers.js +9 -11
- package/dist/modules/bitshares-native/resolvers.js.map +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js +3 -28
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
- package/dist/modules/bitshares-native/serial/index.d.ts +4 -4
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/index.js +5 -46
- package/dist/modules/bitshares-native/serial/index.js.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts +98 -98
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.js +372 -473
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
- package/dist/modules/bitshares-native/serial/serializer.js +3 -8
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
- package/dist/modules/bitshares-native/serial/types.js +9 -74
- package/dist/modules/bitshares-native/serial/types.js.map +1 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/signing_client.js +11 -48
- package/dist/modules/bitshares-native/signing_client.js.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.js +24 -27
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
- package/dist/modules/bitshares-native/transport.js +14 -26
- package/dist/modules/bitshares-native/transport.js.map +1 -1
- package/dist/modules/bitshares-native/tx/builder.js +29 -72
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js +12 -21
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts +21 -0
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +32 -86
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +30 -49
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/bots_file_lock.d.ts.map +1 -1
- package/dist/modules/bots_file_lock.js +5 -13
- package/dist/modules/bots_file_lock.js.map +1 -1
- package/dist/modules/broadcast_failure.js +1 -3
- package/dist/modules/broadcast_failure.js.map +1 -1
- package/dist/modules/chain_keys.d.ts +4 -9
- package/dist/modules/chain_keys.d.ts.map +1 -1
- package/dist/modules/chain_keys.js +77 -182
- package/dist/modules/chain_keys.js.map +1 -1
- package/dist/modules/chain_orders.d.ts +2 -2
- package/dist/modules/chain_orders.d.ts.map +1 -1
- package/dist/modules/chain_orders.js +81 -144
- package/dist/modules/chain_orders.js.map +1 -1
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +23 -28
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +2 -9
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +38 -73
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/cr_planner.js +15 -26
- package/dist/modules/cr_planner.js.map +1 -1
- package/dist/modules/credential_policy.d.ts +3 -6
- package/dist/modules/credential_policy.d.ts.map +1 -1
- package/dist/modules/credential_policy.js +62 -153
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/credential_runtime.d.ts +1 -1
- package/dist/modules/credential_runtime.d.ts.map +1 -1
- package/dist/modules/credential_runtime.js +34 -41
- package/dist/modules/credential_runtime.js.map +1 -1
- package/dist/modules/credential_session_cache.d.ts +1 -1
- package/dist/modules/credential_session_cache.d.ts.map +1 -1
- package/dist/modules/credential_session_cache.js +5 -42
- package/dist/modules/credential_session_cache.js.map +1 -1
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +126 -162
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/crypto/browser_provider.d.ts +1 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +1 -1
- package/dist/modules/crypto/browser_provider.js +7 -11
- package/dist/modules/crypto/browser_provider.js.map +1 -1
- package/dist/modules/crypto/index.d.ts +6 -6
- package/dist/modules/crypto/index.d.ts.map +1 -1
- package/dist/modules/crypto/index.js +12 -30
- package/dist/modules/crypto/index.js.map +1 -1
- package/dist/modules/crypto/node_provider.d.ts +1 -1
- package/dist/modules/crypto/node_provider.d.ts.map +1 -1
- package/dist/modules/crypto/node_provider.js +3 -5
- package/dist/modules/crypto/node_provider.js.map +1 -1
- package/dist/modules/crypto/provider.js +1 -2
- package/dist/modules/crypto/pure_ripemd160.js +1 -3
- package/dist/modules/crypto/pure_ripemd160.js.map +1 -1
- package/dist/modules/crypto/pure_scrypt.js +1 -4
- package/dist/modules/crypto/pure_scrypt.js.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.js +1 -16
- package/dist/modules/crypto/pure_secp256k1.js.map +1 -1
- package/dist/modules/crypto/sync.d.ts.map +1 -1
- package/dist/modules/crypto/sync.js +16 -17
- package/dist/modules/crypto/sync.js.map +1 -1
- package/dist/modules/daemon_node_health.js +14 -16
- package/dist/modules/daemon_node_health.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +19 -14
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +127 -164
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +28 -27
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +55 -45
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_credential_client.d.ts +6 -2
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -1
- package/dist/modules/dexbot_credential_client.js +21 -31
- package/dist/modules/dexbot_credential_client.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +23 -23
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +119 -77
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +46 -38
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +81 -81
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts +3 -3
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_startup_runtime.js +43 -81
- package/dist/modules/dexbot_startup_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts +11 -11
- package/dist/modules/dexbot_state_recovery.js +32 -78
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/env.js +3 -7
- package/dist/modules/env.js.map +1 -1
- package/dist/modules/fund_registry.d.ts.map +1 -1
- package/dist/modules/fund_registry.js +12 -24
- package/dist/modules/fund_registry.js.map +1 -1
- package/dist/modules/general_settings.js +10 -16
- package/dist/modules/general_settings.js.map +1 -1
- package/dist/modules/graceful_shutdown.d.ts.map +1 -1
- package/dist/modules/graceful_shutdown.js +12 -19
- package/dist/modules/graceful_shutdown.js.map +1 -1
- package/dist/modules/key_store.d.ts.map +1 -1
- package/dist/modules/key_store.js +27 -65
- package/dist/modules/key_store.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +89 -118
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/child_env.js +1 -5
- package/dist/modules/launcher/child_env.js.map +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +22 -31
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -1
- package/dist/modules/launcher/credential_daemon.js +37 -75
- package/dist/modules/launcher/credential_daemon.js.map +1 -1
- package/dist/modules/launcher/credential_secret.js +2 -37
- package/dist/modules/launcher/credential_secret.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +25 -31
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/headless_password.js +10 -12
- package/dist/modules/launcher/headless_password.js.map +1 -1
- package/dist/modules/launcher/launch_modes.js +3 -9
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js +25 -35
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.js +42 -45
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +67 -138
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/runtime_entry.d.ts +1 -11
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
- package/dist/modules/launcher/runtime_entry.js +12 -15
- package/dist/modules/launcher/runtime_entry.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +1 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +15 -36
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/launcher/supervisor_control.js +4 -9
- package/dist/modules/launcher/supervisor_control.js.map +1 -1
- package/dist/modules/logger.d.ts +1 -1
- package/dist/modules/logger.d.ts.map +1 -1
- package/dist/modules/logger.js +3 -38
- package/dist/modules/logger.js.map +1 -1
- package/dist/modules/market_adapter_whitelist.js +9 -18
- package/dist/modules/market_adapter_whitelist.js.map +1 -1
- package/dist/modules/node_failure_ledger.js +1 -3
- package/dist/modules/node_failure_ledger.js.map +1 -1
- package/dist/modules/node_health_cache.d.ts.map +1 -1
- package/dist/modules/node_health_cache.js +15 -25
- package/dist/modules/node_health_cache.js.map +1 -1
- package/dist/modules/node_manager.d.ts +1 -1
- package/dist/modules/node_manager.d.ts.map +1 -1
- package/dist/modules/node_manager.js +44 -43
- package/dist/modules/node_manager.js.map +1 -1
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +102 -118
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/async_lock.d.ts +3 -15
- package/dist/modules/order/async_lock.d.ts.map +1 -1
- package/dist/modules/order/async_lock.js +6 -26
- package/dist/modules/order/async_lock.js.map +1 -1
- package/dist/modules/order/export.js +34 -75
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/format.d.ts +1 -3
- package/dist/modules/order/format.d.ts.map +1 -1
- package/dist/modules/order/format.js +4 -24
- package/dist/modules/order/format.js.map +1 -1
- package/dist/modules/order/grid.d.ts +3 -3
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +206 -262
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile.js +77 -94
- package/dist/modules/order/grid_reconcile.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +117 -149
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/index.d.ts.map +1 -1
- package/dist/modules/order/index.js +11 -45
- package/dist/modules/order/index.js.map +1 -1
- package/dist/modules/order/logger.js +28 -69
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/logger_state.d.ts.map +1 -1
- package/dist/modules/order/logger_state.js +3 -4
- package/dist/modules/order/logger_state.js.map +1 -1
- package/dist/modules/order/manager.d.ts +10 -0
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +131 -151
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/processed_fill_store.js +2 -7
- package/dist/modules/order/processed_fill_store.js.map +1 -1
- package/dist/modules/order/strategy.js +23 -25
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts +27 -0
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +232 -181
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +1 -25
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +49 -172
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +46 -2
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +165 -143
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +3 -1
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +152 -211
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/timeout.js +1 -4
- package/dist/modules/order/utils/timeout.js.map +1 -1
- package/dist/modules/order/utils/validate.js +91 -142
- package/dist/modules/order/utils/validate.js.map +1 -1
- package/dist/modules/order/utils/withPoolRef.js +21 -61
- package/dist/modules/order/utils/withPoolRef.js.map +1 -1
- package/dist/modules/order/working_grid.js +6 -9
- package/dist/modules/order/working_grid.js.map +1 -1
- package/dist/modules/path_api.d.ts.map +1 -1
- package/dist/modules/path_api.js +8 -11
- package/dist/modules/path_api.js.map +1 -1
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +61 -67
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/process_discovery.js +13 -21
- package/dist/modules/process_discovery.js.map +1 -1
- package/dist/modules/runtime.js +7 -11
- package/dist/modules/runtime.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +14 -16
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/modules/settings_merge.js +1 -3
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/socket_json_client.js +3 -5
- package/dist/modules/socket_json_client.js.map +1 -1
- package/dist/modules/storage/browser_adapter.js +1 -4
- package/dist/modules/storage/browser_adapter.js.map +1 -1
- package/dist/modules/storage/index.d.ts +3 -2
- package/dist/modules/storage/index.d.ts.map +1 -1
- package/dist/modules/storage/index.js +5 -8
- package/dist/modules/storage/index.js.map +1 -1
- package/dist/modules/storage/node_adapter.d.ts +3 -4
- package/dist/modules/storage/node_adapter.d.ts.map +1 -1
- package/dist/modules/storage/node_adapter.js +12 -16
- package/dist/modules/storage/node_adapter.js.map +1 -1
- package/dist/modules/storage/types.js +1 -2
- package/dist/modules/types.d.ts +0 -6
- package/dist/modules/types.d.ts.map +1 -1
- package/dist/modules/types.js +1 -2
- package/dist/modules/types.js.map +1 -1
- package/dist/modules/utils/base58check.js +8 -15
- package/dist/modules/utils/base58check.js.map +1 -1
- package/dist/modules/utils/build_dir.js +3 -7
- package/dist/modules/utils/build_dir.js.map +1 -1
- package/dist/modules/utils/errors.js +1 -5
- package/dist/modules/utils/errors.js.map +1 -1
- package/dist/modules/utils/math_utils.d.ts +1 -1
- package/dist/modules/utils/math_utils.d.ts.map +1 -1
- package/dist/modules/utils/math_utils.js +2 -7
- package/dist/modules/utils/math_utils.js.map +1 -1
- package/dist/modules/validate_profiles.d.ts.map +1 -1
- package/dist/modules/validate_profiles.js +18 -25
- package/dist/modules/validate_profiles.js.map +1 -1
- package/dist/pm2.d.ts +4 -70
- package/dist/pm2.d.ts.map +1 -1
- package/dist/pm2.js +106 -132
- package/dist/pm2.js.map +1 -1
- package/dist/scripts/analyze-git.js +13 -17
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/analyze-orders.d.ts.map +1 -1
- package/dist/scripts/analyze-orders.js +48 -63
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.js +2 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +1 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -1
- package/dist/scripts/diagnose-pool-history.js +2 -1
- package/dist/scripts/diagnose-pool-history.js.map +1 -1
- package/dist/scripts/divergence-calc.d.ts.map +1 -1
- package/dist/scripts/divergence-calc.js +2 -2
- package/dist/scripts/divergence-calc.js.map +1 -1
- package/dist/scripts/fix-err-message.js +17 -22
- package/dist/scripts/fix-err-message.js.map +1 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -1
- package/dist/scripts/generate_lp_chart.js +7 -15
- package/dist/scripts/generate_lp_chart.js.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.js +3 -2
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.js +18 -24
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -1
- package/dist/scripts/native_release_gates.js +15 -19
- package/dist/scripts/native_release_gates.js.map +1 -1
- package/dist/scripts/print_grid.d.ts.map +1 -1
- package/dist/scripts/print_grid.js +2 -2
- package/dist/scripts/print_grid.js.map +1 -1
- package/dist/scripts/run-tests.js +12 -17
- package/dist/scripts/run-tests.js.map +1 -1
- package/dist/scripts/runner.d.ts.map +1 -1
- package/dist/scripts/runner.js +18 -20
- package/dist/scripts/runner.js.map +1 -1
- package/dist/scripts/sync-version.js +2 -2
- package/dist/scripts/sync-version.js.map +1 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
- package/dist/scripts/test-credit-renewal.js +4 -3
- package/dist/scripts/test-credit-renewal.js.map +1 -1
- package/dist/scripts/update.js +77 -89
- package/dist/scripts/update.js.map +1 -1
- package/dist/scripts/validate_bots.d.ts.map +1 -1
- package/dist/scripts/validate_bots.js +2 -2
- package/dist/scripts/validate_bots.js.map +1 -1
- package/dist/scripts/verify-browser-bundle.js +12 -17
- package/dist/scripts/verify-browser-bundle.js.map +1 -1
- package/dist/unlock.d.ts +0 -30
- package/dist/unlock.d.ts.map +1 -1
- package/dist/unlock.js +95 -143
- package/dist/unlock.js.map +1 -1
- package/package.json +5 -8
- package/scripts/README.md +1 -1
- package/scripts/create-bot-symlinks.sh +2 -2
- package/dist/modules/utils/fs_utils.d.ts +0 -18
- package/dist/modules/utils/fs_utils.d.ts.map +0 -1
- package/dist/modules/utils/fs_utils.js +0 -32
- package/dist/modules/utils/fs_utils.js.map +0 -1
- package/dist/scripts/migrate_bot_keys.d.ts +0 -3
- package/dist/scripts/migrate_bot_keys.d.ts.map +0 -1
- package/dist/scripts/migrate_bot_keys.js +0 -225
- package/dist/scripts/migrate_bot_keys.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* modules/order/manager.ts - OrderManager Engine
|
|
4
3
|
*
|
|
@@ -14,62 +13,24 @@
|
|
|
14
13
|
* SECTION 3: ORDER MANAGER CLASS
|
|
15
14
|
* ===============================================================================
|
|
16
15
|
*/
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
-
var ownKeys = function(o) {
|
|
35
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
-
var ar = [];
|
|
37
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
-
return ar;
|
|
39
|
-
};
|
|
40
|
-
return ownKeys(o);
|
|
41
|
-
};
|
|
42
|
-
return function (mod) {
|
|
43
|
-
if (mod && mod.__esModule) return mod;
|
|
44
|
-
var result = {};
|
|
45
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
-
__setModuleDefault(result, mod);
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
})();
|
|
50
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
51
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.COWRebalanceEngine = exports.OrderManager = void 0;
|
|
55
16
|
// ===============================================================================
|
|
56
17
|
// SECTION 1: EXTERNAL DEPENDENCIES
|
|
57
18
|
// ===============================================================================
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
19
|
+
import { persistGridSnapshot, deepFreeze, cloneMap, withBlockchainRetry } from './utils/system.js';
|
|
20
|
+
import { withTimeout } from './utils/timeout.js';
|
|
21
|
+
import { WorkingGrid } from './working_grid.js';
|
|
22
|
+
import Logger from './logger.js';
|
|
23
|
+
import AsyncLock from './async_lock.js';
|
|
24
|
+
import Accountant from './accounting.js';
|
|
25
|
+
import StrategyEngine from './strategy.js';
|
|
26
|
+
import SyncEngine from './sync_engine.js';
|
|
27
|
+
import { calculateCurrentSpread, checkSpreadCondition, checkGridHealth } from './grid.js';
|
|
28
|
+
import * as Format from './format.js';
|
|
29
|
+
import { ORDER_TYPES, ORDER_STATES, REBALANCE_STATES, DEFAULT_CONFIG, TIMING, LOG_LEVEL, PIPELINE_TIMING, COW_PERFORMANCE, COW_ACTIONS } from '../constants.js';
|
|
30
|
+
import { getMinAbsoluteOrderSize, computeChainFundTotals, hasValidAccountTotals, resolveConfigValueWithRegistry, isExplicitZeroAllocation, floatToBlockchainInt } from './utils/math.js';
|
|
31
|
+
import { validateOrder, validateGridForPersistence, validateWorkingGridFunds, checkFundDrift, reconcileGrid, optimizeRebalanceActions, projectTargetToWorkingGrid, buildStateUpdates, buildAbortedResult, buildSuccessResult, evaluateCommit } from './utils/validate.js';
|
|
32
|
+
import { resolveSpreadOrderSide, parseSlotIndex } from './utils/order.js';
|
|
33
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
73
34
|
const { toFiniteNumber } = Format;
|
|
74
35
|
// ===============================================================================
|
|
75
36
|
// SECTION 2: COW REBALANCE ENGINE
|
|
@@ -107,17 +68,17 @@ const { toFiniteNumber } = Format;
|
|
|
107
68
|
* @returns {string|null} Drop reason for the log, or null to keep the action
|
|
108
69
|
*/
|
|
109
70
|
function stalePlacementDropReason(action, planBoundary) {
|
|
110
|
-
const isPlacement = action?.type ===
|
|
71
|
+
const isPlacement = action?.type === COW_ACTIONS.CREATE || action?.type === COW_ACTIONS.UPDATE;
|
|
111
72
|
if (!isPlacement)
|
|
112
73
|
return null;
|
|
113
|
-
const targetSlot =
|
|
74
|
+
const targetSlot = parseSlotIndex(action?.newGridId ?? action?.id);
|
|
114
75
|
if (targetSlot === null)
|
|
115
76
|
return null;
|
|
116
|
-
const kindWord = action.type ===
|
|
117
|
-
if (action?.order?.type ===
|
|
77
|
+
const kindWord = action.type === COW_ACTIONS.UPDATE ? 'update' : 'create';
|
|
78
|
+
if (action?.order?.type === ORDER_TYPES.BUY && targetSlot > planBoundary) {
|
|
118
79
|
return `BUY ${kindWord} for slot ${action.id}: slot ${targetSlot} > plan boundary ${planBoundary}`;
|
|
119
80
|
}
|
|
120
|
-
if (action?.order?.type ===
|
|
81
|
+
if (action?.order?.type === ORDER_TYPES.SELL && targetSlot < planBoundary) {
|
|
121
82
|
return `SELL ${kindWord} for slot ${action.id}: slot ${targetSlot} < plan boundary ${planBoundary}`;
|
|
122
83
|
}
|
|
123
84
|
return null;
|
|
@@ -174,7 +135,7 @@ class COWRebalanceEngine {
|
|
|
174
135
|
}
|
|
175
136
|
async execute({ masterGrid, gridVersion, boundaryIdx, funds, fills = [], excludeIds = new Set() }) {
|
|
176
137
|
const startTime = Date.now();
|
|
177
|
-
const workingGrid = new
|
|
138
|
+
const workingGrid = new WorkingGrid(masterGrid, { baseVersion: gridVersion });
|
|
178
139
|
const strategyParams = {
|
|
179
140
|
frozenMasterGrid: masterGrid,
|
|
180
141
|
config: this.config,
|
|
@@ -186,14 +147,14 @@ class COWRebalanceEngine {
|
|
|
186
147
|
};
|
|
187
148
|
const { targetGrid, boundaryIdx: targetBoundary } = this.strategy.calculateTargetGrid(strategyParams);
|
|
188
149
|
let dustThresholdPercent = this.config?.gridLimits?.PARTIAL_DUST_THRESHOLD_PERCENTAGE;
|
|
189
|
-
const reconcileResult =
|
|
150
|
+
const reconcileResult = reconcileGrid(masterGrid, targetGrid, targetBoundary, {
|
|
190
151
|
logger: (msg, level) => this.logger?.log(msg, level),
|
|
191
152
|
dustThresholdPercent
|
|
192
153
|
});
|
|
193
154
|
if (reconcileResult.aborted) {
|
|
194
|
-
return
|
|
155
|
+
return buildAbortedResult(reconcileResult.reason);
|
|
195
156
|
}
|
|
196
|
-
const optimizedActions =
|
|
157
|
+
const optimizedActions = optimizeRebalanceActions(reconcileResult.actions, masterGrid);
|
|
197
158
|
// Stale-placement guard: drop placements crossing the plan's own
|
|
198
159
|
// boundary (see stalePlacementDropReason) — defer them to the next
|
|
199
160
|
// cycle instead of filling immediately.
|
|
@@ -216,28 +177,28 @@ class COWRebalanceEngine {
|
|
|
216
177
|
optimizedActions.length = 0;
|
|
217
178
|
optimizedActions.push(...guarded);
|
|
218
179
|
}
|
|
219
|
-
|
|
180
|
+
projectTargetToWorkingGrid(workingGrid, targetGrid, { actions: optimizedActions });
|
|
220
181
|
const precisions = {
|
|
221
182
|
buyPrecision: this.assets?.assetB?.precision,
|
|
222
183
|
sellPrecision: this.assets?.assetA?.precision
|
|
223
184
|
};
|
|
224
|
-
const fundCheck =
|
|
185
|
+
const fundCheck = validateWorkingGridFunds(workingGrid, funds, precisions, this.assets);
|
|
225
186
|
if (!fundCheck.isValid) {
|
|
226
187
|
this.logger?.log(`[COW] Fund validation failed: ${fundCheck.reason}`, 'warn');
|
|
227
|
-
return
|
|
188
|
+
return buildAbortedResult(fundCheck.reason);
|
|
228
189
|
}
|
|
229
190
|
if (workingGrid.isStale()) {
|
|
230
191
|
const reason = workingGrid.getStaleReason() || 'Master grid changed during planning';
|
|
231
192
|
this.logger?.log(`[COW] Rebalance plan invalidated: ${reason}`, 'warn');
|
|
232
|
-
return
|
|
193
|
+
return buildAbortedResult(reason);
|
|
233
194
|
}
|
|
234
|
-
const stateUpdates =
|
|
195
|
+
const stateUpdates = buildStateUpdates(optimizedActions, masterGrid);
|
|
235
196
|
const duration = Date.now() - startTime;
|
|
236
|
-
if (duration >
|
|
197
|
+
if (duration > COW_PERFORMANCE.MAX_REBALANCE_PLANNING_MS) {
|
|
237
198
|
this.logger?.log(`[COW] Rebalance planning took ${duration}ms`, 'warn');
|
|
238
199
|
}
|
|
239
200
|
this.logger?.log(`[COW] Plan: Actions=${optimizedActions.length}, StateUpdates=${stateUpdates.length}`, 'info');
|
|
240
|
-
return
|
|
201
|
+
return buildSuccessResult({
|
|
241
202
|
actions: optimizedActions,
|
|
242
203
|
stateUpdates,
|
|
243
204
|
workingGrid,
|
|
@@ -246,7 +207,6 @@ class COWRebalanceEngine {
|
|
|
246
207
|
});
|
|
247
208
|
}
|
|
248
209
|
}
|
|
249
|
-
exports.COWRebalanceEngine = COWRebalanceEngine;
|
|
250
210
|
// ===============================================================================
|
|
251
211
|
// SECTION 3: ORDER MANAGER CLASS
|
|
252
212
|
// ===============================================================================
|
|
@@ -290,7 +250,7 @@ class OrderManager {
|
|
|
290
250
|
return this._ordersByTypeCache;
|
|
291
251
|
}
|
|
292
252
|
const byType = {};
|
|
293
|
-
for (const key of [
|
|
253
|
+
for (const key of [ORDER_TYPES.BUY, ORDER_TYPES.SELL, ORDER_TYPES.SPREAD]) {
|
|
294
254
|
byType[key] = new Set();
|
|
295
255
|
}
|
|
296
256
|
for (const [id, o] of this.orders) {
|
|
@@ -314,7 +274,7 @@ class OrderManager {
|
|
|
314
274
|
return this._ordersByStateCache;
|
|
315
275
|
}
|
|
316
276
|
const byState = {};
|
|
317
|
-
for (const key of [
|
|
277
|
+
for (const key of [ORDER_STATES.VIRTUAL, ORDER_STATES.ACTIVE, ORDER_STATES.PARTIAL]) {
|
|
318
278
|
byState[key] = new Set();
|
|
319
279
|
}
|
|
320
280
|
for (const [id, o] of this.orders) {
|
|
@@ -368,6 +328,7 @@ class OrderManager {
|
|
|
368
328
|
_orderIdAssignedAt;
|
|
369
329
|
_gapSlots;
|
|
370
330
|
_gridDirtyAt;
|
|
331
|
+
_lastStaleTotalsWarnAt;
|
|
371
332
|
_orphanFillsCreditedAt;
|
|
372
333
|
_pendingRecovery;
|
|
373
334
|
_recentFillKeysSnapshot;
|
|
@@ -380,12 +341,12 @@ class OrderManager {
|
|
|
380
341
|
* @param {Object} [config] - Configuration overrides
|
|
381
342
|
*/
|
|
382
343
|
constructor(config = {}) {
|
|
383
|
-
this.config = { ...
|
|
344
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
384
345
|
this.marketName = this.config.market || (this.config.assetA && this.config.assetB ? `${this.config.assetA}/${this.config.assetB}` : null);
|
|
385
346
|
const logFile = config.logFile || undefined;
|
|
386
347
|
const loggingConfig = this.config.logging;
|
|
387
|
-
this.logger = new
|
|
388
|
-
level: loggingConfig?.level ??
|
|
348
|
+
this.logger = new Logger('DEXBot', {
|
|
349
|
+
level: loggingConfig?.level ?? LOG_LEVEL,
|
|
389
350
|
logFile,
|
|
390
351
|
configOverride: loggingConfig?.config ?? undefined
|
|
391
352
|
});
|
|
@@ -393,10 +354,10 @@ class OrderManager {
|
|
|
393
354
|
this.orders = Object.freeze(new Map());
|
|
394
355
|
this.boundaryIdx = null;
|
|
395
356
|
this.targetGrid = null;
|
|
396
|
-
this.accountant = new
|
|
397
|
-
this.strategy = new
|
|
398
|
-
this.sync = new
|
|
399
|
-
this._rebalanceState =
|
|
357
|
+
this.accountant = new Accountant(this);
|
|
358
|
+
this.strategy = new StrategyEngine(this);
|
|
359
|
+
this.sync = new SyncEngine(this);
|
|
360
|
+
this._rebalanceState = REBALANCE_STATES.NORMAL;
|
|
400
361
|
this._bootstrapping = 0;
|
|
401
362
|
this._broadcastingFlag = 0;
|
|
402
363
|
this._broadcastingStartedAt = 0;
|
|
@@ -437,15 +398,14 @@ class OrderManager {
|
|
|
437
398
|
// Level 2: _syncLock (sync operations — timeout-protected)
|
|
438
399
|
// Level 3: _gridLock (grid mutations)
|
|
439
400
|
// Level 4: _fundLock (fund operations — innermost)
|
|
440
|
-
// Note: AsyncLock IS re-entrant (acquire detects nested calls via
|
|
441
|
-
this._fillProcessingLock = new
|
|
442
|
-
this._divergenceLock = new
|
|
443
|
-
this._syncLock = new
|
|
444
|
-
this._gridLock = new
|
|
445
|
-
level: 3,
|
|
401
|
+
// Note: AsyncLock IS re-entrant (acquire detects nested calls via context).
|
|
402
|
+
this._fillProcessingLock = new AsyncLock({ timeout: TIMING.SYNC_LOCK_TIMEOUT_MS });
|
|
403
|
+
this._divergenceLock = new AsyncLock();
|
|
404
|
+
this._syncLock = new AsyncLock();
|
|
405
|
+
this._gridLock = new AsyncLock({
|
|
446
406
|
onContention: () => { this._metrics.gridLockContention++; }
|
|
447
407
|
});
|
|
448
|
-
this._fundLock = new
|
|
408
|
+
this._fundLock = new AsyncLock({ timeout: 30000 });
|
|
449
409
|
this._recentlyRotatedOrderIds = new Set();
|
|
450
410
|
this._gridSidesUpdated = new Set();
|
|
451
411
|
this._pauseFundRecalc = 0;
|
|
@@ -474,6 +434,7 @@ class OrderManager {
|
|
|
474
434
|
this._orphanFillsCreditedAt = null;
|
|
475
435
|
this._pendingRecovery = null;
|
|
476
436
|
this._recentFillKeysSnapshot = null;
|
|
437
|
+
this._lastStaleTotalsWarnAt = {};
|
|
477
438
|
this._metrics = {
|
|
478
439
|
fundRecalcCount: 0,
|
|
479
440
|
lockAcquisitions: 0,
|
|
@@ -503,8 +464,8 @@ class OrderManager {
|
|
|
503
464
|
_clearWorkingGridRef() {
|
|
504
465
|
this._currentWorkingGridStack.pop();
|
|
505
466
|
this._rebalanceState = this._currentWorkingGridStack.length > 0
|
|
506
|
-
?
|
|
507
|
-
:
|
|
467
|
+
? REBALANCE_STATES.REBALANCING
|
|
468
|
+
: REBALANCE_STATES.NORMAL;
|
|
508
469
|
}
|
|
509
470
|
/**
|
|
510
471
|
* Push a working grid onto the rebalance stack (LIFO), set the state to
|
|
@@ -518,7 +479,7 @@ class OrderManager {
|
|
|
518
479
|
*/
|
|
519
480
|
_pushWorkingGridRef(workingGrid, result = null) {
|
|
520
481
|
this._currentWorkingGridStack.push(workingGrid);
|
|
521
|
-
this._rebalanceState =
|
|
482
|
+
this._rebalanceState = REBALANCE_STATES.REBALANCING;
|
|
522
483
|
if (result) {
|
|
523
484
|
result._workingGridPushed = true;
|
|
524
485
|
}
|
|
@@ -560,20 +521,20 @@ class OrderManager {
|
|
|
560
521
|
}
|
|
561
522
|
_resetRebalanceStateToDepth() {
|
|
562
523
|
this._rebalanceState = this._currentWorkingGridStack.length > 0
|
|
563
|
-
?
|
|
564
|
-
:
|
|
524
|
+
? REBALANCE_STATES.REBALANCING
|
|
525
|
+
: REBALANCE_STATES.NORMAL;
|
|
565
526
|
}
|
|
566
527
|
/**
|
|
567
528
|
* @returns {boolean}
|
|
568
529
|
*/
|
|
569
530
|
isRebalancing() {
|
|
570
|
-
return this._rebalanceState ===
|
|
531
|
+
return this._rebalanceState === REBALANCE_STATES.REBALANCING;
|
|
571
532
|
}
|
|
572
533
|
/**
|
|
573
534
|
* @returns {boolean}
|
|
574
535
|
*/
|
|
575
536
|
isBroadcasting() {
|
|
576
|
-
return this._rebalanceState ===
|
|
537
|
+
return this._rebalanceState === REBALANCE_STATES.BROADCASTING;
|
|
577
538
|
}
|
|
578
539
|
/**
|
|
579
540
|
* @returns {boolean}
|
|
@@ -693,19 +654,19 @@ class OrderManager {
|
|
|
693
654
|
getChainFundsSnapshot() {
|
|
694
655
|
let committedBuy = 0, committedSell = 0;
|
|
695
656
|
for (const order of this.orders.values()) {
|
|
696
|
-
const isActive = (order.state ===
|
|
657
|
+
const isActive = (order.state === ORDER_STATES.ACTIVE || order.state === ORDER_STATES.PARTIAL) && !!order.orderId;
|
|
697
658
|
if (!isActive)
|
|
698
659
|
continue;
|
|
699
660
|
const size = toFiniteNumber(order.size);
|
|
700
661
|
if (size <= 0)
|
|
701
662
|
continue;
|
|
702
|
-
const isBuy = order.type ===
|
|
663
|
+
const isBuy = order.type === ORDER_TYPES.BUY || (order.type === ORDER_TYPES.SPREAD && resolveSpreadOrderSide(order.price, this.config.startPrice) === ORDER_TYPES.BUY);
|
|
703
664
|
if (isBuy)
|
|
704
665
|
committedBuy += size;
|
|
705
666
|
else
|
|
706
667
|
committedSell += size;
|
|
707
668
|
}
|
|
708
|
-
const totals =
|
|
669
|
+
const totals = computeChainFundTotals(this.accountTotals, { buy: committedBuy, sell: committedSell });
|
|
709
670
|
const allocatedBuy = toFiniteNumber(this.funds?.allocated?.buy, totals.chainTotalBuy);
|
|
710
671
|
const allocatedSell = toFiniteNumber(this.funds?.allocated?.sell, totals.chainTotalSell);
|
|
711
672
|
const btsBalance = (this.config.assetA !== 'BTS' && this.config.assetB !== 'BTS')
|
|
@@ -717,12 +678,12 @@ class OrderManager {
|
|
|
717
678
|
* @param {number} [timeoutMs]
|
|
718
679
|
* @returns {Promise<void>}
|
|
719
680
|
*/
|
|
720
|
-
async waitForAccountTotals(timeoutMs =
|
|
721
|
-
if (
|
|
681
|
+
async waitForAccountTotals(timeoutMs = TIMING.ACCOUNT_TOTALS_TIMEOUT_MS) {
|
|
682
|
+
if (hasValidAccountTotals(this.accountTotals, true))
|
|
722
683
|
return;
|
|
723
684
|
let waitPromise = null;
|
|
724
685
|
await this._fundLock.acquire(async () => {
|
|
725
|
-
if (
|
|
686
|
+
if (hasValidAccountTotals(this.accountTotals, true))
|
|
726
687
|
return;
|
|
727
688
|
if (!this._accountTotalsPromise) {
|
|
728
689
|
this._accountTotalsPromise = new Promise((resolve) => {
|
|
@@ -733,7 +694,7 @@ class OrderManager {
|
|
|
733
694
|
});
|
|
734
695
|
if (!waitPromise)
|
|
735
696
|
return;
|
|
736
|
-
await
|
|
697
|
+
await withTimeout(waitPromise, timeoutMs, {
|
|
737
698
|
onTimeout: 'resolve',
|
|
738
699
|
defaultValue: undefined,
|
|
739
700
|
onTimeoutCallback: () => this.logger.log('[FUND] Timeout waiting for account totals', 'warn'),
|
|
@@ -764,7 +725,7 @@ class OrderManager {
|
|
|
764
725
|
async refreshAccountTotalsIfStale(options = {}) {
|
|
765
726
|
const force = options?.force === true;
|
|
766
727
|
const lastFetched = this.accountTotals?._lastFetchedAt || 0;
|
|
767
|
-
if (!force && Date.now() - lastFetched <=
|
|
728
|
+
if (!force && Date.now() - lastFetched <= TIMING.MAX_ACCOUNT_TOTALS_AGE_MS) {
|
|
768
729
|
return { ok: true };
|
|
769
730
|
}
|
|
770
731
|
const fetchedBefore = lastFetched;
|
|
@@ -773,18 +734,35 @@ class OrderManager {
|
|
|
773
734
|
// defer the whole fill batch to the next cycle. Only a genuinely
|
|
774
735
|
// unreachable chain leaves the snapshot stale.
|
|
775
736
|
try {
|
|
776
|
-
await
|
|
737
|
+
await withBlockchainRetry(() => this.fetchAccountTotals(this.accountId), 'refreshAccountTotalsIfStale', { logger: this.logger });
|
|
777
738
|
}
|
|
778
739
|
catch (err) {
|
|
779
|
-
this.logger?.log?.(`[SYNC] refreshAccountTotalsIfStale fetch failed: ${
|
|
740
|
+
this.logger?.log?.(`[SYNC] refreshAccountTotalsIfStale fetch failed: ${getErrorMessage(err)}`, 'warn');
|
|
780
741
|
}
|
|
781
742
|
const fetchedAfter = this.accountTotals?._lastFetchedAt || 0;
|
|
782
743
|
if (fetchedAfter <= fetchedBefore) {
|
|
783
|
-
this.
|
|
744
|
+
if (this._rateLimitStaleTotalsWarn('stale-refresh')) {
|
|
745
|
+
this.logger?.log?.(`[SYNC] refreshAccountTotalsIfStale: accountTotals still stale after refresh (age=${Math.max(0, Date.now() - fetchedAfter)}ms).`, 'warn');
|
|
746
|
+
}
|
|
784
747
|
return { ok: false, reason: 'refresh-failed' };
|
|
785
748
|
}
|
|
786
749
|
return { ok: true };
|
|
787
750
|
}
|
|
751
|
+
/**
|
|
752
|
+
* Rate-limit identical accountTotals-staleness warnings to once per
|
|
753
|
+
* STALE_TOTALS_WARN_RATE_LIMIT_MS per warning kind per manager, so a
|
|
754
|
+
* persistently unreachable chain reports each failure mode once without
|
|
755
|
+
* flooding the log on every fill batch.
|
|
756
|
+
* @param {string} kind - Warning kind key (e.g. 'stale-refresh', 're-anchor')
|
|
757
|
+
* @returns {boolean} true when the warning should be emitted now
|
|
758
|
+
*/
|
|
759
|
+
_rateLimitStaleTotalsWarn(kind) {
|
|
760
|
+
const now = Date.now();
|
|
761
|
+
if (now - (this._lastStaleTotalsWarnAt[kind] || 0) < TIMING.STALE_TOTALS_WARN_RATE_LIMIT_MS)
|
|
762
|
+
return false;
|
|
763
|
+
this._lastStaleTotalsWarnAt[kind] = now;
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
788
766
|
/**
|
|
789
767
|
* Re-anchor accountTotals to authoritative on-chain values after a fill
|
|
790
768
|
* batch has applied its optimistic accounting and grid mutation.
|
|
@@ -802,7 +780,9 @@ class OrderManager {
|
|
|
802
780
|
async reanchorAccountTotals(label = 'fill-batch') {
|
|
803
781
|
const result = await this.refreshAccountTotalsIfStale({ force: true });
|
|
804
782
|
if (!result.ok) {
|
|
805
|
-
this.
|
|
783
|
+
if (this._rateLimitStaleTotalsWarn('re-anchor')) {
|
|
784
|
+
this.logger?.log?.(`[ACCOUNTING] ${label}: accountTotals re-anchor failed (${result.reason}); marking totals stale.`, 'warn');
|
|
785
|
+
}
|
|
806
786
|
this.accountTotalsStale = true;
|
|
807
787
|
return false;
|
|
808
788
|
}
|
|
@@ -825,12 +805,12 @@ class OrderManager {
|
|
|
825
805
|
if (!this.funds)
|
|
826
806
|
await this.resetFunds();
|
|
827
807
|
await this._recalculateFunds();
|
|
828
|
-
if (
|
|
808
|
+
if (hasValidAccountTotals(this.accountTotals, true) && typeof this._accountTotalsResolve === 'function') {
|
|
829
809
|
try {
|
|
830
810
|
this._accountTotalsResolve();
|
|
831
811
|
}
|
|
832
812
|
catch (e) {
|
|
833
|
-
this.logger?.log?.(`Error resolving account totals promise: ${
|
|
813
|
+
this.logger?.log?.(`Error resolving account totals promise: ${getErrorMessage(e)}`, 'warn');
|
|
834
814
|
}
|
|
835
815
|
this._accountTotalsPromise = null;
|
|
836
816
|
this._accountTotalsResolve = null;
|
|
@@ -850,11 +830,11 @@ class OrderManager {
|
|
|
850
830
|
applyBotFundsAllocation() {
|
|
851
831
|
if (!this.config.botFunds || !this.accountTotals)
|
|
852
832
|
return;
|
|
853
|
-
const { chainTotalBuy, chainTotalSell } =
|
|
833
|
+
const { chainTotalBuy, chainTotalSell } = computeChainFundTotals(this.accountTotals, this.funds?.committed?.chain);
|
|
854
834
|
const account = this.config.preferredAccount;
|
|
855
835
|
const botName = this.config.botKey;
|
|
856
|
-
const allocatedBuy =
|
|
857
|
-
const allocatedSell =
|
|
836
|
+
const allocatedBuy = resolveConfigValueWithRegistry(this.config.botFunds.buy, chainTotalBuy, account, botName, 'buy');
|
|
837
|
+
const allocatedSell = resolveConfigValueWithRegistry(this.config.botFunds.sell, chainTotalSell, account, botName, 'sell');
|
|
858
838
|
if (allocatedBuy === 0 && typeof this.config.botFunds.buy === 'string' && this.config.botFunds.buy.trim().endsWith('%')) {
|
|
859
839
|
if (chainTotalBuy === 0)
|
|
860
840
|
this._triggerAccountTotalsFetchIfNeeded();
|
|
@@ -864,8 +844,8 @@ class OrderManager {
|
|
|
864
844
|
this._triggerAccountTotalsFetchIfNeeded();
|
|
865
845
|
}
|
|
866
846
|
this.funds.allocated = { buy: allocatedBuy, sell: allocatedSell };
|
|
867
|
-
const shouldCapBuy = allocatedBuy > 0 ||
|
|
868
|
-
const shouldCapSell = allocatedSell > 0 ||
|
|
847
|
+
const shouldCapBuy = allocatedBuy > 0 || isExplicitZeroAllocation(this.config.botFunds.buy);
|
|
848
|
+
const shouldCapSell = allocatedSell > 0 || isExplicitZeroAllocation(this.config.botFunds.sell);
|
|
869
849
|
if (shouldCapBuy)
|
|
870
850
|
this.funds.available.buy = Math.min(this.funds.available.buy, Math.max(0, allocatedBuy));
|
|
871
851
|
if (shouldCapSell)
|
|
@@ -920,10 +900,10 @@ class OrderManager {
|
|
|
920
900
|
this._pauseFundRecalc = 0;
|
|
921
901
|
this._pauseFundRecalcWatchdog = null;
|
|
922
902
|
this.recalculateFunds().catch((err) => {
|
|
923
|
-
this.logger?.log?.(`[MANAGER] Watchdog recalc failed: ${
|
|
903
|
+
this.logger?.log?.(`[MANAGER] Watchdog recalc failed: ${getErrorMessage(err)}`, 'error');
|
|
924
904
|
});
|
|
925
905
|
}
|
|
926
|
-
},
|
|
906
|
+
}, TIMING.SAFETY_PAUSE_TIMEOUT_MS);
|
|
927
907
|
}
|
|
928
908
|
}
|
|
929
909
|
/**
|
|
@@ -961,10 +941,10 @@ class OrderManager {
|
|
|
961
941
|
clearTimeout(this._pauseRecalcLoggingWatchdog);
|
|
962
942
|
}
|
|
963
943
|
this._pauseRecalcLoggingWatchdog = setTimeout(() => {
|
|
964
|
-
this.logger?.log?.(`[MANAGER] pauseRecalcLogging safety watchdog: forcing resume after ${
|
|
944
|
+
this.logger?.log?.(`[MANAGER] pauseRecalcLogging safety watchdog: forcing resume after ${TIMING.SAFETY_PAUSE_TIMEOUT_MS}ms`, 'warn');
|
|
965
945
|
this._pauseRecalcLogging = false;
|
|
966
946
|
this._pauseRecalcLoggingWatchdog = null;
|
|
967
|
-
},
|
|
947
|
+
}, TIMING.SAFETY_PAUSE_TIMEOUT_MS);
|
|
968
948
|
}
|
|
969
949
|
/**
|
|
970
950
|
* Resume recalc debug logging.
|
|
@@ -1024,7 +1004,7 @@ class OrderManager {
|
|
|
1024
1004
|
lockOrders(orderIds) {
|
|
1025
1005
|
if (!orderIds)
|
|
1026
1006
|
return;
|
|
1027
|
-
const expiration = Date.now() +
|
|
1007
|
+
const expiration = Date.now() + TIMING.LOCK_TIMEOUT_MS;
|
|
1028
1008
|
for (const id of orderIds)
|
|
1029
1009
|
if (id)
|
|
1030
1010
|
this.shadowOrderIds.set(id, expiration);
|
|
@@ -1089,7 +1069,7 @@ class OrderManager {
|
|
|
1089
1069
|
const updateOptions = this._normalizeOrderUpdateOptions(options);
|
|
1090
1070
|
const { skipAccounting, fee: normalizedFee } = updateOptions;
|
|
1091
1071
|
const oldOrder = this.orders.get(order.id);
|
|
1092
|
-
const validation =
|
|
1072
|
+
const validation = validateOrder(order, oldOrder, context);
|
|
1093
1073
|
for (const warning of validation.warnings) {
|
|
1094
1074
|
this.logger.log(warning.message, 'warn');
|
|
1095
1075
|
}
|
|
@@ -1128,7 +1108,7 @@ class OrderManager {
|
|
|
1128
1108
|
if (this.accountant) {
|
|
1129
1109
|
await this.accountant.updateOptimisticFreeBalance(oldOrder, nextOrder, context, normalizedFee, accountingSkip);
|
|
1130
1110
|
}
|
|
1131
|
-
const updatedOrder =
|
|
1111
|
+
const updatedOrder = deepFreeze({ ...nextOrder });
|
|
1132
1112
|
const id = order.id;
|
|
1133
1113
|
// Track when an orderId is first assigned to a slot. A freshly assigned
|
|
1134
1114
|
// orderId (create/adopt broadcast still in flight, or not yet visible to
|
|
@@ -1142,13 +1122,13 @@ class OrderManager {
|
|
|
1142
1122
|
// younger than SYNC_LOCK_TIMEOUT_MS), so keeping them would leak one
|
|
1143
1123
|
// entry per orderId on a perpetual-turnover bot.
|
|
1144
1124
|
for (const [orderId, assignedAt] of this._orderIdAssignedAt) {
|
|
1145
|
-
if (Date.now() - assignedAt >=
|
|
1125
|
+
if (Date.now() - assignedAt >= TIMING.SYNC_LOCK_TIMEOUT_MS) {
|
|
1146
1126
|
this._orderIdAssignedAt.delete(orderId);
|
|
1147
1127
|
}
|
|
1148
1128
|
}
|
|
1149
1129
|
this._orderIdAssignedAt.set(updatedOrder.orderId, Date.now());
|
|
1150
1130
|
}
|
|
1151
|
-
const newMap =
|
|
1131
|
+
const newMap = cloneMap(this.orders);
|
|
1152
1132
|
newMap.set(id, updatedOrder);
|
|
1153
1133
|
this.orders = Object.freeze(newMap);
|
|
1154
1134
|
this._gridVersion++;
|
|
@@ -1185,8 +1165,8 @@ class OrderManager {
|
|
|
1185
1165
|
wg.syncFromMaster(this.orders, orderId, this._gridVersion);
|
|
1186
1166
|
}
|
|
1187
1167
|
catch (syncErr) {
|
|
1188
|
-
wg.markStale(`working-grid sync failure: ${
|
|
1189
|
-
this.logger.log(`[COW] Failed to sync working grid for order ${orderId}: ${
|
|
1168
|
+
wg.markStale(`working-grid sync failure: ${getErrorMessage(syncErr)}`);
|
|
1169
|
+
this.logger.log(`[COW] Failed to sync working grid for order ${orderId}: ${getErrorMessage(syncErr)}`, 'warn');
|
|
1190
1170
|
}
|
|
1191
1171
|
}
|
|
1192
1172
|
/**
|
|
@@ -1299,7 +1279,7 @@ class OrderManager {
|
|
|
1299
1279
|
rebalanceResult.excludeIds = excl || new Set();
|
|
1300
1280
|
return rebalanceResult;
|
|
1301
1281
|
}
|
|
1302
|
-
const workingGrid = new
|
|
1282
|
+
const workingGrid = new WorkingGrid(this.orders, { baseVersion: this._gridVersion });
|
|
1303
1283
|
return {
|
|
1304
1284
|
actions: [],
|
|
1305
1285
|
stateUpdates: [],
|
|
@@ -1319,28 +1299,28 @@ class OrderManager {
|
|
|
1319
1299
|
const buyCount = Math.max(0, toFiniteNumber(this.config.activeOrders?.buy, 1));
|
|
1320
1300
|
// Get minimum sizes for validation
|
|
1321
1301
|
const minOrderSizeFactor = this.config?.gridLimits?.MIN_ORDER_SIZE_FACTOR;
|
|
1322
|
-
const minSellSize =
|
|
1323
|
-
const minBuySize =
|
|
1302
|
+
const minSellSize = getMinAbsoluteOrderSize(ORDER_TYPES.SELL, this.assets, minOrderSizeFactor);
|
|
1303
|
+
const minBuySize = getMinAbsoluteOrderSize(ORDER_TYPES.BUY, this.assets, minOrderSizeFactor);
|
|
1324
1304
|
// Use integer arithmetic for size comparisons to match blockchain behavior
|
|
1325
1305
|
const sellPrecision = this.assets?.assetA?.precision;
|
|
1326
1306
|
const buyPrecision = this.assets?.assetB?.precision;
|
|
1327
|
-
const minSellSizeInt =
|
|
1328
|
-
const minBuySizeInt =
|
|
1307
|
+
const minSellSizeInt = floatToBlockchainInt(minSellSize, sellPrecision);
|
|
1308
|
+
const minBuySizeInt = floatToBlockchainInt(minBuySize, buyPrecision);
|
|
1329
1309
|
// Get closest virtual sells (lowest prices first = closest to market), limit to sellCount
|
|
1330
|
-
const vSells = this.getOrdersByTypeAndState(
|
|
1310
|
+
const vSells = this.getOrdersByTypeAndState(ORDER_TYPES.SELL, ORDER_STATES.VIRTUAL)
|
|
1331
1311
|
.sort((a, b) => a.price - b.price)
|
|
1332
1312
|
.slice(0, sellCount);
|
|
1333
1313
|
// Filter by minimum size, then reverse for placement order (highest first)
|
|
1334
1314
|
const validSells = vSells
|
|
1335
|
-
.filter((o) =>
|
|
1315
|
+
.filter((o) => floatToBlockchainInt(o.size, sellPrecision) >= minSellSizeInt)
|
|
1336
1316
|
.sort((a, b) => b.price - a.price);
|
|
1337
1317
|
// Get closest virtual buys (highest prices first = closest to market), limit to buyCount
|
|
1338
|
-
const vBuys = this.getOrdersByTypeAndState(
|
|
1318
|
+
const vBuys = this.getOrdersByTypeAndState(ORDER_TYPES.BUY, ORDER_STATES.VIRTUAL)
|
|
1339
1319
|
.sort((a, b) => b.price - a.price)
|
|
1340
1320
|
.slice(0, buyCount);
|
|
1341
1321
|
// Filter by minimum size, then reverse for placement order (lowest first)
|
|
1342
1322
|
const validBuys = vBuys
|
|
1343
|
-
.filter((o) =>
|
|
1323
|
+
.filter((o) => floatToBlockchainInt(o.size, buyPrecision) >= minBuySizeInt)
|
|
1344
1324
|
.sort((a, b) => a.price - b.price);
|
|
1345
1325
|
return [...validSells, ...validBuys];
|
|
1346
1326
|
}
|
|
@@ -1413,29 +1393,29 @@ class OrderManager {
|
|
|
1413
1393
|
* @returns {Promise<Object>}
|
|
1414
1394
|
*/
|
|
1415
1395
|
async checkSpreadCondition(BitShares, batchCb) {
|
|
1416
|
-
return await
|
|
1396
|
+
return await checkSpreadCondition(this, BitShares, batchCb);
|
|
1417
1397
|
}
|
|
1418
1398
|
/**
|
|
1419
1399
|
* @param {Function} batchCb - Batch callback
|
|
1420
1400
|
* @returns {Promise<Object>}
|
|
1421
1401
|
*/
|
|
1422
1402
|
async checkGridHealth(batchCb) {
|
|
1423
|
-
return await
|
|
1403
|
+
return await checkGridHealth(this, batchCb);
|
|
1424
1404
|
}
|
|
1425
1405
|
/**
|
|
1426
1406
|
* @returns {Object} Current spread calculation
|
|
1427
1407
|
*/
|
|
1428
1408
|
calculateCurrentSpread() {
|
|
1429
|
-
return
|
|
1409
|
+
return calculateCurrentSpread(this);
|
|
1430
1410
|
}
|
|
1431
1411
|
/**
|
|
1432
1412
|
* @returns {import('./types').DriftCheckResult}
|
|
1433
1413
|
*/
|
|
1434
1414
|
checkFundDriftAfterFills() {
|
|
1435
|
-
if (!this.assets || !
|
|
1415
|
+
if (!this.assets || !hasValidAccountTotals(this.accountTotals)) {
|
|
1436
1416
|
return { isValid: true, reason: 'Skipped: missing assets or totals' };
|
|
1437
1417
|
}
|
|
1438
|
-
return
|
|
1418
|
+
return checkFundDrift(this.orders, this.accountTotals, this.assets, this.config?.gridLimits ?? null);
|
|
1439
1419
|
}
|
|
1440
1420
|
/**
|
|
1441
1421
|
* @param {Object|number} [pipelineSignals] - Pipeline state signals or queue length
|
|
@@ -1490,7 +1470,7 @@ class OrderManager {
|
|
|
1490
1470
|
if (!this._pipelineBlockedSince)
|
|
1491
1471
|
return false;
|
|
1492
1472
|
const age = Date.now() - this._pipelineBlockedSince;
|
|
1493
|
-
const timeoutMs = this.config?.pipelineTiming?.TIMEOUT_MS ??
|
|
1473
|
+
const timeoutMs = this.config?.pipelineTiming?.TIMEOUT_MS ?? PIPELINE_TIMING.TIMEOUT_MS;
|
|
1494
1474
|
if (age < timeoutMs)
|
|
1495
1475
|
return false;
|
|
1496
1476
|
this.ordersNeedingPriceCorrection = [];
|
|
@@ -1503,7 +1483,7 @@ class OrderManager {
|
|
|
1503
1483
|
* @returns {Object}
|
|
1504
1484
|
*/
|
|
1505
1485
|
reconcileGrid(targetGrid, targetBoundary) {
|
|
1506
|
-
return
|
|
1486
|
+
return reconcileGrid(this.orders, targetGrid, targetBoundary, {
|
|
1507
1487
|
logger: (msg, level) => this.logger.log(msg, level),
|
|
1508
1488
|
dustThresholdPercent: this.config?.gridLimits?.PARTIAL_DUST_THRESHOLD_PERCENTAGE
|
|
1509
1489
|
});
|
|
@@ -1522,9 +1502,9 @@ class OrderManager {
|
|
|
1522
1502
|
async _applySafeRebalanceCOW(fills = [], excludeIds = new Set()) {
|
|
1523
1503
|
const cowEngine = this._getCOWEngine();
|
|
1524
1504
|
if (!cowEngine) {
|
|
1525
|
-
return
|
|
1505
|
+
return buildAbortedResult('COW Engine not initialized (assets not available)');
|
|
1526
1506
|
}
|
|
1527
|
-
this._setRebalanceState(
|
|
1507
|
+
this._setRebalanceState(REBALANCE_STATES.REBALANCING);
|
|
1528
1508
|
const result = await cowEngine.execute({
|
|
1529
1509
|
masterGrid: this.orders,
|
|
1530
1510
|
gridVersion: this._gridVersion,
|
|
@@ -1597,11 +1577,11 @@ class OrderManager {
|
|
|
1597
1577
|
comparePrecisions = this._getCowComparePrecisions();
|
|
1598
1578
|
}
|
|
1599
1579
|
catch (precisionErr) {
|
|
1600
|
-
this.logger.log(`[COW] ${
|
|
1580
|
+
this.logger.log(`[COW] ${getErrorMessage(precisionErr)}`, 'error');
|
|
1601
1581
|
releaseStackEntry();
|
|
1602
1582
|
return false;
|
|
1603
1583
|
}
|
|
1604
|
-
const preCommitGuard =
|
|
1584
|
+
const preCommitGuard = evaluateCommit(workingGrid, {
|
|
1605
1585
|
hasLock: false,
|
|
1606
1586
|
currentVersion: this._gridVersion,
|
|
1607
1587
|
masterGrid: this.orders,
|
|
@@ -1613,7 +1593,7 @@ class OrderManager {
|
|
|
1613
1593
|
return false;
|
|
1614
1594
|
}
|
|
1615
1595
|
await this._gridLock.acquire(async () => {
|
|
1616
|
-
const lockCommitGuard =
|
|
1596
|
+
const lockCommitGuard = evaluateCommit(workingGrid, {
|
|
1617
1597
|
hasLock: true,
|
|
1618
1598
|
currentVersion: this._gridVersion,
|
|
1619
1599
|
masterGrid: this.orders,
|
|
@@ -1631,7 +1611,7 @@ class OrderManager {
|
|
|
1631
1611
|
// Ensures COW immutability invariants are maintained for all grid entries.
|
|
1632
1612
|
for (const [, order] of finalMap.entries()) {
|
|
1633
1613
|
if (order && !Object.isFrozen(order)) {
|
|
1634
|
-
|
|
1614
|
+
deepFreeze(order);
|
|
1635
1615
|
}
|
|
1636
1616
|
}
|
|
1637
1617
|
this.orders = Object.freeze(finalMap);
|
|
@@ -1668,12 +1648,12 @@ class OrderManager {
|
|
|
1668
1648
|
}
|
|
1669
1649
|
const duration = Date.now() - startTime;
|
|
1670
1650
|
this.logger.log(`[COW] Grid committed in ${duration}ms`, 'debug');
|
|
1671
|
-
if (stats.size >
|
|
1651
|
+
if (stats.size > COW_PERFORMANCE.GRID_MEMORY_WARNING) {
|
|
1672
1652
|
this.logger.log(`[COW] Warning: Large grid size (${stats.size} orders). Peak memory: ~${Math.round(stats.estimatedBytes / 1024)}KB`, 'warn');
|
|
1673
1653
|
}
|
|
1674
1654
|
}
|
|
1675
1655
|
catch (recalcErr) {
|
|
1676
|
-
this.logger.log(`[COW] Fund recalculation failed post-commit: ${
|
|
1656
|
+
this.logger.log(`[COW] Fund recalculation failed post-commit: ${getErrorMessage(recalcErr)}`, 'error');
|
|
1677
1657
|
this._recoveryState = { ...this._recoveryState, lastFailureAt: Date.now() };
|
|
1678
1658
|
// Re-throw to signal callers that the commit is incomplete
|
|
1679
1659
|
// (grid state committed, but fund state is stale).
|
|
@@ -1697,7 +1677,7 @@ class OrderManager {
|
|
|
1697
1677
|
* @returns {import('./types').PersistenceValidationResult}
|
|
1698
1678
|
*/
|
|
1699
1679
|
validateGridStateForPersistence(options = {}) {
|
|
1700
|
-
const result =
|
|
1680
|
+
const result = validateGridForPersistence(this.orders, this.accountTotals);
|
|
1701
1681
|
const allowBootstrapTransient = options.allowBootstrapTransient !== false;
|
|
1702
1682
|
if (!result.isValid && allowBootstrapTransient && this._bootstrapping) {
|
|
1703
1683
|
this.logger.log(`[BOOTSTRAP] Transient state (expected): ${result.reason}`, 'debug');
|
|
@@ -1753,7 +1733,7 @@ class OrderManager {
|
|
|
1753
1733
|
accountTotals: this.accountTotals,
|
|
1754
1734
|
}));
|
|
1755
1735
|
}
|
|
1756
|
-
const persisted = await
|
|
1736
|
+
const persisted = await persistGridSnapshot(this, this.accountOrders, snapshotOrders, recentFillKeys, effectiveFundSnapshot);
|
|
1757
1737
|
if (persisted === false) {
|
|
1758
1738
|
this.logger.log(`[PERSIST] Grid persistence FAILED (disk full / permissions / write error)`, 'error');
|
|
1759
1739
|
// Keep the dirty flag set so the next flush retries.
|
|
@@ -1840,5 +1820,5 @@ class OrderManager {
|
|
|
1840
1820
|
};
|
|
1841
1821
|
}
|
|
1842
1822
|
}
|
|
1843
|
-
|
|
1823
|
+
export { OrderManager, COWRebalanceEngine };
|
|
1844
1824
|
//# sourceMappingURL=manager.js.map
|