dexbot 1.6.10 → 1.6.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/CHANGELOG.md +50 -3
- package/README.md +3 -1
- package/analysis/README.md +51 -11
- package/analysis/bot_fitting/README.md +12 -0
- package/analysis/tradingview/README.md +3 -3
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +11 -37
- package/analysis/trend_detection/README.md +31 -0
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/launcher_mode_detector.ts +9 -2
- 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/account_resolver.d.ts +1 -1
- package/dist/analysis/account_resolver.js +15 -2
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -7
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
- package/dist/analysis/analyze_args.d.ts +31 -0
- package/dist/analysis/analyze_args.js +41 -0
- package/dist/analysis/analyze_dynamic_weight.js +7 -20
- package/dist/analysis/analyze_kalman.js +7 -17
- package/dist/analysis/analyze_regime.js +7 -17
- package/dist/analysis/analyze_regime_windows.js +8 -18
- package/dist/analysis/analyze_risk_profile.js +8 -18
- package/dist/analysis/analyze_trade_heatmap.js +7 -17
- package/dist/analysis/analyze_volatility.js +7 -17
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +220 -12
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +55 -10
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +72 -66
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.d.ts +21 -0
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +315 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
- package/dist/analysis/bot_fitting/shared_utils.js +2 -2
- package/dist/analysis/bot_key_utils.d.ts +18 -10
- package/dist/analysis/bot_key_utils.js +10 -17
- package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
- package/dist/analysis/chain_pool.d.ts +3 -1
- package/dist/analysis/chart_ui.d.ts +5 -2
- package/dist/analysis/chart_ui.js +6 -3
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +64 -0
- package/dist/analysis/fills_cache.js +254 -0
- package/dist/analysis/fills_source.d.ts +2 -2
- package/dist/analysis/fills_source.js +19 -14
- package/dist/analysis/grid_correction_check.d.ts +1 -1
- package/dist/analysis/grid_correction_check.js +12 -11
- package/dist/analysis/math_utils.d.ts +7 -6
- package/dist/analysis/math_utils.js +5 -8
- package/dist/analysis/pnl_report.d.ts +39 -0
- package/dist/analysis/pnl_report.js +325 -0
- package/dist/analysis/price_sources.d.ts +8 -8
- package/dist/analysis/price_sources.js +5 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -2
- package/dist/analysis/trade_profitability.d.ts +32 -2
- package/dist/analysis/trade_profitability.js +232 -106
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
- package/dist/analysis/tradingview/analyze_tradingview.js +9 -10
- package/dist/analysis/tradingview/grid_reset_config.d.ts +42 -31
- package/dist/analysis/tradingview/grid_reset_config.js +35 -6
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -8
- package/dist/analysis/tradingview/grid_reset_sim.js +42 -5
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -20
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +102 -0
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +725 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +27 -112
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +40 -0
- package/dist/analysis/trend_detection/huber_scale_variants.js +176 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
- package/dist/credential-daemon.js +34 -20
- package/dist/dexbot.js +17 -14
- package/dist/market_adapter/candle_utils.d.ts +22 -18
- package/dist/market_adapter/candle_utils.js +24 -20
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
- package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
- package/dist/market_adapter/core/kibana_candles.d.ts +53 -18
- package/dist/market_adapter/core/kibana_candles.js +9 -7
- package/dist/market_adapter/core/kibana_client.d.ts +9 -1
- package/dist/market_adapter/core/kibana_client.js +8 -7
- package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +297 -115
- package/dist/market_adapter/core/market_adapter_service.js +184 -101
- package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
- package/dist/market_adapter/core/strategies/ama.js +7 -32
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
- package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +36 -8
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +9 -9
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
- package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
- package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
- package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
- package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
- package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
- package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
- package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +97 -226
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
- package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
- package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
- package/dist/market_adapter/inputs/kibana_source.js +2 -2
- package/dist/market_adapter/inputs/window_cache.d.ts +99 -94
- package/dist/market_adapter/inputs/window_cache.js +8 -8
- package/dist/market_adapter/interval_utils.d.ts +4 -4
- package/dist/market_adapter/log_format.d.ts +6 -6
- package/dist/market_adapter/log_format.js +28 -22
- package/dist/market_adapter/lp_chart_core.d.ts +22 -1
- package/dist/market_adapter/lp_chart_core.js +26 -192
- package/dist/market_adapter/lp_chart_runner.d.ts +7 -7
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
- package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
- package/dist/market_adapter/market_adapter.d.ts +94 -33
- package/dist/market_adapter/market_adapter.js +69 -75
- package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
- package/dist/market_adapter/utils/adapter_client.js +2 -2
- package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
- package/dist/market_adapter/utils/chain.d.ts +50 -41
- package/dist/market_adapter/utils/chain.js +40 -46
- package/dist/market_adapter/utils/data_discovery.d.ts +4 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
- package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
- package/dist/market_adapter/utils/file_lock.d.ts +28 -14
- package/dist/market_adapter/utils/file_lock.js +36 -32
- package/dist/market_adapter/utils/native_history.d.ts +9 -2
- package/dist/market_adapter/utils/native_history.js +35 -28
- package/dist/modules/account_bots.d.ts +577 -21
- package/dist/modules/account_bots.js +182 -158
- package/dist/modules/account_orders.d.ts +66 -30
- package/dist/modules/account_orders.js +22 -20
- package/dist/modules/authority_resolver.d.ts +12 -2
- package/dist/modules/authority_resolver.js +15 -8
- package/dist/modules/bitshares-native/chain_client.d.ts +38 -3
- package/dist/modules/bitshares-native/chain_client.js +45 -46
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
- package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
- package/dist/modules/bitshares-native/index.d.ts +1 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
- package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
- package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
- package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
- package/dist/modules/bitshares-native/serial/serializer.js +7 -13
- package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
- package/dist/modules/bitshares-native/serial/types.js +55 -62
- package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
- package/dist/modules/bitshares-native/signing_client.js +19 -14
- package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
- package/dist/modules/bitshares-native/subscriptions.js +12 -12
- package/dist/modules/bitshares-native/transport.d.ts +5 -4
- package/dist/modules/bitshares-native/transport.js +5 -4
- package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
- package/dist/modules/bitshares-native/tx/builder.js +4 -3
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
- package/dist/modules/bitshares_client.d.ts +45 -13
- package/dist/modules/bitshares_client.js +28 -19
- package/dist/modules/bot_defaults.d.ts +6 -15
- package/dist/modules/bot_defaults.js +1 -5
- package/dist/modules/bot_settings.d.ts +44 -10
- package/dist/modules/bot_settings.js +11 -8
- package/dist/modules/bots_file_lock.d.ts +6 -6
- package/dist/modules/bots_file_lock.js +16 -12
- package/dist/modules/broadcast_failure.d.ts +2 -2
- package/dist/modules/broadcast_failure.js +5 -4
- package/dist/modules/chain_keys.d.ts +42 -40
- package/dist/modules/chain_keys.js +53 -45
- package/dist/modules/chain_orders.d.ts +93 -59
- package/dist/modules/chain_orders.js +31 -23
- package/dist/modules/constants.d.ts +530 -32
- package/dist/modules/constants.js +52 -60
- package/dist/modules/cr_planner.d.ts +40 -2
- package/dist/modules/credential_policy.d.ts +68 -8
- package/dist/modules/credential_policy.js +37 -31
- package/dist/modules/credential_session_cache.d.ts +2 -2
- package/dist/modules/credit_pricing.d.ts +42 -6
- package/dist/modules/credit_pricing.js +44 -30
- package/dist/modules/credit_runtime.d.ts +276 -118
- package/dist/modules/credit_runtime.js +462 -165
- package/dist/modules/crypto/browser_provider.js +6 -4
- package/dist/modules/crypto/node_provider.js +1 -1
- package/dist/modules/crypto/pure_scrypt.js +35 -4
- package/dist/modules/crypto/pure_secp256k1.js +72 -26
- package/dist/modules/crypto/sync.d.ts +9 -9
- package/dist/modules/crypto/sync.js +16 -9
- package/dist/modules/dexbot_class.d.ts +195 -139
- package/dist/modules/dexbot_class.js +78 -28
- package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
- package/dist/modules/dexbot_cow_runtime.js +248 -206
- package/dist/modules/dexbot_credential_client.d.ts +19 -11
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
- package/dist/modules/dexbot_fill_runtime.js +48 -41
- package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
- package/dist/modules/dexbot_maintenance_runtime.js +117 -80
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
- package/dist/modules/dexbot_startup_runtime.js +43 -43
- package/dist/modules/dexbot_state_recovery.d.ts +13 -12
- package/dist/modules/dexbot_state_recovery.js +18 -13
- package/dist/modules/fund_registry.d.ts +4 -2
- package/dist/modules/fund_registry.js +10 -10
- package/dist/modules/general_settings.d.ts +30 -4
- package/dist/modules/graceful_shutdown.d.ts +3 -3
- package/dist/modules/graceful_shutdown.js +2 -2
- package/dist/modules/grid_price_source.d.ts +1 -1
- package/dist/modules/key_store.d.ts +14 -8
- package/dist/modules/key_store.js +7 -6
- package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
- package/dist/modules/launcher/adapter_requirement.js +5 -5
- package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
- package/dist/modules/launcher/bot_supervisor.js +12 -11
- package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +1 -1
- package/dist/modules/launcher/credential_daemon.d.ts +4 -4
- package/dist/modules/launcher/credential_daemon.js +2 -2
- package/dist/modules/launcher/credential_secret.d.ts +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
- package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
- package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
- package/dist/modules/launcher/status_reporting.d.ts +22 -14
- package/dist/modules/launcher/supervisor_control.d.ts +8 -1
- package/dist/modules/launcher/supervisor_control.js +4 -2
- package/dist/modules/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- package/dist/modules/node_manager.d.ts +41 -11
- package/dist/modules/node_manager.js +5 -4
- package/dist/modules/order/accounting.d.ts +53 -24
- package/dist/modules/order/accounting.js +40 -14
- package/dist/modules/order/async_lock.d.ts +5 -2
- package/dist/modules/order/async_lock.js +1 -1
- package/dist/modules/order/export.d.ts +7 -6
- package/dist/modules/order/export.js +1 -7
- package/dist/modules/order/format.d.ts +39 -19
- package/dist/modules/order/format.js +62 -16
- package/dist/modules/order/genesis_policy.d.ts +21 -18
- package/dist/modules/order/genesis_policy.js +12 -8
- package/dist/modules/order/grid.d.ts +142 -36
- package/dist/modules/order/grid.js +148 -123
- package/dist/modules/order/grid_reconcile.d.ts +21 -20
- package/dist/modules/order/grid_reconcile.js +13 -12
- package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
- package/dist/modules/order/grid_reconcile_internal.js +28 -19
- package/dist/modules/order/index.d.ts +263 -1
- package/dist/modules/order/logger.d.ts +45 -11
- package/dist/modules/order/logger.js +38 -40
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +226 -180
- package/dist/modules/order/manager.js +101 -83
- package/dist/modules/order/processed_fill_store.d.ts +18 -3
- package/dist/modules/order/processed_fill_store.js +16 -27
- package/dist/modules/order/strategy.d.ts +21 -13
- package/dist/modules/order/strategy.js +5 -6
- package/dist/modules/order/sync_engine.d.ts +91 -33
- package/dist/modules/order/sync_engine.js +99 -54
- package/dist/modules/order/utils/math.d.ts +157 -102
- package/dist/modules/order/utils/math.js +77 -38
- package/dist/modules/order/utils/order.d.ts +326 -106
- package/dist/modules/order/utils/order.js +200 -99
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +176 -26
- package/dist/modules/order/utils/system.js +86 -69
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +24 -22
- package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
- package/dist/modules/order/utils/withPoolRef.js +18 -12
- package/dist/modules/order/working_grid.d.ts +14 -13
- package/dist/modules/paths.d.ts +3 -4
- package/dist/modules/paths.js +3 -27
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.js +2 -1
- package/dist/modules/runtime.d.ts +7 -3
- package/dist/modules/runtime.js +4 -3
- package/dist/modules/runtime_settings.d.ts +15 -10
- package/dist/modules/runtime_settings.js +30 -24
- package/dist/modules/settings_merge.d.ts +29 -3
- package/dist/modules/settings_merge.js +56 -78
- package/dist/modules/socket_json_client.d.ts +7 -4
- package/dist/modules/storage/browser_adapter.d.ts +38 -53
- package/dist/modules/storage/browser_adapter.js +7 -30
- package/dist/modules/storage/index.d.ts +1 -1
- package/dist/modules/storage/node_adapter.d.ts +45 -27
- package/dist/modules/storage/node_adapter.js +9 -9
- package/dist/modules/storage/types.d.ts +5 -4
- package/dist/modules/types.d.ts +1071 -2
- package/dist/modules/types.js +4 -1
- package/dist/modules/utils/asset_symbols.d.ts +2 -1
- package/dist/modules/utils/asset_symbols.js +2 -1
- package/dist/modules/utils/errors.d.ts +9 -0
- package/dist/modules/utils/errors.js +23 -1
- package/dist/modules/utils/time_range.d.ts +4 -0
- package/dist/modules/utils/time_range.js +18 -0
- package/dist/modules/validate_profiles.js +53 -43
- package/dist/modules/version_notice.d.ts +14 -3
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +29 -27
- package/dist/pm2.js +5 -5
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- package/dist/scripts/analyze-orders.d.ts +77 -9
- package/dist/scripts/analyze-orders.js +66 -84
- package/dist/scripts/chart_command.d.ts +27 -18
- package/dist/scripts/chart_command.js +16 -15
- package/dist/scripts/check_any.d.ts +18 -0
- package/dist/scripts/check_any.js +126 -0
- package/dist/scripts/diagnose-pool-history.js +12 -7
- package/dist/scripts/pnl.d.ts +3 -0
- package/dist/scripts/pnl.js +40 -0
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -7
- package/dist/scripts/runner.js +1 -1
- package/dist/scripts/test-credit-renewal.js +30 -21
- package/dist/scripts/update.d.ts +10 -5
- package/dist/scripts/update.js +168 -103
- package/dist/scripts/update_dist_freshness.js +1 -0
- package/dist/scripts/update_layout.d.ts +61 -0
- package/dist/scripts/update_layout.js +180 -0
- package/dist/scripts/validate_bots.js +2 -1
- package/dist/scripts/verify-browser-bundle.js +8 -0
- package/dist/unlock.d.ts +28 -3
- package/dist/unlock.js +72 -10
- package/docs/BITSHARES_ONBOARDING.md +2 -0
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +12 -10
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
- package/docs/GRID_RECALCULATION.md +15 -16
- package/docs/GRID_RECONCILE.md +14 -3
- package/docs/LIFECYCLE.md +11 -11
- package/docs/MPA_CREDIT_USAGE.md +22 -3
- package/docs/README.md +15 -4
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +12 -9
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +9 -26
- package/modules/README.md +4 -1
- package/package.json +4 -1
- package/scripts/README.md +14 -0
|
@@ -70,6 +70,18 @@
|
|
|
70
70
|
*
|
|
71
71
|
* ===============================================================================
|
|
72
72
|
*/
|
|
73
|
+
import type { OrderManagerLike, PendingPriceCorrection, ChainOrder, ParsedChainOrder, AssetPair, AssetInfo, OrderType, ManagedOrder, UnmatchedChainOrder, CowAction, ProjectedFunds } from '../../types.js';
|
|
74
|
+
import type { GridGenesis } from './math.js';
|
|
75
|
+
interface CorrectionAccountOrdersLike {
|
|
76
|
+
cancelOrder(account: string, privateKey: string, chainOrderId: string): Promise<unknown>;
|
|
77
|
+
updateOrder(account: string, privateKey: string, chainOrderId: string, params: {
|
|
78
|
+
amountToSell: unknown;
|
|
79
|
+
minToReceive: unknown;
|
|
80
|
+
}): Promise<unknown>;
|
|
81
|
+
buildCancelOrderOp(account: string, chainOrderId: string): Promise<unknown>;
|
|
82
|
+
batchReadOrders(ids: string[]): Promise<Map<string, unknown>>;
|
|
83
|
+
executeBatch(account: string, privateKey: string, ops: unknown[]): Promise<unknown>;
|
|
84
|
+
}
|
|
73
85
|
/**
|
|
74
86
|
* Detect a "chain order does not exist" error from a broadcast/read failure.
|
|
75
87
|
* Single canonical implementation used by the correction, reconcile-cancel,
|
|
@@ -86,7 +98,7 @@
|
|
|
86
98
|
* for generic object-missing phrasings (precision mode).
|
|
87
99
|
* @returns {boolean} True if the message indicates the order is gone.
|
|
88
100
|
*/
|
|
89
|
-
declare function isOrderGoneErrorMessage(message:
|
|
101
|
+
declare function isOrderGoneErrorMessage(message: string | null | undefined, orderId?: string | null): boolean;
|
|
90
102
|
/**
|
|
91
103
|
* Record a duplicate-orphan detection for an orderId.
|
|
92
104
|
* First sighting stays quiet (count 1). A repeated sighting of the same
|
|
@@ -94,7 +106,7 @@ declare function isOrderGoneErrorMessage(message: any, orderId?: any): boolean;
|
|
|
94
106
|
* @param {string} orderId - Duplicate orphan chain order ID.
|
|
95
107
|
* @returns {{ count: number; shouldEscalate: boolean }} Detection stats.
|
|
96
108
|
*/
|
|
97
|
-
declare function recordDuplicateOrphanDetection(orderId:
|
|
109
|
+
declare function recordDuplicateOrphanDetection(orderId: string | null | undefined): {
|
|
98
110
|
count: number;
|
|
99
111
|
shouldEscalate: boolean;
|
|
100
112
|
};
|
|
@@ -103,7 +115,7 @@ declare function recordDuplicateOrphanDetection(orderId: any): {
|
|
|
103
115
|
* so a resolved orphan never lingers and false-escalates later.
|
|
104
116
|
* @param {string} orderId - Chain order ID to forget.
|
|
105
117
|
*/
|
|
106
|
-
declare function clearDuplicateOrphanDetection(orderId:
|
|
118
|
+
declare function clearDuplicateOrphanDetection(orderId: string | null | undefined): void;
|
|
107
119
|
/**
|
|
108
120
|
* Record a duplicate-orphan detection and return the log level + re-detection
|
|
109
121
|
* suffix for the caller's diagnostic line. First sightings log at info; a
|
|
@@ -111,10 +123,30 @@ declare function clearDuplicateOrphanDetection(orderId: any): void;
|
|
|
111
123
|
* @param {string} orderId - Duplicate orphan chain order ID.
|
|
112
124
|
* @returns {{ level: 'info'|'warn'; suffix: string }} Log level and suffix text.
|
|
113
125
|
*/
|
|
114
|
-
declare function duplicateOrphanLogInfo(orderId:
|
|
126
|
+
declare function duplicateOrphanLogInfo(orderId: string | null | undefined): {
|
|
115
127
|
level: string;
|
|
116
128
|
suffix: string;
|
|
117
129
|
};
|
|
130
|
+
declare function _filterUnmatchedChainOrders(manager: OrderManagerLike, chainOrderId: string): void;
|
|
131
|
+
/**
|
|
132
|
+
* Record a fresh on-chain placement timestamp for surplus-cancel grace.
|
|
133
|
+
* Called when a slot gains a chain orderId it did not have before (create,
|
|
134
|
+
* adopt, rotation target). Powers isFreshlyPlacedOrder below.
|
|
135
|
+
* @param {unknown} manager - OrderManager instance (owns `_placedAt`)
|
|
136
|
+
* @param {string} chainOrderId - Chain order id that was just placed
|
|
137
|
+
*/
|
|
138
|
+
declare function recordOrderPlacement(manager: OrderManagerLike, chainOrderId: string | null | undefined): void;
|
|
139
|
+
/**
|
|
140
|
+
* True when the chain order was placed within the surplus-cancel grace
|
|
141
|
+
* window. Surplus sweeps must skip such orders: a fill landing between two
|
|
142
|
+
* controllers' count snapshots otherwise makes the second cancel what the
|
|
143
|
+
* first just placed (fee bleed + empty levels, no net change).
|
|
144
|
+
* @param {unknown} manager - OrderManager instance
|
|
145
|
+
* @param {string} chainOrderId - Chain order id to test
|
|
146
|
+
* @param {number} [graceMs] - Override grace window (defaults to TIMING.SURPLUS_CANCEL_GRACE_MS)
|
|
147
|
+
* @returns {boolean} True while the order is still inside its grace window
|
|
148
|
+
*/
|
|
149
|
+
declare function isFreshlyPlacedOrder(manager: OrderManagerLike, chainOrderId: string | null | undefined, graceMs?: number): boolean;
|
|
118
150
|
/**
|
|
119
151
|
* Stamp queue provenance on a correction entry: queued-at timestamp plus
|
|
120
152
|
* the detector that produced it. Existing provenance (e.g. a fresher
|
|
@@ -125,14 +157,14 @@ declare function duplicateOrphanLogInfo(orderId: any): {
|
|
|
125
157
|
* @param {string} source - provenance tag (see queuedBy values)
|
|
126
158
|
* @returns {Object} The same entry, stamped
|
|
127
159
|
*/
|
|
128
|
-
declare function _stampCorrectionProvenance(entry:
|
|
160
|
+
declare function _stampCorrectionProvenance(entry: PendingPriceCorrection, source: string): PendingPriceCorrection;
|
|
129
161
|
/**
|
|
130
162
|
* Find the live grid slot that currently owns a chain order.
|
|
131
163
|
* When slotId is supplied, only that exact slot is considered; otherwise all
|
|
132
164
|
* live slots are searched. This keeps stale-decision guards consistent without
|
|
133
165
|
* changing which owner is considered valid.
|
|
134
166
|
*/
|
|
135
|
-
declare function findLiveOrderOwnerByChainId(manager:
|
|
167
|
+
declare function findLiveOrderOwnerByChainId(manager: OrderManagerLike, chainOrderId: string | null | undefined, slotId?: string | null): ManagedOrder | null;
|
|
136
168
|
/**
|
|
137
169
|
* Drain-time staleness validation for a correction entry: verify the queued
|
|
138
170
|
* intent still matches the LIVE grid geometry before broadcasting.
|
|
@@ -169,7 +201,7 @@ declare function findLiveOrderOwnerByChainId(manager: any, chainOrderId: any, sl
|
|
|
169
201
|
* @param {Object} entry - Queued correction entry
|
|
170
202
|
* @returns {{valid: boolean, reason: string}} valid=false drops the entry
|
|
171
203
|
*/
|
|
172
|
-
declare function _validatePriceCorrectionEntry(manager:
|
|
204
|
+
declare function _validatePriceCorrectionEntry(manager: OrderManagerLike, entry: PendingPriceCorrection): {
|
|
173
205
|
valid: boolean;
|
|
174
206
|
reason: string;
|
|
175
207
|
};
|
|
@@ -182,12 +214,7 @@ declare function _validatePriceCorrectionEntry(manager: any, entry: any): {
|
|
|
182
214
|
* @param {Object} assets - Asset metadata with assetA, assetB, and precisions
|
|
183
215
|
* @returns {Object|null} Parsed order {orderId, price, type, size} or null if invalid
|
|
184
216
|
*/
|
|
185
|
-
declare function parseChainOrder(chainOrder:
|
|
186
|
-
orderId: any;
|
|
187
|
-
price: number;
|
|
188
|
-
type: "sell" | "buy";
|
|
189
|
-
size: number | undefined;
|
|
190
|
-
} | null;
|
|
217
|
+
declare function parseChainOrder(chainOrder: ChainOrder | null | undefined, assets: AssetPair | null | undefined): ParsedChainOrder | null;
|
|
191
218
|
/**
|
|
192
219
|
* Update grid order size based on blockchain state.
|
|
193
220
|
* Detects partial fills and updates accounting if size changed.
|
|
@@ -200,7 +227,7 @@ declare function parseChainOrder(chainOrder: any, assets: any): {
|
|
|
200
227
|
* @returns {Promise<Object|null>} Updated order object or null
|
|
201
228
|
* @throws {Error} If chainSize suspicious (possible data corruption)
|
|
202
229
|
*/
|
|
203
|
-
declare function applyChainSizeToGridOrder(manager:
|
|
230
|
+
declare function applyChainSizeToGridOrder(manager: OrderManagerLike, gridOrder: ManagedOrder, chainSize: number | string | null | undefined): Promise<ManagedOrder | null>;
|
|
204
231
|
/**
|
|
205
232
|
* Build a stable fill dedupe key.
|
|
206
233
|
* Accepts either a fill-history entry or explicit parts.
|
|
@@ -210,7 +237,14 @@ declare function applyChainSizeToGridOrder(manager: any, gridOrder: any, chainSi
|
|
|
210
237
|
* @param {Object} fillOrParts - Fill entry ({ op, block_num, id }) or { orderId, blockNum, historyId }
|
|
211
238
|
* @returns {string|null} Stable key in order:block:history form, or null if fields are missing
|
|
212
239
|
*/
|
|
213
|
-
declare function buildFillKey(fillOrParts:
|
|
240
|
+
declare function buildFillKey(fillOrParts: {
|
|
241
|
+
op?: unknown[];
|
|
242
|
+
orderId?: string;
|
|
243
|
+
block_num?: number;
|
|
244
|
+
blockNum?: number;
|
|
245
|
+
id?: string;
|
|
246
|
+
historyId?: string;
|
|
247
|
+
} | null | undefined): string | null;
|
|
214
248
|
/**
|
|
215
249
|
* Correct a single order's price on blockchain.
|
|
216
250
|
* Cancels surplus orders; updates price for others.
|
|
@@ -224,17 +258,23 @@ declare function buildFillKey(fillOrParts: any): string | null;
|
|
|
224
258
|
* @param {Object} accountOrders - AccountOrders accessor for blockchain ops
|
|
225
259
|
* @returns {Promise<Object>} Result {success, cancelled, skipped, error, orderGone}
|
|
226
260
|
*/
|
|
227
|
-
declare function correctOrderPriceOnChain(manager:
|
|
261
|
+
declare function correctOrderPriceOnChain(manager: OrderManagerLike, correctionInfo: PendingPriceCorrection, accountName: string, privateKey: string, accountOrders: CorrectionAccountOrdersLike): Promise<{
|
|
228
262
|
success: boolean;
|
|
229
|
-
|
|
263
|
+
error: string;
|
|
264
|
+
skipped?: undefined;
|
|
230
265
|
cancelled?: undefined;
|
|
266
|
+
orderGone?: undefined;
|
|
267
|
+
} | {
|
|
268
|
+
success: boolean;
|
|
269
|
+
skipped: boolean;
|
|
231
270
|
error?: undefined;
|
|
271
|
+
cancelled?: undefined;
|
|
232
272
|
orderGone?: undefined;
|
|
233
273
|
} | {
|
|
234
274
|
success: boolean;
|
|
235
275
|
cancelled: boolean;
|
|
236
|
-
skipped?: undefined;
|
|
237
276
|
error?: undefined;
|
|
277
|
+
skipped?: undefined;
|
|
238
278
|
orderGone?: undefined;
|
|
239
279
|
} | {
|
|
240
280
|
success: boolean;
|
|
@@ -250,9 +290,9 @@ declare function correctOrderPriceOnChain(manager: any, correctionInfo: any, acc
|
|
|
250
290
|
orderGone?: undefined;
|
|
251
291
|
} | {
|
|
252
292
|
success: boolean;
|
|
293
|
+
error?: undefined;
|
|
253
294
|
skipped?: undefined;
|
|
254
295
|
cancelled?: undefined;
|
|
255
|
-
error?: undefined;
|
|
256
296
|
orderGone?: undefined;
|
|
257
297
|
}>;
|
|
258
298
|
/**
|
|
@@ -266,7 +306,29 @@ declare function correctOrderPriceOnChain(manager: any, correctionInfo: any, acc
|
|
|
266
306
|
* @param {Object} accountOrders - AccountOrders accessor for blockchain ops
|
|
267
307
|
* @returns {Promise<Object>} Summary {corrected, failed, results}
|
|
268
308
|
*/
|
|
269
|
-
declare function correctAllPriceMismatches(manager:
|
|
309
|
+
declare function correctAllPriceMismatches(manager: OrderManagerLike, accountName: string, privateKey: string, accountOrders: CorrectionAccountOrdersLike): Promise<{
|
|
310
|
+
corrected: number;
|
|
311
|
+
failed: number;
|
|
312
|
+
results: (PendingPriceCorrection & {
|
|
313
|
+
result: unknown;
|
|
314
|
+
})[];
|
|
315
|
+
staleDropped: number;
|
|
316
|
+
deferredUpdates: number;
|
|
317
|
+
} | {
|
|
318
|
+
corrected: number;
|
|
319
|
+
failed: number;
|
|
320
|
+
results: never[];
|
|
321
|
+
staleDropped?: undefined;
|
|
322
|
+
deferred?: undefined;
|
|
323
|
+
reason?: undefined;
|
|
324
|
+
} | {
|
|
325
|
+
corrected: number;
|
|
326
|
+
failed: number;
|
|
327
|
+
results: never[];
|
|
328
|
+
staleDropped: number;
|
|
329
|
+
deferred: boolean;
|
|
330
|
+
reason: string;
|
|
331
|
+
}>;
|
|
270
332
|
/**
|
|
271
333
|
* Build blockchain order arguments from grid order.
|
|
272
334
|
* Converts grid order data to blockchain-compatible amounts and asset IDs.
|
|
@@ -278,11 +340,15 @@ declare function correctAllPriceMismatches(manager: any, accountName: any, priva
|
|
|
278
340
|
* @returns {Object} Blockchain args {amountToSell, sellAssetId, minToReceive, receiveAssetId}
|
|
279
341
|
* @throws {Error} If asset precision missing
|
|
280
342
|
*/
|
|
281
|
-
declare function buildCreateOrderArgs(order:
|
|
343
|
+
declare function buildCreateOrderArgs(order: {
|
|
344
|
+
type: OrderType;
|
|
345
|
+
size: number;
|
|
346
|
+
price: number;
|
|
347
|
+
}, assetA: AssetInfo, assetB: AssetInfo): {
|
|
282
348
|
amountToSell: number;
|
|
283
|
-
sellAssetId:
|
|
349
|
+
sellAssetId: string | undefined;
|
|
284
350
|
minToReceive: number;
|
|
285
|
-
receiveAssetId:
|
|
351
|
+
receiveAssetId: string | undefined;
|
|
286
352
|
};
|
|
287
353
|
/**
|
|
288
354
|
* Build a deterministic fingerprint for a planned CREATE order.
|
|
@@ -315,7 +381,14 @@ declare function buildCreateOrderArgs(order: any, assetA: any, assetB: any): {
|
|
|
315
381
|
* @param {string} params.slotId - Grid slot id (e.g. 'sell-3', 'buy-7')
|
|
316
382
|
* @returns {string|null} Fingerprint or null on bad input
|
|
317
383
|
*/
|
|
318
|
-
declare function buildCreateOpFingerprint(params:
|
|
384
|
+
declare function buildCreateOpFingerprint(params: {
|
|
385
|
+
side?: string;
|
|
386
|
+
assetA?: string;
|
|
387
|
+
assetB?: string;
|
|
388
|
+
sellInt?: number | string;
|
|
389
|
+
receiveInt?: number | string;
|
|
390
|
+
slotId?: string;
|
|
391
|
+
} | null): string | null;
|
|
319
392
|
/**
|
|
320
393
|
* Determine which order sides were updated based on update flags.
|
|
321
394
|
*
|
|
@@ -323,7 +396,7 @@ declare function buildCreateOpFingerprint(params: any): string | null;
|
|
|
323
396
|
* @param {boolean} sellUpdated - Whether sell side was updated
|
|
324
397
|
* @returns {string} "buy", "sell", or "both"
|
|
325
398
|
*/
|
|
326
|
-
declare function getOrderTypeFromUpdatedFlags(buyUpdated:
|
|
399
|
+
declare function getOrderTypeFromUpdatedFlags(buyUpdated: boolean | undefined, sellUpdated: boolean | undefined): "sell" | "buy" | "both";
|
|
327
400
|
/**
|
|
328
401
|
* Resolve configured price bound (minPrice/maxPrice) to numeric value.
|
|
329
402
|
* Supports relative expressions like "2x" and fallback defaults.
|
|
@@ -335,7 +408,7 @@ declare function getOrderTypeFromUpdatedFlags(buyUpdated: any, sellUpdated: any)
|
|
|
335
408
|
* @returns {number} Resolved numeric price
|
|
336
409
|
* @throws {Error} If value is invalid and cannot be interpreted
|
|
337
410
|
*/
|
|
338
|
-
declare function resolveConfiguredPriceBound(value:
|
|
411
|
+
declare function resolveConfiguredPriceBound(value: unknown, fallback: number | string | null | undefined, startPrice: number | string | null | undefined, mode: string): number | null;
|
|
339
412
|
/**
|
|
340
413
|
* Convert order to virtual state.
|
|
341
414
|
* Clears on-chain ID and raw blockchain data, marks as VIRTUAL.
|
|
@@ -343,7 +416,27 @@ declare function resolveConfiguredPriceBound(value: any, fallback: any, startPri
|
|
|
343
416
|
* @param {Object} order - Order to virtualize
|
|
344
417
|
* @returns {Object} Virtualized order (VIRTUAL state, no orderId)
|
|
345
418
|
*/
|
|
346
|
-
|
|
419
|
+
interface CrossingCandidate {
|
|
420
|
+
orderId?: string | null;
|
|
421
|
+
chainOrderId?: string | null;
|
|
422
|
+
slotId?: string;
|
|
423
|
+
price?: number;
|
|
424
|
+
type?: string;
|
|
425
|
+
order?: {
|
|
426
|
+
price?: number;
|
|
427
|
+
[key: string]: unknown;
|
|
428
|
+
} | null;
|
|
429
|
+
[key: string]: unknown;
|
|
430
|
+
}
|
|
431
|
+
interface SlotLike {
|
|
432
|
+
id?: string;
|
|
433
|
+
state?: string;
|
|
434
|
+
orderId?: string | null;
|
|
435
|
+
size?: number;
|
|
436
|
+
type?: OrderType | null;
|
|
437
|
+
price?: number;
|
|
438
|
+
}
|
|
439
|
+
declare function virtualizeOrder(order: ManagedOrder): ManagedOrder;
|
|
347
440
|
/**
|
|
348
441
|
* Convert order to spread placeholder (virtual, zero-sized spread order).
|
|
349
442
|
* Used when clearing order slots during rotations or rebalancing.
|
|
@@ -351,7 +444,7 @@ declare function virtualizeOrder(order: any): any;
|
|
|
351
444
|
* @param {Object} order - Order to convert
|
|
352
445
|
* @returns {Object} Spread placeholder order (VIRTUAL, SPREAD type, zero size)
|
|
353
446
|
*/
|
|
354
|
-
declare function convertToSpreadPlaceholder(order:
|
|
447
|
+
declare function convertToSpreadPlaceholder(order: ManagedOrder): ManagedOrder;
|
|
355
448
|
/**
|
|
356
449
|
* Convert an order to a rail-typed hole placeholder: VIRTUAL with the rail
|
|
357
450
|
* (BUY/SELL) type and the booked size preserved.
|
|
@@ -368,13 +461,13 @@ declare function convertToSpreadPlaceholder(order: any): any;
|
|
|
368
461
|
* @param {number} [sizeOverride] - Explicit size (defaults to booked size, 0 when non-finite)
|
|
369
462
|
* @returns {Object} Rail hole placeholder (VIRTUAL, rail type, preserved size)
|
|
370
463
|
*/
|
|
371
|
-
declare function toRailHolePlaceholder(order:
|
|
464
|
+
declare function toRailHolePlaceholder(order: ManagedOrder, railType: string, sizeOverride?: number | null): ManagedOrder;
|
|
372
465
|
/**
|
|
373
466
|
* Geometry type for a slot index: BUY at/below the boundary, SELL at/above
|
|
374
467
|
* sellStart, SPREAD inside the gap band. Null-safe — returns null when the
|
|
375
468
|
* index, boundary, or gap width is unusable so callers fail closed.
|
|
376
469
|
*/
|
|
377
|
-
declare function geometryTypeForSlotIndex(idx:
|
|
470
|
+
declare function geometryTypeForSlotIndex(idx: number | string | null | undefined, boundaryIdx: number | string | null | undefined, gapSlots: number | string | null | undefined): OrderType | null;
|
|
378
471
|
/**
|
|
379
472
|
* Detect gap-evacuation candidates by GEOMETRY ONLY: live on-chain orders
|
|
380
473
|
* whose parsed slot index sits strictly inside the gap band
|
|
@@ -387,7 +480,14 @@ declare function geometryTypeForSlotIndex(idx: any, boundaryIdx: any, gapSlots:
|
|
|
387
480
|
* @param {number} gapSlots - Spread gap slot count (frozen at plan-build)
|
|
388
481
|
* @returns {Array} Candidates [{id, idx, type, price, size, orderId}]
|
|
389
482
|
*/
|
|
390
|
-
declare function detectGapEvacuationCandidates(masterGrid:
|
|
483
|
+
declare function detectGapEvacuationCandidates(masterGrid: Map<string, ManagedOrder>, boundaryIdx: number | string | null, gapSlots: number | string | null): Array<{
|
|
484
|
+
id: string;
|
|
485
|
+
idx: number;
|
|
486
|
+
type: OrderType;
|
|
487
|
+
price: number;
|
|
488
|
+
size: number;
|
|
489
|
+
orderId: string;
|
|
490
|
+
}>;
|
|
391
491
|
/**
|
|
392
492
|
* Tick the per-slot gap-evacuation streak counter. In-memory on the manager
|
|
393
493
|
* (resets on restart — acceptable; a restart re-plans evacuation anyway).
|
|
@@ -399,9 +499,12 @@ declare function detectGapEvacuationCandidates(masterGrid: any, boundaryIdx: any
|
|
|
399
499
|
* @param {number} [threshold] - GRID_LIMITS.GAP_EVACUATION_STREAK_THRESHOLD default
|
|
400
500
|
* @returns {{streaks: Object, ready: Array}}
|
|
401
501
|
*/
|
|
402
|
-
declare function updateGapEvacuationStreaks(streakMap:
|
|
502
|
+
declare function updateGapEvacuationStreaks(streakMap: Map<string, number>, candidates: unknown, threshold?: number | null): {
|
|
403
503
|
streaks: Record<string, number>;
|
|
404
|
-
ready:
|
|
504
|
+
ready: Array<{
|
|
505
|
+
id: string;
|
|
506
|
+
[key: string]: unknown;
|
|
507
|
+
}>;
|
|
405
508
|
};
|
|
406
509
|
/**
|
|
407
510
|
* Resolve the real BUY/SELL side of a SPREAD-typed grid slot from its price
|
|
@@ -414,14 +517,14 @@ declare function updateGapEvacuationStreaks(streakMap: any, candidates: any, thr
|
|
|
414
517
|
* @param {number} startPrice - The configured grid center price.
|
|
415
518
|
* @returns {string} ORDER_TYPES.BUY or ORDER_TYPES.SELL
|
|
416
519
|
*/
|
|
417
|
-
declare function resolveSpreadOrderSide(price:
|
|
520
|
+
declare function resolveSpreadOrderSide(price: number | string, startPrice: number | string | null | undefined): OrderType;
|
|
418
521
|
/**
|
|
419
522
|
* Parse a grid slot id ("slot-123") to its rail index. Delegates to
|
|
420
523
|
* shared slot.ts single source (GRID_PRICE_SLOT_DETERMINISM_PLAN §2.1).
|
|
421
|
-
* @param {
|
|
524
|
+
* @param {unknown} id - grid slot id string
|
|
422
525
|
* @returns {number|null}
|
|
423
526
|
*/
|
|
424
|
-
declare function parseSlotIndex(id:
|
|
527
|
+
declare function parseSlotIndex(id: string | null | undefined): number | null;
|
|
425
528
|
/**
|
|
426
529
|
* Whether a parsed chain order matches a grid slot exactly:
|
|
427
530
|
* type-compatible (slot may be SPREAD), price strictly equal via integer
|
|
@@ -436,7 +539,7 @@ declare function parseSlotIndex(id: any): number | null;
|
|
|
436
539
|
* @param {Object} assets - Manager assets ({assetA, assetB} with precision)
|
|
437
540
|
* @returns {boolean}
|
|
438
541
|
*/
|
|
439
|
-
declare function chainOrderMatchesSlot(parsed:
|
|
542
|
+
declare function chainOrderMatchesSlot(parsed: ParsedChainOrder, slot: ManagedOrder, assets: AssetPair): boolean;
|
|
440
543
|
/**
|
|
441
544
|
* Whether a parsed chain order matches a grid slot within price tolerance:
|
|
442
545
|
* type-compatible (slot may be SPREAD), price within calculatePriceTolerance
|
|
@@ -452,7 +555,7 @@ declare function chainOrderMatchesSlot(parsed: any, slot: any, assets: any): boo
|
|
|
452
555
|
* @param {Object} assets - Manager assets ({assetA, assetB} with precision)
|
|
453
556
|
* @returns {boolean}
|
|
454
557
|
*/
|
|
455
|
-
declare function chainOrderMatchesSlotWithTolerance(parsed:
|
|
558
|
+
declare function chainOrderMatchesSlotWithTolerance(parsed: ParsedChainOrder, slot: ManagedOrder, assets: AssetPair): boolean;
|
|
456
559
|
/**
|
|
457
560
|
* Identity of a crossing-check candidate. Master orders carry orderId,
|
|
458
561
|
* unmatched chain orders carry chainOrderId, pending-broadcast wrappers
|
|
@@ -464,7 +567,7 @@ declare function chainOrderMatchesSlotWithTolerance(parsed: any, slot: any, asse
|
|
|
464
567
|
* @param {Object} o - Candidate order or pending-broadcast wrapper entry
|
|
465
568
|
* @returns {string|null} Chain/slot identity, or null when not placeable
|
|
466
569
|
*/
|
|
467
|
-
declare function crossingCandidateChainId(o:
|
|
570
|
+
declare function crossingCandidateChainId(o: CrossingCandidate | null | undefined): string | null;
|
|
468
571
|
/**
|
|
469
572
|
* Shared predicate for every crossing-placement guard (COW create/rotation/
|
|
470
573
|
* fallback, startup reconcile placement, price-correction re-queue). Accepts
|
|
@@ -479,7 +582,7 @@ declare function crossingCandidateChainId(o: any): string | null;
|
|
|
479
582
|
* @param {Map|null} [cancelOpIndexByOrderId=null] - orderId -> op index of its already-queued cancel
|
|
480
583
|
* @returns {boolean} True when the candidate participates in crossing checks
|
|
481
584
|
*/
|
|
482
|
-
declare function isCrossingCheckCandidate(o:
|
|
585
|
+
declare function isCrossingCheckCandidate(o: CrossingCandidate | null | undefined, excludeChainOrderId?: string | null, cancelOpIndexByOrderId?: Map<string, unknown> | null): boolean;
|
|
483
586
|
/**
|
|
484
587
|
* Shared candidate set for crossing-placement checks: master orders plus
|
|
485
588
|
* chain-side orders that may exist on chain but are not (yet) adopted into
|
|
@@ -491,9 +594,9 @@ declare function isCrossingCheckCandidate(o: any, excludeChainOrderId?: any, can
|
|
|
491
594
|
* master-grid-only checks cannot see (the pending/unmatched batch guards
|
|
492
595
|
* fire only for CREATE batches).
|
|
493
596
|
* @param {Object} manager - OrderManager instance (orders Map, _pendingBroadcasts, _lastUnmatchedChainOrders)
|
|
494
|
-
* @returns {
|
|
597
|
+
* @returns {unknown[]} Candidate orders/wrappers for findCrossedOrder
|
|
495
598
|
*/
|
|
496
|
-
declare function buildCrossingCheckCandidates(manager:
|
|
599
|
+
declare function buildCrossingCheckCandidates(manager: OrderManagerLike): CrossingCandidate[];
|
|
497
600
|
/**
|
|
498
601
|
* Filter orders array by type.
|
|
499
602
|
*
|
|
@@ -501,7 +604,7 @@ declare function buildCrossingCheckCandidates(manager: any): any[];
|
|
|
501
604
|
* @param {string} orderType - Order type to match (BUY, SELL, SPREAD)
|
|
502
605
|
* @returns {Array<Object>} Filtered orders of specified type
|
|
503
606
|
*/
|
|
504
|
-
declare function filterOrdersByType(orders:
|
|
607
|
+
declare function filterOrdersByType(orders: ManagedOrder[], orderType: OrderType): ManagedOrder[];
|
|
505
608
|
/**
|
|
506
609
|
* Build outside->center paired groups from mixed BUY/SELL items.
|
|
507
610
|
* SELL items are ordered highest->lowest price, BUY items lowest->highest,
|
|
@@ -514,7 +617,11 @@ declare function filterOrdersByType(orders: any, orderType: any): any[];
|
|
|
514
617
|
* @param {(item: any) => number|string} accessors.getPrice - Returns item price.
|
|
515
618
|
* @returns {Array<Array<*>>} Grouped items in outside->center pair order.
|
|
516
619
|
*/
|
|
517
|
-
declare function buildOutsideInPairGroups(items:
|
|
620
|
+
declare function buildOutsideInPairGroups<T>(items: T[], { isValid, getType, getPrice }: {
|
|
621
|
+
isValid?: (item: T) => boolean;
|
|
622
|
+
getType: (item: T) => string;
|
|
623
|
+
getPrice: (item: T) => number | string;
|
|
624
|
+
}): T[][];
|
|
518
625
|
/**
|
|
519
626
|
* Extract operation_results from a chain batch execution result.
|
|
520
627
|
* Handles the multiple result shapes returned by different chain library versions
|
|
@@ -523,14 +630,14 @@ declare function buildOutsideInPairGroups(items: any, { isValid, getType, getPri
|
|
|
523
630
|
* @param {Object|Array} result - Raw chain batch execution result.
|
|
524
631
|
* @returns {Array} Array of operation result tuples, or empty array if unrecognized.
|
|
525
632
|
*/
|
|
526
|
-
declare function extractBatchOperationResults(result:
|
|
633
|
+
declare function extractBatchOperationResults(result: unknown): unknown[][] | null;
|
|
527
634
|
/**
|
|
528
635
|
* Format an unmatched chain order/blocker for operator logs.
|
|
529
636
|
*
|
|
530
637
|
* @param {Object} order - Unmatched chain order or structural blocker.
|
|
531
638
|
* @returns {string} Compact human-readable diagnostic.
|
|
532
639
|
*/
|
|
533
|
-
declare function formatUnmatchedChainOrder(order:
|
|
640
|
+
declare function formatUnmatchedChainOrder(order: UnmatchedChainOrder | null | undefined): string;
|
|
534
641
|
/**
|
|
535
642
|
* Whether an unmatched chain-order entry is a deliberate hold that must NOT
|
|
536
643
|
* block CREATEs or snapshot recovery.
|
|
@@ -547,13 +654,17 @@ declare function formatUnmatchedChainOrder(order: any): string;
|
|
|
547
654
|
* @param {Object} order - Unmatched chain order entry.
|
|
548
655
|
* @returns {boolean} True when the entry is a non-blocking deferred hold.
|
|
549
656
|
*/
|
|
550
|
-
declare function isNonBlockingUnmatchedOrder(order:
|
|
657
|
+
declare function isNonBlockingUnmatchedOrder(order: {
|
|
658
|
+
reason?: unknown;
|
|
659
|
+
} | null | undefined): boolean;
|
|
551
660
|
/**
|
|
552
661
|
* @param {Object} order - Unmatched chain order entry.
|
|
553
662
|
* @returns {boolean} True when the hold is stranded and a structural resync is
|
|
554
663
|
* a plausible remedy (see STRANDED_HOLD_REASONS).
|
|
555
664
|
*/
|
|
556
|
-
declare function isStrandedHoldOrder(order:
|
|
665
|
+
declare function isStrandedHoldOrder(order: {
|
|
666
|
+
reason?: unknown;
|
|
667
|
+
} | null | undefined): boolean;
|
|
557
668
|
/**
|
|
558
669
|
* GRID-PRICE-INVARIANT — the price emitted for a slot must be its genesis
|
|
559
670
|
* level. Range guards (isChainPriceOutOfGrid) only test the configured min/max
|
|
@@ -568,10 +679,10 @@ declare function isStrandedHoldOrder(order: any): boolean;
|
|
|
568
679
|
*
|
|
569
680
|
* @param {string} slotId - Grid slot id (slot-<idx>)
|
|
570
681
|
* @param {number} price - Price about to be emitted
|
|
571
|
-
* @param {
|
|
682
|
+
* @param {unknown} genesis - manager._genesis (priceLevels table)
|
|
572
683
|
* @returns {{ok: boolean, reason: string, expected: number|null, idx: number|null, drift: number|null}}
|
|
573
684
|
*/
|
|
574
|
-
declare function checkGridPriceInvariant(slotId:
|
|
685
|
+
declare function checkGridPriceInvariant(slotId: string | null | undefined, price: number | string | null | undefined, genesis: GridGenesis | null | undefined): {
|
|
575
686
|
ok: boolean;
|
|
576
687
|
reason: string;
|
|
577
688
|
expected: number | null;
|
|
@@ -589,7 +700,7 @@ declare function checkGridPriceInvariant(slotId: any, price: any, genesis: any):
|
|
|
589
700
|
* reconcile sites treat `false` as blocking (skip the emission and let the next
|
|
590
701
|
* cycle re-plan). See docs/GRID_PRICE_INVARIANT.md.
|
|
591
702
|
*
|
|
592
|
-
* @param {
|
|
703
|
+
* @param {unknown} manager - OrderManager (reads _genesis, writes logger)
|
|
593
704
|
* @param {string} slotId - Destination slot id whose level the price must match
|
|
594
705
|
* @param {number} price - Price about to be emitted
|
|
595
706
|
* @param {string} site - Emitting site label (CREATE / UPDATE / RECONCILE-*)
|
|
@@ -597,14 +708,14 @@ declare function checkGridPriceInvariant(slotId: any, price: any, genesis: any):
|
|
|
597
708
|
* at the reconcile sites treat `false` as a blocking mismatch and skip the
|
|
598
709
|
* emission, so this must return the check result rather than void.
|
|
599
710
|
*/
|
|
600
|
-
declare function reportGridPriceInvariant(manager:
|
|
711
|
+
declare function reportGridPriceInvariant(manager: OrderManagerLike, slotId: string | null | undefined, price: number | string, site: string): boolean;
|
|
601
712
|
/**
|
|
602
713
|
* Check if order is on blockchain (ACTIVE or PARTIAL state).
|
|
603
714
|
*
|
|
604
715
|
* @param {Object} order - Order to check
|
|
605
716
|
* @returns {boolean} True if order has on-chain state
|
|
606
717
|
*/
|
|
607
|
-
declare function isOrderOnChain(order:
|
|
718
|
+
declare function isOrderOnChain(order: SlotLike | null | undefined): boolean;
|
|
608
719
|
/**
|
|
609
720
|
* Resolve the type to keep when a slot holding a live on-chain order would
|
|
610
721
|
* otherwise be reassigned to SPREAD. SPREAD+ACTIVE/PARTIAL is an illegal state
|
|
@@ -624,14 +735,17 @@ declare function isOrderOnChain(order: any): boolean;
|
|
|
624
735
|
* @param {Object} ORDER_TYPES - ORDER_TYPES constants
|
|
625
736
|
* @returns {string} Type to keep for the on-chain slot
|
|
626
737
|
*/
|
|
627
|
-
declare function resolveOnChainRetypeType(slot:
|
|
738
|
+
declare function resolveOnChainRetypeType(slot: SlotLike, idx: number, buyEndIdx: number, orderTypes: {
|
|
739
|
+
BUY: OrderType;
|
|
740
|
+
SELL: OrderType;
|
|
741
|
+
}): OrderType;
|
|
628
742
|
/**
|
|
629
743
|
* Check if order is virtual (not on blockchain yet).
|
|
630
744
|
*
|
|
631
745
|
* @param {Object} order - Order to check
|
|
632
746
|
* @returns {boolean} True if order in VIRTUAL state
|
|
633
747
|
*/
|
|
634
|
-
declare function isOrderVirtual(order:
|
|
748
|
+
declare function isOrderVirtual(order: SlotLike | null | undefined): boolean;
|
|
635
749
|
/**
|
|
636
750
|
* Whether a slot is an empty reusable placeholder: VIRTUAL, no chain order,
|
|
637
751
|
* and zero size. Empty slots are normalized to SPREAD (side-neutral) so their
|
|
@@ -654,7 +768,7 @@ declare function isOrderVirtual(order: any): boolean;
|
|
|
654
768
|
* @param {boolean} [opts.allowNullType=false] - Treat `type: null` slots as empty.
|
|
655
769
|
* @returns {boolean} True when the slot is a size-0 VIRTUAL placeholder.
|
|
656
770
|
*/
|
|
657
|
-
declare function isEmptyGridSlot(slot:
|
|
771
|
+
declare function isEmptyGridSlot(slot: SlotLike | null | undefined, liveSlot?: SlotLike | null, opts?: {
|
|
658
772
|
allowNullType?: boolean;
|
|
659
773
|
}): boolean;
|
|
660
774
|
/**
|
|
@@ -663,7 +777,9 @@ declare function isEmptyGridSlot(slot: any, liveSlot?: any, opts?: {
|
|
|
663
777
|
* @param {Object} order - Order to check
|
|
664
778
|
* @returns {boolean} True if order has orderId
|
|
665
779
|
*/
|
|
666
|
-
declare function hasOnChainId(order:
|
|
780
|
+
declare function hasOnChainId(order: {
|
|
781
|
+
orderId?: string | null;
|
|
782
|
+
} | null | undefined): boolean;
|
|
667
783
|
/**
|
|
668
784
|
* Check if order is placed and confirmed on blockchain.
|
|
669
785
|
* Must be on-chain (ACTIVE/PARTIAL) with orderId.
|
|
@@ -671,7 +787,7 @@ declare function hasOnChainId(order: any): boolean;
|
|
|
671
787
|
* @param {Object} order - Order to check
|
|
672
788
|
* @returns {boolean} True if order is confirmed placed
|
|
673
789
|
*/
|
|
674
|
-
declare function isOrderPlaced(order:
|
|
790
|
+
declare function isOrderPlaced(order: SlotLike | null | undefined): boolean;
|
|
675
791
|
/**
|
|
676
792
|
* Check if order is phantom (on-chain but missing orderId).
|
|
677
793
|
* Indicates a sync error or ghost order state.
|
|
@@ -679,7 +795,7 @@ declare function isOrderPlaced(order: any): boolean;
|
|
|
679
795
|
* @param {Object} order - Order to check
|
|
680
796
|
* @returns {boolean} True if order appears on-chain but has no ID
|
|
681
797
|
*/
|
|
682
|
-
declare function isPhantomOrder(order:
|
|
798
|
+
declare function isPhantomOrder(order: SlotLike | null | undefined): boolean;
|
|
683
799
|
/**
|
|
684
800
|
* Check if slot is available for new order placement.
|
|
685
801
|
* Slot must be VIRTUAL (not on-chain) and have no orderId.
|
|
@@ -687,7 +803,7 @@ declare function isPhantomOrder(order: any): boolean;
|
|
|
687
803
|
* @param {Object} order - Order/slot to check
|
|
688
804
|
* @returns {boolean} True if slot available
|
|
689
805
|
*/
|
|
690
|
-
declare function isSlotAvailable(order:
|
|
806
|
+
declare function isSlotAvailable(order: SlotLike | null | undefined): boolean;
|
|
691
807
|
/**
|
|
692
808
|
* Check if order size meets health thresholds.
|
|
693
809
|
* Must be above absolute minimum and double-dust threshold.
|
|
@@ -698,7 +814,7 @@ declare function isSlotAvailable(order: any): boolean;
|
|
|
698
814
|
* @param {number} idealSize - Ideal grid size for dust calculation
|
|
699
815
|
* @returns {boolean} True if order is healthy
|
|
700
816
|
*/
|
|
701
|
-
declare function isOrderHealthy(size:
|
|
817
|
+
declare function isOrderHealthy(size: number | string, type: OrderType, assets: AssetPair, idealSize: number | string): boolean;
|
|
702
818
|
/**
|
|
703
819
|
* Check if any size in array falls below threshold.
|
|
704
820
|
* Used for validation before order placement.
|
|
@@ -709,7 +825,7 @@ declare function isOrderHealthy(size: any, type: any, assets: any, idealSize: an
|
|
|
709
825
|
* @param {boolean} [includeNonFinite=false] - Treat non-finite values as below threshold
|
|
710
826
|
* @returns {boolean} True if any size is below threshold
|
|
711
827
|
*/
|
|
712
|
-
declare function checkSizeThreshold(sizes:
|
|
828
|
+
declare function checkSizeThreshold(sizes: number[], threshold: number, precision: number, includeNonFinite?: boolean): boolean;
|
|
713
829
|
/**
|
|
714
830
|
* Check if any sizes are below minimum (including non-finite values).
|
|
715
831
|
* Wrapper for checkSizeThreshold with includeNonFinite=true.
|
|
@@ -719,7 +835,7 @@ declare function checkSizeThreshold(sizes: any, threshold: any, precision: any,
|
|
|
719
835
|
* @param {number} precision - Asset precision
|
|
720
836
|
* @returns {boolean} True if any size is below minimum
|
|
721
837
|
*/
|
|
722
|
-
declare function checkSizesBeforeMinimum(sizes:
|
|
838
|
+
declare function checkSizesBeforeMinimum(sizes: number[], minSize: number, precision: number): boolean;
|
|
723
839
|
/**
|
|
724
840
|
* Calculate ideal grid boundary based on reference price.
|
|
725
841
|
* Places boundary near reference price with gap spacing in mind.
|
|
@@ -736,7 +852,7 @@ declare function checkSizesBeforeMinimum(sizes: any, minSize: any, precision: an
|
|
|
736
852
|
* @param {number} gapSlots - Number of gap slots between buy and sell
|
|
737
853
|
* @returns {number} Ideal boundary index or -1 if slots empty
|
|
738
854
|
*/
|
|
739
|
-
declare function calculateIdealBoundary(allSlots:
|
|
855
|
+
declare function calculateIdealBoundary(allSlots: SlotLike[], referencePrice: number | string, gapSlots: number): number;
|
|
740
856
|
/**
|
|
741
857
|
* Assign BUY/SELL/SPREAD roles to grid slots based on boundary.
|
|
742
858
|
* Slots below boundary are BUY, above boundary are SELL, between are SPREAD.
|
|
@@ -751,10 +867,61 @@ declare function calculateIdealBoundary(allSlots: any, referencePrice: any, gapS
|
|
|
751
867
|
* @param {boolean} [options.assignOnChain=false] - Override on-chain orders if true
|
|
752
868
|
* @returns {Array<Object>} Slots with updated type assignments
|
|
753
869
|
*/
|
|
754
|
-
|
|
870
|
+
interface DeltaAction {
|
|
871
|
+
type: 'create' | 'update' | 'cancel';
|
|
872
|
+
id: string;
|
|
873
|
+
order?: ManagedOrder;
|
|
874
|
+
prevOrder?: ManagedOrder;
|
|
875
|
+
orderId?: string | null;
|
|
876
|
+
[key: string]: unknown;
|
|
877
|
+
}
|
|
878
|
+
interface ReserveConfig {
|
|
879
|
+
reserveOrders?: number | {
|
|
880
|
+
buy?: number;
|
|
881
|
+
sell?: number;
|
|
882
|
+
[key: string]: unknown;
|
|
883
|
+
};
|
|
884
|
+
activeOrders?: {
|
|
885
|
+
buy?: number;
|
|
886
|
+
sell?: number;
|
|
887
|
+
[key: string]: unknown;
|
|
888
|
+
};
|
|
889
|
+
startPrice?: number | string;
|
|
890
|
+
minPrice?: number | string | null;
|
|
891
|
+
maxPrice?: number | string | null;
|
|
892
|
+
assetA?: string;
|
|
893
|
+
assetB?: string;
|
|
894
|
+
feeParams?: {
|
|
895
|
+
BTS_RESERVATION_MULTIPLIER?: number;
|
|
896
|
+
[key: string]: unknown;
|
|
897
|
+
};
|
|
898
|
+
min_BTS_value?: number;
|
|
899
|
+
incrementPercent?: number;
|
|
900
|
+
targetSpreadPercent?: number;
|
|
901
|
+
gridLimits?: {
|
|
902
|
+
[key: string]: unknown;
|
|
903
|
+
};
|
|
904
|
+
[key: string]: unknown;
|
|
905
|
+
}
|
|
906
|
+
interface ManagerFundsLike {
|
|
907
|
+
allocatedBuy?: number;
|
|
908
|
+
allocatedSell?: number;
|
|
909
|
+
chainFreeBuy?: number;
|
|
910
|
+
chainFreeSell?: number;
|
|
911
|
+
btsBalance?: {
|
|
912
|
+
free?: number;
|
|
913
|
+
total?: number;
|
|
914
|
+
locked?: number;
|
|
915
|
+
} | null;
|
|
916
|
+
}
|
|
917
|
+
declare function assignGridRoles<T extends SlotLike>(allSlots: T[], boundaryIdx: number, gapSlots: number, ORDER_TYPES: {
|
|
918
|
+
BUY: OrderType;
|
|
919
|
+
SELL: OrderType;
|
|
920
|
+
SPREAD: OrderType;
|
|
921
|
+
}, _ORDER_STATES: unknown, options?: {
|
|
755
922
|
assignOnChain?: boolean;
|
|
756
|
-
getCurrentSlot?: (id:
|
|
757
|
-
}):
|
|
923
|
+
getCurrentSlot?: (id: string) => ManagedOrder | undefined;
|
|
924
|
+
}): T[];
|
|
758
925
|
/**
|
|
759
926
|
* Determine if grid is out of spread and by how many steps.
|
|
760
927
|
* Compares current spread against nominal with tolerance.
|
|
@@ -768,27 +935,20 @@ declare function assignGridRoles(allSlots: any, boundaryIdx: any, gapSlots: any,
|
|
|
768
935
|
* @param {number} [incrementPercent=0.5] - Grid increment percentage
|
|
769
936
|
* @returns {number} Excess steps (0 if in-spread, >0 if out-of-spread)
|
|
770
937
|
*/
|
|
771
|
-
declare function shouldFlagOutOfSpread(currentSpread:
|
|
938
|
+
declare function shouldFlagOutOfSpread(currentSpread: number, nominalSpread: number, toleranceSteps: number, buyCount: number, sellCount: number, incrementPercent?: number): number;
|
|
772
939
|
/**
|
|
773
940
|
* Build complete index set from grid
|
|
774
941
|
* @param {Map} grid - Order grid
|
|
775
942
|
* @returns {Object} - Index object with state and type indexes
|
|
776
943
|
*/
|
|
777
|
-
declare function buildIndexes(grid:
|
|
778
|
-
virtual: Set<unknown>;
|
|
779
|
-
active: Set<unknown>;
|
|
780
|
-
partial: Set<unknown>;
|
|
781
|
-
buy: Set<unknown>;
|
|
782
|
-
sell: Set<unknown>;
|
|
783
|
-
spread: Set<unknown>;
|
|
784
|
-
};
|
|
944
|
+
declare function buildIndexes(grid: Map<string, ManagedOrder>): Record<string, Set<string>>;
|
|
785
945
|
/**
|
|
786
946
|
* Validate index consistency (for testing/debugging)
|
|
787
947
|
* @param {Map} grid - Order grid
|
|
788
948
|
* @param {Object} indexes - Index object
|
|
789
949
|
* @returns {Object} - Validation result
|
|
790
950
|
*/
|
|
791
|
-
declare function validateIndexes(grid:
|
|
951
|
+
declare function validateIndexes(grid: Map<string, ManagedOrder>, indexes: Record<string, Set<string>>): {
|
|
792
952
|
valid: boolean;
|
|
793
953
|
errors: string[];
|
|
794
954
|
};
|
|
@@ -800,7 +960,7 @@ declare function validateIndexes(grid: any, indexes: any): {
|
|
|
800
960
|
* @param {Object} [options.precisions] - Optional precision hints {buyPrecision, sellPrecision, defaultPrecision, priceRelativeTolerance}
|
|
801
961
|
* @returns {boolean} - True if orders are equivalent
|
|
802
962
|
*/
|
|
803
|
-
declare function ordersEqual(a:
|
|
963
|
+
declare function ordersEqual(a: ManagedOrder | null | undefined, b: ManagedOrder | null | undefined, options?: {
|
|
804
964
|
precisions?: {
|
|
805
965
|
buyPrecision?: number;
|
|
806
966
|
sellPrecision?: number;
|
|
@@ -821,7 +981,20 @@ declare function ordersEqual(a: any, b: any, options?: {
|
|
|
821
981
|
* @param {Object} [options={}] - Delta options forwarded to ordersEqual
|
|
822
982
|
* @returns {Array} - Array of action objects
|
|
823
983
|
*/
|
|
824
|
-
declare function buildDelta(masterGrid:
|
|
984
|
+
declare function buildDelta(masterGrid: Map<string, ManagedOrder>, workingGrid: Map<string, ManagedOrder>, options?: {
|
|
985
|
+
precisions?: {
|
|
986
|
+
buyPrecision?: number;
|
|
987
|
+
sellPrecision?: number;
|
|
988
|
+
defaultPrecision?: number;
|
|
989
|
+
priceRelativeTolerance?: number;
|
|
990
|
+
};
|
|
991
|
+
comparePrecisions?: {
|
|
992
|
+
buyPrecision?: number;
|
|
993
|
+
sellPrecision?: number;
|
|
994
|
+
defaultPrecision?: number;
|
|
995
|
+
priceRelativeTolerance?: number;
|
|
996
|
+
};
|
|
997
|
+
}): DeltaAction[];
|
|
825
998
|
/**
|
|
826
999
|
* Check whether a fill is eligible to drive boundary shift / rotation.
|
|
827
1000
|
* Partials only count when they are delayed-rotation triggers.
|
|
@@ -829,8 +1002,30 @@ declare function buildDelta(masterGrid: any, workingGrid: any, options?: any): a
|
|
|
829
1002
|
* @param {Object} fill - Fill event
|
|
830
1003
|
* @returns {boolean} True when the fill may shift the boundary
|
|
831
1004
|
*/
|
|
832
|
-
declare function isShiftEligibleFill(fill:
|
|
833
|
-
|
|
1005
|
+
declare function isShiftEligibleFill(fill: {
|
|
1006
|
+
isPartial?: boolean;
|
|
1007
|
+
isDelayedRotationTrigger?: boolean;
|
|
1008
|
+
[key: string]: unknown;
|
|
1009
|
+
} | null | undefined): boolean;
|
|
1010
|
+
declare function deriveTargetBoundary(fills: Array<{
|
|
1011
|
+
id?: string;
|
|
1012
|
+
price?: number;
|
|
1013
|
+
type?: string;
|
|
1014
|
+
[key: string]: unknown;
|
|
1015
|
+
}> | null | undefined, currentBoundaryIdx: number | null | undefined, allSlots: ManagedOrder[], config: {
|
|
1016
|
+
startPrice?: number | string;
|
|
1017
|
+
genesisStartPrice?: number | string;
|
|
1018
|
+
activeOrders?: {
|
|
1019
|
+
buy?: number;
|
|
1020
|
+
sell?: number;
|
|
1021
|
+
[key: string]: unknown;
|
|
1022
|
+
};
|
|
1023
|
+
[key: string]: unknown;
|
|
1024
|
+
} | null | undefined, gapSlots: number, crossChunkBudget?: number | null, pendingCrawls?: Array<{
|
|
1025
|
+
slotId?: string;
|
|
1026
|
+
side?: string;
|
|
1027
|
+
[key: string]: unknown;
|
|
1028
|
+
}> | null, edgeAnchors?: {
|
|
834
1029
|
buy?: number | null;
|
|
835
1030
|
sell?: number | null;
|
|
836
1031
|
} | null): {
|
|
@@ -852,10 +1047,10 @@ declare function deriveTargetBoundary(fills: any, currentBoundaryIdx: any, allSl
|
|
|
852
1047
|
* dropped rather than stranding live orders. Commits clear the record, so
|
|
853
1048
|
* entries present here predate every commit since recording — always owed.
|
|
854
1049
|
*
|
|
855
|
-
* @param {
|
|
1050
|
+
* @param {unknown} manager - OrderManager (boundaryIdx, orders, config restored)
|
|
856
1051
|
* @returns {{applied: boolean, from?: number, to?: number, count?: number, reason?: string}}
|
|
857
1052
|
*/
|
|
858
|
-
export declare function consumePendingFillCrawls(manager:
|
|
1053
|
+
export declare function consumePendingFillCrawls(manager: OrderManagerLike): {
|
|
859
1054
|
applied: boolean;
|
|
860
1055
|
from?: number;
|
|
861
1056
|
to?: number;
|
|
@@ -876,14 +1071,14 @@ export declare function consumePendingFillCrawls(manager: any): {
|
|
|
876
1071
|
* @param {string} side - 'buy' or 'sell'
|
|
877
1072
|
* @returns {number} Reserve count for the side (>= 0 integer)
|
|
878
1073
|
*/
|
|
879
|
-
declare function resolveReserveCount(config:
|
|
1074
|
+
declare function resolveReserveCount(config: ReserveConfig | null | undefined, side: string): number;
|
|
880
1075
|
/**
|
|
881
1076
|
* Total reserve count across both sides (fee/count totals).
|
|
882
1077
|
*
|
|
883
1078
|
* @param {Object} config - Bot configuration
|
|
884
1079
|
* @returns {number} Total reserves (buy + sell)
|
|
885
1080
|
*/
|
|
886
|
-
declare function resolveReserveOrders(config:
|
|
1081
|
+
declare function resolveReserveOrders(config: ReserveConfig | null | undefined): number;
|
|
887
1082
|
/**
|
|
888
1083
|
* Edge-pinned reserve id set for one side, or null when disabled.
|
|
889
1084
|
* Type/price-filtered, then ordered by the SAME edge order the placement
|
|
@@ -912,17 +1107,17 @@ declare function resolveReserveOrders(config: any): number;
|
|
|
912
1107
|
* dedicated reserves and the deficit never fires (issue #27 follow-up).
|
|
913
1108
|
* @returns {Set<string>|null} Edge slot ids, or null when side disabled
|
|
914
1109
|
*/
|
|
915
|
-
declare function reserveEdgeIdSet(allSlots:
|
|
1110
|
+
declare function reserveEdgeIdSet(allSlots: SlotLike[], config: ReserveConfig | null | undefined, orderType: OrderType, anchorPrice?: unknown, excludeIds?: Set<string> | null): Set<string> | null;
|
|
916
1111
|
/**
|
|
917
1112
|
* Window member ids for one side from the live manager (see
|
|
918
1113
|
* windowIdSetFromSlots). Delegates so the manager and explicit-geometry
|
|
919
1114
|
* callers share one definition.
|
|
920
1115
|
*
|
|
921
|
-
* @param {
|
|
1116
|
+
* @param {unknown} manager - OrderManager (orders Map, config, boundaryIdx)
|
|
922
1117
|
* @param {string} orderType - ORDER_TYPES.BUY or ORDER_TYPES.SELL
|
|
923
1118
|
* @returns {Set<string>|null} Window slot ids, or null when geometry unknown
|
|
924
1119
|
*/
|
|
925
|
-
declare function liveWindowIdSet(manager:
|
|
1120
|
+
declare function liveWindowIdSet(manager: OrderManagerLike, orderType: OrderType): Set<string> | null;
|
|
926
1121
|
/**
|
|
927
1122
|
* Refill-slot wire for the COW boundary hold (single source for both plan
|
|
928
1123
|
* producers: the fill-driven COW engine and the divergence fold).
|
|
@@ -951,19 +1146,19 @@ declare function liveWindowIdSet(manager: any, orderType: any): Set<string> | nu
|
|
|
951
1146
|
* @param {Iterable<Object>} [options.slots] - Master slots (reserve classification)
|
|
952
1147
|
* @param {{buy?: number|null, sell?: number|null}} [options.edgeAnchors] - Live
|
|
953
1148
|
* edge anchors (same pair the strategy classifies reserve fills against)
|
|
954
|
-
* @param {
|
|
1149
|
+
* @param {unknown} [options.manager] - OrderManager for the window exclusion (same
|
|
955
1150
|
* set the placement pickers exclude); omit to fall back to the previous
|
|
956
1151
|
* exclusion-free classification (fail-open)
|
|
957
1152
|
* @returns {string[]} Refill slot ids (CREATE ids minus reserve edge ids)
|
|
958
1153
|
*/
|
|
959
|
-
declare function collectRefillSlotIds(actions:
|
|
960
|
-
config?:
|
|
961
|
-
slots?:
|
|
1154
|
+
declare function collectRefillSlotIds(actions: CowAction[], options?: {
|
|
1155
|
+
config?: ReserveConfig | null;
|
|
1156
|
+
slots?: unknown;
|
|
962
1157
|
edgeAnchors?: {
|
|
963
1158
|
buy?: number | null;
|
|
964
1159
|
sell?: number | null;
|
|
965
1160
|
} | null;
|
|
966
|
-
manager?:
|
|
1161
|
+
manager?: OrderManagerLike | null;
|
|
967
1162
|
}): string[];
|
|
968
1163
|
/**
|
|
969
1164
|
* Resolved bound anchor for reserve edges from CONFIG alone.
|
|
@@ -983,7 +1178,7 @@ declare function collectRefillSlotIds(actions: any, options?: {
|
|
|
983
1178
|
* @param {string} side - 'buy' or 'sell'
|
|
984
1179
|
* @returns {number|null} Finite anchor price, or null
|
|
985
1180
|
*/
|
|
986
|
-
declare function resolveReserveEdgeAnchorPrice(config:
|
|
1181
|
+
declare function resolveReserveEdgeAnchorPrice(config: ReserveConfig | null | undefined, side: string): number | null;
|
|
987
1182
|
/** Manager surface the live reserve-edge anchor reads (structural view). */
|
|
988
1183
|
type ReserveEdgeAnchorManager = {
|
|
989
1184
|
_genesis?: {
|
|
@@ -1038,7 +1233,7 @@ declare function resolveLiveReserveEdgeAnchorPrice(manager: ReserveEdgeAnchorMan
|
|
|
1038
1233
|
* @param {number|null} anchorPrice - Resolved bound anchor (null = rank fallback)
|
|
1039
1234
|
* @returns {number} Comparator result for Array.prototype.sort
|
|
1040
1235
|
*/
|
|
1041
|
-
declare function compareReserveEdge(a:
|
|
1236
|
+
declare function compareReserveEdge(a: SlotLike, b: SlotLike, edge: string, anchorPrice: number | null): number;
|
|
1042
1237
|
/**
|
|
1043
1238
|
* Central edge selector: take reserve slots from a price-ascending list,
|
|
1044
1239
|
* skipping already-windowed ids. Both edges anchor at the live grid's own
|
|
@@ -1058,7 +1253,7 @@ declare function compareReserveEdge(a: any, b: any, edge: any, anchorPrice: any)
|
|
|
1058
1253
|
* @param {number|null} [anchorPrice] - Live edge anchor for the side (null = rank-based)
|
|
1059
1254
|
* @returns {Array<Object>} Reserve slots (ascending for floor, descending for ceiling)
|
|
1060
1255
|
*/
|
|
1061
|
-
declare function selectReserveEdgeSlots(sortedAsc:
|
|
1256
|
+
declare function selectReserveEdgeSlots<T extends SlotLike>(sortedAsc: T[], count: number, excludeIds: Set<string> | null, edge: string, anchorPrice?: number | null): T[];
|
|
1062
1257
|
/**
|
|
1063
1258
|
* Total target order count across both sides (used for BTS fee calculation).
|
|
1064
1259
|
* Single source of truth so every budget derivation sizes identically.
|
|
@@ -1067,7 +1262,7 @@ declare function selectReserveEdgeSlots(sortedAsc: any, count: any, excludeIds:
|
|
|
1067
1262
|
* @param {Object} config - Bot configuration
|
|
1068
1263
|
* @returns {number} Total target order count
|
|
1069
1264
|
*/
|
|
1070
|
-
declare function getActiveOrdersTotal(config:
|
|
1265
|
+
declare function getActiveOrdersTotal(config: ReserveConfig | null | undefined): number;
|
|
1071
1266
|
/**
|
|
1072
1267
|
* Calculate side budget after BTS fee deduction.
|
|
1073
1268
|
*
|
|
@@ -1077,7 +1272,7 @@ declare function getActiveOrdersTotal(config: any): number;
|
|
|
1077
1272
|
* @param {number} totalTarget - Total target order count (used for BTS fee calculation on both sides)
|
|
1078
1273
|
* @returns {number} Available budget for the side
|
|
1079
1274
|
*/
|
|
1080
|
-
declare function getSideBudget(side:
|
|
1275
|
+
declare function getSideBudget(side: string, funds: ManagerFundsLike | ProjectedFunds | null, config: ReserveConfig, totalTarget: number): number;
|
|
1081
1276
|
/**
|
|
1082
1277
|
* Calculate sizes for all slots on a side using weighted distribution.
|
|
1083
1278
|
*
|
|
@@ -1089,7 +1284,7 @@ declare function getSideBudget(side: any, funds: any, config: any, totalTarget:
|
|
|
1089
1284
|
* @param {Object} assets - Asset metadata for precision
|
|
1090
1285
|
* @returns {Array} Array of calculated sizes
|
|
1091
1286
|
*/
|
|
1092
|
-
declare function calculateBudgetedSizes(slots:
|
|
1287
|
+
declare function calculateBudgetedSizes(slots: SlotLike[], side: string, budget: number, weightDist: unknown, incrementPercent: number | undefined, assets: AssetPair | null): number[];
|
|
1093
1288
|
/**
|
|
1094
1289
|
* Whether a chain order still matches the cached pre-update state the
|
|
1095
1290
|
* limit_order_update delta was built from. Only a provably-unchanged order
|
|
@@ -1099,7 +1294,17 @@ declare function calculateBudgetedSizes(slots: any, side: any, budget: any, weig
|
|
|
1099
1294
|
* @param {Object|null} cachedRaw - The rawOnChain cache captured at build time
|
|
1100
1295
|
* @returns {boolean}
|
|
1101
1296
|
*/
|
|
1102
|
-
declare function chainOrderUnchangedFromCache(chainOrder:
|
|
1297
|
+
declare function chainOrderUnchangedFromCache(chainOrder: ChainOrder | null | undefined, cachedRaw: {
|
|
1298
|
+
sell_price?: {
|
|
1299
|
+
base?: {
|
|
1300
|
+
amount?: unknown;
|
|
1301
|
+
};
|
|
1302
|
+
quote?: {
|
|
1303
|
+
amount?: unknown;
|
|
1304
|
+
};
|
|
1305
|
+
};
|
|
1306
|
+
for_sale?: unknown;
|
|
1307
|
+
} | null | undefined): boolean;
|
|
1103
1308
|
/**
|
|
1104
1309
|
* PRE-BROADCAST CROSSED-BOOK ASSERT (defense-in-depth, any-writer detection).
|
|
1105
1310
|
*
|
|
@@ -1113,7 +1318,7 @@ declare function chainOrderUnchangedFromCache(chainOrder: any, cachedRaw: any):
|
|
|
1113
1318
|
*
|
|
1114
1319
|
* Detector only: any internal failure returns null (never blocks a broadcast).
|
|
1115
1320
|
*/
|
|
1116
|
-
declare function detectCrossedBookPlan(manager:
|
|
1321
|
+
declare function detectCrossedBookPlan(manager: OrderManagerLike, actions: CowAction[]): string | null;
|
|
1117
1322
|
/**
|
|
1118
1323
|
* Collect every on-chain order id master currently needs to converge against,
|
|
1119
1324
|
* so adoption can re-read them by id (immune to the get_full_accounts window
|
|
@@ -1124,20 +1329,35 @@ declare function detectCrossedBookPlan(manager: any, actions: any[]): string | n
|
|
|
1124
1329
|
* - the batch's fresh CREATE ids extracted from the broadcast result
|
|
1125
1330
|
* (operation_results[i][1] aligns positionally with placedContexts[i]).
|
|
1126
1331
|
*
|
|
1127
|
-
* @param {
|
|
1128
|
-
* @param {
|
|
1129
|
-
* @param {
|
|
1332
|
+
* @param {unknown} mgr - bot.manager
|
|
1333
|
+
* @param {unknown} placedResults - broadcast result (has operation_results); null when unavailable
|
|
1334
|
+
* @param {unknown[]} placedContexts - opContexts (aligned with operation_results); null when unavailable
|
|
1130
1335
|
* @param {string[]|null} [extraCreateIds=null] - fresh CREATE chain ids from another
|
|
1131
1336
|
* authoritative source (e.g. the uncertain-broadcast poll confirmation) when
|
|
1132
1337
|
* no broadcast result exists; merged into createIds so the lagging-create
|
|
1133
1338
|
* retry guards them
|
|
1134
1339
|
* @returns {string[]} Unique, well-formed 1.7.x order ids
|
|
1135
1340
|
*/
|
|
1136
|
-
declare function collectKnownOnChainOrderIds(mgr:
|
|
1341
|
+
declare function collectKnownOnChainOrderIds(mgr: OrderManagerLike, placedResults: unknown, placedContexts: Array<{
|
|
1342
|
+
kind?: string;
|
|
1343
|
+
order?: {
|
|
1344
|
+
orderId?: string | null;
|
|
1345
|
+
} | null;
|
|
1346
|
+
rotation?: {
|
|
1347
|
+
oldOrder?: {
|
|
1348
|
+
orderId?: string | null;
|
|
1349
|
+
} | null;
|
|
1350
|
+
} | null;
|
|
1351
|
+
updateInfo?: {
|
|
1352
|
+
partialOrder?: {
|
|
1353
|
+
orderId?: string | null;
|
|
1354
|
+
} | null;
|
|
1355
|
+
} | null;
|
|
1356
|
+
} | null> | null, extraCreateIds?: string[] | null): {
|
|
1137
1357
|
masterIds: string[];
|
|
1138
1358
|
createIds: string[];
|
|
1139
1359
|
all: string[];
|
|
1140
1360
|
};
|
|
1141
1361
|
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 };
|
|
1142
|
-
export { resolveReserveEdgeAnchorPrice, resolveLiveReserveEdgeAnchorPrice, compareReserveEdge, collectRefillSlotIds };
|
|
1362
|
+
export { resolveReserveEdgeAnchorPrice, resolveLiveReserveEdgeAnchorPrice, compareReserveEdge, collectRefillSlotIds, recordOrderPlacement, isFreshlyPlacedOrder, _filterUnmatchedChainOrders };
|
|
1143
1363
|
//# sourceMappingURL=order.d.ts.map
|