dexbot 1.4.11 → 1.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +9 -18
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/math_utils.d.ts.map +1 -1
- package/dist/analysis/math_utils.js +6 -16
- package/dist/analysis/math_utils.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +31 -38
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js +7 -10
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +10 -14
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +10 -15
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +7 -10
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +4 -12
- package/dist/bot.js.map +1 -1
- package/dist/credential-daemon.d.ts +0 -1
- package/dist/credential-daemon.d.ts.map +1 -1
- package/dist/credential-daemon.js +3 -123
- package/dist/credential-daemon.js.map +1 -1
- package/dist/dexbot.d.ts +0 -87
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +11 -14
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +8 -9
- package/dist/market_adapter/ama_signal_runner.js.map +1 -1
- package/dist/market_adapter/candle_utils.js +1 -7
- package/dist/market_adapter/candle_utils.js.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.js +1 -4
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
- package/dist/market_adapter/core/config_normalizers.js +5 -9
- package/dist/market_adapter/core/config_normalizers.js.map +1 -1
- package/dist/market_adapter/core/kibana_candles.js +8 -15
- package/dist/market_adapter/core/kibana_candles.js.map +1 -1
- package/dist/market_adapter/core/kibana_client.js +7 -13
- package/dist/market_adapter/core/kibana_client.js.map +1 -1
- package/dist/market_adapter/core/kibana_market_candles.js +6 -12
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +92 -102
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama.js +5 -10
- package/dist/market_adapter/core/strategies/ama.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +21 -24
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js +3 -5
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +4 -6
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.js +15 -22
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
- package/dist/market_adapter/index.d.ts +23 -23
- package/dist/market_adapter/index.d.ts.map +1 -1
- package/dist/market_adapter/index.js +24 -82
- package/dist/market_adapter/index.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +59 -98
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.js +11 -17
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
- package/dist/market_adapter/interval_utils.js +1 -2
- package/dist/market_adapter/interval_utils.js.map +1 -1
- package/dist/market_adapter/log_format.js +1 -7
- package/dist/market_adapter/log_format.js.map +1 -1
- package/dist/market_adapter/lp_chart_core.js +20 -22
- package/dist/market_adapter/lp_chart_core.js.map +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_runner.js +41 -57
- package/dist/market_adapter/lp_chart_runner.js.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js +30 -34
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
- package/dist/market_adapter/market_adapter.d.ts +2 -2
- package/dist/market_adapter/market_adapter.d.ts.map +1 -1
- package/dist/market_adapter/market_adapter.js +157 -221
- package/dist/market_adapter/market_adapter.js.map +1 -1
- package/dist/market_adapter/merge_lp_data.js +17 -18
- package/dist/market_adapter/merge_lp_data.js.map +1 -1
- package/dist/market_adapter/test_helpers.js +3 -14
- package/dist/market_adapter/test_helpers.js.map +1 -1
- package/dist/market_adapter/utils/adapter_client.js +7 -16
- package/dist/market_adapter/utils/adapter_client.js.map +1 -1
- package/dist/market_adapter/utils/atomic_write.js +3 -5
- package/dist/market_adapter/utils/atomic_write.js.map +1 -1
- package/dist/market_adapter/utils/chain.d.ts.map +1 -1
- package/dist/market_adapter/utils/chain.js +9 -17
- package/dist/market_adapter/utils/chain.js.map +1 -1
- package/dist/market_adapter/utils/data_discovery.js +8 -10
- package/dist/market_adapter/utils/data_discovery.js.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +11 -14
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
- package/dist/market_adapter/utils/file_lock.js +14 -19
- package/dist/market_adapter/utils/file_lock.js.map +1 -1
- package/dist/market_adapter/utils/native_history.js +8 -14
- package/dist/market_adapter/utils/native_history.js.map +1 -1
- package/dist/market_adapter/utils/paths.js +3 -6
- package/dist/market_adapter/utils/paths.js.map +1 -1
- package/dist/modules/account_bots.d.ts +1 -1
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +90 -97
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +0 -9
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +26 -121
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/authority_resolver.js +12 -18
- package/dist/modules/authority_resolver.js.map +1 -1
- package/dist/modules/bitshares-native/chain_client.js +16 -21
- package/dist/modules/bitshares-native/chain_client.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +12 -72
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -40
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +5 -6
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
- package/dist/modules/bitshares-native/index.d.ts +8 -8
- package/dist/modules/bitshares-native/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/index.js +11 -68
- package/dist/modules/bitshares-native/index.js.map +1 -1
- package/dist/modules/bitshares-native/lru_cache.js +3 -6
- package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
- package/dist/modules/bitshares-native/resolvers.js +9 -11
- package/dist/modules/bitshares-native/resolvers.js.map +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js +3 -28
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
- package/dist/modules/bitshares-native/serial/index.d.ts +4 -4
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/index.js +5 -46
- package/dist/modules/bitshares-native/serial/index.js.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts +98 -98
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.js +372 -473
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
- package/dist/modules/bitshares-native/serial/serializer.js +3 -8
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
- package/dist/modules/bitshares-native/serial/types.js +9 -74
- package/dist/modules/bitshares-native/serial/types.js.map +1 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/signing_client.js +11 -48
- package/dist/modules/bitshares-native/signing_client.js.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.js +24 -27
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
- package/dist/modules/bitshares-native/transport.js +14 -26
- package/dist/modules/bitshares-native/transport.js.map +1 -1
- package/dist/modules/bitshares-native/tx/builder.js +29 -72
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js +12 -21
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts +21 -0
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +32 -86
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +30 -49
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/bots_file_lock.d.ts.map +1 -1
- package/dist/modules/bots_file_lock.js +5 -13
- package/dist/modules/bots_file_lock.js.map +1 -1
- package/dist/modules/broadcast_failure.js +1 -3
- package/dist/modules/broadcast_failure.js.map +1 -1
- package/dist/modules/chain_keys.d.ts +4 -9
- package/dist/modules/chain_keys.d.ts.map +1 -1
- package/dist/modules/chain_keys.js +77 -182
- package/dist/modules/chain_keys.js.map +1 -1
- package/dist/modules/chain_orders.d.ts +2 -2
- package/dist/modules/chain_orders.d.ts.map +1 -1
- package/dist/modules/chain_orders.js +81 -144
- package/dist/modules/chain_orders.js.map +1 -1
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +23 -28
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +2 -9
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +38 -73
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/cr_planner.js +15 -26
- package/dist/modules/cr_planner.js.map +1 -1
- package/dist/modules/credential_policy.d.ts +3 -6
- package/dist/modules/credential_policy.d.ts.map +1 -1
- package/dist/modules/credential_policy.js +62 -153
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/credential_runtime.d.ts +1 -1
- package/dist/modules/credential_runtime.d.ts.map +1 -1
- package/dist/modules/credential_runtime.js +34 -41
- package/dist/modules/credential_runtime.js.map +1 -1
- package/dist/modules/credential_session_cache.d.ts +1 -1
- package/dist/modules/credential_session_cache.d.ts.map +1 -1
- package/dist/modules/credential_session_cache.js +5 -42
- package/dist/modules/credential_session_cache.js.map +1 -1
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +126 -162
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/crypto/browser_provider.d.ts +1 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +1 -1
- package/dist/modules/crypto/browser_provider.js +7 -11
- package/dist/modules/crypto/browser_provider.js.map +1 -1
- package/dist/modules/crypto/index.d.ts +6 -6
- package/dist/modules/crypto/index.d.ts.map +1 -1
- package/dist/modules/crypto/index.js +12 -30
- package/dist/modules/crypto/index.js.map +1 -1
- package/dist/modules/crypto/node_provider.d.ts +1 -1
- package/dist/modules/crypto/node_provider.d.ts.map +1 -1
- package/dist/modules/crypto/node_provider.js +3 -5
- package/dist/modules/crypto/node_provider.js.map +1 -1
- package/dist/modules/crypto/provider.js +1 -2
- package/dist/modules/crypto/pure_ripemd160.js +1 -3
- package/dist/modules/crypto/pure_ripemd160.js.map +1 -1
- package/dist/modules/crypto/pure_scrypt.js +1 -4
- package/dist/modules/crypto/pure_scrypt.js.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.js +1 -16
- package/dist/modules/crypto/pure_secp256k1.js.map +1 -1
- package/dist/modules/crypto/sync.d.ts.map +1 -1
- package/dist/modules/crypto/sync.js +16 -17
- package/dist/modules/crypto/sync.js.map +1 -1
- package/dist/modules/daemon_node_health.js +14 -16
- package/dist/modules/daemon_node_health.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +19 -14
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +127 -164
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +28 -27
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +55 -45
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_credential_client.d.ts +6 -2
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -1
- package/dist/modules/dexbot_credential_client.js +21 -31
- package/dist/modules/dexbot_credential_client.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +23 -23
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +119 -77
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +46 -38
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +81 -81
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts +3 -3
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_startup_runtime.js +43 -81
- package/dist/modules/dexbot_startup_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts +11 -11
- package/dist/modules/dexbot_state_recovery.js +32 -78
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/env.js +3 -7
- package/dist/modules/env.js.map +1 -1
- package/dist/modules/fund_registry.d.ts.map +1 -1
- package/dist/modules/fund_registry.js +12 -24
- package/dist/modules/fund_registry.js.map +1 -1
- package/dist/modules/general_settings.js +10 -16
- package/dist/modules/general_settings.js.map +1 -1
- package/dist/modules/graceful_shutdown.d.ts.map +1 -1
- package/dist/modules/graceful_shutdown.js +12 -19
- package/dist/modules/graceful_shutdown.js.map +1 -1
- package/dist/modules/key_store.d.ts.map +1 -1
- package/dist/modules/key_store.js +27 -65
- package/dist/modules/key_store.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +89 -118
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/child_env.js +1 -5
- package/dist/modules/launcher/child_env.js.map +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +22 -31
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -1
- package/dist/modules/launcher/credential_daemon.js +37 -75
- package/dist/modules/launcher/credential_daemon.js.map +1 -1
- package/dist/modules/launcher/credential_secret.js +2 -37
- package/dist/modules/launcher/credential_secret.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +25 -31
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/headless_password.js +10 -12
- package/dist/modules/launcher/headless_password.js.map +1 -1
- package/dist/modules/launcher/launch_modes.js +3 -9
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js +25 -35
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.js +42 -45
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +67 -138
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/runtime_entry.d.ts +1 -11
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
- package/dist/modules/launcher/runtime_entry.js +12 -15
- package/dist/modules/launcher/runtime_entry.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +1 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +15 -36
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/launcher/supervisor_control.js +4 -9
- package/dist/modules/launcher/supervisor_control.js.map +1 -1
- package/dist/modules/logger.d.ts +1 -1
- package/dist/modules/logger.d.ts.map +1 -1
- package/dist/modules/logger.js +3 -38
- package/dist/modules/logger.js.map +1 -1
- package/dist/modules/market_adapter_whitelist.js +9 -18
- package/dist/modules/market_adapter_whitelist.js.map +1 -1
- package/dist/modules/node_failure_ledger.js +1 -3
- package/dist/modules/node_failure_ledger.js.map +1 -1
- package/dist/modules/node_health_cache.d.ts.map +1 -1
- package/dist/modules/node_health_cache.js +15 -25
- package/dist/modules/node_health_cache.js.map +1 -1
- package/dist/modules/node_manager.d.ts +1 -1
- package/dist/modules/node_manager.d.ts.map +1 -1
- package/dist/modules/node_manager.js +44 -43
- package/dist/modules/node_manager.js.map +1 -1
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +102 -118
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/async_lock.d.ts +3 -15
- package/dist/modules/order/async_lock.d.ts.map +1 -1
- package/dist/modules/order/async_lock.js +6 -26
- package/dist/modules/order/async_lock.js.map +1 -1
- package/dist/modules/order/export.js +34 -75
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/format.d.ts +1 -3
- package/dist/modules/order/format.d.ts.map +1 -1
- package/dist/modules/order/format.js +4 -24
- package/dist/modules/order/format.js.map +1 -1
- package/dist/modules/order/grid.d.ts +3 -3
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +206 -262
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile.js +77 -94
- package/dist/modules/order/grid_reconcile.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +117 -149
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/index.d.ts.map +1 -1
- package/dist/modules/order/index.js +11 -45
- package/dist/modules/order/index.js.map +1 -1
- package/dist/modules/order/logger.js +28 -69
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/logger_state.d.ts.map +1 -1
- package/dist/modules/order/logger_state.js +3 -4
- package/dist/modules/order/logger_state.js.map +1 -1
- package/dist/modules/order/manager.d.ts +10 -0
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +131 -151
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/processed_fill_store.js +2 -7
- package/dist/modules/order/processed_fill_store.js.map +1 -1
- package/dist/modules/order/strategy.js +23 -25
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts +27 -0
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +232 -181
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +1 -25
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +49 -172
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +46 -2
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +165 -143
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +3 -1
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +152 -211
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/timeout.js +1 -4
- package/dist/modules/order/utils/timeout.js.map +1 -1
- package/dist/modules/order/utils/validate.js +91 -142
- package/dist/modules/order/utils/validate.js.map +1 -1
- package/dist/modules/order/utils/withPoolRef.js +21 -61
- package/dist/modules/order/utils/withPoolRef.js.map +1 -1
- package/dist/modules/order/working_grid.js +6 -9
- package/dist/modules/order/working_grid.js.map +1 -1
- package/dist/modules/path_api.d.ts.map +1 -1
- package/dist/modules/path_api.js +8 -11
- package/dist/modules/path_api.js.map +1 -1
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +61 -67
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/process_discovery.js +13 -21
- package/dist/modules/process_discovery.js.map +1 -1
- package/dist/modules/runtime.js +7 -11
- package/dist/modules/runtime.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +14 -16
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/modules/settings_merge.js +1 -3
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/socket_json_client.js +3 -5
- package/dist/modules/socket_json_client.js.map +1 -1
- package/dist/modules/storage/browser_adapter.js +1 -4
- package/dist/modules/storage/browser_adapter.js.map +1 -1
- package/dist/modules/storage/index.d.ts +3 -2
- package/dist/modules/storage/index.d.ts.map +1 -1
- package/dist/modules/storage/index.js +5 -8
- package/dist/modules/storage/index.js.map +1 -1
- package/dist/modules/storage/node_adapter.d.ts +3 -4
- package/dist/modules/storage/node_adapter.d.ts.map +1 -1
- package/dist/modules/storage/node_adapter.js +12 -16
- package/dist/modules/storage/node_adapter.js.map +1 -1
- package/dist/modules/storage/types.js +1 -2
- package/dist/modules/types.d.ts +0 -6
- package/dist/modules/types.d.ts.map +1 -1
- package/dist/modules/types.js +1 -2
- package/dist/modules/types.js.map +1 -1
- package/dist/modules/utils/base58check.js +8 -15
- package/dist/modules/utils/base58check.js.map +1 -1
- package/dist/modules/utils/build_dir.js +3 -7
- package/dist/modules/utils/build_dir.js.map +1 -1
- package/dist/modules/utils/errors.js +1 -5
- package/dist/modules/utils/errors.js.map +1 -1
- package/dist/modules/utils/math_utils.d.ts +1 -1
- package/dist/modules/utils/math_utils.d.ts.map +1 -1
- package/dist/modules/utils/math_utils.js +2 -7
- package/dist/modules/utils/math_utils.js.map +1 -1
- package/dist/modules/validate_profiles.d.ts.map +1 -1
- package/dist/modules/validate_profiles.js +18 -25
- package/dist/modules/validate_profiles.js.map +1 -1
- package/dist/pm2.d.ts +4 -70
- package/dist/pm2.d.ts.map +1 -1
- package/dist/pm2.js +106 -132
- package/dist/pm2.js.map +1 -1
- package/dist/scripts/analyze-git.js +13 -17
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/analyze-orders.d.ts.map +1 -1
- package/dist/scripts/analyze-orders.js +48 -63
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.js +2 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +1 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -1
- package/dist/scripts/diagnose-pool-history.js +2 -1
- package/dist/scripts/diagnose-pool-history.js.map +1 -1
- package/dist/scripts/divergence-calc.d.ts.map +1 -1
- package/dist/scripts/divergence-calc.js +2 -2
- package/dist/scripts/divergence-calc.js.map +1 -1
- package/dist/scripts/fix-err-message.js +17 -22
- package/dist/scripts/fix-err-message.js.map +1 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -1
- package/dist/scripts/generate_lp_chart.js +7 -15
- package/dist/scripts/generate_lp_chart.js.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.js +3 -2
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.js +18 -24
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -1
- package/dist/scripts/native_release_gates.js +15 -19
- package/dist/scripts/native_release_gates.js.map +1 -1
- package/dist/scripts/print_grid.d.ts.map +1 -1
- package/dist/scripts/print_grid.js +2 -2
- package/dist/scripts/print_grid.js.map +1 -1
- package/dist/scripts/run-tests.js +12 -17
- package/dist/scripts/run-tests.js.map +1 -1
- package/dist/scripts/runner.d.ts.map +1 -1
- package/dist/scripts/runner.js +18 -20
- package/dist/scripts/runner.js.map +1 -1
- package/dist/scripts/sync-version.js +2 -2
- package/dist/scripts/sync-version.js.map +1 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
- package/dist/scripts/test-credit-renewal.js +4 -3
- package/dist/scripts/test-credit-renewal.js.map +1 -1
- package/dist/scripts/update.js +77 -89
- package/dist/scripts/update.js.map +1 -1
- package/dist/scripts/validate_bots.d.ts.map +1 -1
- package/dist/scripts/validate_bots.js +2 -2
- package/dist/scripts/validate_bots.js.map +1 -1
- package/dist/scripts/verify-browser-bundle.js +12 -17
- package/dist/scripts/verify-browser-bundle.js.map +1 -1
- package/dist/unlock.d.ts +0 -30
- package/dist/unlock.d.ts.map +1 -1
- package/dist/unlock.js +95 -143
- package/dist/unlock.js.map +1 -1
- package/package.json +5 -8
- package/scripts/README.md +1 -1
- package/scripts/create-bot-symlinks.sh +2 -2
- package/dist/modules/utils/fs_utils.d.ts +0 -18
- package/dist/modules/utils/fs_utils.d.ts.map +0 -1
- package/dist/modules/utils/fs_utils.js +0 -32
- package/dist/modules/utils/fs_utils.js.map +0 -1
- package/dist/scripts/migrate_bot_keys.d.ts +0 -3
- package/dist/scripts/migrate_bot_keys.d.ts.map +0 -1
- package/dist/scripts/migrate_bot_keys.js +0 -225
- package/dist/scripts/migrate_bot_keys.js.map +0 -1
|
@@ -1,77 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* modules/order/grid_reconcile_internal.ts - Internal helpers for grid reconciliation
|
|
4
3
|
*
|
|
5
4
|
* Extracted from grid_reconcile.ts for file-size management.
|
|
6
5
|
* All helpers are prefixed with _ and are NOT part of the public API.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports._countActiveOnGrid = _countActiveOnGrid;
|
|
43
|
-
exports._pickVirtualSlotsToActivate = _pickVirtualSlotsToActivate;
|
|
44
|
-
exports._getStartupSideComparators = _getStartupSideComparators;
|
|
45
|
-
exports._isGridEdgeFullyActive = _isGridEdgeFullyActive;
|
|
46
|
-
exports._findLargestOrder = _findLargestOrder;
|
|
47
|
-
exports._cancelLargestOrder = _cancelLargestOrder;
|
|
48
|
-
exports._createOrderFromGrid = _createOrderFromGrid;
|
|
49
|
-
exports._cancelChainOrder = _cancelChainOrder;
|
|
50
|
-
exports._recoverStartupSyncFailure = _recoverStartupSyncFailure;
|
|
51
|
-
exports._refreshStartupUpdatePlans = _refreshStartupUpdatePlans;
|
|
52
|
-
exports._prepareStartupUpdatePlan = _prepareStartupUpdatePlan;
|
|
53
|
-
exports._finalizeStartupUpdate = _finalizeStartupUpdate;
|
|
54
|
-
exports._executeStartupUpdateBatch = _executeStartupUpdateBatch;
|
|
55
|
-
exports._executeStartupSingleUpdate = _executeStartupSingleUpdate;
|
|
56
|
-
exports._executeStartupSequentialUpdateFallback = _executeStartupSequentialUpdateFallback;
|
|
57
|
-
exports._createStartupOrderWithHandling = _createStartupOrderWithHandling;
|
|
58
|
-
exports._extractBatchOperationResults = _extractBatchOperationResults;
|
|
59
|
-
exports._resolveGroupRecovery = _resolveGroupRecovery;
|
|
60
|
-
exports._executeStartupCreateGroupBatch = _executeStartupCreateGroupBatch;
|
|
61
|
-
exports._buildOutsideInCreateGroups = _buildOutsideInCreateGroups;
|
|
62
|
-
exports._executePlannedStartupCreates = _executePlannedStartupCreates;
|
|
63
|
-
exports._reconcileStartupSide = _reconcileStartupSide;
|
|
64
|
-
const constants_1 = require("../constants");
|
|
65
|
-
const chain_orders_1 = require("../chain_orders");
|
|
66
|
-
const math_1 = require("./utils/math");
|
|
67
|
-
const order_1 = require("./utils/order");
|
|
68
|
-
const system_1 = require("./utils/system");
|
|
69
|
-
const Format = __importStar(require("./format"));
|
|
70
|
-
const errors_1 = require("../utils/errors");
|
|
7
|
+
import { ORDER_TYPES, ORDER_STATES, TIMING, BTS_PRECISION } from '../constants.js';
|
|
8
|
+
import { readOpenOrdersGuarded } from '../chain_orders.js';
|
|
9
|
+
import { getMinAbsoluteOrderSize, getAssetFees, getAssetFeesSafe, blockchainToFloat, findPriceCollision, resolveGapBand } from './utils/math.js';
|
|
10
|
+
import { isOrderPlaced, parseChainOrder, parseSlotIndex, buildCreateOrderArgs, buildOutsideInPairGroups, extractBatchOperationResults, chainOrderMatchesSlot, getSideBudget, calculateBudgetedSizes, getActiveOrdersTotal, convertToSpreadPlaceholder, isOrderGoneErrorMessage, clearDuplicateOrphanDetection } from './utils/order.js';
|
|
11
|
+
import { resolveAccountRef } from './utils/system.js';
|
|
12
|
+
import * as Format from './format.js';
|
|
13
|
+
import { getErrorMessage } from '../utils/errors.js';
|
|
71
14
|
function computePlacementPriceCollision(manager, gridOrder) {
|
|
72
15
|
const createPrice = gridOrder.price;
|
|
73
16
|
const createSize = gridOrder.size;
|
|
74
|
-
return createPrice != null &&
|
|
17
|
+
return createPrice != null && findPriceCollision(manager.orders.values(), gridOrder.id, createPrice, createSize, gridOrder.type, manager.assets, isOrderPlaced);
|
|
75
18
|
}
|
|
76
19
|
/**
|
|
77
20
|
* Count active orders on the grid for a given type.
|
|
@@ -81,8 +24,8 @@ function computePlacementPriceCollision(manager, gridOrder) {
|
|
|
81
24
|
* @private
|
|
82
25
|
*/
|
|
83
26
|
function _countActiveOnGrid(manager, type) {
|
|
84
|
-
const active = manager.getOrdersByTypeAndState(type,
|
|
85
|
-
const partial = manager.getOrdersByTypeAndState(type,
|
|
27
|
+
const active = manager.getOrdersByTypeAndState(type, ORDER_STATES.ACTIVE).filter((o) => o && o.orderId);
|
|
28
|
+
const partial = manager.getOrdersByTypeAndState(type, ORDER_STATES.PARTIAL).filter((o) => o && o.orderId);
|
|
86
29
|
return active.length + partial.length;
|
|
87
30
|
}
|
|
88
31
|
/**
|
|
@@ -123,9 +66,9 @@ function _deriveBudgetedSideSizes(manager, type) {
|
|
|
123
66
|
}
|
|
124
67
|
if (!funds)
|
|
125
68
|
return derived;
|
|
126
|
-
const side = type ===
|
|
127
|
-
const totalTarget =
|
|
128
|
-
const budget =
|
|
69
|
+
const side = type === ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
70
|
+
const totalTarget = getActiveOrdersTotal(manager.config);
|
|
71
|
+
const budget = getSideBudget(side, funds, manager.config, totalTarget);
|
|
129
72
|
if (!(budget > 0))
|
|
130
73
|
return derived;
|
|
131
74
|
// Include every in-rail slot that belongs to this side by geometry. Empty
|
|
@@ -139,22 +82,22 @@ function _deriveBudgetedSideSizes(manager, type) {
|
|
|
139
82
|
// temporarily) rather than guess a side. Only accept concrete BUY/SELL
|
|
140
83
|
// types in that case; this mirrors pre-commit behavior where the type
|
|
141
84
|
// filter was the only guard.
|
|
142
|
-
const resolved =
|
|
85
|
+
const resolved = resolveGapBand(manager);
|
|
143
86
|
const boundaryKnown = resolved.boundaryIdx !== null && resolved.sellStartIdx !== null;
|
|
144
87
|
const boundaryIdx = resolved.boundaryIdx;
|
|
145
88
|
const sellStartIdx = resolved.sellStartIdx;
|
|
146
89
|
const inSideRail = (o) => {
|
|
147
90
|
if (!boundaryKnown)
|
|
148
91
|
return true;
|
|
149
|
-
const idx =
|
|
92
|
+
const idx = parseSlotIndex(o.id);
|
|
150
93
|
if (idx === null)
|
|
151
94
|
return true;
|
|
152
|
-
if (type ===
|
|
95
|
+
if (type === ORDER_TYPES.BUY)
|
|
153
96
|
return idx <= boundaryIdx;
|
|
154
97
|
return idx >= sellStartIdx;
|
|
155
98
|
};
|
|
156
99
|
const typeFilter = boundaryKnown
|
|
157
|
-
? (o) => o && o.price != null && (o.type === type || o.type ===
|
|
100
|
+
? (o) => o && o.price != null && (o.type === type || o.type === ORDER_TYPES.SPREAD)
|
|
158
101
|
: (o) => o && o.price != null && o.type === type;
|
|
159
102
|
const allSideSlots = Array.from(manager.orders.values())
|
|
160
103
|
.filter(typeFilter)
|
|
@@ -164,7 +107,7 @@ function _deriveBudgetedSideSizes(manager, type) {
|
|
|
164
107
|
return derived;
|
|
165
108
|
let sizes;
|
|
166
109
|
try {
|
|
167
|
-
sizes =
|
|
110
|
+
sizes = calculateBudgetedSizes(allSideSlots, side, budget, weightDist[side], manager.config.incrementPercent, manager.assets);
|
|
168
111
|
}
|
|
169
112
|
catch (e) {
|
|
170
113
|
return derived;
|
|
@@ -191,17 +134,17 @@ function _pickVirtualSlotsToActivate(manager, type, count) {
|
|
|
191
134
|
// such slots typed BUY/SELL (never SPREAD+ACTIVE), so a VIRTUAL sell left
|
|
192
135
|
// behind by a rotation/rebalance could otherwise be re-picked here and
|
|
193
136
|
// placed back inside the gap. Filter by geometry, not just type.
|
|
194
|
-
const resolved =
|
|
137
|
+
const resolved = resolveGapBand(manager);
|
|
195
138
|
const boundaryKnown = resolved.boundaryIdx !== null && resolved.sellStartIdx !== null;
|
|
196
139
|
const boundaryIdx = resolved.boundaryIdx;
|
|
197
140
|
const sellStartIdx = resolved.sellStartIdx;
|
|
198
141
|
const inRail = (slot) => {
|
|
199
142
|
if (!boundaryKnown)
|
|
200
143
|
return true;
|
|
201
|
-
const idx =
|
|
144
|
+
const idx = parseSlotIndex(slot.id);
|
|
202
145
|
if (idx === null)
|
|
203
146
|
return true;
|
|
204
|
-
if (type ===
|
|
147
|
+
if (type === ORDER_TYPES.BUY)
|
|
205
148
|
return idx <= boundaryIdx;
|
|
206
149
|
return idx >= sellStartIdx;
|
|
207
150
|
};
|
|
@@ -214,15 +157,15 @@ function _pickVirtualSlotsToActivate(manager, type, count) {
|
|
|
214
157
|
// When boundary is unknown, geometry cannot classify an empty — only
|
|
215
158
|
// accept concrete BUY/SELL types (safe: don't activate what we can't place).
|
|
216
159
|
const typeFilter = boundaryKnown
|
|
217
|
-
? (slot) => slot && (slot.type === type || slot.type ===
|
|
160
|
+
? (slot) => slot && (slot.type === type || slot.type === ORDER_TYPES.SPREAD)
|
|
218
161
|
: (slot) => slot && slot.type === type;
|
|
219
162
|
const slotsOfType = Array.from(manager.orders.values())
|
|
220
163
|
.filter(typeFilter)
|
|
221
164
|
.filter(inRail)
|
|
222
|
-
.sort((a, b) => type ===
|
|
165
|
+
.sort((a, b) => type === ORDER_TYPES.BUY ? b.price - a.price : a.price - b.price);
|
|
223
166
|
let effectiveMin = 0;
|
|
224
167
|
try {
|
|
225
|
-
effectiveMin =
|
|
168
|
+
effectiveMin = getMinAbsoluteOrderSize(type, manager.assets);
|
|
226
169
|
}
|
|
227
170
|
catch (e) {
|
|
228
171
|
effectiveMin = 0;
|
|
@@ -234,7 +177,7 @@ function _pickVirtualSlotsToActivate(manager, type, count) {
|
|
|
234
177
|
for (const slot of slotsOfType) {
|
|
235
178
|
if (valid.length >= count)
|
|
236
179
|
break;
|
|
237
|
-
if (!slot.orderId && slot.state ===
|
|
180
|
+
if (!slot.orderId && slot.state === ORDER_STATES.VIRTUAL) {
|
|
238
181
|
// Role invariant: Only pick slots that make sense for this type based on current market pivot
|
|
239
182
|
// (Strategy will enforce this strictly, but we filter here for cleaner activation)
|
|
240
183
|
const storedSize = Number(slot.size) || 0;
|
|
@@ -266,10 +209,10 @@ function _pickVirtualSlotsToActivate(manager, type, count) {
|
|
|
266
209
|
return valid;
|
|
267
210
|
}
|
|
268
211
|
function _getStartupSideComparators(orderType, assets) {
|
|
269
|
-
const isSell = orderType ===
|
|
212
|
+
const isSell = orderType === ORDER_TYPES.SELL;
|
|
270
213
|
const sortUpdateComparator = isSell
|
|
271
|
-
? (a, b) => (
|
|
272
|
-
: (a, b) => (
|
|
214
|
+
? (a, b) => (parseChainOrder(a, assets)?.price || 0) - (parseChainOrder(b, assets)?.price || 0)
|
|
215
|
+
: (a, b) => (parseChainOrder(b, assets)?.price || 0) - (parseChainOrder(a, assets)?.price || 0);
|
|
273
216
|
const sortExcessCancelComparator = isSell
|
|
274
217
|
? (a, b) => (b.parsed.price || 0) - (a.parsed.price || 0)
|
|
275
218
|
: (a, b) => (a.parsed.price || 0) - (b.parsed.price || 0);
|
|
@@ -302,7 +245,7 @@ function _isGridEdgeFullyActive(manager, orderType, updateCount) {
|
|
|
302
245
|
return false;
|
|
303
246
|
// Sort: for BUY (highest to lowest price), for SELL (lowest to highest)
|
|
304
247
|
// This puts market edge first, grid edge (furthest) last
|
|
305
|
-
const sorted = orderType ===
|
|
248
|
+
const sorted = orderType === ORDER_TYPES.BUY
|
|
306
249
|
? allOrders.sort((a, b) => (b.price || 0) - (a.price || 0)) // Buy: high to low price
|
|
307
250
|
: allOrders.sort((a, b) => (a.price || 0) - (b.price || 0)); // Sell: low to high price
|
|
308
251
|
// Get the outermost orders (last N in sorted = furthest from market)
|
|
@@ -312,7 +255,7 @@ function _isGridEdgeFullyActive(manager, orderType, updateCount) {
|
|
|
312
255
|
// Empty array check prevents vacuous truth: every([]) returns true
|
|
313
256
|
if (edgeOrders.length === 0)
|
|
314
257
|
return false;
|
|
315
|
-
const allEdgeActive = edgeOrders.every((o) =>
|
|
258
|
+
const allEdgeActive = edgeOrders.every((o) => isOrderPlaced(o));
|
|
316
259
|
return allEdgeActive;
|
|
317
260
|
}
|
|
318
261
|
/**
|
|
@@ -394,7 +337,7 @@ async function _cancelLargestOrder({ chainOrders, account, privateKey, manager,
|
|
|
394
337
|
return { index: largestIndex, orderType };
|
|
395
338
|
}
|
|
396
339
|
catch (err) {
|
|
397
|
-
logger?.log?.(`Warning: Could not cancel largest order ${orderId}: ${
|
|
340
|
+
logger?.log?.(`Warning: Could not cancel largest order ${orderId}: ${getErrorMessage(err)}`, 'warn');
|
|
398
341
|
return null;
|
|
399
342
|
}
|
|
400
343
|
}
|
|
@@ -433,14 +376,14 @@ async function _createOrderFromGrid({ chainOrders, account, privateKey, manager,
|
|
|
433
376
|
`collides with placed order ${priceCollision.id} (${priceCollision.orderId}) at ${Format.formatPrice6(priceCollision.price)}`, 'warn');
|
|
434
377
|
return null;
|
|
435
378
|
}
|
|
436
|
-
const { amountToSell, sellAssetId, minToReceive, receiveAssetId } =
|
|
379
|
+
const { amountToSell, sellAssetId, minToReceive, receiveAssetId } = buildCreateOrderArgs(gridOrder, manager.assets.assetA, manager.assets.assetB);
|
|
437
380
|
const result = await chainOrders.createOrder(account, privateKey, amountToSell, sellAssetId, minToReceive, receiveAssetId, null, false, extraOptions);
|
|
438
381
|
if (result && result.skipped) {
|
|
439
382
|
const logger = manager && manager.logger;
|
|
440
383
|
logger?.log?.(`[_createOrderFromGrid] Skipped slot ${gridOrder.id}: order amounts too small to place on-chain`, 'warn');
|
|
441
384
|
return null;
|
|
442
385
|
}
|
|
443
|
-
const operationResults =
|
|
386
|
+
const operationResults = extractBatchOperationResults(result) || [];
|
|
444
387
|
const chainOrderId = operationResults[0] && operationResults[0][1];
|
|
445
388
|
if (chainOrderId) {
|
|
446
389
|
// Capture chain order ID BEFORE _applySync, so even if _applySync
|
|
@@ -448,7 +391,7 @@ async function _createOrderFromGrid({ chainOrders, account, privateKey, manager,
|
|
|
448
391
|
// will still know this order was legitimately created and avoid cancelling it.
|
|
449
392
|
const capturedId = chainOrderId;
|
|
450
393
|
try {
|
|
451
|
-
const btsFeeData =
|
|
394
|
+
const btsFeeData = getAssetFees('BTS');
|
|
452
395
|
await manager._applySync({
|
|
453
396
|
gridOrderId: gridOrder.id,
|
|
454
397
|
chainOrderId,
|
|
@@ -459,7 +402,7 @@ async function _createOrderFromGrid({ chainOrders, account, privateKey, manager,
|
|
|
459
402
|
}
|
|
460
403
|
catch (syncErr) {
|
|
461
404
|
const logger = manager && manager.logger;
|
|
462
|
-
logger?.log?.(`[_createOrderFromGrid] _applySync failed after successful broadcast for ${capturedId}: ${
|
|
405
|
+
logger?.log?.(`[_createOrderFromGrid] _applySync failed after successful broadcast for ${capturedId}: ${getErrorMessage(syncErr)}`, 'error');
|
|
463
406
|
// Run recovery sync to register the orphaned order. If this also
|
|
464
407
|
// fails (or the chain read is empty/truncated), the returned
|
|
465
408
|
// capturedId still prevents Phase 3 cancellation.
|
|
@@ -500,13 +443,13 @@ async function _createOrderFromGrid({ chainOrders, account, privateKey, manager,
|
|
|
500
443
|
// Note: caller does NOT hold _gridLock (Phase 2 runs outside lock),
|
|
501
444
|
// so we acquire it explicitly for the grid mutation.
|
|
502
445
|
try {
|
|
503
|
-
const zeroOrder =
|
|
446
|
+
const zeroOrder = convertToSpreadPlaceholder(gridOrder);
|
|
504
447
|
await manager._gridLock.acquire(async () => {
|
|
505
448
|
await manager._applyOrderUpdate(zeroOrder, 'createOrder-extraction-failure', { skipAccounting: true, fee: 0 });
|
|
506
449
|
});
|
|
507
450
|
}
|
|
508
451
|
catch (zeroErr) {
|
|
509
|
-
logger?.log?.(`[_createOrderFromGrid] Failed to zero slot ${gridOrder.id}: ${
|
|
452
|
+
logger?.log?.(`[_createOrderFromGrid] Failed to zero slot ${gridOrder.id}: ${getErrorMessage(zeroErr)}`, 'error');
|
|
510
453
|
}
|
|
511
454
|
}
|
|
512
455
|
}
|
|
@@ -531,33 +474,57 @@ async function _createOrderFromGrid({ chainOrders, account, privateKey, manager,
|
|
|
531
474
|
async function _cancelChainOrder({ chainOrders, account, privateKey, manager, chainOrderId, dryRun, chainOrderObj, releaseUntrackedFunds = false }) {
|
|
532
475
|
if (dryRun)
|
|
533
476
|
return;
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
477
|
+
// The snapshot this cancel is based on may be stale: another path (e.g. the
|
|
478
|
+
// sync-layer cancel-only correction) may already have cancelled the order and
|
|
479
|
+
// the wasRecentlyOwnCancelled 5s TTL lapsed before reconcile's Phase-2 ran.
|
|
480
|
+
// When releasing untracked funds, treat "order does not exist" as a successful
|
|
481
|
+
// cancel and still release the capital — otherwise the funds are stranded and
|
|
482
|
+
// the chainTotal = chainFree + chainCommitted invariant is violated. Non-release
|
|
483
|
+
// cancels (matched slots) keep the previous throw-and-log behavior.
|
|
484
|
+
let cancelResult = null;
|
|
485
|
+
let orderGone = false;
|
|
486
|
+
try {
|
|
487
|
+
cancelResult = await chainOrders.cancelOrder(account, privateKey, chainOrderId);
|
|
488
|
+
}
|
|
489
|
+
catch (cancelErr) {
|
|
490
|
+
const errMsg = getErrorMessage(cancelErr) || '';
|
|
491
|
+
if (releaseUntrackedFunds && isOrderGoneErrorMessage(errMsg)) {
|
|
492
|
+
orderGone = true;
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
throw cancelErr;
|
|
552
496
|
}
|
|
553
497
|
}
|
|
554
|
-
|
|
555
|
-
|
|
498
|
+
if (!orderGone) {
|
|
499
|
+
if (cancelResult?.verifiedAfterFailure) {
|
|
500
|
+
const recovered = await _recoverSyncFromChain({
|
|
501
|
+
chainOrders,
|
|
502
|
+
manager,
|
|
503
|
+
account,
|
|
504
|
+
logger: manager && manager.logger,
|
|
505
|
+
source: 'cancelOrder',
|
|
506
|
+
});
|
|
507
|
+
if (!recovered) {
|
|
508
|
+
// The cancellation was authoritatively confirmed absent inside
|
|
509
|
+
// cancelOrder, but the recovery refetch was skipped (empty/
|
|
510
|
+
// truncated read — ambiguous, so the full sync must NOT run) or
|
|
511
|
+
// failed. The order is provably gone, so apply the local cancel
|
|
512
|
+
// sync to release its capital and clear the slot — same fallback
|
|
513
|
+
// as the dust-cancel path. Skipping it would leave the slot stuck
|
|
514
|
+
// ACTIVE with a chain order that no longer exists.
|
|
515
|
+
await manager._applySync({ orderId: chainOrderId }, 'cancelOrder');
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
await manager._applySync({ orderId: chainOrderId }, 'cancelOrder');
|
|
520
|
+
}
|
|
556
521
|
}
|
|
522
|
+
// Resolved: forget any persistent-duplicate escalation counter for this orphan.
|
|
523
|
+
clearDuplicateOrphanDetection(chainOrderId);
|
|
557
524
|
// Unmatched chain orders are not represented as ACTIVE/PARTIAL grid slots, so
|
|
558
525
|
// synchronizeWithChain('cancelOrder') cannot release their commitment.
|
|
559
526
|
if (releaseUntrackedFunds && manager.accountant && chainOrderObj) {
|
|
560
|
-
const parsed =
|
|
527
|
+
const parsed = parseChainOrder(chainOrderObj, manager.assets);
|
|
561
528
|
if (parsed && parsed.size != null && parsed.size > 0) {
|
|
562
529
|
await manager._fundLock.acquire(async () => {
|
|
563
530
|
await manager.accountant.addToChainFree(parsed.type, parsed.size, 'startup-cancel-unmatched');
|
|
@@ -581,11 +548,11 @@ async function _recoverSyncFromChain({ chainOrders, manager, account, logger, so
|
|
|
581
548
|
try {
|
|
582
549
|
if (triggerMessage)
|
|
583
550
|
logger?.log?.(triggerMessage, 'warn');
|
|
584
|
-
const freshChainOrders = await
|
|
551
|
+
const freshChainOrders = await readOpenOrdersGuarded(chainOrders, resolveAccountRef(manager, account), {
|
|
585
552
|
log: (message, level) => logger?.log?.(message, level),
|
|
586
553
|
label: 'RECOVERY',
|
|
587
554
|
deferEmpty: true,
|
|
588
|
-
timeoutMs:
|
|
555
|
+
timeoutMs: TIMING.CONNECTION_TIMEOUT_MS,
|
|
589
556
|
skipMessage: skipMessage || 'Recovery sync skipped - empty/truncated chain read is ambiguous (node may be lagging, or the get_full_accounts window omitted fresh orders); deferring to next reconcile cycle',
|
|
590
557
|
});
|
|
591
558
|
if (freshChainOrders === null)
|
|
@@ -597,7 +564,7 @@ async function _recoverSyncFromChain({ chainOrders, manager, account, logger, so
|
|
|
597
564
|
return freshChainOrders;
|
|
598
565
|
}
|
|
599
566
|
catch (syncErr) {
|
|
600
|
-
logger?.log?.(`Recovery sync failed: ${
|
|
567
|
+
logger?.log?.(`Recovery sync failed: ${getErrorMessage(syncErr)}`, 'error');
|
|
601
568
|
return null;
|
|
602
569
|
}
|
|
603
570
|
}
|
|
@@ -647,12 +614,12 @@ function _prepareStartupUpdatePlan(plan, manager, logger) {
|
|
|
647
614
|
logger?.log?.(`Startup: Skip update ${chainOrderId} -> ${gridOrder.id}; slot already matched`, 'debug');
|
|
648
615
|
return null;
|
|
649
616
|
}
|
|
650
|
-
const { amountToSell, minToReceive } =
|
|
617
|
+
const { amountToSell, minToReceive } = buildCreateOrderArgs(gridOrder, manager.assets.assetA, manager.assets.assetB);
|
|
651
618
|
return {
|
|
652
619
|
plan,
|
|
653
620
|
chainOrderId,
|
|
654
621
|
gridOrder,
|
|
655
|
-
parsedChain:
|
|
622
|
+
parsedChain: parseChainOrder(plan.chainOrderObj, manager.assets),
|
|
656
623
|
updateParams: {
|
|
657
624
|
newPrice: gridOrder.price,
|
|
658
625
|
amountToSell,
|
|
@@ -676,8 +643,8 @@ async function _finalizeStartupUpdate({ manager, preparedUpdate }) {
|
|
|
676
643
|
const rawDeferredFee = plan.chainOrderObj?.deferred_fee != null
|
|
677
644
|
? Format.toFiniteNumber(plan.chainOrderObj?.deferred_fee, undefined)
|
|
678
645
|
: null;
|
|
679
|
-
const deferredFeeFloat = rawDeferredFee !== null ?
|
|
680
|
-
const btsFeeData =
|
|
646
|
+
const deferredFeeFloat = rawDeferredFee !== null ? blockchainToFloat(rawDeferredFee, BTS_PRECISION) : null;
|
|
647
|
+
const btsFeeData = getAssetFees('BTS');
|
|
681
648
|
await manager._applySync({
|
|
682
649
|
gridOrderId: plan.gridOrder.id,
|
|
683
650
|
chainOrderId: plan.chainOrderId,
|
|
@@ -726,7 +693,7 @@ async function _executeStartupUpdateBatch({ updatePlans, chainOrders, account, p
|
|
|
726
693
|
await _finalizeStartupUpdate({ manager, preparedUpdate: entry });
|
|
727
694
|
}
|
|
728
695
|
catch (finalizeErr) {
|
|
729
|
-
logger?.log?.(`Startup: Finalize failed for ${entry.plan.gridOrder.id}: ${
|
|
696
|
+
logger?.log?.(`Startup: Finalize failed for ${entry.plan.gridOrder.id}: ${getErrorMessage(finalizeErr)}`, 'error');
|
|
730
697
|
finalizeFailed = true;
|
|
731
698
|
}
|
|
732
699
|
}
|
|
@@ -794,7 +761,7 @@ async function _executeStartupSequentialUpdateFallback({ updatePlans, chainOrder
|
|
|
794
761
|
}
|
|
795
762
|
catch (err) {
|
|
796
763
|
failed++;
|
|
797
|
-
logger?.log?.(`Startup: Sequential update failed for ${plan.chainOrderId} -> ${plan.gridOrderId || plan.gridOrder?.id}: ${
|
|
764
|
+
logger?.log?.(`Startup: Sequential update failed for ${plan.chainOrderId} -> ${plan.gridOrderId || plan.gridOrder?.id}: ${getErrorMessage(err)}`, 'error');
|
|
798
765
|
const refreshedChainOrders = await _recoverStartupSyncFailure({
|
|
799
766
|
chainOrders,
|
|
800
767
|
manager,
|
|
@@ -829,9 +796,9 @@ async function _adoptPossiblyLandedCreate({ chainOrders, manager, account, gridO
|
|
|
829
796
|
// reads are indistinguishable from a lagging node that missed the
|
|
830
797
|
// just-broadcast transaction. Both are unverifiable; absence is only
|
|
831
798
|
// authoritative on a clean, non-empty read.
|
|
832
|
-
const freshChainOrders = await
|
|
799
|
+
const freshChainOrders = await readOpenOrdersGuarded(chainOrders, resolveAccountRef(manager, account), {
|
|
833
800
|
deferEmpty: true,
|
|
834
|
-
timeoutMs:
|
|
801
|
+
timeoutMs: TIMING.CONNECTION_TIMEOUT_MS,
|
|
835
802
|
});
|
|
836
803
|
if (freshChainOrders === null) {
|
|
837
804
|
return 'unknown';
|
|
@@ -841,12 +808,12 @@ async function _adoptPossiblyLandedCreate({ chainOrders, manager, account, gridO
|
|
|
841
808
|
return 'unknown';
|
|
842
809
|
let matched = null;
|
|
843
810
|
for (const o of freshChainOrders) {
|
|
844
|
-
const parsed =
|
|
811
|
+
const parsed = parseChainOrder(o, assets);
|
|
845
812
|
if (!parsed || parsed.type !== gridOrder.type)
|
|
846
813
|
continue;
|
|
847
814
|
if (parsed.orderId && Array.from(manager.orders.values()).some((g) => g.orderId === parsed.orderId))
|
|
848
815
|
continue;
|
|
849
|
-
if (!
|
|
816
|
+
if (!chainOrderMatchesSlot(parsed, gridOrder, assets))
|
|
850
817
|
continue;
|
|
851
818
|
matched = o;
|
|
852
819
|
break;
|
|
@@ -866,7 +833,7 @@ async function _adoptPossiblyLandedCreate({ chainOrders, manager, account, gridO
|
|
|
866
833
|
// batch path and the grid_reconcile adoption loop both apply it via
|
|
867
834
|
// _applySync(fee: createFee) — mirror that here so the optimistic
|
|
868
835
|
// balance reflects the real chain cost.
|
|
869
|
-
const btsFeeData =
|
|
836
|
+
const btsFeeData = getAssetFeesSafe('BTS');
|
|
870
837
|
await manager._applySync({
|
|
871
838
|
gridOrderId: gridOrder.id,
|
|
872
839
|
chainOrderId: matched.id,
|
|
@@ -877,7 +844,7 @@ async function _adoptPossiblyLandedCreate({ chainOrders, manager, account, gridO
|
|
|
877
844
|
return matched.id || null;
|
|
878
845
|
}
|
|
879
846
|
catch (adoptErr) {
|
|
880
|
-
manager?.logger?.log?.(`Startup: Uncertain-create adoption check failed for ${gridOrder?.id}: ${
|
|
847
|
+
manager?.logger?.log?.(`Startup: Uncertain-create adoption check failed for ${gridOrder?.id}: ${getErrorMessage(adoptErr)}`, 'warn');
|
|
881
848
|
return 'unknown';
|
|
882
849
|
}
|
|
883
850
|
}
|
|
@@ -893,7 +860,7 @@ async function _createStartupOrderWithHandling({ chainOrders, account, privateKe
|
|
|
893
860
|
}
|
|
894
861
|
catch (err) {
|
|
895
862
|
const isUncertain = err?.code === 'BROADCAST_UNCERTAIN' || err?.name === 'BroadcastUncertainError';
|
|
896
|
-
manager?.logger?.log?.(`Startup: Failed to create ${orderLabel} (attempt ${attempt}/${maxAttempts}${isUncertain ? ', uncertain broadcast' : ''}): ${
|
|
863
|
+
manager?.logger?.log?.(`Startup: Failed to create ${orderLabel} (attempt ${attempt}/${maxAttempts}${isUncertain ? ', uncertain broadcast' : ''}): ${getErrorMessage(err)}`, 'error');
|
|
897
864
|
if (!isUncertain)
|
|
898
865
|
break;
|
|
899
866
|
failedWithUncertain = true;
|
|
@@ -932,7 +899,7 @@ async function _createStartupOrderWithHandling({ chainOrders, account, privateKe
|
|
|
932
899
|
// _extractBatchOperationResults — thin wrapper over shared utility,
|
|
933
900
|
// returns empty array (not null) for callers that iterate directly.
|
|
934
901
|
function _extractBatchOperationResults(result) {
|
|
935
|
-
return
|
|
902
|
+
return extractBatchOperationResults(result) || [];
|
|
936
903
|
}
|
|
937
904
|
function _resolveGroupRecovery(group, fallbackMessage, fallbackSource) {
|
|
938
905
|
for (const plan of group || []) {
|
|
@@ -970,7 +937,7 @@ async function _executeStartupCreateGroupBatch({ group, chainOrders, account, pr
|
|
|
970
937
|
`at ${Format.formatPrice6(priceCollision.price)}`, 'warn');
|
|
971
938
|
continue;
|
|
972
939
|
}
|
|
973
|
-
const { amountToSell, sellAssetId, minToReceive, receiveAssetId } =
|
|
940
|
+
const { amountToSell, sellAssetId, minToReceive, receiveAssetId } = buildCreateOrderArgs(gridOrder, manager.assets.assetA, manager.assets.assetB);
|
|
974
941
|
const buildResult = await chainOrders.buildCreateOrderOp(account, amountToSell, sellAssetId, minToReceive, receiveAssetId, null);
|
|
975
942
|
if (!buildResult) {
|
|
976
943
|
logger?.log?.(`Startup: Skip create ${plan.orderLabel} - order amounts too small to place on-chain`, 'warn');
|
|
@@ -986,7 +953,7 @@ async function _executeStartupCreateGroupBatch({ group, chainOrders, account, pr
|
|
|
986
953
|
logger?.log?.(`Startup: Broadcasting create group ${groupIndex + 1}/${totalGroups} in single batch (${prepared.length} op${prepared.length > 1 ? 's' : ''})`, 'info');
|
|
987
954
|
const batchResult = await chainOrders.executeBatch(account, privateKey, prepared.map((p) => p.op));
|
|
988
955
|
const opResults = _extractBatchOperationResults(batchResult);
|
|
989
|
-
const btsFeeData =
|
|
956
|
+
const btsFeeData = getAssetFees('BTS');
|
|
990
957
|
// Phase A: Extract ALL chain order IDs from batch results first, capturing
|
|
991
958
|
// every on-chain ID before any _applySync call. This ensures createdOrderIds
|
|
992
959
|
// is complete even if a subsequent _applySync throws mid-loop.
|
|
@@ -1030,7 +997,7 @@ async function _executeStartupCreateGroupBatch({ group, chainOrders, account, pr
|
|
|
1030
997
|
}
|
|
1031
998
|
catch (err) {
|
|
1032
999
|
const isUncertain = err?.code === 'BROADCAST_UNCERTAIN' || err?.name === 'BroadcastUncertainError';
|
|
1033
|
-
logger?.log?.(`Startup: Failed to create group ${groupIndex + 1}/${totalGroups}${isUncertain ? ' (uncertain broadcast)' : ''}: ${
|
|
1000
|
+
logger?.log?.(`Startup: Failed to create group ${groupIndex + 1}/${totalGroups}${isUncertain ? ' (uncertain broadcast)' : ''}: ${getErrorMessage(err)}`, 'error');
|
|
1034
1001
|
if (isUncertain) {
|
|
1035
1002
|
// The batch may have landed despite the deadline. Verify on chain and
|
|
1036
1003
|
// adopt any landed orders via chain sync instead of blindly
|
|
@@ -1048,11 +1015,11 @@ async function _executeStartupCreateGroupBatch({ group, chainOrders, account, pr
|
|
|
1048
1015
|
// guarded recovery sync, which re-reads and only syncs on
|
|
1049
1016
|
// an authoritative snapshot (deferring to the next
|
|
1050
1017
|
// reconcile cycle otherwise).
|
|
1051
|
-
const freshChainOrders = await
|
|
1018
|
+
const freshChainOrders = await readOpenOrdersGuarded(chainOrders, resolveAccountRef(manager, account), {
|
|
1052
1019
|
log: (message, level) => logger?.log?.(message, level),
|
|
1053
1020
|
label: 'STARTUP',
|
|
1054
1021
|
deferEmpty: true,
|
|
1055
|
-
timeoutMs:
|
|
1022
|
+
timeoutMs: TIMING.CONNECTION_TIMEOUT_MS,
|
|
1056
1023
|
skipMessage: (kind) => `Startup: Uncertain create group ${groupIndex + 1}/${totalGroups} verification read is ` +
|
|
1057
1024
|
`${kind}; cannot confirm whether the batch landed - ` +
|
|
1058
1025
|
`deferring to guarded recovery sync (duplicate-order protection)`,
|
|
@@ -1080,7 +1047,7 @@ async function _executeStartupCreateGroupBatch({ group, chainOrders, account, pr
|
|
|
1080
1047
|
// for every group plan whose slot was adopted, and register
|
|
1081
1048
|
// the adopted IDs so the final refresh never cancels them
|
|
1082
1049
|
// as surplus.
|
|
1083
|
-
const btsFeeData =
|
|
1050
|
+
const btsFeeData = getAssetFeesSafe('BTS');
|
|
1084
1051
|
for (const item of prepared) {
|
|
1085
1052
|
const plan = item?.plan;
|
|
1086
1053
|
const slot = plan?.gridOrder?.id ? manager.orders.get(plan.gridOrder.id) : null;
|
|
@@ -1098,13 +1065,13 @@ async function _executeStartupCreateGroupBatch({ group, chainOrders, account, pr
|
|
|
1098
1065
|
logger?.log?.(`Startup: Uncertain create for ${plan.orderLabel} confirmed on chain (${slot.orderId}); adopted + accounted`, 'warn');
|
|
1099
1066
|
}
|
|
1100
1067
|
catch (applyErr) {
|
|
1101
|
-
logger?.log?.(`Startup: Adoption accounting failed for ${plan.orderLabel}: ${
|
|
1068
|
+
logger?.log?.(`Startup: Adoption accounting failed for ${plan.orderLabel}: ${getErrorMessage(applyErr)}`, 'warn');
|
|
1102
1069
|
}
|
|
1103
1070
|
}
|
|
1104
1071
|
}
|
|
1105
1072
|
}
|
|
1106
1073
|
catch (verifyErr) {
|
|
1107
|
-
logger?.log?.(`Startup: Uncertain group verification failed: ${
|
|
1074
|
+
logger?.log?.(`Startup: Uncertain group verification failed: ${getErrorMessage(verifyErr)}; falling back to recovery sync`, 'error');
|
|
1108
1075
|
await _recoverStartupSyncFailure({
|
|
1109
1076
|
chainOrders,
|
|
1110
1077
|
manager,
|
|
@@ -1129,7 +1096,7 @@ async function _executeStartupCreateGroupBatch({ group, chainOrders, account, pr
|
|
|
1129
1096
|
return createdOrderIds;
|
|
1130
1097
|
}
|
|
1131
1098
|
function _buildOutsideInCreateGroups(createPlans) {
|
|
1132
|
-
return
|
|
1099
|
+
return buildOutsideInPairGroups(createPlans, {
|
|
1133
1100
|
isValid: (p) => Boolean(p?.gridOrder),
|
|
1134
1101
|
getType: (p) => p.orderType,
|
|
1135
1102
|
getPrice: (p) => p.gridOrder?.price,
|
|
@@ -1187,9 +1154,9 @@ async function _executePlannedStartupCreates({ createPlans, chainOrders, account
|
|
|
1187
1154
|
}
|
|
1188
1155
|
async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders, unmatchedSideOrders, manager, chainOrders, account, privateKey, dryRun, plannedCreates, plannedUpdates, plannedCancels, planOnly = false, }) {
|
|
1189
1156
|
const logger = manager?.logger;
|
|
1190
|
-
const sideUpper = orderType ===
|
|
1191
|
-
const balanceKey = orderType ===
|
|
1192
|
-
const balanceSymbol = orderType ===
|
|
1157
|
+
const sideUpper = orderType === ORDER_TYPES.SELL ? 'SELL' : 'BUY';
|
|
1158
|
+
const balanceKey = orderType === ORDER_TYPES.SELL ? 'sellFree' : 'buyFree';
|
|
1159
|
+
const balanceSymbol = orderType === ORDER_TYPES.SELL ? manager.assets.assetA.symbol : manager.assets.assetB.symbol;
|
|
1193
1160
|
const { sortUpdateComparator, sortExcessCancelComparator, sortMatchedCancelComparator, } = _getStartupSideComparators(orderType, manager.assets);
|
|
1194
1161
|
const matchedOnGrid = _countActiveOnGrid(manager, orderType);
|
|
1195
1162
|
const neededSlots = Math.max(0, targetCount - matchedOnGrid);
|
|
@@ -1229,7 +1196,7 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1229
1196
|
const chainOrder = sortedUnmatched[i];
|
|
1230
1197
|
const gridOrder = desiredSlots[i];
|
|
1231
1198
|
const gridSize = Number(gridOrder.size) || 0;
|
|
1232
|
-
const parsedChain =
|
|
1199
|
+
const parsedChain = parseChainOrder(chainOrder, manager.assets);
|
|
1233
1200
|
const currentSize = parsedChain ? (parsedChain.size ?? 0) : 0;
|
|
1234
1201
|
const sizeIncrease = Math.max(0, gridSize - currentSize);
|
|
1235
1202
|
const currentAssetBalance = projectedSideBalance;
|
|
@@ -1294,7 +1261,7 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1294
1261
|
}
|
|
1295
1262
|
if (cancelCount > 0) {
|
|
1296
1263
|
const parsedUnmatched = processedUnmatched
|
|
1297
|
-
.map((co) => ({ chain: co, parsed:
|
|
1264
|
+
.map((co) => ({ chain: co, parsed: parseChainOrder(co, manager.assets) }))
|
|
1298
1265
|
.filter((x) => x.parsed)
|
|
1299
1266
|
.sort(sortExcessCancelComparator);
|
|
1300
1267
|
if (planOnly) {
|
|
@@ -1334,11 +1301,11 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1334
1301
|
cancelCount--;
|
|
1335
1302
|
}
|
|
1336
1303
|
catch (err) {
|
|
1337
|
-
logger?.log?.(`Startup: Failed to cancel ${sideUpper} ${x.chain.id}: ${
|
|
1304
|
+
logger?.log?.(`Startup: Failed to cancel ${sideUpper} ${x.chain.id}: ${getErrorMessage(err)}`, 'error');
|
|
1338
1305
|
}
|
|
1339
1306
|
}
|
|
1340
1307
|
if (cancelCount > 0) {
|
|
1341
|
-
const activeOrders = manager.getOrdersByTypeAndState(orderType,
|
|
1308
|
+
const activeOrders = manager.getOrdersByTypeAndState(orderType, ORDER_STATES.ACTIVE)
|
|
1342
1309
|
.filter((o) => o && o.orderId)
|
|
1343
1310
|
.sort(sortMatchedCancelComparator);
|
|
1344
1311
|
for (const o of activeOrders) {
|
|
@@ -1351,7 +1318,7 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1351
1318
|
cancelCount--;
|
|
1352
1319
|
}
|
|
1353
1320
|
catch (err) {
|
|
1354
|
-
logger?.log?.(`Startup: Failed to cancel matched ${sideUpper} ${o.orderId}: ${
|
|
1321
|
+
logger?.log?.(`Startup: Failed to cancel matched ${sideUpper} ${o.orderId}: ${getErrorMessage(err)}`, 'error');
|
|
1355
1322
|
}
|
|
1356
1323
|
}
|
|
1357
1324
|
}
|
|
@@ -1361,4 +1328,5 @@ async function _reconcileStartupSide({ orderType, targetCount, chainSideOrders,
|
|
|
1361
1328
|
chainCount,
|
|
1362
1329
|
};
|
|
1363
1330
|
}
|
|
1331
|
+
export { _countActiveOnGrid, _pickVirtualSlotsToActivate, _getStartupSideComparators, _isGridEdgeFullyActive, _findLargestOrder, _cancelLargestOrder, _createOrderFromGrid, _cancelChainOrder, _recoverStartupSyncFailure, _refreshStartupUpdatePlans, _prepareStartupUpdatePlan, _finalizeStartupUpdate, _executeStartupUpdateBatch, _executeStartupSingleUpdate, _executeStartupSequentialUpdateFallback, _createStartupOrderWithHandling, _extractBatchOperationResults, _resolveGroupRecovery, _executeStartupCreateGroupBatch, _buildOutsideInCreateGroups, _executePlannedStartupCreates, _reconcileStartupSide };
|
|
1364
1332
|
//# sourceMappingURL=grid_reconcile_internal.js.map
|