dexbot 1.6.7 → 1.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -1
- package/README.md +3 -3
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +22 -6
- package/dist/market_adapter/core/market_adapter_service.js +14 -2
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/market_adapter.d.ts +8 -1
- package/dist/market_adapter/market_adapter.js +22 -4
- package/dist/modules/account_bots.js +10 -0
- package/dist/modules/account_orders.d.ts +24 -2
- package/dist/modules/account_orders.js +41 -4
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.js +1 -0
- package/dist/modules/constants.d.ts +11 -3
- package/dist/modules/constants.js +116 -37
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +4 -87
- package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
- package/dist/modules/dexbot_maintenance_runtime.js +59 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +21 -0
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +76 -134
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +2 -2
- package/dist/modules/order/manager.d.ts +4 -0
- package/dist/modules/order/manager.js +14 -1
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +220 -197
- package/dist/modules/order/utils/system.js +8 -1
- package/dist/modules/paths.d.ts +1 -0
- package/dist/modules/paths.js +1 -0
- package/dist/modules/version_notice.d.ts +165 -0
- package/dist/modules/version_notice.js +364 -0
- package/dist/pm2.js +9 -0
- package/dist/unlock.js +28 -0
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +3 -2
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +20 -19
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +149 -31
- package/docs/GRID_RECALCULATION.md +12 -0
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +1 -1
- package/modules/README.md +18 -1
- package/package.json +13 -5
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- 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 -128
- 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 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/cli_start_onboarding.d.ts.map +0 -1
- package/dist/modules/cli_start_onboarding.js.map +0 -1
- package/dist/modules/cli_start_output.d.ts.map +0 -1
- package/dist/modules/cli_start_output.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/utils/text_width.d.ts.map +0 -1
- package/dist/modules/utils/text_width.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
*
|
|
11
11
|
* SECTION 1: CHAIN ORDER MATCHING & RECONCILIATION (5 functions)
|
|
12
12
|
* - parseChainOrder(chainOrder, assets) - Parse blockchain order to grid format
|
|
13
|
-
* - findMatchingGridOrderByOpenOrder(parsedChainOrder, opts) - Find matching grid order
|
|
14
13
|
* - applyChainSizeToGridOrder(manager, gridOrder, chainSize) - Apply chain size to grid
|
|
15
14
|
* - correctOrderPriceOnChain(manager, correctionInfo, ...) - Correct order price on chain
|
|
16
15
|
* - correctAllPriceMismatches(manager, accountName, ...) - Correct all price mismatches
|
|
@@ -63,10 +62,10 @@
|
|
|
63
62
|
* SECTION 10: STRATEGY CALCULATIONS (7 functions)
|
|
64
63
|
* - resolveReserveCount(config, side) - Clamped per-side reserve count (>=0 int, 0 disables)
|
|
65
64
|
* - resolveReserveOrders(config) - Total reserves buy+sell (fee/count totals)
|
|
66
|
-
* - resolveLiveReserveEdgeAnchorPrice(manager, side) - Live-grid edge anchor (ladder
|
|
65
|
+
* - resolveLiveReserveEdgeAnchorPrice(manager, side) - Live-grid edge anchor (genesis ladder extreme; null when no usable ladder)
|
|
67
66
|
* - resolveReserveEdgeAnchorPrice(config, side) - Config-bound anchor fallback (buy→minPrice, sell→maxPrice; null when unresolvable)
|
|
68
67
|
* - compareReserveEdge(a, b, edge, anchorPrice) - Shared anchored edge comparator (single ordering source)
|
|
69
|
-
* - reserveEdgeIdSet(allSlots, config, orderType, anchorPrice?) - Edge reserve id set (config count; shares the picker ordering)
|
|
68
|
+
* - reserveEdgeIdSet(allSlots, config, orderType, anchorPrice?, excludeIds?) - Edge reserve id set (config count; shares the picker ordering; excludeIds carries the window exclusion)
|
|
70
69
|
* - selectReserveEdgeSlots(sortedAsc, count, excludeIds, edge, anchorPrice?) - Shared position picker (both edges anchor toward their bound)
|
|
71
70
|
*
|
|
72
71
|
* ===============================================================================
|
|
@@ -77,6 +76,7 @@ import * as MathUtils from './math.js';
|
|
|
77
76
|
import Logger from '../../order/logger.js';
|
|
78
77
|
import { sleep } from './system.js';
|
|
79
78
|
import { getErrorMessage } from '../../utils/errors.js';
|
|
79
|
+
import { hasGenesisLadder } from '../genesis_policy.js';
|
|
80
80
|
import { parseSlotIndex as parseSlotIndexShared } from './slot.js';
|
|
81
81
|
const { isValidNumber, toFiniteNumber } = Format;
|
|
82
82
|
const { blockchainToFloat, floatToBlockchainInt, quantizeFloat, priceSlotEqual } = MathUtils;
|
|
@@ -264,10 +264,10 @@ function findLiveOrderOwnerByChainId(manager, chainOrderId, slotId) {
|
|
|
264
264
|
* An entry is actionable only when the live slot:
|
|
265
265
|
* 1. still exists in the master grid,
|
|
266
266
|
* 2. still owns this chainOrderId (not re-slotted / adopted elsewhere),
|
|
267
|
-
* 3. still targets the queued price —
|
|
268
|
-
*
|
|
269
|
-
* uses)
|
|
270
|
-
*
|
|
267
|
+
* 3. still targets the queued price — priceSlotEqual against the slot's own
|
|
268
|
+
* level (the same integer-round-trip predicate the pass-1 detector
|
|
269
|
+
* uses). A ladder-less manager is an INV-GRID-004 fault, so the entry is
|
|
270
|
+
* dropped rather than matched by tolerance.
|
|
271
271
|
*
|
|
272
272
|
* Cancel-only duplicate-orphan decisions need an ownership check. They are
|
|
273
273
|
* queued when a chain order has no matching grid slot, but startup reconcile
|
|
@@ -335,21 +335,17 @@ function _validatePriceCorrectionEntry(manager, entry) {
|
|
|
335
335
|
}
|
|
336
336
|
const assets = manager?.assets;
|
|
337
337
|
const precision = entry.type === ORDER_TYPES.SELL ? assets?.assetA?.precision : assets?.assetB?.precision;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
catch {
|
|
350
|
-
priceMatches = slot.price === entry.expectedPrice;
|
|
351
|
-
}
|
|
352
|
-
if (!priceMatches) {
|
|
338
|
+
// A correction is stale when the slot no longer targets the price it was
|
|
339
|
+
// queued for. That is integer equality at the asset precision (the slot's
|
|
340
|
+
// level is its ladder level). A ladder-less manager is an INV-GRID-004
|
|
341
|
+
// fault: no slot has a price authority, so the entry cannot be validated
|
|
342
|
+
// and is dropped. The E2 sync gate refuses such a grid outright (queues
|
|
343
|
+
// nothing); it is the structural resync that restores the ladder, after
|
|
344
|
+
// which a later sync re-evaluates the slot.
|
|
345
|
+
if (!hasGenesisLadder(manager?._genesis)) {
|
|
346
|
+
return { valid: false, reason: `no price ladder (INV-GRID-004) — slot ${slotId} has no authoritative price` };
|
|
347
|
+
}
|
|
348
|
+
if (!priceSlotEqual(slot.price, entry.expectedPrice, precision)) {
|
|
353
349
|
return { valid: false, reason: `slot ${slotId} now targets ${slot.price} (entry queued ${entry.expectedPrice})` };
|
|
354
350
|
}
|
|
355
351
|
// Size check: the broadcast sends amountToSell from the QUEUED snapshot.
|
|
@@ -422,74 +418,6 @@ function parseChainOrder(chainOrder, assets) {
|
|
|
422
418
|
}
|
|
423
419
|
return { orderId: chainOrder.id, price, type, size };
|
|
424
420
|
}
|
|
425
|
-
/**
|
|
426
|
-
* Find grid order matching a blockchain order.
|
|
427
|
-
* First tries exact orderId match, then falls back to price/size matching within tolerance.
|
|
428
|
-
* Used during synchronization to link blockchain orders to grid slots.
|
|
429
|
-
*
|
|
430
|
-
* @param {Object} parsedChainOrder - Parsed blockchain order {orderId, price, type, size}
|
|
431
|
-
* @param {Object} [opts={}] - Options object
|
|
432
|
-
* @param {Map} [opts.orders] - Grid orders map to search
|
|
433
|
-
* @param {Object} [opts.assets] - Asset metadata for precision
|
|
434
|
-
* @param {Function} [opts.calcToleranceFn] - Function to calculate price tolerance
|
|
435
|
-
* @param {Object} [opts.logger] - Optional logger
|
|
436
|
-
* @param {boolean} [opts.skipSizeMatch=false] - Skip size matching check
|
|
437
|
-
* @param {boolean} [opts.allowSmallerChainSize=false] - Allow chain order to be smaller
|
|
438
|
-
* @param {boolean} [opts.requireAvailableSlot=false] - Skip slots already bound to a different chain order
|
|
439
|
-
* @param {Set<string>} [opts.excludeGridOrderIds] - Skip grid slot ids already assigned in this sync pass
|
|
440
|
-
* @returns {Object|null} Matching grid order or null if no match found
|
|
441
|
-
*/
|
|
442
|
-
function findMatchingGridOrderByOpenOrder(parsedChainOrder, opts) {
|
|
443
|
-
const { orders, assets, calcToleranceFn } = opts || {};
|
|
444
|
-
if (!parsedChainOrder || !orders)
|
|
445
|
-
return null;
|
|
446
|
-
if (parsedChainOrder.orderId) {
|
|
447
|
-
for (const gridOrder of orders.values()) {
|
|
448
|
-
if (gridOrder?.orderId === parsedChainOrder.orderId)
|
|
449
|
-
return gridOrder;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
const chainSize = toFiniteNumber(parsedChainOrder.size);
|
|
453
|
-
const chainPrice = toFiniteNumber(parsedChainOrder.price);
|
|
454
|
-
const isSell = parsedChainOrder.type === ORDER_TYPES.SELL;
|
|
455
|
-
const precision = isSell ? assets?.assetA?.precision : assets?.assetB?.precision;
|
|
456
|
-
if (typeof precision !== 'number')
|
|
457
|
-
return null;
|
|
458
|
-
const chainInt = floatToBlockchainInt(chainSize, precision);
|
|
459
|
-
let bestMatch = null;
|
|
460
|
-
let bestPriceDiff = Infinity;
|
|
461
|
-
for (const gridOrder of orders.values()) {
|
|
462
|
-
const typeMatch = gridOrder?.type === parsedChainOrder.type ||
|
|
463
|
-
(opts?.allowSpreadType && gridOrder?.type === ORDER_TYPES.SPREAD);
|
|
464
|
-
if (!gridOrder || !typeMatch)
|
|
465
|
-
continue;
|
|
466
|
-
if (opts?.excludeGridOrderIds?.has?.(gridOrder.id))
|
|
467
|
-
continue;
|
|
468
|
-
if (![ORDER_STATES.ACTIVE, ORDER_STATES.PARTIAL, ORDER_STATES.VIRTUAL].includes(gridOrder.state))
|
|
469
|
-
continue;
|
|
470
|
-
if (opts?.requireAvailableSlot && gridOrder.orderId && gridOrder.orderId !== parsedChainOrder.orderId)
|
|
471
|
-
continue;
|
|
472
|
-
const priceDiff = Math.abs(gridOrder.price - chainPrice);
|
|
473
|
-
// Virtual/spread slots have size=0 — fall back to chain order's size so the
|
|
474
|
-
// precision-based tolerance is meaningful instead of collapsing to 0.
|
|
475
|
-
const effectiveSize = gridOrder.size > 0 ? gridOrder.size : chainSize;
|
|
476
|
-
// When calcToleranceFn returns null (e.g. zero-size virtual slot), fall back to
|
|
477
|
-
// exact matching (tolerance=0). This is intentional — virtual/spread slots should
|
|
478
|
-
// only match chain orders at exactly their grid price.
|
|
479
|
-
const priceTolerance = calcToleranceFn?.(gridOrder.price, effectiveSize, parsedChainOrder.type) || 0;
|
|
480
|
-
if (priceDiff > priceTolerance)
|
|
481
|
-
continue;
|
|
482
|
-
const gridInt = floatToBlockchainInt(gridOrder.size, precision);
|
|
483
|
-
const sizeMismatch = opts?.allowSmallerChainSize ? (chainInt > gridInt + 1) : (Math.abs(gridInt - chainInt) > 1);
|
|
484
|
-
if (!opts?.skipSizeMatch && sizeMismatch)
|
|
485
|
-
continue;
|
|
486
|
-
if (priceDiff < bestPriceDiff) {
|
|
487
|
-
bestPriceDiff = priceDiff;
|
|
488
|
-
bestMatch = gridOrder;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return bestMatch;
|
|
492
|
-
}
|
|
493
421
|
/**
|
|
494
422
|
* Update grid order size based on blockchain state.
|
|
495
423
|
* Detects partial fills and updates accounting if size changed.
|
|
@@ -844,22 +772,40 @@ async function _batchCancelCorrections(manager, entries, accountName, privateKey
|
|
|
844
772
|
return { corrected, failed, unresolved };
|
|
845
773
|
}
|
|
846
774
|
/**
|
|
847
|
-
* Resolve the
|
|
775
|
+
* Resolve the wall-clock budget for the sequential price-update drain in
|
|
848
776
|
* correctAllPriceMismatches. Cancel-class entries are never budgeted; only
|
|
849
|
-
* the SYNC_DELAY_MS-spaced update loop is bounded so an unbounded backlog
|
|
777
|
+
* the SYNC_DELAY_MS-spaced update loop is bounded, so an unbounded backlog
|
|
850
778
|
* cannot hold _gridLock (no acquisition timeout) for minutes. Reads the bot
|
|
851
|
-
* config override first, then the frozen default. Non-finite
|
|
852
|
-
*
|
|
779
|
+
* config override first, then the frozen default. Non-finite/non-positive
|
|
780
|
+
* falls back to the frozen default, then to 4000ms.
|
|
853
781
|
* @param {any} manager
|
|
854
|
-
* @returns {number}
|
|
782
|
+
* @returns {number} Positive hold budget in milliseconds
|
|
783
|
+
*/
|
|
784
|
+
function resolveCorrectionHoldBudget(manager) {
|
|
785
|
+
const raw = manager?.config?.fillProcessing?.CORRECTION_LOCK_HOLD_BUDGET_MS
|
|
786
|
+
?? FILL_PROCESSING?.CORRECTION_LOCK_HOLD_BUDGET_MS;
|
|
787
|
+
const n = Number(raw);
|
|
788
|
+
if (Number.isFinite(n) && n > 0)
|
|
789
|
+
return Math.floor(n);
|
|
790
|
+
return 4000;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Resolve the optional hard cap on price updates drained per cycle. Layered
|
|
794
|
+
* on top of the hold-time budget: unset (null/undefined/non-finite) means no
|
|
795
|
+
* count cap and the elapsed-time budget alone governs; a finite value >= 0 is
|
|
796
|
+
* honored verbatim (0 intentionally drains no updates this cycle).
|
|
797
|
+
* @param {any} manager
|
|
798
|
+
* @returns {number} Finite cap, or Infinity when uncapped
|
|
855
799
|
*/
|
|
856
|
-
function
|
|
800
|
+
function resolveCorrectionMaxUpdates(manager) {
|
|
857
801
|
const raw = manager?.config?.fillProcessing?.CORRECTION_MAX_UPDATES_PER_CYCLE
|
|
858
802
|
?? FILL_PROCESSING?.CORRECTION_MAX_UPDATES_PER_CYCLE;
|
|
803
|
+
if (raw == null)
|
|
804
|
+
return Infinity;
|
|
859
805
|
const n = Number(raw);
|
|
860
806
|
if (Number.isFinite(n) && n >= 0)
|
|
861
807
|
return Math.floor(n);
|
|
862
|
-
return
|
|
808
|
+
return Infinity;
|
|
863
809
|
}
|
|
864
810
|
/**
|
|
865
811
|
* Resolve the correction-backlog warn threshold (see
|
|
@@ -982,28 +928,50 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
|
|
|
982
928
|
// durably and re-drains next cycle.
|
|
983
929
|
const cancelEntries = liveEntries.filter((c) => c.cancelOnly === true || c.isSurplus === true);
|
|
984
930
|
const updateEntries = liveEntries.filter((c) => !(c.cancelOnly === true || c.isSurplus === true));
|
|
985
|
-
const updateBudget = resolveCorrectionUpdateBudget(manager);
|
|
986
|
-
const budgetedUpdates = updateEntries.slice(0, updateBudget);
|
|
987
|
-
const deferredUpdates = updateEntries.length - budgetedUpdates.length;
|
|
988
931
|
const canBatch = cancelEntries.length > 1
|
|
989
932
|
&& typeof accountOrders?.buildCancelOrderOp === 'function'
|
|
990
933
|
&& typeof accountOrders?.executeBatch === 'function';
|
|
991
|
-
let
|
|
934
|
+
let serialCancels = cancelEntries;
|
|
992
935
|
if (canBatch) {
|
|
993
936
|
const batchOutcome = await _batchCancelCorrections(manager, cancelEntries, accountName, privateKey, accountOrders);
|
|
994
937
|
corrected += batchOutcome.corrected;
|
|
995
938
|
failed += batchOutcome.failed;
|
|
996
|
-
// Unresolved cancels still serialize (they must not be dropped)
|
|
997
|
-
|
|
998
|
-
|
|
939
|
+
// Unresolved cancels still serialize (they must not be dropped).
|
|
940
|
+
serialCancels = batchOutcome.unresolved;
|
|
941
|
+
}
|
|
942
|
+
for (const correctionInfo of serialCancels) {
|
|
943
|
+
const result = await correctOrderPriceOnChain(manager, correctionInfo, accountName, privateKey, accountOrders);
|
|
944
|
+
results.push({ ...correctionInfo, result });
|
|
945
|
+
if (result && result.success)
|
|
946
|
+
corrected++;
|
|
947
|
+
else
|
|
948
|
+
failed++;
|
|
949
|
+
await sleep(TIMING.SYNC_DELAY_MS);
|
|
999
950
|
}
|
|
1000
|
-
|
|
951
|
+
// Price updates are bounded by wall-clock lock-hold budget (primary)
|
|
952
|
+
// plus an optional hard count cap. The window opens *after* cancels so
|
|
953
|
+
// fund-critical cancels are never delayed by the update budget, and it
|
|
954
|
+
// is measured from the clock rather than a fixed count so a slow chain
|
|
955
|
+
// (large RPC round-trip) drains fewer updates instead of holding
|
|
956
|
+
// _gridLock past the 20s fill-lock timeout. Leftovers stay queued in
|
|
957
|
+
// order for the next cycle.
|
|
958
|
+
const holdBudgetMs = resolveCorrectionHoldBudget(manager);
|
|
959
|
+
const maxUpdates = resolveCorrectionMaxUpdates(manager);
|
|
960
|
+
const updateDeadline = Date.now() + holdBudgetMs;
|
|
961
|
+
let updatesProcessed = 0;
|
|
962
|
+
let deferredUpdates = 0;
|
|
963
|
+
for (const correctionInfo of updateEntries) {
|
|
964
|
+
if (updatesProcessed >= maxUpdates || Date.now() >= updateDeadline) {
|
|
965
|
+
deferredUpdates++;
|
|
966
|
+
continue;
|
|
967
|
+
}
|
|
1001
968
|
const result = await correctOrderPriceOnChain(manager, correctionInfo, accountName, privateKey, accountOrders);
|
|
1002
969
|
results.push({ ...correctionInfo, result });
|
|
1003
970
|
if (result && result.success)
|
|
1004
971
|
corrected++;
|
|
1005
972
|
else
|
|
1006
973
|
failed++;
|
|
974
|
+
updatesProcessed++;
|
|
1007
975
|
await sleep(TIMING.SYNC_DELAY_MS);
|
|
1008
976
|
}
|
|
1009
977
|
// Persist master grid mutations from surplus-type-mismatch cancellations.
|
|
@@ -1018,7 +986,8 @@ async function correctAllPriceMismatches(manager, accountName, privateKey, accou
|
|
|
1018
986
|
? manager.ordersNeedingPriceCorrection.length
|
|
1019
987
|
: 0;
|
|
1020
988
|
manager?.logger?.log?.(`[CORRECTION] Deferred ${deferredUpdates} price update(s) to the next cycle ` +
|
|
1021
|
-
`(budget ${
|
|
989
|
+
`(hold budget ${holdBudgetMs}ms${Number.isFinite(maxUpdates) ? `, cap ${maxUpdates}` : ''}, ` +
|
|
990
|
+
`${queuedAfter} still queued)`, 'info');
|
|
1022
991
|
}
|
|
1023
992
|
return { corrected, failed, results, staleDropped, deferredUpdates };
|
|
1024
993
|
});
|
|
@@ -1602,6 +1571,8 @@ function isNonBlockingUnmatchedOrder(order) {
|
|
|
1602
1571
|
* - `boundary-unknown-deferred`: gap geometry is unknown pre-boundary; the
|
|
1603
1572
|
* comment at sync_engine.ts names the accepted cost as one sync cycle
|
|
1604
1573
|
* after the boundary commits. Self-resolving, not stranded.
|
|
1574
|
+
* - `no-genesis-deferred`: included deliberately — a ladder-less grid is
|
|
1575
|
+
* repaired by exactly the reload this escalation performs.
|
|
1605
1576
|
*
|
|
1606
1577
|
* Anything not listed is treated as NOT escalatable, so a future transient
|
|
1607
1578
|
* reason is excluded by default rather than silently becoming a resync
|
|
@@ -1610,6 +1581,9 @@ function isNonBlockingUnmatchedOrder(order) {
|
|
|
1610
1581
|
const STRANDED_HOLD_REASONS = new Set([
|
|
1611
1582
|
'out-of-rail-deferred',
|
|
1612
1583
|
'out-of-grid-deferred',
|
|
1584
|
+
// Undefined grid (INV-GRID-004): a reload/rebuild IS the remedy, so this
|
|
1585
|
+
// hold escalates rather than sitting until a fill happens to trigger one.
|
|
1586
|
+
'no-genesis-deferred',
|
|
1613
1587
|
]);
|
|
1614
1588
|
/**
|
|
1615
1589
|
* @param {Object} order - Unmatched chain order entry.
|
|
@@ -1865,6 +1839,23 @@ function checkSizeThreshold(sizes, threshold, precision, includeNonFinite = fals
|
|
|
1865
1839
|
function checkSizesBeforeMinimum(sizes, minSize, precision) {
|
|
1866
1840
|
return checkSizeThreshold(sizes, minSize, precision, true);
|
|
1867
1841
|
}
|
|
1842
|
+
/**
|
|
1843
|
+
* Bounded rail-center index for a slot array of `length` with `gapSlots`.
|
|
1844
|
+
* The same fallback used by `calculateIdealBoundary` (non-numeric reference)
|
|
1845
|
+
* and `deriveTargetBoundary` (Tier-4 recovery): never a rail edge, wrong by
|
|
1846
|
+
* at most half the rail. Shared so the two spellings cannot drift.
|
|
1847
|
+
*
|
|
1848
|
+
* @param {number} length - Slot count
|
|
1849
|
+
* @param {number} gapSlots - Gap band size
|
|
1850
|
+
* @returns {number} Clamped center index (0 when the rail is empty)
|
|
1851
|
+
*/
|
|
1852
|
+
function railCenterIndex(length, gapSlots) {
|
|
1853
|
+
const len = Number(length);
|
|
1854
|
+
if (!Number.isFinite(len) || len <= 0)
|
|
1855
|
+
return 0;
|
|
1856
|
+
const gap = Number.isFinite(Number(gapSlots)) && Number(gapSlots) >= 0 ? Math.floor(Number(gapSlots)) : 0;
|
|
1857
|
+
return Math.max(0, Math.floor((len - 1 - gap) / 2));
|
|
1858
|
+
}
|
|
1868
1859
|
/**
|
|
1869
1860
|
* Calculate ideal grid boundary based on reference price.
|
|
1870
1861
|
* Places boundary near reference price with gap spacing in mind.
|
|
@@ -1885,8 +1876,7 @@ function calculateIdealBoundary(allSlots, referencePrice, gapSlots) {
|
|
|
1885
1876
|
if (!allSlots || allSlots.length === 0)
|
|
1886
1877
|
return -1;
|
|
1887
1878
|
if (!Number.isFinite(Number(referencePrice))) {
|
|
1888
|
-
|
|
1889
|
-
return Math.max(0, Math.floor((allSlots.length - 1 - gap) / 2));
|
|
1879
|
+
return railCenterIndex(allSlots.length, gapSlots);
|
|
1890
1880
|
}
|
|
1891
1881
|
let splitIdx = allSlots.findIndex((s) => s.price >= referencePrice);
|
|
1892
1882
|
if (splitIdx === -1)
|
|
@@ -2304,8 +2294,7 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
|
|
|
2304
2294
|
// never a rail-edge fabrication. The next fill batch re-anchors
|
|
2305
2295
|
// from live prices via Tier 1.
|
|
2306
2296
|
if (referencePrice === null && Array.isArray(allSlots) && allSlots.length > 0) {
|
|
2307
|
-
const
|
|
2308
|
-
const centerIdx = Math.max(0, Math.floor((allSlots.length - 1 - gap) / 2));
|
|
2297
|
+
const centerIdx = railCenterIndex(allSlots.length, gapSlots);
|
|
2309
2298
|
const centerPrice = Number(allSlots[centerIdx]?.price);
|
|
2310
2299
|
if (Number.isFinite(centerPrice))
|
|
2311
2300
|
referencePrice = centerPrice;
|
|
@@ -2332,8 +2321,19 @@ function deriveTargetBoundary(fills, currentBoundaryIdx, allSlots, config, gapSl
|
|
|
2332
2321
|
// `edgeAnchors` (resolveLiveReserveEdgeAnchorPrice) is the same anchor the
|
|
2333
2322
|
// placement sites use; without it the classification falls back to the
|
|
2334
2323
|
// config-bound anchor, which can disagree with the slots actually placed.
|
|
2335
|
-
|
|
2336
|
-
|
|
2324
|
+
// The window exclusion is the same one every placement picker applies: a
|
|
2325
|
+
// window that reaches the grid edge (e.g. a keep-low window sitting on
|
|
2326
|
+
// the floor) must not let the edge pick land on window members — otherwise
|
|
2327
|
+
// a genuine window fill is treated as a static reserve fill and never
|
|
2328
|
+
// crawls, and the hole is refilled same-side. Unknown geometry
|
|
2329
|
+
// (null boundary) fails open to the previous classification.
|
|
2330
|
+
const windowBoundaryIdx = (currentBoundaryIdx === null || currentBoundaryIdx === undefined)
|
|
2331
|
+
? newBoundaryIdx
|
|
2332
|
+
: currentBoundaryIdx;
|
|
2333
|
+
const windowBuyIds = windowIdSetFromSlots(allSlots, config, ORDER_TYPES.BUY, windowBoundaryIdx, gapSlots);
|
|
2334
|
+
const windowSellIds = windowIdSetFromSlots(allSlots, config, ORDER_TYPES.SELL, windowBoundaryIdx, gapSlots);
|
|
2335
|
+
const reserveBuyIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null, windowBuyIds);
|
|
2336
|
+
const reserveSellIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.SELL, edgeAnchors?.sell ?? null, windowSellIds);
|
|
2337
2337
|
// Pending crawls: fills recorded by earlier batches whose derivation
|
|
2338
2338
|
// never committed (refused broadcast, P4 abort, or pre-restart loss —
|
|
2339
2339
|
// the Sep-10 case: 4 fills consumed under a null boundary, crawl lost,
|
|
@@ -2461,8 +2461,13 @@ export function consumePendingFillCrawls(manager) {
|
|
|
2461
2461
|
// two disagree: the config-bound fallback is null for mode-string/relative
|
|
2462
2462
|
// bounds, so a restart would rank a stale below-rail slot as a reserve and
|
|
2463
2463
|
// silently drop a crawl the live run recorded as ordinary market movement.
|
|
2464
|
-
|
|
2465
|
-
|
|
2464
|
+
// The window exclusion must match placement too (same source as the count
|
|
2465
|
+
// fix) — a window over the reserve edge must not be read as a reserve, or
|
|
2466
|
+
// its owed crawl is dropped instead of applied.
|
|
2467
|
+
const windowBuyIds = liveWindowIdSet(manager, ORDER_TYPES.BUY);
|
|
2468
|
+
const windowSellIds = liveWindowIdSet(manager, ORDER_TYPES.SELL);
|
|
2469
|
+
const reserveBuyIds = reserveEdgeIdSet(slots, config, ORDER_TYPES.BUY, resolveLiveReserveEdgeAnchorPrice(manager, 'buy'), windowBuyIds);
|
|
2470
|
+
const reserveSellIds = reserveEdgeIdSet(slots, config, ORDER_TYPES.SELL, resolveLiveReserveEdgeAnchorPrice(manager, 'sell'), windowSellIds);
|
|
2466
2471
|
let netShift = 0;
|
|
2467
2472
|
let count = 0;
|
|
2468
2473
|
for (const e of pending) {
|
|
@@ -2524,13 +2529,25 @@ export function consumePendingFillCrawls(manager) {
|
|
|
2524
2529
|
* Buy reserves pin at the grid floor, sell reserves at the grid ceiling.
|
|
2525
2530
|
* Non-finite/non-integer/negative values disable (0).
|
|
2526
2531
|
*
|
|
2532
|
+
* The legacy numeric form (`reserveOrders: n`) is migrated here at read time
|
|
2533
|
+
* to `{ buy: n, sell: 0 }`: the editor seeder rewrites the persisted JSON, but
|
|
2534
|
+
* a hand-edited bots.json that bypassed the editor must not have its reserve
|
|
2535
|
+
* count silently read as 0.
|
|
2536
|
+
*
|
|
2527
2537
|
* @param {Object} config - Bot configuration
|
|
2528
2538
|
* @param {string} side - 'buy' or 'sell'
|
|
2529
2539
|
* @returns {number} Reserve count for the side (>= 0 integer)
|
|
2530
2540
|
*/
|
|
2531
2541
|
function resolveReserveCount(config, side) {
|
|
2532
2542
|
const key = side === 'sell' ? 'sell' : 'buy';
|
|
2533
|
-
const
|
|
2543
|
+
const rawReserve = config?.reserveOrders;
|
|
2544
|
+
if (typeof rawReserve === 'number') {
|
|
2545
|
+
if (side === 'sell')
|
|
2546
|
+
return 0;
|
|
2547
|
+
const n = Math.floor(rawReserve);
|
|
2548
|
+
return Number.isFinite(n) && n >= 0 ? n : 0;
|
|
2549
|
+
}
|
|
2550
|
+
const raw = Number(rawReserve?.[key] ?? 0);
|
|
2534
2551
|
if (!Number.isInteger(raw) || raw < 0)
|
|
2535
2552
|
return 0;
|
|
2536
2553
|
return raw;
|
|
@@ -2596,41 +2613,47 @@ function reserveEdgeIdSet(allSlots, config, orderType, anchorPrice = null, exclu
|
|
|
2596
2613
|
return ids;
|
|
2597
2614
|
}
|
|
2598
2615
|
/**
|
|
2599
|
-
* Window member ids for one side
|
|
2600
|
-
* picker excludes from its reserve pick: in-rail slots of the side (geometry
|
|
2601
|
-
* via resolveGapBand/isSlotInRail — the same source the reconcile pickers
|
|
2602
|
-
* use), ordered closest to market first (buys: highest price first; sells:
|
|
2603
|
-
* lowest first), sliced to the configured activeOrders count. The slice runs
|
|
2604
|
-
* over the FULL master rail, not just live orders — window membership is
|
|
2605
|
-
* geometric (a virtual hole inside the window still blocks the reserve pick
|
|
2606
|
-
* there), so live-only slices would misclassify live reserves as window
|
|
2607
|
-
* members whenever the window itself is under-filled.
|
|
2616
|
+
* Window member ids for one side from an explicit slot list and geometry.
|
|
2608
2617
|
*
|
|
2609
|
-
*
|
|
2610
|
-
*
|
|
2611
|
-
*
|
|
2618
|
+
* Mirror of the window every placement picker excludes from its reserve
|
|
2619
|
+
* pick: in-rail slots of the side (geometry via isSlotInRail), ordered
|
|
2620
|
+
* closest to market first (buys: highest price first; sells: lowest first),
|
|
2621
|
+
* sliced to the configured activeOrders count. The slice runs over the FULL
|
|
2622
|
+
* rail, not just live orders — window membership is geometric (a virtual
|
|
2623
|
+
* hole inside the window still blocks the reserve pick there), so live-only
|
|
2624
|
+
* slices would misclassify live reserves as window members whenever the
|
|
2625
|
+
* window itself is under-filled.
|
|
2612
2626
|
*
|
|
2613
|
-
*
|
|
2614
|
-
*
|
|
2627
|
+
* Returns null when the boundary geometry is unknown (null boundary): the
|
|
2628
|
+
* pickers cannot place reserves without it either, so callers fail open
|
|
2629
|
+
* (no exclusion) and keep their previous classification instead of guessing.
|
|
2630
|
+
*
|
|
2631
|
+
* @param {Array<Object>} allSlots - Slots (master grid or clone)
|
|
2632
|
+
* @param {Object} config - Bot configuration (activeOrders count source)
|
|
2633
|
+
* @param {string} orderType - ORDER_TYPES.BUY or SELL
|
|
2634
|
+
* @param {number|null|undefined} boundaryIdx - Boundary the rail is derived from
|
|
2635
|
+
* @param {number} gapSlots - Gap band size
|
|
2615
2636
|
* @returns {Set<string>|null} Window slot ids, or null when geometry unknown
|
|
2616
2637
|
*/
|
|
2617
|
-
function
|
|
2638
|
+
function windowIdSetFromSlots(allSlots, config, orderType, boundaryIdx, gapSlots) {
|
|
2618
2639
|
try {
|
|
2619
2640
|
const isSell = orderType === ORDER_TYPES.SELL;
|
|
2620
2641
|
const type = isSell ? ORDER_TYPES.SELL : ORDER_TYPES.BUY;
|
|
2621
2642
|
const side = isSell ? 'sell' : 'buy';
|
|
2622
|
-
const count = Math.max(0, Math.floor(Number(
|
|
2623
|
-
if (!(count > 0)
|
|
2643
|
+
const count = Math.max(0, Math.floor(Number(config?.activeOrders?.[side])) || 0);
|
|
2644
|
+
if (!(count > 0))
|
|
2624
2645
|
return new Set();
|
|
2625
|
-
|
|
2626
|
-
|
|
2646
|
+
if (!Array.isArray(allSlots))
|
|
2647
|
+
return new Set();
|
|
2648
|
+
if (boundaryIdx === null || boundaryIdx === undefined || !Number.isFinite(Number(boundaryIdx)))
|
|
2627
2649
|
return null;
|
|
2628
|
-
const
|
|
2650
|
+
const gap = Number.isFinite(Number(gapSlots)) ? Number(gapSlots) : 0;
|
|
2651
|
+
const inRail = (o) => MathUtils.isSlotInRail(boundaryIdx, gap, type, o);
|
|
2629
2652
|
// Same type filter as the window pickers with known geometry: the
|
|
2630
2653
|
// side's concrete type plus SPREAD placeholders (normalized empties
|
|
2631
2654
|
// sitting in this side's rail).
|
|
2632
2655
|
const typeFilter = (o) => o && o.id != null && o.price != null && (o.type === type || o.type === ORDER_TYPES.SPREAD);
|
|
2633
|
-
const ids =
|
|
2656
|
+
const ids = allSlots
|
|
2634
2657
|
.filter(typeFilter)
|
|
2635
2658
|
.filter(inRail)
|
|
2636
2659
|
.sort((a, b) => isSell ? Number(a.price) - Number(b.price) : Number(b.price) - Number(a.price))
|
|
@@ -2642,6 +2665,28 @@ function liveWindowIdSet(manager, orderType) {
|
|
|
2642
2665
|
return null;
|
|
2643
2666
|
}
|
|
2644
2667
|
}
|
|
2668
|
+
/**
|
|
2669
|
+
* Window member ids for one side from the live manager (see
|
|
2670
|
+
* windowIdSetFromSlots). Delegates so the manager and explicit-geometry
|
|
2671
|
+
* callers share one definition.
|
|
2672
|
+
*
|
|
2673
|
+
* @param {any} manager - OrderManager (orders Map, config, boundaryIdx)
|
|
2674
|
+
* @param {string} orderType - ORDER_TYPES.BUY or ORDER_TYPES.SELL
|
|
2675
|
+
* @returns {Set<string>|null} Window slot ids, or null when geometry unknown
|
|
2676
|
+
*/
|
|
2677
|
+
function liveWindowIdSet(manager, orderType) {
|
|
2678
|
+
try {
|
|
2679
|
+
if (!manager?.orders || typeof manager.orders.values !== 'function')
|
|
2680
|
+
return new Set();
|
|
2681
|
+
const resolved = MathUtils.resolveGapBand(manager);
|
|
2682
|
+
if (resolved?.boundaryIdx == null || resolved?.sellStartIdx == null)
|
|
2683
|
+
return null;
|
|
2684
|
+
return windowIdSetFromSlots(Array.from(manager.orders.values()), manager.config, orderType, resolved.boundaryIdx, resolved.gapSlots);
|
|
2685
|
+
}
|
|
2686
|
+
catch {
|
|
2687
|
+
return null;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2645
2690
|
/**
|
|
2646
2691
|
* Refill-slot wire for the COW boundary hold (single source for both plan
|
|
2647
2692
|
* producers: the fill-driven COW engine and the divergence fold).
|
|
@@ -2670,10 +2715,13 @@ function liveWindowIdSet(manager, orderType) {
|
|
|
2670
2715
|
* @param {Iterable<Object>} [options.slots] - Master slots (reserve classification)
|
|
2671
2716
|
* @param {{buy?: number|null, sell?: number|null}} [options.edgeAnchors] - Live
|
|
2672
2717
|
* edge anchors (same pair the strategy classifies reserve fills against)
|
|
2718
|
+
* @param {any} [options.manager] - OrderManager for the window exclusion (same
|
|
2719
|
+
* set the placement pickers exclude); omit to fall back to the previous
|
|
2720
|
+
* exclusion-free classification (fail-open)
|
|
2673
2721
|
* @returns {string[]} Refill slot ids (CREATE ids minus reserve edge ids)
|
|
2674
2722
|
*/
|
|
2675
2723
|
function collectRefillSlotIds(actions, options = {}) {
|
|
2676
|
-
const { config = null, slots = null, edgeAnchors = null } = options;
|
|
2724
|
+
const { config = null, slots = null, edgeAnchors = null, manager = null } = options;
|
|
2677
2725
|
const out = [];
|
|
2678
2726
|
if (!Array.isArray(actions))
|
|
2679
2727
|
return out;
|
|
@@ -2693,8 +2741,15 @@ function collectRefillSlotIds(actions, options = {}) {
|
|
|
2693
2741
|
: (typeof slots?.values === 'function'
|
|
2694
2742
|
? Array.from(slots.values())
|
|
2695
2743
|
: Array.from(slots));
|
|
2696
|
-
|
|
2697
|
-
|
|
2744
|
+
// Window exclusion keeps classification in agreement with the
|
|
2745
|
+
// placement pickers: a window reaching the grid edge must not have
|
|
2746
|
+
// its window hole-CREATEs dropped from the wire as if they were
|
|
2747
|
+
// reserves, or a guard-skipped window refill would no longer pin
|
|
2748
|
+
// the committed boundary (stranding the hole it failed to fill).
|
|
2749
|
+
const windowBuyIds = manager ? liveWindowIdSet(manager, ORDER_TYPES.BUY) : null;
|
|
2750
|
+
const windowSellIds = manager ? liveWindowIdSet(manager, ORDER_TYPES.SELL) : null;
|
|
2751
|
+
const buyIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.BUY, edgeAnchors?.buy ?? null, windowBuyIds);
|
|
2752
|
+
const sellIds = reserveEdgeIdSet(allSlots, config, ORDER_TYPES.SELL, edgeAnchors?.sell ?? null, windowSellIds);
|
|
2698
2753
|
if (buyIds || sellIds)
|
|
2699
2754
|
reserveIds = new Set([...(buyIds ?? []), ...(sellIds ?? [])]);
|
|
2700
2755
|
}
|
|
@@ -2720,8 +2775,10 @@ function collectRefillSlotIds(actions, options = {}) {
|
|
|
2720
2775
|
*
|
|
2721
2776
|
* Known limit: this is the statically resolved config bound, not the
|
|
2722
2777
|
* gridPrice/AMA-referenced live rail bound. Placement call sites should use
|
|
2723
|
-
* resolveLiveReserveEdgeAnchorPrice(manager, side), which prefers the
|
|
2724
|
-
*
|
|
2778
|
+
* resolveLiveReserveEdgeAnchorPrice(manager, side), which prefers the genesis
|
|
2779
|
+
* ladder extreme and returns null when there is no usable ladder. Callers that
|
|
2780
|
+
* need a fallback (e.g. reserveEdgeIdSet) still resolve this config bound when
|
|
2781
|
+
* the live anchor is null; the live resolver itself no longer computes it.
|
|
2725
2782
|
*
|
|
2726
2783
|
* @param {Object} config - Bot configuration
|
|
2727
2784
|
* @param {string} side - 'buy' or 'sell'
|
|
@@ -2745,72 +2802,38 @@ function resolveReserveEdgeAnchorPrice(config, side) {
|
|
|
2745
2802
|
*
|
|
2746
2803
|
* The anchor must come from the geometry the bot is actually trading, never
|
|
2747
2804
|
* from a config value that can be a mode string ("pool"/"book"), a relative
|
|
2748
|
-
* multiplier, or a stale bound
|
|
2749
|
-
*
|
|
2750
|
-
*
|
|
2751
|
-
*
|
|
2752
|
-
*
|
|
2753
|
-
*
|
|
2754
|
-
*
|
|
2755
|
-
*
|
|
2756
|
-
*
|
|
2757
|
-
*
|
|
2758
|
-
*
|
|
2759
|
-
*
|
|
2760
|
-
*
|
|
2761
|
-
*
|
|
2762
|
-
*
|
|
2763
|
-
*
|
|
2764
|
-
*
|
|
2805
|
+
* multiplier, or a stale bound, and never from the live slot prices of a grid
|
|
2806
|
+
* whose levels have no authority. The only source is the genesis ladder:
|
|
2807
|
+
* `_genesis.priceLevels` is the exact ladder the loaded grid was built from —
|
|
2808
|
+
* sorted ascending, index-aligned with `slot-<idx>` (assertSlotPriceInvariant),
|
|
2809
|
+
* refreshed by initializeGrid, persisted with the grid, and unaffected by the
|
|
2810
|
+
* raw-profile re-merge a resync performs. Slot 0 is always on the buy rail and
|
|
2811
|
+
* the last level always on the sell rail, so the ladder extremes are the live
|
|
2812
|
+
* rail bounds.
|
|
2813
|
+
*
|
|
2814
|
+
* A manager with no usable ladder returns null. That is the undefined-grid state
|
|
2815
|
+
* (INV-GRID-004), which the load and sync gates refuse, not a degraded mode to
|
|
2816
|
+
* paper over. The former tiers — the live in-rail slot extreme and the resolved
|
|
2817
|
+
* config bound — are gone with the legacy matcher they only existed to cover;
|
|
2818
|
+
* any config-bound fallback is now resolved by the individual consumer that
|
|
2819
|
+
* wants one (see reserveEdgeIdSet), not by this live-edge resolver. The fault
|
|
2820
|
+
* itself is reported
|
|
2821
|
+
* once per grid generation by the sync-entry gate; this resolver stays silent
|
|
2822
|
+
* because it is called from per-fill and per-placement paths.
|
|
2823
|
+
*
|
|
2824
|
+
* @param {Object} manager - OrderManager (needs _genesis)
|
|
2765
2825
|
* @param {string} side - 'buy' or 'sell'
|
|
2766
2826
|
* @returns {number|null} Finite anchor price, or null
|
|
2767
2827
|
*/
|
|
2768
2828
|
function resolveLiveReserveEdgeAnchorPrice(manager, side) {
|
|
2769
2829
|
const isSell = side === 'sell';
|
|
2770
|
-
// Tier 1 — the ladder the loaded grid was generated from.
|
|
2771
2830
|
const levels = manager?._genesis?.priceLevels;
|
|
2772
2831
|
if (Array.isArray(levels) && levels.length > 0) {
|
|
2773
2832
|
const extreme = Number(isSell ? levels[levels.length - 1] : levels[0]);
|
|
2774
2833
|
if (Number.isFinite(extreme) && extreme > 0)
|
|
2775
2834
|
return extreme;
|
|
2776
2835
|
}
|
|
2777
|
-
|
|
2778
|
-
const sideType = isSell ? ORDER_TYPES.SELL : ORDER_TYPES.BUY;
|
|
2779
|
-
if (manager?.orders && typeof manager.orders.values === 'function') {
|
|
2780
|
-
let best = null;
|
|
2781
|
-
try {
|
|
2782
|
-
const band = MathUtils.resolveGapBand(manager);
|
|
2783
|
-
for (const entry of manager.orders.values()) {
|
|
2784
|
-
if (!entry || typeof entry !== 'object')
|
|
2785
|
-
continue;
|
|
2786
|
-
if (!('type' in entry) || !('price' in entry))
|
|
2787
|
-
continue;
|
|
2788
|
-
if (entry.type !== sideType)
|
|
2789
|
-
continue;
|
|
2790
|
-
// Shelf/manual ids (e.g. fork-kept deep-* orders below the rail)
|
|
2791
|
-
// are never rail geometry: isSlotInRail is fail-open for
|
|
2792
|
-
// unparseable ids, so without this gate a cheap shelf order drags
|
|
2793
|
-
// the anchor down to itself and then qualifies as the reserve edge
|
|
2794
|
-
// (issue #27 follow-up). No-op upstream (grids only mint slot-N).
|
|
2795
|
-
if (parseSlotIndex(entry?.id) === null)
|
|
2796
|
-
continue;
|
|
2797
|
-
if (!MathUtils.isSlotInRail(band.boundaryIdx, band.gapSlots, sideType, entry))
|
|
2798
|
-
continue;
|
|
2799
|
-
const price = Number(entry.price);
|
|
2800
|
-
if (!Number.isFinite(price) || price <= 0)
|
|
2801
|
-
continue;
|
|
2802
|
-
if (best === null || (isSell ? price > best : price < best))
|
|
2803
|
-
best = price;
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
catch (e) {
|
|
2807
|
-
best = null;
|
|
2808
|
-
}
|
|
2809
|
-
if (best !== null)
|
|
2810
|
-
return best;
|
|
2811
|
-
}
|
|
2812
|
-
// Tier 3 — configured/resolved bound.
|
|
2813
|
-
return resolveReserveEdgeAnchorPrice(manager?.config, side);
|
|
2836
|
+
return null;
|
|
2814
2837
|
}
|
|
2815
2838
|
/**
|
|
2816
2839
|
* Shared anchored edge comparator for reserve selection (single source).
|
|
@@ -3140,6 +3163,6 @@ function collectKnownOnChainOrderIds(mgr, placedResults, placedContexts, extraCr
|
|
|
3140
3163
|
const all = new Set([...masterIds, ...createIds]);
|
|
3141
3164
|
return { masterIds: [...masterIds], createIds: [...createIds], all: [...all] };
|
|
3142
3165
|
}
|
|
3143
|
-
export { parseChainOrder,
|
|
3166
|
+
export { parseChainOrder, applyChainSizeToGridOrder, buildFillKey, correctOrderPriceOnChain, correctAllPriceMismatches, _validatePriceCorrectionEntry, _stampCorrectionProvenance, findLiveOrderOwnerByChainId, buildCreateOrderArgs, getOrderTypeFromUpdatedFlags, resolveConfiguredPriceBound, virtualizeOrder, convertToSpreadPlaceholder, toRailHolePlaceholder, geometryTypeForSlotIndex, detectGapEvacuationCandidates, updateGapEvacuationStreaks, resolveSpreadOrderSide, chainOrderMatchesSlot, chainOrderMatchesSlotWithTolerance, crossingCandidateChainId, isCrossingCheckCandidate, buildCrossingCheckCandidates, parseSlotIndex, filterOrdersByType, buildOutsideInPairGroups, extractBatchOperationResults, formatUnmatchedChainOrder, isNonBlockingUnmatchedOrder, isStrandedHoldOrder, isOrderOnChain, isOrderVirtual, hasOnChainId, isOrderPlaced, isPhantomOrder, isSlotAvailable, isEmptyGridSlot, isOrderHealthy, checkSizeThreshold, checkSizesBeforeMinimum, calculateIdealBoundary, assignGridRoles, resolveOnChainRetypeType, shouldFlagOutOfSpread, buildIndexes, validateIndexes, ordersEqual, buildDelta, deriveTargetBoundary, isShiftEligibleFill, resolveReserveCount, resolveReserveOrders, selectReserveEdgeSlots, getActiveOrdersTotal, getSideBudget, calculateBudgetedSizes, buildCreateOpFingerprint, isOrderGoneErrorMessage, recordDuplicateOrphanDetection, clearDuplicateOrphanDetection, duplicateOrphanLogInfo, chainOrderUnchangedFromCache, detectCrossedBookPlan, collectKnownOnChainOrderIds, reserveEdgeIdSet, liveWindowIdSet, checkGridPriceInvariant, reportGridPriceInvariant };
|
|
3144
3167
|
export { resolveReserveEdgeAnchorPrice, resolveLiveReserveEdgeAnchorPrice, compareReserveEdge, collectRefillSlotIds };
|
|
3145
3168
|
//# sourceMappingURL=order.js.map
|