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
package/dist/dexbot.js CHANGED
@@ -157,7 +157,7 @@ const CLI_EXAMPLES = [
157
157
  { title: 'Analyze persisted order grids', command: 'dexbot order', notes: 'Runs the order analyzer across the orders directory (<profiles>/orders) and prints spread/increment/funds/distribution metrics. Add a bot key to render only that bot, and --export for an HTML report.' },
158
158
  { title: 'Show live credit/MPA positions', command: 'dexbot credit', notes: 'Queries get_margin_positions + get_credit_deals_by_borrower per preferredAccount and prints debt/collateral sums plus one Curr. CR line per whitelisted pair (active CR, else borrow-now CR vs funds avail. on the offer) and one Avar. CR line per bot. CR covers only pairs whitelisted in bots.json and listed on the current credit offer. Add a bot key to render only that bot.' },
159
159
  { title: 'TradingView chart for a bot, pool, or pair', command: 'dexbot tv <bot|pool-id|AssetA/AssetB> --month 3', notes: 'Fetches 1h candles for N months (default 3, pool-first with orderbook fallback; --feed charts MPA price-feed history) and writes an auto-named HTML chart.' },
160
- { title: 'Clear all bot log files', command: 'dexbot clear', notes: 'Runs scripts/clear-logs.sh to remove log files from the logs directory (<profiles>/logs).' },
160
+ { title: 'Clear all bot log files', command: 'dexbot clear', notes: 'Runs scripts/clear-logs.sh to remove *.log, rotated *.log.N and *.jsonl* from the logs directory (<profiles>/logs), including the credential audit trail daemon-audit.jsonl and its rotated siblings (named in the preview). Offline only: the scripts warn when a live runtime is detected, but a running bot keeps writing to unlinked files and the space is not freed until it restarts; dexbot clear-orders / clear-market-adapter / clear-all are undone within seconds (grid state is re-persisted, the adapter rewrites its state file and lock). Stop first with dexbot stop / dexbot pm2 stop all.' },
161
161
  { title: 'Reset settings to defaults', command: 'dexbot default', notes: 'Runs scripts/reset-settings.sh to delete general.settings.json, market_profiles.json, and market_adapter_settings.json.' }
162
162
  ];
163
163
  const STARTUP_COLORS = {
@@ -217,10 +217,10 @@ function printCLIUsage() {
217
217
  ['dw <target>', 'Dynamic-weight research chart: same targets/flags as tv (see analysis/).'],
218
218
  ]],
219
219
  ['Files', [
220
- ['clear', 'Remove all log files from <profiles>/logs/.'],
221
- ['clear-orders', 'Remove all persisted order files from <profiles>/orders/.'],
222
- ['clear-market-adapter', 'Remove market adapter data, state, and logs.'],
223
- ['clear-all', 'Remove orders, logs, market adapter, and claw files (all of the above).'],
220
+ ['clear', 'Delete <profiles>/logs/*.log, *.log.N and *.jsonl* (audit trail included). Stop the runtime first.'],
221
+ ['clear-orders', 'Delete persisted grid state in <profiles>/orders (regenerated on next start).'],
222
+ ['clear-market-adapter', 'Delete market adapter data, state, lock, and adapter logs.'],
223
+ ['clear-all', 'All of the above, plus claw data. Stop the runtime first.'],
224
224
  ]],
225
225
  ];
226
226
  const width = Math.max(...groups.flatMap(([, entries]) => entries.map(([cmd]) => cmd.length))) + 2;
@@ -1072,8 +1072,52 @@ async function handleCLICommands() {
1072
1072
  return true;
1073
1073
  }
