dexbot 1.3.2 → 1.4.0
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/dist/analysis/chart_utils.d.ts +11 -9
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +21 -16
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/math_utils.d.ts +4 -13
- package/dist/analysis/math_utils.d.ts.map +1 -1
- package/dist/analysis/math_utils.js +16 -18
- package/dist/analysis/math_utils.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +3 -7
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +38 -34
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts +1 -4
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js +10 -7
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +6 -6
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +23 -15
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +12 -13
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +16 -16
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +1 -4
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +10 -7
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +6 -13
- package/dist/bot.js.map +1 -1
- package/dist/credential-daemon.d.ts.map +1 -1
- package/dist/credential-daemon.js +74 -35
- package/dist/credential-daemon.js.map +1 -1
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +16 -15
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.d.ts +1 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +8 -20
- package/dist/market_adapter/ama_signal_runner.js.map +1 -1
- package/dist/market_adapter/candle_utils.d.ts +2 -10
- package/dist/market_adapter/candle_utils.d.ts.map +1 -1
- package/dist/market_adapter/candle_utils.js +7 -8
- package/dist/market_adapter/candle_utils.js.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +12 -7
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.js +4 -5
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
- package/dist/market_adapter/core/config_normalizers.d.ts +4 -9
- package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -1
- package/dist/market_adapter/core/config_normalizers.js +9 -9
- package/dist/market_adapter/core/config_normalizers.js.map +1 -1
- package/dist/market_adapter/core/kibana_candles.d.ts +16 -20
- package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_candles.js +16 -15
- package/dist/market_adapter/core/kibana_candles.js.map +1 -1
- package/dist/market_adapter/core/kibana_client.d.ts +8 -11
- package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_client.js +13 -11
- package/dist/market_adapter/core/kibana_client.js.map +1 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts +5 -12
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -1
- package/dist/market_adapter/core/kibana_market_candles.js +12 -21
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts +75 -53
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +102 -98
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama.d.ts +21 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/ama.js +10 -10
- package/dist/market_adapter/core/strategies/ama.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +7 -11
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +23 -30
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +5 -4
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js +5 -3
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +4 -7
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +5 -4
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +11 -19
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.js +22 -22
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
- package/dist/market_adapter/index.d.ts +24 -2
- package/dist/market_adapter/index.d.ts.map +1 -1
- package/dist/market_adapter/index.js +82 -56
- package/dist/market_adapter/index.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +26 -37
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +4 -12
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +100 -66
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts +4 -9
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.js +17 -18
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
- package/dist/market_adapter/interval_utils.d.ts +1 -4
- package/dist/market_adapter/interval_utils.d.ts.map +1 -1
- package/dist/market_adapter/interval_utils.js +2 -3
- package/dist/market_adapter/interval_utils.js.map +1 -1
- package/dist/market_adapter/log_format.d.ts +1 -9
- package/dist/market_adapter/log_format.d.ts.map +1 -1
- package/dist/market_adapter/log_format.js +7 -8
- package/dist/market_adapter/log_format.js.map +1 -1
- package/dist/market_adapter/lp_chart_core.d.ts +1 -4
- package/dist/market_adapter/lp_chart_core.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_core.js +22 -20
- package/dist/market_adapter/lp_chart_core.js.map +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +13 -24
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_runner.js +58 -56
- package/dist/market_adapter/lp_chart_runner.js.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +4 -17
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js +36 -36
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
- package/dist/market_adapter/market_adapter.d.ts +51 -72
- package/dist/market_adapter/market_adapter.d.ts.map +1 -1
- package/dist/market_adapter/market_adapter.js +227 -192
- package/dist/market_adapter/market_adapter.js.map +1 -1
- package/dist/market_adapter/merge_lp_data.js +17 -16
- package/dist/market_adapter/merge_lp_data.js.map +1 -1
- package/dist/market_adapter/test_helpers.d.ts +9 -13
- package/dist/market_adapter/test_helpers.d.ts.map +1 -1
- package/dist/market_adapter/test_helpers.js +14 -14
- package/dist/market_adapter/test_helpers.js.map +1 -1
- package/dist/market_adapter/utils/adapter_client.d.ts +6 -14
- package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -1
- package/dist/market_adapter/utils/adapter_client.js +16 -15
- package/dist/market_adapter/utils/adapter_client.js.map +1 -1
- package/dist/market_adapter/utils/atomic_write.d.ts +2 -5
- package/dist/market_adapter/utils/atomic_write.d.ts.map +1 -1
- package/dist/market_adapter/utils/atomic_write.js +5 -5
- package/dist/market_adapter/utils/atomic_write.js.map +1 -1
- package/dist/market_adapter/utils/chain.d.ts +19 -21
- package/dist/market_adapter/utils/chain.d.ts.map +1 -1
- package/dist/market_adapter/utils/chain.js +15 -16
- package/dist/market_adapter/utils/chain.js.map +1 -1
- package/dist/market_adapter/utils/data_discovery.d.ts +1 -4
- package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -1
- package/dist/market_adapter/utils/data_discovery.js +10 -10
- package/dist/market_adapter/utils/data_discovery.js.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +1 -6
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +14 -14
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
- package/dist/market_adapter/utils/file_lock.d.ts +1 -7
- package/dist/market_adapter/utils/file_lock.d.ts.map +1 -1
- package/dist/market_adapter/utils/file_lock.js +21 -25
- package/dist/market_adapter/utils/file_lock.js.map +1 -1
- package/dist/market_adapter/utils/native_history.d.ts +12 -12
- package/dist/market_adapter/utils/native_history.d.ts.map +1 -1
- package/dist/market_adapter/utils/native_history.js +15 -15
- package/dist/market_adapter/utils/native_history.js.map +1 -1
- package/dist/market_adapter/utils/paths.d.ts +2 -4
- package/dist/market_adapter/utils/paths.d.ts.map +1 -1
- package/dist/market_adapter/utils/paths.js +6 -5
- package/dist/market_adapter/utils/paths.js.map +1 -1
- package/dist/modules/account_bots.d.ts +7 -8
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +92 -114
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +5 -9
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +69 -32
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/authority_resolver.d.ts +32 -1
- package/dist/modules/authority_resolver.d.ts.map +1 -1
- package/dist/modules/authority_resolver.js +18 -12
- package/dist/modules/authority_resolver.js.map +1 -1
- package/dist/modules/bitshares-native/chain_client.d.ts +3 -8
- package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/chain_client.js +21 -16
- package/dist/modules/bitshares-native/chain_client.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +21 -29
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +72 -38
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts +9 -36
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.js +40 -83
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +14 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +5 -3
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
- package/dist/modules/bitshares-native/index.d.ts +10 -2
- package/dist/modules/bitshares-native/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/index.js +68 -31
- package/dist/modules/bitshares-native/index.js.map +1 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts +1 -4
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +1 -1
- package/dist/modules/bitshares-native/lru_cache.js +6 -3
- package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
- package/dist/modules/bitshares-native/resolvers.d.ts +3 -6
- package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -1
- package/dist/modules/bitshares-native/resolvers.js +11 -9
- package/dist/modules/bitshares-native/resolvers.js.map +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +53 -55
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js +28 -27
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
- package/dist/modules/bitshares-native/serial/index.d.ts +5 -9
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/index.js +46 -12
- package/dist/modules/bitshares-native/serial/index.js.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts +102 -100
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.js +473 -471
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts +2 -7
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/serializer.js +8 -3
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
- package/dist/modules/bitshares-native/serial/types.d.ts +26 -41
- package/dist/modules/bitshares-native/serial/types.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/types.js +76 -42
- package/dist/modules/bitshares-native/serial/types.js.map +1 -1
- package/dist/modules/bitshares-native/signing_client.d.ts +1 -5
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/signing_client.js +49 -11
- package/dist/modules/bitshares-native/signing_client.js.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts +1 -4
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.js +47 -84
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
- package/dist/modules/bitshares-native/transport.d.ts +1 -8
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
- package/dist/modules/bitshares-native/transport.js +22 -15
- package/dist/modules/bitshares-native/transport.js.map +1 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts +3 -8
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +1 -1
- package/dist/modules/bitshares-native/tx/builder.js +61 -23
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts +1 -8
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +1 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js +21 -17
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts +12 -23
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +109 -56
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.d.ts +1 -13
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +34 -34
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/bots_file_lock.d.ts +3 -9
- package/dist/modules/bots_file_lock.d.ts.map +1 -1
- package/dist/modules/bots_file_lock.js +8 -9
- package/dist/modules/bots_file_lock.js.map +1 -1
- package/dist/modules/chain_keys.d.ts +7 -39
- package/dist/modules/chain_keys.d.ts.map +1 -1
- package/dist/modules/chain_keys.js +126 -90
- package/dist/modules/chain_keys.js.map +1 -1
- package/dist/modules/chain_orders.d.ts +46 -52
- package/dist/modules/chain_orders.d.ts.map +1 -1
- package/dist/modules/chain_orders.js +152 -104
- package/dist/modules/chain_orders.js.map +1 -1
- package/dist/modules/config.d.ts +50 -57
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +28 -24
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +492 -492
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +79 -39
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/cr_planner.d.ts +1 -13
- package/dist/modules/cr_planner.d.ts.map +1 -1
- package/dist/modules/cr_planner.js +28 -28
- package/dist/modules/cr_planner.js.map +1 -1
- package/dist/modules/credential_policy.d.ts +18 -33
- package/dist/modules/credential_policy.d.ts.map +1 -1
- package/dist/modules/credential_policy.js +114 -87
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/credential_runtime.d.ts +11 -21
- package/dist/modules/credential_runtime.d.ts.map +1 -1
- package/dist/modules/credential_runtime.js +40 -40
- package/dist/modules/credential_runtime.js.map +1 -1
- package/dist/modules/credential_session_cache.d.ts +8 -8
- package/dist/modules/credential_session_cache.d.ts.map +1 -1
- package/dist/modules/credential_session_cache.js +41 -8
- package/dist/modules/credential_session_cache.js.map +1 -1
- package/dist/modules/credit_runtime.d.ts +51 -316
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +257 -183
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/crypto/browser_provider.js +6 -6
- package/dist/modules/crypto/browser_provider.js.map +1 -1
- package/dist/modules/crypto/index.d.ts.map +1 -1
- package/dist/modules/crypto/index.js +2 -0
- package/dist/modules/crypto/index.js.map +1 -1
- package/dist/modules/crypto/sync.js +3 -3
- package/dist/modules/crypto/sync.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +124 -73
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +198 -3577
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +322 -0
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_cow_runtime.js +1836 -0
- package/dist/modules/dexbot_cow_runtime.js.map +1 -0
- package/dist/modules/dexbot_credential_client.d.ts +5 -11
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -1
- package/dist/modules/dexbot_credential_client.js +32 -30
- package/dist/modules/dexbot_credential_client.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +47 -15
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +565 -22
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +79 -10
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +294 -55
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts +26 -0
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_startup_runtime.js +575 -0
- package/dist/modules/dexbot_startup_runtime.js.map +1 -0
- package/dist/modules/dexbot_state_recovery.d.ts +115 -0
- package/dist/modules/dexbot_state_recovery.d.ts.map +1 -0
- package/dist/modules/dexbot_state_recovery.js +431 -0
- package/dist/modules/dexbot_state_recovery.js.map +1 -0
- package/dist/modules/fund_registry.d.ts +1 -13
- package/dist/modules/fund_registry.d.ts.map +1 -1
- package/dist/modules/fund_registry.js +23 -22
- package/dist/modules/fund_registry.js.map +1 -1
- package/dist/modules/general_settings.d.ts +3 -7
- package/dist/modules/general_settings.d.ts.map +1 -1
- package/dist/modules/general_settings.js +15 -15
- package/dist/modules/general_settings.js.map +1 -1
- package/dist/modules/graceful_shutdown.d.ts +1 -6
- package/dist/modules/graceful_shutdown.d.ts.map +1 -1
- package/dist/modules/graceful_shutdown.js +19 -16
- 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 +53 -20
- package/dist/modules/key_store.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts +23 -66
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +115 -107
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/child_env.d.ts +2 -5
- package/dist/modules/launcher/child_env.d.ts.map +1 -1
- package/dist/modules/launcher/child_env.js +4 -4
- package/dist/modules/launcher/child_env.js.map +1 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts +4 -8
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +30 -26
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -1
- package/dist/modules/launcher/credential_daemon.d.ts +8 -15
- package/dist/modules/launcher/credential_daemon.d.ts.map +1 -1
- package/dist/modules/launcher/credential_daemon.js +72 -41
- package/dist/modules/launcher/credential_daemon.js.map +1 -1
- package/dist/modules/launcher/credential_secret.d.ts +1 -4
- package/dist/modules/launcher/credential_secret.d.ts.map +1 -1
- package/dist/modules/launcher/credential_secret.js +36 -4
- package/dist/modules/launcher/credential_secret.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +32 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +25 -28
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/headless_password.d.ts +1 -4
- package/dist/modules/launcher/headless_password.d.ts.map +1 -1
- package/dist/modules/launcher/headless_password.js +11 -11
- package/dist/modules/launcher/headless_password.js.map +1 -1
- package/dist/modules/launcher/launch_modes.d.ts +15 -14
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -1
- package/dist/modules/launcher/launch_modes.js +8 -8
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts +10 -19
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js +33 -34
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -17
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.js +42 -39
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts +28 -57
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +135 -108
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/runtime_entry.d.ts +5 -10
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
- package/dist/modules/launcher/runtime_entry.js +14 -14
- package/dist/modules/launcher/runtime_entry.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +17 -37
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +35 -34
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/launcher/supervisor_control.d.ts +1 -4
- package/dist/modules/launcher/supervisor_control.d.ts.map +1 -1
- package/dist/modules/launcher/supervisor_control.js +9 -4
- package/dist/modules/launcher/supervisor_control.js.map +1 -1
- package/dist/modules/logger.d.ts +3 -1
- package/dist/modules/logger.d.ts.map +1 -1
- package/dist/modules/logger.js +38 -28
- package/dist/modules/logger.js.map +1 -1
- package/dist/modules/market_adapter_whitelist.d.ts +2 -10
- package/dist/modules/market_adapter_whitelist.d.ts.map +1 -1
- package/dist/modules/market_adapter_whitelist.js +18 -16
- package/dist/modules/market_adapter_whitelist.js.map +1 -1
- package/dist/modules/node_health_cache.d.ts +2 -12
- package/dist/modules/node_health_cache.d.ts.map +1 -1
- package/dist/modules/node_health_cache.js +24 -24
- 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 -38
- package/dist/modules/node_manager.js.map +1 -1
- package/dist/modules/order/accounting.d.ts +12 -12
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +111 -76
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/async_lock.d.ts +1 -2
- package/dist/modules/order/async_lock.d.ts.map +1 -1
- package/dist/modules/order/async_lock.js +4 -4
- package/dist/modules/order/async_lock.js.map +1 -1
- package/dist/modules/order/export.d.ts +8 -14
- package/dist/modules/order/export.d.ts.map +1 -1
- package/dist/modules/order/export.js +77 -42
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/format.d.ts +17 -22
- package/dist/modules/order/format.d.ts.map +1 -1
- package/dist/modules/order/format.js +25 -31
- package/dist/modules/order/format.js.map +1 -1
- package/dist/modules/order/grid.d.ts +18 -104
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +246 -188
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile.d.ts +8 -8
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile.js +24 -24
- package/dist/modules/order/grid_reconcile.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts +224 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +145 -72
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/index.d.ts +1 -1
- package/dist/modules/order/index.d.ts.map +1 -1
- package/dist/modules/order/index.js +42 -7
- package/dist/modules/order/index.js.map +1 -1
- package/dist/modules/order/logger.d.ts +6 -16
- package/dist/modules/order/logger.d.ts.map +1 -1
- package/dist/modules/order/logger.js +76 -53
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/logger_state.d.ts.map +1 -1
- package/dist/modules/order/logger_state.js +3 -1
- package/dist/modules/order/logger_state.js.map +1 -1
- package/dist/modules/order/manager.d.ts +160 -37
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +166 -128
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/processed_fill_store.d.ts +6 -10
- package/dist/modules/order/processed_fill_store.d.ts.map +1 -1
- package/dist/modules/order/processed_fill_store.js +10 -9
- package/dist/modules/order/processed_fill_store.js.map +1 -1
- package/dist/modules/order/strategy.d.ts +3 -3
- package/dist/modules/order/strategy.d.ts.map +1 -1
- package/dist/modules/order/strategy.js +29 -27
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts +9 -19
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +176 -126
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +55 -85
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +155 -88
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +27 -72
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +144 -105
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +74 -44
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +188 -149
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/validate.d.ts +21 -43
- package/dist/modules/order/utils/validate.d.ts.map +1 -1
- package/dist/modules/order/utils/validate.js +140 -110
- package/dist/modules/order/utils/validate.js.map +1 -1
- package/dist/modules/order/working_grid.d.ts +1 -4
- package/dist/modules/order/working_grid.d.ts.map +1 -1
- package/dist/modules/order/working_grid.js +9 -7
- package/dist/modules/order/working_grid.js.map +1 -1
- package/dist/modules/path_api.js +2 -2
- package/dist/modules/path_api.js.map +1 -1
- package/dist/modules/paths.d.ts +51 -55
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +72 -52
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.d.ts.map +1 -1
- package/dist/modules/process_discovery.js +7 -7
- package/dist/modules/process_discovery.js.map +1 -1
- package/dist/modules/runtime.d.ts +1 -1
- package/dist/modules/runtime.d.ts.map +1 -1
- package/dist/modules/runtime.js +4 -4
- package/dist/modules/runtime.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts +1 -0
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +15 -10
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/modules/settings_merge.d.ts +1 -4
- package/dist/modules/settings_merge.d.ts.map +1 -1
- package/dist/modules/settings_merge.js +2 -1
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/storage/browser_adapter.d.ts +7 -3
- package/dist/modules/storage/browser_adapter.d.ts.map +1 -1
- package/dist/modules/storage/browser_adapter.js +2 -0
- package/dist/modules/storage/browser_adapter.js.map +1 -1
- package/dist/modules/storage/index.d.ts +2 -2
- package/dist/modules/storage/index.d.ts.map +1 -1
- package/dist/modules/storage/index.js +2 -5
- package/dist/modules/storage/index.js.map +1 -1
- package/dist/modules/storage/node_adapter.d.ts +3 -3
- package/dist/modules/storage/node_adapter.d.ts.map +1 -1
- package/dist/modules/storage/node_adapter.js +9 -7
- package/dist/modules/storage/node_adapter.js.map +1 -1
- package/dist/modules/storage/types.d.ts +13 -10
- package/dist/modules/storage/types.d.ts.map +1 -1
- package/dist/modules/types.d.ts +0 -2
- package/dist/modules/types.d.ts.map +1 -1
- package/dist/modules/utils/base58check.d.ts +1 -9
- package/dist/modules/utils/base58check.d.ts.map +1 -1
- package/dist/modules/utils/base58check.js +14 -16
- package/dist/modules/utils/base58check.js.map +1 -1
- package/dist/modules/utils/build_dir.d.ts +2 -5
- package/dist/modules/utils/build_dir.d.ts.map +1 -1
- package/dist/modules/utils/build_dir.js +6 -3
- package/dist/modules/utils/build_dir.js.map +1 -1
- package/dist/modules/utils/errors.d.ts +2 -0
- package/dist/modules/utils/errors.d.ts.map +1 -0
- package/dist/modules/utils/errors.js +12 -0
- package/dist/modules/utils/errors.js.map +1 -0
- package/dist/modules/utils/fs_utils.d.ts +1 -8
- package/dist/modules/utils/fs_utils.d.ts.map +1 -1
- package/dist/modules/utils/fs_utils.js +8 -3
- package/dist/modules/utils/fs_utils.js.map +1 -1
- package/dist/modules/utils/math_utils.d.ts +2 -6
- package/dist/modules/utils/math_utils.d.ts.map +1 -1
- package/dist/modules/utils/math_utils.js +6 -2
- package/dist/modules/utils/math_utils.js.map +1 -1
- package/dist/modules/validate_profiles.d.ts +1 -11
- package/dist/modules/validate_profiles.d.ts.map +1 -1
- package/dist/modules/validate_profiles.js +25 -27
- package/dist/modules/validate_profiles.js.map +1 -1
- package/dist/pm2.d.ts +7 -6
- package/dist/pm2.d.ts.map +1 -1
- package/dist/pm2.js +132 -106
- package/dist/pm2.js.map +1 -1
- package/dist/scripts/analyze-git.d.ts.map +1 -1
- package/dist/scripts/analyze-git.js +15 -11
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/analyze-orders.d.ts +146 -1
- package/dist/scripts/analyze-orders.d.ts.map +1 -1
- package/dist/scripts/analyze-orders.js +81 -105
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -1
- package/dist/scripts/diagnose-pool-history.js +9 -8
- 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 +11 -8
- package/dist/scripts/divergence-calc.js.map +1 -1
- package/dist/scripts/fix-err-message.d.ts +3 -0
- package/dist/scripts/fix-err-message.d.ts.map +1 -0
- package/dist/scripts/fix-err-message.js +198 -0
- package/dist/scripts/fix-err-message.js.map +1 -0
- package/dist/scripts/generate_lp_chart.d.ts +2 -9
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -1
- package/dist/scripts/generate_lp_chart.js +14 -10
- package/dist/scripts/generate_lp_chart.js.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.js +4 -4
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts +17 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.js +23 -20
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -1
- package/dist/scripts/migrate_bot_keys.d.ts +1 -4
- package/dist/scripts/migrate_bot_keys.d.ts.map +1 -1
- package/dist/scripts/migrate_bot_keys.js +48 -124
- package/dist/scripts/migrate_bot_keys.js.map +1 -1
- package/dist/scripts/native_release_gates.d.ts.map +1 -1
- package/dist/scripts/native_release_gates.js +18 -14
- package/dist/scripts/native_release_gates.js.map +1 -1
- package/dist/scripts/print_grid.js +1 -1
- package/dist/scripts/print_grid.js.map +1 -1
- package/dist/scripts/run-tests.js +1 -0
- package/dist/scripts/run-tests.js.map +1 -1
- package/dist/scripts/runner.d.ts +1 -11
- package/dist/scripts/runner.d.ts.map +1 -1
- package/dist/scripts/runner.js +21 -19
- package/dist/scripts/runner.js.map +1 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
- package/dist/scripts/test-credit-renewal.js +2 -1
- package/dist/scripts/test-credit-renewal.js.map +1 -1
- package/dist/scripts/update.d.ts.map +1 -1
- package/dist/scripts/update.js +85 -79
- package/dist/scripts/update.js.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 +25 -1
- package/dist/scripts/verify-browser-bundle.js.map +1 -1
- package/dist/unlock.d.ts +4 -17
- package/dist/unlock.d.ts.map +1 -1
- package/dist/unlock.js +141 -108
- package/dist/unlock.js.map +1 -1
- package/package.json +7 -2
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +0 -3
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +0 -149
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +0 -3
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +0 -387
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +0 -3
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -200
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +0 -3
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +0 -212
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +0 -31
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +0 -249
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +0 -2
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +0 -782
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_derivatives.d.ts +0 -95
- package/dist/analysis/analyze_derivatives.d.ts.map +0 -1
- package/dist/analysis/analyze_derivatives.js +0 -295
- package/dist/analysis/analyze_derivatives.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts +0 -14
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js +0 -207
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts +0 -13
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js +0 -123
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts +0 -20
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js +0 -139
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts +0 -19
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js +0 -413
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts +0 -3
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js +0 -159
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts +0 -3
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js +0 -367
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts +0 -22
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js +0 -172
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +0 -99
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +0 -804
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +0 -2
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +0 -347
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts +0 -15
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js +0 -48
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts +0 -22
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js +0 -162
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +0 -3
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js +0 -498
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +0 -546
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js +0 -427
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/derivative_chart_generator.d.ts +0 -18
- package/dist/analysis/derivative_chart_generator.d.ts.map +0 -1
- package/dist/analysis/derivative_chart_generator.js +0 -896
- package/dist/analysis/derivative_chart_generator.js.map +0 -1
- package/dist/analysis/price_sources.d.ts +0 -34
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js +0 -103
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts +0 -115
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js +0 -1247
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +0 -36
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js +0 -172
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts +0 -250
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/derivative_analyzer.js +0 -903
- package/dist/analysis/trend_detection/derivative_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +0 -6
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +0 -1450
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +0 -6
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +0 -408
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +0 -6
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +0 -345
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -130
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -38
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +0 -6
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js +0 -732
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
|
@@ -95,6 +95,39 @@
|
|
|
95
95
|
*
|
|
96
96
|
* ===============================================================================
|
|
97
97
|
*/
|
|
98
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
99
|
+
if (k2 === undefined) k2 = k;
|
|
100
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
101
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
102
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
103
|
+
}
|
|
104
|
+
Object.defineProperty(o, k2, desc);
|
|
105
|
+
}) : (function(o, m, k, k2) {
|
|
106
|
+
if (k2 === undefined) k2 = k;
|
|
107
|
+
o[k2] = m[k];
|
|
108
|
+
}));
|
|
109
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
110
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
111
|
+
}) : function(o, v) {
|
|
112
|
+
o["default"] = v;
|
|
113
|
+
});
|
|
114
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
115
|
+
var ownKeys = function(o) {
|
|
116
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
117
|
+
var ar = [];
|
|
118
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
119
|
+
return ar;
|
|
120
|
+
};
|
|
121
|
+
return ownKeys(o);
|
|
122
|
+
};
|
|
123
|
+
return function (mod) {
|
|
124
|
+
if (mod && mod.__esModule) return mod;
|
|
125
|
+
var result = {};
|
|
126
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
127
|
+
__setModuleDefault(result, mod);
|
|
128
|
+
return result;
|
|
129
|
+
};
|
|
130
|
+
})();
|
|
98
131
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
99
132
|
exports.calculateGapSlots = calculateGapSlots;
|
|
100
133
|
exports.isGridBloated = isGridBloated;
|
|
@@ -120,10 +153,10 @@ exports.getDustOrders = getDustOrders;
|
|
|
120
153
|
exports.determineOrderSideByFunds = determineOrderSideByFunds;
|
|
121
154
|
exports.calculateGeometricSizeForSpreadCorrection = calculateGeometricSizeForSpreadCorrection;
|
|
122
155
|
exports.prepareSpreadCorrectionOrders = prepareSpreadCorrectionOrders;
|
|
123
|
-
const
|
|
124
|
-
const { GRID_COMPARISON } = GRID_LIMITS;
|
|
125
|
-
const Format = require(
|
|
126
|
-
const
|
|
156
|
+
const constants_1 = require("../constants");
|
|
157
|
+
const { GRID_COMPARISON } = constants_1.GRID_LIMITS;
|
|
158
|
+
const Format = __importStar(require("./format"));
|
|
159
|
+
const asymmetric_bounds_1 = require("../../market_adapter/core/asymmetric_bounds");
|
|
127
160
|
// FIX: Extract magic numbers to named constants for maintainability
|
|
128
161
|
const GRID_CONSTANTS = {
|
|
129
162
|
RMS_PERCENTAGE_SCALE: 100, // Convert RMS percentage threshold from percent to decimal
|
|
@@ -136,12 +169,13 @@ function _snapshotFundState(manager) {
|
|
|
136
169
|
sellLocked: Number(manager.accountTotals?.sellLocked || 0),
|
|
137
170
|
};
|
|
138
171
|
}
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
172
|
+
const math_1 = require("./utils/math");
|
|
173
|
+
const order_1 = require("./utils/order");
|
|
174
|
+
const system_1 = require("./utils/system");
|
|
175
|
+
const market_adapter_whitelist_1 = require("../market_adapter_whitelist");
|
|
176
|
+
const errors_1 = require("../utils/errors");
|
|
143
177
|
function calculateGapSlots(incrementPercent, targetSpreadPercent, gridLimitsOverride) {
|
|
144
|
-
return
|
|
178
|
+
return (0, math_1.calculateGapSlots)(incrementPercent, targetSpreadPercent, gridLimitsOverride ?? constants_1.GRID_LIMITS);
|
|
145
179
|
}
|
|
146
180
|
function isGridBloated(manager, orders) {
|
|
147
181
|
const gridSize = Array.isArray(orders) ? orders.length : orders.size;
|
|
@@ -153,11 +187,11 @@ function isGridBloated(manager, orders) {
|
|
|
153
187
|
return { bloated: false };
|
|
154
188
|
const targetSpreadPct = config.targetSpreadPercent || incPct * 2;
|
|
155
189
|
const orderList = Array.isArray(orders) ? orders : Array.from(orders.values());
|
|
156
|
-
const numBuyActive = orderList.filter((o) => o.type === ORDER_TYPES.BUY &&
|
|
157
|
-
(o.state === ORDER_STATES.ACTIVE || o.state === ORDER_STATES.PARTIAL) &&
|
|
190
|
+
const numBuyActive = orderList.filter((o) => o.type === constants_1.ORDER_TYPES.BUY &&
|
|
191
|
+
(o.state === constants_1.ORDER_STATES.ACTIVE || o.state === constants_1.ORDER_STATES.PARTIAL) &&
|
|
158
192
|
o.orderId).length;
|
|
159
|
-
const numSellActive = orderList.filter((o) => o.type === ORDER_TYPES.SELL &&
|
|
160
|
-
(o.state === ORDER_STATES.ACTIVE || o.state === ORDER_STATES.PARTIAL) &&
|
|
193
|
+
const numSellActive = orderList.filter((o) => o.type === constants_1.ORDER_TYPES.SELL &&
|
|
194
|
+
(o.state === constants_1.ORDER_STATES.ACTIVE || o.state === constants_1.ORDER_STATES.PARTIAL) &&
|
|
161
195
|
o.orderId).length;
|
|
162
196
|
const placedCount = numBuyActive + numSellActive;
|
|
163
197
|
if (!placedCount)
|
|
@@ -188,7 +222,7 @@ function isGridBloated(manager, orders) {
|
|
|
188
222
|
}
|
|
189
223
|
}
|
|
190
224
|
const railEstimate = Math.max(expectedTotal, placedCount);
|
|
191
|
-
const buffer = (config.gridLimits?.MIN_SPREAD_ORDERS ?? GRID_LIMITS.MIN_SPREAD_ORDERS);
|
|
225
|
+
const buffer = (config.gridLimits?.MIN_SPREAD_ORDERS ?? constants_1.GRID_LIMITS.MIN_SPREAD_ORDERS);
|
|
192
226
|
const maxAllowed = railEstimate + gapSlots + buffer;
|
|
193
227
|
return {
|
|
194
228
|
bloated: gridSize > maxAllowed,
|
|
@@ -209,7 +243,7 @@ function isGridBloated(manager, orders) {
|
|
|
209
243
|
* @returns {{active: boolean, elapsed: number, graceMs: number}}
|
|
210
244
|
*/
|
|
211
245
|
function isGridBloatGraceActive(manager) {
|
|
212
|
-
const graceMs = Number(TIMING?.GRID_BLOAT_RESYNC_GRACE_MS) || TIMING.GRID_BLOAT_RESYNC_GRACE_MS;
|
|
246
|
+
const graceMs = Number(constants_1.TIMING?.GRID_BLOAT_RESYNC_GRACE_MS) || constants_1.TIMING.GRID_BLOAT_RESYNC_GRACE_MS;
|
|
213
247
|
if (!manager._gridBloatDetectedAt) {
|
|
214
248
|
return { active: false, elapsed: 0, graceMs };
|
|
215
249
|
}
|
|
@@ -253,7 +287,7 @@ async function _getSizingContext(manager, side, { skipRecalc = false } = {}) {
|
|
|
253
287
|
}
|
|
254
288
|
const snap = manager.getChainFundsSnapshot ? manager.getChainFundsSnapshot() : {};
|
|
255
289
|
const isBuy = side === 'buy';
|
|
256
|
-
const type = isBuy ? ORDER_TYPES.BUY : ORDER_TYPES.SELL;
|
|
290
|
+
const type = isBuy ? constants_1.ORDER_TYPES.BUY : constants_1.ORDER_TYPES.SELL;
|
|
257
291
|
// 2. Determine base budget: Always use ALLOCATED funds (respects botFunds %)
|
|
258
292
|
// This ensures the bot only "thinks" about the capital it is allowed to use.
|
|
259
293
|
let budget = isBuy ? (snap.allocatedBuy || 0) : (snap.allocatedSell || 0);
|
|
@@ -265,13 +299,13 @@ async function _getSizingContext(manager, side, { skipRecalc = false } = {}) {
|
|
|
265
299
|
const targetSell = Math.max(0, manager.config.activeOrders?.sell ?? 1);
|
|
266
300
|
const totalTarget = targetBuy + targetSell;
|
|
267
301
|
const isBtsSide = (isBuy && manager.config.assetB === 'BTS') || (!isBuy && manager.config.assetA === 'BTS');
|
|
268
|
-
const formulaBudget = calculateOrderCreationFees(manager.config.assetA, manager.config.assetB, totalTarget, manager.config?.feeParams?.BTS_RESERVATION_MULTIPLIER);
|
|
269
|
-
budget = adjustBudgetForBtsFees(budget, isBtsSide, formulaBudget, manager.config.min_BTS_value || 0, Format.toFiniteNumber(manager.funds?.btsBalance?.free, 0), Format.toFiniteNumber(isBuy ? (snap.allocatedBuy || 0) : (snap.allocatedSell || 0)), Format.toFiniteNumber(snap.allocatedBuy || 0)
|
|
302
|
+
const formulaBudget = (0, math_1.calculateOrderCreationFees)(manager.config.assetA, manager.config.assetB, totalTarget, manager.config?.feeParams?.BTS_RESERVATION_MULTIPLIER);
|
|
303
|
+
budget = (0, order_1.adjustBudgetForBtsFees)(budget, isBtsSide, formulaBudget, manager.config.min_BTS_value || 0, Format.toFiniteNumber(manager.funds?.btsBalance?.free, 0), Format.toFiniteNumber(isBuy ? (snap.allocatedBuy || 0) : (snap.allocatedSell || 0)), Format.toFiniteNumber(snap.allocatedBuy || 0)
|
|
270
304
|
+ Format.toFiniteNumber(snap.allocatedSell || 0));
|
|
271
305
|
}
|
|
272
306
|
return {
|
|
273
307
|
budget,
|
|
274
|
-
precision: getPrecisionByOrderType(manager.assets, type),
|
|
308
|
+
precision: (0, math_1.getPrecisionByOrderType)(manager.assets, type),
|
|
275
309
|
config: manager.config
|
|
276
310
|
};
|
|
277
311
|
}
|
|
@@ -401,7 +435,7 @@ function createOrderGrid(config) {
|
|
|
401
435
|
// Determine the boundary and assign roles (BUY/SPREAD/SELL) to each slot.
|
|
402
436
|
//
|
|
403
437
|
// STRATEGY: Center the spread gap around startPrice
|
|
404
|
-
const boundaryIdx = calculateIdealBoundary(priceLevels.map(p => ({ price: p })), startPrice, gapSlots);
|
|
438
|
+
const boundaryIdx = (0, order_1.calculateIdealBoundary)(priceLevels.map((p) => ({ price: p })), startPrice, gapSlots);
|
|
405
439
|
// ================================================================================
|
|
406
440
|
// STEP 4: CREATE ORDER OBJECTS
|
|
407
441
|
// ================================================================================
|
|
@@ -410,12 +444,12 @@ function createOrderGrid(config) {
|
|
|
410
444
|
id: `slot-${i}`,
|
|
411
445
|
price,
|
|
412
446
|
type: null, // assigned below
|
|
413
|
-
state: ORDER_STATES.VIRTUAL,
|
|
447
|
+
state: constants_1.ORDER_STATES.VIRTUAL,
|
|
414
448
|
size: 0
|
|
415
449
|
}));
|
|
416
|
-
const updatedOrders = assignGridRoles(orders, boundaryIdx, gapSlots, ORDER_TYPES, ORDER_STATES);
|
|
417
|
-
const buyCount = updatedOrders.filter(o => o.type === ORDER_TYPES.BUY).length;
|
|
418
|
-
const sellCount = updatedOrders.filter(o => o.type === ORDER_TYPES.SELL).length;
|
|
450
|
+
const updatedOrders = (0, order_1.assignGridRoles)(orders, boundaryIdx, gapSlots, constants_1.ORDER_TYPES, constants_1.ORDER_STATES);
|
|
451
|
+
const buyCount = updatedOrders.filter((o) => o.type === constants_1.ORDER_TYPES.BUY).length;
|
|
452
|
+
const sellCount = updatedOrders.filter((o) => o.type === constants_1.ORDER_TYPES.SELL).length;
|
|
419
453
|
if (buyCount === 0 || sellCount === 0) {
|
|
420
454
|
throw new Error(`Grid generation produced an imbalanced rail (buy=${buyCount}, sell=${sellCount}) for ` +
|
|
421
455
|
`startPrice=${startPrice}, bounds=[${minPrice}, ${maxPrice}], incrementPercent=${incrementPercent}, ` +
|
|
@@ -468,7 +502,7 @@ async function loadGrid(manager, grid, boundaryIdx = null) {
|
|
|
468
502
|
await manager._initializeAssets();
|
|
469
503
|
}
|
|
470
504
|
catch (e) {
|
|
471
|
-
manager.logger?.log?.(`Asset initialization failed during grid load: ${e
|
|
505
|
+
manager.logger?.log?.(`Asset initialization failed during grid load: ${(0, errors_1.getErrorMessage)(e)}`, 'warn');
|
|
472
506
|
}
|
|
473
507
|
// RC-2: Use logic helper
|
|
474
508
|
_clearOrderCachesLogic(manager);
|
|
@@ -491,12 +525,12 @@ async function loadGrid(manager, grid, boundaryIdx = null) {
|
|
|
491
525
|
const sellStartIdx = boundaryIdx + gapSlots + 1;
|
|
492
526
|
let reassignCount = 0;
|
|
493
527
|
grid = grid.map((slot, i) => {
|
|
494
|
-
if (slot.state === ORDER_STATES.VIRTUAL && !slot.orderId) {
|
|
528
|
+
if (slot.state === constants_1.ORDER_STATES.VIRTUAL && !slot.orderId) {
|
|
495
529
|
const correctType = (i <= buyEndIdx)
|
|
496
|
-
? ORDER_TYPES.BUY
|
|
530
|
+
? constants_1.ORDER_TYPES.BUY
|
|
497
531
|
: (i >= sellStartIdx)
|
|
498
|
-
? ORDER_TYPES.SELL
|
|
499
|
-
: ORDER_TYPES.SPREAD;
|
|
532
|
+
? constants_1.ORDER_TYPES.SELL
|
|
533
|
+
: constants_1.ORDER_TYPES.SPREAD;
|
|
500
534
|
if (slot.type !== correctType) {
|
|
501
535
|
reassignCount++;
|
|
502
536
|
return { ...slot, type: correctType };
|
|
@@ -525,7 +559,7 @@ async function loadGrid(manager, grid, boundaryIdx = null) {
|
|
|
525
559
|
manager._gridBloatDetectedAt = Date.now();
|
|
526
560
|
if (typeof manager.requestStructuralGridResync === 'function') {
|
|
527
561
|
manager.requestStructuralGridResync('grid-bloat-detected', { reason: `Grid size ${d.gridSize} exceeds maximum ${d.maxAllowed}` }).catch((err) => {
|
|
528
|
-
manager.logger?.log?.(`[GRID-BLOAT] Structural resync request failed: ${err
|
|
562
|
+
manager.logger?.log?.(`[GRID-BLOAT] Structural resync request failed: ${(0, errors_1.getErrorMessage)(err)}`, 'error');
|
|
529
563
|
});
|
|
530
564
|
}
|
|
531
565
|
}
|
|
@@ -536,13 +570,13 @@ async function loadGrid(manager, grid, boundaryIdx = null) {
|
|
|
536
570
|
// RC-2: Use applyOrderUpdate (PRIVATE/UNLOCKED)
|
|
537
571
|
for (const order of grid) {
|
|
538
572
|
let currentOrder = order;
|
|
539
|
-
if (isPhantomOrder(order)) {
|
|
573
|
+
if ((0, order_1.isPhantomOrder)(order)) {
|
|
540
574
|
manager.logger?.log?.(`Sanitizing corrupted order ${order.id}: ACTIVE/PARTIAL without orderId -> VIRTUAL`, 'warn');
|
|
541
|
-
currentOrder = { ...order, state: ORDER_STATES.VIRTUAL };
|
|
575
|
+
currentOrder = { ...order, state: constants_1.ORDER_STATES.VIRTUAL };
|
|
542
576
|
}
|
|
543
577
|
await manager._applyOrderUpdate(currentOrder, 'grid-load', { skipAccounting: true });
|
|
544
578
|
}
|
|
545
|
-
const spreadCount = grid.filter(o => o.type === ORDER_TYPES.SPREAD).length;
|
|
579
|
+
const spreadCount = grid.filter((o) => o.type === constants_1.ORDER_TYPES.SPREAD).length;
|
|
546
580
|
manager.targetSpreadCount = spreadCount;
|
|
547
581
|
manager.currentSpreadCount = spreadCount;
|
|
548
582
|
}
|
|
@@ -576,7 +610,7 @@ async function initializeGrid(manager) {
|
|
|
576
610
|
if (typeof mpRaw !== 'number' || isNaN(mpRaw)) {
|
|
577
611
|
try {
|
|
578
612
|
const { BitShares } = require('../bitshares_client');
|
|
579
|
-
const derived = await derivePrice(BitShares, manager.config.assetA, manager.config.assetB, manager.config.priceMode || 'auto');
|
|
613
|
+
const derived = await (0, system_1.derivePrice)(BitShares, manager.config.assetA, manager.config.assetB, manager.config.priceMode || 'auto');
|
|
580
614
|
if (derived) {
|
|
581
615
|
manager.logger?.log?.(`[DIAGNOSTIC] initializeGrid: Derived new startPrice=${derived.toFixed(8)} (mode=${manager.config.priceMode || 'auto'})`, 'info');
|
|
582
616
|
manager.config.startPrice = Number(derived);
|
|
@@ -586,11 +620,10 @@ async function initializeGrid(manager) {
|
|
|
586
620
|
}
|
|
587
621
|
}
|
|
588
622
|
catch (err) {
|
|
589
|
-
manager.logger?.log?.(`Failed to derive market price: ${err
|
|
623
|
+
manager.logger?.log?.(`Failed to derive market price: ${(0, errors_1.getErrorMessage)(err)}`, 'warn');
|
|
590
624
|
throw err; // Re-throw to prevent "pool" string reaching numeric math
|
|
591
625
|
}
|
|
592
626
|
}
|
|
593
|
-
const configuredStartPrice = manager.config.startPrice;
|
|
594
627
|
const configuredMinPrice = manager.config.minPrice;
|
|
595
628
|
const configuredMaxPrice = manager.config.maxPrice;
|
|
596
629
|
const mp = Number(manager.config.startPrice);
|
|
@@ -603,7 +636,7 @@ async function initializeGrid(manager) {
|
|
|
603
636
|
let gp = mp;
|
|
604
637
|
let gpSource = 'startPrice';
|
|
605
638
|
let amaSnapshot = null;
|
|
606
|
-
const whitelistFlags = getWhitelistFlags(manager.config.botKey);
|
|
639
|
+
const whitelistFlags = (0, market_adapter_whitelist_1.getWhitelistFlags)(manager.config.botKey);
|
|
607
640
|
const isGridRangeScalingWhitelisted = whitelistFlags.asymmetricBounds === true;
|
|
608
641
|
let gridPriceOffsetPct = 0;
|
|
609
642
|
const gpRaw = manager.config.gridPrice;
|
|
@@ -616,7 +649,7 @@ async function initializeGrid(manager) {
|
|
|
616
649
|
else if (gpMode === 'pool' || gpMode === 'book') {
|
|
617
650
|
try {
|
|
618
651
|
const { BitShares } = require('../bitshares_client');
|
|
619
|
-
const derived = await derivePrice(BitShares, manager.config.assetA, manager.config.assetB, gpMode);
|
|
652
|
+
const derived = await (0, system_1.derivePrice)(BitShares, manager.config.assetA, manager.config.assetB, gpMode);
|
|
620
653
|
if (derived) {
|
|
621
654
|
gp = Number(derived);
|
|
622
655
|
gpSource = gpMode;
|
|
@@ -627,12 +660,12 @@ async function initializeGrid(manager) {
|
|
|
627
660
|
}
|
|
628
661
|
}
|
|
629
662
|
catch (err) {
|
|
630
|
-
manager.logger?.log?.(`initializeGrid: ${gpMode} gridPrice derivation failed: ${err
|
|
663
|
+
manager.logger?.log?.(`initializeGrid: ${gpMode} gridPrice derivation failed: ${(0, errors_1.getErrorMessage)(err)}`, 'warn');
|
|
631
664
|
}
|
|
632
665
|
}
|
|
633
666
|
else if (/^ama(?:[1-4])?$/.test(gpMode || '')) {
|
|
634
|
-
amaSnapshot = loadAmaCenterSnapshot(manager.config.botKey);
|
|
635
|
-
const amaCenter = amaSnapshot?.gridCenterPrice ?? loadAmaCenterPrice(manager.config.botKey);
|
|
667
|
+
amaSnapshot = (0, system_1.loadAmaCenterSnapshot)(manager.config.botKey);
|
|
668
|
+
const amaCenter = amaSnapshot?.gridCenterPrice ?? (0, system_1.loadAmaCenterPrice)(manager.config.botKey);
|
|
636
669
|
if (Number.isFinite(amaCenter) && amaCenter > 0) {
|
|
637
670
|
gp = amaCenter;
|
|
638
671
|
gpSource = 'ama';
|
|
@@ -647,8 +680,8 @@ async function initializeGrid(manager) {
|
|
|
647
680
|
manager.logger?.log?.(`initializeGrid: AMA center unavailable for gridPrice, falling back to startPrice`, 'warn');
|
|
648
681
|
}
|
|
649
682
|
}
|
|
650
|
-
const minP = resolveConfiguredPriceBound(manager.config.minPrice, DEFAULT_CONFIG.minPrice, gp, 'min');
|
|
651
|
-
const maxP = resolveConfiguredPriceBound(manager.config.maxPrice, DEFAULT_CONFIG.maxPrice, gp, 'max');
|
|
683
|
+
const minP = (0, order_1.resolveConfiguredPriceBound)(manager.config.minPrice, constants_1.DEFAULT_CONFIG.minPrice, gp, 'min');
|
|
684
|
+
const maxP = (0, order_1.resolveConfiguredPriceBound)(manager.config.maxPrice, constants_1.DEFAULT_CONFIG.maxPrice, gp, 'max');
|
|
652
685
|
// Asymmetric bound adjustment: widen the bound in the AMA trend direction
|
|
653
686
|
// and tighten the opposite side, giving the grid more room when the center
|
|
654
687
|
// trails price. Uses slope data from the dynamicgrid.json snapshot.
|
|
@@ -665,8 +698,8 @@ async function initializeGrid(manager) {
|
|
|
665
698
|
? amaSnapshot.asymmetricBounds
|
|
666
699
|
: null;
|
|
667
700
|
if (dw) {
|
|
668
|
-
const maxAsymmetryFactor = resolveMaxAsymmetryFactor(manager.config.asymmetricBounds?.maxAsymmetryFactor, dw?.maxAsymmetryFactor, MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MAX_ASYMMETRY_FACTOR);
|
|
669
|
-
const adjustment = applyAsymmetricBounds({
|
|
701
|
+
const maxAsymmetryFactor = (0, asymmetric_bounds_1.resolveMaxAsymmetryFactor)(manager.config.asymmetricBounds?.maxAsymmetryFactor, dw?.maxAsymmetryFactor, constants_1.MARKET_ADAPTER.ASYMMETRIC_BOUNDS_MAX_ASYMMETRY_FACTOR);
|
|
702
|
+
const adjustment = (0, asymmetric_bounds_1.applyAsymmetricBounds)({
|
|
670
703
|
centerPrice: gp,
|
|
671
704
|
minPrice: minP,
|
|
672
705
|
maxPrice: maxP,
|
|
@@ -680,11 +713,11 @@ async function initializeGrid(manager) {
|
|
|
680
713
|
resolvedMaxP = adjustment.resolvedMaxPrice;
|
|
681
714
|
rangeScalingFactor = Number(adjustment.appliedAsymmetryFactor);
|
|
682
715
|
manager.logger?.log?.(`[BOUND-ASYMMETRY] trend=${dw.trend} slopeOffset=${dw.slopeOffset.toFixed(4)} `
|
|
683
|
-
+ `raw=${(adjustment.rawAsymmetryFactor * 100).toFixed(1)}% `
|
|
684
|
-
+ `cap=${(maxAsymmetryFactor * 100).toFixed(0)}% `
|
|
685
|
-
+ `asymmetry=${(adjustment.appliedAsymmetryFactor * 100).toFixed(1)}% `
|
|
686
|
-
+ `min ${minP.toFixed(8)}→${resolvedMinP.toFixed(8)} `
|
|
687
|
-
+ `max ${maxP.toFixed(8)}→${resolvedMaxP.toFixed(8)}`, 'info');
|
|
716
|
+
+ `raw=${((adjustment.rawAsymmetryFactor ?? 0) * 100).toFixed(1)}% `
|
|
717
|
+
+ `cap=${((maxAsymmetryFactor ?? 0) * 100).toFixed(0)}% `
|
|
718
|
+
+ `asymmetry=${((adjustment.appliedAsymmetryFactor ?? 0) * 100).toFixed(1)}% `
|
|
719
|
+
+ `min ${(minP ?? 0).toFixed(8)}→${(resolvedMinP ?? 0).toFixed(8)} `
|
|
720
|
+
+ `max ${(maxP ?? 0).toFixed(8)}→${(resolvedMaxP ?? 0).toFixed(8)}`, 'info');
|
|
688
721
|
}
|
|
689
722
|
}
|
|
690
723
|
else if (rootBounds && Number.isFinite(rootBounds.appliedAsymmetryFactor)
|
|
@@ -702,8 +735,8 @@ async function initializeGrid(manager) {
|
|
|
702
735
|
rangeScalingFactor = asymmetry;
|
|
703
736
|
manager.logger?.log?.(`[BOUND-ASYMMETRY] trend=${rootTrend} `
|
|
704
737
|
+ `asymmetry=${(asymmetry * 100).toFixed(1)}% `
|
|
705
|
-
+ `(root-level) min ${minP.toFixed(8)}→${resolvedMinP.toFixed(8)} `
|
|
706
|
-
+ `max ${maxP.toFixed(8)}→${resolvedMaxP.toFixed(8)}`, 'info');
|
|
738
|
+
+ `(root-level) min ${(minP ?? 0).toFixed(8)}→${(resolvedMinP ?? 0).toFixed(8)} `
|
|
739
|
+
+ `max ${(maxP ?? 0).toFixed(8)}→${(resolvedMaxP ?? 0).toFixed(8)}`, 'info');
|
|
707
740
|
}
|
|
708
741
|
}
|
|
709
742
|
let gridStartPrice = mp;
|
|
@@ -715,14 +748,16 @@ async function initializeGrid(manager) {
|
|
|
715
748
|
gridStartPrice = adjustedMarketPrice;
|
|
716
749
|
offsetAdjustedStartPrice = adjustedMarketPrice;
|
|
717
750
|
}
|
|
718
|
-
|
|
719
|
-
|
|
751
|
+
const rMinP = resolvedMinP ?? 0;
|
|
752
|
+
const rMaxP = resolvedMaxP ?? 0;
|
|
753
|
+
if (!(gridStartPrice >= rMinP && gridStartPrice <= rMaxP)) {
|
|
754
|
+
if (Number.isFinite(gp) && gp > 0 && gp >= rMinP && gp <= rMaxP) {
|
|
720
755
|
gridStartPrice = gp;
|
|
721
|
-
manager.logger?.log?.(`initializeGrid: startPrice (${mp}) outside bounds [${
|
|
756
|
+
manager.logger?.log?.(`initializeGrid: startPrice (${mp}) outside bounds [${rMinP}, ${rMaxP}]; using gridPrice center ${gp}`, 'warn');
|
|
722
757
|
}
|
|
723
758
|
else {
|
|
724
|
-
const clamped = Math.min(
|
|
725
|
-
manager.logger?.log?.(`initializeGrid: startPrice (${mp}) outside bounds [${
|
|
759
|
+
const clamped = Math.min(rMaxP, Math.max(rMinP, gridStartPrice));
|
|
760
|
+
manager.logger?.log?.(`initializeGrid: startPrice (${mp}) outside bounds [${rMinP}, ${rMaxP}]; clamping to ${clamped}`, 'warn');
|
|
726
761
|
gridStartPrice = clamped;
|
|
727
762
|
}
|
|
728
763
|
}
|
|
@@ -740,14 +775,14 @@ async function initializeGrid(manager) {
|
|
|
740
775
|
// Ensure percentage-based funds are resolved before sizing
|
|
741
776
|
try {
|
|
742
777
|
if (manager.accountId && !manager.accountTotals) {
|
|
743
|
-
await manager.waitForAccountTotals(TIMING.ACCOUNT_TOTALS_TIMEOUT_MS);
|
|
778
|
+
await manager.waitForAccountTotals(constants_1.TIMING.ACCOUNT_TOTALS_TIMEOUT_MS);
|
|
744
779
|
}
|
|
745
780
|
}
|
|
746
781
|
catch (e) {
|
|
747
|
-
manager.logger?.log?.(`Failed to load account totals: ${e
|
|
782
|
+
manager.logger?.log?.(`Failed to load account totals: ${(0, errors_1.getErrorMessage)(e)}`, 'warn');
|
|
748
783
|
// FIX: Add error handling - cannot proceed with grid initialization without account totals
|
|
749
784
|
// Continuing would create grid with 0 fund allocation, rendering it non-functional
|
|
750
|
-
throw new Error(`Cannot initialize grid without account totals: ${e
|
|
785
|
+
throw new Error(`Cannot initialize grid without account totals: ${(0, errors_1.getErrorMessage)(e)}`);
|
|
751
786
|
}
|
|
752
787
|
const { orders, boundaryIdx, initialSpreadCount } = createOrderGrid({
|
|
753
788
|
...manager.config,
|
|
@@ -765,13 +800,13 @@ async function initializeGrid(manager) {
|
|
|
765
800
|
manager.notifyBoundaryUpdate(boundaryIdx);
|
|
766
801
|
}
|
|
767
802
|
catch (err) {
|
|
768
|
-
manager.logger?.log?.(`Error notifying boundary update: ${err
|
|
803
|
+
manager.logger?.log?.(`Error notifying boundary update: ${(0, errors_1.getErrorMessage)(err)}`, 'warn');
|
|
769
804
|
}
|
|
770
805
|
}
|
|
771
806
|
}
|
|
772
|
-
const minSellSize = getMinAbsoluteOrderSize(ORDER_TYPES.SELL, manager.assets);
|
|
773
|
-
const minBuySize = getMinAbsoluteOrderSize(ORDER_TYPES.BUY, manager.assets);
|
|
774
|
-
const { A: precA, B: precB } = getPrecisionsForManager(manager.assets);
|
|
807
|
+
const minSellSize = (0, math_1.getMinAbsoluteOrderSize)(constants_1.ORDER_TYPES.SELL, manager.assets);
|
|
808
|
+
const minBuySize = (0, math_1.getMinAbsoluteOrderSize)(constants_1.ORDER_TYPES.BUY, manager.assets);
|
|
809
|
+
const { A: precA, B: precB } = (0, math_1.getPrecisionsForManager)(manager.assets);
|
|
775
810
|
// Use centralized sizing context for both sides.
|
|
776
811
|
// Resolve funds once upfront so both contexts share the same snapshot,
|
|
777
812
|
// avoiding a redundant recalculateFunds inside the second _getSizingContext call.
|
|
@@ -780,17 +815,17 @@ async function initializeGrid(manager) {
|
|
|
780
815
|
const buyCtx = await _getSizingContext(manager, 'buy', { skipRecalc: true });
|
|
781
816
|
if (!sellCtx || !buyCtx)
|
|
782
817
|
throw new Error('Failed to retrieve sizing context for grid initialization');
|
|
783
|
-
let sizedOrders = calculateOrderSizes(orders, manager.config, sellCtx.budget, buyCtx.budget, minSellSize, minBuySize, precA, precB);
|
|
818
|
+
let sizedOrders = (0, math_1.calculateOrderSizes)(orders, manager.config, sellCtx.budget, buyCtx.budget, minSellSize, minBuySize, precA, precB);
|
|
784
819
|
// Verification of sizes
|
|
785
|
-
const sells = filterOrdersByType(sizedOrders, ORDER_TYPES.SELL).map(o => Number(o.size || 0));
|
|
786
|
-
const buys = filterOrdersByType(sizedOrders, ORDER_TYPES.BUY).map(o => Number(o.size || 0));
|
|
787
|
-
if (checkSizesBeforeMinimum(sells, minSellSize, precA) || checkSizesBeforeMinimum(buys, minBuySize, precB)) {
|
|
820
|
+
const sells = (0, order_1.filterOrdersByType)(sizedOrders, constants_1.ORDER_TYPES.SELL).map((o) => Number(o.size || 0));
|
|
821
|
+
const buys = (0, order_1.filterOrdersByType)(sizedOrders, constants_1.ORDER_TYPES.BUY).map((o) => Number(o.size || 0));
|
|
822
|
+
if ((0, order_1.checkSizesBeforeMinimum)(sells, minSellSize, precA) || (0, order_1.checkSizesBeforeMinimum)(buys, minBuySize, precB)) {
|
|
788
823
|
throw new Error('Calculated orders fall below minimum allowable size.');
|
|
789
824
|
}
|
|
790
825
|
// Check for warning if orders are near minimal size (regression fix)
|
|
791
|
-
const warningSellSize = minSellSize > 0 ? getMinAbsoluteOrderSize(ORDER_TYPES.SELL, manager.assets, 100) : 0;
|
|
792
|
-
const warningBuySize = minBuySize > 0 ? getMinAbsoluteOrderSize(ORDER_TYPES.BUY, manager.assets, 100) : 0;
|
|
793
|
-
if (checkSizeThreshold(sells, warningSellSize, precA, false) || checkSizeThreshold(buys, warningBuySize, precB, false)) {
|
|
826
|
+
const warningSellSize = minSellSize > 0 ? (0, math_1.getMinAbsoluteOrderSize)(constants_1.ORDER_TYPES.SELL, manager.assets, 100) : 0;
|
|
827
|
+
const warningBuySize = minBuySize > 0 ? (0, math_1.getMinAbsoluteOrderSize)(constants_1.ORDER_TYPES.BUY, manager.assets, 100) : 0;
|
|
828
|
+
if ((0, order_1.checkSizeThreshold)(sells, warningSellSize, precA, false) || (0, order_1.checkSizeThreshold)(buys, warningBuySize, precB, false)) {
|
|
794
829
|
manager.logger?.log?.("WARNING: Order grid contains orders near minimum size. To ensure the bot runs properly, consider increasing the funds of your bot.", "warn");
|
|
795
830
|
}
|
|
796
831
|
// RC-2: Wrap atomic changes in grid lock
|
|
@@ -837,12 +872,25 @@ async function recalculateGrid(manager, opts) {
|
|
|
837
872
|
manager.logger?.log?.('Starting full resync...', 'info');
|
|
838
873
|
await manager._initializeAssets();
|
|
839
874
|
await manager.fetchAccountTotals();
|
|
840
|
-
const
|
|
875
|
+
const READ_OPEN_ORDERS_TIMEOUT_MS = 30000;
|
|
876
|
+
let _readOpenOrdersTimer;
|
|
877
|
+
let chainOpenOrders;
|
|
878
|
+
try {
|
|
879
|
+
chainOpenOrders = await Promise.race([
|
|
880
|
+
readOpenOrdersFn(),
|
|
881
|
+
new Promise((_, reject) => {
|
|
882
|
+
_readOpenOrdersTimer = setTimeout(() => reject(new Error('readOpenOrders timeout')), READ_OPEN_ORDERS_TIMEOUT_MS);
|
|
883
|
+
})
|
|
884
|
+
]);
|
|
885
|
+
}
|
|
886
|
+
finally {
|
|
887
|
+
clearTimeout(_readOpenOrdersTimer);
|
|
888
|
+
}
|
|
841
889
|
if (!Array.isArray(chainOpenOrders))
|
|
842
890
|
return;
|
|
843
891
|
// CRITICAL: Filter out PARTIAL orders before synchronizing - they're from old grid
|
|
844
892
|
// and shouldn't be part of the fresh regenerated grid structure
|
|
845
|
-
const activeOrders = chainOpenOrders.filter(o => o.state !== ORDER_STATES.PARTIAL);
|
|
893
|
+
const activeOrders = chainOpenOrders.filter((o) => o.state !== constants_1.ORDER_STATES.PARTIAL);
|
|
846
894
|
await manager.syncFromOpenOrders(activeOrders, { skipAccounting: true });
|
|
847
895
|
manager.resetFunds();
|
|
848
896
|
await manager.persistGrid();
|
|
@@ -853,8 +901,8 @@ async function recalculateGrid(manager, opts) {
|
|
|
853
901
|
await reconcileGridOrders({ manager, config: manager.config, account, privateKey, chainOrders, chainOpenOrders });
|
|
854
902
|
}
|
|
855
903
|
catch (err) {
|
|
856
|
-
manager.logger?.log?.(`Error during startup order reconciliation: ${err
|
|
857
|
-
throw new Error(`Grid recalculation failed during order reconciliation: ${err
|
|
904
|
+
manager.logger?.log?.(`Error during startup order reconciliation: ${(0, errors_1.getErrorMessage)(err)}`, 'error');
|
|
905
|
+
throw new Error(`Grid recalculation failed during order reconciliation: ${(0, errors_1.getErrorMessage)(err)}`);
|
|
858
906
|
}
|
|
859
907
|
// FIX: Use consistent optional chaining pattern for logger calls
|
|
860
908
|
manager.logger?.log?.('Full resync complete.', 'info');
|
|
@@ -876,13 +924,13 @@ function checkAndUpdateGridIfNeeded(manager) {
|
|
|
876
924
|
const gridSell = Number(manager.funds?.total?.grid?.sell || 0);
|
|
877
925
|
const result = { buyUpdated: false, sellUpdated: false };
|
|
878
926
|
const sides = [
|
|
879
|
-
{ name: 'buy', grid: gridBuy, orderType: ORDER_TYPES.BUY },
|
|
880
|
-
{ name: 'sell', grid: gridSell, orderType: ORDER_TYPES.SELL }
|
|
927
|
+
{ name: 'buy', grid: gridBuy, orderType: constants_1.ORDER_TYPES.BUY },
|
|
928
|
+
{ name: 'sell', grid: gridSell, orderType: constants_1.ORDER_TYPES.SELL }
|
|
881
929
|
];
|
|
882
930
|
for (const s of sides) {
|
|
883
931
|
if (s.grid <= 0)
|
|
884
932
|
continue;
|
|
885
|
-
const availableFunds = calculateAvailableFundsValue(s.name, manager.accountTotals, manager.funds, manager.config.assetA, manager.config.assetB, manager.config.activeOrders, manager.config.min_BTS_value, manager.config.feeParams ?? null);
|
|
933
|
+
const availableFunds = (0, math_1.calculateAvailableFundsValue)(s.name, manager.accountTotals, manager.funds, manager.config.assetA, manager.config.assetB, manager.config.activeOrders, manager.config.min_BTS_value, manager.config.feeParams ?? null);
|
|
886
934
|
// Denominator: side's allocated capital (or chain total fallback).
|
|
887
935
|
const allocated = s.name === 'buy' ? chainSnap.allocatedBuy : chainSnap.allocatedSell;
|
|
888
936
|
const denominator = (allocated > 0) ? allocated : (s.grid + availableFunds);
|
|
@@ -961,7 +1009,7 @@ async function _recalculateGridOrderSizesFromBlockchain(manager, orderType, opti
|
|
|
961
1009
|
return options?.workingGrid ? { actions: [], changed: false } : undefined;
|
|
962
1010
|
const workingGrid = options?.workingGrid || null;
|
|
963
1011
|
const collectActions = !!workingGrid;
|
|
964
|
-
const isBuy = orderType === ORDER_TYPES.BUY;
|
|
1012
|
+
const isBuy = orderType === constants_1.ORDER_TYPES.BUY;
|
|
965
1013
|
const sideName = isBuy ? 'buy' : 'sell';
|
|
966
1014
|
// Use centralized sizing context (respects botFunds % allocation)
|
|
967
1015
|
const ctx = await _getSizingContext(manager, sideName);
|
|
@@ -971,12 +1019,12 @@ async function _recalculateGridOrderSizesFromBlockchain(manager, orderType, opti
|
|
|
971
1019
|
// SELL: sorted ASC (Market to Edge)
|
|
972
1020
|
// BUY: sorted ASC (Edge to Market)
|
|
973
1021
|
const allSideSlots = Array.from(manager.orders.values())
|
|
974
|
-
.filter(o => o.type === orderType)
|
|
1022
|
+
.filter((o) => o.type === orderType)
|
|
975
1023
|
.sort((a, b) => a.price - b.price);
|
|
976
1024
|
if (allSideSlots.length === 0)
|
|
977
1025
|
return collectActions ? { actions: [], changed: false } : undefined;
|
|
978
1026
|
// Calculate geometric sizes for the ENTIRE rail
|
|
979
|
-
const newSizes = calculateRotationOrderSizes(ctx.budget, 0, allSideSlots.length, orderType, manager.config, 0, ctx.precision);
|
|
1027
|
+
const newSizes = (0, math_1.calculateRotationOrderSizes)(ctx.budget, 0, allSideSlots.length, orderType, manager.config, 0, ctx.precision);
|
|
980
1028
|
const actions = [];
|
|
981
1029
|
let changed = false;
|
|
982
1030
|
const freeKey = isBuy ? 'buyFree' : 'sellFree';
|
|
@@ -995,7 +1043,7 @@ async function _recalculateGridOrderSizesFromBlockchain(manager, orderType, opti
|
|
|
995
1043
|
// NOTE: BTS update fees are paid from BTS balance (separate from asset balance),
|
|
996
1044
|
// so they don't affect this asset-side size cap. Fee budgets are tracked in
|
|
997
1045
|
// funds.btsFeesOwed and reserved separately via btsFeesReservation.
|
|
998
|
-
const isCommitted = isOrderOnChain(slot);
|
|
1046
|
+
const isCommitted = (0, order_1.isOrderOnChain)(slot);
|
|
999
1047
|
if (isCommitted) {
|
|
1000
1048
|
const currentSize = Number(slot.size || 0);
|
|
1001
1049
|
const delta = newSize - currentSize;
|
|
@@ -1015,8 +1063,8 @@ async function _recalculateGridOrderSizesFromBlockchain(manager, orderType, opti
|
|
|
1015
1063
|
}
|
|
1016
1064
|
}
|
|
1017
1065
|
// Use integer comparison to avoid redundant updates from float noise
|
|
1018
|
-
const currentSizeInt = floatToBlockchainInt(slot.size || 0, ctx.precision);
|
|
1019
|
-
const newSizeInt = floatToBlockchainInt(newSize, ctx.precision);
|
|
1066
|
+
const currentSizeInt = (0, math_1.floatToBlockchainInt)(slot.size || 0, ctx.precision);
|
|
1067
|
+
const newSizeInt = (0, math_1.floatToBlockchainInt)(newSize, ctx.precision);
|
|
1020
1068
|
if (slot.size === undefined || currentSizeInt !== newSizeInt) {
|
|
1021
1069
|
changed = true;
|
|
1022
1070
|
if (collectActions) {
|
|
@@ -1024,9 +1072,9 @@ async function _recalculateGridOrderSizesFromBlockchain(manager, orderType, opti
|
|
|
1024
1072
|
...slot,
|
|
1025
1073
|
size: newSize
|
|
1026
1074
|
});
|
|
1027
|
-
if (isCommitted && hasOnChainId(slot)) {
|
|
1075
|
+
if (isCommitted && (0, order_1.hasOnChainId)(slot)) {
|
|
1028
1076
|
actions.push({
|
|
1029
|
-
type: COW_ACTIONS.UPDATE,
|
|
1077
|
+
type: constants_1.COW_ACTIONS.UPDATE,
|
|
1030
1078
|
id: slot.id,
|
|
1031
1079
|
orderId: slot.orderId,
|
|
1032
1080
|
newGridId: slot.id,
|
|
@@ -1083,13 +1131,13 @@ async function updateGridFromBlockchainSnapshot(manager, orderType = 'both', fro
|
|
|
1083
1131
|
const allActions = [];
|
|
1084
1132
|
let hasWorkingChanges = false;
|
|
1085
1133
|
// Calculate size updates for each side (via existing sizing function in COW mode)
|
|
1086
|
-
if (orderType === ORDER_TYPES.BUY || orderType === 'both') {
|
|
1087
|
-
const buyResult = await _recalculateGridOrderSizesFromBlockchain(manager, ORDER_TYPES.BUY, { workingGrid });
|
|
1134
|
+
if (orderType === constants_1.ORDER_TYPES.BUY || orderType === 'both') {
|
|
1135
|
+
const buyResult = await _recalculateGridOrderSizesFromBlockchain(manager, constants_1.ORDER_TYPES.BUY, { workingGrid });
|
|
1088
1136
|
allActions.push(...buyResult.actions);
|
|
1089
1137
|
hasWorkingChanges = hasWorkingChanges || buyResult.changed;
|
|
1090
1138
|
}
|
|
1091
|
-
if (orderType === ORDER_TYPES.SELL || orderType === 'both') {
|
|
1092
|
-
const sellResult = await _recalculateGridOrderSizesFromBlockchain(manager, ORDER_TYPES.SELL, { workingGrid });
|
|
1139
|
+
if (orderType === constants_1.ORDER_TYPES.SELL || orderType === 'both') {
|
|
1140
|
+
const sellResult = await _recalculateGridOrderSizesFromBlockchain(manager, constants_1.ORDER_TYPES.SELL, { workingGrid });
|
|
1093
1141
|
allActions.push(...sellResult.actions);
|
|
1094
1142
|
hasWorkingChanges = hasWorkingChanges || sellResult.changed;
|
|
1095
1143
|
}
|
|
@@ -1100,9 +1148,9 @@ async function updateGridFromBlockchainSnapshot(manager, orderType = 'both', fro
|
|
|
1100
1148
|
if (overrideBoundaryIdx !== null && overrideBoundaryIdx !== manager.boundaryIdx) {
|
|
1101
1149
|
const gapSlots = calculateGapSlots(manager.config.incrementPercent, manager.config.targetSpreadPercent, manager.config.gridLimits);
|
|
1102
1150
|
const allSlots = Array.from(workingGrid.values())
|
|
1103
|
-
.filter(s => s.price != null)
|
|
1151
|
+
.filter((s) => s.price != null)
|
|
1104
1152
|
.sort((a, b) => a.price - b.price);
|
|
1105
|
-
const updatedSlots = assignGridRoles(allSlots, newBoundary, gapSlots, ORDER_TYPES, ORDER_STATES);
|
|
1153
|
+
const updatedSlots = (0, order_1.assignGridRoles)(allSlots, newBoundary, gapSlots, constants_1.ORDER_TYPES, constants_1.ORDER_STATES);
|
|
1106
1154
|
for (const slot of updatedSlots) {
|
|
1107
1155
|
workingGrid.set(slot.id, slot);
|
|
1108
1156
|
}
|
|
@@ -1173,14 +1221,14 @@ async function compareGrids(calculatedGrid, persistedGrid, manager = null) {
|
|
|
1173
1221
|
// they are instead handled by the available-funds ratio check or follow-up correction.
|
|
1174
1222
|
// Must be sorted ASC for calculateRotationOrderSizes to match geometric weight distribution
|
|
1175
1223
|
const filterForRms = (orders, type) => {
|
|
1176
|
-
const result = Array.isArray(orders) ? orders.filter(o => o && o.type === type && o.state === ORDER_STATES.ACTIVE) : [];
|
|
1224
|
+
const result = Array.isArray(orders) ? orders.filter((o) => o && o.type === type && o.state === constants_1.ORDER_STATES.ACTIVE) : [];
|
|
1177
1225
|
return result
|
|
1178
1226
|
.sort((a, b) => (a.price ?? 0) - (b.price ?? 0));
|
|
1179
1227
|
};
|
|
1180
|
-
const calculatedBuys = filterForRms(calculatedSnap, ORDER_TYPES.BUY);
|
|
1181
|
-
const calculatedSells = filterForRms(calculatedSnap, ORDER_TYPES.SELL);
|
|
1182
|
-
const persistedBuys = filterForRms(persistedSnap, ORDER_TYPES.BUY);
|
|
1183
|
-
const persistedSells = filterForRms(persistedSnap, ORDER_TYPES.SELL);
|
|
1228
|
+
const calculatedBuys = filterForRms(calculatedSnap, constants_1.ORDER_TYPES.BUY);
|
|
1229
|
+
const calculatedSells = filterForRms(calculatedSnap, constants_1.ORDER_TYPES.SELL);
|
|
1230
|
+
const persistedBuys = filterForRms(persistedSnap, constants_1.ORDER_TYPES.BUY);
|
|
1231
|
+
const persistedSells = filterForRms(persistedSnap, constants_1.ORDER_TYPES.SELL);
|
|
1184
1232
|
// Calculate ideal sizes for each order based on current available budget.
|
|
1185
1233
|
// The sizing context (which includes recalculateFunds) is resolved once per side up front
|
|
1186
1234
|
// so both buy and sell metrics share a single fund snapshot. This avoids the previous
|
|
@@ -1192,18 +1240,18 @@ async function compareGrids(calculatedGrid, persistedGrid, manager = null) {
|
|
|
1192
1240
|
// Identify ALL slots currently assigned to this side.
|
|
1193
1241
|
// Ideal sizing must use the full slot count to determine geometric share per slot.
|
|
1194
1242
|
const sideSlots = Array.from(manager.orders.values())
|
|
1195
|
-
.filter(o => o.type === type)
|
|
1243
|
+
.filter((o) => o.type === type)
|
|
1196
1244
|
.sort((a, b) => (a.price ?? 0) - (b.price ?? 0));
|
|
1197
1245
|
if (sideSlots.length === 0)
|
|
1198
1246
|
return activeOrders;
|
|
1199
1247
|
// Calculate geometric ideals for the ENTIRE side (all slots)
|
|
1200
1248
|
try {
|
|
1201
|
-
const allIdealSizes = calculateRotationOrderSizes(ctx.budget, 0, sideSlots.length, type, manager.config, 0, ctx.precision);
|
|
1249
|
+
const allIdealSizes = (0, math_1.calculateRotationOrderSizes)(ctx.budget, 0, sideSlots.length, type, manager.config, 0, ctx.precision);
|
|
1202
1250
|
// Map Ideal sizes to IDs for quick lookup
|
|
1203
1251
|
const idealMap = new Map();
|
|
1204
1252
|
sideSlots.forEach((slot, i) => idealMap.set(slot.id, allIdealSizes[i]));
|
|
1205
1253
|
// Return the activeOrders subset with their true geometric ideal sizes
|
|
1206
|
-
return activeOrders.map(o => ({ ...o, size: idealMap.get(o.id) ?? 0 }));
|
|
1254
|
+
return activeOrders.map((o) => ({ ...o, size: idealMap.get(o.id) ?? 0 }));
|
|
1207
1255
|
}
|
|
1208
1256
|
catch (e) {
|
|
1209
1257
|
return activeOrders;
|
|
@@ -1220,11 +1268,11 @@ async function compareGrids(calculatedGrid, persistedGrid, manager = null) {
|
|
|
1220
1268
|
const sellCtx = needsSell
|
|
1221
1269
|
? await _getSizingContext(manager, 'sell', { skipRecalc: true })
|
|
1222
1270
|
: null;
|
|
1223
|
-
const buyIdeals = computeSideIdeals(calculatedBuys, ORDER_TYPES.BUY, buyCtx);
|
|
1224
|
-
const sellIdeals = computeSideIdeals(calculatedSells, ORDER_TYPES.SELL, sellCtx);
|
|
1271
|
+
const buyIdeals = computeSideIdeals(calculatedBuys, constants_1.ORDER_TYPES.BUY, buyCtx);
|
|
1272
|
+
const sellIdeals = computeSideIdeals(calculatedSells, constants_1.ORDER_TYPES.SELL, sellCtx);
|
|
1225
1273
|
// Calculate RMS divergence metric for each side
|
|
1226
|
-
const buyMetric = calculateGridSideDivergenceMetric(buyIdeals, persistedBuys, 'buy');
|
|
1227
|
-
const sellMetric = calculateGridSideDivergenceMetric(sellIdeals, persistedSells, 'sell');
|
|
1274
|
+
const buyMetric = (0, math_1.calculateGridSideDivergenceMetric)(buyIdeals, persistedBuys, 'buy');
|
|
1275
|
+
const sellMetric = (0, math_1.calculateGridSideDivergenceMetric)(sellIdeals, persistedSells, 'sell');
|
|
1228
1276
|
// Check if metrics exceed threshold and flag sides for regeneration
|
|
1229
1277
|
// Set RMS_PERCENTAGE to 0 to disable RMS divergence checks
|
|
1230
1278
|
let buyUpdated = false, sellUpdated = false;
|
|
@@ -1234,14 +1282,14 @@ async function compareGrids(calculatedGrid, persistedGrid, manager = null) {
|
|
|
1234
1282
|
// RC-3: Use Set for automatic duplicate prevention
|
|
1235
1283
|
if (!(manager._gridSidesUpdated instanceof Set))
|
|
1236
1284
|
manager._gridSidesUpdated = new Set();
|
|
1237
|
-
manager._gridSidesUpdated.add(ORDER_TYPES.BUY);
|
|
1285
|
+
manager._gridSidesUpdated.add(constants_1.ORDER_TYPES.BUY);
|
|
1238
1286
|
buyUpdated = true;
|
|
1239
1287
|
}
|
|
1240
1288
|
if (sellMetric > limit) {
|
|
1241
1289
|
// RC-3: Use Set for automatic duplicate prevention
|
|
1242
1290
|
if (!(manager._gridSidesUpdated instanceof Set))
|
|
1243
1291
|
manager._gridSidesUpdated = new Set();
|
|
1244
|
-
manager._gridSidesUpdated.add(ORDER_TYPES.SELL);
|
|
1292
|
+
manager._gridSidesUpdated.add(constants_1.ORDER_TYPES.SELL);
|
|
1245
1293
|
sellUpdated = true;
|
|
1246
1294
|
}
|
|
1247
1295
|
}
|
|
@@ -1292,13 +1340,13 @@ async function monitorDivergence(manager, calculatedGrid, persistedGrid) {
|
|
|
1292
1340
|
*/
|
|
1293
1341
|
function _getOnChainOrders(manager) {
|
|
1294
1342
|
const onChainBuys = [
|
|
1295
|
-
...manager.getOrdersByTypeAndState(ORDER_TYPES.BUY, ORDER_STATES.ACTIVE),
|
|
1296
|
-
...manager.getOrdersByTypeAndState(ORDER_TYPES.BUY, ORDER_STATES.PARTIAL)
|
|
1297
|
-
].filter(o => o?.orderId && Number(o?.size || 0) > 0);
|
|
1343
|
+
...manager.getOrdersByTypeAndState(constants_1.ORDER_TYPES.BUY, constants_1.ORDER_STATES.ACTIVE),
|
|
1344
|
+
...manager.getOrdersByTypeAndState(constants_1.ORDER_TYPES.BUY, constants_1.ORDER_STATES.PARTIAL)
|
|
1345
|
+
].filter((o) => o?.orderId && Number(o?.size || 0) > 0);
|
|
1298
1346
|
const onChainSells = [
|
|
1299
|
-
...manager.getOrdersByTypeAndState(ORDER_TYPES.SELL, ORDER_STATES.ACTIVE),
|
|
1300
|
-
...manager.getOrdersByTypeAndState(ORDER_TYPES.SELL, ORDER_STATES.PARTIAL)
|
|
1301
|
-
].filter(o => o?.orderId && Number(o?.size || 0) > 0);
|
|
1347
|
+
...manager.getOrdersByTypeAndState(constants_1.ORDER_TYPES.SELL, constants_1.ORDER_STATES.ACTIVE),
|
|
1348
|
+
...manager.getOrdersByTypeAndState(constants_1.ORDER_TYPES.SELL, constants_1.ORDER_STATES.PARTIAL)
|
|
1349
|
+
].filter((o) => o?.orderId && Number(o?.size || 0) > 0);
|
|
1302
1350
|
return { onChainBuys, onChainSells };
|
|
1303
1351
|
}
|
|
1304
1352
|
/**
|
|
@@ -1308,7 +1356,7 @@ function _getOnChainOrders(manager) {
|
|
|
1308
1356
|
*/
|
|
1309
1357
|
function calculateCurrentSpread(manager) {
|
|
1310
1358
|
const { onChainBuys, onChainSells } = _getOnChainOrders(manager);
|
|
1311
|
-
return calculateSpreadFromOrders(onChainBuys, onChainSells);
|
|
1359
|
+
return (0, math_1.calculateSpreadFromOrders)(onChainBuys, onChainSells);
|
|
1312
1360
|
}
|
|
1313
1361
|
/**
|
|
1314
1362
|
* Proactive spread correction check.
|
|
@@ -1333,7 +1381,7 @@ function calculateCurrentSpread(manager) {
|
|
|
1333
1381
|
* @param {Function|null} [updateOrdersOnChainBatch=null] - Optional batch update function
|
|
1334
1382
|
* @returns {Promise<import('./types').SpreadCheckResult>}
|
|
1335
1383
|
*/
|
|
1336
|
-
async function checkSpreadCondition(manager,
|
|
1384
|
+
async function checkSpreadCondition(manager, _BitShares, updateOrdersOnChainBatch = null) {
|
|
1337
1385
|
// CRITICAL: Acquire corrections lock to serialize spread correction operations
|
|
1338
1386
|
// This prevents concurrent fill processing from modifying funds while we're making decisions
|
|
1339
1387
|
let correction = null;
|
|
@@ -1343,7 +1391,7 @@ async function checkSpreadCondition(manager, BitShares, updateOrdersOnChainBatch
|
|
|
1343
1391
|
// Mid between best bid and best ask is the most current price the bot has.
|
|
1344
1392
|
// Falls back to config.startPrice when either side is empty (e.g. at startup).
|
|
1345
1393
|
const { onChainBuys, onChainSells } = _getOnChainOrders(manager);
|
|
1346
|
-
const { bestBuy, bestSell } = getGridBestPrices(onChainBuys, onChainSells);
|
|
1394
|
+
const { bestBuy, bestSell } = (0, math_1.getGridBestPrices)(onChainBuys, onChainSells);
|
|
1347
1395
|
const lastPrice = (bestBuy !== null && bestSell !== null)
|
|
1348
1396
|
? (bestBuy + bestSell) / 2
|
|
1349
1397
|
: Number(manager.config.startPrice) || 0;
|
|
@@ -1361,18 +1409,18 @@ async function checkSpreadCondition(manager, BitShares, updateOrdersOnChainBatch
|
|
|
1361
1409
|
const currentSpread = calculateCurrentSpread(manager);
|
|
1362
1410
|
// Nominal spread is the configured target spread percentage.
|
|
1363
1411
|
// Keep this fixed: doubled-side flags are fill/replacement mechanics only.
|
|
1364
|
-
const nominalSpread = manager.config.targetSpreadPercent ?? DEFAULT_CONFIG.targetSpreadPercent;
|
|
1412
|
+
const nominalSpread = manager.config.targetSpreadPercent ?? constants_1.DEFAULT_CONFIG.targetSpreadPercent;
|
|
1365
1413
|
// Fixed tolerance: 0.5 steps = half increment (tighter spread check).
|
|
1366
1414
|
const toleranceSteps = 0.5;
|
|
1367
|
-
const buyCount = manager.getOrdersByTypeAndState(ORDER_TYPES.BUY, ORDER_STATES.ACTIVE)
|
|
1368
|
-
.concat(manager.getOrdersByTypeAndState(ORDER_TYPES.BUY, ORDER_STATES.PARTIAL))
|
|
1369
|
-
.filter(o => o?.orderId && Number(o?.size || 0) > 0)
|
|
1415
|
+
const buyCount = manager.getOrdersByTypeAndState(constants_1.ORDER_TYPES.BUY, constants_1.ORDER_STATES.ACTIVE)
|
|
1416
|
+
.concat(manager.getOrdersByTypeAndState(constants_1.ORDER_TYPES.BUY, constants_1.ORDER_STATES.PARTIAL))
|
|
1417
|
+
.filter((o) => o?.orderId && Number(o?.size || 0) > 0)
|
|
1370
1418
|
.length;
|
|
1371
|
-
const sellCount = manager.getOrdersByTypeAndState(ORDER_TYPES.SELL, ORDER_STATES.ACTIVE)
|
|
1372
|
-
.concat(manager.getOrdersByTypeAndState(ORDER_TYPES.SELL, ORDER_STATES.PARTIAL))
|
|
1373
|
-
.filter(o => o?.orderId && Number(o?.size || 0) > 0)
|
|
1419
|
+
const sellCount = manager.getOrdersByTypeAndState(constants_1.ORDER_TYPES.SELL, constants_1.ORDER_STATES.ACTIVE)
|
|
1420
|
+
.concat(manager.getOrdersByTypeAndState(constants_1.ORDER_TYPES.SELL, constants_1.ORDER_STATES.PARTIAL))
|
|
1421
|
+
.filter((o) => o?.orderId && Number(o?.size || 0) > 0)
|
|
1374
1422
|
.length;
|
|
1375
|
-
manager.outOfSpread = shouldFlagOutOfSpread(currentSpread, nominalSpread, toleranceSteps, buyCount, sellCount, manager.config.incrementPercent);
|
|
1423
|
+
manager.outOfSpread = (0, order_1.shouldFlagOutOfSpread)(currentSpread, nominalSpread, toleranceSteps, buyCount, sellCount, manager.config.incrementPercent);
|
|
1376
1424
|
if (manager.outOfSpread === 0)
|
|
1377
1425
|
return false;
|
|
1378
1426
|
// Check whether the empty side is caused by boundary-at-rail-edge.
|
|
@@ -1402,7 +1450,7 @@ async function checkSpreadCondition(manager, BitShares, updateOrdersOnChainBatch
|
|
|
1402
1450
|
`Requesting structural grid resync to re-center.`, 'warn');
|
|
1403
1451
|
if (typeof manager.requestStructuralGridResync === 'function') {
|
|
1404
1452
|
manager.requestStructuralGridResync('boundary-at-rail-edge', { reason: `Boundary ${manager.boundaryIdx} leaves ${buySideCount} buy / ${sellSideCount} sell slots` }).catch((err) => {
|
|
1405
|
-
manager.logger?.log?.(`[SPREAD] Structural resync request failed: ${err
|
|
1453
|
+
manager.logger?.log?.(`[SPREAD] Structural resync request failed: ${(0, errors_1.getErrorMessage)(err)}`, 'error');
|
|
1406
1454
|
});
|
|
1407
1455
|
}
|
|
1408
1456
|
}
|
|
@@ -1427,7 +1475,7 @@ async function checkSpreadCondition(manager, BitShares, updateOrdersOnChainBatch
|
|
|
1427
1475
|
shouldApplyCorrection = await manager._gridLock.acquire(executeSpreadCheck);
|
|
1428
1476
|
}
|
|
1429
1477
|
catch (err) {
|
|
1430
|
-
manager.logger?.log?.(`Error checking spread condition: ${err
|
|
1478
|
+
manager.logger?.log?.(`Error checking spread condition: ${(0, errors_1.getErrorMessage)(err)}`, 'warn');
|
|
1431
1479
|
return { ordersPlaced: 0, partialsMoved: 0 };
|
|
1432
1480
|
}
|
|
1433
1481
|
// FIX: Apply blockchain operations OUTSIDE the lock to reduce lock contention
|
|
@@ -1475,7 +1523,7 @@ async function checkSpreadCondition(manager, BitShares, updateOrdersOnChainBatch
|
|
|
1475
1523
|
return { ordersPlaced: placed + updated, partialsMoved: updated };
|
|
1476
1524
|
}
|
|
1477
1525
|
catch (err) {
|
|
1478
|
-
manager.logger?.log?.(`Error applying spread correction on-chain: ${err
|
|
1526
|
+
manager.logger?.log?.(`Error applying spread correction on-chain: ${(0, errors_1.getErrorMessage)(err)}`, 'warn');
|
|
1479
1527
|
return { ordersPlaced: 0, partialsMoved: 0 };
|
|
1480
1528
|
}
|
|
1481
1529
|
}
|
|
@@ -1494,7 +1542,7 @@ async function checkSpreadCondition(manager, BitShares, updateOrdersOnChainBatch
|
|
|
1494
1542
|
* @param {Function|null} [updateOrdersOnChainBatch=null] - Optional batch update function.
|
|
1495
1543
|
* @returns {Promise<import('./types').DustCheckResult>}
|
|
1496
1544
|
*/
|
|
1497
|
-
async function checkGridHealth(manager,
|
|
1545
|
+
async function checkGridHealth(manager, _updateOrdersOnChainBatch = null) {
|
|
1498
1546
|
if (!manager)
|
|
1499
1547
|
return { buyDust: false, sellDust: false, buyDustOrders: [], sellDustOrders: [] };
|
|
1500
1548
|
// Skip health checks during bootstrap to prevent spamming warnings
|
|
@@ -1529,16 +1577,16 @@ async function checkWindowDust(manager) {
|
|
|
1529
1577
|
if (!manager)
|
|
1530
1578
|
return { buyDust: false, sellDust: false, buyDustOrders: [], sellDustOrders: [] };
|
|
1531
1579
|
const allOrders = Array.from(manager.orders.values());
|
|
1532
|
-
const isLiveOrder = order => order &&
|
|
1580
|
+
const isLiveOrder = (order) => order &&
|
|
1533
1581
|
order.orderId &&
|
|
1534
1582
|
order.price != null &&
|
|
1535
|
-
(order.state === ORDER_STATES.ACTIVE || order.state === ORDER_STATES.PARTIAL);
|
|
1583
|
+
(order.state === constants_1.ORDER_STATES.ACTIVE || order.state === constants_1.ORDER_STATES.PARTIAL);
|
|
1536
1584
|
// Identify top-of-window orders (closest to market per side).
|
|
1537
1585
|
const topBuyOrder = allOrders
|
|
1538
|
-
.filter(o => o.type === ORDER_TYPES.BUY && isLiveOrder(o))
|
|
1586
|
+
.filter((o) => o.type === constants_1.ORDER_TYPES.BUY && isLiveOrder(o))
|
|
1539
1587
|
.sort((a, b) => b.price - a.price)[0];
|
|
1540
1588
|
const topSellOrder = allOrders
|
|
1541
|
-
.filter(o => o.type === ORDER_TYPES.SELL && isLiveOrder(o))
|
|
1589
|
+
.filter((o) => o.type === constants_1.ORDER_TYPES.SELL && isLiveOrder(o))
|
|
1542
1590
|
.sort((a, b) => a.price - b.price)[0];
|
|
1543
1591
|
// Check if an order has a duplicate price level — an active sibling at the
|
|
1544
1592
|
// same price within tolerance. If so, cancelling won't create a grid gap.
|
|
@@ -1546,25 +1594,17 @@ async function checkWindowDust(manager) {
|
|
|
1546
1594
|
// sibling, neither qualifies and the gap is left to the rebalancer.
|
|
1547
1595
|
// Uses the LARGER size of the two orders for tolerance calculation to prevent
|
|
1548
1596
|
// a tiny dust order from inflating the tolerance window.
|
|
1549
|
-
const hasDuplicatePriceLevel = (order, assets) => allOrders.
|
|
1550
|
-
if (o.id === order.id || o.type !== order.type)
|
|
1551
|
-
return false;
|
|
1552
|
-
if (o.state !== ORDER_STATES.ACTIVE || !o.orderId || o.price == null)
|
|
1553
|
-
return false;
|
|
1554
|
-
const toleranceSize = Math.max(order.size, o.size);
|
|
1555
|
-
const tolerance = calculatePriceTolerance(Math.min(order.price, o.price), toleranceSize, order.type, assets);
|
|
1556
|
-
return tolerance != null && Math.abs(o.price - order.price) <= tolerance;
|
|
1557
|
-
});
|
|
1597
|
+
const hasDuplicatePriceLevel = (order, assets) => (0, math_1.findPriceCollision)(allOrders, order.id, order.price, order.size, order.type, assets, (o) => o.type === order.type && o.state === constants_1.ORDER_STATES.ACTIVE && !!o.orderId && o.price != null) != null;
|
|
1558
1598
|
const assets = manager.assets;
|
|
1559
|
-
const allPartials = allOrders.filter((o) => isLiveOrder(o) && o.state === ORDER_STATES.PARTIAL);
|
|
1599
|
+
const allPartials = allOrders.filter((o) => isLiveOrder(o) && o.state === constants_1.ORDER_STATES.PARTIAL);
|
|
1560
1600
|
const isTopBuy = (o) => topBuyOrder && o.id === topBuyOrder.id;
|
|
1561
1601
|
const isTopSell = (o) => topSellOrder && o.id === topSellOrder.id;
|
|
1562
1602
|
// Safety filter: top-of-window partials always qualify; interior partials
|
|
1563
1603
|
// only qualify if they have a duplicate price level (no gap risk).
|
|
1564
|
-
const eligibleBuyPartials = allPartials.filter((o) => o.type === ORDER_TYPES.BUY && (isTopBuy(o) || hasDuplicatePriceLevel(o, assets)));
|
|
1565
|
-
const eligibleSellPartials = allPartials.filter((o) => o.type === ORDER_TYPES.SELL && (isTopSell(o) || hasDuplicatePriceLevel(o, assets)));
|
|
1566
|
-
const buyDustOrders = await _getDustOrders(manager, eligibleBuyPartials, ORDER_TYPES.BUY);
|
|
1567
|
-
const sellDustOrders = await _getDustOrders(manager, eligibleSellPartials, ORDER_TYPES.SELL);
|
|
1604
|
+
const eligibleBuyPartials = allPartials.filter((o) => o.type === constants_1.ORDER_TYPES.BUY && (isTopBuy(o) || hasDuplicatePriceLevel(o, assets)));
|
|
1605
|
+
const eligibleSellPartials = allPartials.filter((o) => o.type === constants_1.ORDER_TYPES.SELL && (isTopSell(o) || hasDuplicatePriceLevel(o, assets)));
|
|
1606
|
+
const buyDustOrders = await _getDustOrders(manager, eligibleBuyPartials, constants_1.ORDER_TYPES.BUY);
|
|
1607
|
+
const sellDustOrders = await _getDustOrders(manager, eligibleSellPartials, constants_1.ORDER_TYPES.SELL);
|
|
1568
1608
|
return {
|
|
1569
1609
|
buyDust: buyDustOrders.length > 0,
|
|
1570
1610
|
sellDust: sellDustOrders.length > 0,
|
|
@@ -1585,27 +1625,27 @@ async function checkWindowDust(manager) {
|
|
|
1585
1625
|
async function _getDustOrders(manager, partials, type) {
|
|
1586
1626
|
if (!partials || partials.length === 0)
|
|
1587
1627
|
return [];
|
|
1588
|
-
const side = type === ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
1628
|
+
const side = type === constants_1.ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
1589
1629
|
const ctx = await _getSizingContext(manager, side);
|
|
1590
1630
|
const dustThresholdPercent = manager.config?.gridLimits?.PARTIAL_DUST_THRESHOLD_PERCENTAGE;
|
|
1591
1631
|
const sideSlots = Array.from(manager.orders.values())
|
|
1592
|
-
.filter(o => o.type === type)
|
|
1632
|
+
.filter((o) => o.type === type)
|
|
1593
1633
|
.sort((a, b) => a.price - b.price);
|
|
1594
1634
|
if (sideSlots.length === 0)
|
|
1595
1635
|
return [];
|
|
1596
1636
|
const idealSizes = ctx && ctx.budget > 0
|
|
1597
|
-
? allocateFundsByWeights(ctx.budget, sideSlots.length, manager.config.weightDistribution[side], manager.config.incrementPercent / 100, type === ORDER_TYPES.BUY, 0, ctx.precision)
|
|
1637
|
+
? (0, math_1.allocateFundsByWeights)(ctx.budget, sideSlots.length, manager.config.weightDistribution[side], manager.config.incrementPercent / 100, type === constants_1.ORDER_TYPES.BUY, 0, ctx.precision)
|
|
1598
1638
|
: [];
|
|
1599
1639
|
// When no budget is available, idealSizes becomes [] so every
|
|
1600
1640
|
// partial's threshold collapses to 0 — no order qualifies as dust.
|
|
1601
1641
|
// We still run the filter for uniformity so the threshold logic
|
|
1602
1642
|
// stays consistent regardless of budget state.
|
|
1603
|
-
return partials.filter(p => {
|
|
1604
|
-
const idx = sideSlots.findIndex(s => s.id === p.id);
|
|
1643
|
+
return partials.filter((p) => {
|
|
1644
|
+
const idx = sideSlots.findIndex((s) => s.id === p.id);
|
|
1605
1645
|
if (idx === -1)
|
|
1606
1646
|
return false;
|
|
1607
1647
|
const threshold = idealSizes.length > idx && idealSizes[idx] > 0
|
|
1608
|
-
? getSingleDustThreshold(idealSizes[idx], dustThresholdPercent)
|
|
1648
|
+
? (0, math_1.getSingleDustThreshold)(idealSizes[idx], dustThresholdPercent)
|
|
1609
1649
|
: 0;
|
|
1610
1650
|
return p.size < threshold;
|
|
1611
1651
|
});
|
|
@@ -1629,7 +1669,7 @@ async function _hasAnyDust(manager, partials, type) {
|
|
|
1629
1669
|
* @returns {Promise<boolean>}
|
|
1630
1670
|
*/
|
|
1631
1671
|
async function hasAnyDust(manager, partials, side) {
|
|
1632
|
-
const type = side === 'buy' ? ORDER_TYPES.BUY : side === 'sell' ? ORDER_TYPES.SELL : null;
|
|
1672
|
+
const type = side === 'buy' ? constants_1.ORDER_TYPES.BUY : side === 'sell' ? constants_1.ORDER_TYPES.SELL : null;
|
|
1633
1673
|
if (!type)
|
|
1634
1674
|
return false;
|
|
1635
1675
|
return await _hasAnyDust(manager, partials, type);
|
|
@@ -1643,7 +1683,7 @@ async function hasAnyDust(manager, partials, side) {
|
|
|
1643
1683
|
* @returns {Promise<Array<import('./types').GridOrderSlot>>}
|
|
1644
1684
|
*/
|
|
1645
1685
|
async function getDustOrders(manager, partials, side) {
|
|
1646
|
-
const type = side === 'buy' ? ORDER_TYPES.BUY : side === 'sell' ? ORDER_TYPES.SELL : null;
|
|
1686
|
+
const type = side === 'buy' ? constants_1.ORDER_TYPES.BUY : side === 'sell' ? constants_1.ORDER_TYPES.SELL : null;
|
|
1647
1687
|
if (!type)
|
|
1648
1688
|
return [];
|
|
1649
1689
|
return await _getDustOrders(manager, partials, type);
|
|
@@ -1677,13 +1717,13 @@ function determineOrderSideByFunds(manager, currentMarketPrice) {
|
|
|
1677
1717
|
const sellInBuyUnits = (Number.isFinite(marketPrice) && marketPrice > 0)
|
|
1678
1718
|
? sellAvailable * marketPrice
|
|
1679
1719
|
: sellAvailable;
|
|
1680
|
-
side = buyAvailable >= sellInBuyUnits ? ORDER_TYPES.BUY : ORDER_TYPES.SELL;
|
|
1720
|
+
side = buyAvailable >= sellInBuyUnits ? constants_1.ORDER_TYPES.BUY : constants_1.ORDER_TYPES.SELL;
|
|
1681
1721
|
}
|
|
1682
1722
|
else if (buyViable) {
|
|
1683
|
-
side = ORDER_TYPES.BUY;
|
|
1723
|
+
side = constants_1.ORDER_TYPES.BUY;
|
|
1684
1724
|
}
|
|
1685
1725
|
else if (sellViable) {
|
|
1686
|
-
side = ORDER_TYPES.SELL;
|
|
1726
|
+
side = constants_1.ORDER_TYPES.SELL;
|
|
1687
1727
|
}
|
|
1688
1728
|
if (!side) {
|
|
1689
1729
|
const committedBuy = Math.max(0, Number(manager.funds?.committed?.chain?.buy || 0));
|
|
@@ -1694,17 +1734,17 @@ function determineOrderSideByFunds(manager, currentMarketPrice) {
|
|
|
1694
1734
|
if (hasValidPrice) {
|
|
1695
1735
|
const buyComparable = committedBuy;
|
|
1696
1736
|
const sellComparable = committedSell * marketPrice;
|
|
1697
|
-
side = buyComparable >= sellComparable ? ORDER_TYPES.BUY : ORDER_TYPES.SELL;
|
|
1737
|
+
side = buyComparable >= sellComparable ? constants_1.ORDER_TYPES.BUY : constants_1.ORDER_TYPES.SELL;
|
|
1698
1738
|
}
|
|
1699
1739
|
else if (committedBuy > buyMinUnit && committedSell <= sellMinUnit) {
|
|
1700
|
-
side = ORDER_TYPES.BUY;
|
|
1740
|
+
side = constants_1.ORDER_TYPES.BUY;
|
|
1701
1741
|
}
|
|
1702
1742
|
else if (committedSell > sellMinUnit && committedBuy <= buyMinUnit) {
|
|
1703
|
-
side = ORDER_TYPES.SELL;
|
|
1743
|
+
side = constants_1.ORDER_TYPES.SELL;
|
|
1704
1744
|
}
|
|
1705
1745
|
else {
|
|
1706
1746
|
// Deterministic fallback when both sides hold inventory but market valuation is unavailable.
|
|
1707
|
-
side = ORDER_TYPES.BUY;
|
|
1747
|
+
side = constants_1.ORDER_TYPES.BUY;
|
|
1708
1748
|
}
|
|
1709
1749
|
manager.logger?.log?.(`Spread correction using redistribution fallback on ${side} ` +
|
|
1710
1750
|
`(free buy=${Format.formatAmount8(buyAvailable)}, free sell=${Format.formatAmount8(sellAvailable)}, ` +
|
|
@@ -1724,13 +1764,13 @@ function determineOrderSideByFunds(manager, currentMarketPrice) {
|
|
|
1724
1764
|
* @returns {Promise<number|null>} The calculated geometric size.
|
|
1725
1765
|
*/
|
|
1726
1766
|
async function calculateGeometricSizeForSpreadCorrection(manager, targetType) {
|
|
1727
|
-
const side = targetType === ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
1767
|
+
const side = targetType === constants_1.ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
1728
1768
|
// Count only on-chain orders (ACTIVE+PARTIAL) to avoid diluting the
|
|
1729
1769
|
// spread-correction order size across hundreds of virtual slots on a
|
|
1730
1770
|
// full-rail grid. Virtual slots have their capital tracked separately
|
|
1731
1771
|
// in funds.virtual and should not compete for the free budget.
|
|
1732
1772
|
const slotsCount = Array.from(manager.orders.values())
|
|
1733
|
-
.filter(o => o.type === targetType && (o.state === ORDER_STATES.ACTIVE || o.state === ORDER_STATES.PARTIAL))
|
|
1773
|
+
.filter((o) => o.type === targetType && (o.state === constants_1.ORDER_STATES.ACTIVE || o.state === constants_1.ORDER_STATES.PARTIAL))
|
|
1734
1774
|
.length + 1;
|
|
1735
1775
|
// Use centralized sizing context (respects botFunds % allocation)
|
|
1736
1776
|
const ctx = await _getSizingContext(manager, side);
|
|
@@ -1739,7 +1779,7 @@ async function calculateGeometricSizeForSpreadCorrection(manager, targetType) {
|
|
|
1739
1779
|
// ALLOW slotsCount === 1 to enable spread correction even if a side is completely missing
|
|
1740
1780
|
const dummy = Array.from({ length: slotsCount }, () => ({ type: targetType }));
|
|
1741
1781
|
try {
|
|
1742
|
-
const sized = calculateOrderSizes(dummy, manager.config, side === 'sell' ? ctx.budget : 0, side === 'buy' ? ctx.budget : 0, 0, 0, ctx.precision, ctx.precision);
|
|
1782
|
+
const sized = (0, math_1.calculateOrderSizes)(dummy, manager.config, side === 'sell' ? ctx.budget : 0, side === 'buy' ? ctx.budget : 0, 0, 0, ctx.precision, ctx.precision);
|
|
1743
1783
|
if (!Array.isArray(sized) || sized.length === 0) {
|
|
1744
1784
|
manager.logger?.log?.(`calculateOrderSizes returned invalid result for spread correction`, 'warn');
|
|
1745
1785
|
return null;
|
|
@@ -1747,7 +1787,7 @@ async function calculateGeometricSizeForSpreadCorrection(manager, targetType) {
|
|
|
1747
1787
|
return side === 'sell' ? sized[0].size : sized[sized.length - 1].size;
|
|
1748
1788
|
}
|
|
1749
1789
|
catch (e) {
|
|
1750
|
-
manager.logger?.log?.(`Error calculating geometric size for spread correction: ${e
|
|
1790
|
+
manager.logger?.log?.(`Error calculating geometric size for spread correction: ${(0, errors_1.getErrorMessage)(e)}`, 'warn');
|
|
1751
1791
|
return null;
|
|
1752
1792
|
}
|
|
1753
1793
|
}
|
|
@@ -1760,13 +1800,13 @@ async function calculateGeometricSizeForSpreadCorrection(manager, targetType) {
|
|
|
1760
1800
|
*/
|
|
1761
1801
|
async function prepareSpreadCorrectionOrders(manager, preferredSide) {
|
|
1762
1802
|
// FIX: Validate preferredSide parameter to prevent silent logic errors
|
|
1763
|
-
if (preferredSide !== ORDER_TYPES.BUY && preferredSide !== ORDER_TYPES.SELL) {
|
|
1764
|
-
throw new Error(`Invalid preferredSide: ${preferredSide}. Must be '${ORDER_TYPES.BUY}' or '${ORDER_TYPES.SELL}'.`);
|
|
1803
|
+
if (preferredSide !== constants_1.ORDER_TYPES.BUY && preferredSide !== constants_1.ORDER_TYPES.SELL) {
|
|
1804
|
+
throw new Error(`Invalid preferredSide: ${preferredSide}. Must be '${constants_1.ORDER_TYPES.BUY}' or '${constants_1.ORDER_TYPES.SELL}'.`);
|
|
1765
1805
|
}
|
|
1766
1806
|
const ordersToPlace = [];
|
|
1767
1807
|
const ordersToUpdate = [];
|
|
1768
1808
|
const railType = preferredSide;
|
|
1769
|
-
const sideName = railType === ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
1809
|
+
const sideName = railType === constants_1.ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
1770
1810
|
const configuredMissingSlots = Number(manager.outOfSpread || 0);
|
|
1771
1811
|
const missingSlots = configuredMissingSlots > 0
|
|
1772
1812
|
? Math.floor(configuredMissingSlots)
|
|
@@ -1779,31 +1819,49 @@ async function prepareSpreadCorrectionOrders(manager, preferredSide) {
|
|
|
1779
1819
|
const allOrders = Array.from(manager.orders.values());
|
|
1780
1820
|
let edgePartial = null;
|
|
1781
1821
|
const partials = allOrders
|
|
1782
|
-
.filter(o => o.type === railType && o.state === ORDER_STATES.PARTIAL)
|
|
1783
|
-
.sort((a, b) => railType === ORDER_TYPES.BUY ? b.price - a.price : a.price - b.price);
|
|
1822
|
+
.filter((o) => o.type === railType && o.state === constants_1.ORDER_STATES.PARTIAL)
|
|
1823
|
+
.sort((a, b) => railType === constants_1.ORDER_TYPES.BUY ? b.price - a.price : a.price - b.price);
|
|
1784
1824
|
if (partials.length > 0) {
|
|
1785
1825
|
edgePartial = partials[0];
|
|
1786
1826
|
manager.logger?.log?.(`[SPREAD-CORRECTION] Identified partial order at ${edgePartial.price} for update`, 'debug');
|
|
1787
1827
|
}
|
|
1788
1828
|
// Primary candidates: SPREAD-type slots adjacent to the gap.
|
|
1789
1829
|
const typedSpreadCandidates = allOrders
|
|
1790
|
-
.filter(o => o.type === ORDER_TYPES.SPREAD && isSlotAvailable(o))
|
|
1791
|
-
.sort((a, b) => railType === ORDER_TYPES.BUY ? a.price - b.price : b.price - a.price)
|
|
1830
|
+
.filter((o) => o.type === constants_1.ORDER_TYPES.SPREAD && (0, order_1.isSlotAvailable)(o))
|
|
1831
|
+
.sort((a, b) => railType === constants_1.ORDER_TYPES.BUY ? a.price - b.price : b.price - a.price)
|
|
1792
1832
|
.slice(0, missingSlots);
|
|
1793
1833
|
// Secondary candidates: orphaned virtual slots of the correct side-type that have
|
|
1794
1834
|
// lost their order (e.g. stale-cleaned after a race condition during a crash).
|
|
1795
1835
|
// These sit inside the active window and are invisible to the SPREAD-type filter above.
|
|
1796
1836
|
const orphanedVirtualCandidates = allOrders
|
|
1797
|
-
.filter(o => o.type === railType && o.state === ORDER_STATES.VIRTUAL && !o.orderId && Number(o.size || 0) === 0)
|
|
1798
|
-
.sort((a, b) => railType === ORDER_TYPES.BUY ? b.price - a.price : a.price - b.price)
|
|
1837
|
+
.filter((o) => o.type === railType && o.state === constants_1.ORDER_STATES.VIRTUAL && !o.orderId && Number(o.size || 0) === 0)
|
|
1838
|
+
.sort((a, b) => railType === constants_1.ORDER_TYPES.BUY ? b.price - a.price : a.price - b.price)
|
|
1799
1839
|
.slice(0, missingSlots);
|
|
1800
1840
|
// Merge: prefer orphaned virtuals (they already occupy correct grid positions) then
|
|
1801
1841
|
// fall back to SPREAD slots for any remaining quota.
|
|
1802
1842
|
const remainingQuota = Math.max(0, missingSlots - orphanedVirtualCandidates.length);
|
|
1803
|
-
|
|
1843
|
+
let spreadCandidates = [
|
|
1804
1844
|
...orphanedVirtualCandidates,
|
|
1805
1845
|
...typedSpreadCandidates.slice(0, remainingQuota)
|
|
1806
1846
|
];
|
|
1847
|
+
// P2: Filter out candidates whose price already has a placed order from any slot.
|
|
1848
|
+
// This prevents creating a duplicate order at the same price when a prior cycle's
|
|
1849
|
+
// order was not properly cleaned up (e.g. uncertain broadcast).
|
|
1850
|
+
if (spreadCandidates.length > 0) {
|
|
1851
|
+
const preFilter = spreadCandidates.length;
|
|
1852
|
+
spreadCandidates = spreadCandidates.filter((c) => {
|
|
1853
|
+
if (c.price == null)
|
|
1854
|
+
return false;
|
|
1855
|
+
// Resolve candidate size: if zero/missing, use minimum so tolerance
|
|
1856
|
+
// doesn't collapse to zero (calculatePriceTolerance returns null for size <= 0).
|
|
1857
|
+
const cs = (c.size && c.size > 0) ? c.size : (0, math_1.getMinAbsoluteOrderSize)(railType, manager.assets);
|
|
1858
|
+
return !(0, math_1.findPriceCollision)(allOrders, c.id, c.price, cs, railType, manager.assets, (o) => (0, order_1.isOrderPlaced)(o) && o.price != null);
|
|
1859
|
+
});
|
|
1860
|
+
const filteredCount = preFilter - spreadCandidates.length;
|
|
1861
|
+
if (filteredCount > 0) {
|
|
1862
|
+
manager.logger?.log?.(`[SPREAD-CORRECTION] Filtered ${filteredCount}/${preFilter} candidate(s) with duplicate price levels`, 'warn');
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1807
1865
|
if (spreadCandidates.length > 0) {
|
|
1808
1866
|
manager.logger?.log?.(`[SPREAD-CORRECTION] Identified ${spreadCandidates.length}/${missingSlots} slot(s) for activation on ${sideName} (orphaned=${orphanedVirtualCandidates.length}, spread=${spreadCandidates.length - orphanedVirtualCandidates.length})`, 'debug');
|
|
1809
1867
|
}
|
|
@@ -1811,26 +1869,26 @@ async function prepareSpreadCorrectionOrders(manager, preferredSide) {
|
|
|
1811
1869
|
manager.logger?.log?.(`[SPREAD-CORRECTION] No suitable partials, orphaned virtual slots, or spread slots found. Skipping.`, 'warn');
|
|
1812
1870
|
return { ordersToPlace: [], ordersToUpdate: [] };
|
|
1813
1871
|
}
|
|
1814
|
-
const orphanedIds = new Set(orphanedVirtualCandidates.map(o => o.id));
|
|
1872
|
+
const orphanedIds = new Set(orphanedVirtualCandidates.map((o) => o.id));
|
|
1815
1873
|
const sideSlots = allOrders
|
|
1816
|
-
.filter(o => o.type === railType && !orphanedIds.has(o.id))
|
|
1874
|
+
.filter((o) => o.type === railType && !orphanedIds.has(o.id))
|
|
1817
1875
|
.sort((a, b) => a.price - b.price);
|
|
1818
1876
|
const syntheticSideSlots = [
|
|
1819
1877
|
...sideSlots,
|
|
1820
|
-
...spreadCandidates.map(slot => ({ ...slot, type: railType }))
|
|
1878
|
+
...spreadCandidates.map((slot) => ({ ...slot, type: railType }))
|
|
1821
1879
|
].sort((a, b) => a.price - b.price);
|
|
1822
1880
|
const ctx = await _getSizingContext(manager, sideName);
|
|
1823
1881
|
if (!ctx || ctx.budget <= 0 || syntheticSideSlots.length === 0) {
|
|
1824
1882
|
return { ordersToPlace: [], ordersToUpdate: [] };
|
|
1825
1883
|
}
|
|
1826
|
-
const precisionEpsilon = getPrecisionSlack(ctx.precision, 1);
|
|
1827
|
-
const idealSizes = allocateFundsByWeights(ctx.budget, syntheticSideSlots.length, manager.config.weightDistribution[sideName], manager.config.incrementPercent / 100, railType === ORDER_TYPES.BUY, 0, ctx.precision);
|
|
1884
|
+
const precisionEpsilon = (0, math_1.getPrecisionSlack)(ctx.precision, 1);
|
|
1885
|
+
const idealSizes = (0, math_1.allocateFundsByWeights)(ctx.budget, syntheticSideSlots.length, manager.config.weightDistribution[sideName], manager.config.incrementPercent / 100, railType === constants_1.ORDER_TYPES.BUY, 0, ctx.precision);
|
|
1828
1886
|
const idealById = new Map();
|
|
1829
1887
|
syntheticSideSlots.forEach((slot, idx) => {
|
|
1830
1888
|
idealById.set(slot.id, Number(idealSizes[idx] || 0));
|
|
1831
1889
|
});
|
|
1832
1890
|
const availableFund = Math.max(0, Math.min(Number(manager.funds?.available?.[sideName] || 0), Number(sideName === 'buy' ? manager.accountTotals?.buyFree : manager.accountTotals?.sellFree) || 0));
|
|
1833
|
-
const minAbsoluteSize = getMinAbsoluteOrderSize(railType, manager.assets);
|
|
1891
|
+
const minAbsoluteSize = (0, math_1.getMinAbsoluteOrderSize)(railType, manager.assets);
|
|
1834
1892
|
const prioritizedTargets = [];
|
|
1835
1893
|
if (edgePartial && edgePartial.id) {
|
|
1836
1894
|
const ideal = Number(idealById.get(edgePartial.id) || 0);
|
|
@@ -1866,9 +1924,9 @@ async function prepareSpreadCorrectionOrders(manager, preferredSide) {
|
|
|
1866
1924
|
if (totalNeeded > availableFund + precisionEpsilon) {
|
|
1867
1925
|
let shortfall = totalNeeded - availableFund;
|
|
1868
1926
|
const donors = sideSlots
|
|
1869
|
-
.filter(o => hasOnChainId(o) && (o.state === ORDER_STATES.ACTIVE || o.state === ORDER_STATES.PARTIAL))
|
|
1870
|
-
.filter(o => !edgePartial || o.id !== edgePartial.id)
|
|
1871
|
-
.sort((a, b) => railType === ORDER_TYPES.BUY ? a.price - b.price : b.price - a.price);
|
|
1927
|
+
.filter((o) => (0, order_1.hasOnChainId)(o) && (o.state === constants_1.ORDER_STATES.ACTIVE || o.state === constants_1.ORDER_STATES.PARTIAL))
|
|
1928
|
+
.filter((o) => !edgePartial || o.id !== edgePartial.id)
|
|
1929
|
+
.sort((a, b) => railType === constants_1.ORDER_TYPES.BUY ? a.price - b.price : b.price - a.price);
|
|
1872
1930
|
for (const donor of donors) {
|
|
1873
1931
|
if (shortfall <= precisionEpsilon)
|
|
1874
1932
|
break;
|
|
@@ -1882,7 +1940,7 @@ async function prepareSpreadCorrectionOrders(manager, preferredSide) {
|
|
|
1882
1940
|
const donorNext = donorCurrent - reduction;
|
|
1883
1941
|
if (donorNext <= precisionEpsilon)
|
|
1884
1942
|
continue;
|
|
1885
|
-
if (!isOrderHealthy(donorNext, railType, manager.assets, donorIdeal || donorNext))
|
|
1943
|
+
if (!(0, order_1.isOrderHealthy)(donorNext, railType, manager.assets, donorIdeal || donorNext))
|
|
1886
1944
|
continue;
|
|
1887
1945
|
redistributionUpdates.push({ partialOrder: { ...donor }, newSize: donorNext });
|
|
1888
1946
|
recoveredBudget += reduction;
|
|
@@ -1899,7 +1957,7 @@ async function prepareSpreadCorrectionOrders(manager, preferredSide) {
|
|
|
1899
1957
|
if (target.kind === 'partial-topup') {
|
|
1900
1958
|
const topUp = Math.min(target.needed, remainingBudget);
|
|
1901
1959
|
const newSize = target.current + topUp;
|
|
1902
|
-
if (newSize > target.current + precisionEpsilon && isOrderHealthy(newSize, railType, manager.assets, target.ideal)) {
|
|
1960
|
+
if (newSize > target.current + precisionEpsilon && (0, order_1.isOrderHealthy)(newSize, railType, manager.assets, target.ideal)) {
|
|
1903
1961
|
ordersToUpdate.push({ partialOrder: { ...target.order }, newSize });
|
|
1904
1962
|
remainingBudget -= topUp;
|
|
1905
1963
|
}
|
|
@@ -1908,13 +1966,13 @@ async function prepareSpreadCorrectionOrders(manager, preferredSide) {
|
|
|
1908
1966
|
const createSize = Math.min(target.ideal, remainingBudget);
|
|
1909
1967
|
if (createSize <= precisionEpsilon)
|
|
1910
1968
|
continue;
|
|
1911
|
-
if (!isOrderHealthy(createSize, railType, manager.assets, target.ideal))
|
|
1969
|
+
if (!(0, order_1.isOrderHealthy)(createSize, railType, manager.assets, target.ideal))
|
|
1912
1970
|
continue;
|
|
1913
1971
|
ordersToPlace.push({
|
|
1914
1972
|
...target.order,
|
|
1915
1973
|
type: railType,
|
|
1916
1974
|
size: createSize,
|
|
1917
|
-
state: ORDER_STATES.VIRTUAL
|
|
1975
|
+
state: constants_1.ORDER_STATES.VIRTUAL
|
|
1918
1976
|
});
|
|
1919
1977
|
remainingBudget -= createSize;
|
|
1920
1978
|
}
|
|
@@ -1923,7 +1981,7 @@ async function prepareSpreadCorrectionOrders(manager, preferredSide) {
|
|
|
1923
1981
|
const id = plannedUpdate?.partialOrder?.id || plannedUpdate?.id;
|
|
1924
1982
|
if (!id)
|
|
1925
1983
|
continue;
|
|
1926
|
-
const existingIdx = combinedUpdates.findIndex(u => (u?.partialOrder?.id || u?.id) === id);
|
|
1984
|
+
const existingIdx = combinedUpdates.findIndex((u) => (u?.partialOrder?.id || u?.id) === id);
|
|
1927
1985
|
if (existingIdx >= 0) {
|
|
1928
1986
|
combinedUpdates[existingIdx] = plannedUpdate;
|
|
1929
1987
|
}
|