dexbot 1.6.7 → 1.6.9

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 (626) hide show
  1. package/CHANGELOG.md +73 -1
  2. package/README.md +3 -3
  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 +55 -16
  17. package/dist/market_adapter/core/market_adapter_service.d.ts +81 -1
  18. package/dist/market_adapter/core/market_adapter_service.js +239 -20
  19. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +10 -1
  20. package/dist/market_adapter/core/signals/hurst_analyzer.js +40 -18
  21. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +26 -2
  22. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +132 -29
  23. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
  24. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
  25. package/dist/market_adapter/core/strategies/regime_gate.d.ts +61 -3
  26. package/dist/market_adapter/core/strategies/regime_gate.js +207 -7
  27. package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
  28. package/dist/market_adapter/inputs/window_cache.js +302 -48
  29. package/dist/market_adapter/interval_utils.d.ts +18 -1
  30. package/dist/market_adapter/interval_utils.js +31 -1
  31. package/dist/market_adapter/market_adapter.d.ts +158 -2
  32. package/dist/market_adapter/market_adapter.js +399 -65
  33. package/dist/market_adapter/test_helpers.d.ts +2 -2
  34. package/dist/market_adapter/test_helpers.js +2 -2
  35. package/dist/market_adapter/utils/file_json_cache.d.ts +29 -0
  36. package/dist/market_adapter/utils/file_json_cache.js +106 -0
  37. package/dist/modules/account_bots.js +10 -0
  38. package/dist/modules/account_orders.d.ts +24 -2
  39. package/dist/modules/account_orders.js +41 -4
  40. package/dist/modules/bot_settings.js +10 -1
  41. package/dist/modules/config.d.ts +7 -0
  42. package/dist/modules/config.js +2 -0
  43. package/dist/modules/constants.d.ts +16 -4
  44. package/dist/modules/constants.js +144 -38
  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 +4 -87
  49. package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
  50. package/dist/modules/dexbot_maintenance_runtime.js +59 -11
  51. package/dist/modules/dexbot_startup_runtime.js +73 -20
  52. package/dist/modules/dexbot_state_recovery.d.ts +6 -0
  53. package/dist/modules/dexbot_state_recovery.js +21 -0
  54. package/dist/modules/order/async_lock.d.ts +8 -0
  55. package/dist/modules/order/async_lock.js +15 -0
  56. package/dist/modules/order/genesis_policy.d.ts +162 -0
  57. package/dist/modules/order/genesis_policy.js +267 -0
  58. package/dist/modules/order/grid.js +172 -160
  59. package/dist/modules/order/grid_reconcile.d.ts +9 -0
  60. package/dist/modules/order/grid_reconcile.js +13 -4
  61. package/dist/modules/order/grid_reconcile_internal.js +2 -2
  62. package/dist/modules/order/manager.d.ts +4 -0
  63. package/dist/modules/order/manager.js +14 -1
  64. package/dist/modules/order/sync_engine.d.ts +19 -0
  65. package/dist/modules/order/sync_engine.js +284 -344
  66. package/dist/modules/order/utils/math.d.ts +22 -1
  67. package/dist/modules/order/utils/math.js +64 -1
  68. package/dist/modules/order/utils/order.d.ts +43 -58
  69. package/dist/modules/order/utils/order.js +220 -197
  70. package/dist/modules/order/utils/system.js +8 -1
  71. package/dist/modules/paths.d.ts +1 -0
  72. package/dist/modules/paths.js +1 -0
  73. package/dist/modules/version_notice.d.ts +311 -0
  74. package/dist/modules/version_notice.js +709 -0
  75. package/dist/pm2.js +16 -0
  76. package/dist/unlock.js +28 -0
  77. package/docs/BITSHARES_ONBOARDING.md +8 -1
  78. package/docs/COW_INVARIANTS.md +3 -2
  79. package/docs/DEXBOT_COMPARISON.md +4 -4
  80. package/docs/EVOLUTION.md +22 -20
  81. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  82. package/docs/GRID_PRICE_INVARIANT.md +149 -31
  83. package/docs/GRID_RECALCULATION.md +18 -2
  84. package/docs/README.md +3 -1
  85. package/docs/WORKFLOW.md +16 -5
  86. package/market_adapter/README.md +29 -1
  87. package/modules/README.md +18 -1
  88. package/package.json +13 -5
  89. package/scripts/README.md +28 -2
  90. package/scripts/clear-all.sh +13 -4
  91. package/scripts/clear-logs.sh +13 -4
  92. package/scripts/clear-market-adapter.sh +6 -0
  93. package/scripts/clear-orders.sh +5 -0
  94. package/scripts/lib/dexbot-paths.sh +108 -0
  95. package/tests/README.md +11 -3
  96. package/analysis/account_resolver.ts +0 -161
  97. package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
  98. package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
  99. package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
  100. package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
  101. package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
  102. package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
  103. package/analysis/analyze_dynamic_weight.ts +0 -243
  104. package/analysis/analyze_kalman.ts +0 -157
  105. package/analysis/analyze_regime.ts +0 -158
  106. package/analysis/analyze_regime_windows.ts +0 -470
  107. package/analysis/analyze_risk_profile.ts +0 -199
  108. package/analysis/analyze_trade_heatmap.ts +0 -362
  109. package/analysis/analyze_volatility.ts +0 -182
  110. package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
  111. package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
  112. package/analysis/bot_fitting/shared_utils.ts +0 -52
  113. package/analysis/bot_key_utils.ts +0 -426
  114. package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
  115. package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
  116. package/analysis/chain_pool.ts +0 -47
  117. package/analysis/chart_css.ts +0 -62
  118. package/analysis/chart_ui.ts +0 -105
  119. package/analysis/chart_utils.ts +0 -210
  120. package/analysis/fills_source.ts +0 -228
  121. package/analysis/grid_correction_check.ts +0 -786
  122. package/analysis/math_utils.ts +0 -53
  123. package/analysis/price_sources.ts +0 -136
  124. package/analysis/resolve_bot_accounts.ts +0 -199
  125. package/analysis/resolve_source.ts +0 -99
  126. package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
  127. package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
  128. package/analysis/trade_profitability.ts +0 -1335
  129. package/analysis/tradingview/analyze_tradingview.ts +0 -280
  130. package/analysis/tradingview/h-bts_tradingview.html +0 -1570
  131. package/analysis/tradingview/t-bts_tradingview.html +0 -1570
  132. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
  133. package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
  134. package/analysis/trend_detection/hurst_analyzer.ts +0 -7
  135. package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
  136. package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
  137. package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
  138. package/analysis/trend_detection/package.json +0 -23
  139. package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
  140. package/analysis/trend_detection/regime_chart_generator.ts +0 -338
  141. package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
  142. package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
  143. package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
  144. package/analysis/tsconfig.json +0 -29
  145. package/claw/tests/package.json +0 -3
  146. package/claw/tests/test_claw_bridge.ts +0 -570
  147. package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
  148. package/claw/tests/test_claw_chain_layer.ts +0 -739
  149. package/claw/tests/test_claw_data_flow.ts +0 -525
  150. package/claw/tests/test_claw_domain_logic.ts +0 -471
  151. package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
  152. package/claw/tests/test_claw_mcp_transport.ts +0 -243
  153. package/claw/tests/test_claw_regressions.ts +0 -711
  154. package/claw/tests/test_claw_skill_generation.ts +0 -103
  155. package/claw/tests/test_claw_state_store.ts +0 -44
  156. package/claw/tests/test_dexbot_profiles.ts +0 -654
  157. package/claw/tests/test_memu_bridge.ts +0 -189
  158. package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
  159. package/claw/tests/test_position_health.ts +0 -343
  160. package/claw/tests/test_position_manager.ts +0 -429
  161. package/claw/tests/test_position_manager_watch_health.ts +0 -100
  162. package/claw/tests/test_short_mpa_strategy.ts +0 -232
  163. package/dist/analysis/account_resolver.d.ts.map +0 -1
  164. package/dist/analysis/account_resolver.js.map +0 -1
  165. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
  166. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
  167. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
  168. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
  169. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
  170. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
  171. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
  172. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
  173. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
  174. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
  175. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
  176. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
  177. package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
  178. package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
  179. package/dist/analysis/analyze_kalman.d.ts.map +0 -1
  180. package/dist/analysis/analyze_kalman.js.map +0 -1
  181. package/dist/analysis/analyze_regime.d.ts.map +0 -1
  182. package/dist/analysis/analyze_regime.js.map +0 -1
  183. package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
  184. package/dist/analysis/analyze_regime_windows.js.map +0 -1
  185. package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
  186. package/dist/analysis/analyze_risk_profile.js.map +0 -1
  187. package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
  188. package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
  189. package/dist/analysis/analyze_volatility.d.ts.map +0 -1
  190. package/dist/analysis/analyze_volatility.js.map +0 -1
  191. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
  192. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
  193. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
  194. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
  195. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
  196. package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
  197. package/dist/analysis/bot_key_utils.d.ts.map +0 -1
  198. package/dist/analysis/bot_key_utils.js.map +0 -1
  199. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
  200. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
  201. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
  202. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
  203. package/dist/analysis/chain_pool.d.ts.map +0 -1
  204. package/dist/analysis/chain_pool.js.map +0 -1
  205. package/dist/analysis/chart_css.d.ts.map +0 -1
  206. package/dist/analysis/chart_css.js.map +0 -1
  207. package/dist/analysis/chart_ui.d.ts.map +0 -1
  208. package/dist/analysis/chart_ui.js.map +0 -1
  209. package/dist/analysis/chart_utils.d.ts.map +0 -1
  210. package/dist/analysis/chart_utils.js.map +0 -1
  211. package/dist/analysis/fills_source.d.ts.map +0 -1
  212. package/dist/analysis/fills_source.js.map +0 -1
  213. package/dist/analysis/grid_correction_check.d.ts.map +0 -1
  214. package/dist/analysis/grid_correction_check.js.map +0 -1
  215. package/dist/analysis/math_utils.d.ts.map +0 -1
  216. package/dist/analysis/math_utils.js.map +0 -1
  217. package/dist/analysis/price_sources.d.ts.map +0 -1
  218. package/dist/analysis/price_sources.js.map +0 -1
  219. package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
  220. package/dist/analysis/resolve_bot_accounts.js.map +0 -1
  221. package/dist/analysis/resolve_source.d.ts.map +0 -1
  222. package/dist/analysis/resolve_source.js.map +0 -1
  223. package/dist/analysis/trade_profitability.d.ts.map +0 -1
  224. package/dist/analysis/trade_profitability.js.map +0 -1
  225. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
  226. package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
  227. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
  228. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
  229. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
  230. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
  231. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
  232. package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
  233. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
  234. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
  235. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
  236. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
  237. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
  238. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
  239. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
  240. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
  241. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
  242. package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
  243. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
  244. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
  245. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
  246. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
  247. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
  248. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
  249. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
  250. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
  251. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
  252. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
  253. package/dist/bot.d.ts.map +0 -1
  254. package/dist/bot.js.map +0 -1
  255. package/dist/credential-daemon.d.ts.map +0 -1
  256. package/dist/credential-daemon.js.map +0 -1
  257. package/dist/dexbot.d.ts.map +0 -1
  258. package/dist/dexbot.js.map +0 -1
  259. package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
  260. package/dist/market_adapter/ama_signal_runner.js.map +0 -1
  261. package/dist/market_adapter/candle_utils.d.ts.map +0 -1
  262. package/dist/market_adapter/candle_utils.js.map +0 -1
  263. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
  264. package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
  265. package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
  266. package/dist/market_adapter/core/config_normalizers.js.map +0 -1
  267. package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
  268. package/dist/market_adapter/core/kibana_candles.js.map +0 -1
  269. package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
  270. package/dist/market_adapter/core/kibana_client.js.map +0 -1
  271. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
  272. package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
  273. package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
  274. package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
  275. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
  276. package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
  277. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
  278. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
  279. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
  280. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
  281. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
  282. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
  283. package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
  284. package/dist/market_adapter/core/strategies/ama.js.map +0 -1
  285. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
  286. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
  287. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
  288. package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
  289. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
  290. package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
  291. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
  292. package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
  293. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
  294. package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
  295. package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
  296. package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
  297. package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
  298. package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
  299. package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
  300. package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
  301. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
  302. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
  303. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
  304. package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
  305. package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
  306. package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
  307. package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
  308. package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
  309. package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
  310. package/dist/market_adapter/inputs/window_cache.js.map +0 -1
  311. package/dist/market_adapter/interval_utils.d.ts.map +0 -1
  312. package/dist/market_adapter/interval_utils.js.map +0 -1
  313. package/dist/market_adapter/log_format.d.ts.map +0 -1
  314. package/dist/market_adapter/log_format.js.map +0 -1
  315. package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
  316. package/dist/market_adapter/lp_chart_core.js.map +0 -1
  317. package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
  318. package/dist/market_adapter/lp_chart_runner.js.map +0 -1
  319. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
  320. package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
  321. package/dist/market_adapter/market_adapter.d.ts.map +0 -1
  322. package/dist/market_adapter/market_adapter.js.map +0 -1
  323. package/dist/market_adapter/test_helpers.d.ts.map +0 -1
  324. package/dist/market_adapter/test_helpers.js.map +0 -1
  325. package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
  326. package/dist/market_adapter/utils/adapter_client.js.map +0 -1
  327. package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
  328. package/dist/market_adapter/utils/atomic_write.js.map +0 -1
  329. package/dist/market_adapter/utils/chain.d.ts.map +0 -1
  330. package/dist/market_adapter/utils/chain.js.map +0 -1
  331. package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
  332. package/dist/market_adapter/utils/data_discovery.js.map +0 -1
  333. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
  334. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
  335. package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
  336. package/dist/market_adapter/utils/file_lock.js.map +0 -1
  337. package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
  338. package/dist/market_adapter/utils/native_history.js.map +0 -1
  339. package/dist/modules/account_bots.d.ts.map +0 -1
  340. package/dist/modules/account_bots.js.map +0 -1
  341. package/dist/modules/account_orders.d.ts.map +0 -1
  342. package/dist/modules/account_orders.js.map +0 -1
  343. package/dist/modules/authority_resolver.d.ts.map +0 -1
  344. package/dist/modules/authority_resolver.js.map +0 -1
  345. package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
  346. package/dist/modules/bitshares-native/chain_client.js.map +0 -1
  347. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
  348. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
  349. package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
  350. package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
  351. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
  352. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
  353. package/dist/modules/bitshares-native/index.d.ts.map +0 -1
  354. package/dist/modules/bitshares-native/index.js.map +0 -1
  355. package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
  356. package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
  357. package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
  358. package/dist/modules/bitshares-native/resolvers.js.map +0 -1
  359. package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
  360. package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
  361. package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
  362. package/dist/modules/bitshares-native/serial/index.js.map +0 -1
  363. package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
  364. package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
  365. package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
  366. package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
  367. package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
  368. package/dist/modules/bitshares-native/serial/types.js.map +0 -1
  369. package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
  370. package/dist/modules/bitshares-native/signing_client.js.map +0 -1
  371. package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
  372. package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
  373. package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
  374. package/dist/modules/bitshares-native/transport.js.map +0 -1
  375. package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
  376. package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
  377. package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
  378. package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
  379. package/dist/modules/bitshares_client.d.ts.map +0 -1
  380. package/dist/modules/bitshares_client.js.map +0 -1
  381. package/dist/modules/bot_defaults.d.ts.map +0 -1
  382. package/dist/modules/bot_defaults.js.map +0 -1
  383. package/dist/modules/bot_settings.d.ts.map +0 -1
  384. package/dist/modules/bot_settings.js.map +0 -1
  385. package/dist/modules/bots_file_lock.d.ts.map +0 -1
  386. package/dist/modules/bots_file_lock.js.map +0 -1
  387. package/dist/modules/broadcast_failure.d.ts.map +0 -1
  388. package/dist/modules/broadcast_failure.js.map +0 -1
  389. package/dist/modules/chain_keys.d.ts.map +0 -1
  390. package/dist/modules/chain_keys.js.map +0 -1
  391. package/dist/modules/chain_orders.d.ts.map +0 -1
  392. package/dist/modules/chain_orders.js.map +0 -1
  393. package/dist/modules/cli_colors.d.ts.map +0 -1
  394. package/dist/modules/cli_colors.js.map +0 -1
  395. package/dist/modules/cli_start_onboarding.d.ts.map +0 -1
  396. package/dist/modules/cli_start_onboarding.js.map +0 -1
  397. package/dist/modules/cli_start_output.d.ts.map +0 -1
  398. package/dist/modules/cli_start_output.js.map +0 -1
  399. package/dist/modules/config.d.ts.map +0 -1
  400. package/dist/modules/config.js.map +0 -1
  401. package/dist/modules/constants.d.ts.map +0 -1
  402. package/dist/modules/constants.js.map +0 -1
  403. package/dist/modules/cr_planner.d.ts.map +0 -1
  404. package/dist/modules/cr_planner.js.map +0 -1
  405. package/dist/modules/credential_policy.d.ts.map +0 -1
  406. package/dist/modules/credential_policy.js.map +0 -1
  407. package/dist/modules/credential_runtime.d.ts.map +0 -1
  408. package/dist/modules/credential_runtime.js.map +0 -1
  409. package/dist/modules/credential_session_cache.d.ts.map +0 -1
  410. package/dist/modules/credential_session_cache.js.map +0 -1
  411. package/dist/modules/credit_pricing.d.ts.map +0 -1
  412. package/dist/modules/credit_pricing.js.map +0 -1
  413. package/dist/modules/credit_runtime.d.ts.map +0 -1
  414. package/dist/modules/credit_runtime.js.map +0 -1
  415. package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
  416. package/dist/modules/crypto/browser_provider.js.map +0 -1
  417. package/dist/modules/crypto/index.d.ts.map +0 -1
  418. package/dist/modules/crypto/index.js.map +0 -1
  419. package/dist/modules/crypto/node_provider.d.ts.map +0 -1
  420. package/dist/modules/crypto/node_provider.js.map +0 -1
  421. package/dist/modules/crypto/provider.d.ts.map +0 -1
  422. package/dist/modules/crypto/provider.js.map +0 -1
  423. package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
  424. package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
  425. package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
  426. package/dist/modules/crypto/pure_scrypt.js.map +0 -1
  427. package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
  428. package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
  429. package/dist/modules/crypto/sync.d.ts.map +0 -1
  430. package/dist/modules/crypto/sync.js.map +0 -1
  431. package/dist/modules/daemon_node_health.d.ts.map +0 -1
  432. package/dist/modules/daemon_node_health.js.map +0 -1
  433. package/dist/modules/dexbot_class.d.ts.map +0 -1
  434. package/dist/modules/dexbot_class.js.map +0 -1
  435. package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
  436. package/dist/modules/dexbot_cow_runtime.js.map +0 -1
  437. package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
  438. package/dist/modules/dexbot_credential_client.js.map +0 -1
  439. package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
  440. package/dist/modules/dexbot_fill_runtime.js.map +0 -1
  441. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
  442. package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
  443. package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
  444. package/dist/modules/dexbot_startup_runtime.js.map +0 -1
  445. package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
  446. package/dist/modules/dexbot_state_recovery.js.map +0 -1
  447. package/dist/modules/env.d.ts.map +0 -1
  448. package/dist/modules/env.js.map +0 -1
  449. package/dist/modules/fund_registry.d.ts.map +0 -1
  450. package/dist/modules/fund_registry.js.map +0 -1
  451. package/dist/modules/general_settings.d.ts.map +0 -1
  452. package/dist/modules/general_settings.js.map +0 -1
  453. package/dist/modules/graceful_shutdown.d.ts.map +0 -1
  454. package/dist/modules/graceful_shutdown.js.map +0 -1
  455. package/dist/modules/grid_price_source.d.ts.map +0 -1
  456. package/dist/modules/grid_price_source.js.map +0 -1
  457. package/dist/modules/key_store.d.ts.map +0 -1
  458. package/dist/modules/key_store.js.map +0 -1
  459. package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
  460. package/dist/modules/launcher/adapter_requirement.js.map +0 -1
  461. package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
  462. package/dist/modules/launcher/bot_supervisor.js.map +0 -1
  463. package/dist/modules/launcher/child_env.d.ts.map +0 -1
  464. package/dist/modules/launcher/child_env.js.map +0 -1
  465. package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
  466. package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
  467. package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
  468. package/dist/modules/launcher/credential_daemon.js.map +0 -1
  469. package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
  470. package/dist/modules/launcher/credential_secret.js.map +0 -1
  471. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
  472. package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
  473. package/dist/modules/launcher/headless_password.d.ts.map +0 -1
  474. package/dist/modules/launcher/headless_password.js.map +0 -1
  475. package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
  476. package/dist/modules/launcher/launch_modes.js.map +0 -1
  477. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
  478. package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
  479. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
  480. package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
  481. package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
  482. package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
  483. package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
  484. package/dist/modules/launcher/runtime_entry.js.map +0 -1
  485. package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
  486. package/dist/modules/launcher/status_reporting.js.map +0 -1
  487. package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
  488. package/dist/modules/launcher/supervisor_control.js.map +0 -1
  489. package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
  490. package/dist/modules/market_adapter_whitelist.js.map +0 -1
  491. package/dist/modules/node_connect_policy.d.ts.map +0 -1
  492. package/dist/modules/node_connect_policy.js.map +0 -1
  493. package/dist/modules/node_failure_ledger.d.ts.map +0 -1
  494. package/dist/modules/node_failure_ledger.js.map +0 -1
  495. package/dist/modules/node_health_cache.d.ts.map +0 -1
  496. package/dist/modules/node_health_cache.js.map +0 -1
  497. package/dist/modules/node_manager.d.ts.map +0 -1
  498. package/dist/modules/node_manager.js.map +0 -1
  499. package/dist/modules/order/accounting.d.ts.map +0 -1
  500. package/dist/modules/order/accounting.js.map +0 -1
  501. package/dist/modules/order/async_lock.d.ts.map +0 -1
  502. package/dist/modules/order/async_lock.js.map +0 -1
  503. package/dist/modules/order/export.d.ts.map +0 -1
  504. package/dist/modules/order/export.js.map +0 -1
  505. package/dist/modules/order/format.d.ts.map +0 -1
  506. package/dist/modules/order/format.js.map +0 -1
  507. package/dist/modules/order/grid.d.ts.map +0 -1
  508. package/dist/modules/order/grid.js.map +0 -1
  509. package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
  510. package/dist/modules/order/grid_reconcile.js.map +0 -1
  511. package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
  512. package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
  513. package/dist/modules/order/index.d.ts.map +0 -1
  514. package/dist/modules/order/index.js.map +0 -1
  515. package/dist/modules/order/logger.d.ts.map +0 -1
  516. package/dist/modules/order/logger.js.map +0 -1
  517. package/dist/modules/order/logger_state.d.ts.map +0 -1
  518. package/dist/modules/order/logger_state.js.map +0 -1
  519. package/dist/modules/order/manager.d.ts.map +0 -1
  520. package/dist/modules/order/manager.js.map +0 -1
  521. package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
  522. package/dist/modules/order/processed_fill_store.js.map +0 -1
  523. package/dist/modules/order/strategy.d.ts.map +0 -1
  524. package/dist/modules/order/strategy.js.map +0 -1
  525. package/dist/modules/order/sync_engine.d.ts.map +0 -1
  526. package/dist/modules/order/sync_engine.js.map +0 -1
  527. package/dist/modules/order/utils/math.d.ts.map +0 -1
  528. package/dist/modules/order/utils/math.js.map +0 -1
  529. package/dist/modules/order/utils/order.d.ts.map +0 -1
  530. package/dist/modules/order/utils/order.js.map +0 -1
  531. package/dist/modules/order/utils/slot.d.ts.map +0 -1
  532. package/dist/modules/order/utils/slot.js.map +0 -1
  533. package/dist/modules/order/utils/system.d.ts.map +0 -1
  534. package/dist/modules/order/utils/system.js.map +0 -1
  535. package/dist/modules/order/utils/timeout.d.ts.map +0 -1
  536. package/dist/modules/order/utils/timeout.js.map +0 -1
  537. package/dist/modules/order/utils/validate.d.ts.map +0 -1
  538. package/dist/modules/order/utils/validate.js.map +0 -1
  539. package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
  540. package/dist/modules/order/utils/withPoolRef.js.map +0 -1
  541. package/dist/modules/order/working_grid.d.ts.map +0 -1
  542. package/dist/modules/order/working_grid.js.map +0 -1
  543. package/dist/modules/path_api.d.ts.map +0 -1
  544. package/dist/modules/path_api.js.map +0 -1
  545. package/dist/modules/paths.d.ts.map +0 -1
  546. package/dist/modules/paths.js.map +0 -1
  547. package/dist/modules/process_discovery.d.ts.map +0 -1
  548. package/dist/modules/process_discovery.js.map +0 -1
  549. package/dist/modules/runtime.d.ts.map +0 -1
  550. package/dist/modules/runtime.js.map +0 -1
  551. package/dist/modules/runtime_settings.d.ts.map +0 -1
  552. package/dist/modules/runtime_settings.js.map +0 -1
  553. package/dist/modules/settings_merge.d.ts.map +0 -1
  554. package/dist/modules/settings_merge.js.map +0 -1
  555. package/dist/modules/socket_json_client.d.ts.map +0 -1
  556. package/dist/modules/socket_json_client.js.map +0 -1
  557. package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
  558. package/dist/modules/storage/browser_adapter.js.map +0 -1
  559. package/dist/modules/storage/index.d.ts.map +0 -1
  560. package/dist/modules/storage/index.js.map +0 -1
  561. package/dist/modules/storage/node_adapter.d.ts.map +0 -1
  562. package/dist/modules/storage/node_adapter.js.map +0 -1
  563. package/dist/modules/storage/types.d.ts.map +0 -1
  564. package/dist/modules/storage/types.js.map +0 -1
  565. package/dist/modules/types.d.ts.map +0 -1
  566. package/dist/modules/types.js.map +0 -1
  567. package/dist/modules/utils/base58check.d.ts.map +0 -1
  568. package/dist/modules/utils/base58check.js.map +0 -1
  569. package/dist/modules/utils/build_dir.d.ts.map +0 -1
  570. package/dist/modules/utils/build_dir.js.map +0 -1
  571. package/dist/modules/utils/chain_logs.d.ts.map +0 -1
  572. package/dist/modules/utils/chain_logs.js.map +0 -1
  573. package/dist/modules/utils/errors.d.ts.map +0 -1
  574. package/dist/modules/utils/errors.js.map +0 -1
  575. package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
  576. package/dist/modules/utils/sanitize_key.js.map +0 -1
  577. package/dist/modules/utils/text_width.d.ts.map +0 -1
  578. package/dist/modules/utils/text_width.js.map +0 -1
  579. package/dist/modules/validate_profiles.d.ts.map +0 -1
  580. package/dist/modules/validate_profiles.js.map +0 -1
  581. package/dist/pm2.d.ts.map +0 -1
  582. package/dist/pm2.js.map +0 -1
  583. package/dist/scripts/analyze-credit.d.ts.map +0 -1
  584. package/dist/scripts/analyze-credit.js.map +0 -1
  585. package/dist/scripts/analyze-git.d.ts.map +0 -1
  586. package/dist/scripts/analyze-git.js.map +0 -1
  587. package/dist/scripts/analyze-orders.d.ts.map +0 -1
  588. package/dist/scripts/analyze-orders.js.map +0 -1
  589. package/dist/scripts/chart_command.d.ts.map +0 -1
  590. package/dist/scripts/chart_command.js.map +0 -1
  591. package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
  592. package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
  593. package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
  594. package/dist/scripts/diagnose-pool-history.js.map +0 -1
  595. package/dist/scripts/divergence-calc.d.ts.map +0 -1
  596. package/dist/scripts/divergence-calc.js.map +0 -1
  597. package/dist/scripts/dw.d.ts.map +0 -1
  598. package/dist/scripts/dw.js.map +0 -1
  599. package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
  600. package/dist/scripts/generate_lp_chart.js.map +0 -1
  601. package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
  602. package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
  603. package/dist/scripts/native_release_gates.d.ts.map +0 -1
  604. package/dist/scripts/native_release_gates.js.map +0 -1
  605. package/dist/scripts/print_grid.d.ts.map +0 -1
  606. package/dist/scripts/print_grid.js.map +0 -1
  607. package/dist/scripts/run-tests.d.ts.map +0 -1
  608. package/dist/scripts/run-tests.js.map +0 -1
  609. package/dist/scripts/runner.d.ts.map +0 -1
  610. package/dist/scripts/runner.js.map +0 -1
  611. package/dist/scripts/sync-version.d.ts.map +0 -1
  612. package/dist/scripts/sync-version.js.map +0 -1
  613. package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
  614. package/dist/scripts/test-credit-renewal.js.map +0 -1
  615. package/dist/scripts/tv.d.ts.map +0 -1
  616. package/dist/scripts/tv.js.map +0 -1
  617. package/dist/scripts/update.d.ts.map +0 -1
  618. package/dist/scripts/update.js.map +0 -1
  619. package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
  620. package/dist/scripts/update_dist_freshness.js.map +0 -1
  621. package/dist/scripts/validate_bots.d.ts.map +0 -1
  622. package/dist/scripts/validate_bots.js.map +0 -1
  623. package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
  624. package/dist/scripts/verify-browser-bundle.js.map +0 -1
  625. package/dist/unlock.d.ts.map +0 -1
  626. package/dist/unlock.js.map +0 -1
