dexbot 1.6.11 → 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 +35 -4
- package/README.md +2 -1
- package/analysis/README.md +2 -0
- package/analysis/tradingview/README.md +1 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
- 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 +2 -1
- 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 -17
- 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 +6 -5
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +11 -63
- 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 +7 -4
- 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 +1 -1
- package/dist/analysis/fills_source.d.ts +2 -2
- package/dist/analysis/fills_source.js +14 -12
- 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.js +29 -29
- 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 -1
- package/dist/analysis/trade_profitability.d.ts +23 -2
- package/dist/analysis/trade_profitability.js +50 -50
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
- package/dist/analysis/tradingview/analyze_tradingview.js +6 -5
- package/dist/analysis/tradingview/grid_reset_config.d.ts +41 -32
- package/dist/analysis/tradingview/grid_reset_config.js +23 -11
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -9
- package/dist/analysis/tradingview/grid_reset_sim.js +4 -3
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +18 -19
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -1
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +5 -5
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +5 -4
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +9 -3
- package/dist/analysis/trend_detection/huber_scale_variants.js +4 -4
- 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 +11 -11
- 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 +284 -117
- package/dist/market_adapter/core/market_adapter_service.js +137 -113
- package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
- package/dist/market_adapter/core/strategies/ama.js +2 -4
- 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 +34 -6
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +7 -7
- 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 +96 -224
- 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 -21
- 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 -32
- package/dist/market_adapter/market_adapter.js +67 -48
- 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 +527 -31
- package/dist/modules/constants.js +15 -47
- 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 +108 -83
- 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 +16 -15
- 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 +4 -4
- 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 +225 -180
- package/dist/modules/order/manager.js +80 -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 +84 -53
- 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 +310 -110
- package/dist/modules/order/utils/order.js +122 -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 +1 -4
- package/dist/modules/paths.js +1 -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 +1 -12
- package/dist/modules/utils/time_range.js +1 -1
- 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 +65 -40
- package/dist/scripts/chart_command.d.ts +27 -18
- package/dist/scripts/chart_command.js +13 -11
- 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/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 +63 -35
- 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 +10 -9
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
- package/docs/GRID_RECALCULATION.md +4 -2
- 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 +14 -3
- package/docs/architecture.md +12 -9
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +6 -1
- package/modules/README.md +4 -1
- package/package.json +4 -1
|
@@ -13,66 +13,106 @@
|
|
|
13
13
|
* SECTION 3: ORDER MANAGER CLASS
|
|
14
14
|
* ===============================================================================
|
|
15
15
|
*/
|
|
16
|
+
import { WorkingGrid } from './working_grid.js';
|
|
17
|
+
import Logger from './logger.js';
|
|
18
|
+
import Accountant from './accounting.js';
|
|
19
|
+
import StrategyEngine from './strategy.js';
|
|
20
|
+
import SyncEngine from './sync_engine.js';
|
|
21
|
+
import type { GridGenesis } from './utils/math.js';
|
|
22
|
+
import type { OrderManagerLike, ManagedOrder, GridConfig, AssetPair, AccountTotals, ManagerFunds, PendingPriceCorrection, ProcessedFillStoreLike, PendingBroadcast, ManagerLock, IllegalStateSignal, AccountingFailureSignal, BotMetrics, AccountOrdersLike, CowAction, RebalanceResult, ProjectedFunds, SyncResult, FillHistorySyncResult, FundDriftCheck, ChainFundsSnapshot, OrderType, OrderState, UnknownRecord } from '../types.js';
|
|
23
|
+
/**
|
|
24
|
+
* Stale-placement veto: whether a placement action crosses the plan's own
|
|
25
|
+
* boundary and would fill immediately on stale market data.
|
|
26
|
+
* - BUY create/update targeting a slot ABOVE the boundary is dropped; SELL
|
|
27
|
+
* create/update targeting a slot BELOW the boundary is dropped. Strict
|
|
28
|
+
* comparison: a placement AT the boundary is kept (the boundary slot is
|
|
29
|
+
* the spread, which reconcile never targets).
|
|
30
|
+
* - The reference is the PLAN'S OWN targetBoundary — and ONLY that: the
|
|
31
|
+
* plan's slots derive from the same target grid, so a stale plan's
|
|
32
|
+
* placements cross its own boundary while legitimate re-placements never
|
|
33
|
+
* do (the boundary is capped, the fills are not). Fill-based veto lines
|
|
34
|
+
* are deliberately NOT used — after a burst the fills sit beyond the
|
|
35
|
+
* plan's legitimate re-place levels (e.g. SELL fills 5,6,7 with cap=1
|
|
36
|
+
* moves the boundary only to slot 6), so ANY fill comparison can veto
|
|
37
|
+
* valid placements, including the strategy's own rotations (a partial
|
|
38
|
+
* SELL rotated into a slot below the last BUY fill after the boundary
|
|
39
|
+
* crawled left). The guard is therefore "inert" for boundary-consistent
|
|
40
|
+
* engine output by construction.
|
|
41
|
+
* - Slot ids are compared within the plan's own grid generation
|
|
42
|
+
* (targetBoundary and target slots are both from the current plan), so a
|
|
43
|
+
* recenter between the fill capture and the plan cannot skew the
|
|
44
|
+
* comparison. Both CREATE and UPDATE actions are guarded: the
|
|
45
|
+
* cancel/create optimization can convert the same logical placement into
|
|
46
|
+
* an UPDATE op (target slot = newGridId), which the CREATE-only check
|
|
47
|
+
* would have missed.
|
|
48
|
+
* - When no plan boundary is available (hand-built plans), nothing is
|
|
49
|
+
* vetoed — fill evidence is not a reliable veto line. Non-placement
|
|
50
|
+
* actions and non-grid-slot targets are never vetoed.
|
|
51
|
+
* @param {Object} action - COW action
|
|
52
|
+
* @param {number} planBoundary - The plan's target boundary slot index
|
|
53
|
+
* @returns {string|null} Drop reason for the log, or null to keep the action
|
|
54
|
+
*/
|
|
55
|
+
interface COWFillLike extends UnknownRecord {
|
|
56
|
+
id?: string;
|
|
57
|
+
type?: string;
|
|
58
|
+
price?: number;
|
|
59
|
+
size?: number;
|
|
60
|
+
isPartial?: boolean;
|
|
61
|
+
isDelayedRotationTrigger?: boolean;
|
|
62
|
+
order?: {
|
|
63
|
+
price?: number;
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
} | null;
|
|
66
|
+
}
|
|
67
|
+
type WorkingGridResult = RebalanceResult & {
|
|
68
|
+
_workingGridPushed?: boolean;
|
|
69
|
+
};
|
|
70
|
+
interface COWExecuteParams {
|
|
71
|
+
masterGrid: Map<string, ManagedOrder>;
|
|
72
|
+
gridVersion: number;
|
|
73
|
+
boundaryIdx: number | null;
|
|
74
|
+
funds: ProjectedFunds | null;
|
|
75
|
+
manager?: OrderManagerLike | null;
|
|
76
|
+
fills?: COWFillLike[];
|
|
77
|
+
excludeIds?: Set<string>;
|
|
78
|
+
gapSlots?: number | null;
|
|
79
|
+
evacStreaks?: Map<string, number> | null;
|
|
80
|
+
reserveEdgeAnchors?: {
|
|
81
|
+
buy?: number | null;
|
|
82
|
+
sell?: number | null;
|
|
83
|
+
} | null;
|
|
84
|
+
}
|
|
16
85
|
declare class COWRebalanceEngine {
|
|
17
|
-
strategy:
|
|
18
|
-
logger:
|
|
19
|
-
assets:
|
|
20
|
-
config:
|
|
21
|
-
constructor(deps:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
workingBoundary: null;
|
|
29
|
-
planningDuration: number;
|
|
30
|
-
aborted: boolean;
|
|
31
|
-
reason: any;
|
|
32
|
-
} | {
|
|
33
|
-
needsResync?: boolean | undefined;
|
|
34
|
-
resyncReason?: string | undefined;
|
|
35
|
-
evacReady: never[];
|
|
36
|
-
actions: never[];
|
|
37
|
-
stateUpdates: never[];
|
|
38
|
-
hadRotation: boolean;
|
|
39
|
-
workingGrid: null;
|
|
40
|
-
workingIndexes: null;
|
|
41
|
-
workingBoundary: null;
|
|
42
|
-
planningDuration: number;
|
|
43
|
-
aborted: boolean;
|
|
44
|
-
reason: any;
|
|
45
|
-
} | {
|
|
46
|
-
evacReady: any;
|
|
47
|
-
aborted: boolean;
|
|
48
|
-
refillSlotIds?: any;
|
|
49
|
-
actions: any;
|
|
50
|
-
stateUpdates: any;
|
|
51
|
-
hadRotation: any;
|
|
52
|
-
workingGrid: any;
|
|
53
|
-
workingIndexes: any;
|
|
54
|
-
workingBoundary: any;
|
|
55
|
-
planningDuration: any;
|
|
56
|
-
}>;
|
|
86
|
+
strategy: StrategyEngine;
|
|
87
|
+
logger: Logger;
|
|
88
|
+
assets: AssetPair | null;
|
|
89
|
+
config: GridConfig;
|
|
90
|
+
constructor(deps: {
|
|
91
|
+
strategy: StrategyEngine;
|
|
92
|
+
logger: Logger;
|
|
93
|
+
assets: AssetPair | null;
|
|
94
|
+
config: GridConfig;
|
|
95
|
+
});
|
|
96
|
+
execute({ masterGrid, gridVersion, boundaryIdx, funds, manager, fills, excludeIds, gapSlots, evacStreaks, reserveEdgeAnchors }: COWExecuteParams): Promise<RebalanceResult>;
|
|
57
97
|
}
|
|
58
|
-
declare class OrderManager {
|
|
59
|
-
config:
|
|
60
|
-
marketName:
|
|
61
|
-
logger:
|
|
62
|
-
orders:
|
|
63
|
-
boundaryIdx:
|
|
64
|
-
targetGrid:
|
|
65
|
-
accountant:
|
|
66
|
-
strategy:
|
|
67
|
-
sync:
|
|
98
|
+
declare class OrderManager implements OrderManagerLike {
|
|
99
|
+
config: GridConfig;
|
|
100
|
+
marketName: string | null;
|
|
101
|
+
logger: Logger;
|
|
102
|
+
orders: Map<string, ManagedOrder>;
|
|
103
|
+
boundaryIdx: number | null;
|
|
104
|
+
targetGrid: Map<string, ManagedOrder> | null;
|
|
105
|
+
accountant: Accountant;
|
|
106
|
+
strategy: StrategyEngine;
|
|
107
|
+
sync: SyncEngine;
|
|
68
108
|
_rebalanceState: string;
|
|
69
109
|
_bootstrapping: number;
|
|
70
110
|
_endOfBootstrapValidationDone: boolean;
|
|
71
111
|
_broadcastingFlag: number;
|
|
72
112
|
_broadcastingStartedAt: number;
|
|
73
113
|
_shuttingDown: boolean;
|
|
74
|
-
_illegalStateSignal:
|
|
75
|
-
_accountingFailureSignal:
|
|
114
|
+
_illegalStateSignal: IllegalStateSignal | null;
|
|
115
|
+
_accountingFailureSignal: AccountingFailureSignal | null;
|
|
76
116
|
_recoveryStateValue: {
|
|
77
117
|
phase: string;
|
|
78
118
|
attemptCount: number;
|
|
@@ -119,43 +159,43 @@ declare class OrderManager {
|
|
|
119
159
|
initialSpreadCount: number;
|
|
120
160
|
currentSpreadCount: number;
|
|
121
161
|
outOfSpread: number;
|
|
122
|
-
assets:
|
|
123
|
-
accountId:
|
|
124
|
-
accountTotals:
|
|
125
|
-
funds:
|
|
126
|
-
_accountTotalsPromise:
|
|
127
|
-
_accountTotalsResolve:
|
|
162
|
+
assets: AssetPair;
|
|
163
|
+
accountId: string | null;
|
|
164
|
+
accountTotals: AccountTotals;
|
|
165
|
+
funds: ManagerFunds;
|
|
166
|
+
_accountTotalsPromise: Promise<void> | null;
|
|
167
|
+
_accountTotalsResolve: (() => void) | null;
|
|
128
168
|
_isFetchingTotals: boolean;
|
|
129
169
|
accountTotalsStale: boolean;
|
|
130
|
-
ordersNeedingPriceCorrection:
|
|
131
|
-
shadowOrderIds: Map<
|
|
132
|
-
processedFillTracker: Map<
|
|
133
|
-
processedFillStore:
|
|
134
|
-
_syncLock:
|
|
135
|
-
_fillProcessingLock:
|
|
136
|
-
_divergenceLock:
|
|
137
|
-
_gridLock:
|
|
138
|
-
_fundLock:
|
|
139
|
-
_gridSidesUpdated: Set<
|
|
170
|
+
ordersNeedingPriceCorrection: PendingPriceCorrection[];
|
|
171
|
+
shadowOrderIds: Map<string, number>;
|
|
172
|
+
processedFillTracker: Map<string, number>;
|
|
173
|
+
processedFillStore: ProcessedFillStoreLike | null;
|
|
174
|
+
_syncLock: ManagerLock;
|
|
175
|
+
_fillProcessingLock: ManagerLock;
|
|
176
|
+
_divergenceLock: ManagerLock;
|
|
177
|
+
_gridLock: ManagerLock;
|
|
178
|
+
_fundLock: ManagerLock;
|
|
179
|
+
_gridSidesUpdated: Set<string>;
|
|
140
180
|
_pauseFundRecalc: number;
|
|
141
181
|
_pauseFundRecalcWatchdog: ReturnType<typeof setTimeout> | null;
|
|
142
182
|
_fillBatchInFlight: number;
|
|
143
183
|
_pauseRecalcLogging: boolean;
|
|
144
184
|
_pauseRecalcLoggingWatchdog: ReturnType<typeof setTimeout> | null;
|
|
145
185
|
_throwOnIllegalState: boolean;
|
|
146
|
-
_pipelineBlockedSince:
|
|
186
|
+
_pipelineBlockedSince: number | null;
|
|
147
187
|
_recoveryAttempted: boolean;
|
|
148
188
|
_syncGeneration: number;
|
|
149
189
|
_gridVersion: number;
|
|
150
|
-
_gridPersistenceSuspendedReason:
|
|
151
|
-
_pendingBroadcasts: Map<
|
|
190
|
+
_gridPersistenceSuspendedReason: string | null;
|
|
191
|
+
_pendingBroadcasts: Map<string, PendingBroadcast>;
|
|
152
192
|
_committedOrderIds: Set<string>;
|
|
153
193
|
_committedOrderIdsBuiltAt: number;
|
|
154
194
|
_orderIdAssignedAt: Map<string, number>;
|
|
155
195
|
_placedAt: Map<string, number>;
|
|
156
196
|
_gapSlots: number;
|
|
157
|
-
_genesis:
|
|
158
|
-
_missingGenesis:
|
|
197
|
+
_genesis: GridGenesis | null;
|
|
198
|
+
_missingGenesis: unknown;
|
|
159
199
|
_genesisInvariantViolations: number;
|
|
160
200
|
_genesisInvariantLoggedAt: number;
|
|
161
201
|
_gridDirtyAt: number | null;
|
|
@@ -182,16 +222,21 @@ declare class OrderManager {
|
|
|
182
222
|
_lastFilledAt: number;
|
|
183
223
|
lastFillPivotSource: 'fill' | 'book' | null;
|
|
184
224
|
_deferredRebalanceAt: number;
|
|
185
|
-
_lastHeldPlanSignature:
|
|
225
|
+
_lastHeldPlanSignature: {
|
|
226
|
+
boundaryIdx: number | null;
|
|
227
|
+
pivot: number | null;
|
|
228
|
+
fillsAt: number | null;
|
|
229
|
+
} | null;
|
|
186
230
|
_heldPlanSuppressionCount: number;
|
|
231
|
+
_onBroadcastRegionEnd?: () => void;
|
|
187
232
|
_onBroadcastRegionEndListeners: Array<() => void>;
|
|
188
233
|
_lastBoundaryHoldResyncAt: number;
|
|
189
234
|
_gapEvacStreaks: Map<string, number>;
|
|
190
235
|
_gapEvacCancelQueued: Set<string>;
|
|
191
|
-
_metrics:
|
|
236
|
+
_metrics: BotMetrics;
|
|
192
237
|
private _currentWorkingGridStack;
|
|
193
|
-
_cowEngine:
|
|
194
|
-
accountOrders:
|
|
238
|
+
_cowEngine: COWRebalanceEngine | null;
|
|
239
|
+
accountOrders: AccountOrdersLike;
|
|
195
240
|
btsBalance: {
|
|
196
241
|
free: number;
|
|
197
242
|
total: number;
|
|
@@ -200,8 +245,8 @@ declare class OrderManager {
|
|
|
200
245
|
/**
|
|
201
246
|
* @param {Object} [config] - Configuration overrides
|
|
202
247
|
*/
|
|
203
|
-
constructor(config?: Record<string,
|
|
204
|
-
_getCOWEngine():
|
|
248
|
+
constructor(config?: Record<string, unknown>);
|
|
249
|
+
_getCOWEngine(): COWRebalanceEngine | null;
|
|
205
250
|
_clearWorkingGridRef(): void;
|
|
206
251
|
/**
|
|
207
252
|
* Push a working grid onto the rebalance stack (LIFO), set the state to
|
|
@@ -213,7 +258,7 @@ declare class OrderManager {
|
|
|
213
258
|
* @param {Object} workingGrid - The working grid to push
|
|
214
259
|
* @param {Object} [result] - Result object to carry the push marker on
|
|
215
260
|
*/
|
|
216
|
-
_pushWorkingGridRef(workingGrid:
|
|
261
|
+
_pushWorkingGridRef(workingGrid: WorkingGrid, result?: WorkingGridResult | null): WorkingGridResult | null;
|
|
217
262
|
/**
|
|
218
263
|
* Pop the stack entry owned by a result, exactly once (marker-guarded).
|
|
219
264
|
* Results that were never pushed (aborted plans, no-trigger
|
|
@@ -223,7 +268,7 @@ declare class OrderManager {
|
|
|
223
268
|
* a later throw in the same frame cannot pop a second time.
|
|
224
269
|
* @param {Object} [result] - Result object carrying the push marker
|
|
225
270
|
*/
|
|
226
|
-
_popWorkingGridRef(result?:
|
|
271
|
+
_popWorkingGridRef(result?: WorkingGridResult | null): void;
|
|
227
272
|
/**
|
|
228
273
|
* Release the stack entry for a grid after its commit settles, exactly
|
|
229
274
|
* once per commit invocation. Identity-checked: plan-path grids
|
|
@@ -233,8 +278,8 @@ declare class OrderManager {
|
|
|
233
278
|
* the check is a no-op for them.
|
|
234
279
|
* @param {Object} workingGrid - The committed working grid
|
|
235
280
|
*/
|
|
236
|
-
_releaseWorkingGridRef(workingGrid:
|
|
237
|
-
_setRebalanceState(state:
|
|
281
|
+
_releaseWorkingGridRef(workingGrid: WorkingGrid): void;
|
|
282
|
+
_setRebalanceState(state: string): void;
|
|
238
283
|
_resetRebalanceStateToDepth(): void;
|
|
239
284
|
/**
|
|
240
285
|
* @returns {boolean}
|
|
@@ -253,7 +298,7 @@ declare class OrderManager {
|
|
|
253
298
|
* @param {boolean} value
|
|
254
299
|
* @returns {void}
|
|
255
300
|
*/
|
|
256
|
-
setShuttingDown(value:
|
|
301
|
+
setShuttingDown(value: boolean): void;
|
|
257
302
|
/**
|
|
258
303
|
* Auto-clears a stale broadcast flag after 120s so a hung
|
|
259
304
|
* broadcast cannot permanently block rebalancing.
|
|
@@ -273,11 +318,11 @@ declare class OrderManager {
|
|
|
273
318
|
*/
|
|
274
319
|
startBootstrap(): void;
|
|
275
320
|
/**
|
|
276
|
-
* @returns {
|
|
321
|
+
* @returns {unknown}
|
|
277
322
|
*/
|
|
278
323
|
finishBootstrap(): {
|
|
279
324
|
hadDrift: boolean;
|
|
280
|
-
driftInfo: null;
|
|
325
|
+
driftInfo: FundDriftCheck | null;
|
|
281
326
|
};
|
|
282
327
|
/**
|
|
283
328
|
* @returns {void}
|
|
@@ -315,7 +360,7 @@ declare class OrderManager {
|
|
|
315
360
|
* (deductBtsFees, tryDeductFromChainFree, updateOptimisticFreeBalance).
|
|
316
361
|
* @returns {Promise<void>}
|
|
317
362
|
*/
|
|
318
|
-
resetFunds(): Promise<
|
|
363
|
+
resetFunds(): Promise<void>;
|
|
319
364
|
/**
|
|
320
365
|
* Computes committed amounts directly from the orders map to ensure the
|
|
321
366
|
* snapshot is internally consistent even when called inside a
|
|
@@ -324,35 +369,19 @@ declare class OrderManager {
|
|
|
324
369
|
* value can lag behind the actual orders state (virtualized orders
|
|
325
370
|
* release committed capital via updateOptimisticFreeBalance without
|
|
326
371
|
* triggering a recalc). Reading from the orders map avoids that race.
|
|
327
|
-
* @returns {
|
|
372
|
+
* @returns {unknown}
|
|
328
373
|
*/
|
|
329
|
-
getChainFundsSnapshot():
|
|
330
|
-
allocatedBuy: number;
|
|
331
|
-
allocatedSell: number;
|
|
332
|
-
btsBalance: {
|
|
333
|
-
free: number;
|
|
334
|
-
total: number;
|
|
335
|
-
locked: number;
|
|
336
|
-
} | null;
|
|
337
|
-
chainFreeBuy: number;
|
|
338
|
-
chainFreeSell: number;
|
|
339
|
-
committedChainBuy: number;
|
|
340
|
-
committedChainSell: number;
|
|
341
|
-
freePlusLockedBuy: number;
|
|
342
|
-
freePlusLockedSell: number;
|
|
343
|
-
chainTotalBuy: number;
|
|
344
|
-
chainTotalSell: number;
|
|
345
|
-
};
|
|
374
|
+
getChainFundsSnapshot(): ChainFundsSnapshot;
|
|
346
375
|
/**
|
|
347
376
|
* @param {number} [timeoutMs]
|
|
348
377
|
* @returns {Promise<void>}
|
|
349
378
|
*/
|
|
350
|
-
waitForAccountTotals(timeoutMs?:
|
|
379
|
+
waitForAccountTotals(timeoutMs?: number): Promise<void>;
|
|
351
380
|
/**
|
|
352
381
|
* @param {string} [accountId] - Blockchain account ID
|
|
353
382
|
* @returns {Promise<void>}
|
|
354
383
|
*/
|
|
355
|
-
fetchAccountTotals(accountId:
|
|
384
|
+
fetchAccountTotals(accountId: string | null): Promise<void>;
|
|
356
385
|
/**
|
|
357
386
|
* Refresh accountTotals from chain when the cached snapshot is stale.
|
|
358
387
|
*
|
|
@@ -399,13 +428,13 @@ declare class OrderManager {
|
|
|
399
428
|
* @returns {Promise<boolean>} true when the re-anchor refreshed successfully
|
|
400
429
|
*/
|
|
401
430
|
reanchorAccountTotals(label?: string): Promise<boolean>;
|
|
402
|
-
_fetchAccountBalancesAndSetTotals(): Promise<
|
|
431
|
+
_fetchAccountBalancesAndSetTotals(): Promise<void>;
|
|
403
432
|
/**
|
|
404
|
-
* @param {
|
|
433
|
+
* @param {unknown} totals - Account balance totals
|
|
405
434
|
* @returns {Promise<void>}
|
|
406
435
|
*/
|
|
407
|
-
setAccountTotals(totals?:
|
|
408
|
-
_setAccountTotals(totals:
|
|
436
|
+
setAccountTotals(totals?: Partial<AccountTotals>): Promise<void>;
|
|
437
|
+
_setAccountTotals(totals: Partial<AccountTotals>): Promise<void>;
|
|
409
438
|
_triggerAccountTotalsFetchIfNeeded(): void;
|
|
410
439
|
/**
|
|
411
440
|
* @returns {void}
|
|
@@ -414,7 +443,7 @@ declare class OrderManager {
|
|
|
414
443
|
/**
|
|
415
444
|
* @returns {Promise<void>}
|
|
416
445
|
*/
|
|
417
|
-
recalculateFunds(): Promise<
|
|
446
|
+
recalculateFunds(): Promise<void>;
|
|
418
447
|
_recalculateFunds(): Promise<void>;
|
|
419
448
|
/**
|
|
420
449
|
* Suppress fund recalculation during batch mutations.
|
|
@@ -467,42 +496,42 @@ declare class OrderManager {
|
|
|
467
496
|
* @param {Object} info
|
|
468
497
|
* @returns {Promise<any>}
|
|
469
498
|
*/
|
|
470
|
-
syncFromOpenOrders(orders:
|
|
499
|
+
syncFromOpenOrders(orders: unknown[] | null, info?: UnknownRecord): Promise<SyncResult>;
|
|
471
500
|
/**
|
|
472
501
|
* @param {Object} fill - Fill event data
|
|
473
502
|
* @param {Object} [options]
|
|
474
503
|
* @returns {Promise<any>}
|
|
475
504
|
*/
|
|
476
|
-
syncFromFillHistory(fill:
|
|
505
|
+
syncFromFillHistory(fill: unknown, options?: UnknownRecord): Promise<FillHistorySyncResult>;
|
|
477
506
|
/**
|
|
478
507
|
* @param {Array} fills - Array of fill event objects (same block group)
|
|
479
508
|
* @param {Object} [options]
|
|
480
509
|
* @returns {Promise<any>}
|
|
481
510
|
*/
|
|
482
|
-
syncFromFillHistoryBatch(fills:
|
|
511
|
+
syncFromFillHistoryBatch(fills: unknown[], options?: UnknownRecord): Promise<FillHistorySyncResult>;
|
|
483
512
|
/**
|
|
484
513
|
* @param {Object} data - Chain data to synchronize
|
|
485
514
|
* @param {string} src - Source identifier
|
|
486
515
|
* @returns {Promise<any>}
|
|
487
516
|
*/
|
|
488
|
-
synchronizeWithChain(data:
|
|
489
|
-
_applySync(data:
|
|
490
|
-
_initializeAssets(): Promise<
|
|
517
|
+
synchronizeWithChain(data: unknown, src: string): Promise<SyncResult>;
|
|
518
|
+
_applySync(data: unknown, src: string): Promise<SyncResult>;
|
|
519
|
+
_initializeAssets(): Promise<void>;
|
|
491
520
|
/**
|
|
492
521
|
* @param {string[]|Set<string>} orderIds - Order IDs to lock
|
|
493
522
|
* @returns {void}
|
|
494
523
|
*/
|
|
495
|
-
lockOrders(orderIds:
|
|
524
|
+
lockOrders(orderIds: Iterable<string> | null | undefined): void;
|
|
496
525
|
/**
|
|
497
526
|
* @param {string[]|Set<string>} orderIds - Order IDs to unlock
|
|
498
527
|
* @returns {void}
|
|
499
528
|
*/
|
|
500
|
-
unlockOrders(orderIds:
|
|
529
|
+
unlockOrders(orderIds: Iterable<string> | null | undefined): void;
|
|
501
530
|
/**
|
|
502
531
|
* @param {string} id - Order ID
|
|
503
532
|
* @returns {boolean}
|
|
504
533
|
*/
|
|
505
|
-
isOrderLocked(id:
|
|
534
|
+
isOrderLocked(id: string): boolean;
|
|
506
535
|
/**
|
|
507
536
|
* Number of distinct live orders currently shadow-locked.
|
|
508
537
|
*
|
|
@@ -513,31 +542,25 @@ declare class OrderManager {
|
|
|
513
542
|
*/
|
|
514
543
|
getActiveShadowLockCount(): number;
|
|
515
544
|
_cleanExpiredLocks(): void;
|
|
516
|
-
_normalizeOrderUpdateOptions(options?:
|
|
545
|
+
_normalizeOrderUpdateOptions(options?: UnknownRecord): {
|
|
517
546
|
skipAccounting: boolean;
|
|
518
547
|
fee: number;
|
|
519
548
|
};
|
|
520
|
-
_normalizeCommitOptions(options?:
|
|
549
|
+
_normalizeCommitOptions(options?: UnknownRecord): {
|
|
521
550
|
skipRecalc: boolean;
|
|
522
551
|
boundaryHeld: boolean;
|
|
523
552
|
};
|
|
524
|
-
_updateOrder(order:
|
|
525
|
-
_applyOrderUpdate(order:
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
* Returns the top of the working grid stack (null if empty).
|
|
529
|
-
*/
|
|
530
|
-
get _currentWorkingGrid(): any;
|
|
531
|
-
set _currentWorkingGrid(val: any);
|
|
532
|
-
_peekWorkingGrid(): any;
|
|
533
|
-
_syncWorkingGridFromMasterMutation(orderId: any, context: any): void;
|
|
553
|
+
_updateOrder(order: ManagedOrder, context?: string, options?: UnknownRecord): Promise<boolean>;
|
|
554
|
+
_applyOrderUpdate(order: ManagedOrder, context?: string, options?: UnknownRecord): Promise<boolean>;
|
|
555
|
+
_peekWorkingGrid(): WorkingGrid | null;
|
|
556
|
+
_syncWorkingGridFromMasterMutation(orderId: string, context: string): void;
|
|
534
557
|
/**
|
|
535
558
|
* @param {Array<import('./types').Order>} updates - Order updates to apply
|
|
536
559
|
* @param {string} [context] - Update context label
|
|
537
|
-
* @param {
|
|
560
|
+
* @param {unknown} [options]
|
|
538
561
|
* @returns {Promise<boolean>}
|
|
539
562
|
*/
|
|
540
|
-
applyGridUpdateBatch(updates:
|
|
563
|
+
applyGridUpdateBatch(updates: ManagedOrder[], context?: string, options?: UnknownRecord): Promise<boolean>;
|
|
541
564
|
/**
|
|
542
565
|
* Flag the in-memory master grid as dirty so the next flushGridDirty()
|
|
543
566
|
* call persists it. Internal helper — every successful _applyOrderUpdate
|
|
@@ -573,17 +596,12 @@ declare class OrderManager {
|
|
|
573
596
|
* @param {string} [contextLabel='flush-grid-dirty'] - Label for logs
|
|
574
597
|
* @returns {Promise<{skipped?: boolean, suspended?: boolean, isValid?: boolean, reason?: string}>}
|
|
575
598
|
*/
|
|
576
|
-
flushGridDirty(contextLabel?:
|
|
599
|
+
flushGridDirty(contextLabel?: string): Promise<{
|
|
577
600
|
isValid: boolean;
|
|
578
601
|
reason: string;
|
|
579
602
|
} | {
|
|
580
603
|
isValid: boolean;
|
|
581
604
|
reason: null;
|
|
582
|
-
} | {
|
|
583
|
-
isValid: boolean;
|
|
584
|
-
skipped: boolean;
|
|
585
|
-
suspended: boolean;
|
|
586
|
-
reason: any;
|
|
587
605
|
} | {
|
|
588
606
|
skipped: boolean;
|
|
589
607
|
reason: string;
|
|
@@ -591,7 +609,7 @@ declare class OrderManager {
|
|
|
591
609
|
} | {
|
|
592
610
|
skipped: boolean;
|
|
593
611
|
suspended: boolean;
|
|
594
|
-
reason:
|
|
612
|
+
reason: string;
|
|
595
613
|
}>;
|
|
596
614
|
/**
|
|
597
615
|
* @param {Array<import('./types').Order>} orders - Filled orders
|
|
@@ -599,11 +617,11 @@ declare class OrderManager {
|
|
|
599
617
|
* @param {Object} [options]
|
|
600
618
|
* @returns {Promise<any>}
|
|
601
619
|
*/
|
|
602
|
-
processFilledOrders(orders:
|
|
620
|
+
processFilledOrders(orders: COWFillLike[], excl: Set<string>, options?: UnknownRecord): Promise<RebalanceResult>;
|
|
603
621
|
/**
|
|
604
622
|
* @returns {Array<import('./types').Order>}
|
|
605
623
|
*/
|
|
606
|
-
getInitialOrdersToActivate():
|
|
624
|
+
getInitialOrdersToActivate(): ManagedOrder[];
|
|
607
625
|
/**
|
|
608
626
|
* Get orders matching the specified type and state.
|
|
609
627
|
*
|
|
@@ -611,7 +629,7 @@ declare class OrderManager {
|
|
|
611
629
|
* @param {string} state - Order state (ORDER_STATES.ACTIVE/PARTIAL/VIRTUAL)
|
|
612
630
|
* @returns {Array} Array of matching orders
|
|
613
631
|
*/
|
|
614
|
-
getOrdersByTypeAndState(type:
|
|
632
|
+
getOrdersByTypeAndState(type: OrderType | null, state: OrderState): ManagedOrder[];
|
|
615
633
|
/**
|
|
616
634
|
* Write boundaryIdx under COW-commit-only discipline.
|
|
617
635
|
*
|
|
@@ -620,7 +638,7 @@ declare class OrderManager {
|
|
|
620
638
|
* so a misbehaving caller doesn't silently lose the update, but the warning
|
|
621
639
|
* flags a violation of the COW boundary-write invariant.
|
|
622
640
|
*/
|
|
623
|
-
_setBoundary(newIdx: number): void;
|
|
641
|
+
_setBoundary(newIdx: number | null): void;
|
|
624
642
|
/**
|
|
625
643
|
* Restore boundaryIdx outside the COW commit path (startup, recovery,
|
|
626
644
|
* disk-load). This is the same write as _setBoundary but without the
|
|
@@ -651,7 +669,7 @@ declare class OrderManager {
|
|
|
651
669
|
*
|
|
652
670
|
* @param {string} reason - Log/debug label for the drop
|
|
653
671
|
*/
|
|
654
|
-
_clearPendingFillCrawls(reason?:
|
|
672
|
+
_clearPendingFillCrawls(reason?: string): void;
|
|
655
673
|
/**
|
|
656
674
|
* Observability (fix #4, docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md §2): emit the live
|
|
657
675
|
* boundary whenever roles are (re)assigned, so a silent boundary crawl that
|
|
@@ -687,7 +705,7 @@ declare class OrderManager {
|
|
|
687
705
|
* @param {number} [atMs] - Fill timestamp to preserve (defaults to now)
|
|
688
706
|
* @returns {boolean} True when the pivot was written
|
|
689
707
|
*/
|
|
690
|
-
_setLastFillPivot(type:
|
|
708
|
+
_setLastFillPivot(type: OrderType, price: number, provenance: 'fill' | 'book', atMs?: number): boolean;
|
|
691
709
|
/**
|
|
692
710
|
* Reset the LAST-FILL-GUARD pivot to cold state, clearing the whole
|
|
693
711
|
* scalar family (per-side mirrors included): leaves seedLastFilledPricesFromBook's
|
|
@@ -717,7 +735,7 @@ declare class OrderManager {
|
|
|
717
735
|
* cold-check and per-side seeding in seedLastFilledPricesFromBook.
|
|
718
736
|
* @param {Array} fills
|
|
719
737
|
*/
|
|
720
|
-
recordLastFilledPrices(fills:
|
|
738
|
+
recordLastFilledPrices(fills: COWFillLike[]): void;
|
|
721
739
|
/**
|
|
722
740
|
* Seed last-filled guard from the live book at startup. Book-derived
|
|
723
741
|
* (survives restart), analogous to the deleted MarketAnchor book-seed.
|
|
@@ -727,32 +745,45 @@ declare class OrderManager {
|
|
|
727
745
|
* the book alone.
|
|
728
746
|
* @param {Array} chainOpenOrders - raw chain open orders (from readOpenOrdersGuarded)
|
|
729
747
|
*/
|
|
730
|
-
seedLastFilledPricesFromBook(chainOpenOrders:
|
|
748
|
+
seedLastFilledPricesFromBook(chainOpenOrders: unknown[]): void;
|
|
731
749
|
/**
|
|
732
750
|
* @returns {Object|null} The consumed signal or null
|
|
733
751
|
*/
|
|
734
|
-
consumeIllegalStateSignal():
|
|
752
|
+
consumeIllegalStateSignal(): IllegalStateSignal | null;
|
|
735
753
|
/**
|
|
736
754
|
* @returns {Object|null} The consumed signal or null
|
|
737
755
|
*/
|
|
738
|
-
consumeAccountingFailureSignal():
|
|
756
|
+
consumeAccountingFailureSignal(): AccountingFailureSignal | null;
|
|
739
757
|
/**
|
|
740
758
|
* @param {Object} BitShares - BitShares API instance
|
|
741
759
|
* @param {Function} batchCb - Batch callback
|
|
742
760
|
* @returns {Promise<Object>}
|
|
743
761
|
*/
|
|
744
|
-
checkSpreadCondition(BitShares:
|
|
762
|
+
checkSpreadCondition(BitShares: unknown, batchCb?: ((correction: unknown) => Promise<{
|
|
763
|
+
executed?: boolean;
|
|
764
|
+
}>) | null): Promise<{
|
|
765
|
+
ordersPlaced: number;
|
|
766
|
+
partialsMoved: number;
|
|
767
|
+
fundsExhausted?: boolean;
|
|
768
|
+
}>;
|
|
745
769
|
/**
|
|
746
770
|
* @param {Function} batchCb - Batch callback
|
|
747
771
|
* @returns {Promise<Object>}
|
|
748
772
|
*/
|
|
749
|
-
checkGridHealth(batchCb:
|
|
773
|
+
checkGridHealth(batchCb?: ((correction: unknown) => Promise<{
|
|
774
|
+
executed?: boolean;
|
|
775
|
+
}>) | null): Promise<{
|
|
776
|
+
buyDust: boolean;
|
|
777
|
+
sellDust: boolean;
|
|
778
|
+
buyDustOrders: unknown[];
|
|
779
|
+
sellDustOrders: unknown[];
|
|
780
|
+
}>;
|
|
750
781
|
/**
|
|
751
782
|
* @returns {Object} Current spread calculation
|
|
752
783
|
*/
|
|
753
784
|
calculateCurrentSpread(): number;
|
|
754
785
|
/**
|
|
755
|
-
* @returns {
|
|
786
|
+
* @returns {unknown}
|
|
756
787
|
*/
|
|
757
788
|
checkFundDriftAfterFills(): {
|
|
758
789
|
isValid: boolean;
|
|
@@ -774,9 +805,9 @@ declare class OrderManager {
|
|
|
774
805
|
};
|
|
775
806
|
/**
|
|
776
807
|
* @param {Object|number} [pipelineSignals] - Pipeline state signals or queue length
|
|
777
|
-
* @returns {
|
|
808
|
+
* @returns {unknown}
|
|
778
809
|
*/
|
|
779
|
-
isPipelineEmpty(pipelineSignals?: number | Record<string,
|
|
810
|
+
isPipelineEmpty(pipelineSignals?: number | Record<string, unknown>): {
|
|
780
811
|
isEmpty: boolean;
|
|
781
812
|
reasons: string[];
|
|
782
813
|
};
|
|
@@ -789,16 +820,18 @@ declare class OrderManager {
|
|
|
789
820
|
* @param {number} targetBoundary
|
|
790
821
|
* @returns {Object}
|
|
791
822
|
*/
|
|
792
|
-
reconcileGrid(targetGrid:
|
|
793
|
-
actions:
|
|
823
|
+
reconcileGrid(targetGrid: Map<string, ManagedOrder>, targetBoundary: number | null): {
|
|
824
|
+
actions: CowAction[];
|
|
794
825
|
aborted: boolean;
|
|
795
|
-
boundaryIdx:
|
|
796
|
-
evacReady:
|
|
826
|
+
boundaryIdx: number | null;
|
|
827
|
+
evacReady: {
|
|
828
|
+
id: string;
|
|
829
|
+
}[];
|
|
797
830
|
summary: {
|
|
798
|
-
total:
|
|
799
|
-
creates:
|
|
800
|
-
cancels:
|
|
801
|
-
updates:
|
|
831
|
+
total: number;
|
|
832
|
+
creates: number;
|
|
833
|
+
cancels: number;
|
|
834
|
+
updates: number;
|
|
802
835
|
};
|
|
803
836
|
};
|
|
804
837
|
/**
|
|
@@ -826,7 +859,7 @@ declare class OrderManager {
|
|
|
826
859
|
* @param {Array} candidates - evacReady candidates [{id, idx, type, price, size, orderId}]
|
|
827
860
|
* @returns {number} Number of corrections queued
|
|
828
861
|
*/
|
|
829
|
-
_processGapEvacuationTeeth(candidates:
|
|
862
|
+
_processGapEvacuationTeeth(candidates: unknown): number;
|
|
830
863
|
/**
|
|
831
864
|
* Wait (bounded) until any non-COW broadcast/placement activity — the
|
|
832
865
|
* refcounted _broadcastingFlag — has released. Startup/structural
|
|
@@ -857,20 +890,32 @@ declare class OrderManager {
|
|
|
857
890
|
* on the flag it holds itself.
|
|
858
891
|
* @returns {Promise<any>}
|
|
859
892
|
*/
|
|
860
|
-
performSafeRebalance(fills?:
|
|
861
|
-
|
|
893
|
+
performSafeRebalance(fills?: COWFillLike[], excludeIds?: Set<string>, options?: {
|
|
894
|
+
skipBroadcastWait?: boolean;
|
|
895
|
+
deferIfBroadcasting?: boolean;
|
|
896
|
+
[key: string]: unknown;
|
|
897
|
+
}): Promise<RebalanceResult>;
|
|
898
|
+
_applySafeRebalanceCOW(fills?: COWFillLike[], excludeIds?: Set<string>): Promise<RebalanceResult>;
|
|
862
899
|
_getCowComparePrecisions(): {
|
|
863
900
|
buyPrecision: number;
|
|
864
901
|
sellPrecision: number;
|
|
865
902
|
priceRelativeTolerance: number;
|
|
866
903
|
};
|
|
867
|
-
_commitWorkingGrid(workingGrid:
|
|
904
|
+
_commitWorkingGrid(workingGrid: WorkingGrid, _workingIndexes: unknown, workingBoundary: number | null, options?: {
|
|
905
|
+
skipRecalc?: boolean;
|
|
906
|
+
boundaryHeld?: boolean;
|
|
907
|
+
result?: WorkingGridResult;
|
|
908
|
+
[key: string]: unknown;
|
|
909
|
+
}): Promise<boolean>;
|
|
868
910
|
/**
|
|
869
911
|
* @param {Object} [options]
|
|
870
912
|
* @param {boolean} [options.allowBootstrapTransient]
|
|
871
|
-
* @returns {
|
|
913
|
+
* @returns {unknown}
|
|
872
914
|
*/
|
|
873
|
-
validateGridStateForPersistence(options?:
|
|
915
|
+
validateGridStateForPersistence(options?: {
|
|
916
|
+
allowBootstrapTransient?: boolean;
|
|
917
|
+
[key: string]: unknown;
|
|
918
|
+
}): {
|
|
874
919
|
isValid: boolean;
|
|
875
920
|
reason: string;
|
|
876
921
|
} | {
|
|
@@ -881,12 +926,12 @@ declare class OrderManager {
|
|
|
881
926
|
* @param {string} [reason]
|
|
882
927
|
* @returns {void}
|
|
883
928
|
*/
|
|
884
|
-
suspendGridPersistence(reason?:
|
|
929
|
+
suspendGridPersistence(reason?: string): void;
|
|
885
930
|
/**
|
|
886
931
|
* @param {string} [reason]
|
|
887
932
|
* @returns {void}
|
|
888
933
|
*/
|
|
889
|
-
resumeGridPersistence(reason?:
|
|
934
|
+
resumeGridPersistence(reason?: string | null): void;
|
|
890
935
|
/**
|
|
891
936
|
* @param {Array<Object>} [snapshotOrders] - Optional explicit orders to persist.
|
|
892
937
|
* When provided, this list is persisted as-is and the live `manager.orders`
|
|
@@ -895,9 +940,9 @@ declare class OrderManager {
|
|
|
895
940
|
* swapping the live map and exposing it to concurrent readers.
|
|
896
941
|
* @returns {Promise<any>}
|
|
897
942
|
*/
|
|
898
|
-
persistGrid(snapshotOrders
|
|
943
|
+
persistGrid(snapshotOrders?: ManagedOrder[], recentFillKeys?: Record<string, number>, fundSnapshot?: {
|
|
899
944
|
btsFeesOwed: number;
|
|
900
|
-
accountTotals:
|
|
945
|
+
accountTotals: AccountTotals;
|
|
901
946
|
}): Promise<{
|
|
902
947
|
isValid: boolean;
|
|
903
948
|
reason: string;
|
|
@@ -908,12 +953,12 @@ declare class OrderManager {
|
|
|
908
953
|
isValid: boolean;
|
|
909
954
|
skipped: boolean;
|
|
910
955
|
suspended: boolean;
|
|
911
|
-
reason:
|
|
956
|
+
reason: string;
|
|
912
957
|
}>;
|
|
913
|
-
get _lastIllegalState():
|
|
914
|
-
set _lastIllegalState(value:
|
|
915
|
-
get _lastAccountingFailure():
|
|
916
|
-
set _lastAccountingFailure(value:
|
|
958
|
+
get _lastIllegalState(): IllegalStateSignal | null;
|
|
959
|
+
set _lastIllegalState(value: IllegalStateSignal | null);
|
|
960
|
+
get _lastAccountingFailure(): AccountingFailureSignal | null;
|
|
961
|
+
set _lastAccountingFailure(value: AccountingFailureSignal | null);
|
|
917
962
|
get _recoveryState(): {
|
|
918
963
|
phase: string;
|
|
919
964
|
attemptCount: number;
|