dexbot 1.6.6 → 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.
Files changed (632) hide show
  1. package/CHANGELOG.md +89 -1
  2. package/README.md +8 -5
  3. package/analysis/README.md +2 -3
  4. package/analysis/tradingview/README.md +78 -1
  5. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
  6. package/claw/package.json +1 -1
  7. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  8. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  9. package/dist/analysis/tradingview/analyze_tradingview.d.ts +4 -0
  10. package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
  11. package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
  12. package/dist/analysis/tradingview/grid_reset_config.js +235 -0
  13. package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
  14. package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
  15. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
  16. package/dist/dexbot.js +44 -15
  17. package/dist/market_adapter/core/market_adapter_service.js +14 -2
  18. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
  19. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
  20. package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
  21. package/dist/market_adapter/inputs/window_cache.js +302 -48
  22. package/dist/market_adapter/market_adapter.d.ts +8 -1
  23. package/dist/market_adapter/market_adapter.js +22 -4
  24. package/dist/modules/account_bots.js +20 -9
  25. package/dist/modules/account_orders.d.ts +44 -4
  26. package/dist/modules/account_orders.js +104 -7
  27. package/dist/modules/bitshares-native/chain_client.d.ts +10 -0
  28. package/dist/modules/bitshares-native/chain_client.js +197 -28
  29. package/dist/modules/bitshares-native/subscriptions.js +312 -10
  30. package/dist/modules/bitshares-native/transport.d.ts +1 -0
  31. package/dist/modules/bitshares-native/transport.js +97 -3
  32. package/dist/modules/bitshares_client.d.ts +20 -0
  33. package/dist/modules/bitshares_client.js +29 -0
  34. package/dist/modules/bot_settings.js +10 -1
  35. package/dist/modules/chain_keys.d.ts +37 -22
  36. package/dist/modules/chain_keys.js +145 -44
  37. package/dist/modules/cli_start_onboarding.d.ts +10 -0
  38. package/dist/modules/cli_start_onboarding.js +15 -0
  39. package/dist/modules/cli_start_output.d.ts +6 -0
  40. package/dist/modules/cli_start_output.js +8 -0
  41. package/dist/modules/config.d.ts +1 -0
  42. package/dist/modules/config.js +1 -0
  43. package/dist/modules/constants.d.ts +23 -2
  44. package/dist/modules/constants.js +196 -15
  45. package/dist/modules/dexbot_class.d.ts +6 -76
  46. package/dist/modules/dexbot_class.js +0 -32
  47. package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
  48. package/dist/modules/dexbot_cow_runtime.js +53 -96
  49. package/dist/modules/dexbot_fill_runtime.d.ts +6 -1
  50. package/dist/modules/dexbot_fill_runtime.js +22 -3
  51. package/dist/modules/dexbot_maintenance_runtime.d.ts +38 -1
  52. package/dist/modules/dexbot_maintenance_runtime.js +103 -11
  53. package/dist/modules/dexbot_startup_runtime.js +73 -20
  54. package/dist/modules/dexbot_state_recovery.d.ts +6 -0
  55. package/dist/modules/dexbot_state_recovery.js +34 -1
  56. package/dist/modules/order/async_lock.d.ts +8 -0
  57. package/dist/modules/order/async_lock.js +15 -0
  58. package/dist/modules/order/genesis_policy.d.ts +162 -0
  59. package/dist/modules/order/genesis_policy.js +267 -0
  60. package/dist/modules/order/grid.js +109 -135
  61. package/dist/modules/order/grid_reconcile.d.ts +9 -0
  62. package/dist/modules/order/grid_reconcile.js +13 -4
  63. package/dist/modules/order/grid_reconcile_internal.js +13 -2
  64. package/dist/modules/order/logger.d.ts +12 -2
  65. package/dist/modules/order/logger.js +29 -7
  66. package/dist/modules/order/manager.d.ts +53 -0
  67. package/dist/modules/order/manager.js +86 -25
  68. package/dist/modules/order/sync_engine.d.ts +19 -0
  69. package/dist/modules/order/sync_engine.js +284 -344
  70. package/dist/modules/order/utils/math.d.ts +22 -1
  71. package/dist/modules/order/utils/math.js +64 -1
  72. package/dist/modules/order/utils/order.d.ts +43 -58
  73. package/dist/modules/order/utils/order.js +302 -194
  74. package/dist/modules/order/utils/system.d.ts +97 -0
  75. package/dist/modules/order/utils/system.js +282 -3
  76. package/dist/modules/paths.d.ts +8 -1
  77. package/dist/modules/paths.js +11 -3
  78. package/dist/modules/utils/text_width.d.ts +19 -0
  79. package/dist/modules/utils/text_width.js +97 -0
  80. package/dist/modules/version_notice.d.ts +165 -0
  81. package/dist/modules/version_notice.js +364 -0
  82. package/dist/pm2.js +104 -18
  83. package/dist/scripts/update.js +62 -13
  84. package/dist/unlock.d.ts +14 -2
  85. package/dist/unlock.js +101 -4
  86. package/docs/BITSHARES_ONBOARDING.md +8 -1
  87. package/docs/COW_INVARIANTS.md +11 -2
  88. package/docs/CREDENTIAL_SECURITY.md +26 -0
  89. package/docs/DEXBOT_COMPARISON.md +4 -4
  90. package/docs/EVOLUTION.md +20 -18
  91. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  92. package/docs/GRID_PRICE_INVARIANT.md +204 -31
  93. package/docs/GRID_RECALCULATION.md +12 -0
  94. package/docs/LOGGING.md +17 -2
  95. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +6 -7
  96. package/docs/README.md +3 -1
  97. package/docs/WORKFLOW.md +16 -5
  98. package/market_adapter/README.md +1 -1
  99. package/modules/README.md +18 -1
  100. package/package.json +14 -6
  101. package/scripts/README.md +28 -2
  102. package/scripts/clear-all.sh +13 -4
  103. package/scripts/clear-logs.sh +13 -4
  104. package/scripts/clear-market-adapter.sh +6 -0
  105. package/scripts/clear-orders.sh +5 -0
  106. package/scripts/lib/dexbot-paths.sh +108 -0
  107. package/tests/README.md +11 -3
  108. package/analysis/account_resolver.ts +0 -161
  109. package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
  110. package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
  111. package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
  112. package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
  113. package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
  114. package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
  115. package/analysis/analyze_dynamic_weight.ts +0 -243
  116. package/analysis/analyze_kalman.ts +0 -157
  117. package/analysis/analyze_regime.ts +0 -158
  118. package/analysis/analyze_regime_windows.ts +0 -470
  119. package/analysis/analyze_risk_profile.ts +0 -199
  120. package/analysis/analyze_trade_heatmap.ts +0 -362
  121. package/analysis/analyze_volatility.ts +0 -182
  122. package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
  123. package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
  124. package/analysis/bot_fitting/shared_utils.ts +0 -52
  125. package/analysis/bot_key_utils.ts +0 -426
  126. package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
  127. package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
  128. package/analysis/chain_pool.ts +0 -47
  129. package/analysis/chart_css.ts +0 -62
  130. package/analysis/chart_ui.ts +0 -105
  131. package/analysis/chart_utils.ts +0 -210
  132. package/analysis/fills_source.ts +0 -228
  133. package/analysis/grid_correction_check.ts +0 -786
  134. package/analysis/math_utils.ts +0 -53
  135. package/analysis/price_sources.ts +0 -136
  136. package/analysis/resolve_bot_accounts.ts +0 -199
  137. package/analysis/resolve_source.ts +0 -99
  138. package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
  139. package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
  140. package/analysis/trade_profitability.ts +0 -1335
  141. package/analysis/tradingview/analyze_tradingview.ts +0 -280
  142. package/analysis/tradingview/h-bts_tradingview.html +0 -1570
  143. package/analysis/tradingview/t-bts_tradingview.html +0 -1570
  144. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
  145. package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
  146. package/analysis/trend_detection/hurst_analyzer.ts +0 -7
  147. package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
  148. package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
  149. package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
  150. package/analysis/trend_detection/package.json +0 -23
  151. package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
  152. package/analysis/trend_detection/regime_chart_generator.ts +0 -338
  153. package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
  154. package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
  155. package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
  156. package/analysis/tsconfig.json +0 -29
  157. package/claw/tests/package.json +0 -3
  158. package/claw/tests/test_claw_bridge.ts +0 -570
  159. package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
  160. package/claw/tests/test_claw_chain_layer.ts +0 -739
  161. package/claw/tests/test_claw_data_flow.ts +0 -525
  162. package/claw/tests/test_claw_domain_logic.ts +0 -471
  163. package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
  164. package/claw/tests/test_claw_mcp_transport.ts +0 -243
  165. package/claw/tests/test_claw_regressions.ts +0 -711
  166. package/claw/tests/test_claw_skill_generation.ts +0 -103
  167. package/claw/tests/test_claw_state_store.ts +0 -44
  168. package/claw/tests/test_dexbot_profiles.ts +0 -654
  169. package/claw/tests/test_memu_bridge.ts +0 -189
  170. package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
  171. package/claw/tests/test_position_health.ts +0 -343
  172. package/claw/tests/test_position_manager.ts +0 -429
  173. package/claw/tests/test_position_manager_watch_health.ts +0 -100
  174. package/claw/tests/test_short_mpa_strategy.ts +0 -232
  175. package/dist/analysis/account_resolver.d.ts.map +0 -1
  176. package/dist/analysis/account_resolver.js.map +0 -1
  177. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
  178. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
  179. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
  180. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
  181. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
  182. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
  183. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
  184. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
  185. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
  186. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
  187. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
  188. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
  189. package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
  190. package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
  191. package/dist/analysis/analyze_kalman.d.ts.map +0 -1
  192. package/dist/analysis/analyze_kalman.js.map +0 -1
  193. package/dist/analysis/analyze_regime.d.ts.map +0 -1
  194. package/dist/analysis/analyze_regime.js.map +0 -1
  195. package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
  196. package/dist/analysis/analyze_regime_windows.js.map +0 -1
  197. package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
  198. package/dist/analysis/analyze_risk_profile.js.map +0 -1
  199. package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
  200. package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
  201. package/dist/analysis/analyze_volatility.d.ts.map +0 -1
  202. package/dist/analysis/analyze_volatility.js.map +0 -1
  203. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
  204. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
  205. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
  206. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
  207. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
  208. package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
  209. package/dist/analysis/bot_key_utils.d.ts.map +0 -1
  210. package/dist/analysis/bot_key_utils.js.map +0 -1
  211. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
  212. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
  213. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
  214. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
  215. package/dist/analysis/chain_pool.d.ts.map +0 -1
  216. package/dist/analysis/chain_pool.js.map +0 -1
  217. package/dist/analysis/chart_css.d.ts.map +0 -1
  218. package/dist/analysis/chart_css.js.map +0 -1
  219. package/dist/analysis/chart_ui.d.ts.map +0 -1
  220. package/dist/analysis/chart_ui.js.map +0 -1
  221. package/dist/analysis/chart_utils.d.ts.map +0 -1
  222. package/dist/analysis/chart_utils.js.map +0 -1
  223. package/dist/analysis/fills_source.d.ts.map +0 -1
  224. package/dist/analysis/fills_source.js.map +0 -1
  225. package/dist/analysis/grid_correction_check.d.ts.map +0 -1
  226. package/dist/analysis/grid_correction_check.js.map +0 -1
  227. package/dist/analysis/math_utils.d.ts.map +0 -1
  228. package/dist/analysis/math_utils.js.map +0 -1
  229. package/dist/analysis/price_sources.d.ts.map +0 -1
  230. package/dist/analysis/price_sources.js.map +0 -1
  231. package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
  232. package/dist/analysis/resolve_bot_accounts.js.map +0 -1
  233. package/dist/analysis/resolve_source.d.ts.map +0 -1
  234. package/dist/analysis/resolve_source.js.map +0 -1
  235. package/dist/analysis/trade_profitability.d.ts.map +0 -1
  236. package/dist/analysis/trade_profitability.js.map +0 -1
  237. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
  238. package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
  239. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
  240. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
  241. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
  242. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
  243. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
  244. package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
  245. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
  246. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
  247. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
  248. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
  249. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
  250. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
  251. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
  252. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
  253. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
  254. package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
  255. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
  256. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
  257. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
  258. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
  259. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
  260. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
  261. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
  262. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
  263. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
  264. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
  265. package/dist/bot.d.ts.map +0 -1
  266. package/dist/bot.js.map +0 -1
  267. package/dist/credential-daemon.d.ts.map +0 -1
  268. package/dist/credential-daemon.js.map +0 -1
  269. package/dist/dexbot.d.ts.map +0 -1
  270. package/dist/dexbot.js.map +0 -1
  271. package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
  272. package/dist/market_adapter/ama_signal_runner.js.map +0 -1
  273. package/dist/market_adapter/candle_utils.d.ts.map +0 -1
  274. package/dist/market_adapter/candle_utils.js.map +0 -1
  275. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
  276. package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
  277. package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
  278. package/dist/market_adapter/core/config_normalizers.js.map +0 -1
  279. package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
  280. package/dist/market_adapter/core/kibana_candles.js.map +0 -1
  281. package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
  282. package/dist/market_adapter/core/kibana_client.js.map +0 -1
  283. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
  284. package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
  285. package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
  286. package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
  287. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
  288. package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
  289. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
  290. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
  291. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
  292. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
  293. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
  294. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
  295. package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
  296. package/dist/market_adapter/core/strategies/ama.js.map +0 -1
  297. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
  298. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
  299. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
  300. package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
  301. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
  302. package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
  303. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
  304. package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
  305. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
  306. package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
  307. package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
  308. package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
  309. package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
  310. package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
  311. package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
  312. package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
  313. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
  314. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
  315. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
  316. package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
  317. package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
  318. package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
  319. package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
  320. package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
  321. package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
  322. package/dist/market_adapter/inputs/window_cache.js.map +0 -1
  323. package/dist/market_adapter/interval_utils.d.ts.map +0 -1
  324. package/dist/market_adapter/interval_utils.js.map +0 -1
  325. package/dist/market_adapter/log_format.d.ts.map +0 -1
  326. package/dist/market_adapter/log_format.js.map +0 -1
  327. package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
  328. package/dist/market_adapter/lp_chart_core.js.map +0 -1
  329. package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
  330. package/dist/market_adapter/lp_chart_runner.js.map +0 -1
  331. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
  332. package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
  333. package/dist/market_adapter/market_adapter.d.ts.map +0 -1
  334. package/dist/market_adapter/market_adapter.js.map +0 -1
  335. package/dist/market_adapter/test_helpers.d.ts.map +0 -1
  336. package/dist/market_adapter/test_helpers.js.map +0 -1
  337. package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
  338. package/dist/market_adapter/utils/adapter_client.js.map +0 -1
  339. package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
  340. package/dist/market_adapter/utils/atomic_write.js.map +0 -1
  341. package/dist/market_adapter/utils/chain.d.ts.map +0 -1
  342. package/dist/market_adapter/utils/chain.js.map +0 -1
  343. package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
  344. package/dist/market_adapter/utils/data_discovery.js.map +0 -1
  345. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
  346. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
  347. package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
  348. package/dist/market_adapter/utils/file_lock.js.map +0 -1
  349. package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
  350. package/dist/market_adapter/utils/native_history.js.map +0 -1
  351. package/dist/modules/account_bots.d.ts.map +0 -1
  352. package/dist/modules/account_bots.js.map +0 -1
  353. package/dist/modules/account_orders.d.ts.map +0 -1
  354. package/dist/modules/account_orders.js.map +0 -1
  355. package/dist/modules/authority_resolver.d.ts.map +0 -1
  356. package/dist/modules/authority_resolver.js.map +0 -1
  357. package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
  358. package/dist/modules/bitshares-native/chain_client.js.map +0 -1
  359. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
  360. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
  361. package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
  362. package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
  363. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
  364. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
  365. package/dist/modules/bitshares-native/index.d.ts.map +0 -1
  366. package/dist/modules/bitshares-native/index.js.map +0 -1
  367. package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
  368. package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
  369. package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
  370. package/dist/modules/bitshares-native/resolvers.js.map +0 -1
  371. package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
  372. package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
  373. package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
  374. package/dist/modules/bitshares-native/serial/index.js.map +0 -1
  375. package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
  376. package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
  377. package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
  378. package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
  379. package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
  380. package/dist/modules/bitshares-native/serial/types.js.map +0 -1
  381. package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
  382. package/dist/modules/bitshares-native/signing_client.js.map +0 -1
  383. package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
  384. package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
  385. package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
  386. package/dist/modules/bitshares-native/transport.js.map +0 -1
  387. package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
  388. package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
  389. package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
  390. package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
  391. package/dist/modules/bitshares_client.d.ts.map +0 -1
  392. package/dist/modules/bitshares_client.js.map +0 -1
  393. package/dist/modules/bot_defaults.d.ts.map +0 -1
  394. package/dist/modules/bot_defaults.js.map +0 -1
  395. package/dist/modules/bot_settings.d.ts.map +0 -1
  396. package/dist/modules/bot_settings.js.map +0 -1
  397. package/dist/modules/bots_file_lock.d.ts.map +0 -1
  398. package/dist/modules/bots_file_lock.js.map +0 -1
  399. package/dist/modules/broadcast_failure.d.ts.map +0 -1
  400. package/dist/modules/broadcast_failure.js.map +0 -1
  401. package/dist/modules/chain_keys.d.ts.map +0 -1
  402. package/dist/modules/chain_keys.js.map +0 -1
  403. package/dist/modules/chain_orders.d.ts.map +0 -1
  404. package/dist/modules/chain_orders.js.map +0 -1
  405. package/dist/modules/cli_colors.d.ts.map +0 -1
  406. package/dist/modules/cli_colors.js.map +0 -1
  407. package/dist/modules/config.d.ts.map +0 -1
  408. package/dist/modules/config.js.map +0 -1
  409. package/dist/modules/constants.d.ts.map +0 -1
  410. package/dist/modules/constants.js.map +0 -1
  411. package/dist/modules/cr_planner.d.ts.map +0 -1
  412. package/dist/modules/cr_planner.js.map +0 -1
  413. package/dist/modules/credential_policy.d.ts.map +0 -1
  414. package/dist/modules/credential_policy.js.map +0 -1
  415. package/dist/modules/credential_runtime.d.ts.map +0 -1
  416. package/dist/modules/credential_runtime.js.map +0 -1
  417. package/dist/modules/credential_session_cache.d.ts.map +0 -1
  418. package/dist/modules/credential_session_cache.js.map +0 -1
  419. package/dist/modules/credit_pricing.d.ts.map +0 -1
  420. package/dist/modules/credit_pricing.js.map +0 -1
  421. package/dist/modules/credit_runtime.d.ts.map +0 -1
  422. package/dist/modules/credit_runtime.js.map +0 -1
  423. package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
  424. package/dist/modules/crypto/browser_provider.js.map +0 -1
  425. package/dist/modules/crypto/index.d.ts.map +0 -1
  426. package/dist/modules/crypto/index.js.map +0 -1
  427. package/dist/modules/crypto/node_provider.d.ts.map +0 -1
  428. package/dist/modules/crypto/node_provider.js.map +0 -1
  429. package/dist/modules/crypto/provider.d.ts.map +0 -1
  430. package/dist/modules/crypto/provider.js.map +0 -1
  431. package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
  432. package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
  433. package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
  434. package/dist/modules/crypto/pure_scrypt.js.map +0 -1
  435. package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
  436. package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
  437. package/dist/modules/crypto/sync.d.ts.map +0 -1
  438. package/dist/modules/crypto/sync.js.map +0 -1
  439. package/dist/modules/daemon_node_health.d.ts.map +0 -1
  440. package/dist/modules/daemon_node_health.js.map +0 -1
  441. package/dist/modules/dexbot_class.d.ts.map +0 -1
  442. package/dist/modules/dexbot_class.js.map +0 -1
  443. package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
  444. package/dist/modules/dexbot_cow_runtime.js.map +0 -1
  445. package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
  446. package/dist/modules/dexbot_credential_client.js.map +0 -1
  447. package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
  448. package/dist/modules/dexbot_fill_runtime.js.map +0 -1
  449. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
  450. package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
  451. package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
  452. package/dist/modules/dexbot_startup_runtime.js.map +0 -1
  453. package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
  454. package/dist/modules/dexbot_state_recovery.js.map +0 -1
  455. package/dist/modules/env.d.ts.map +0 -1
  456. package/dist/modules/env.js.map +0 -1
  457. package/dist/modules/fund_registry.d.ts.map +0 -1
  458. package/dist/modules/fund_registry.js.map +0 -1
  459. package/dist/modules/general_settings.d.ts.map +0 -1
  460. package/dist/modules/general_settings.js.map +0 -1
  461. package/dist/modules/graceful_shutdown.d.ts.map +0 -1
  462. package/dist/modules/graceful_shutdown.js.map +0 -1
  463. package/dist/modules/grid_price_source.d.ts.map +0 -1
  464. package/dist/modules/grid_price_source.js.map +0 -1
  465. package/dist/modules/key_store.d.ts.map +0 -1
  466. package/dist/modules/key_store.js.map +0 -1
  467. package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
  468. package/dist/modules/launcher/adapter_requirement.js.map +0 -1
  469. package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
  470. package/dist/modules/launcher/bot_supervisor.js.map +0 -1
  471. package/dist/modules/launcher/child_env.d.ts.map +0 -1
  472. package/dist/modules/launcher/child_env.js.map +0 -1
  473. package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
  474. package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
  475. package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
  476. package/dist/modules/launcher/credential_daemon.js.map +0 -1
  477. package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
  478. package/dist/modules/launcher/credential_secret.js.map +0 -1
  479. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
  480. package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
  481. package/dist/modules/launcher/headless_password.d.ts.map +0 -1
  482. package/dist/modules/launcher/headless_password.js.map +0 -1
  483. package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
  484. package/dist/modules/launcher/launch_modes.js.map +0 -1
  485. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
  486. package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
  487. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
  488. package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
  489. package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
  490. package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
  491. package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
  492. package/dist/modules/launcher/runtime_entry.js.map +0 -1
  493. package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
  494. package/dist/modules/launcher/status_reporting.js.map +0 -1
  495. package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
  496. package/dist/modules/launcher/supervisor_control.js.map +0 -1
  497. package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
  498. package/dist/modules/market_adapter_whitelist.js.map +0 -1
  499. package/dist/modules/node_connect_policy.d.ts.map +0 -1
  500. package/dist/modules/node_connect_policy.js.map +0 -1
  501. package/dist/modules/node_failure_ledger.d.ts.map +0 -1
  502. package/dist/modules/node_failure_ledger.js.map +0 -1
  503. package/dist/modules/node_health_cache.d.ts.map +0 -1
  504. package/dist/modules/node_health_cache.js.map +0 -1
  505. package/dist/modules/node_manager.d.ts.map +0 -1
  506. package/dist/modules/node_manager.js.map +0 -1
  507. package/dist/modules/order/accounting.d.ts.map +0 -1
  508. package/dist/modules/order/accounting.js.map +0 -1
  509. package/dist/modules/order/async_lock.d.ts.map +0 -1
  510. package/dist/modules/order/async_lock.js.map +0 -1
  511. package/dist/modules/order/export.d.ts.map +0 -1
  512. package/dist/modules/order/export.js.map +0 -1
  513. package/dist/modules/order/format.d.ts.map +0 -1
  514. package/dist/modules/order/format.js.map +0 -1
  515. package/dist/modules/order/grid.d.ts.map +0 -1
  516. package/dist/modules/order/grid.js.map +0 -1
  517. package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
  518. package/dist/modules/order/grid_reconcile.js.map +0 -1
  519. package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
  520. package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
  521. package/dist/modules/order/index.d.ts.map +0 -1
  522. package/dist/modules/order/index.js.map +0 -1
  523. package/dist/modules/order/logger.d.ts.map +0 -1
  524. package/dist/modules/order/logger.js.map +0 -1
  525. package/dist/modules/order/logger_state.d.ts.map +0 -1
  526. package/dist/modules/order/logger_state.js.map +0 -1
  527. package/dist/modules/order/manager.d.ts.map +0 -1
  528. package/dist/modules/order/manager.js.map +0 -1
  529. package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
  530. package/dist/modules/order/processed_fill_store.js.map +0 -1
  531. package/dist/modules/order/strategy.d.ts.map +0 -1
  532. package/dist/modules/order/strategy.js.map +0 -1
  533. package/dist/modules/order/sync_engine.d.ts.map +0 -1
  534. package/dist/modules/order/sync_engine.js.map +0 -1
  535. package/dist/modules/order/utils/math.d.ts.map +0 -1
  536. package/dist/modules/order/utils/math.js.map +0 -1
  537. package/dist/modules/order/utils/order.d.ts.map +0 -1
  538. package/dist/modules/order/utils/order.js.map +0 -1
  539. package/dist/modules/order/utils/slot.d.ts.map +0 -1
  540. package/dist/modules/order/utils/slot.js.map +0 -1
  541. package/dist/modules/order/utils/system.d.ts.map +0 -1
  542. package/dist/modules/order/utils/system.js.map +0 -1
  543. package/dist/modules/order/utils/timeout.d.ts.map +0 -1
  544. package/dist/modules/order/utils/timeout.js.map +0 -1
  545. package/dist/modules/order/utils/validate.d.ts.map +0 -1
  546. package/dist/modules/order/utils/validate.js.map +0 -1
  547. package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
  548. package/dist/modules/order/utils/withPoolRef.js.map +0 -1
  549. package/dist/modules/order/working_grid.d.ts.map +0 -1
  550. package/dist/modules/order/working_grid.js.map +0 -1
  551. package/dist/modules/path_api.d.ts.map +0 -1
  552. package/dist/modules/path_api.js.map +0 -1
  553. package/dist/modules/paths.d.ts.map +0 -1
  554. package/dist/modules/paths.js.map +0 -1
  555. package/dist/modules/process_discovery.d.ts.map +0 -1
  556. package/dist/modules/process_discovery.js.map +0 -1
  557. package/dist/modules/runtime.d.ts.map +0 -1
  558. package/dist/modules/runtime.js.map +0 -1
  559. package/dist/modules/runtime_settings.d.ts.map +0 -1
  560. package/dist/modules/runtime_settings.js.map +0 -1
  561. package/dist/modules/settings_merge.d.ts.map +0 -1
  562. package/dist/modules/settings_merge.js.map +0 -1
  563. package/dist/modules/socket_json_client.d.ts.map +0 -1
  564. package/dist/modules/socket_json_client.js.map +0 -1
  565. package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
  566. package/dist/modules/storage/browser_adapter.js.map +0 -1
  567. package/dist/modules/storage/index.d.ts.map +0 -1
  568. package/dist/modules/storage/index.js.map +0 -1
  569. package/dist/modules/storage/node_adapter.d.ts.map +0 -1
  570. package/dist/modules/storage/node_adapter.js.map +0 -1
  571. package/dist/modules/storage/types.d.ts.map +0 -1
  572. package/dist/modules/storage/types.js.map +0 -1
  573. package/dist/modules/types.d.ts.map +0 -1
  574. package/dist/modules/types.js.map +0 -1
  575. package/dist/modules/utils/base58check.d.ts.map +0 -1
  576. package/dist/modules/utils/base58check.js.map +0 -1
  577. package/dist/modules/utils/build_dir.d.ts.map +0 -1
  578. package/dist/modules/utils/build_dir.js.map +0 -1
  579. package/dist/modules/utils/chain_logs.d.ts.map +0 -1
  580. package/dist/modules/utils/chain_logs.js.map +0 -1
  581. package/dist/modules/utils/errors.d.ts.map +0 -1
  582. package/dist/modules/utils/errors.js.map +0 -1
  583. package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
  584. package/dist/modules/utils/sanitize_key.js.map +0 -1
  585. package/dist/modules/validate_profiles.d.ts.map +0 -1
  586. package/dist/modules/validate_profiles.js.map +0 -1
  587. package/dist/pm2.d.ts.map +0 -1
  588. package/dist/pm2.js.map +0 -1
  589. package/dist/scripts/analyze-credit.d.ts.map +0 -1
  590. package/dist/scripts/analyze-credit.js.map +0 -1
  591. package/dist/scripts/analyze-git.d.ts.map +0 -1
  592. package/dist/scripts/analyze-git.js.map +0 -1
  593. package/dist/scripts/analyze-orders.d.ts.map +0 -1
  594. package/dist/scripts/analyze-orders.js.map +0 -1
  595. package/dist/scripts/chart_command.d.ts.map +0 -1
  596. package/dist/scripts/chart_command.js.map +0 -1
  597. package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
  598. package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
  599. package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
  600. package/dist/scripts/diagnose-pool-history.js.map +0 -1
  601. package/dist/scripts/divergence-calc.d.ts.map +0 -1
  602. package/dist/scripts/divergence-calc.js.map +0 -1
  603. package/dist/scripts/dw.d.ts.map +0 -1
  604. package/dist/scripts/dw.js.map +0 -1
  605. package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
  606. package/dist/scripts/generate_lp_chart.js.map +0 -1
  607. package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
  608. package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
  609. package/dist/scripts/native_release_gates.d.ts.map +0 -1
  610. package/dist/scripts/native_release_gates.js.map +0 -1
  611. package/dist/scripts/print_grid.d.ts.map +0 -1
  612. package/dist/scripts/print_grid.js.map +0 -1
  613. package/dist/scripts/run-tests.d.ts.map +0 -1
  614. package/dist/scripts/run-tests.js.map +0 -1
  615. package/dist/scripts/runner.d.ts.map +0 -1
  616. package/dist/scripts/runner.js.map +0 -1
  617. package/dist/scripts/sync-version.d.ts.map +0 -1
  618. package/dist/scripts/sync-version.js.map +0 -1
  619. package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
  620. package/dist/scripts/test-credit-renewal.js.map +0 -1
  621. package/dist/scripts/tv.d.ts.map +0 -1
  622. package/dist/scripts/tv.js.map +0 -1
  623. package/dist/scripts/update.d.ts.map +0 -1
  624. package/dist/scripts/update.js.map +0 -1
  625. package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
  626. package/dist/scripts/update_dist_freshness.js.map +0 -1
  627. package/dist/scripts/validate_bots.d.ts.map +0 -1
  628. package/dist/scripts/validate_bots.js.map +0 -1
  629. package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
  630. package/dist/scripts/verify-browser-bundle.js.map +0 -1
  631. package/dist/unlock.d.ts.map +0 -1
  632. 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). Missing buckets are pruned only against recorded query coverage —
