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/accounting.ts - Accountant Engine
|
|
4
3
|
*
|
|
@@ -75,51 +74,24 @@
|
|
|
75
74
|
*
|
|
76
75
|
* ===============================================================================
|
|
77
76
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
91
|
-
}) : function(o, v) {
|
|
92
|
-
o["default"] = v;
|
|
93
|
-
});
|
|
94
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
95
|
-
var ownKeys = function(o) {
|
|
96
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
97
|
-
var ar = [];
|
|
98
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
99
|
-
return ar;
|
|
100
|
-
};
|
|
101
|
-
return ownKeys(o);
|
|
102
|
-
};
|
|
103
|
-
return function (mod) {
|
|
104
|
-
if (mod && mod.__esModule) return mod;
|
|
105
|
-
var result = {};
|
|
106
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
107
|
-
__setModuleDefault(result, mod);
|
|
108
|
-
return result;
|
|
109
|
-
};
|
|
110
|
-
})();
|
|
111
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
112
|
-
const constants_1 = require("../constants");
|
|
113
|
-
const system_1 = require("./utils/system");
|
|
114
|
-
const order_1 = require("./utils/order");
|
|
115
|
-
const Format = __importStar(require("./format"));
|
|
116
|
-
const fundRegistry = __importStar(require("../fund_registry"));
|
|
117
|
-
const chainOrders = __importStar(require("../chain_orders"));
|
|
118
|
-
const chain_orders_1 = require("../chain_orders");
|
|
119
|
-
const math_1 = require("./utils/math");
|
|
120
|
-
const processed_fill_store_1 = require("./processed_fill_store");
|
|
121
|
-
const errors_1 = require("../utils/errors");
|
|
77
|
+
import { createRequire } from 'node:module';
|
|
78
|
+
const require = createRequire(import.meta.url);
|
|
79
|
+
import { ORDER_TYPES, ORDER_STATES, PIPELINE_TIMING, TIMING, FEE_PARAMETERS } from '../constants.js';
|
|
80
|
+
import { resolveAccountRef } from './utils/system.js';
|
|
81
|
+
import { resolveSpreadOrderSide, parseSlotIndex } from './utils/order.js';
|
|
82
|
+
import * as Format from './format.js';
|
|
83
|
+
import * as fundRegistry from '../fund_registry.js';
|
|
84
|
+
import * as chainOrders from '../chain_orders.js';
|
|
85
|
+
import { readOpenOrdersGuarded } from '../chain_orders.js';
|
|
86
|
+
import { calculateAvailableFundsValue, getAssetFees, blockchainToFloat, getPrecisionSlack, getBtsSide, countGapBandSpread } from './utils/math.js';
|
|
87
|
+
import { PROCESSED_FILL_PERSISTENCE_MODES, resolveProcessedFillPersistenceMode } from './processed_fill_store.js';
|
|
88
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
122
89
|
const { toFiniteNumber } = Format;
|
|
90
|
+
// Warn once per asset instead of once per fill/operation when the fee cache is
|
|
91
|
+
// missing, so a cold/absent fee cache does not flood the logs while the bot
|
|
92
|
+
// keeps running on fallback fees.
|
|
93
|
+
const warnedBtsFeeScheduleFallback = new Set();
|
|
94
|
+
const warnedFillFeeSymbols = new Set();
|
|
123
95
|
/**
|
|
124
96
|
* Accountant engine - Specialized handler for fund tracking and calculations
|
|
125
97
|
* @class Accountant
|
|
@@ -144,7 +116,7 @@ class Accountant {
|
|
|
144
116
|
this._pendingInvariantSnapshot = null; // Coalesces latest request while one is running
|
|
145
117
|
this._logThrottleState = new Map();
|
|
146
118
|
}
|
|
147
|
-
_logThrottled(key, message, level = 'warn', intervalMs =
|
|
119
|
+
_logThrottled(key, message, level = 'warn', intervalMs = TIMING.LOG_THROTTLE_INTERVAL_MS) {
|
|
148
120
|
const now = Date.now();
|
|
149
121
|
let state = this._logThrottleState.get(key);
|
|
150
122
|
if (!state || (now - state.lastAt) >= intervalMs) {
|
|
@@ -169,7 +141,7 @@ class Accountant {
|
|
|
169
141
|
}
|
|
170
142
|
}
|
|
171
143
|
_getBtsOrderType() {
|
|
172
|
-
return
|
|
144
|
+
return getBtsSide(this.manager.config?.assetA, this.manager.config?.assetB);
|
|
173
145
|
}
|
|
174
146
|
_normalizeBtsFeeState(order) {
|
|
175
147
|
const deferredFee = toFiniteNumber(order?.btsFeeState?.deferredFee, 0);
|
|
@@ -179,21 +151,24 @@ class Accountant {
|
|
|
179
151
|
}
|
|
180
152
|
_getBtsFeeSchedule() {
|
|
181
153
|
try {
|
|
182
|
-
const fees =
|
|
154
|
+
const fees = getAssetFees('BTS');
|
|
183
155
|
return {
|
|
184
156
|
createFee: Math.max(0, toFiniteNumber(fees?.createFee, 0)),
|
|
185
157
|
updateFee: Math.max(0, toFiniteNumber(fees?.updateFee, 0)),
|
|
186
158
|
cancelFee: Math.max(0, toFiniteNumber(fees?.cancelFee, 0)),
|
|
187
|
-
makerFeeDiscountPercent: Math.max(0, toFiniteNumber(fees?.makerFeeDiscountPercent, this.manager?.config?.feeParams?.MAKER_REFUND_PERCENT ??
|
|
159
|
+
makerFeeDiscountPercent: Math.max(0, toFiniteNumber(fees?.makerFeeDiscountPercent, this.manager?.config?.feeParams?.MAKER_REFUND_PERCENT ?? FEE_PARAMETERS.MAKER_REFUND_PERCENT))
|
|
188
160
|
};
|
|
189
161
|
}
|
|
190
162
|
catch (err) {
|
|
191
|
-
|
|
163
|
+
if (!warnedBtsFeeScheduleFallback.has('BTS')) {
|
|
164
|
+
warnedBtsFeeScheduleFallback.add('BTS');
|
|
165
|
+
this.manager?.logger?.log?.(`[FEE] Failed to load BTS fee schedule: ${err?.message || err}; using fallback defaults`, 'warn');
|
|
166
|
+
}
|
|
192
167
|
return {
|
|
193
168
|
createFee: 0,
|
|
194
169
|
updateFee: 0,
|
|
195
170
|
cancelFee: 0,
|
|
196
|
-
makerFeeDiscountPercent: this.manager?.config?.feeParams?.MAKER_REFUND_PERCENT ??
|
|
171
|
+
makerFeeDiscountPercent: this.manager?.config?.feeParams?.MAKER_REFUND_PERCENT ?? FEE_PARAMETERS.MAKER_REFUND_PERCENT
|
|
197
172
|
};
|
|
198
173
|
}
|
|
199
174
|
}
|
|
@@ -215,8 +190,8 @@ class Accountant {
|
|
|
215
190
|
}
|
|
216
191
|
_resolveBtsFeeLifecycle(oldOrder, newOrder, context, explicitFee) {
|
|
217
192
|
const fee = Math.max(0, toFiniteNumber(explicitFee, 0));
|
|
218
|
-
const oldActive = !!(oldOrder && (oldOrder.state ===
|
|
219
|
-
const newActive = !!(newOrder && (newOrder.state ===
|
|
193
|
+
const oldActive = !!(oldOrder && (oldOrder.state === ORDER_STATES.ACTIVE || oldOrder.state === ORDER_STATES.PARTIAL) && oldOrder.orderId);
|
|
194
|
+
const newActive = !!(newOrder && (newOrder.state === ORDER_STATES.ACTIVE || newOrder.state === ORDER_STATES.PARTIAL) && newOrder.orderId);
|
|
220
195
|
const oldDeferred = this._normalizeBtsFeeState(oldOrder).deferredFee;
|
|
221
196
|
const sameChainOrder = oldActive && newActive && oldOrder.orderId === newOrder.orderId;
|
|
222
197
|
const feeSchedule = this._getBtsFeeSchedule();
|
|
@@ -370,11 +345,11 @@ class Accountant {
|
|
|
370
345
|
// SPREAD-type count would include every empty slot on both rails.
|
|
371
346
|
// countGapBandSpread requires both SPREAD type and band geometry —
|
|
372
347
|
// matching initialSpreadCount (gapSlots) set at grid load/creation.
|
|
373
|
-
mgr.currentSpreadCount =
|
|
348
|
+
mgr.currentSpreadCount = countGapBandSpread(mgr, orderSnapshot, (o) => parseSlotIndex(o.id));
|
|
374
349
|
// STEP 1-4: Iterate all orders, classify, and aggregate by state
|
|
375
350
|
for (const order of orderSnapshot) {
|
|
376
|
-
const isActive = (order.state ===
|
|
377
|
-
const isVirtual = (order.state ===
|
|
351
|
+
const isActive = (order.state === ORDER_STATES.ACTIVE || order.state === ORDER_STATES.PARTIAL) && !!order.orderId;
|
|
352
|
+
const isVirtual = (order.state === ORDER_STATES.VIRTUAL);
|
|
378
353
|
const size = toFiniteNumber(order.size);
|
|
379
354
|
if (size <= 0)
|
|
380
355
|
continue;
|
|
@@ -383,8 +358,8 @@ class Accountant {
|
|
|
383
358
|
// - SPREAD type: derive from price relation to startPrice (market midpoint)
|
|
384
359
|
// * price < startPrice → BUY side (lower prices are bids)
|
|
385
360
|
// * price >= startPrice → SELL side (higher prices are asks)
|
|
386
|
-
const isBuy = order.type ===
|
|
387
|
-
const isSell = order.type ===
|
|
361
|
+
const isBuy = order.type === ORDER_TYPES.BUY || (order.type === ORDER_TYPES.SPREAD && resolveSpreadOrderSide(order.price, mgr.config.startPrice) === ORDER_TYPES.BUY);
|
|
362
|
+
const isSell = order.type === ORDER_TYPES.SELL || (order.type === ORDER_TYPES.SPREAD && resolveSpreadOrderSide(order.price, mgr.config.startPrice) === ORDER_TYPES.SELL);
|
|
388
363
|
if (isBuy) {
|
|
389
364
|
if (isActive) {
|
|
390
365
|
gridBuy += size;
|
|
@@ -417,8 +392,8 @@ class Accountant {
|
|
|
417
392
|
mgr.funds.total.grid = { buy: gridBuy + virtualBuy, sell: gridSell + virtualSell };
|
|
418
393
|
// STEP 6: Calculate available funds (what we can spend right now)
|
|
419
394
|
// Uses utils::calculateAvailableFundsValue which deducts committe amounts
|
|
420
|
-
mgr.funds.available.buy =
|
|
421
|
-
mgr.funds.available.sell =
|
|
395
|
+
mgr.funds.available.buy = calculateAvailableFundsValue('buy', mgr.accountTotals, mgr.funds, mgr.config.assetA, mgr.config.assetB, mgr.config.activeOrders, mgr.config.min_BTS_value, mgr.config?.feeParams ?? null);
|
|
396
|
+
mgr.funds.available.sell = calculateAvailableFundsValue('sell', mgr.accountTotals, mgr.funds, mgr.config.assetA, mgr.config.assetB, mgr.config.activeOrders, mgr.config.min_BTS_value, mgr.config?.feeParams ?? null);
|
|
422
397
|
// Ensure percentage-based allocations are applied to the newly calculated totals
|
|
423
398
|
if (typeof mgr.applyBotFundsAllocation === 'function') {
|
|
424
399
|
mgr.applyBotFundsAllocation();
|
|
@@ -437,7 +412,7 @@ class Accountant {
|
|
|
437
412
|
this._isVerifyingInvariants = true;
|
|
438
413
|
this._verifyFundInvariants(mgr, nextSnapshot.chainFreeBuy, nextSnapshot.chainFreeSell, nextSnapshot.chainBuy, nextSnapshot.chainSell, nextSnapshot.actualBuy, nextSnapshot.actualSell)
|
|
439
414
|
.catch((err) => {
|
|
440
|
-
mgr.logger?.log?.(`[RECOVERY] Verification error: ${
|
|
415
|
+
mgr.logger?.log?.(`[RECOVERY] Verification error: ${getErrorMessage(err)}`, 'error');
|
|
441
416
|
})
|
|
442
417
|
.finally(() => {
|
|
443
418
|
this._isVerifyingInvariants = false;
|
|
@@ -493,8 +468,8 @@ class Accountant {
|
|
|
493
468
|
if (!Number.isFinite(buyPrecision) || !Number.isFinite(sellPrecision)) {
|
|
494
469
|
return; // Skip invariant check if precision not available
|
|
495
470
|
}
|
|
496
|
-
const precisionSlackBuy =
|
|
497
|
-
const precisionSlackSell =
|
|
471
|
+
const precisionSlackBuy = getPrecisionSlack(buyPrecision);
|
|
472
|
+
const precisionSlackSell = getPrecisionSlack(sellPrecision);
|
|
498
473
|
const PERCENT_TOLERANCE = (mgr.config?.gridLimits?.FUND_INVARIANT_PERCENT_TOLERANCE) / 100;
|
|
499
474
|
// FIX 5: Widen tolerance when orphan fills were recently credited.
|
|
500
475
|
// Orphan fill accounting adjusts mgr.accountTotals optimistically, but
|
|
@@ -573,7 +548,7 @@ class Accountant {
|
|
|
573
548
|
}
|
|
574
549
|
}
|
|
575
550
|
catch (_err) {
|
|
576
|
-
mgr.logger?.log?.(`[INVARIANT] Cross-bot registry check skipped: ${
|
|
551
|
+
mgr.logger?.log?.(`[INVARIANT] Cross-bot registry check skipped: ${getErrorMessage(_err)}`, 'warn');
|
|
577
552
|
}
|
|
578
553
|
}
|
|
579
554
|
// NEW: Attempt immediate recovery if violation detected
|
|
@@ -583,13 +558,13 @@ class Accountant {
|
|
|
583
558
|
await this._attemptFundRecovery(mgr, 'Fund invariant violation');
|
|
584
559
|
}
|
|
585
560
|
catch (err) {
|
|
586
|
-
mgr.logger?.log?.(`[RECOVERY] Deferred recovery failed: ${
|
|
561
|
+
mgr.logger?.log?.(`[RECOVERY] Deferred recovery failed: ${getErrorMessage(err)}`, 'error');
|
|
587
562
|
mgr._recoveryState = { ...mgr._recoveryState, lastFailureAt: Date.now() };
|
|
588
563
|
}
|
|
589
564
|
};
|
|
590
565
|
if (mgr._gridLock?.isLocked?.()) {
|
|
591
566
|
doRecovery().catch((err) => {
|
|
592
|
-
mgr.logger?.log?.(`[RECOVERY] Deferred recovery scheduling failed: ${
|
|
567
|
+
mgr.logger?.log?.(`[RECOVERY] Deferred recovery scheduling failed: ${getErrorMessage(err)}`, 'error');
|
|
593
568
|
});
|
|
594
569
|
}
|
|
595
570
|
else {
|
|
@@ -605,7 +580,7 @@ class Accountant {
|
|
|
605
580
|
* @returns {Promise<Object>} - Validation result from validateGridStateForPersistence()
|
|
606
581
|
*/
|
|
607
582
|
async _performStateRecovery(mgr) {
|
|
608
|
-
const accountRef =
|
|
583
|
+
const accountRef = resolveAccountRef(mgr, '');
|
|
609
584
|
if (!accountRef) {
|
|
610
585
|
return {
|
|
611
586
|
isValid: false,
|
|
@@ -625,7 +600,7 @@ class Accountant {
|
|
|
625
600
|
// ACTIVE/PARTIAL slots that are live on chain, after which the next
|
|
626
601
|
// cycle re-creates them as duplicates. Skip the sync and defer to the
|
|
627
602
|
// next reconcile cycle, mirroring the other recovery-read guards.
|
|
628
|
-
const openOrders = await
|
|
603
|
+
const openOrders = await readOpenOrdersGuarded(chainOrders, accountRef, {
|
|
629
604
|
log: (message, level) => mgr.logger?.log?.(message, level),
|
|
630
605
|
label: 'RECOVERY',
|
|
631
606
|
detail: 'during state recovery',
|
|
@@ -689,7 +664,7 @@ class Accountant {
|
|
|
689
664
|
if (!mgr._recoveryState || typeof mgr._recoveryState !== 'object') {
|
|
690
665
|
mgr._recoveryState = { attemptCount: 0, lastAttemptAt: 0, inFlight: false, lastFailureAt: 0, structuralResyncRequested: false };
|
|
691
666
|
}
|
|
692
|
-
const pt = mgr.config?.pipelineTiming ||
|
|
667
|
+
const pt = mgr.config?.pipelineTiming || PIPELINE_TIMING;
|
|
693
668
|
const state = mgr._recoveryState;
|
|
694
669
|
const now = Date.now();
|
|
695
670
|
const retryIntervalMs = Math.max(0, Number(pt.RECOVERY_RETRY_INTERVAL_MS));
|
|
@@ -702,12 +677,12 @@ class Accountant {
|
|
|
702
677
|
// Decay: if enough time has passed since the last failure, treat this
|
|
703
678
|
// as a fresh violation cycle to prevent stale counts from a previous
|
|
704
679
|
// cycle permanently exhausting the attempt budget.
|
|
705
|
-
const decayMs = retryIntervalMs > 0 ? retryIntervalMs * 3 : (pt.RECOVERY_DECAY_FALLBACK_MS ??
|
|
680
|
+
const decayMs = retryIntervalMs > 0 ? retryIntervalMs * 3 : (pt.RECOVERY_DECAY_FALLBACK_MS ?? PIPELINE_TIMING.RECOVERY_DECAY_FALLBACK_MS);
|
|
706
681
|
if (state.attemptCount > 0 && state.lastFailureAt > 0 && (now - state.lastFailureAt) > decayMs) {
|
|
707
682
|
// Log at 'info' level so operators can monitor for repeated decay patterns
|
|
708
683
|
// which may indicate a persistent issue that self-corrects just long enough
|
|
709
684
|
// to trigger decay, then recurs. Pattern: repeated "decayed" messages.
|
|
710
|
-
mgr.logger?.log?.(`[RECOVERY] Attempt count decayed (${state.attemptCount} -> 0) after ${Math.round((now - state.lastFailureAt) /
|
|
685
|
+
mgr.logger?.log?.(`[RECOVERY] Attempt count decayed (${state.attemptCount} -> 0) after ${Math.round((now - state.lastFailureAt) / TIMING.MILLISECONDS_PER_SECOND)}s idle`, 'info');
|
|
711
686
|
state.attemptCount = 0;
|
|
712
687
|
state.lastFailureAt = 0;
|
|
713
688
|
}
|
|
@@ -785,7 +760,7 @@ class Accountant {
|
|
|
785
760
|
})
|
|
786
761
|
.catch((err) => {
|
|
787
762
|
state.structuralResyncRequested = false;
|
|
788
|
-
mgr.logger?.log?.(`[RECOVERY] Structural grid resync scheduling failed: ${
|
|
763
|
+
mgr.logger?.log?.(`[RECOVERY] Structural grid resync scheduling failed: ${getErrorMessage(err)}`, 'error');
|
|
789
764
|
});
|
|
790
765
|
}
|
|
791
766
|
else {
|
|
@@ -797,7 +772,7 @@ class Accountant {
|
|
|
797
772
|
}
|
|
798
773
|
catch (err) {
|
|
799
774
|
state.lastFailureAt = Date.now();
|
|
800
|
-
mgr.logger?.log?.(`[RECOVERY] State recovery error: ${
|
|
775
|
+
mgr.logger?.log?.(`[RECOVERY] State recovery error: ${getErrorMessage(err)}`, 'error');
|
|
801
776
|
return false;
|
|
802
777
|
}
|
|
803
778
|
finally {
|
|
@@ -835,7 +810,7 @@ class Accountant {
|
|
|
835
810
|
*/
|
|
836
811
|
async tryDeductFromChainFree(orderType, size, operation = 'move') {
|
|
837
812
|
const mgr = this.manager;
|
|
838
|
-
const isBuy = orderType ===
|
|
813
|
+
const isBuy = orderType === ORDER_TYPES.BUY;
|
|
839
814
|
const key = isBuy ? 'buyFree' : 'sellFree';
|
|
840
815
|
if (!mgr.accountTotals || mgr.accountTotals[key] === undefined) {
|
|
841
816
|
return { ok: false, reason: 'undefined' };
|
|
@@ -873,7 +848,7 @@ class Accountant {
|
|
|
873
848
|
*/
|
|
874
849
|
async addToChainFree(orderType, size, operation = 'release') {
|
|
875
850
|
const mgr = this.manager;
|
|
876
|
-
const isBuy = orderType ===
|
|
851
|
+
const isBuy = orderType === ORDER_TYPES.BUY;
|
|
877
852
|
const key = isBuy ? 'buyFree' : 'sellFree';
|
|
878
853
|
if (!mgr.accountTotals || mgr.accountTotals[key] === undefined)
|
|
879
854
|
return false;
|
|
@@ -901,13 +876,13 @@ class Accountant {
|
|
|
901
876
|
// Determine orientation
|
|
902
877
|
if (paysAsset === assetA) {
|
|
903
878
|
// Bot paid assetA (Selling assetA, buying assetB)
|
|
904
|
-
this._adjustTotalBalanceLocked(
|
|
905
|
-
this._adjustTotalBalanceLocked(
|
|
879
|
+
this._adjustTotalBalanceLocked(ORDER_TYPES.SELL, -paysAmount, `${context}-pays`);
|
|
880
|
+
this._adjustTotalBalanceLocked(ORDER_TYPES.BUY, receivesAmount, `${context}-receives`);
|
|
906
881
|
}
|
|
907
882
|
else {
|
|
908
883
|
// Bot paid assetB (Buying assetA, selling assetB)
|
|
909
|
-
this._adjustTotalBalanceLocked(
|
|
910
|
-
this._adjustTotalBalanceLocked(
|
|
884
|
+
this._adjustTotalBalanceLocked(ORDER_TYPES.BUY, -paysAmount, `${context}-pays`);
|
|
885
|
+
this._adjustTotalBalanceLocked(ORDER_TYPES.SELL, receivesAmount, `${context}-receives`);
|
|
911
886
|
}
|
|
912
887
|
});
|
|
913
888
|
}
|
|
@@ -918,7 +893,7 @@ class Accountant {
|
|
|
918
893
|
*/
|
|
919
894
|
_adjustTotalBalanceLocked(orderType, delta, operation) {
|
|
920
895
|
const mgr = this.manager;
|
|
921
|
-
const isBuy = (orderType ===
|
|
896
|
+
const isBuy = (orderType === ORDER_TYPES.BUY);
|
|
922
897
|
const freeKey = isBuy ? 'buyFree' : 'sellFree';
|
|
923
898
|
const totalKey = isBuy ? 'buy' : 'sell';
|
|
924
899
|
if (!mgr.accountTotals)
|
|
@@ -952,10 +927,10 @@ class Accountant {
|
|
|
952
927
|
* @returns {string|null} Normalized side or null if unrecognised
|
|
953
928
|
*/
|
|
954
929
|
_normalizeSideHint(sideHint) {
|
|
955
|
-
if (sideHint ===
|
|
956
|
-
return
|
|
957
|
-
if (sideHint ===
|
|
958
|
-
return
|
|
930
|
+
if (sideHint === ORDER_TYPES.BUY || sideHint === 'buy')
|
|
931
|
+
return ORDER_TYPES.BUY;
|
|
932
|
+
if (sideHint === ORDER_TYPES.SELL || sideHint === 'sell')
|
|
933
|
+
return ORDER_TYPES.SELL;
|
|
959
934
|
return null;
|
|
960
935
|
}
|
|
961
936
|
/**
|
|
@@ -1011,8 +986,8 @@ class Accountant {
|
|
|
1011
986
|
// of deferring. Only the plain mutation runs under the lock.
|
|
1012
987
|
let preLockRefreshFailed = false;
|
|
1013
988
|
if (!skipAssetAccounting) {
|
|
1014
|
-
const oldIsActive = (oldOrder.state ===
|
|
1015
|
-
const newIsActive = (newOrder.state ===
|
|
989
|
+
const oldIsActive = (oldOrder.state === ORDER_STATES.ACTIVE || oldOrder.state === ORDER_STATES.PARTIAL);
|
|
990
|
+
const newIsActive = (newOrder.state === ORDER_STATES.ACTIVE || newOrder.state === ORDER_STATES.PARTIAL);
|
|
1016
991
|
const willLock = (newIsActive ? toFiniteNumber(newOrder.size) : 0) - (oldIsActive ? toFiniteNumber(oldOrder.size) : 0) > 0;
|
|
1017
992
|
if (willLock) {
|
|
1018
993
|
try {
|
|
@@ -1021,7 +996,7 @@ class Accountant {
|
|
|
1021
996
|
}
|
|
1022
997
|
catch (err) {
|
|
1023
998
|
preLockRefreshFailed = true;
|
|
1024
|
-
mgr.logger?.log?.(`[ACCOUNTING] pre-lock accountTotals refresh error: ${
|
|
999
|
+
mgr.logger?.log?.(`[ACCOUNTING] pre-lock accountTotals refresh error: ${getErrorMessage(err)}`, 'warn');
|
|
1025
1000
|
}
|
|
1026
1001
|
}
|
|
1027
1002
|
}
|
|
@@ -1032,8 +1007,8 @@ class Accountant {
|
|
|
1032
1007
|
newOrder = { ...newOrder };
|
|
1033
1008
|
}
|
|
1034
1009
|
if (!skipAssetAccounting) {
|
|
1035
|
-
const oldIsActive = (oldOrder.state ===
|
|
1036
|
-
const newIsActive = (newOrder.state ===
|
|
1010
|
+
const oldIsActive = (oldOrder.state === ORDER_STATES.ACTIVE || oldOrder.state === ORDER_STATES.PARTIAL);
|
|
1011
|
+
const newIsActive = (newOrder.state === ORDER_STATES.ACTIVE || newOrder.state === ORDER_STATES.PARTIAL);
|
|
1037
1012
|
const oldSize = toFiniteNumber(oldOrder.size);
|
|
1038
1013
|
const newSize = toFiniteNumber(newOrder.size);
|
|
1039
1014
|
// 1. Handle Capital Commitment (Moves between FREE and LOCKED)
|
|
@@ -1069,7 +1044,7 @@ class Accountant {
|
|
|
1069
1044
|
if (refresh.ok) {
|
|
1070
1045
|
result = await this.tryDeductFromChainFree(commitmentSide, commitmentDelta, `${context} (post-refresh retry)`);
|
|
1071
1046
|
}
|
|
1072
|
-
else {
|
|
1047
|
+
else if (mgr._rateLimitStaleTotalsWarn?.('refresh-failed') !== false) {
|
|
1073
1048
|
mgr.logger?.log?.(`[ACCOUNTING] accountTotals refresh failed (${refresh.reason}); cannot retry optimistic lock of ${Format.formatAmount8(commitmentDelta)} for ${commitmentSide}.`, 'warn');
|
|
1074
1049
|
}
|
|
1075
1050
|
}
|
|
@@ -1078,7 +1053,9 @@ class Accountant {
|
|
|
1078
1053
|
// refuse to re-run the blocking RPC under _fundLock. Fall
|
|
1079
1054
|
// through to the stale failure/recovery path below; the batch
|
|
1080
1055
|
// stays accounted for and recovery is scheduled.
|
|
1081
|
-
mgr.
|
|
1056
|
+
if (mgr._rateLimitStaleTotalsWarn?.('pre-lock-refresh-failed') !== false) {
|
|
1057
|
+
mgr.logger?.log?.(`[ACCOUNTING] Stale accountTotals during ${context}; pre-lock refresh failed, skipping in-lock refresh to avoid holding _fundLock across a blocking chain RPC.`, 'warn');
|
|
1058
|
+
}
|
|
1082
1059
|
}
|
|
1083
1060
|
if (!result.ok) {
|
|
1084
1061
|
const failure = {
|
|
@@ -1091,7 +1068,9 @@ class Accountant {
|
|
|
1091
1068
|
};
|
|
1092
1069
|
mgr._lastAccountingFailure = failure;
|
|
1093
1070
|
if (result.reason === 'stale') {
|
|
1094
|
-
mgr.
|
|
1071
|
+
if (mgr._rateLimitStaleTotalsWarn?.('skip-optimistic-lock') !== false) {
|
|
1072
|
+
mgr.logger?.log?.(`[ACCOUNTING] Stale accountTotals: skipping optimistic lock of ${Format.formatAmount8(commitmentDelta)} for ${commitmentSide} during ${context}. Recovery scheduled.`, 'warn');
|
|
1073
|
+
}
|
|
1095
1074
|
// Schedule recovery but DON'T throw — staleness is transient.
|
|
1096
1075
|
// The batch already confirmed on-chain; aborting the commit
|
|
1097
1076
|
// would orphan a successful broadcast from the grid state.
|
|
@@ -1110,7 +1089,7 @@ class Accountant {
|
|
|
1110
1089
|
if (!mgr._pendingRecovery) {
|
|
1111
1090
|
mgr._pendingRecovery = this._attemptFundRecovery(mgr, 'Optimistic commitment deduction failure')
|
|
1112
1091
|
.catch((err) => {
|
|
1113
|
-
mgr.logger?.log?.(`[RECOVERY] Immediate recovery scheduling failed: ${
|
|
1092
|
+
mgr.logger?.log?.(`[RECOVERY] Immediate recovery scheduling failed: ${getErrorMessage(err)}`, 'error');
|
|
1114
1093
|
mgr._recoveryState = { ...mgr._recoveryState, lastFailureAt: Date.now() };
|
|
1115
1094
|
})
|
|
1116
1095
|
.finally(() => {
|
|
@@ -1135,7 +1114,9 @@ class Accountant {
|
|
|
1135
1114
|
if (btsOrderType) {
|
|
1136
1115
|
const { balanceDelta } = this._resolveBtsFeeLifecycle(oldOrder, newOrder, context, fee);
|
|
1137
1116
|
if (Math.abs(balanceDelta) > 0) {
|
|
1138
|
-
|
|
1117
|
+
// Caller already holds _fundLock, so use the locked body directly
|
|
1118
|
+
// (adjustTotalBalance would re-acquire the re-entrant lock).
|
|
1119
|
+
this._adjustTotalBalanceLocked(btsOrderType, balanceDelta, `${context}-fee`);
|
|
1139
1120
|
}
|
|
1140
1121
|
}
|
|
1141
1122
|
});
|
|
@@ -1156,7 +1137,7 @@ class Accountant {
|
|
|
1156
1137
|
// happen inside _fundLock below so overlapping calls cannot double-deduct)
|
|
1157
1138
|
if (!mgr.funds || !mgr.accountTotals)
|
|
1158
1139
|
return;
|
|
1159
|
-
const btsSide =
|
|
1140
|
+
const btsSide = getBtsSide(mgr.config?.assetA, mgr.config?.assetB);
|
|
1160
1141
|
const normalizedRequestedSide = (requestedSide === 'buy' || requestedSide === 'sell') ? requestedSide : null;
|
|
1161
1142
|
let side = btsSide || normalizedRequestedSide;
|
|
1162
1143
|
if (normalizedRequestedSide && btsSide && normalizedRequestedSide !== btsSide) {
|
|
@@ -1173,7 +1154,7 @@ class Accountant {
|
|
|
1173
1154
|
const fees = mgr.funds.btsFeesOwed;
|
|
1174
1155
|
if (!fees || fees <= 0)
|
|
1175
1156
|
return;
|
|
1176
|
-
const orderType = (side === 'buy') ?
|
|
1157
|
+
const orderType = (side === 'buy') ? ORDER_TYPES.BUY : ORDER_TYPES.SELL;
|
|
1177
1158
|
const freeKey = (side === 'buy') ? 'buyFree' : 'sellFree';
|
|
1178
1159
|
const chainFree = mgr.accountTotals[freeKey] || 0;
|
|
1179
1160
|
// SUFFICIENCY CHECK: Defer if insufficient funds
|
|
@@ -1216,18 +1197,18 @@ class Accountant {
|
|
|
1216
1197
|
const size = toFiniteNumber(order.size);
|
|
1217
1198
|
if (size <= 0)
|
|
1218
1199
|
continue;
|
|
1219
|
-
if (order.type ===
|
|
1200
|
+
if (order.type === ORDER_TYPES.BUY) {
|
|
1220
1201
|
// Buy order uses Asset B (Quote)
|
|
1221
1202
|
requiredBuy += size;
|
|
1222
1203
|
}
|
|
1223
|
-
else if (order.type ===
|
|
1204
|
+
else if (order.type === ORDER_TYPES.SELL) {
|
|
1224
1205
|
// Sell order uses Asset A (Base)
|
|
1225
1206
|
requiredSell += size;
|
|
1226
1207
|
}
|
|
1227
1208
|
}
|
|
1228
1209
|
// 2. Add Estimated BTS Fees (if BTS is one of the pairs)
|
|
1229
1210
|
// Fees reduce the "Free" balance, so they compete with Order Capital
|
|
1230
|
-
const btsSide =
|
|
1211
|
+
const btsSide = getBtsSide(mgr.config?.assetA, mgr.config?.assetB);
|
|
1231
1212
|
if (btsSide && mgr.funds.btsFeesOwed > 0) {
|
|
1232
1213
|
if (btsSide === 'buy')
|
|
1233
1214
|
requiredBuy += mgr.funds.btsFeesOwed;
|
|
@@ -1244,8 +1225,8 @@ class Accountant {
|
|
|
1244
1225
|
if (mgr.assets?.assetB?.precision === undefined || mgr.assets?.assetA?.precision === undefined) {
|
|
1245
1226
|
throw new Error(`CRITICAL: Asset precision unavailable for slack calculation`);
|
|
1246
1227
|
}
|
|
1247
|
-
const slackBuy =
|
|
1248
|
-
const slackSell =
|
|
1228
|
+
const slackBuy = getPrecisionSlack(mgr.assets?.assetB?.precision);
|
|
1229
|
+
const slackSell = getPrecisionSlack(mgr.assets?.assetA?.precision);
|
|
1249
1230
|
const buyShortfall = Math.max(0, requiredBuy - (totalBuy + slackBuy));
|
|
1250
1231
|
const sellShortfall = Math.max(0, requiredSell - (totalSell + slackSell));
|
|
1251
1232
|
const isValid = buyShortfall === 0 && sellShortfall === 0;
|
|
@@ -1279,7 +1260,7 @@ class Accountant {
|
|
|
1279
1260
|
// For other assets: apply normal fee calculation (market fee %)
|
|
1280
1261
|
// Fail-safe: if fee cache is missing/stale, do not crash fill processing.
|
|
1281
1262
|
try {
|
|
1282
|
-
const feeInfo =
|
|
1263
|
+
const feeInfo = getAssetFees(assetSymbol, rawAmount, isMaker);
|
|
1283
1264
|
const netProceeds = toFiniteNumber(feeInfo?.netProceeds, undefined);
|
|
1284
1265
|
if (netProceeds === null) {
|
|
1285
1266
|
throw new Error('netProceeds is not finite');
|
|
@@ -1287,7 +1268,10 @@ class Accountant {
|
|
|
1287
1268
|
return netProceeds;
|
|
1288
1269
|
}
|
|
1289
1270
|
catch (err) {
|
|
1290
|
-
|
|
1271
|
+
if (!warnedFillFeeSymbols.has(assetSymbol)) {
|
|
1272
|
+
warnedFillFeeSymbols.add(assetSymbol);
|
|
1273
|
+
this.manager?.logger?.log?.(`[FILL-FEE] CRITICAL: Failed to compute fees for ${assetSymbol}: ${getErrorMessage(err)}. Using raw proceeds (${Format.formatAmount8(rawAmount)}) — fund tracking will over-credit by un-deducted fee.`, 'error');
|
|
1274
|
+
}
|
|
1291
1275
|
return rawAmount;
|
|
1292
1276
|
}
|
|
1293
1277
|
}
|
|
@@ -1305,7 +1289,7 @@ class Accountant {
|
|
|
1305
1289
|
// Persistence is durable by default. Callers that process many fills under
|
|
1306
1290
|
// the fill lock can opt into deferred persistence and close the window with
|
|
1307
1291
|
// one explicit batch flush before leaving the processing cycle.
|
|
1308
|
-
const persistenceMode =
|
|
1292
|
+
const persistenceMode = resolveProcessedFillPersistenceMode(options);
|
|
1309
1293
|
const pays = fillOp?.pays;
|
|
1310
1294
|
const receives = fillOp?.receives;
|
|
1311
1295
|
if (!pays || !receives)
|
|
@@ -1331,22 +1315,22 @@ class Accountant {
|
|
|
1331
1315
|
const assetASymbol = mgr.config?.assetA;
|
|
1332
1316
|
const assetBSymbol = mgr.config?.assetB;
|
|
1333
1317
|
if (pays.asset_id === assetAId) {
|
|
1334
|
-
const amount =
|
|
1335
|
-
balanceAdjustments.push({ orderType:
|
|
1318
|
+
const amount = blockchainToFloat(pays.amount, assetAPrecision);
|
|
1319
|
+
balanceAdjustments.push({ orderType: ORDER_TYPES.SELL, delta: -amount, operation: 'fill-pays' });
|
|
1336
1320
|
}
|
|
1337
1321
|
else if (pays.asset_id === assetBId) {
|
|
1338
|
-
const amount =
|
|
1339
|
-
balanceAdjustments.push({ orderType:
|
|
1322
|
+
const amount = blockchainToFloat(pays.amount, assetBPrecision);
|
|
1323
|
+
balanceAdjustments.push({ orderType: ORDER_TYPES.BUY, delta: -amount, operation: 'fill-pays' });
|
|
1340
1324
|
}
|
|
1341
1325
|
if (receives.asset_id === assetAId) {
|
|
1342
|
-
const rawAmount =
|
|
1326
|
+
const rawAmount = blockchainToFloat(receives.amount, assetAPrecision);
|
|
1343
1327
|
const netAmount = this._deductFeesFromProceeds(assetASymbol, rawAmount, isMaker);
|
|
1344
|
-
balanceAdjustments.push({ orderType:
|
|
1328
|
+
balanceAdjustments.push({ orderType: ORDER_TYPES.SELL, delta: netAmount, operation: 'fill-receives' });
|
|
1345
1329
|
}
|
|
1346
1330
|
else if (receives.asset_id === assetBId) {
|
|
1347
|
-
const rawAmount =
|
|
1331
|
+
const rawAmount = blockchainToFloat(receives.amount, assetBPrecision);
|
|
1348
1332
|
const netAmount = this._deductFeesFromProceeds(assetBSymbol, rawAmount, isMaker);
|
|
1349
|
-
balanceAdjustments.push({ orderType:
|
|
1333
|
+
balanceAdjustments.push({ orderType: ORDER_TYPES.BUY, delta: netAmount, operation: 'fill-receives' });
|
|
1350
1334
|
}
|
|
1351
1335
|
const btsRefundAdjustment = this._buildBtsDeferredRefundAdjustment(fillOp.order_id, isMaker);
|
|
1352
1336
|
if (btsRefundAdjustment) {
|
|
@@ -1357,7 +1341,7 @@ class Accountant {
|
|
|
1357
1341
|
if (fillKey) {
|
|
1358
1342
|
processedAt = Date.now();
|
|
1359
1343
|
const lastProcessed = tracker.get(fillKey);
|
|
1360
|
-
if (lastProcessed !== undefined && (processedAt - lastProcessed) <
|
|
1344
|
+
if (lastProcessed !== undefined && (processedAt - lastProcessed) < TIMING.FILL_RECORD_RETENTION_MS) {
|
|
1361
1345
|
this.manager?.logger?.log(`[FILL-DEDUP] Skipping duplicate credit for fill ${fillKey} (processed ${processedAt - lastProcessed}ms ago)`, 'warn');
|
|
1362
1346
|
return false;
|
|
1363
1347
|
}
|
|
@@ -1369,10 +1353,10 @@ class Accountant {
|
|
|
1369
1353
|
if (fillKey && processedFillStore) {
|
|
1370
1354
|
try {
|
|
1371
1355
|
// Queue without flush — flush follows after balance adjustments succeed.
|
|
1372
|
-
await processedFillStore.persist(fillKey, processedAt || Date.now(), { mode:
|
|
1356
|
+
await processedFillStore.persist(fillKey, processedAt || Date.now(), { mode: PROCESSED_FILL_PERSISTENCE_MODES.MANUAL });
|
|
1373
1357
|
}
|
|
1374
1358
|
catch (err) {
|
|
1375
|
-
mgr.logger?.log?.(`[FILL-DEDUP] Failed to queue fill ${fillKey}: ${
|
|
1359
|
+
mgr.logger?.log?.(`[FILL-DEDUP] Failed to queue fill ${fillKey}: ${getErrorMessage(err)}`, 'warn');
|
|
1376
1360
|
return false;
|
|
1377
1361
|
}
|
|
1378
1362
|
}
|
|
@@ -1382,7 +1366,7 @@ class Accountant {
|
|
|
1382
1366
|
// key remains queued for the caller's batch flush.
|
|
1383
1367
|
if (fillKey && processedFillStore) {
|
|
1384
1368
|
try {
|
|
1385
|
-
if (persistenceMode ===
|
|
1369
|
+
if (persistenceMode === PROCESSED_FILL_PERSISTENCE_MODES.IMMEDIATE) {
|
|
1386
1370
|
await processedFillStore.flush('fill-persist', { throwOnError: true });
|
|
1387
1371
|
}
|
|
1388
1372
|
}
|
|
@@ -1400,7 +1384,7 @@ class Accountant {
|
|
|
1400
1384
|
tracker.set(fillKey, processedAt || Date.now());
|
|
1401
1385
|
// Prune entries beyond the retention horizon to prevent unbounded growth.
|
|
1402
1386
|
if (tracker.size > 500) {
|
|
1403
|
-
const cutoff = (processedAt || Date.now()) -
|
|
1387
|
+
const cutoff = (processedAt || Date.now()) - TIMING.FILL_RECORD_RETENTION_MS;
|
|
1404
1388
|
for (const [k, ts] of tracker) {
|
|
1405
1389
|
if (ts < cutoff)
|
|
1406
1390
|
tracker.delete(k);
|
|
@@ -1410,5 +1394,5 @@ class Accountant {
|
|
|
1410
1394
|
return true;
|
|
1411
1395
|
}
|
|
1412
1396
|
}
|
|
1413
|
-
|
|
1397
|
+
export default Accountant;
|
|
1414
1398
|
//# sourceMappingURL=accounting.js.map
|