@@ -6,6 +6,157 @@ import { roundTo } from '../../../modules/order/utils/math.js';
6
6
  import { bilinearInterpolate } from './regime_interp.js';
7
7
  const HURST_CONFIG = MARKET_ADAPTER.HURST_CONFIG;
8
8
  const PE_CONFIG = MARKET_ADAPTER.PE_CONFIG;
9
+ /**
10
+ * Cross-cycle memoization for the regime gate.
11
+ *
12
+ * The adapter runs one cycle per hour per bot, but only ONE new candle closes in
13
+ * that window, and the Hurst/PE state at bar i depends solely on the previous
14
+ * `window` prices. Re-creating both analyzers and re-feeding all ~780 closes
15
+ * every hour therefore recomputed ~99.8% of the same numbers — the single
16
+ * largest CPU item in a cycle.
17
+ *
18
+ * When the caller supplies a stable `cacheKey` (the adapter passes
19
+ * `<botKey>:<intervalSeconds>`), the analyzers and the already-computed
20
+ * per-bar series are kept per key. The next cycle resumes the memoized state
21
+ * when the regime parameters are unchanged and the incoming window is the
22
+ * cached one advanced: same bars, with k leading bars dropped and m new bars
23
+ * appended. A gap repair, a corrected bar, a rewritten value, a different
24
+ * market or a config change all fail that check and fall back to a full
25
+ * recomputation. The resumed result is bit-identical to a from-scratch run in
26
+ * the headline multiplier and in every bar from that run's first ready bar
27
+ * onwards; the pre-warmup prefix can differ by the one-bar readiness offset
28
+ * described below. See tests/test_market_adapter_entropy_equivalence.ts.
29
+ *
30
+ * The leading-drop tolerance is what makes this worthwhile in production: the
31
+ * adapter caps the analysis window (rawKeepCount + analysisKeepCount), so once
32
+ * history saturates every hourly cycle SLIDES the window by one bar. A
33
+ * strict "cached is a prefix of incoming" test misses every one of those
34
+ * cycles. It is safe because both analyzers are rolling: their state depends
35
+ * only on the last `bufferSize` bars, so as long as the shared region still
36
+ * covers that much history, feeding only the new bars lands on exactly the
37
+ * state a cold replay of the whole window would produce.
38
+ *
39
+ * What a resume does NOT reproduce: the warmup boundary in the historical
40
+ * prefix. A warm analyzer pair has been fed one more bar in total than a freshly
41
+ * created one, so it reports its first value one bar earlier. Only the prefix
42
+ * is affected — the headline multiplier and every bar from the cold run's first
43
+ * ready index onwards are identical, which is every bar the service can act on
44
+ * (regimeMultipliers scales a per-bar offset that is itself zero before the
45
+ * AMA/Kalman channels are ready). See
46
+ * tests/test_market_adapter_entropy_equivalence.ts.
47
+ *
48
+ * Without a `cacheKey` the function is stateless, exactly as before.
49
+ */
50
+ const REGIME_CACHE_LIMIT = 32;
51
+ const _regimeCache = new Map();
52
+ /**
53
+ * How many bars of history the analyzers' rolling state can depend on.
54
+ *
55
+ * Taken from the analyzer INSTANCES (each exposes `bufferBars`), never from a
56
+ * second copy of their constructor defaults: a mirrored formula silently
57
+ * under-estimates whenever a default or a buffer formula changes. Being too
58
+ * large only costs a missed resume; being too small would let the resume carry
59
+ * `cached.series` entries that were computed from bars the incoming window no
60
+ * longer contains (the analyzers' final state is unaffected either way — see
61
+ * _locateResume). An analyzer that does not report a usable size fails closed
62
+ * (MAX_SAFE_INTEGER), which disables resuming for that cache entry.
63
+ */
64
+ function _analyzerBufferSize(hurst, pe) {
65
+ const sizes = [Number(hurst?.bufferBars), Number(pe?.bufferBars)]
66
+ .filter((value) => Number.isFinite(value) && value > 0);
67
+ if (sizes.length !== 2)
68
+ return Number.MAX_SAFE_INTEGER;
69
+ return Math.max(sizes[0], sizes[1]);
70
+ }
71
+ /**
72
+ * Locate how `closes` advances the cached window, or null when they are not
73
+ * related that way.
74
+ *
75
+ * Returns `{ k, shared }` where `closes[0..shared)` is exactly
76
+ * `cached[k..cached.length)` — i.e. the incoming window dropped k leading bars
77
+ * and appended `closes.length - shared` new ones. `k = 0, shared =
78
+ * cached.length` is the plain "one or more bars were added" case.
79
+ *
80
+ * The shift is pinned by matching the cached window's newest bar inside the
81
+ * incoming window, then the ENTIRE shared region is verified, so a coincidental
82
+ * price match cannot pass. NaN-aware, like the pre-cache implementation.
83
+ *
84
+ * When the cached newest bar occurs at more than one position and more than one
85
+ * candidate alignment verifies, the window is ambiguous and the function
86
+ * declines to resume. This is hygiene, not a safety requirement: any verified
87
+ * alignment with `shared >= minShared` is exact by construction, because that
88
+ * requirement guarantees the resumed stream's last `bufferBars` values are the
89
+ * same values the incoming stream ends with — the analyzers are rolling, so
90
+ * their final state (and every series entry from that point on) is identical
91
+ * whichever alignment is chosen. Declining only avoids anchoring the
92
+ * `cached.series` carry-over — whose early entries rest on bars the window may
93
+ * no longer contain — to a pattern match we did not intend. It can only arise
94
+ * on degenerate periodic windows, and a cold recompute there is cheap and
95
+ * honest.
96
+ */
97
+ function _locateResume(cached, closes, minShared) {
98
+ if (cached.length === 0 || closes.length === 0)
99
+ return null;
100
+ if (cached.length > closes.length)
101
+ return null;
102
+ // Unchanged window: no scan needed, and no ambiguity to resolve.
103
+ if (cached.length === closes.length) {
104
+ let identical = true;
105
+ for (let i = 0; i < cached.length; i++) {
106
+ if (cached[i] === closes[i] || (Number.isNaN(cached[i]) && Number.isNaN(closes[i])))
107
+ continue;
108
+ identical = false;
109
+ break;
110
+ }
111
+ if (identical)
112
+ return minShared <= cached.length ? { k: 0, shared: cached.length } : null;
113
+ }
114
+ const newest = cached[cached.length - 1];
115
+ let found = null;
116
+ // Newest match first, so the alignment that drops the fewest bars wins.
117
+ for (let p = closes.length - 1; p >= 0; p--) {
118
+ if (!(closes[p] === newest || (Number.isNaN(closes[p]) && Number.isNaN(newest))))
119
+ continue;
120
+ const k = cached.length - 1 - p;
121
+ // k < 0 means the match sits beyond the cached window: not this
122
+ // alignment, but a smaller p may still hold the right one.
123
+ if (k < 0)
124
+ continue;
125
+ const shared = cached.length - k;
126
+ if (shared < minShared)
127
+ return null; // too little history survives the slide
128
+ let ok = true;
129
+ for (let j = k; j < cached.length; j++) {
130
+ const a = cached[j];
131
+ const b = closes[j - k];
132
+ if (a === b || (Number.isNaN(a) && Number.isNaN(b)))
133
+ continue;
134
+ ok = false;
135
+ break;
136
+ }
137
+ if (!ok)
138
+ continue;
139
+ if (found)
140
+ return null; // ambiguous: repeated closes
141
+ found = { k, shared };
142
+ }
143
+ return found;
144
+ }
145
+ function regimeParamsKey(sensitivity, regimeTable, hurstZoneBand, peNodes, hurstCfg, peCfg) {
146
+ return JSON.stringify([sensitivity, regimeTable, hurstZoneBand, peNodes, hurstCfg, peCfg]);
147
+ }
148
+ /**
149
+ * Drop all memoized analyzer state.
150
+ *
151
+ * A test seam today, not a runtime path: the cycle resolves its parameters once
152
+ * per run, so there is no in-process config reload to invalidate state for, and
153
+ * a parameter change is already detected by `regimeParamsKey` (it forces a full
154
+ * recompute). Production never calls this — it exists so a test can assert a
155
+ * cold run against a warm cache without leaking entries between cases.
156
+ */
157
+ function _resetRegimeCache() {
158
+ _regimeCache.clear();
159
+ }
9
160
  function resolvePeNodes(peNodes = null) {
10
161
  if (Array.isArray(peNodes) && peNodes.length === 3 && peNodes.every(Number.isFinite)) {
11
162
  return peNodes;
@@ -39,9 +190,13 @@ function classifyPeRegime(pe, peNodes = null) {
39
190
  * canonical pure implementation in strategies/regime_interp.ts (shared with the
40
191
  * browser-embedded chart scripts).
41
192
  *
42
- * Feeds all prices through HurstAnalyzer and PermutationEntropyAnalyzer,
193
+ * Feeds prices through HurstAnalyzer and PermutationEntropyAnalyzer,
43
194
  * then bilinear-interpolates the regime table to produce a multiplier that
44
- * gates the AMA slope offset in production weight computation.
195
+ * gates the AMA slope offset in production weight computation. When
196
+ * `opts.cacheKey` is set, a window that ADVANCES the memoized one (k leading
197
+ * bars dropped, m appended) resumes from the cached analyzer state and feeds
198
+ * only the appended bars; anything else recomputes from scratch. See the cache
199
+ * notes above.
45
200
  *
46
201
  * @param {number[]} closes - Full close price series (same array used for AMA)
47
202
  * @param {Object} [opts]
@@ -49,6 +204,7 @@ function classifyPeRegime(pe, peNodes = null) {
49
204
  * @param {Array} [opts.regimeTable] - Custom 3x3 regime multiplier table
50
205
  * @param {number} [opts.hurstZoneBand] - Override Hurst neutral-zone width
51
206
  * @param {Array} [opts.peNodes] - Override entropy thresholds
207
+ * @param {string} [opts.cacheKey] - Stable per-market key enabling cross-cycle reuse
52
208
  * @param {Object} [opts.hurstConfig] - Override for HurstAnalyzer config
53
209
  * @param {Object} [opts.peConfig] - Override for PermutationEntropyAnalyzer config
54
210
  * @returns {{ multiplier: number, hurst: number|null, pe: number|null,
@@ -67,6 +223,7 @@ function computeRegimeMultiplier(closes, opts = {}) {
67
223
  const peNodes = Array.isArray(opts.peNodes) ? opts.peNodes : MARKET_ADAPTER.PE_NODES;
68
224
  const hurstCfg = opts.hurstConfig ?? HURST_CONFIG;
69
225
  const peCfg = opts.peConfig ?? PE_CONFIG;
226
+ const cacheKey = typeof opts.cacheKey === 'string' && opts.cacheKey !== '' ? opts.cacheKey : null;
70
227
  // Clamp to 1.0 max: regime only dampens, never amplifies. The
71
228
  // sensitivity exponent is applied in one place for both the per-bar
72
229
  // series and the final value.
@@ -82,12 +239,31 @@ function computeRegimeMultiplier(closes, opts = {}) {
82
239
  };
83
240
  if (!Array.isArray(closes) || closes.length === 0)
84
241
  return notReady;
85
- const hurst = new HurstAnalyzer(hurstCfg);
86
- const pe = new PermutationEntropyAnalyzer(peCfg);
242
+ const paramsKey = regimeParamsKey(sensitivity, regimeTable, hurstZoneBand, peNodes, hurstCfg, peCfg);
243
+ const cached = cacheKey ? _regimeCache.get(cacheKey) : null;
244
+ const resume = (cached && cached.paramsKey === paramsKey)
245
+ ? _locateResume(cached.closes, closes, _analyzerBufferSize(cached.hurst, cached.pe))
246
+ : null;
247
+ const resumable = !!resume;
248
+ const hurst = resumable ? cached.hurst : new HurstAnalyzer(hurstCfg);
249
+ const pe = resumable ? cached.pe : new PermutationEntropyAnalyzer(peCfg);
250
+ // Index-aligned with `closes`, exactly like the pre-cache implementation.
251
+ // The neutral 1.0 fill also covers bars the loop below does not produce a
252
+ // value for (warmup, or a non-finite price it skips): a resumed run must
253
+ // never come back with a hole the cold path would have filled.
254
+ const series = new Array(closes.length).fill(1.0);
255
+ // cached.series[i] was computed for cached.closes[i] === closes[i - k].
256
+ const startIndex = resumable ? resume.shared : 0;
257
+ if (resumable) {
258
+ for (let i = 0; i < startIndex; i++) {
259
+ const carried = cached.series[i + resume.k];
260
+ if (carried !== undefined)
261
+ series[i] = carried;
262
+ }
263
+ }
87
264
  let hurstResult = null;
88
265
  let peResult = null;
89
- const series = new Array(closes.length).fill(1.0);
90
- for (let i = 0; i < closes.length; i++) {
266
+ for (let i = startIndex; i < closes.length; i++) {
91
267
  const price = closes[i];
92
268
  if (!Number.isFinite(price) || price <= 0)
93
269
  continue;
@@ -105,6 +281,30 @@ function computeRegimeMultiplier(closes, opts = {}) {
105
281
  // skip invalid prices (analyzers throw only on non-positive prices)
106
282
  }
107
283
  }
284
+ if (cacheKey) {
285
+ const entry = {
286
+ paramsKey,
287
+ closes: closes.slice(),
288
+ series: series.slice(),
289
+ hurst,
290
+ pe,
291
+ };
292
+ // Re-insert so the Map's insertion order stays a usable LRU order.
293
+ _regimeCache.delete(cacheKey);
294
+ _regimeCache.set(cacheKey, entry);
295
+ while (_regimeCache.size > REGIME_CACHE_LIMIT) {
296
+ const oldest = _regimeCache.keys().next();
297
+ if (oldest.done)
298
+ break;
299
+ _regimeCache.delete(oldest.value);
300
+ }
301
+ }
302
+ // A resumed cycle can legitimately have no new bar to feed (the window is
303
+ // unchanged since the last call); the analyzers already hold that state.
304
+ if (!hurstResult)
305
+ hurstResult = hurst.getAnalysis();
306
+ if (!peResult)
307
+ peResult = pe.getAnalysis();
108
308
  if (!hurstResult?.isReady || !peResult?.isReady)
109
309
  return notReady;
110
310
  const h = hurstResult.hurst;
@@ -121,5 +321,5 @@ function computeRegimeMultiplier(closes, opts = {}) {
121
321
  series: series.map((value) => roundTo(value, 1000)),
122
322
  };
123
323
  }
124
- export { computeRegimeMultiplier };
324
+ export { computeRegimeMultiplier, _resetRegimeCache, _locateResume, _analyzerBufferSize };
125
325
  //# sourceMappingURL=regime_gate.js.map
@@ -1,5 +1,10 @@
1
1
  declare const TAIL_REFRESH_HOURS = 48;
2
- declare const IMMUTABLE_WINDOW_AGE_MS: number;
2
+ declare const TAIL_SETTLE_LAG_MS: number;
3
+ declare const GAP_SETTLE_HORIZON_MS: number;
4
+ declare const GAP_MERGE_TOLERANCE_BUCKETS = 2;
5
+ declare const MAX_SUBFETCH_RANGES = 8;
6
+ declare const MAX_SUBFETCH_SPAN_RATIO = 0.5;
7
+ declare const MAX_COVERAGE_SPANS = 64;
3
8
  declare function shardKeyForTimestamp(tsMs: any): string;
4
9
  declare function shardBoundsForKey(key: any): {
5
10
  start: number;
@@ -13,7 +18,7 @@ declare function readCacheChunk(chunkFile: any, requestKey: any, isMatch: (meta:
13
18
  file: any;
14
19
  rangeGte: number | null;
15
20
  rangeLte: number | null;
16
- queried: any;
21
+ queried: QueriedRange[];
17
22
  } | null;
18
23
  declare function loadBucketCache(outPath: any, requestKey: any, isMatch: (meta: any, requestKey: any) => boolean, range?: {
19
24
  gte: number;
@@ -25,29 +30,42 @@ declare function loadBucketCache(outPath: any, requestKey: any, isMatch: (meta:
25
30
  gte: number | null;
26
31
  lte: number | null;
27
32
  count: number;
28
- queried: {
29
- gte: number;
30
- lte: number;
31
- }[];
33
+ queried: QueriedRange[];
32
34
  }[];
33
35
  shards: {
34
36
  file: string;
35
37
  shardKey: string;
36
38
  candles: any[];
37
- queried: {
38
- gte: number;
39
- lte: number;
40
- }[];
39
+ queried: QueriedRange[];
41
40
  }[];
42
41
  };
43
42
  declare function cachedCandlesInRange(localCache: any, gteMs: number, lteMs: number): any[];
44
- declare function unionQueriedRanges(ranges: {
43
+ /** Span of time actually queried, plus when the query ran (null = unknown). */
44
+ type QueriedRange = {
45
45
  gte: number;
46
46
  lte: number;
47
- }[], bucketMs: number): {
47
+ at: number | null;
48
+ };
49
+ /** Parse a verification timestamp: epoch ms or ISO. Anything else is unknown. */
50
+ declare function timestampMs(raw: any): number | null;
51
+ declare function verifiedAt(range: any): number | null;
52
+ /**
53
+ * Normalize recorded spans: sort, then merge overlapping / bucket-adjacent
54
+ * ones — but ONLY when they assert the same verification time. Merging spans
55
+ * with different `at` would have to pick one verdict for the whole union, and
56
+ * either pick loses (min → the merged span vouches for buckets the older
57
+ * query never saw; max → buckets verified long ago look freshly verified).
58
+ * Keeping them separate preserves exact per-bucket freshness, which is the
59
+ * whole point of `at`. Spans therefore accumulate ~1 per tail run, each a few
60
+ * dozen bytes — negligible next to the candles in the same file, and the
61
+ * same-`at` case (bulk fetches, and every pre-`at` shard) still collapses to
62
+ * one span as before.
63
+ */
64
+ declare function unionQueriedRanges(ranges: {
48
65
  gte: number;
49
66
  lte: number;
50
- }[];
67
+ at?: number | null;
68
+ }[], bucketMs: number): QueriedRange[];
51
69
  declare function rangesCoveredBy(have: {
52
70
  gte: number;
53
71
  lte: number;
@@ -55,24 +73,83 @@ declare function rangesCoveredBy(have: {
55
73
  gte: number;
56
74
  lte: number;
57
75
  }[]): boolean;
76
+ /**
77
+ * Change detection for shard writes: `have` already accounts for every span in
78
+ * `want`, in extent AND in verification time. Without the `at` half, a run
79
+ * whose only news is "these buckets were re-verified 1h later" would skip the
80
+ * write and the next run would fall back to the wide fixed refresh window.
81
+ * An unknown `at` on either side is never treated as fresh.
82
+ */
83
+ declare function coverageSatisfied(have: QueriedRange[], want: QueriedRange[]): boolean;
84
+ /** Every recorded span across the loaded files, newest verification included. */
85
+ declare function allQueriedRanges(fileCover: {
86
+ queried?: QueriedRange[] | null;
87
+ }[]): QueriedRange[];
88
+ /**
89
+ * How settled a window is, given the recorded coverage.
90
+ *
91
+ * A bucket is settled when some recorded query covering it ran at least
92
+ * `lagMs` after the bucket closed — late indexing has certainly landed by
93
+ * then, so re-querying it can only re-confirm cached data. Returns
94
+ * `hasTimestamps: false` when no coverage carries a verification time (all
95
+ * pre-`at` shards), which tells the caller to fall back to the fixed window.
96
+ * Otherwise `firstUnsettled` is the earliest bucket that still needs a query
97
+ * (null when the whole window is settled).
98
+ */
99
+ declare function settleCoverage(opts: {
100
+ gteMs: number;
101
+ lteMs: number;
102
+ bucketMs: number;
103
+ queried: QueriedRange[];
104
+ lagMs: number;
105
+ }): {
106
+ hasTimestamps: boolean;
107
+ firstUnsettled: number | null;
108
+ };
109
+ /**
110
+ * Bound the persisted span list. Because spans merge only when they assert
111
+ * the same `at`, a shard that is re-verified on every run gains one span per
112
+ * run and would grow without limit (and `settleCoverage` scans the list once
113
+ * per tail window). Dropping the OLDEST spans never invents emptiness, but it
114
+ * is not free: coverage is consulted by BOTH `pruneImmutableGaps` (to skip a
115
+ * query) and `settleCoverage` (to decide a bucket is fresh). A dropped span
116
+ * makes its buckets look unsettled, and the tail refresh would otherwise start
117
+ * at the earliest of them. That is why the refresh is capped at
118
+ * TAIL_REFRESH_HOURS: the worst a dropped span can cost is the legacy 48h
119
+ * overlap, never weeks. The input is already sorted by extent, so the tail of
120
+ * the list is the newest.
121
+ */
122
+ declare function compactCoverage(spans: QueriedRange[], maxSpans: number): QueriedRange[];
58
123
  declare function buildFetchWindowsFromRange(timeRange: any, chunkMonths: any): any[];
59
124
  declare function findMissingBucketRanges(gteMs: number, lteMs: number, bucketMs: number, haveTs: Set<number>): {
60
125
  gte: number;
61
126
  lte: number;
62
127
  hours: number;
63
128
  }[];
129
+ /**
130
+ * Merge gap ranges that sit closer together than `toleranceBuckets`, so a
131
+ * cluster of one-bucket holes costs one query instead of one per hole. Only
132
+ * the bounding span widens (the buckets in between get queried too — they are
133
+ * local anyway, so the over-claim is harmless), and input order is preserved.
134
+ */
135
+ declare function mergeGapRanges(missing: {
136
+ gte: number;
137
+ lte: number;
138
+ hours: number;
139
+ }[], bucketMs: number, toleranceBuckets: number): {
140
+ gte: number;
141
+ lte: number;
142
+ hours: number;
143
+ }[];
64
144
  declare function pruneImmutableGaps(missing: {
65
145
  gte: number;
66
146
  lte: number;
67
147
  hours: number;
68
- }[], lteMs: number, fileCover: {
148
+ }[], fileCover: {
69
149
  gte: number | null;
70
150
  lte: number | null;
71
151
  count: number;
72
- queried: {
73
- gte: number;
74
- lte: number;
75
- }[];
152
+ queried: QueriedRange[];
76
153
  }[], nowMs?: number): {
77
154
  gte: number;
78
155
  lte: number;
@@ -147,5 +224,6 @@ declare function runCachedWindows(opts: {
147
224
  lte: string;
148
225
  }) => void;
149
226
  }): Promise<any[]>;
150
- export { TAIL_REFRESH_HOURS, IMMUTABLE_WINDOW_AGE_MS, shardKeyForTimestamp, shardBoundsForKey, shardKeysForRange, shardPathFor, readCacheChunk, loadBucketCache, cachedCandlesInRange, unionQueriedRanges, rangesCoveredBy, buildFetchWindowsFromRange, findMissingBucketRanges, pruneImmutableGaps, persistCacheChunk, planWindowReuse, formatWindowLine, runCachedWindows, };
227
+ 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, };
228
+ export type { QueriedRange };
151
229
  //# sourceMappingURL=window_cache.d.ts.map