15
- * the absence of local buckets alone never certifies history as empty.
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 always re-fetched on the newest window. Kibana indexing
35
- // can lag minutes–hours, so buckets cached as zero-volume fills may gain
36
- // real trades after the fact. 48h bounds the extra query to a small range.
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
- // Windows fully in the past are immutable: blockchain history does not change
39
- // and Kibana indexing lag (minutes–hours) is long past. Leading buckets with
40
- // no trades stay empty forever, so re-querying them every shifted rerun is
41
- // pure waste. Only the recent past is re-checked (see TAIL_REFRESH_HOURS).
42
- const IMMUTABLE_WINDOW_AGE_MS = 7 * 24 * 3600 * 1000;
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
- // ─── Queried-range set ops ────────────────────────────────────────────────────
168
- // Coverage provenance: normalize recorded spans (sort, merge overlapping or
169
- // bucket-adjacent) so growth checks and absorption decisions are exact.
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
- function pruneImmutableGaps(missing, lteMs, fileCover, nowMs = Date.now()) {
265
- const windowOld = lteMs < nowMs - IMMUTABLE_WINDOW_AGE_MS;
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, and only
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
- if (windowOld) {
281
- for (const f of fileCover) {
282
- for (const q of f.queried || []) {
283
- if (q.gte <= m.gte && q.lte >= m.lte)
284
- return false;
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, lteMs, localCache.fileCover, nowMs);
543
+ missing = pruneImmutableGaps(missing, localCache.fileCover, nowMs);
339
544
  };
340
545
  prune();
341
- // Late-indexing guard: the newest window always re-fetches its
342
- // trailing overlap so zero-volume fills can gain real trades.
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 refreshFromMs = lteMs - TAIL_REFRESH_HOURS * 3600 * 1000;
345
- if (refreshFromMs > gteMs) {
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, missingHours, windowHours, inputsValid } = plan;
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 && missing.length > 0 && missingHours <= windowHours / 2 && missing.length <= 3) {
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 ${missingHours}h in ${missing.length} sub-range(s))`);
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 missing) {
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
- queriedRanges = [{ gte: gteMs, lte: lteMs }];
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
- if (candlesEqual(before, after) && rangesCoveredBy(state.queried, union))
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, IMMUTABLE_WINDOW_AGE_MS, shardKeyForTimestamp, shardBoundsForKey, shardKeysForRange, shardPathFor, readCacheChunk, loadBucketCache, cachedCandlesInRange, unionQueriedRanges, rangesCoveredBy, buildFetchWindowsFromRange, findMissingBucketRanges, pruneImmutableGaps, persistCacheChunk, planWindowReuse, formatWindowLine, runCachedWindows, };
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
@@ -101,6 +101,7 @@ import { mergeSettings } from './settings_merge.js';
101
101
  import { getErrorMessage } from './utils/errors.js';
102
102
  import { roundToDecimals, parseRelativeMultiplier } from './order/utils/math.js';
103
103
  import { CLI_COLORS } from './cli_colors.js';
104
+ import { displayWidth, padDisplay } from './utils/text_width.js';
104
105
  const storage = getStorage();
105
106
  const { writeJSON } = storage;
106
107
  const BOTS_FILE = PATHS.PROFILES.BOTS_JSON;
@@ -218,22 +219,22 @@ function listBots(bots) {
218
219
  dryRun: !!bot.dryRun
219
220
  }));
220
221
  const indexWidth = Math.max(1, ...rows.map(r => r.index.length));
221
- const nameWidth = Math.max('Name'.length, ...rows.map(r => r.name.length));
222
- const accountWidth = Math.max('Account'.length, ...rows.map(r => r.account.length));
223
- const pairWidth = Math.max('Pair'.length, ...rows.map(r => r.pair.length));
222
+ const nameWidth = Math.max('Name'.length, ...rows.map(r => displayWidth(r.name)));
223
+ const accountWidth = Math.max('Account'.length, ...rows.map(r => displayWidth(r.account)));
224
+ const pairWidth = Math.max('Pair'.length, ...rows.map(r => displayWidth(r.pair)));
224
225
  const header = [
225
226
  '#'.padEnd(indexWidth),
226
- 'Name'.padEnd(nameWidth),
227
- 'Account'.padEnd(accountWidth),
228
- 'Pair'.padEnd(pairWidth)
227
+ padDisplay('Name', nameWidth),
228
+ padDisplay('Account', accountWidth),
229
+ padDisplay('Pair', pairWidth)
229
230
  ].join(' ');
230
231
  console.log(` ${COLORS.yellowBold}${header}${COLORS.reset}`);
231
232
  for (const row of rows) {
232
233
  const flags = `${row.inactive ? ` ${COLORS.red}[inactive]${COLORS.reset}` : ''}${row.dryRun ? ` ${COLORS.yellow}(dryRun)${COLORS.reset}` : ''}`;
233
234
  console.log(` ${COLORS.gray}${row.index.padEnd(indexWidth)}${COLORS.reset} ` +
234
- `${COLORS.green}${row.name.padEnd(nameWidth)}${COLORS.reset} ` +
235
- `${COLORS.orange}${row.account.padEnd(accountWidth)}${COLORS.reset} ` +
236
- `${COLORS.cyan}${row.pair.padEnd(pairWidth)}${COLORS.reset}${flags}`);
235
+ `${COLORS.green}${padDisplay(row.name, nameWidth)}${COLORS.reset} ` +
236
+ `${COLORS.orange}${padDisplay(row.account, accountWidth)}${COLORS.reset} ` +
237
+ `${COLORS.cyan}${padDisplay(row.pair, pairWidth)}${COLORS.reset}${flags}`);
237
238
  }
238
239
  }
239
240
  /**
@@ -1562,6 +1563,8 @@ async function promptGeneralSettings() {
1562
1563
  const updaterStatus = settings.UPDATER.ACTIVE ? `${COLORS.green}ON${COLORS.reset}` : `${COLORS.red}OFF${COLORS.reset}`;
1563
1564
  const currentSched = parseCronToDelta(settings.UPDATER.SCHEDULE || "0 0 * * *");
1564
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}`);
1565
1568
  console.log('--------------------------------------------------');
1566
1569
  console.log(`${COLORS.greenBold}S) Save & Exit${COLORS.reset}`);
1567
1570
  console.log(`${COLORS.white}C) Cancel (Discard changes)${COLORS.reset}`);
@@ -1679,6 +1682,14 @@ async function promptGeneralSettings() {
1679
1682
  break;
1680
1683
  settings.UPDATER.BRANCH = branch;
1681
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;
1682
1693
  break;
1683
1694
  case 's':
1684
1695
  saveGeneralSettings(settings);