1074
1074
  case 'status': {
1075
- console.log(`DEXBot2 v${Config.VERSION}`);
1075
+ // Installed-vs-published version status, from the single shared
1076
+ // renderer in modules/version_notice.ts: green when current, orange
1077
+ // when a newer release exists, gray when the probe cannot answer.
1078
+ //
1079
+ // The probe is STAGED around the report instead of being awaited
1080
+ // inline (see startStagedVersionStatus):
1081
+ // top 1s grace. A valid cache or a quick registry answer lands
1082
+ // inside it and the report never notices the wait.
1083
+ // bottom 1s more for the probe still in flight, then a forced
1084
+ // re-probe with the full NOTICE_STATUS_TIMEOUT_MS budget.
1085
+ // If even that is silent, the verdict says so explicitly
1086
+ // rather than leaving a missing line to be read as
1087
+ // "you are up to date".
1088
+ // So the report costs at most 1s up front, and the verdict is
1089
+ // printed at exactly one terminal point, which no early
1090
+ // `process.exit()` in a branch below can truncate.
1091
+ const { UPDATER } = require('./modules/constants');
1092
+ const { startStagedVersionStatus, printVersionStatusOrHeader } = require('./modules/version_notice');
1093
+ const versionWait = startStagedVersionStatus({
1094
+ graceMs: UPDATER.NOTICE_STAGE_GRACE_MS,
1095
+ timeoutMs: UPDATER.NOTICE_STATUS_TIMEOUT_MS,
1096
+ // DEXBOT_VERSION_CHECK_FORCE=1 re-probes instead of answering
1097
+ // from the cache: the escape hatch when a cached failure is
1098
+ // indistinguishable from a live one.
1099
+ force: Config.DEXBOT_VERSION_CHECK_FORCE,
1100
+ });
1101
+ // Top-of-report grace. The VALUE is unused on purpose, only the
1102
+ // timing matters: `settled` is what gets displayed at the end.
1103
+ await versionWait.quick;
1076
1104
  console.log();
1105
+ // The ONE terminal point of this command: every branch below ends
1106
+ // in `finish(...)` instead of `process.exit(...)`, so the deferred
1107
+ // version line is always printed — including on the "no processes"
1108
+ // and delegated-`unlock status` paths, which used to exit before
1109
+ // the probe had anything to say.
1110
+ const finish = async (code) => {
1111
+ // Blank line, then the verdict: it is the last thing the
1112
+ // operator reads, so it gets its own block at the bottom. With
1113
+ // the check switched off, the shared helper falls back to the
1114
+ // bare "DEXBot2 vX.Y.Z" header, so the running build is always
1115
+ // named - the inline path's long-standing behaviour.
1116
+ console.log();
1117
+ printVersionStatusOrHeader(await versionWait.settled, { indent: '', surround: false });
1118
+ process.exit(code);
1119
+ return true;
1120
+ };
1077
1121
  const { spawnSync, execSync } = require('child_process');
1078
1122
  const MONOLITHIC_PID_FILE = PATHS.PROFILES.MONOLITHIC_PID;
1079
1123
  const MONOLITHIC_CRED_PID_FILE = PATHS.PROFILES.MONOLITHIC_CRED_PID;
@@ -1133,22 +1177,19 @@ async function handleCLICommands() {
1133
1177
  cwd: PATHS.PROJECT_ROOT,
1134
1178
  stdio: 'inherit',
1135
1179
  });
1136
- process.exit(result.status ?? 0);
1137
- return true;
1180
+ return finish(result.status ?? 0);
1138
1181
  }
1139
1182
  try {
1140
1183
  const output = execSync('pm2 jlist 2>/dev/null', { encoding: 'utf8', timeout: 5000 }).toString().trim();
1141
1184
  const jsonStart = output.indexOf('[');
1142
1185
  if (jsonStart === -1) {
1143
1186
  console.log('No DEXBot2 processes running.');
1144
- process.exit(0);
1145
- return true;
1187
+ return finish(0);
1146
1188
  }
1147
1189
  const allProcs = JSON.parse(output.slice(jsonStart));
1148
1190
  if (!Array.isArray(allProcs) || allProcs.length === 0) {
1149
1191
  console.log('No DEXBot2 processes running.');
1150
- process.exit(0);
1151
- return true;
1192
+ return finish(0);
1152
1193
  }
1153
1194
  const serviceNames = new Set(['dexbot-cred', 'dexbot-adapter', 'dexbot-update']);
1154
1195
  const botNames = new Set();
@@ -1167,8 +1208,7 @@ async function handleCLICommands() {
1167
1208
  });
1168
1209
  if (dexbotProcs.length === 0) {
1169
1210
  console.log('No DEXBot2 processes running.');
1170
- process.exit(0);
1171
- return true;
1211
+ return finish(0);
1172
1212
  }
1173
1213
  console.log('='.repeat(50));
1174
1214
  console.log('DEXBot2 PM2 Processes');
@@ -1219,8 +1259,7 @@ async function handleCLICommands() {
1219
1259
  catch {
1220
1260
  console.log('No DEXBot2 processes running.');
1221
1261
  }
1222
- process.exit(0);
1223
- return true;
1262
+ return finish(0);
1224
1263
  }
1225
1264
  case 'delete':
1226
1265
  case 'stop':
@@ -1,6 +1,19 @@
1
1
  declare const AMA_SLOPE_PERCENT_MODE_PER_BAR = "perBar";
2
2
  declare function normalizeAmaSlopePercentMode(value: any): "perBar" | "window" | null;
3
3
  declare function convertSlopePercentToPerBar(value: any, lookbackBars: any, mode: any): number | null;
