dexbot 1.6.7 → 1.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -1
- package/README.md +3 -3
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +22 -6
- package/dist/market_adapter/core/market_adapter_service.js +14 -2
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/market_adapter.d.ts +8 -1
- package/dist/market_adapter/market_adapter.js +22 -4
- package/dist/modules/account_bots.js +10 -0
- package/dist/modules/account_orders.d.ts +24 -2
- package/dist/modules/account_orders.js +41 -4
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.js +1 -0
- package/dist/modules/constants.d.ts +11 -3
- package/dist/modules/constants.js +116 -37
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +4 -87
- package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
- package/dist/modules/dexbot_maintenance_runtime.js +59 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +21 -0
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +76 -134
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +2 -2
- package/dist/modules/order/manager.d.ts +4 -0
- package/dist/modules/order/manager.js +14 -1
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +220 -197
- package/dist/modules/order/utils/system.js +8 -1
- package/dist/modules/paths.d.ts +1 -0
- package/dist/modules/paths.js +1 -0
- package/dist/modules/version_notice.d.ts +165 -0
- package/dist/modules/version_notice.js +364 -0
- package/dist/pm2.js +9 -0
- package/dist/unlock.js +28 -0
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +3 -2
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +20 -19
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +149 -31
- package/docs/GRID_RECALCULATION.md +12 -0
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +1 -1
- package/modules/README.md +18 -1
- package/package.json +13 -5
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/cli_start_onboarding.d.ts.map +0 -1
- package/dist/modules/cli_start_onboarding.js.map +0 -1
- package/dist/modules/cli_start_output.d.ts.map +0 -1
- package/dist/modules/cli_start_output.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/utils/text_width.d.ts.map +0 -1
- package/dist/modules/utils/text_width.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -11,8 +11,16 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Each shard holds `{ meta, candles }` where `meta.queriedRanges` records the
|
|
13
13
|
* spans actually queried to produce the data (monotonically unioned on every
|
|
14
|
-
* write)
|
|
15
|
-
*
|
|
14
|
+
* write) together with `at`, the time each query ran. Missing buckets are
|
|
15
|
+
* pruned only against recorded query coverage — the absence of local buckets
|
|
16
|
+
* alone never certifies history as empty — and only once the span is older
|
|
17
|
+
* than GAP_SETTLE_HORIZON_MS, judged per gap rather than per window. `at` is
|
|
18
|
+
* what makes the newest window's late-indexing refresh incremental: buckets a
|
|
19
|
+
* previous query already saw TAIL_SETTLE_LAG_MS after they closed are settled
|
|
20
|
+
* and never re-queried (see settleCoverage). A run that re-verifies the tail
|
|
21
|
+
* therefore REWRITES that shard even when the candles come back identical —
|
|
22
|
+
* the moved verification time is the only news, and skipping the write would
|
|
23
|
+
* throw it away. Pure-reuse runs (no query at all) still write nothing.
|
|
16
24
|
*
|
|
17
25
|
* Callers supply:
|
|
18
26
|
* - `requestKey` — opaque identity object stored in each shard's meta,
|
|
@@ -31,15 +39,53 @@ import { sleepMs } from '../../modules/utils/errors.js';
|
|
|
31
39
|
import { mergeCandles } from '../candle_utils.js';
|
|
32
40
|
const storage = getStorage();
|
|
33
41
|
const { readJSON } = storage;
|
|
34
|
-
// Trailing overlap
|
|
35
|
-
//
|
|
36
|
-
//
|
|
42
|
+
// Trailing overlap for the newest window. It is the refresh when the cache
|
|
43
|
+
// records no query timestamps (pre-`at` shard files) AND the hard ceiling when
|
|
44
|
+
// it does: Kibana indexing can lag minutes–hours, so buckets cached as
|
|
45
|
+
// zero-volume fills may gain real trades after the fact, and 48h bounds the
|
|
46
|
+
// extra query to a small range. Once coverage carries `at`, the refresh shrinks
|
|
47
|
+
// to the still-unsettled tail instead (see TAIL_SETTLE_LAG_MS /
|
|
48
|
+
// settleCoverage) — but never reaches back past this window. Without the
|
|
49
|
+
// ceiling a single mid-window coverage hole (e.g. an old span dropped by
|
|
50
|
+
// compactCoverage) would drag the boundary back weeks and re-query settled
|
|
51
|
+
// history on every run.
|
|
37
52
|
const TAIL_REFRESH_HOURS = 48;
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
|
|
53
|
+
// How long after a bucket closes its last trade may still be indexed. A
|
|
54
|
+
// bucket is settled once some query covering it ran at least this long after
|
|
55
|
+
// the bucket closed — after that, re-querying it can only confirm what we
|
|
56
|
+
// already have. Sized well above real Kibana indexing lag (minutes–hours)
|
|
57
|
+
// while staying far below the 48h legacy fallback, so a rerun minutes after a
|
|
58
|
+
// previous one costs a few hours of query instead of two days.
|
|
59
|
+
const TAIL_SETTLE_LAG_MS = 6 * 3600 * 1000;
|
|
60
|
+
// A missing bucket range that ended longer ago than this is immutable:
|
|
61
|
+
// blockchain history does not change and Kibana indexing lag is long past.
|
|
62
|
+
// Judged PER GAP, not per window: a month-old gap at the leading edge of the
|
|
63
|
+
// newest window is just as settled as one in last year's window, and the
|
|
64
|
+
// window-level test could never prune it. Inside the horizon nothing is
|
|
65
|
+
// certified — recent buckets may still gain late-indexed trades.
|
|
66
|
+
//
|
|
67
|
+
// 7 days, i.e. the margin the window-level rule used before: the win here
|
|
68
|
+
// comes from judging each gap by its OWN age, not from trusting the cache
|
|
69
|
+
// sooner. Nothing in this repo measures how far behind Kibana indexing can
|
|
70
|
+
// lag, so the horizon stays at the last value that was live-proven rather
|
|
71
|
+
// than being tightened on a guess — the reported incident (a month-old,
|
|
72
|
+
// already-queried gap re-fetched forever) is pruned either way.
|
|
73
|
+
const GAP_SETTLE_HORIZON_MS = 7 * 24 * 3600 * 1000;
|
|
74
|
+
// Sub-range fetch budget. Small gaps are queried individually; gaps closer
|
|
75
|
+
// than this many buckets are merged first (one query instead of two) and the
|
|
76
|
+
// run only takes the sub-range path while the merged spans stay under
|
|
77
|
+
// MAX_SUBFETCH_SPAN_RATIO of the window. The cap is on merged SPAN HOURS, not
|
|
78
|
+
// on the gap count: a count cap made a 4th tiny gap escalate to a full-month
|
|
79
|
+
// fetch (~700x the query for one extra hour of data).
|
|
80
|
+
const GAP_MERGE_TOLERANCE_BUCKETS = 2;
|
|
81
|
+
const MAX_SUBFETCH_RANGES = 8;
|
|
82
|
+
const MAX_SUBFETCH_SPAN_RATIO = 0.5;
|
|
83
|
+
// Upper bound on the spans persisted in one shard. Spans merge only when they
|
|
84
|
+
// agree on `at` (see unionQueriedRanges), so a shard that is re-verified often
|
|
85
|
+
// gains one span per run and would otherwise grow without limit. Normal
|
|
86
|
+
// operation stays far below this: coverage is clipped per shard, so only the
|
|
87
|
+
// current month accumulates.
|
|
88
|
+
const MAX_COVERAGE_SPANS = 64;
|
|
43
89
|
// ─── Month-shard naming ───────────────────────────────────────────────────────
|
|
44
90
|
// Shard key is the UTC calendar month; bounds are half-open [start, end) so
|
|
45
91
|
// every bucket timestamp maps to exactly one shard (a bucket exactly at a
|
|
@@ -107,11 +153,22 @@ function readCacheChunk(chunkFile, requestKey, isMatch) {
|
|
|
107
153
|
// Ranges actually queried to produce these candles. Pre-fix files
|
|
108
154
|
// predate sub-range fetches (full-window only), so their timeRange
|
|
109
155
|
// claim is exact and serves as the fallback.
|
|
156
|
+
// `at` = when the covering query actually ran. Shards written before
|
|
157
|
+
// timestamps were recorded carry none, so the FILE's own write time
|
|
158
|
+
// stands in: `persistCacheChunk` stamps `fetchedAt` at flush time and
|
|
159
|
+
// the data in that file was queried in the same run, so the real query
|
|
160
|
+
// time is at most one run-duration earlier. That optimism is minutes
|
|
161
|
+
// against a 6h settle lag and only touches the run's own tail; the
|
|
162
|
+
// alternative — treating those spans as unverifiable — poisons the
|
|
163
|
+
// whole window (see planWindowReuse) and silently disables the
|
|
164
|
+
// late-indexing refresh on every cache that has one old shard.
|
|
165
|
+
const fileAt = timestampMs(meta?.fetchedAt);
|
|
166
|
+
const spanAt = (q) => verifiedAt(q) ?? fileAt;
|
|
110
167
|
const queried = Array.isArray(meta.queriedRanges)
|
|
111
168
|
? meta.queriedRanges
|
|
112
169
|
.filter((q) => Number.isFinite(Number(q?.gte)) && Number.isFinite(Number(q?.lte)))
|
|
113
|
-
.map((q) => ({ gte: Number(q.gte), lte: Number(q.lte) }))
|
|
114
|
-
: (gte !== null && lte !== null ? [{ gte, lte }] : []);
|
|
170
|
+
.map((q) => ({ gte: Number(q.gte), lte: Number(q.lte), at: spanAt(q) }))
|
|
171
|
+
: (gte !== null && lte !== null ? [{ gte, lte, at: fileAt }] : []);
|
|
115
172
|
return {
|
|
116
173
|
candles: parsed.candles,
|
|
117
174
|
fetchedAt: meta.fetchedAt || null,
|
|
@@ -164,24 +221,51 @@ function cachedCandlesInRange(localCache, gteMs, lteMs) {
|
|
|
164
221
|
out.sort((a, b) => a[0] - b[0]);
|
|
165
222
|
return out;
|
|
166
223
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
//
|
|
224
|
+
/** Parse a verification timestamp: epoch ms or ISO. Anything else is unknown. */
|
|
225
|
+
function timestampMs(raw) {
|
|
226
|
+
// `null`/`undefined`/`''` mean "not recorded". They must NOT fall through
|
|
227
|
+
// to Number(): Number(null) === 0 is finite, which would read an unknown
|
|
228
|
+
// verification time as "verified at the epoch" — i.e. as maximally stale,
|
|
229
|
+
// silently disabling the tail refresh on every pre-`at` shard.
|
|
230
|
+
if (raw == null || raw === '')
|
|
231
|
+
return null;
|
|
232
|
+
if (typeof raw === 'string') {
|
|
233
|
+
const parsed = Date.parse(raw);
|
|
234
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
235
|
+
}
|
|
236
|
+
const at = Number(raw);
|
|
237
|
+
return Number.isFinite(at) ? at : null;
|
|
238
|
+
}
|
|
239
|
+
function verifiedAt(range) {
|
|
240
|
+
return timestampMs(range?.at);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Normalize recorded spans: sort, then merge overlapping / bucket-adjacent
|
|
244
|
+
* ones — but ONLY when they assert the same verification time. Merging spans
|
|
245
|
+
* with different `at` would have to pick one verdict for the whole union, and
|
|
246
|
+
* either pick loses (min → the merged span vouches for buckets the older
|
|
247
|
+
* query never saw; max → buckets verified long ago look freshly verified).
|
|
248
|
+
* Keeping them separate preserves exact per-bucket freshness, which is the
|
|
249
|
+
* whole point of `at`. Spans therefore accumulate ~1 per tail run, each a few
|
|
250
|
+
* dozen bytes — negligible next to the candles in the same file, and the
|
|
251
|
+
* same-`at` case (bulk fetches, and every pre-`at` shard) still collapses to
|
|
252
|
+
* one span as before.
|
|
253
|
+
*/
|
|
170
254
|
function unionQueriedRanges(ranges, bucketMs) {
|
|
171
255
|
const clean = (ranges || [])
|
|
172
256
|
.filter((q) => q && Number.isFinite(Number(q.gte)) && Number.isFinite(Number(q.lte)) && Number(q.lte) >= Number(q.gte))
|
|
173
|
-
.map((q) => ({ gte: Number(q.gte), lte: Number(q.lte) }))
|
|
257
|
+
.map((q) => ({ gte: Number(q.gte), lte: Number(q.lte), at: verifiedAt(q) }))
|
|
174
258
|
.sort((a, b) => a.gte - b.gte || a.lte - b.lte);
|
|
175
259
|
const merged = [];
|
|
176
260
|
const gap = Number.isFinite(Number(bucketMs)) && Number(bucketMs) > 0 ? Number(bucketMs) : 0;
|
|
177
261
|
for (const q of clean) {
|
|
178
262
|
const top = merged[merged.length - 1];
|
|
179
|
-
if (top && q.gte <= top.lte + gap) {
|
|
263
|
+
if (top && q.gte <= top.lte + gap && top.at === q.at) {
|
|
180
264
|
if (q.lte > top.lte)
|
|
181
265
|
top.lte = q.lte;
|
|
182
266
|
}
|
|
183
267
|
else {
|
|
184
|
-
merged.push({ gte: q.gte, lte: q.lte });
|
|
268
|
+
merged.push({ gte: q.gte, lte: q.lte, at: q.at });
|
|
185
269
|
}
|
|
186
270
|
}
|
|
187
271
|
return merged;
|
|
@@ -200,10 +284,103 @@ function rangesCoveredBy(have, want) {
|
|
|
200
284
|
}
|
|
201
285
|
return true;
|
|
202
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Change detection for shard writes: `have` already accounts for every span in
|
|
289
|
+
* `want`, in extent AND in verification time. Without the `at` half, a run
|
|
290
|
+
* whose only news is "these buckets were re-verified 1h later" would skip the
|
|
291
|
+
* write and the next run would fall back to the wide fixed refresh window.
|
|
292
|
+
* An unknown `at` on either side is never treated as fresh.
|
|
293
|
+
*/
|
|
294
|
+
function coverageSatisfied(have, want) {
|
|
295
|
+
if (!rangesCoveredBy(have, want))
|
|
296
|
+
return false;
|
|
297
|
+
for (const w of want || []) {
|
|
298
|
+
const wAt = verifiedAt(w);
|
|
299
|
+
if (wAt == null)
|
|
300
|
+
continue;
|
|
301
|
+
let fresh = false;
|
|
302
|
+
for (const h of have || []) {
|
|
303
|
+
if (h.gte > w.gte || h.lte < w.lte)
|
|
304
|
+
continue;
|
|
305
|
+
const hAt = verifiedAt(h);
|
|
306
|
+
if (hAt != null && hAt >= wAt) {
|
|
307
|
+
fresh = true;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (!fresh)
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
/** Every recorded span across the loaded files, newest verification included. */
|
|
317
|
+
function allQueriedRanges(fileCover) {
|
|
318
|
+
const out = [];
|
|
319
|
+
for (const f of fileCover || []) {
|
|
320
|
+
for (const q of f?.queried || []) {
|
|
321
|
+
if (q && Number.isFinite(Number(q.gte)) && Number.isFinite(Number(q.lte)))
|
|
322
|
+
out.push(q);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* How settled a window is, given the recorded coverage.
|
|
329
|
+
*
|
|
330
|
+
* A bucket is settled when some recorded query covering it ran at least
|
|
331
|
+
* `lagMs` after the bucket closed — late indexing has certainly landed by
|
|
332
|
+
* then, so re-querying it can only re-confirm cached data. Returns
|
|
333
|
+
* `hasTimestamps: false` when no coverage carries a verification time (all
|
|
334
|
+
* pre-`at` shards), which tells the caller to fall back to the fixed window.
|
|
335
|
+
* Otherwise `firstUnsettled` is the earliest bucket that still needs a query
|
|
336
|
+
* (null when the whole window is settled).
|
|
337
|
+
*/
|
|
338
|
+
function settleCoverage(opts) {
|
|
339
|
+
const { gteMs, lteMs, bucketMs, lagMs } = opts;
|
|
340
|
+
const spans = (opts.queried || []).filter((q) => q && Number.isFinite(Number(q.gte)) && Number.isFinite(Number(q.lte)));
|
|
341
|
+
const hasTimestamps = spans.some((q) => verifiedAt(q) != null);
|
|
342
|
+
if (!hasTimestamps)
|
|
343
|
+
return { hasTimestamps: false, firstUnsettled: null };
|
|
344
|
+
const first = Math.floor(gteMs / bucketMs) * bucketMs;
|
|
345
|
+
const last = Math.floor(lteMs / bucketMs) * bucketMs;
|
|
346
|
+
for (let ts = first; ts <= last; ts += bucketMs) {
|
|
347
|
+
let settled = false;
|
|
348
|
+
for (const q of spans) {
|
|
349
|
+
if (q.gte > ts || q.lte < ts)
|
|
350
|
+
continue;
|
|
351
|
+
const at = verifiedAt(q);
|
|
352
|
+
if (at != null && at >= ts + bucketMs + lagMs) {
|
|
353
|
+
settled = true;
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (!settled)
|
|
358
|
+
return { hasTimestamps: true, firstUnsettled: ts };
|
|
359
|
+
}
|
|
360
|
+
return { hasTimestamps: true, firstUnsettled: null };
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Bound the persisted span list. Because spans merge only when they assert
|
|
364
|
+
* the same `at`, a shard that is re-verified on every run gains one span per
|
|
365
|
+
* run and would grow without limit (and `settleCoverage` scans the list once
|
|
366
|
+
* per tail window). Dropping the OLDEST spans never invents emptiness, but it
|
|
367
|
+
* is not free: coverage is consulted by BOTH `pruneImmutableGaps` (to skip a
|
|
368
|
+
* query) and `settleCoverage` (to decide a bucket is fresh). A dropped span
|
|
369
|
+
* makes its buckets look unsettled, and the tail refresh would otherwise start
|
|
370
|
+
* at the earliest of them. That is why the refresh is capped at
|
|
371
|
+
* TAIL_REFRESH_HOURS: the worst a dropped span can cost is the legacy 48h
|
|
372
|
+
* overlap, never weeks. The input is already sorted by extent, so the tail of
|
|
373
|
+
* the list is the newest.
|
|
374
|
+
*/
|
|
375
|
+
function compactCoverage(spans, maxSpans) {
|
|
376
|
+
const list = spans || [];
|
|
377
|
+
const max = Number.isFinite(Number(maxSpans)) && Number(maxSpans) >= 1 ? Math.floor(Number(maxSpans)) : list.length;
|
|
378
|
+
return list.length <= max ? list : list.slice(list.length - max);
|
|
379
|
+
}
|
|
203
380
|
function clipRangeTo(q, gteMs, lteMs) {
|
|
204
381
|
const gte = Math.max(q.gte, gteMs);
|
|
205
382
|
const lte = Math.min(q.lte, lteMs);
|
|
206
|
-
return lte >= gte ? { gte, lte } : null;
|
|
383
|
+
return lte >= gte ? { gte, lte, at: verifiedAt(q) } : null;
|
|
207
384
|
}
|
|
208
385
|
function addUtcMonths(date, months) {
|
|
209
386
|
const result = new Date(date.getTime());
|
|
@@ -261,28 +438,56 @@ function findMissingBucketRanges(gteMs, lteMs, bucketMs, haveTs) {
|
|
|
261
438
|
}
|
|
262
439
|
return missing;
|
|
263
440
|
}
|
|
264
|
-
|
|
265
|
-
|
|
441
|
+
/**
|
|
442
|
+
* Merge gap ranges that sit closer together than `toleranceBuckets`, so a
|
|
443
|
+
* cluster of one-bucket holes costs one query instead of one per hole. Only
|
|
444
|
+
* the bounding span widens (the buckets in between get queried too — they are
|
|
445
|
+
* local anyway, so the over-claim is harmless), and input order is preserved.
|
|
446
|
+
*/
|
|
447
|
+
function mergeGapRanges(missing, bucketMs, toleranceBuckets) {
|
|
448
|
+
const tolMs = Number.isFinite(bucketMs) && bucketMs > 0 ? bucketMs * Math.max(0, toleranceBuckets || 0) : 0;
|
|
449
|
+
const out = [];
|
|
450
|
+
for (const m of missing || []) {
|
|
451
|
+
if (!m)
|
|
452
|
+
continue;
|
|
453
|
+
const prev = out[out.length - 1];
|
|
454
|
+
if (prev && m.gte <= prev.lte + tolMs) {
|
|
455
|
+
if (m.lte > prev.lte) {
|
|
456
|
+
prev.lte = m.lte;
|
|
457
|
+
prev.hours = Math.round((m.lte - prev.gte) / bucketMs) + 1;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
out.push({ gte: m.gte, lte: m.lte, hours: m.hours });
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return out;
|
|
465
|
+
}
|
|
466
|
+
function pruneImmutableGaps(missing, fileCover, nowMs = Date.now()) {
|
|
467
|
+
const settleBeforeMs = nowMs - GAP_SETTLE_HORIZON_MS;
|
|
266
468
|
return missing.filter((m) => {
|
|
267
469
|
// Absence of local buckets is NEVER proof of emptiness: stray
|
|
268
470
|
// buckets from a sibling window's file (e.g. boundary over-fetch)
|
|
269
|
-
// must not vouch for anything. Only queriedRanges count
|
|
270
|
-
// for old windows — recent files may predate late-indexed trades.
|
|
471
|
+
// must not vouch for anything. Only queriedRanges count.
|
|
271
472
|
// (A former "leading no-trade gap" heuristic pruned everything
|
|
272
473
|
// before the first local bucket; it once certified a whole month
|
|
273
474
|
// as empty from 5 stray boundary buckets of the next window.)
|
|
274
|
-
// Ranges an existing chunk file actually queried (only trusted for
|
|
275
|
-
// old windows — recent files may predate late-indexed trades).
|
|
276
475
|
// Coverage comes from meta.queriedRanges, not the file's overall
|
|
277
476
|
// timeRange: a chunk rewritten from reused buckets plus sub-range
|
|
278
477
|
// fetches only proves its fetched sub-ranges empty, never the
|
|
279
478
|
// ranges it merely copied forward.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
479
|
+
// Immutability is judged per GAP, not per window: a month-old gap at
|
|
480
|
+
// the leading edge of the newest window is exactly as settled as one
|
|
481
|
+
// in a fully past window, and a window-level test could never prune it
|
|
482
|
+
// (that gap was re-queried on every single run). Gaps ending inside
|
|
483
|
+
// the horizon are always kept — recent buckets may still gain
|
|
484
|
+
// late-indexed trades.
|
|
485
|
+
if (m.lte >= settleBeforeMs)
|
|
486
|
+
return true;
|
|
487
|
+
for (const f of fileCover) {
|
|
488
|
+
for (const q of f.queried || []) {
|
|
489
|
+
if (q.gte <= m.gte && q.lte >= m.lte)
|
|
490
|
+
return false;
|
|
286
491
|
}
|
|
287
492
|
}
|
|
288
493
|
return true;
|
|
@@ -335,14 +540,42 @@ function planWindowReuse(localCache, opts) {
|
|
|
335
540
|
// Immutable history (pruned again after the tail widening below, which
|
|
336
541
|
// reintroduces the leading gap via its refresh set).
|
|
337
542
|
const prune = () => {
|
|
338
|
-
missing = pruneImmutableGaps(missing,
|
|
543
|
+
missing = pruneImmutableGaps(missing, localCache.fileCover, nowMs);
|
|
339
544
|
};
|
|
340
545
|
prune();
|
|
341
|
-
// Late-indexing guard: the newest window
|
|
342
|
-
//
|
|
546
|
+
// Late-indexing guard: the newest window re-fetches everything that is
|
|
547
|
+
// not yet SETTLED — a bucket closes at ts+bucket and may still gain
|
|
548
|
+
// late-indexed trades until a query has run TAIL_SETTLE_LAG_MS later.
|
|
549
|
+
// With verification times on record the refresh shrinks to exactly that
|
|
550
|
+
// unsettled tail, so a rerun an hour later queries ~lag+1h instead of a
|
|
551
|
+
// fixed 48h, and repeated reruns converge instead of repeating the same
|
|
552
|
+
// 48h query forever. Coverage without timestamps (pre-`at` shards) falls
|
|
553
|
+
// back to the fixed trailing window.
|
|
343
554
|
if (allowSubFetch && isTail && reusable.length > 0) {
|
|
344
|
-
const
|
|
345
|
-
|
|
555
|
+
const settle = settleCoverage({
|
|
556
|
+
gteMs, lteMs, bucketMs,
|
|
557
|
+
queried: allQueriedRanges(localCache.fileCover),
|
|
558
|
+
lagMs: TAIL_SETTLE_LAG_MS,
|
|
559
|
+
});
|
|
560
|
+
// Refresh start, widest case last:
|
|
561
|
+
// no timestamps -> the bounded 48h fallback,
|
|
562
|
+
// everything settled -> no refresh at all,
|
|
563
|
+
// unsettled tail -> the earliest unsettled bucket, but never
|
|
564
|
+
// earlier than 48h. An unsettled bucket older than the legacy
|
|
565
|
+
// window is past any plausible indexing lag, and letting it pull
|
|
566
|
+
// the boundary back (a coverage hole after span compaction, an
|
|
567
|
+
// undatable span, a hand-written file) would re-query weeks of
|
|
568
|
+
// settled history on every run. The clamp also covers the old
|
|
569
|
+
// `firstUnsettled <= gte` fallback: when the window begins
|
|
570
|
+
// unsettled, `max` lands on the 48h floor rather than switching
|
|
571
|
+
// the late-indexing refresh off.
|
|
572
|
+
const fallbackFromMs = lteMs - TAIL_REFRESH_HOURS * 3600 * 1000;
|
|
573
|
+
const refreshFromMs = settle.hasTimestamps
|
|
574
|
+
? (settle.firstUnsettled == null
|
|
575
|
+
? lteMs + bucketMs
|
|
576
|
+
: Math.max(settle.firstUnsettled, fallbackFromMs))
|
|
577
|
+
: fallbackFromMs;
|
|
578
|
+
if (refreshFromMs > gteMs && refreshFromMs <= lteMs) {
|
|
346
579
|
const refreshSet = new Set(reusable.filter((c) => Number(c[0]) < refreshFromMs).map((c) => Number(c[0])));
|
|
347
580
|
const refreshed = findMissingBucketRanges(gteMs, lteMs, bucketMs, refreshSet);
|
|
348
581
|
// Only widen, never narrow: keep previously-missing buckets.
|
|
@@ -558,7 +791,14 @@ async function runCachedWindows(opts) {
|
|
|
558
791
|
isTail: windowEntry.index === total,
|
|
559
792
|
allowSubFetch, nowMs,
|
|
560
793
|
});
|
|
561
|
-
const { reusable, missing,
|
|
794
|
+
const { reusable, missing, windowHours, inputsValid } = plan;
|
|
795
|
+
// Gap clusters closer than GAP_MERGE_TOLERANCE_BUCKETS collapse into
|
|
796
|
+
// one query, and the sub-range budget is spent on merged SPAN HOURS
|
|
797
|
+
// rather than on the gap count: the old `missing.length <= 3` made one
|
|
798
|
+
// extra 1-hour hole escalate an otherwise 2-hour refresh into a full
|
|
799
|
+
// ~700-bucket window fetch.
|
|
800
|
+
const subRanges = mergeGapRanges(missing, bucketMs, GAP_MERGE_TOLERANCE_BUCKETS);
|
|
801
|
+
const subRangeHours = subRanges.reduce((sum, m) => sum + m.hours, 0);
|
|
562
802
|
const reusableNote = reusable.length > 0 ? `, ${reusable.length} buckets local` : '';
|
|
563
803
|
if (inputsValid && missing.length === 0 && (reusable.length > 0 || localCache.files > 0)) {
|
|
564
804
|
console.log(`${tag} (reused ${reusable.length} local buckets, nothing missing)`);
|
|
@@ -570,16 +810,18 @@ async function runCachedWindows(opts) {
|
|
|
570
810
|
continue;
|
|
571
811
|
}
|
|
572
812
|
let candles;
|
|
573
|
-
let queriedRanges;
|
|
813
|
+
let queriedRanges = [];
|
|
574
814
|
// A partial sub-range makes the whole window partial: gap-filled
|
|
575
815
|
// buckets from the surviving side would otherwise claim coverage
|
|
576
816
|
// the failed side never earned, baking the skew into the cache.
|
|
577
817
|
let windowComplete = true;
|
|
578
|
-
if (allowSubFetch && reusable.length > 0 &&
|
|
818
|
+
if (allowSubFetch && reusable.length > 0 && subRanges.length > 0
|
|
819
|
+
&& subRangeHours <= windowHours * MAX_SUBFETCH_SPAN_RATIO
|
|
820
|
+
&& subRanges.length <= MAX_SUBFETCH_RANGES) {
|
|
579
821
|
// Small gaps: query only the missing sub-ranges, merge over local.
|
|
580
|
-
console.log(`${tag} (local cover${reusableNote}; fetching ${
|
|
822
|
+
console.log(`${tag} (local cover${reusableNote}; fetching ${subRangeHours}h in ${subRanges.length} sub-range(s))`);
|
|
581
823
|
let mergedLocal = reusable.slice();
|
|
582
|
-
for (const m of
|
|
824
|
+
for (const m of subRanges) {
|
|
583
825
|
// Extend lte past the final bucket start: the ES range is
|
|
584
826
|
// inclusive and m.lte is a bucket *start*, so without this
|
|
585
827
|
// the bucket's real trades are cut off and the gap-filler
|
|
@@ -589,12 +831,15 @@ async function runCachedWindows(opts) {
|
|
|
589
831
|
if (!part.complete)
|
|
590
832
|
windowComplete = false;
|
|
591
833
|
mergedLocal = mergeCandles(mergedLocal, part.candles, { onCollision: higherVolumeWins });
|
|
834
|
+
// Claimed coverage is the canonical missing range (a
|
|
835
|
+
// conservative subset of what was actually queried with the
|
|
836
|
+
// +1-bucket overlap), stamped per sub-range with the moment
|
|
837
|
+
// THAT query returned — one shared stamp would date the first
|
|
838
|
+
// sub-range to the end of the whole loop.
|
|
839
|
+
queriedRanges.push({ gte: m.gte, lte: m.lte, at: Date.now() });
|
|
592
840
|
}
|
|
593
841
|
// Clamp to the window (drops the one-bucket over-fetch above).
|
|
594
842
|
candles = mergedLocal.filter((c) => Number(c[0]) >= gteMs && Number(c[0]) <= lteMs);
|
|
595
|
-
// Claimed coverage is the canonical missing ranges (a conservative
|
|
596
|
-
// subset of what was actually queried with the +1-bucket overlap).
|
|
597
|
-
queriedRanges = missing.map((m) => ({ gte: m.gte, lte: m.lte }));
|
|
598
843
|
}
|
|
599
844
|
else {
|
|
600
845
|
if (reusable.length > 0) {
|
|
@@ -606,7 +851,12 @@ async function runCachedWindows(opts) {
|
|
|
606
851
|
candles = reusable.length > 0
|
|
607
852
|
? mergeCandles(reusable, fresh.candles, { onCollision: higherVolumeWins }).filter((c) => Number(c[0]) >= gteMs && Number(c[0]) <= lteMs).sort((a, b) => a[0] - b[0])
|
|
608
853
|
: fresh.candles;
|
|
609
|
-
|
|
854
|
+
// Full-window fetch. `at` is deliberately the WALL clock, never
|
|
855
|
+
// `nowMs`: `at` answers "when did this query run", so stamping a
|
|
856
|
+
// backdated test clock would certify old buckets as freshly
|
|
857
|
+
// verified. That also means a backdated-window test sees those
|
|
858
|
+
// buckets as already settled — a property tests must account for.
|
|
859
|
+
queriedRanges = [{ gte: gteMs, lte: lteMs, at: Date.now() }];
|
|
610
860
|
}
|
|
611
861
|
if (windowComplete) {
|
|
612
862
|
noteCompletedWindow(gteMs, lteMs, candles, queriedRanges);
|
|
@@ -638,8 +888,12 @@ async function runCachedWindows(opts) {
|
|
|
638
888
|
.filter((c) => Array.isArray(c) && Number.isFinite(Number(c[0])))
|
|
639
889
|
.map((c) => [Number(c[0]), c])));
|
|
640
890
|
const after = sortedCandles(state.candles);
|
|
641
|
-
const union = unionQueriedRanges(state.queried.concat(state.pendingQueried), bucketMs);
|
|
642
|
-
|
|
891
|
+
const union = compactCoverage(unionQueriedRanges(state.queried.concat(state.pendingQueried), bucketMs), MAX_COVERAGE_SPANS);
|
|
892
|
+
// Coverage counts as unchanged only when the recorded verification
|
|
893
|
+
// times are current too: a re-query that returned identical candles
|
|
894
|
+
// still moved the "verified as of" mark forward, and persisting
|
|
895
|
+
// that is what lets the next run shrink its tail refresh.
|
|
896
|
+
if (candlesEqual(before, after) && coverageSatisfied(state.queried, union))
|
|
643
897
|
continue;
|
|
644
898
|
const synthWindow = {
|
|
645
899
|
index: 0,
|
|
@@ -657,5 +911,5 @@ async function runCachedWindows(opts) {
|
|
|
657
911
|
}
|
|
658
912
|
return merged;
|
|
659
913
|
}
|
|
660
|
-
export { TAIL_REFRESH_HOURS,
|
|
914
|
+
export { TAIL_REFRESH_HOURS, TAIL_SETTLE_LAG_MS, GAP_SETTLE_HORIZON_MS, GAP_MERGE_TOLERANCE_BUCKETS, MAX_SUBFETCH_RANGES, MAX_SUBFETCH_SPAN_RATIO, MAX_COVERAGE_SPANS, shardKeyForTimestamp, shardBoundsForKey, shardKeysForRange, shardPathFor, readCacheChunk, loadBucketCache, cachedCandlesInRange, unionQueriedRanges, compactCoverage, rangesCoveredBy, coverageSatisfied, verifiedAt, timestampMs, allQueriedRanges, settleCoverage, buildFetchWindowsFromRange, findMissingBucketRanges, mergeGapRanges, pruneImmutableGaps, persistCacheChunk, planWindowReuse, formatWindowLine, runCachedWindows, };
|
|
661
915
|
//# sourceMappingURL=window_cache.js.map
|
|
@@ -47,6 +47,13 @@ declare const DEFAULT_AMA: {
|
|
|
47
47
|
};
|
|
48
48
|
declare function sleepUntilAlignedBoundary(pollSeconds: number, referenceNowMs?: any, nowMs?: any): number;
|
|
49
49
|
declare function resolveDeltaThresholdPercentFromGeneralSettings(settings: any): number | null;
|
|
50
|
+
/**
|
|
51
|
+
* Slope-trigger factor from general settings (`(value/100) × maxSlopePct`).
|
|
52
|
+
* Mirrors the price resolver above; the bot editor writes this knob under
|
|
53
|
+
* `MARKET_ADAPTER.AMA_SLOPE_DELTA_THRESHOLD_PERCENT`, so the runtime must read
|
|
54
|
+
* it back or the user-facing `AMA-Slope Δ` setting would be inert.
|
|
55
|
+
*/
|
|
56
|
+
declare function resolveAmaSlopeDeltaThresholdPercentFromGeneralSettings(settings: any): number | null;
|
|
50
57
|
declare function applyRuntimeDefaultsFromGeneralSettings(cfg: any, provided?: {
|
|
51
58
|
deltaThresholdPercent?: boolean;
|
|
52
59
|
}, settingsOverride?: any): any;
|
|
@@ -107,5 +114,5 @@ declare function runOnceForAma(overrides?: any): Promise<{
|
|
|
107
114
|
updatedAt: any;
|
|
108
115
|
}>;
|
|
109
116
|
declare function main(): Promise<0 | 1>;
|
|
110
|
-
export { main, runOnceForAma, DEFAULT_AMA, DEFAULTS, calculateBotThreshold, calcAmaComparison, computeCandleStaleness, normalizeMarketSource, sleepUntilAlignedBoundary, resolveAmaForBot, resolveDeltaThresholdPercentFromGeneralSettings, applyRuntimeDefaultsFromGeneralSettings, resolveBotCfg, usesAmaGridPrice, isBotWhitelisted, isBotDynamicWeightWhitelisted, isBotAsymmetricBoundsWhitelisted, _resetCycleCache, writeCenterSnapshot, writeBotDynamicGrid, writeGridResetTrigger, mergeGridResetMetadataFromDynamicGrid, normalizeNativeMarketHistoryCandles, fetchNativeMarketHistorySince, setBitsharesClientForTests as _setBitsharesClientForTests, loadMarketAdapterSettings, findPairForBot };
|
|
117
|
+
export { main, runOnceForAma, DEFAULT_AMA, DEFAULTS, calculateBotThreshold, calcAmaComparison, computeCandleStaleness, normalizeMarketSource, sleepUntilAlignedBoundary, resolveAmaForBot, resolveDeltaThresholdPercentFromGeneralSettings, resolveAmaSlopeDeltaThresholdPercentFromGeneralSettings, applyRuntimeDefaultsFromGeneralSettings, resolveBotCfg, usesAmaGridPrice, isBotWhitelisted, isBotDynamicWeightWhitelisted, isBotAsymmetricBoundsWhitelisted, _resetCycleCache, writeCenterSnapshot, writeBotDynamicGrid, writeGridResetTrigger, mergeGridResetMetadataFromDynamicGrid, normalizeNativeMarketHistoryCandles, fetchNativeMarketHistorySince, setBitsharesClientForTests as _setBitsharesClientForTests, loadMarketAdapterSettings, findPairForBot };
|
|
111
118
|
//# sourceMappingURL=market_adapter.d.ts.map
|
|
@@ -536,17 +536,35 @@ function resolveDeltaThresholdPercentFromGeneralSettings(settings) {
|
|
|
536
536
|
return explicit;
|
|
537
537
|
return null;
|
|
538
538
|
}
|
|
539
|
+
/**
|
|
540
|
+
* Slope-trigger factor from general settings (`(value/100) × maxSlopePct`).
|
|
541
|
+
* Mirrors the price resolver above; the bot editor writes this knob under
|
|
542
|
+
* `MARKET_ADAPTER.AMA_SLOPE_DELTA_THRESHOLD_PERCENT`, so the runtime must read
|
|
543
|
+
* it back or the user-facing `AMA-Slope Δ` setting would be inert.
|
|
544
|
+
*/
|
|
545
|
+
function resolveAmaSlopeDeltaThresholdPercentFromGeneralSettings(settings) {
|
|
546
|
+
const explicit = Number(settings?.MARKET_ADAPTER?.AMA_SLOPE_DELTA_THRESHOLD_PERCENT);
|
|
547
|
+
if (Number.isFinite(explicit) && explicit > 0)
|
|
548
|
+
return explicit;
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
539
551
|
function applyRuntimeDefaultsFromGeneralSettings(cfg, provided = {}, settingsOverride) {
|
|
540
552
|
const out = { ...cfg };
|
|
553
|
+
const settings = settingsOverride === undefined
|
|
554
|
+
? readGeneralSettings({ fallback: null })
|
|
555
|
+
: settingsOverride;
|
|
541
556
|
if (!provided?.deltaThresholdPercent) {
|
|
542
|
-
const settings = settingsOverride === undefined
|
|
543
|
-
? readGeneralSettings({ fallback: null })
|
|
544
|
-
: settingsOverride;
|
|
545
557
|
const fromSettings = resolveDeltaThresholdPercentFromGeneralSettings(settings);
|
|
546
558
|
if (fromSettings != null) {
|
|
547
559
|
out.deltaThresholdPercent = fromSettings;
|
|
548
560
|
}
|
|
549
561
|
}
|
|
562
|
+
const slopeFromSettings = resolveAmaSlopeDeltaThresholdPercentFromGeneralSettings(settings);
|
|
563
|
+
if (slopeFromSettings != null) {
|
|
564
|
+
// Rebuild amaSlope instead of mutating it: `cfg` may be the shared
|
|
565
|
+
// DEFAULTS object and must not be poisoned for later calls.
|
|
566
|
+
out.amaSlope = { ...(out.amaSlope || {}), deltaThresholdPct: slopeFromSettings };
|
|
567
|
+
}
|
|
550
568
|
return out;
|
|
551
569
|
}
|
|
552
570
|
const marketAdapterLogFile = path.join(PATHS.LOGS_DIR, 'market_adapter.log');
|
|
@@ -1305,5 +1323,5 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
|
1305
1323
|
process.exit(1);
|
|
1306
1324
|
});
|
|
1307
1325
|
}
|
|
1308
|
-
export { main, runOnceForAma, DEFAULT_AMA, DEFAULTS, calculateBotThreshold, calcAmaComparison, computeCandleStaleness, normalizeMarketSource, sleepUntilAlignedBoundary, resolveAmaForBot, resolveDeltaThresholdPercentFromGeneralSettings, applyRuntimeDefaultsFromGeneralSettings, resolveBotCfg, usesAmaGridPrice, isBotWhitelisted, isBotDynamicWeightWhitelisted, isBotAsymmetricBoundsWhitelisted, _resetCycleCache, writeCenterSnapshot, writeBotDynamicGrid, writeGridResetTrigger, mergeGridResetMetadataFromDynamicGrid, normalizeNativeMarketHistoryCandles, fetchNativeMarketHistorySince, setBitsharesClientForTests as _setBitsharesClientForTests, loadMarketAdapterSettings, findPairForBot };
|
|
1326
|
+
export { main, runOnceForAma, DEFAULT_AMA, DEFAULTS, calculateBotThreshold, calcAmaComparison, computeCandleStaleness, normalizeMarketSource, sleepUntilAlignedBoundary, resolveAmaForBot, resolveDeltaThresholdPercentFromGeneralSettings, resolveAmaSlopeDeltaThresholdPercentFromGeneralSettings, applyRuntimeDefaultsFromGeneralSettings, resolveBotCfg, usesAmaGridPrice, isBotWhitelisted, isBotDynamicWeightWhitelisted, isBotAsymmetricBoundsWhitelisted, _resetCycleCache, writeCenterSnapshot, writeBotDynamicGrid, writeGridResetTrigger, mergeGridResetMetadataFromDynamicGrid, normalizeNativeMarketHistoryCandles, fetchNativeMarketHistorySince, setBitsharesClientForTests as _setBitsharesClientForTests, loadMarketAdapterSettings, findPairForBot };
|
|
1309
1327
|
//# sourceMappingURL=market_adapter.js.map
|
|
@@ -1563,6 +1563,8 @@ async function promptGeneralSettings() {
|
|
|
1563
1563
|
const updaterStatus = settings.UPDATER.ACTIVE ? `${COLORS.green}ON${COLORS.reset}` : `${COLORS.red}OFF${COLORS.reset}`;
|
|
1564
1564
|
const currentSched = parseCronToDelta(settings.UPDATER.SCHEDULE || "0 0 * * *");
|
|
1565
1565
|
console.log(`${COLORS.yellowBold}5) Updater:${COLORS.reset} [${updaterStatus}] ${COLORS.orange}Branch:${COLORS.reset} ${settings.UPDATER.BRANCH}, ${COLORS.orange}Interval:${COLORS.reset} ${currentSched.days}d, ${COLORS.orange}Time:${COLORS.reset} ${currentSched.time}`);
|
|
1566
|
+
const noticeStatus = settings.UPDATER.NOTICE_ENABLED !== false ? `${COLORS.green}ON${COLORS.reset}` : `${COLORS.red}OFF${COLORS.reset}`;
|
|
1567
|
+
console.log(` ${COLORS.orange}New-version notice:${COLORS.reset} [${noticeStatus}] ${COLORS.gray}(startup hint only, never auto-updates)${COLORS.reset}`);
|
|
1566
1568
|
console.log('--------------------------------------------------');
|
|
1567
1569
|
console.log(`${COLORS.greenBold}S) Save & Exit${COLORS.reset}`);
|
|
1568
1570
|
console.log(`${COLORS.white}C) Cancel (Discard changes)${COLORS.reset}`);
|
|
@@ -1680,6 +1682,14 @@ async function promptGeneralSettings() {
|
|
|
1680
1682
|
break;
|
|
1681
1683
|
settings.UPDATER.BRANCH = branch;
|
|
1682
1684
|
settings.UPDATER.SCHEDULE = schedule;
|
|
1685
|
+
// Offered right after the updater switch: the notice is
|
|
1686
|
+
// independent of it (it never changes code), but operators
|
|
1687
|
+
// reach for this screen when they want the "new version out"
|
|
1688
|
+
// hint silenced or restored.
|
|
1689
|
+
const noticeOn = await askBoolean('Show "new version available" notice on startup', settings.UPDATER.NOTICE_ENABLED !== false);
|
|
1690
|
+
if (noticeOn === '\x1b')
|
|
1691
|
+
break;
|
|
1692
|
+
settings.UPDATER.NOTICE_ENABLED = noticeOn;
|
|
1683
1693
|
break;
|
|
1684
1694
|
case 's':
|
|
1685
1695
|
saveGeneralSettings(settings);
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
* Methods:
|
|
19
19
|
* syncMeta(botConfig), storeMasterGrid(orders, btsFeesOwed, boundaryIdx, assets, debugInputs, recentFillKeys, genesis, gapEvacStreaks, pendingFillCrawls, lastFillPivot)
|
|
20
20
|
* loadGrid(forceReload), loadRecentFillKeys(forceReload), loadPersistedAssets(forceReload), loadPendingFillCrawls(forceReload)
|
|
21
|
-
* loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload)
|
|
22
|
-
* clearGrid()
|
|
21
|
+
* loadBoundaryIdx(forceReload), loadBtsBalance(forceReload), loadBtsFeesOwed(forceReload), loadGapEvacStreaks(forceReload), loadGenesis(forceReload), loadLastFillPivot(forceReload)
|
|
22
|
+
* clearGrid(), clearPersistedBoundary(), clearPersistedLastFillPivot()
|
|
23
23
|
* loadProcessedFills(options), updateProcessedFillsBatch(fills), cleanOldProcessedFills(olderThanMs)
|
|
24
24
|
* getAssetBalances(forceReload)
|
|
25
25
|
*
|
|
@@ -195,7 +195,29 @@ declare class AccountOrders {
|
|
|
195
195
|
* @returns {Array|null} Order grid array or null if not found
|
|
196
196
|
*/
|
|
197
197
|
loadGrid(forceReload?: boolean): any;
|
|
198
|
+
/**
|
|
199
|
+
* Load the persisted price-ladder (genesis) for this bot.
|
|
200
|
+
*
|
|
201
|
+
* SCHEMA GATE (docs/GRID_PRICE_INVARIANT.md, "Schema"): a usable ladder needs a
|
|
202
|
+
* NON-EMPTY `priceLevels` array. A row without one is not a ladder --
|
|
203
|
+
* accepting it would hand `loadGrid` a genesis it cannot validate against
|
|
204
|
+
* (and, for an empty array, silently disable every genesis-derived consumer).
|
|
205
|
+
* Refusing it here means the caller takes the missing-genesis path once, at
|
|
206
|
+
* the source, instead of at every consumer.
|
|
207
|
+
*
|
|
208
|
+
* The hash is deliberately NOT required here: a present-but-tampered hash is
|
|
209
|
+
* still returned, because the hash-mismatch warning belongs to `loadGrid`,
|
|
210
|
+
* which can say what it compared against (`hasGenesisLadder` in
|
|
211
|
+
* modules/order/genesis_policy.ts draws the same distinction).
|
|
212
|
+
* @param {boolean} forceReload - If true, reload from disk
|
|
213
|
+
* @returns {Object|null} The genesis object, or null when absent/invalid
|
|
214
|
+
*/
|
|
198
215
|
loadGenesis(forceReload?: boolean): any;
|
|
216
|
+
/**
|
|
217
|
+
* Record why a persisted genesis row was refused (observability for the
|
|
218
|
+
* schema gate above; loadGrid cannot report a row it never receives).
|
|
219
|
+
*/
|
|
220
|
+
private _noteRejectedGenesis;
|
|
199
221
|
/**
|
|
200
222
|
* Load the persisted gap-evacuation streaks (per-slot in-band cycle counts).
|
|
201
223
|
* @param {boolean} forceReload - If true, reload from disk
|