4
+ /**
5
+ * Standing repair verdict for a PERSISTED STATE entry — the summary the
6
+ * previous cycle wrote. Returns a reason string when repair is still owed,
7
+ * null when the cache is clean.
8
+ *
9
+ * State-side mirror of candleFileCoversClosedBucket: that gate judges the
10
+ * on-disk candle file, this one judges the state summary, and the two must
11
+ * describe the same standing conditions so the startup sleep and the in-cycle
12
+ * skip cannot silently disagree. When a new standing signal is added to one,
13
+ * add it to the other (source/newest-candle checks are file-only and cannot
14
+ * appear here; unresolvedGapCount and the warmup shortfall exist in both).
15
+ */
16
+ declare function evaluateStateRepairVeto(entry: any): "unresolved_gaps" | "cache_count_unknown" | "cache_below_warmup_target" | null;
4
17
  declare class MarketAdapterService {
5
18
  deps: any;
6
19
  constructor(deps?: any);
@@ -16,6 +29,73 @@ declare class MarketAdapterService {
16
29
  * deeper history than the analytical minimum.
17
30
  */
18
31
  bootstrapKibanaLookbackHours(cfg: any, keepCount: any): number;
32
+ /**
33
+ * Closed-bucket arithmetic shared by the off-hour skip logic.
34
+ *
35
+ * Thin instance wrapper around the shared bucket helper so the `getNowMs`
36
+ * injection used by tests and embedders keeps working. `intervalSeconds`
37
+ * is validated by the helper: a missing/invalid interval can never
38
+ * masquerade as "nothing new" — it returns null and the caller must fall
39
+ * through to the network path instead of skipping a cycle it cannot
40
+ * evaluate.
41
+ */
42
+ latestClosedBucketStartMs(intervalSeconds: any, nowMs?: any): number | null;
43
+ /**
44
+ * Off-hour skip check: is there any closed candle this bot has not
45
+ * consumed yet? Runs on persisted state + the wall clock only — no
46
+ * chain RPC, no candle parse. Returns null when the answer cannot be
47
+ * determined (invalid interval, unknown state shape, one-shot mode), in
48
+ * which case the caller must run the full cycle instead of skipping.
49
+ *
50
+ * `once` (the `--once` CLI and the embedded runOnceForAma) always runs the
51
+ * full cycle: those entry points exist to *produce* a result on demand —
52
+ * the signal runner prints the AMA, an operator asks for a fresh cycle —
53
+ * and returning a state-only "skipped" record with null prices would
54
+ * quietly degrade their output. Only the long-running daemon, which has a
55
+ * schedule of its own, may answer "nothing new, skipping".
56
+ *
57
+ * The verdict requires the consumed marker to equal the newest closed
58
+ * bucket exactly. A marker AHEAD of that bucket means the two clocks
59
+ * disagree (clock skew, a state file carried across hosts, a synthetic
60
+ * fixture); skipping there would discard a candle the adapter may not
61
+ * actually have processed, so the conservative answer is always "run".
62
+ *
63
+ * Skipped bots still refresh `lastCycleAt`/`lastCycleSource` in state so
64
+ * monitoring can tell "idle by design" apart from "dead process".
65
+ */
66
+ shouldSkipBotForClosedCandle(_bot: any, botState: any, intervalSeconds: any, nowMs?: any, cfg?: any): {
67
+ latestClosedBucketStartMs: number;
68
+ previousClosedCandleTs: number;
69
+ } | null;
70
+ /**
71
+ * Does the cached candle file belong to a different market source than the
72
+ * bot is configured for?
73
+ *
74
+ * Single source of truth for the reset rule: the off-hour gate
75
+ * (candleFileCoversClosedBucket) and the full path must agree, otherwise a
76
+ * source switch could be skipped off-hour and the cache would keep serving
77
+ * candles from the old source until the next close forced a full run.
78
+ * The pool/book cross-checks matter for legacy caches that predate
79
+ * `meta.marketSource`: a stored pool id alongside a book-configured bot (or
80
+ * a book cache under a pool bot) is just as much a mismatch.
81
+ */
82
+ isCandleSourceMismatch(meta: any, marketSource: any): boolean;
83
+ /**
84
+ * Does the local candle cache already hold the data for a closed bucket?
85
+ *
86
+ * Second half of the off-hour skip verdict (see
87
+ * shouldSkipBotForClosedCandle): the full cycle repairs history even
88
+ * without a new close (Kibana backfill, gap fill), so skipping is only
89
+ * safe when the cache is healthy for that bucket. False whenever
90
+ * anything needs repair: a source switch, unresolved gaps, an empty or
91
+ * short file (fewer candles than the AMA warmup target — the exact case
92
+ * the backfill path exists for), or a newest candle that predates the
93
+ * bucket.
94
+ *
95
+ * The state-side mirror of the standing conditions (unresolved gaps, warmup
96
+ * shortfall) is evaluateStateRepairVeto above; keep the two in step.
97
+ */
98
+ candleFileCoversClosedBucket(candles: any, meta: any, marketSource: any, closedBucketStartMs: any, requiredCount?: any): boolean;
19
99
  selectClosedCandles(candles: any, intervalSeconds: any, nowMs?: any): {
20
100
  closedCandles: any[];
21
101
  currentBucketStartMs: null;
@@ -231,5 +311,5 @@ declare class MarketAdapterService {
231
311
  };
232
312
  processBot(bot: any, state: any, cfg: any, contextCache: any, hooks?: any): Promise<any>;
233
313
  }
234
- export { MarketAdapterService, AMA_SLOPE_PERCENT_MODE_PER_BAR, normalizeAmaSlopePercentMode, convertSlopePercentToPerBar };
314
+ export { MarketAdapterService, AMA_SLOPE_PERCENT_MODE_PER_BAR, normalizeAmaSlopePercentMode, convertSlopePercentToPerBar, evaluateStateRepairVeto };
235
315
  //# sourceMappingURL=market_adapter_service.d.ts.map
@@ -2,6 +2,7 @@
2
2
  import { calculateATR } from './strategies/atr/calculator.js';
3
3
  import { normalizeMarketSource, hasNumericStartPrice, resolveMarketSourceForBot } from '../utils/chain.js';
4
4
  import { computeRegimeMultiplier } from './strategies/regime_gate.js';
5
+ import { noteJsonWritten, readCachedJson } from '../utils/file_json_cache.js';
5
6
  import { calculateAMA, getAmaWarmupBars } from './strategies/ama.js';
6
7
  import { computeDynamicWeightSeries } from './strategies/dynamic_weight_series.js';
7
8
  import { KalmanTrendAnalyzer } from './signals/kalman_trend_analyzer.js';
@@ -16,6 +17,7 @@ import { normalizeAtrPeriod, normalizeMaxVolatilityOffset, normalizeVolatilityTh
16
17
  import { buildKalmanVelocitySeries, computeAbsolutePercentileThreshold, } from './signals/kalman_velocity_smoothing.js';
17
18
  import { resolveMaxAsymmetryFactor, computeAsymmetricBoundsMetrics, } from './asymmetric_bounds.js';
18
19
  import { getErrorMessage } from '../../modules/utils/errors.js';
20
+ import { bucketStartMs, latestClosedBucketStartMs as latestClosedBucket } from '../interval_utils.js';
19
21
  const marketAdapterServiceLogger = new Logger('MarketAdapterService');
20
22
  const AMA_SLOPE_PERCENT_MODE_PER_BAR = 'perBar';
21
23
  const AMA_SLOPE_PERCENT_MODE_WINDOW = 'window';
@@ -94,6 +96,34 @@ function computeGridPriceOffsetPlan(bot, amaSlope) {
94
96
  gridPriceOffsetPct,
95
97
  };
96
98
  }
99
+ /**
100
+ * Standing repair verdict for a PERSISTED STATE entry — the summary the
101
+ * previous cycle wrote. Returns a reason string when repair is still owed,
102
+ * null when the cache is clean.
103
+ *
104
+ * State-side mirror of candleFileCoversClosedBucket: that gate judges the
105
+ * on-disk candle file, this one judges the state summary, and the two must
106
+ * describe the same standing conditions so the startup sleep and the in-cycle
107
+ * skip cannot silently disagree. When a new standing signal is added to one,
108
+ * add it to the other (source/newest-candle checks are file-only and cannot
109
+ * appear here; unresolvedGapCount and the warmup shortfall exist in both).
110
+ */
111
+ function evaluateStateRepairVeto(entry) {
112
+ if (Number(entry?.unresolvedGapCount) > 0)
113
+ return 'unresolved_gaps';
114
+ const keepTarget = Number(entry?.rawKeepCount);
115
+ if (!Number.isFinite(keepTarget) || keepTarget <= 0)
116
+ return null;
117
+ const candleCount = Number(entry?.candleCount);
118
+ // Target known but current count unknown is NOT "nothing owed": an
119
+ // older or half-written row would otherwise read as healthy. Veto, and
120
+ // let the next full cycle rewrite the row with both fields.
121
+ if (!Number.isFinite(candleCount))
122
+ return 'cache_count_unknown';
123
+ if (candleCount < keepTarget)
124
+ return 'cache_below_warmup_target';
125
+ return null;
126
+ }
97
127
  class MarketAdapterService {
98
128
  deps;
99
129
  constructor(deps = {}) {
@@ -130,18 +160,123 @@ class MarketAdapterService {
130
160
  : 1;
131
161
  return Math.max(Number(cfg?.bootstrapLookbackHours) || 0, Number(keepCount) * intervalHours);
132
162
  }
163
+ /**
164
+ * Closed-bucket arithmetic shared by the off-hour skip logic.
165
+ *
166
+ * Thin instance wrapper around the shared bucket helper so the `getNowMs`
167
+ * injection used by tests and embedders keeps working. `intervalSeconds`
168
+ * is validated by the helper: a missing/invalid interval can never
169
+ * masquerade as "nothing new" — it returns null and the caller must fall
170
+ * through to the network path instead of skipping a cycle it cannot
171
+ * evaluate.
172
+ */
173
+ latestClosedBucketStartMs(intervalSeconds, nowMs = this.getNowMs()) {
174
+ return latestClosedBucket(nowMs, intervalSeconds);
175
+ }
176
+ /**
177
+ * Off-hour skip check: is there any closed candle this bot has not
178
+ * consumed yet? Runs on persisted state + the wall clock only — no
179
+ * chain RPC, no candle parse. Returns null when the answer cannot be
180
+ * determined (invalid interval, unknown state shape, one-shot mode), in
181
+ * which case the caller must run the full cycle instead of skipping.
182
+ *
183
+ * `once` (the `--once` CLI and the embedded runOnceForAma) always runs the
184
+ * full cycle: those entry points exist to *produce* a result on demand —
185
+ * the signal runner prints the AMA, an operator asks for a fresh cycle —
186
+ * and returning a state-only "skipped" record with null prices would
187
+ * quietly degrade their output. Only the long-running daemon, which has a
188
+ * schedule of its own, may answer "nothing new, skipping".
189
+ *
190
+ * The verdict requires the consumed marker to equal the newest closed
191
+ * bucket exactly. A marker AHEAD of that bucket means the two clocks
192
+ * disagree (clock skew, a state file carried across hosts, a synthetic
193
+ * fixture); skipping there would discard a candle the adapter may not
194
+ * actually have processed, so the conservative answer is always "run".
195
+ *
196
+ * Skipped bots still refresh `lastCycleAt`/`lastCycleSource` in state so
197
+ * monitoring can tell "idle by design" apart from "dead process".
198
+ */
199
+ shouldSkipBotForClosedCandle(_bot, botState, intervalSeconds, nowMs = this.getNowMs(), cfg = null) {
200
+ if (cfg?.once)
201
+ return null;
202
+ if (!botState || typeof botState !== 'object' || Array.isArray(botState))
203
+ return null;
204
+ const latestClosed = this.latestClosedBucketStartMs(intervalSeconds, nowMs);
205
+ if (latestClosed === null)
206
+ return null;
207
+ const previousClosedCandleTs = Number(botState.lastClosedCandleTs || 0);
208
+ // No consumed marker yet (fresh state / cleared state): the full
209
+ // cycle must run — bootstrap and warmup checks live there.
210
+ if (!Number.isFinite(previousClosedCandleTs) || previousClosedCandleTs <= 0)
211
+ return null;
212
+ if (latestClosed === previousClosedCandleTs) {
213
+ return { latestClosedBucketStartMs: latestClosed, previousClosedCandleTs };
214
+ }
215
+ return null;
216
+ }
217
+ /**
218
+ * Does the cached candle file belong to a different market source than the
219
+ * bot is configured for?
220
+ *
221
+ * Single source of truth for the reset rule: the off-hour gate
222
+ * (candleFileCoversClosedBucket) and the full path must agree, otherwise a
223
+ * source switch could be skipped off-hour and the cache would keep serving
224
+ * candles from the old source until the next close forced a full run.
225
+ * The pool/book cross-checks matter for legacy caches that predate
226
+ * `meta.marketSource`: a stored pool id alongside a book-configured bot (or
227
+ * a book cache under a pool bot) is just as much a mismatch.
228
+ */
229
+ isCandleSourceMismatch(meta, marketSource) {
230
+ const storedSource = normalizeMarketSource(meta?.marketSource);
231
+ const hasStoredPoolContext = meta?.pool != null && String(meta.pool).trim() !== '';
232
+ return (!!storedSource && storedSource !== marketSource)
233
+ || (marketSource === 'book' && hasStoredPoolContext)
234
+ || (marketSource === 'pool' && storedSource === 'book');
235
+ }
236
+ /**
237
+ * Does the local candle cache already hold the data for a closed bucket?
238
+ *
239
+ * Second half of the off-hour skip verdict (see
240
+ * shouldSkipBotForClosedCandle): the full cycle repairs history even
241
+ * without a new close (Kibana backfill, gap fill), so skipping is only
242
+ * safe when the cache is healthy for that bucket. False whenever
243
+ * anything needs repair: a source switch, unresolved gaps, an empty or
244
+ * short file (fewer candles than the AMA warmup target — the exact case
245
+ * the backfill path exists for), or a newest candle that predates the
246
+ * bucket.
247
+ *
248
+ * The state-side mirror of the standing conditions (unresolved gaps, warmup
249
+ * shortfall) is evaluateStateRepairVeto above; keep the two in step.
250
+ */
251
+ candleFileCoversClosedBucket(candles, meta, marketSource, closedBucketStartMs, requiredCount = 0) {
252
+ if (!Number.isFinite(closedBucketStartMs) || closedBucketStartMs <= 0)
253
+ return false;
254
+ if (this.isCandleSourceMismatch(meta, marketSource))
255
+ return false;
256
+ if (Number(meta?.unresolvedGapCount) > 0)
257
+ return false;
258
+ if (!Array.isArray(candles) || candles.length === 0)
259
+ return false;
260
+ // Short history means the warmup/backfill path still has work to do.
261
+ const required = Number(requiredCount);
262
+ if (Number.isFinite(required) && required > 0 && candles.length < required)
263
+ return false;
264
+ const newestTs = Number(candles[candles.length - 1]?.[0]);
265
+ if (!Number.isFinite(newestTs))
266
+ return false;
267
+ return newestTs >= closedBucketStartMs;
268
+ }
133
269
  selectClosedCandles(candles, intervalSeconds, nowMs = this.getNowMs()) {
134
- const bucketMs = Number(intervalSeconds) * 1000;
135
- if (!Number.isFinite(bucketMs) || bucketMs <= 0) {
270
+ const currentBucketStart = bucketStartMs(nowMs, intervalSeconds);
271
+ if (currentBucketStart === null) {
136
272
  return {
137
273
  closedCandles: Array.isArray(candles) ? candles.slice() : [],
138
274
  currentBucketStartMs: null,
139
275
  };
140
276
  }
141
- const currentBucketStartMs = Math.floor(Number(nowMs) / bucketMs) * bucketMs;
142
277
  const closedCandles = (Array.isArray(candles) ? candles : [])
143
- .filter((c) => Array.isArray(c) && Number.isFinite(c[0]) && c[0] < currentBucketStartMs);
144
- return { closedCandles, currentBucketStartMs };
278
+ .filter((c) => Array.isArray(c) && Number.isFinite(c[0]) && c[0] < currentBucketStart);
279
+ return { closedCandles, currentBucketStartMs: currentBucketStart };
145
280
  }
146
281
  buildBotContextSignature(bot) {
147
282
  return [
@@ -500,11 +635,23 @@ class MarketAdapterService {
500
635
  const currentSlopePct = Number(currentAmaSlope?.slopePct);
501
636
  const previousSlopePct = Number(previousAmaSlope?.slopePct);
502
637
  const currentReady = !!currentAmaSlope?.isReady && Number.isFinite(currentSlopePct);
503
- const previousReady = !!previousAmaSlope && Number.isFinite(previousSlopePct);
638
+ // A not-ready snapshot (`isReady:false`, slopePct 0) is a truthy object
639
+ // that can be persisted as the reset baseline before AMA warmup. Treat
640
+ // it as "no baseline" so its phantom 0 %/bar cannot later trip the
641
+ // slope trigger on the first real slope. Legacy snapshots without an
642
+ // `isReady` field still count as ready.
643
+ const previousReady = !!previousAmaSlope
644
+ && previousAmaSlope.isReady !== false
645
+ && Number.isFinite(previousSlopePct);
504
646
  const deltaPercent = currentReady && previousReady
505
647
  ? Math.abs(currentSlopePct - previousSlopePct)
506
648
  : null;
507
- const thresholdCrossed = Number.isFinite(deltaPercent) && deltaPercent >= thresholdPercent;
649
+ // A non-positive threshold means the slope trigger is DISABLED, not
650
+ // "fire on any delta": `deltaPercent >= 0` would otherwise reset the
651
+ // grid every cycle whenever the factor/maxSlopePct config is missing.
652
+ const thresholdCrossed = Number.isFinite(deltaPercent)
653
+ && thresholdPercent > 0
654
+ && deltaPercent >= thresholdPercent;
508
655
  return {
509
656
  thresholdPercent,
510
657
  currentSlopePct: Number.isFinite(currentSlopePct) ? currentSlopePct : null,
@@ -615,6 +762,12 @@ class MarketAdapterService {
615
762
  regimeTable: cfg.regimeTable,
616
763
  hurstZoneBand: cfg.hurstZoneBand,
617
764
  peNodes: cfg.peNodes,
765
+ // Stable per-market key: lets the gate resume from the previous
766
+ // cycle's analyzer state instead of replaying the whole history.
767
+ // The gate still recomputes from scratch whenever the cached
768
+ // closes are not a prefix of the incoming window (gap repair,
769
+ // rewritten bar, shortened window) or a parameter changed.
770
+ cacheKey: `${bot?.botKey ?? 'bot'}:${cfg.intervalSeconds}`,
618
771
  });
619
772
  regimeMultiplier = regimeResult.isReady && Math.abs(regimeResult.multiplier - 1.0) >= absoluteThreshold
620
773
  ? regimeResult.multiplier
@@ -931,17 +1084,84 @@ class MarketAdapterService {
931
1084
  });
932
1085
  }
933
1086
  const botAma = deps.resolveAmaForBot(bot, ctx, cfg);
1087
+ // `botAma.enabled` is a derived invariant (always true): `gridPrice` is
1088
+ // the single switch that makes a bot AMA-driven, and
1089
+ // usesAmaGridPrice(bot) below is what actually gates AMA work for this
1090
+ // bot. This guard stays only so a future resolver that can fail to
1091
+ // resolve an AMA config cannot silently trade on a missing one.
934
1092
  if (!botAma.enabled) {
935
1093
  return { ok: false, reason: 'ama disabled' };
936
1094
  }
937
1095
  const lookbackBars = normalizeAmaSlopeLookbackBars(cfg.amaSlope?.lookbackBars);
938
1096
  const filePath = deps.candleFileForBot(bot.botKey, cfg.intervalSeconds);
939
- const existing = deps.loadJson(filePath, null);
1097
+ // mtime-validated read cache: the previous cycle serialized this very
1098
+ // file, so re-parsing ~250 KiB of JSON per bot per hour is pure waste.
1099
+ // The cache decides on the file's stat alone — an unstattable file (or a
1100
+ // storage adapter that reports no mtime) is never served from the cache
1101
+ // and always goes through the loader, so it can never serve stale data.
1102
+ // Injecting deps.loadJson does not change that decision; it only changes
1103
+ // what a cache miss parses.
1104
+ const existing = readCachedJson(filePath, () => deps.loadJson(filePath, null));
940
1105
  const existingMeta = existing?.meta && typeof existing.meta === 'object' ? existing.meta : {};
941
1106
  let existingCandles = Array.isArray(existing?.candles) ? existing.candles : [];
942
- const existingMarketSource = normalizeMarketSource(existingMeta.marketSource);
943
1107
  const marketSource = resolveMarketSourceForBot(bot) || 'pool';
944
1108
  const isBookSource = marketSource === 'book';
1109
+ // Retention targets, derived from the bot's own AMA parameters. Pure and
1110
+ // local, so they are computed before the off-hour gate below (which
1111
+ // needs the warmup target) and reused by the full path unchanged.
1112
+ const amaWarmupBars = getAmaWarmupBars(botAma.erPeriod, botAma.slowPeriod, lookbackBars, botAma.fastPeriod, botAma.erSmoothPeriod ?? 0);
1113
+ const analysisKeepCount = amaWarmupBars + 1;
1114
+ // Retain one extra raw candle so the closed-candle analysis window still keeps a
1115
+ // full warmup/history set when the newest bucket is the current in-progress bar.
1116
+ const rawKeepCount = analysisKeepCount + 1;
1117
+ // Off-hour skip: the newest closed 1h bucket is already consumed, so
1118
+ // this bot cannot produce a new AMA, trigger, or snapshot this cycle.
1119
+ // Skip BEFORE the stale-tail Kibana verification and the native
1120
+ // overlap fetch below — on a mid-hour restart those are pure waste
1121
+ // (a per-bot RPC fetch, a Kibana round trip, and a ~250 KiB candle
1122
+ // re-serialize) for zero new information. Every input is already
1123
+ // local: persisted state, the candle file we just read, and the wall
1124
+ // clock. Note the chain connection itself is NOT saved here — the
1125
+ // daemon already opened it before runOnce; that socket is closed right
1126
+ // after the cycle, and the startup sleep is what avoids opening one.
1127
+ //
1128
+ // The local candle file is part of the verdict on purpose. The full
1129
+ // cycle also repairs history (Kibana backfill, gap fill) even when no
1130
+ // new candle closed, so a bot whose cache does not yet COVER the
1131
+ // newest closed bucket — short history, unresolved gaps, a source
1132
+ // change — must still run. Only a bot that has demonstrably consumed
1133
+ // that bucket and holds the data for it is skipped.
1134
+ const persistedBotState = (state?.bots && typeof state.bots === 'object')
1135
+ ? state.bots[bot.botKey]
1136
+ : null;
1137
+ const offHourSkip = this.shouldSkipBotForClosedCandle(bot, persistedBotState, cfg.intervalSeconds, undefined, cfg);
1138
+ const offHourSkipCovered = !!offHourSkip && this.candleFileCoversClosedBucket(existingCandles, existingMeta, marketSource, offHourSkip.latestClosedBucketStartMs, rawKeepCount);
1139
+ if (offHourSkip && offHourSkipCovered) {
1140
+ const skipNowIso = new Date().toISOString();
1141
+ const skipThreshold = typeof deps.calculateBotThreshold === 'function'
1142
+ ? deps.calculateBotThreshold(cfg)
1143
+ : null;
1144
+ const skippedState = {
1145
+ ...(persistedBotState && typeof persistedBotState === 'object' ? persistedBotState : {}),
1146
+ botName: bot.name,
1147
+ botKey: bot.botKey,
1148
+ lastCycleSource: 'off-hour-skip',
1149
+ lastCycleAt: skipNowIso,
1150
+ pendingClosedCandle: true,
1151
+ lastTriggerSuppressedReason: 'waiting_for_new_closed_candle',
1152
+ };
1153
+ state.bots[bot.botKey] = skippedState;
1154
+ return this.buildDefaultResult(bot, {
1155
+ dryRunMessages,
1156
+ source: 'off-hour-skip',
1157
+ thresholdPercent: skipThreshold,
1158
+ triggerSuppressedReason: 'waiting_for_new_closed_candle',
1159
+ lastCandleTs: persistedBotState?.lastCandleTs ?? null,
1160
+ rawLastCandleTs: persistedBotState?.rawLastCandleTs ?? null,
1161
+ lastClosedCandleTs: offHourSkip.previousClosedCandleTs || null,
1162
+ pendingClosedCandle: true,
1163
+ });
1164
+ }
945
1165
  const kibanaRequestTimeoutMs = Number.isFinite(cfg.kibanaRequestTimeoutMs) && cfg.kibanaRequestTimeoutMs > 0
946
1166
  ? cfg.kibanaRequestTimeoutMs
947
1167
  : MARKET_ADAPTER.KIBANA_REQUEST_TIMEOUT_MS;
@@ -1043,10 +1263,7 @@ class MarketAdapterService {
1043
1263
  existingCandles = verified.candles;
1044
1264
  applyStaleTailVerificationMeta(verified);
1045
1265
  }
1046
- const hasStoredPoolContext = existingMeta.pool != null && String(existingMeta.pool).trim() !== '';
1047
- const sourceMismatch = (existingMarketSource && existingMarketSource !== marketSource)
1048
- || (marketSource === 'book' && hasStoredPoolContext)
1049
- || (marketSource === 'pool' && existingMarketSource === 'book');
1266
+ const sourceMismatch = this.isCandleSourceMismatch(existingMeta, marketSource);
1050
1267
  if (sourceMismatch) {
1051
1268
  existingCandles = [];
1052
1269
  existingMeta.nativeRecentTradeSequences = [];
@@ -1055,11 +1272,6 @@ class MarketAdapterService {
1055
1272
  existingMeta.staleTailVerifiedEndTs = null;
1056
1273
  }
1057
1274
  const needBootstrap = existingCandles.length === 0;
1058
- const amaWarmupBars = getAmaWarmupBars(botAma.erPeriod, botAma.slowPeriod, lookbackBars, botAma.fastPeriod, botAma.erSmoothPeriod ?? 0);
1059
- const analysisKeepCount = amaWarmupBars + 1;
1060
- // Retain one extra raw candle so the closed-candle analysis window still keeps a
1061
- // full warmup/history set when the newest bucket is the current in-progress bar.
1062
- const rawKeepCount = analysisKeepCount + 1;
1063
1275
  const nowIso = new Date().toISOString();
1064
1276
  const botThreshold = deps.calculateBotThreshold(cfg);
1065
1277
  if (!Number.isFinite(botThreshold) || botThreshold <= 0) {
@@ -1710,6 +1922,9 @@ class MarketAdapterService {
1710
1922
  candles: nextCandles,
1711
1923
  };
1712
1924
  deps.saveJson(filePath, candlePayload);
1925
+ // The object just serialized IS the file's content now, so the next
1926
+ // cycle's read can skip the parse.
1927
+ noteJsonWritten(filePath, candlePayload);
1713
1928
  if (!hasNewClosedCandle) {
1714
1929
  const { staleData, staleAgeHours } = deps.computeCandleStaleness(lastClosedCandleTs, cfg.maxStaleHours);
1715
1930
  const pendingClosedCandle = !staleData;
@@ -1856,7 +2071,11 @@ class MarketAdapterService {
1856
2071
  const amaSlopeThresholdPercent = amaSlopeResetDetails.thresholdPercent;
1857
2072
  // 4. Advisory collateral-ratio hint only; execution is owned by the debt runtime.
1858
2073
  const collateralRecommendation = canExposeDynamicWeights ? adjustCollateralRatio(slopeResult, 1.5, 2.0) : null;
1859
- const amaComparison = deps.calcAmaComparison(analysisCandles, bot, ctx);
2074
+ // Reports the single AMA this bot trades on (its own resolved
2075
+ // parameters, value already computed above as `amaPrice`). No extra
2076
+ // calculateAMA pass: the AMA1..AMA4 preset sweep this replaced fed
2077
+ // nothing but a log line.
2078
+ const amaComparison = deps.buildAmaRecord(botAma, amaPrice);
1860
2079
  const closedCandleTs = lastCandle[0] || null;
1861
2080
  const { staleData, staleAgeHours } = deps.computeCandleStaleness(closedCandleTs, cfg.maxStaleHours);
1862
2081
  const referencePrice = amaPrice;
@@ -2309,5 +2528,5 @@ class MarketAdapterService {
2309
2528
  };
2310
2529
  }
2311
2530
  }
2312
- export { MarketAdapterService, AMA_SLOPE_PERCENT_MODE_PER_BAR, normalizeAmaSlopePercentMode, convertSlopePercentToPerBar };
2531
+ export { MarketAdapterService, AMA_SLOPE_PERCENT_MODE_PER_BAR, normalizeAmaSlopePercentMode, convertSlopePercentToPerBar, evaluateStateRepairVeto };
2313
2532
  //# sourceMappingURL=market_adapter_service.js.map
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Compute R/S (rescaled range) over `returns[from..to)` (to exclusive).
3
+ * Taking a range instead of a slice keeps the caller's buffer reusable.
4
+ */
5
+ declare function computeRS(returns: ArrayLike<number>, from: number, to: number): number;
1
6
  /**
2
7
  * Shared Hurst zone classification used by both HurstAnalyzer.getAnalysis()
3
8
  * and the regime gate, so the zone boundaries live in exactly one place.
@@ -10,8 +15,12 @@ declare function classifyHurst(h: number, band?: number): {
10
15
  declare class HurstAnalyzer {
11
16
  private _w;
12
17
  window: number;
18
+ /** Bars of history this analyzer's state depends on (see bufferBars use in the regime gate). */
19
+ bufferBars: number;
13
20
  scales: number[];
14
21
  private _prices;
22
+ private _returns;
23
+ private _priceCount;
15
24
  private _updateCount;
16
25
  hurst: number;
17
26
  isReady: boolean;
@@ -44,5 +53,5 @@ declare class HurstAnalyzer {
44
53
  updateCount: number;
45
54
  };
46
55
  }
47
- export { HurstAnalyzer, classifyHurst };
56
+ export { HurstAnalyzer, classifyHurst, computeRS };
48
57
  //# sourceMappingURL=hurst_analyzer.d.ts.map