dexbot 1.4.21 → 1.4.23

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 (601) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +8 -5
  3. package/analysis/ama_fitting/analyze_ama_price_changes.ts +7 -3
  4. package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +6 -6
  5. package/analysis/ama_fitting/calibrate_convergence_er.ts +7 -5
  6. package/analysis/ama_fitting/fetch_lp_candles.ts +8 -3
  7. package/analysis/ama_fitting/generate_unified_comparison_chart.ts +30 -67
  8. package/analysis/ama_fitting/optimizer_high_resolution.ts +26 -17
  9. package/analysis/ama_fitting/package.json +1 -1
  10. package/analysis/analyze_derivatives.ts +4 -4
  11. package/analysis/analyze_dynamic_weight.ts +21 -5
  12. package/analysis/analyze_kalman.ts +54 -25
  13. package/analysis/analyze_regime.ts +2 -2
  14. package/analysis/analyze_regime_windows.ts +27 -19
  15. package/analysis/analyze_risk_profile.ts +3 -3
  16. package/analysis/analyze_trade_heatmap.ts +3 -3
  17. package/analysis/analyze_volatility.ts +2 -2
  18. package/analysis/bot_fitting/README.md +93 -19
  19. package/analysis/bot_fitting/backtest_ama_sweep.ts +316 -199
  20. package/analysis/bot_fitting/backtest_bot_fitting.ts +520 -85
  21. package/analysis/bot_fitting/shared_utils.ts +15 -9
  22. package/analysis/bot_key_utils.ts +13 -6
  23. package/analysis/bot_usage/discover_bot_accounts.ts +5 -3
  24. package/analysis/bot_usage/kibana_bot_queries.ts +1 -1
  25. package/analysis/chart_css.ts +6 -4
  26. package/analysis/chart_ui.ts +0 -1
  27. package/analysis/chart_utils.ts +11 -2
  28. package/analysis/derivative_chart_generator.ts +2 -2
  29. package/analysis/price_sources.ts +8 -2
  30. package/analysis/resolve_source.ts +1 -1
  31. package/analysis/trade_profitability.ts +61 -28
  32. package/analysis/tradingview/README.md +24 -4
  33. package/analysis/tradingview/analyze_tradingview.ts +1 -1
  34. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +356 -86
  35. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
  36. package/analysis/trend_detection/derivative_analyzer.ts +12 -3
  37. package/analysis/trend_detection/dynamic_weight_chart_generator.ts +25 -27
  38. package/analysis/trend_detection/hurst_analyzer.ts +1 -1
  39. package/analysis/trend_detection/kalman_chart_generator.ts +42 -14
  40. package/analysis/trend_detection/package.json +1 -1
  41. package/analysis/trend_detection/regime_chart_generator.ts +39 -19
  42. package/analysis/trend_detection/tests/test_kalman_trend.ts +1 -1
  43. package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +1 -1
  44. package/analysis/trend_detection/volatility_chart_generator.ts +1 -1
  45. package/claw/index.ts +1 -1
  46. package/claw/modules/claw_bridge.ts +3 -3
  47. package/claw/modules/claw_catalog.ts +1 -1
  48. package/claw/modules/claw_launcher.ts +1 -1
  49. package/claw/modules/claw_skill_md.ts +7 -10
  50. package/claw/modules/credit_runtime_adapter.ts +1 -1
  51. package/claw/modules/decision_loop.ts +5 -9
  52. package/claw/modules/dexbot_bridge.ts +7 -7
  53. package/claw/modules/feed_price_source.ts +1 -1
  54. package/claw/modules/kibana_price_source.ts +1 -1
  55. package/claw/modules/launcher_mode_detector.ts +1 -1
  56. package/claw/modules/launcher_paths.ts +1 -1
  57. package/claw/modules/position_discovery.ts +1 -1
  58. package/claw/modules/position_health.ts +1 -1
  59. package/claw/package.json +3 -3
  60. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  61. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  62. package/claw/skills/launcher-ops/references/launcher-workflow.md +2 -2
  63. package/claw/tests/package.json +1 -1
  64. package/claw/tests/test_claw_bridge.ts +45 -21
  65. package/claw/tests/test_claw_catalog_and_credentials.ts +8 -4
  66. package/claw/tests/test_claw_chain_layer.ts +39 -19
  67. package/claw/tests/test_claw_data_flow.ts +28 -20
  68. package/claw/tests/test_claw_domain_logic.ts +25 -19
  69. package/claw/tests/test_claw_manifest_and_matrix.ts +23 -3
  70. package/claw/tests/test_claw_mcp_transport.ts +13 -8
  71. package/claw/tests/test_claw_regressions.ts +254 -128
  72. package/claw/tests/test_claw_skill_generation.ts +1 -1
  73. package/claw/tests/test_nullclaw_tmp_integration.ts +2 -3
  74. package/claw/tests/test_position_health.ts +1 -77
  75. package/claw/tests/test_position_manager.ts +20 -18
  76. package/claw/tests/test_position_manager_watch_health.ts +39 -43
  77. package/claw/tests/test_short_mpa_strategy.ts +20 -17
  78. package/claw/tsconfig.json +4 -3
  79. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +7 -3
  80. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +1 -1
  81. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +6 -6
  82. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -1
  83. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +7 -5
  84. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -1
  85. package/dist/analysis/ama_fitting/fetch_lp_candles.js +8 -3
  86. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -1
  87. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +2 -2
  88. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +1 -1
  89. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +31 -75
  90. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +1 -1
  91. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -1
  92. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +25 -17
  93. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -1
  94. package/dist/analysis/analyze_derivatives.d.ts +0 -18
  95. package/dist/analysis/analyze_derivatives.d.ts.map +1 -1
  96. package/dist/analysis/analyze_derivatives.js +4 -4
  97. package/dist/analysis/analyze_derivatives.js.map +1 -1
  98. package/dist/analysis/analyze_dynamic_weight.d.ts +0 -11
  99. package/dist/analysis/analyze_dynamic_weight.d.ts.map +1 -1
  100. package/dist/analysis/analyze_dynamic_weight.js +19 -5
  101. package/dist/analysis/analyze_dynamic_weight.js.map +1 -1
  102. package/dist/analysis/analyze_kalman.d.ts +0 -10
  103. package/dist/analysis/analyze_kalman.d.ts.map +1 -1
  104. package/dist/analysis/analyze_kalman.js +51 -26
  105. package/dist/analysis/analyze_kalman.js.map +1 -1
  106. package/dist/analysis/analyze_regime.d.ts +0 -17
  107. package/dist/analysis/analyze_regime.d.ts.map +1 -1
  108. package/dist/analysis/analyze_regime.js +2 -2
  109. package/dist/analysis/analyze_regime.js.map +1 -1
  110. package/dist/analysis/analyze_regime_windows.d.ts +0 -16
  111. package/dist/analysis/analyze_regime_windows.d.ts.map +1 -1
  112. package/dist/analysis/analyze_regime_windows.js +28 -21
  113. package/dist/analysis/analyze_regime_windows.js.map +1 -1
  114. package/dist/analysis/analyze_risk_profile.js +3 -3
  115. package/dist/analysis/analyze_risk_profile.js.map +1 -1
  116. package/dist/analysis/analyze_trade_heatmap.js +3 -3
  117. package/dist/analysis/analyze_trade_heatmap.js.map +1 -1
  118. package/dist/analysis/analyze_volatility.d.ts +0 -19
  119. package/dist/analysis/analyze_volatility.d.ts.map +1 -1
  120. package/dist/analysis/analyze_volatility.js +2 -2
  121. package/dist/analysis/analyze_volatility.js.map +1 -1
  122. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +30 -14
  123. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -1
  124. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +330 -193
  125. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -1
  126. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +136 -1
  127. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +1 -1
  128. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +527 -83
  129. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -1
  130. package/dist/analysis/bot_fitting/shared_utils.d.ts +1 -1
  131. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -1
  132. package/dist/analysis/bot_fitting/shared_utils.js +14 -8
  133. package/dist/analysis/bot_fitting/shared_utils.js.map +1 -1
  134. package/dist/analysis/bot_key_utils.d.ts.map +1 -1
  135. package/dist/analysis/bot_key_utils.js +13 -6
  136. package/dist/analysis/bot_key_utils.js.map +1 -1
  137. package/dist/analysis/bot_usage/discover_bot_accounts.js +5 -3
  138. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -1
  139. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -1
  140. package/dist/analysis/bot_usage/kibana_bot_queries.js +1 -1
  141. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -1
  142. package/dist/analysis/chart_css.d.ts +3 -1
  143. package/dist/analysis/chart_css.d.ts.map +1 -1
  144. package/dist/analysis/chart_css.js +6 -3
  145. package/dist/analysis/chart_css.js.map +1 -1
  146. package/dist/analysis/chart_ui.d.ts.map +1 -1
  147. package/dist/analysis/chart_ui.js.map +1 -1
  148. package/dist/analysis/chart_utils.d.ts.map +1 -1
  149. package/dist/analysis/chart_utils.js +15 -2
  150. package/dist/analysis/chart_utils.js.map +1 -1
  151. package/dist/analysis/derivative_chart_generator.js +2 -2
  152. package/dist/analysis/derivative_chart_generator.js.map +1 -1
  153. package/dist/analysis/price_sources.d.ts +1 -0
  154. package/dist/analysis/price_sources.d.ts.map +1 -1
  155. package/dist/analysis/price_sources.js +8 -2
  156. package/dist/analysis/price_sources.js.map +1 -1
  157. package/dist/analysis/resolve_source.d.ts.map +1 -1
  158. package/dist/analysis/resolve_source.js +1 -1
  159. package/dist/analysis/resolve_source.js.map +1 -1
  160. package/dist/analysis/trade_profitability.d.ts.map +1 -1
  161. package/dist/analysis/trade_profitability.js +58 -29
  162. package/dist/analysis/trade_profitability.js.map +1 -1
  163. package/dist/analysis/tradingview/analyze_tradingview.js +1 -1
  164. package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -1
  165. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
  166. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +356 -86
  167. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
  168. package/dist/analysis/trend_detection/derivative_analyzer.d.ts +1 -0
  169. package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +1 -1
  170. package/dist/analysis/trend_detection/derivative_analyzer.js +12 -3
  171. package/dist/analysis/trend_detection/derivative_analyzer.js.map +1 -1
  172. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -1
  173. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +26 -27
  174. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -1
  175. package/dist/analysis/trend_detection/hurst_analyzer.d.ts +1 -1
  176. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -1
  177. package/dist/analysis/trend_detection/hurst_analyzer.js +1 -1
  178. package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
  179. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -1
  180. package/dist/analysis/trend_detection/kalman_chart_generator.js +41 -13
  181. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -1
  182. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -1
  183. package/dist/analysis/trend_detection/regime_chart_generator.js +38 -19
  184. package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -1
  185. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +1 -1
  186. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +1 -1
  187. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +1 -1
  188. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +1 -1
  189. package/dist/analysis/trend_detection/volatility_chart_generator.js +1 -1
  190. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -1
  191. package/dist/bot.js +1 -1
  192. package/dist/bot.js.map +1 -1
  193. package/dist/credential-daemon.d.ts +1 -1
  194. package/dist/credential-daemon.js +1 -1
  195. package/dist/dexbot.d.ts.map +1 -1
  196. package/dist/dexbot.js +7 -8
  197. package/dist/dexbot.js.map +1 -1
  198. package/dist/market_adapter/ama_signal_runner.js +3 -1
  199. package/dist/market_adapter/ama_signal_runner.js.map +1 -1
  200. package/dist/market_adapter/candle_utils.d.ts +1 -3
  201. package/dist/market_adapter/candle_utils.d.ts.map +1 -1
  202. package/dist/market_adapter/candle_utils.js +1 -11
  203. package/dist/market_adapter/candle_utils.js.map +1 -1
  204. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -1
  205. package/dist/market_adapter/core/asymmetric_bounds.js +33 -30
  206. package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
  207. package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -1
  208. package/dist/market_adapter/core/config_normalizers.js +10 -1
  209. package/dist/market_adapter/core/config_normalizers.js.map +1 -1
  210. package/dist/market_adapter/core/kibana_candles.d.ts +18 -42
  211. package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -1
  212. package/dist/market_adapter/core/kibana_candles.js +101 -7
  213. package/dist/market_adapter/core/kibana_candles.js.map +1 -1
  214. package/dist/market_adapter/core/kibana_client.d.ts +0 -14
  215. package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
  216. package/dist/market_adapter/core/kibana_client.js +39 -6
  217. package/dist/market_adapter/core/kibana_client.js.map +1 -1
  218. package/dist/market_adapter/core/kibana_market_candles.d.ts +0 -27
  219. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -1
  220. package/dist/market_adapter/core/kibana_market_candles.js +1 -1
  221. package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
  222. package/dist/market_adapter/core/market_adapter_service.d.ts +21 -11
  223. package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
  224. package/dist/market_adapter/core/market_adapter_service.js +95 -37
  225. package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
  226. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +10 -1
  227. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +1 -1
  228. package/dist/market_adapter/core/signals/hurst_analyzer.js +28 -17
  229. package/dist/market_adapter/core/signals/hurst_analyzer.js.map +1 -1
  230. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts +5 -0
  231. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +1 -1
  232. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js +24 -24
  233. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +1 -1
  234. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +1 -1
  235. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js +5 -1
  236. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +1 -1
  237. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +1 -1
  238. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +20 -3
  239. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +1 -1
  240. package/dist/market_adapter/core/strategies/ama.js +1 -1
  241. package/dist/market_adapter/core/strategies/ama.js.map +1 -1
  242. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +2 -2
  243. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -1
  244. package/dist/market_adapter/core/strategies/ama_slope_model.js +16 -4
  245. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
  246. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +4 -3
  247. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -1
  248. package/dist/market_adapter/core/strategies/atr/calculator.js +16 -8
  249. package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
  250. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -1
  251. package/dist/market_adapter/core/strategies/collateral_manager.js +8 -3
  252. package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
  253. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +40 -1
  254. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +1 -1
  255. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +116 -2
  256. package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +1 -1
  257. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
  258. package/dist/market_adapter/core/strategies/regime_gate.js +26 -20
  259. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
  260. package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +1 -1
  261. package/dist/market_adapter/core/strategies/volatility_shift.js +3 -0
  262. package/dist/market_adapter/core/strategies/volatility_shift.js.map +1 -1
  263. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +69 -55
  264. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
  265. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +0 -26
  266. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
  267. package/dist/market_adapter/inputs/fetch_lp_data.js +67 -14
  268. package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
  269. package/dist/market_adapter/inputs/kibana_source.d.ts +4 -28
  270. package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
  271. package/dist/market_adapter/inputs/kibana_source.js +5 -2
  272. package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
  273. package/dist/market_adapter/lp_chart_core.js +1 -1
  274. package/dist/market_adapter/lp_chart_core.js.map +1 -1
  275. package/dist/market_adapter/lp_chart_runner.d.ts +10 -1
  276. package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
  277. package/dist/market_adapter/lp_chart_runner.js +2 -2
  278. package/dist/market_adapter/lp_chart_runner.js.map +1 -1
  279. package/dist/market_adapter/lp_chart_strategy_loader.js +1 -1
  280. package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
  281. package/dist/market_adapter/market_adapter.d.ts +1 -2
  282. package/dist/market_adapter/market_adapter.d.ts.map +1 -1
  283. package/dist/market_adapter/market_adapter.js +9 -8
  284. package/dist/market_adapter/market_adapter.js.map +1 -1
  285. package/dist/market_adapter/test_helpers.d.ts +3 -3
  286. package/dist/market_adapter/test_helpers.d.ts.map +1 -1
  287. package/dist/market_adapter/test_helpers.js +3 -3
  288. package/dist/market_adapter/test_helpers.js.map +1 -1
  289. package/dist/market_adapter/utils/adapter_client.js +1 -1
  290. package/dist/market_adapter/utils/adapter_client.js.map +1 -1
  291. package/dist/market_adapter/utils/atomic_write.js +1 -1
  292. package/dist/market_adapter/utils/atomic_write.js.map +1 -1
  293. package/dist/market_adapter/utils/chain.d.ts +0 -2
  294. package/dist/market_adapter/utils/chain.d.ts.map +1 -1
  295. package/dist/market_adapter/utils/chain.js +2 -3
  296. package/dist/market_adapter/utils/chain.js.map +1 -1
  297. package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -1
  298. package/dist/market_adapter/utils/data_discovery.js +24 -8
  299. package/dist/market_adapter/utils/data_discovery.js.map +1 -1
  300. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
  301. package/dist/market_adapter/utils/dynamic_grid_snapshot.js +2 -5
  302. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
  303. package/dist/market_adapter/utils/file_lock.d.ts +4 -1
  304. package/dist/market_adapter/utils/file_lock.d.ts.map +1 -1
  305. package/dist/market_adapter/utils/file_lock.js +89 -25
  306. package/dist/market_adapter/utils/file_lock.js.map +1 -1
  307. package/dist/market_adapter/utils/native_history.d.ts.map +1 -1
  308. package/dist/market_adapter/utils/native_history.js +5 -1
  309. package/dist/market_adapter/utils/native_history.js.map +1 -1
  310. package/dist/modules/account_bots.d.ts.map +1 -1
  311. package/dist/modules/account_bots.js +47 -12
  312. package/dist/modules/account_bots.js.map +1 -1
  313. package/dist/modules/authority_resolver.js +1 -1
  314. package/dist/modules/authority_resolver.js.map +1 -1
  315. package/dist/modules/bitshares-native/chain_client.js +1 -1
  316. package/dist/modules/bitshares-native/chain_client.js.map +1 -1
  317. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +0 -12
  318. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -1
  319. package/dist/modules/bitshares-native/crypto/ecc.browser.js +1 -1
  320. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
  321. package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -1
  322. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
  323. package/dist/modules/bitshares-native/index.d.ts.map +1 -1
  324. package/dist/modules/bitshares-native/index.js +1 -1
  325. package/dist/modules/bitshares-native/index.js.map +1 -1
  326. package/dist/modules/bitshares-native/lru_cache.js +1 -1
  327. package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
  328. package/dist/modules/bitshares-native/resolvers.d.ts +0 -2
  329. package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -1
  330. package/dist/modules/bitshares-native/resolvers.js +18 -4
  331. package/dist/modules/bitshares-native/resolvers.js.map +1 -1
  332. package/dist/modules/bitshares-native/serial/chain_constants.js +1 -1
  333. package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
  334. package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
  335. package/dist/modules/bitshares-native/serial/index.js +1 -1
  336. package/dist/modules/bitshares-native/serial/index.js.map +1 -1
  337. package/dist/modules/bitshares-native/serial/operations.js +1 -1
  338. package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
  339. package/dist/modules/bitshares-native/serial/serializer.js +1 -1
  340. package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
  341. package/dist/modules/bitshares-native/serial/types.js +1 -1
  342. package/dist/modules/bitshares-native/serial/types.js.map +1 -1
  343. package/dist/modules/bitshares-native/signing_client.js +2 -2
  344. package/dist/modules/bitshares-native/signing_client.js.map +1 -1
  345. package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
  346. package/dist/modules/bitshares-native/subscriptions.js +5 -14
  347. package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
  348. package/dist/modules/bitshares-native/transport.js +1 -1
  349. package/dist/modules/bitshares-native/transport.js.map +1 -1
  350. package/dist/modules/bitshares-native/tx/builder.js +1 -1
  351. package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
  352. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +3 -2
  353. package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +1 -1
  354. package/dist/modules/bitshares-native/tx/tx_cache.js +7 -4
  355. package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
  356. package/dist/modules/bitshares_client.js +10 -10
  357. package/dist/modules/bitshares_client.js.map +1 -1
  358. package/dist/modules/bot_settings.d.ts.map +1 -1
  359. package/dist/modules/bot_settings.js +11 -18
  360. package/dist/modules/bot_settings.js.map +1 -1
  361. package/dist/modules/bots_file_lock.d.ts +1 -1
  362. package/dist/modules/bots_file_lock.js +1 -1
  363. package/dist/modules/broadcast_failure.d.ts +13 -0
  364. package/dist/modules/broadcast_failure.d.ts.map +1 -1
  365. package/dist/modules/broadcast_failure.js +0 -13
  366. package/dist/modules/broadcast_failure.js.map +1 -1
  367. package/dist/modules/chain_orders.d.ts.map +1 -1
  368. package/dist/modules/chain_orders.js +15 -17
  369. package/dist/modules/chain_orders.js.map +1 -1
  370. package/dist/modules/config.js +1 -1
  371. package/dist/modules/config.js.map +1 -1
  372. package/dist/modules/constants.d.ts +21 -20
  373. package/dist/modules/constants.d.ts.map +1 -1
  374. package/dist/modules/constants.js +60 -63
  375. package/dist/modules/constants.js.map +1 -1
  376. package/dist/modules/cr_planner.d.ts +1 -7
  377. package/dist/modules/cr_planner.d.ts.map +1 -1
  378. package/dist/modules/cr_planner.js +3 -77
  379. package/dist/modules/cr_planner.js.map +1 -1
  380. package/dist/modules/credential_policy.d.ts +0 -4
  381. package/dist/modules/credential_policy.d.ts.map +1 -1
  382. package/dist/modules/credential_policy.js +17 -2
  383. package/dist/modules/credential_policy.js.map +1 -1
  384. package/dist/modules/credit_runtime.d.ts +0 -7
  385. package/dist/modules/credit_runtime.d.ts.map +1 -1
  386. package/dist/modules/credit_runtime.js +21 -60
  387. package/dist/modules/credit_runtime.js.map +1 -1
  388. package/dist/modules/crypto/index.d.ts +0 -2
  389. package/dist/modules/crypto/index.d.ts.map +1 -1
  390. package/dist/modules/crypto/index.js +0 -2
  391. package/dist/modules/crypto/index.js.map +1 -1
  392. package/dist/modules/crypto/sync.js.map +1 -1
  393. package/dist/modules/daemon_node_health.js +1 -1
  394. package/dist/modules/daemon_node_health.js.map +1 -1
  395. package/dist/modules/dexbot_class.d.ts +8 -134
  396. package/dist/modules/dexbot_class.d.ts.map +1 -1
  397. package/dist/modules/dexbot_class.js +36 -197
  398. package/dist/modules/dexbot_class.js.map +1 -1
  399. package/dist/modules/dexbot_credential_client.js +1 -1
  400. package/dist/modules/dexbot_credential_client.js.map +1 -1
  401. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
  402. package/dist/modules/dexbot_fill_runtime.js +3 -6
  403. package/dist/modules/dexbot_fill_runtime.js.map +1 -1
  404. package/dist/modules/dexbot_maintenance_runtime.d.ts +6 -34
  405. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
  406. package/dist/modules/dexbot_maintenance_runtime.js +27 -19
  407. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
  408. package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
  409. package/dist/modules/dexbot_startup_runtime.js +31 -15
  410. package/dist/modules/dexbot_startup_runtime.js.map +1 -1
  411. package/dist/modules/dexbot_state_recovery.d.ts +2 -2
  412. package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
  413. package/dist/modules/dexbot_state_recovery.js +9 -6
  414. package/dist/modules/dexbot_state_recovery.js.map +1 -1
  415. package/dist/modules/fund_registry.d.ts.map +1 -1
  416. package/dist/modules/fund_registry.js +19 -4
  417. package/dist/modules/fund_registry.js.map +1 -1
  418. package/dist/modules/general_settings.d.ts +1 -2
  419. package/dist/modules/general_settings.d.ts.map +1 -1
  420. package/dist/modules/general_settings.js +1 -2
  421. package/dist/modules/general_settings.js.map +1 -1
  422. package/dist/modules/graceful_shutdown.d.ts.map +1 -1
  423. package/dist/modules/graceful_shutdown.js +10 -1
  424. package/dist/modules/graceful_shutdown.js.map +1 -1
  425. package/dist/modules/grid_price_source.d.ts +19 -0
  426. package/dist/modules/grid_price_source.d.ts.map +1 -0
  427. package/dist/modules/grid_price_source.js +23 -0
  428. package/dist/modules/grid_price_source.js.map +1 -0
  429. package/dist/modules/key_store.d.ts +0 -5
  430. package/dist/modules/key_store.d.ts.map +1 -1
  431. package/dist/modules/key_store.js +1 -14
  432. package/dist/modules/key_store.js.map +1 -1
  433. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
  434. package/dist/modules/launcher/bot_supervisor.js +9 -19
  435. package/dist/modules/launcher/bot_supervisor.js.map +1 -1
  436. package/dist/modules/launcher/child_env.d.ts +1 -2
  437. package/dist/modules/launcher/child_env.d.ts.map +1 -1
  438. package/dist/modules/launcher/child_env.js +1 -1
  439. package/dist/modules/launcher/child_env.js.map +1 -1
  440. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
  441. package/dist/modules/launcher/foreign_cred_daemon.js +2 -14
  442. package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
  443. package/dist/modules/launcher/market_adapter_runtime.d.ts +1 -1
  444. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
  445. package/dist/modules/launcher/market_adapter_runtime.js +3 -14
  446. package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
  447. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
  448. package/dist/modules/launcher/market_adapter_watchdog.js +3 -2
  449. package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
  450. package/dist/modules/launcher/monolithic_runtime.d.ts +0 -1
  451. package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
  452. package/dist/modules/launcher/monolithic_runtime.js +3 -18
  453. package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
  454. package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
  455. package/dist/modules/launcher/runtime_entry.js +4 -5
  456. package/dist/modules/launcher/runtime_entry.js.map +1 -1
  457. package/dist/modules/launcher/status_reporting.js +1 -1
  458. package/dist/modules/launcher/status_reporting.js.map +1 -1
  459. package/dist/modules/launcher/supervisor_control.js +1 -1
  460. package/dist/modules/launcher/supervisor_control.js.map +1 -1
  461. package/dist/modules/market_adapter_whitelist.d.ts +2 -2
  462. package/dist/modules/market_adapter_whitelist.d.ts.map +1 -1
  463. package/dist/modules/market_adapter_whitelist.js +12 -6
  464. package/dist/modules/market_adapter_whitelist.js.map +1 -1
  465. package/dist/modules/node_failure_ledger.d.ts +23 -0
  466. package/dist/modules/node_failure_ledger.d.ts.map +1 -1
  467. package/dist/modules/node_failure_ledger.js +0 -23
  468. package/dist/modules/node_failure_ledger.js.map +1 -1
  469. package/dist/modules/node_manager.d.ts.map +1 -1
  470. package/dist/modules/node_manager.js +3 -3
  471. package/dist/modules/node_manager.js.map +1 -1
  472. package/dist/modules/order/accounting.js +1 -1
  473. package/dist/modules/order/accounting.js.map +1 -1
  474. package/dist/modules/order/async_lock.d.ts +6 -0
  475. package/dist/modules/order/async_lock.d.ts.map +1 -1
  476. package/dist/modules/order/async_lock.js +11 -0
  477. package/dist/modules/order/async_lock.js.map +1 -1
  478. package/dist/modules/order/export.d.ts +1 -1
  479. package/dist/modules/order/export.js +10 -10
  480. package/dist/modules/order/export.js.map +1 -1
  481. package/dist/modules/order/format.d.ts +1 -0
  482. package/dist/modules/order/format.d.ts.map +1 -1
  483. package/dist/modules/order/format.js +0 -6
  484. package/dist/modules/order/format.js.map +1 -1
  485. package/dist/modules/order/grid.d.ts +2 -12
  486. package/dist/modules/order/grid.d.ts.map +1 -1
  487. package/dist/modules/order/grid.js +40 -27
  488. package/dist/modules/order/grid.js.map +1 -1
  489. package/dist/modules/order/grid_reconcile.d.ts +1 -1
  490. package/dist/modules/order/grid_reconcile.js +1 -1
  491. package/dist/modules/order/grid_reconcile_internal.js +1 -1
  492. package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
  493. package/dist/modules/order/logger.d.ts +3 -0
  494. package/dist/modules/order/logger.d.ts.map +1 -1
  495. package/dist/modules/order/logger.js +22 -13
  496. package/dist/modules/order/logger.js.map +1 -1
  497. package/dist/modules/order/logger_state.d.ts +4 -9
  498. package/dist/modules/order/logger_state.d.ts.map +1 -1
  499. package/dist/modules/order/logger_state.js +5 -14
  500. package/dist/modules/order/logger_state.js.map +1 -1
  501. package/dist/modules/order/manager.d.ts +1 -4
  502. package/dist/modules/order/manager.d.ts.map +1 -1
  503. package/dist/modules/order/manager.js +34 -33
  504. package/dist/modules/order/manager.js.map +1 -1
  505. package/dist/modules/order/processed_fill_store.d.ts.map +1 -1
  506. package/dist/modules/order/processed_fill_store.js +9 -3
  507. package/dist/modules/order/processed_fill_store.js.map +1 -1
  508. package/dist/modules/order/strategy.d.ts +6 -4
  509. package/dist/modules/order/strategy.d.ts.map +1 -1
  510. package/dist/modules/order/strategy.js +6 -4
  511. package/dist/modules/order/strategy.js.map +1 -1
  512. package/dist/modules/order/sync_engine.js +7 -7
  513. package/dist/modules/order/sync_engine.js.map +1 -1
  514. package/dist/modules/order/utils/math.d.ts +29 -3
  515. package/dist/modules/order/utils/math.d.ts.map +1 -1
  516. package/dist/modules/order/utils/math.js +54 -10
  517. package/dist/modules/order/utils/math.js.map +1 -1
  518. package/dist/modules/order/utils/order.d.ts.map +1 -1
  519. package/dist/modules/order/utils/order.js +14 -2
  520. package/dist/modules/order/utils/order.js.map +1 -1
  521. package/dist/modules/order/utils/system.d.ts +3 -8
  522. package/dist/modules/order/utils/system.d.ts.map +1 -1
  523. package/dist/modules/order/utils/system.js +14 -4
  524. package/dist/modules/order/utils/system.js.map +1 -1
  525. package/dist/modules/order/utils/validate.js +1 -1
  526. package/dist/modules/order/utils/validate.js.map +1 -1
  527. package/dist/modules/path_api.js +1 -1
  528. package/dist/modules/path_api.js.map +1 -1
  529. package/dist/modules/paths.d.ts +1 -7
  530. package/dist/modules/paths.d.ts.map +1 -1
  531. package/dist/modules/paths.js +1 -1
  532. package/dist/modules/paths.js.map +1 -1
  533. package/dist/modules/process_discovery.d.ts +3 -0
  534. package/dist/modules/process_discovery.d.ts.map +1 -1
  535. package/dist/modules/process_discovery.js +15 -1
  536. package/dist/modules/process_discovery.js.map +1 -1
  537. package/dist/modules/runtime_settings.js +1 -1
  538. package/dist/modules/runtime_settings.js.map +1 -1
  539. package/dist/modules/settings_merge.d.ts +5 -1
  540. package/dist/modules/settings_merge.d.ts.map +1 -1
  541. package/dist/modules/settings_merge.js +14 -3
  542. package/dist/modules/settings_merge.js.map +1 -1
  543. package/dist/modules/socket_json_client.d.ts.map +1 -1
  544. package/dist/modules/socket_json_client.js +12 -2
  545. package/dist/modules/socket_json_client.js.map +1 -1
  546. package/dist/modules/storage/browser_adapter.d.ts.map +1 -1
  547. package/dist/modules/storage/browser_adapter.js +5 -3
  548. package/dist/modules/storage/browser_adapter.js.map +1 -1
  549. package/dist/modules/storage/index.d.ts +1 -1
  550. package/dist/modules/storage/index.js +1 -1
  551. package/dist/modules/types.d.ts +1 -1
  552. package/dist/modules/types.d.ts.map +1 -1
  553. package/dist/modules/validate_profiles.d.ts.map +1 -1
  554. package/dist/modules/validate_profiles.js +6 -8
  555. package/dist/modules/validate_profiles.js.map +1 -1
  556. package/dist/pm2.d.ts.map +1 -1
  557. package/dist/pm2.js +2 -3
  558. package/dist/pm2.js.map +1 -1
  559. package/dist/scripts/analyze-git.d.ts +1 -1
  560. package/dist/scripts/analyze-git.js +1 -1
  561. package/dist/scripts/analyze-orders.d.ts.map +1 -1
  562. package/dist/scripts/analyze-orders.js +61 -18
  563. package/dist/scripts/analyze-orders.js.map +1 -1
  564. package/dist/scripts/diagnose-pool-history.js +1 -1
  565. package/dist/scripts/divergence-calc.d.ts +1 -1
  566. package/dist/scripts/divergence-calc.js +3 -3
  567. package/dist/scripts/native_release_gates.js +4 -2
  568. package/dist/scripts/native_release_gates.js.map +1 -1
  569. package/dist/scripts/print_grid.d.ts +1 -1
  570. package/dist/scripts/print_grid.js +1 -1
  571. package/dist/scripts/run-tests.js +38 -19
  572. package/dist/scripts/run-tests.js.map +1 -1
  573. package/dist/scripts/runner.d.ts +3 -5
  574. package/dist/scripts/runner.d.ts.map +1 -1
  575. package/dist/scripts/runner.js +3 -5
  576. package/dist/scripts/runner.js.map +1 -1
  577. package/dist/scripts/sync-version.d.ts +2 -2
  578. package/dist/scripts/sync-version.js +7 -4
  579. package/dist/scripts/sync-version.js.map +1 -1
  580. package/dist/scripts/update.d.ts +1 -1
  581. package/dist/scripts/update.js +1 -1
  582. package/dist/scripts/validate_bots.d.ts +1 -1
  583. package/dist/scripts/validate_bots.js +1 -1
  584. package/dist/scripts/verify-browser-bundle.d.ts +1 -1
  585. package/dist/scripts/verify-browser-bundle.js +1 -1
  586. package/dist/unlock.js +4 -4
  587. package/dist/unlock.js.map +1 -1
  588. package/docs/BITSHARES_ONBOARDING.md +15 -10
  589. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +9 -9
  590. package/docs/DEXBOT_COMPARISON.md +19 -19
  591. package/docs/EVOLUTION.md +18 -44
  592. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  593. package/docs/GRID_RECALCULATION.md +1 -1
  594. package/docs/README.md +3 -3
  595. package/docs/architecture.md +5 -5
  596. package/docs/developer_guide.md +6 -6
  597. package/market_adapter/README.md +13 -8
  598. package/package.json +22 -14
  599. package/scripts/README.md +33 -7
  600. package/scripts/clean-dist.js +10 -2
  601. package/tests/README.md +4 -3
@@ -1,6 +1,6 @@
1
+ 'use strict';
1
2
 
2
3
  import { roundTo } from '../../modules/order/utils/math.js';
3
- 'use strict';
4
4
 
5
5
  /**
6
6
  * Derivative Analyzer
@@ -235,6 +235,10 @@ class DerivativeAnalyzer {
235
235
  rsiBullThreshold: number;
236
236
  rsiBearThreshold: number;
237
237
  macdMinHist: number;
238
+ // Resolved threshold for the MACD-line gates: falls back to the historical
239
+ // 0.02 default only when unset/NaN, so an explicit 0 (strict sign test)
240
+ // stays expressible via the API.
241
+ macdLineGateThreshold: number;
238
242
  fastSmaCommitmentBars: number;
239
243
  trendFilterEnabled: boolean;
240
244
  trendFilterMinBars: number;
@@ -311,6 +315,11 @@ class DerivativeAnalyzer {
311
315
  this.rsiBullThreshold = config.rsiBullThreshold ?? 55;
312
316
  this.rsiBearThreshold = config.rsiBearThreshold ?? 45;
313
317
  this.macdMinHist = config.macdMinHist ?? 0;
318
+ // Unset/NaN → historical 0.02 gate default; explicit 0 → strict sign test.
319
+ // (`this.macdMinHist || 0.02` at the gates made explicit 0 unreachable.)
320
+ this.macdLineGateThreshold = config.macdMinHist != null && Number.isFinite(config.macdMinHist)
321
+ ? config.macdMinHist
322
+ : 0.02;
314
323
  this.fastSmaCommitmentBars = config.fastSmaCommitmentBars ?? 2;
315
324
  this.trendFilterEnabled = config.trendFilterEnabled ?? false;
316
325
  this.trendFilterMinBars = config.trendFilterMinBars ?? 3;
@@ -421,7 +430,7 @@ class DerivativeAnalyzer {
421
430
  // This ignores marginal crossings at ~0 and ensures signals only start when
422
431
  // momentum is clearly confirmed.
423
432
  if (this.macd && this.currMacd !== null) {
424
- const threshold = this.macdMinHist || 0.02;
433
+ const threshold = this.macdLineGateThreshold;
425
434
  if ((rawInterp === 'BEAR' || rawInterp === 'BEAR_WEAK') && this.currMacd.macd > -threshold)
426
435
  rawInterp = 'NEUTRAL';
427
436
  if ((rawInterp === 'BULL' || rawInterp === 'BULL_WEAK') && this.currMacd.macd < threshold)
@@ -744,7 +753,7 @@ class DerivativeAnalyzer {
744
753
  if (interp !== 'BULL' && interp !== 'BEAR') return false;
745
754
 
746
755
  if (this.macd && this.currMacd !== null) {
747
- const threshold = this.macdMinHist || 0.02;
756
+ const threshold = this.macdLineGateThreshold;
748
757
  if (interp === 'BULL' && this.currMacd.macd < threshold) return true;
749
758
  if (interp === 'BEAR' && this.currMacd.macd > -threshold) return true;
750
759
  }
@@ -1,8 +1,9 @@
1
+ 'use strict';
1
2
 
2
3
  import { DEFAULT_CONFIG, MARKET_ADAPTER } from '../../modules/constants.js';
3
4
  import { getAmaWarmupBars } from '../../market_adapter/core/strategies/ama.js';
4
5
  import { bilinearInterpolate } from '../../market_adapter/core/strategies/regime_interp.js';
5
- import { computeDynamicWeightSeries, computeAverageAmaSlopePct, echoLatchSeries, roundToN } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
6
+ import { computeDynamicWeightSeries, computeAverageAmaSlopePct, computeAmaSlopeClipThreshold, echoLatchSeries, roundToN } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
6
7
  import {
7
8
  buildKalmanVelocitySeries,
8
9
  computeAbsolutePercentileThreshold,
@@ -12,12 +13,12 @@ import {
12
13
  import { embedFunctionSources, escapeHtml, serializeJsonForScript, toEpochSeconds, UPLOT_SHARED_SCRIPT } from '../chart_utils.js';
13
14
  import { sharedChartCSS } from '../chart_css.js';
14
15
  import { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, wireChartEvents, zoomResetScript, sizeChartsFn } from '../chart_ui.js';
15
- 'use strict';
16
16
 
17
17
  // Browser-embedded shared functions — the interactive chart runs the exact same
18
18
  // pure logic as the live market adapter service instead of a hand-copied copy.
19
19
  const EMBEDDED_SHARED_FUNCS = embedFunctionSources([
20
20
  computeAverageAmaSlopePct,
21
+ computeAmaSlopeClipThreshold,
21
22
  bilinearInterpolate,
22
23
  echoLatchSeries,
23
24
  buildKalmanVelocitySeries,
@@ -36,7 +37,7 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
36
37
  // payload transport, and client paste-clamp bounds.
37
38
  const LB_MIN = 1, LB_MAX = 32;
38
39
  const GAIN_MIN = 0.5, GAIN_MAX = 2.0;
39
- const AMA_MS_MIN = 0.04, AMA_MS_MAX = 0.12;
40
+ const AMA_MS_MIN = 0.06, AMA_MS_MAX = 0.12;
40
41
  const KAL_MS_MIN = 0.5, KAL_MS_MAX = 1.5;
41
42
  const CLIP_PCT_MAX = 20;
42
43
  const TH_MIN = 0, TH_MAX = 0.5;
@@ -204,10 +205,14 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
204
205
  const sorted: number[] = [];
205
206
  for (let i = safeStartIndex; i < realBarCount; i++) { if (arr[i] != null) sorted.push(Math.abs(arr[i])); }
206
207
  sorted.sort((a, b) => a - b);
208
+ // Empty pool → Infinity: the live percentile lookup treats an empty
209
+ // history as "no clipping" (percentileFromSorted returns Infinity);
210
+ // collapsing to 0 here would clip every slope to ±0 instead.
211
+ if (sorted.length === 0) return new Array(101).fill(Infinity);
207
212
  const pcts: number[] = [];
208
213
  for (let p = 0; p <= 100; p++) {
209
214
  const idx = Math.min(Math.floor(sorted.length * p / 100), sorted.length - 1);
210
- pcts.push(sorted[idx] || 0);
215
+ pcts.push(sorted[idx]);
211
216
  }
212
217
  return pcts;
213
218
  }
@@ -437,8 +442,11 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
437
442
  const gainValToSlider = (val) => Math.round((Math.log(Math.max(Math.exp(GAIN_LOG_MIN), val)) - GAIN_LOG_MIN) / (GAIN_LOG_MAX - GAIN_LOG_MIN) * 1000);
438
443
 
439
444
  let currentClipPct = data.clipPct ?? ${JSON.stringify(defaultClipPct)};
445
+ // Only the clipPct===0 branch value is ever read (recalcWeights reads
446
+ // currentAmaClipThreshold solely when clipping is disabled; otherwise
447
+ // it uses the canonical dynamicClipThreshold from computeAmaSlopeClipThreshold).
440
448
  const maxAmaSlope = data.amaPercentiles[data.amaPercentiles.length - 1];
441
- let currentAmaClipThreshold = currentClipPct === 0 ? maxAmaSlope : data.amaPercentiles[100 - currentClipPct];
449
+ let currentAmaClipThreshold = currentClipPct === 0 ? maxAmaSlope : Infinity;
442
450
  let currentKalClipThreshold = currentClipPct === 0 ? Infinity : data.kalPercentiles[100 - currentClipPct];
443
451
 
444
452
  // Regime table and axis nodes from payload — sourced from MARKET_ADAPTER in constants.ts
@@ -589,22 +597,11 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
589
597
  const amaErWarmup = Math.max(0, Number.isFinite(data.amaErPeriod) ? Math.ceil(data.amaErPeriod) : ${JSON.stringify(MARKET_ADAPTER.AMAS[MARKET_ADAPTER.DEFAULT_AMA_KEY as keyof typeof MARKET_ADAPTER.AMAS].erPeriod)});
590
598
  const amaReadyBar = Math.max(lb, amaErWarmup + lb);
591
599
 
592
- // Recompute clip threshold based on current lookback
593
- dynamicClipThreshold = Infinity;
594
- if (currentClipPct > 0) {
595
- const slopes = [];
596
- for (let i = amaReadyBar; i < data.realBarCount; i++) {
597
- // Keep every finite slope (zeros included) — matches the live
598
- // market adapter service clip pool exactly.
599
- const s = computeAverageAmaSlopePct(data.ama3Prices[i], data.ama3Prices[i - lb], lb);
600
- if (Number.isFinite(s)) slopes.push(Math.abs(s));
601
- }
602
- if (slopes.length > 0) {
603
- slopes.sort((a, b) => a - b);
604
- const idx = Math.min(Math.floor((100 - currentClipPct) / 100 * slopes.length), slopes.length - 1);
605
- dynamicClipThreshold = slopes[idx];
606
- }
607
- }
600
+ // Recompute clip threshold based on current lookback — canonical
601
+ // implementation (computeAmaSlopeClipThreshold injected above),
602
+ // shared with the live market adapter service. Trailing padded
603
+ // nulls beyond realBarCount are skipped by its finiteness guards.
604
+ dynamicClipThreshold = computeAmaSlopeClipThreshold(data.ama3Prices, amaErWarmup, lb, currentClipPct);
608
605
 
609
606
  for (let i = 0; i < data.realBarCount; i++) {
610
607
  // AMA raw slope % for the display panel (offsets computed in recalcWeights)
@@ -790,7 +787,7 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
790
787
  const cRaw = combinedOff[idx];
791
788
  const cRawEl = document.getElementById('l-combined-raw');
792
789
  if (cRaw == null) { cRawEl.textContent = '-'; cRawEl.style.color = '#8b949e'; }
793
- else { cRawEl.textContent = (cRaw >= 0 ? '+' : '') + cRaw.toFixed(3); cRawEl.style.color = cRaw > 0.01 ? '#8b949e' : cRaw < -0.01 ? '#8b949e' : '#8b949e'; }
790
+ else { cRawEl.textContent = (cRaw >= 0 ? '+' : '') + cRaw.toFixed(3); cRawEl.style.color = '#8b949e'; }
794
791
 
795
792
  const cEcho = echoCombinedOff[idx];
796
793
  const cEchoEl = document.getElementById('l-combined-echo');
@@ -1018,7 +1015,7 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
1018
1015
  ],
1019
1016
  axes: [
1020
1017
  makeTimeAxis(false),
1021
- { scale: 'p', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30303d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
1018
+ { scale: 'p', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30363d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
1022
1019
  values: (u, v) => v.map(x => x != null ? (x >= 0 ? '+' : '') + (x * 10).toFixed(2) + '‰' : '') }
1023
1020
  ],
1024
1021
  cursor: cursorCfg,
@@ -1036,7 +1033,7 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
1036
1033
  ],
1037
1034
  axes: [
1038
1035
  makeTimeAxis(false),
1039
- { scale: 'v', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30303d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
1036
+ { scale: 'v', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30363d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
1040
1037
  values: (u, v) => v.map(x => x != null ? (x >= 0 ? '+' : '') + x.toFixed(1) + '%' : '') }
1041
1038
  ],
1042
1039
  cursor: cursorCfg,
@@ -1061,7 +1058,7 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
1061
1058
  ],
1062
1059
  axes: [
1063
1060
  makeTimeAxis(true),
1064
- { scale: 'ow', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30303d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
1061
+ { scale: 'ow', stroke: '#ffffff', grid: { stroke: '#1c2128', dash: [4, 4] }, ticks: { stroke: '#30363d', width: 1 }, size: Y_AXIS_SIZE, font: '11px Segoe UI, sans-serif',
1065
1062
  values: (u, v) => v.map(x => x != null ? (x >= 0 ? '+' : '') + x.toFixed(2) : ''),
1066
1063
  splits: () => { const m = Math.max(0.5, currentOutputAxisMax || 0.5); return [-m, -m/2, 0, m/2, m]; } }
1067
1064
  ],
@@ -1163,7 +1160,9 @@ function generateHTML(data: any, title = 'Dynamic Weight Research') {
1163
1160
  currentAmaClipThreshold = data.amaPercentiles[data.amaPercentiles.length - 1];
1164
1161
  currentKalClipThreshold = Infinity;
1165
1162
  } else {
1166
- currentAmaClipThreshold = data.amaPercentiles[100 - currentClipPct];
1163
+ // AMA clip threshold for clipPct>0 comes from the canonical
1164
+ // computeAmaSlopeClipThreshold inside recalcInputs() —
1165
+ // no percentile-table store needed here.
1167
1166
  recalcKalmanClipThreshold();
1168
1167
  }
1169
1168
  document.getElementById('clip-value').textContent = currentClipPct + '%';
@@ -1260,7 +1259,6 @@ function applyParams(p, btn) {
1260
1259
  currentAmaClipThreshold = data.amaPercentiles[data.amaPercentiles.length - 1];
1261
1260
  currentKalClipThreshold = Infinity;
1262
1261
  } else {
1263
- currentAmaClipThreshold = data.amaPercentiles[100 - currentClipPct];
1264
1262
  recalcKalmanClipThreshold();
1265
1263
  }
1266
1264
  }
@@ -4,4 +4,4 @@
4
4
  * Re-export shim — canonical implementation lives in
5
5
  * market_adapter/core/signals/hurst_analyzer.ts.
6
6
  */
7
- export { HurstAnalyzer } from '../../market_adapter/core/signals/hurst_analyzer.js';
7
+ export { HurstAnalyzer, classifyHurst } from '../../market_adapter/core/signals/hurst_analyzer.js';
@@ -1,21 +1,13 @@
1
+ 'use strict';
1
2
 
3
+ import { MARKET_ADAPTER } from '../../modules/constants.js';
4
+ import { computeDynamicWeightSeries } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
5
+ import { computeAbsolutePercentileThreshold } from '../../market_adapter/core/signals/kalman_velocity_smoothing.js';
2
6
  import { escapeHtml, serializeJsonForScript, toEpochSeconds, UPLOT_SHARED_SCRIPT } from '../chart_utils.js';
3
7
  import { sharedChartCSS } from '../chart_css.js';
4
8
  import { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, wireChartEvents, zoomResetScript, sizeChartsFn } from '../chart_ui.js';
5
- 'use strict';
6
9
 
7
10
 
8
- const NEUTRAL_ZONE_PCT = 0.15;
9
- const MAX_SLOPE_PCT = 3.0;
10
- const MAX_SLOPE_OFFSET = 0.5;
11
-
12
- function computeKalmanWeightOffset(velocityPct: any, isReady: any) {
13
- if (!isReady || velocityPct == null) return 0;
14
- if (Math.abs(velocityPct) < NEUTRAL_ZONE_PCT) return 0;
15
- return Math.max(-MAX_SLOPE_OFFSET, Math.min(MAX_SLOPE_OFFSET,
16
- (velocityPct / MAX_SLOPE_PCT) * MAX_SLOPE_OFFSET));
17
- }
18
-
19
11
  function generateHTML(data: any, title = 'Kalman Trajectory Analysis') {
20
12
  const results = data.allResults || [];
21
13
  if (results.length === 0) throw new Error('No analysis results in input');
@@ -31,7 +23,43 @@ function generateHTML(data: any, title = 'Kalman Trajectory Analysis') {
31
23
  const trendUp = results.map((r: any) =>
32
24
  r.kalmanPrice != null && r.modalPrice != null ? r.kalmanPrice > r.modalPrice : null
33
25
  );
34
- const kalmanWeights = results.map((r: any) => computeKalmanWeightOffset(r.velocityFilteredPct ?? r.velocityPct, r.isReady));
26
+
27
+ // Kalman weight channel — canonical implementation shared with the live
28
+ // market adapter (computeDynamicWeightSeries), including the percentile
29
+ // clip threshold and the displacement-confidence/momentum-alignment
30
+ // composite the previous hand-rolled copy omitted.
31
+ const amaLb = MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS;
32
+ const defaultAmaKey = MARKET_ADAPTER.DEFAULT_AMA_KEY as keyof typeof MARKET_ADAPTER.AMAS;
33
+ const amaErPeriod = data.amaConfig?.erPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].erPeriod;
34
+ const clipPct = data.clipPct ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_CLIP_PERCENTILE;
35
+ const velocityPct = results.map((r: any) => r.velocityFilteredPct ?? r.velocityPct ?? null);
36
+ const displacementPct = results.map((r: any) => r.displacementRawPct ?? r.displacementPct ?? null);
37
+ const isReady = results.map((r: any) => !!r.isReady);
38
+ const kalClipThreshold = clipPct > 0
39
+ ? computeAbsolutePercentileThreshold(velocityPct, clipPct, Infinity)
40
+ : Infinity;
41
+ const dwSeries = computeDynamicWeightSeries({
42
+ amaValues: prices, // AMA channel unused here; length driver only
43
+ kalmanVelocityPct: velocityPct,
44
+ kalmanDisplacementPct: displacementPct,
45
+ kalmanIsReady: isReady,
46
+ regimeMultipliers: undefined,
47
+ lookbackBars: amaLb,
48
+ amaErPeriod,
49
+ amaClipThreshold: Infinity,
50
+ kalClipThreshold,
51
+ neutralZonePct: MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_NEUTRAL_ZONE_PCT,
52
+ amaMaxSlopePct: MARKET_ADAPTER.DYNAMIC_WEIGHT_AMA_MAX_SLOPE_PCT,
53
+ kalmanMaxSlopePct: MARKET_ADAPTER.DYNAMIC_WEIGHT_KALMAN_MAX_SLOPE_PCT,
54
+ offsetClamp: MARKET_ADAPTER.DYNAMIC_WEIGHT_ASYMMETRIC_OFFSET_CLAMP,
55
+ dispScaleMinPct: MARKET_ADAPTER.DYNAMIC_WEIGHT_DISP_SCALE_MIN_PCT,
56
+ alpha: MARKET_ADAPTER.DYNAMIC_WEIGHT_ALPHA,
57
+ dw: MARKET_ADAPTER.DYNAMIC_WEIGHT_DW,
58
+ gain: MARKET_ADAPTER.DYNAMIC_WEIGHT_GAIN,
59
+ minOutputThreshold: MARKET_ADAPTER.DYNAMIC_WEIGHT_ASYMMETRIC_TREND_THRESHOLD,
60
+ signalConfirmBars: MARKET_ADAPTER.DYNAMIC_WEIGHT_SIGNAL_CONFIRM_BARS_DEFAULT,
61
+ });
62
+ const kalmanWeights = dwSeries.kalmanOffsets;
35
63
  const amaWeights = results.map((r: any) => r.amaWeightOffset ?? null);
36
64
 
37
65
  // Future Projection (150 bars)
@@ -101,7 +129,7 @@ function generateHTML(data: any, title = 'Kalman Trajectory Analysis') {
101
129
  <div id="ama-panel">
102
130
  <div class="legend">
103
131
  <div class="legend-item"><div class="dot" style="background:linear-gradient(to bottom,#f0a000,#4a90d9);"></div>AMA Weight: <span id="l-ama-w" style="font-weight:bold;">-</span></div>
104
- <span style="color:#8b949e;font-size:10px;">lookback 72 bars &nbsp;·&nbsp; er10/2/30</span>
132
+ <span style="color:#8b949e;font-size:10px;">lookback ${amaLb} bars &nbsp;·&nbsp; er${escapeHtml(String(data.amaConfig?.erPeriod ?? amaErPeriod))}/${escapeHtml(String(data.amaConfig?.fastPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].fastPeriod))}/${escapeHtml(String(data.amaConfig?.slowPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].slowPeriod))}</span>
105
133
  </div>
106
134
  <div id="ama-chart"></div>
107
135
  </div>
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trend-detection",
3
- "version": "1.4.21",
3
+ "version": "1.4.23",
4
4
  "description": "Kalman filter trend detection with tactical/modal state tracking",
5
5
  "main": "../../dist/analysis/trend_detection/kalman_trend_analyzer.js",
6
6
  "scripts": {
@@ -1,8 +1,21 @@
1
+ 'use strict';
1
2
 
3
+ import { MARKET_ADAPTER } from '../../modules/constants.js';
2
4
  import { escapeHtml, serializeJsonForScript, toEpochSeconds, UPLOT_SHARED_SCRIPT } from '../chart_utils.js';
3
5
  import { sharedChartCSS } from '../chart_css.js';
4
6
  import { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, wireChartEvents, zoomResetScript, sizeChartsFn, fmtDateFn } from '../chart_ui.js';
5
- 'use strict';
7
+
8
+ // Zone boundaries sourced from MARKET_ADAPTER (single source of truth shared
9
+ // with the live adapter) instead of hardcoded copies. Hurst classification
10
+ // uses inclusive >=/<= bounds matching market_adapter/core/signals/hurst_analyzer.ts.
11
+ const HURST_WINDOW_DEFAULT = MARKET_ADAPTER.HURST_CONFIG.window;
12
+ const HURST_SCALES_DEFAULT = MARKET_ADAPTER.HURST_CONFIG.scales;
13
+ const PE_M_DEFAULT = MARKET_ADAPTER.PE_CONFIG.m;
14
+ const PE_WINDOW_DEFAULT = MARKET_ADAPTER.PE_CONFIG.window;
15
+ const H_UPPER = 0.5 + MARKET_ADAPTER.HURST_ZONE_BAND;
16
+ const H_LOWER = 0.5 - MARKET_ADAPTER.HURST_ZONE_BAND;
17
+ const PE_STRUCTURED = MARKET_ADAPTER.PE_NODES[0];
18
+ const PE_NOISE = MARKET_ADAPTER.PE_NODES[MARKET_ADAPTER.PE_NODES.length - 1];
6
19
 
7
20
 
8
21
  /**
@@ -61,16 +74,16 @@ function generateRegimeHTML(data: any, title = 'Regime Analysis') {
61
74
  }
62
75
 
63
76
  // Background shading segments (server-side, passed to browser via JSON payload)
64
- const hurstSegments = buildSegments(hurstArr.slice(0, realBarCount), (v: any) => v > 0.55, (v: any) => v < 0.45);
65
- const peSegments = buildSegments(peArr.slice(0, realBarCount), (v: any) => v < 0.60, (v: any) => v > 0.85);
77
+ const hurstSegments = buildSegments(hurstArr.slice(0, realBarCount), (v: any) => v >= H_UPPER, (v: any) => v <= H_LOWER);
78
+ const peSegments = buildSegments(peArr.slice(0, realBarCount), (v: any) => v < PE_STRUCTURED, (v: any) => v > PE_NOISE);
66
79
 
67
80
  const payload = {
68
81
  dates, prices, ama3Prices, hurstArr, peArr,
69
82
  hurstSegments, peSegments,
70
83
  realBarCount,
71
- hurstWindow: hurstConfig.window ?? 128,
72
- peM: peConfig.m ?? 5,
73
- peWindow: peConfig.window ?? 100,
84
+ hurstWindow: hurstConfig.window ?? HURST_WINDOW_DEFAULT,
85
+ peM: peConfig.m ?? PE_M_DEFAULT,
86
+ peWindow: peConfig.window ?? PE_WINDOW_DEFAULT,
74
87
  };
75
88
 
76
89
  return `<!DOCTYPE html>
@@ -96,12 +109,12 @@ function generateRegimeHTML(data: any, title = 'Regime Analysis') {
96
109
  <div style="font-weight:bold;color:#fff;">${escapeHtml(title)}</div>
97
110
  <div style="display:flex;align-items:center;gap:16px;">
98
111
  <span style="font-size:10px;color:#8b949e;font-family:monospace;">
99
- Hurst: window=${escapeHtml(String(hurstConfig.window ?? 128))}&thinsp;bars &middot; scales=[${escapeHtml((hurstConfig.scales ?? [8,16,32,64]).join(','))}]
112
+ Hurst: window=${escapeHtml(String(hurstConfig.window ?? HURST_WINDOW_DEFAULT))}&thinsp;bars &middot; scales=[${escapeHtml((hurstConfig.scales ?? HURST_SCALES_DEFAULT).join(','))}]
100
113
  &nbsp;&nbsp;|&nbsp;&nbsp;
101
- PE: m=${escapeHtml(String(peConfig.m ?? 5))} &middot; window=${escapeHtml(String(peConfig.window ?? 100))}&thinsp;bars
114
+ PE: m=${escapeHtml(String(peConfig.m ?? PE_M_DEFAULT))} &middot; window=${escapeHtml(String(peConfig.window ?? PE_WINDOW_DEFAULT))}&thinsp;bars
102
115
  </span>
103
116
  <span style="font-size:11px;color:#adbac7;text-transform:uppercase;">
104
- H&gt;0.55=trend &middot; H&lt;0.45=revert &middot; PE&lt;0.60=structured &middot; PE&gt;0.85=noise
117
+ H&ge;${H_UPPER.toFixed(2)}=trend &middot; H&le;${H_LOWER.toFixed(2)}=revert &middot; PE&lt;${PE_STRUCTURED.toFixed(2)}=structured &middot; PE&gt;${PE_NOISE.toFixed(2)}=noise
105
118
  &nbsp;&nbsp;|&nbsp;&nbsp; Scroll &middot; Drag &middot; Ctrl+0
106
119
  </span>
107
120
  </div>
@@ -122,7 +135,7 @@ function generateRegimeHTML(data: any, title = 'Regime Analysis') {
122
135
  <div class="legend">
123
136
  <div class="legend-item"><div class="dot" style="background:#4dc3ff;"></div>H: <span id="l-hurst" style="font-weight:bold;color:#4dc3ff;">-</span></div>
124
137
  <div class="legend-item">Regime: <span id="l-hurst-regime" style="font-weight:bold;">-</span></div>
125
- <div class="legend-item" style="color:#555;font-size:10px;">window=${escapeHtml(String(hurstConfig.window ?? 128))} bars</div>
138
+ <div class="legend-item" style="color:#555;font-size:10px;">window=${escapeHtml(String(hurstConfig.window ?? HURST_WINDOW_DEFAULT))} bars</div>
126
139
  </div>
127
140
  <div id="hurst-chart"></div>
128
141
  </div>
@@ -131,7 +144,7 @@ function generateRegimeHTML(data: any, title = 'Regime Analysis') {
131
144
  <div class="legend">
132
145
  <div class="legend-item"><div class="dot" style="background:#d2a8ff;"></div>PE: <span id="l-pe" style="font-weight:bold;color:#d2a8ff;">-</span></div>
133
146
  <div class="legend-item">Regime: <span id="l-pe-regime" style="font-weight:bold;">-</span></div>
134
- <div class="legend-item" style="color:#555;font-size:10px;">m=${escapeHtml(String(peConfig.m ?? 5))}, window=${escapeHtml(String(peConfig.window ?? 100))} bars</div>
147
+ <div class="legend-item" style="color:#555;font-size:10px;">m=${escapeHtml(String(peConfig.m ?? PE_M_DEFAULT))}, window=${escapeHtml(String(peConfig.window ?? PE_WINDOW_DEFAULT))} bars</div>
135
148
  </div>
136
149
  <div id="pe-chart"></div>
137
150
  </div>
@@ -156,16 +169,23 @@ function generateRegimeHTML(data: any, title = 'Regime Analysis') {
156
169
  ${fmtDateFn()}
157
170
  ${bindHoverStateFn()}
158
171
 
172
+ // Inclusive zone boundaries — same semantics as the live classifier
173
+ // (market_adapter/core/signals/hurst_analyzer.ts classifyHurst).
174
+ const H_UPPER = ${JSON.stringify(H_UPPER)};
175
+ const H_LOWER = ${JSON.stringify(H_LOWER)};
176
+ const PE_STRUCTURED = ${JSON.stringify(PE_STRUCTURED)};
177
+ const PE_NOISE = ${JSON.stringify(PE_NOISE)};
178
+
159
179
  function hurstRegimeLabel(v) {
160
180
  if (v == null) return '<span class="badge badge-grey">-</span>';
161
- if (v > 0.55) return '<span class="badge badge-green">TRENDING</span>';
162
- if (v < 0.45) return '<span class="badge badge-red">MEAN REV</span>';
181
+ if (v >= H_UPPER) return '<span class="badge badge-green">TRENDING</span>';
182
+ if (v <= H_LOWER) return '<span class="badge badge-red">MEAN REV</span>';
163
183
  return '<span class="badge badge-grey">RANDOM</span>';
164
184
  }
165
185
  function peRegimeLabel(v) {
166
186
  if (v == null) return '<span class="badge badge-grey">-</span>';
167
- if (v < 0.60) return '<span class="badge badge-green">STRUCTURED</span>';
168
- if (v > 0.85) return '<span class="badge badge-red">NOISE</span>';
187
+ if (v < PE_STRUCTURED) return '<span class="badge badge-green">STRUCTURED</span>';
188
+ if (v > PE_NOISE) return '<span class="badge badge-red">NOISE</span>';
169
189
  return '<span class="badge badge-grey">MIXED</span>';
170
190
  }
171
191
 
@@ -218,13 +238,13 @@ function generateRegimeHTML(data: any, title = 'Regime Analysis') {
218
238
  // ── chart instances ──────────────────────────────────────────────────
219
239
 
220
240
  const hurstRefLines = [
221
- { y: 0.55, color: 'rgba(46,160,67,0.5)' },
241
+ { y: H_UPPER, color: 'rgba(46,160,67,0.5)' },
222
242
  { y: 0.50, color: 'rgba(110,118,129,0.3)' },
223
- { y: 0.45, color: 'rgba(248,81,73,0.5)' },
243
+ { y: H_LOWER, color: 'rgba(248,81,73,0.5)' },
224
244
  ];
225
245
  const peRefLines = [
226
- { y: 0.85, color: 'rgba(248,81,73,0.5)' },
227
- { y: 0.60, color: 'rgba(46,160,67,0.5)' },
246
+ { y: PE_NOISE, color: 'rgba(248,81,73,0.5)' },
247
+ { y: PE_STRUCTURED, color: 'rgba(46,160,67,0.5)' },
228
248
  ];
229
249
 
230
250
  const hurstBgFn = makeBgHook(data.hurstSegments, hurstRefLines, 'h');
@@ -1,7 +1,7 @@
1
+ 'use strict';
1
2
  import assert from 'node:assert';
2
3
  import { KalmanTrendAnalyzer, KalmanFilter } from '../kalman_trend_analyzer.js';
3
4
 
4
- 'use strict';
5
5
 
6
6
  /**
7
7
  * Test Suite for Kalman Trend Detection
@@ -1,10 +1,10 @@
1
+ 'use strict';
1
2
  import assert from 'node:assert';
2
3
  import {
3
4
  buildKalmanVelocitySeries,
4
5
  smoothKalmanVelocityPoint,
5
6
  } from '../kalman_velocity_smoothing.js';
6
7
 
7
- 'use strict';
8
8
 
9
9
  const baseline = smoothKalmanVelocityPoint(
10
10
  0,
@@ -1,3 +1,4 @@
1
+ 'use strict';
1
2
 
2
3
  import { MARKET_ADAPTER } from '../../modules/constants.js';
3
4
  import { computeATRSeries } from '../../market_adapter/core/strategies/atr/calculator.js';
@@ -5,7 +6,6 @@ import { computeVolatilityShift } from '../../market_adapter/core/strategies/vol
5
6
  import { embedFunctionSources, escapeHtml, serializeJsonForScript, toEpochSeconds, UPLOT_SHARED_SCRIPT } from '../chart_utils.js';
6
7
  import { sharedChartCSS } from '../chart_css.js';
7
8
  import { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, wireChartEvents, zoomResetScript, sizeChartsFn } from '../chart_ui.js';
8
- 'use strict';
9
9
 
10
10
  const EMBEDDED_SHARED_FUNCS = embedFunctionSources([computeATRSeries, computeVolatilityShift]);
11
11
 
package/claw/index.ts CHANGED
@@ -59,6 +59,6 @@ const _default = {
59
59
  resolveSigningAccountName: chainBroadcast.resolveAccountName
60
60
  };
61
61
  export default _default;
62
- // CJS compatibility - tsx/require gets the object directly
62
+ // CJS compatibility - require() gets the object directly
63
63
 
64
64
 
@@ -4,7 +4,7 @@ const require = createRequire(import.meta.url);
4
4
 
5
5
  import { createClawInfrastructure } from './claw_infra.js';
6
6
  import { describeClawBridge } from './claw_manifest.js';
7
- import { runMemuCommand } from './memu_bridge.js';
7
+ import { describeMemuBridge, runMemuCommand } from './memu_bridge.js';
8
8
  import { clone } from './utils.js';
9
9
  import { adjustMpaCollateral, borrowMpa, cancelLimitOrder, createLimitOrder, executeBatch, getMpaPosition, getOpenOrders, repayMpaDebt, buildUpdateLimitOrderOperation, updateLimitOrder, settleMpa } from './chain_actions.js';
10
10
  import { buildCloseShortPlan, buildOpenShortPlan, buildTakeProfitPlan, closeShortOnBts, openShortOnBts, placeTakeProfitBuyOrderOnBts } from './short_mpa_strategy.js';
@@ -126,7 +126,7 @@ function describeRuntimeManifest(options: ClawBridgeOptions = {}): any {
126
126
  function describeCommandManifest(options: ClawBridgeOptions = {}): any {
127
127
  const runtimeName = options.runtimeName || options.runtime?.name || null;
128
128
  if (runtimeName && String(runtimeName).trim().toLowerCase() === 'memu') {
129
- return require('./memu_bridge').describeMemuBridge(options);
129
+ return describeMemuBridge(options);
130
130
  }
131
131
  return describeClawBridge(options);
132
132
  }
@@ -373,7 +373,7 @@ async function runClawCommand(command: string, options: ClawBridgeOptions = {}):
373
373
  return launcherPm2Restart(safeOptions.botName || 'all', safeOptions);
374
374
 
375
375
  case 'memu-manifest':
376
- return require('./memu_bridge').describeMemuBridge(safeOptions);
376
+ return describeMemuBridge(safeOptions);
377
377
 
378
378
  case 'memu-memorize':
379
379
  case 'memu-retrieve':
@@ -809,7 +809,7 @@ function getClawToolCatalog() {
809
809
  return CLAW_TOOL_CATALOG.map(cloneTool);
810
810
  }
811
811
 
812
- function buildClawCommandExamples(scriptPath = 'tsx claw/scripts/claw_bridge.ts') {
812
+ function buildClawCommandExamples(scriptPath = 'node dist/claw/scripts/claw_bridge.js') {
813
813
  return CLAW_TOOL_CATALOG
814
814
  .filter((tool) => Array.isArray(tool.exampleArgs))
815
815
  .map((tool) => [
@@ -1,3 +1,4 @@
1
+ 'use strict';
1
2
 
2
3
  import { createRequire } from 'node:module';
3
4
  const require = createRequire(import.meta.url);
@@ -8,7 +9,6 @@ import { loadSettingsFile, resolveRawBotEntries, saveSettingsFile, normalizeBotE
8
9
  import { normalizeMode, detectMode, setPreferredMode, describeModeChoice } from './launcher_mode_detector.js';
9
10
  import { normalizeRoot, resolveRuntimeScript, normalizeProfileDir } from './launcher_paths.js';
10
11
  import { getErrorMessage } from '../../modules/utils/errors.js';
11
- 'use strict';
12
12
 
13
13
  const storage = getStorage();
14
14
 
@@ -12,14 +12,11 @@ function normalizeClawRepoRoot(repoRoot: string) {
12
12
  }
13
13
 
14
14
  // Generated docs must reference scripts that actually exist. Claw tooling
15
- // lives in claw/scripts/ (shipped as source); prefer a compiled sibling when
16
- // present, otherwise fall back to the .ts source run through tsx.
15
+ // ships compiled to dist/claw/scripts/ (npm run build); generated skill
16
+ // files always reference the node + .js form so they work without any
17
+ // TypeScript loader installed.
17
18
  function resolveScriptInvocation(repoRoot: string, name: string) {
18
- const jsPath = path.join(repoRoot, 'claw', 'scripts', `${name}.js`);
19
- if (storage.exists(jsPath)) {
20
- return { command: 'node', script: jsPath };
21
- }
22
- return { command: 'npx tsx', script: path.join(repoRoot, 'claw', 'scripts', `${name}.ts`) };
19
+ return { command: 'node', script: path.join(repoRoot, 'dist', 'claw', 'scripts', `${name}.js`) };
23
20
  }
24
21
 
25
22
  function buildBridgeInvocation(repoRoot: string, profileRoot: string, command: string, extraArgs: any[] = []) {
@@ -49,8 +46,8 @@ function buildToolSummary(runtimeName: string) {
49
46
 
50
47
  function buildRuntimeSetup(runtime: any, repoRoot: string, profileRoot: string) {
51
48
  const { command, script: mcpScriptPath } = resolveScriptInvocation(repoRoot, 'claw_mcp_server');
52
- // command is 'node' or 'npx tsx'; split so the config blocks can set the
53
- // executable and args correctly for both the built and source layouts.
49
+ // command is 'node'; split so the config blocks can set the
50
+ // executable and args correctly for the built layout.
54
51
  const runnerParts = command.split(' ');
55
52
  const mcpExec = runnerParts[0];
56
53
  const mcpArgs = `[${[...runnerParts.slice(1), mcpScriptPath, '--profile-root', profileRoot].map((part: any) => JSON.stringify(part)).join(', ')}]`;
@@ -209,7 +206,7 @@ function buildRuntimeSetup(runtime: any, repoRoot: string, profileRoot: string)
209
206
  'Start the memU MCP server:',
210
207
  '',
211
208
  '```bash',
212
- `tsx ${path.join(repoRoot, 'claw', 'scripts', 'memu_mcp_server.ts').replace(/\\/g, '/')} --memu-dir ${PATHS.CLAW.MEMU_DIR.replace(/\\/g, '/')}`,
209
+ `node ${path.join(repoRoot, 'dist', 'claw', 'scripts', 'memu_mcp_server.js').replace(/\\/g, '/')} --memu-dir ${PATHS.CLAW.MEMU_DIR.replace(/\\/g, '/')}`,
213
210
  '```',
214
211
  '',
215
212
  'Or use the npm script:',
@@ -1,8 +1,8 @@
1
+ 'use strict';
1
2
 
2
3
  import { PATHS } from '../../modules/paths.js';
3
4
  import CreditRuntime from '../../modules/credit_runtime.js';
4
5
  import { getErrorMessage } from '../../modules/utils/errors.js';
5
- 'use strict';
6
6
 
7
7
 
8
8
  function createCreditRuntimeAdapter(infra: any, options: Record<string, any> = {}) {
@@ -1,3 +1,4 @@
1
+ 'use strict';
1
2
  /**
2
3
  * Decision Loop
3
4
  *
@@ -16,22 +17,17 @@
16
17
  */
17
18
 
18
19
 
19
- import { createRequire } from 'node:module';
20
- const require = createRequire(import.meta.url);
21
-
22
20
  import { discoverPositions } from './position_discovery.js';
23
21
  import { assessPosition } from './position_health.js';
24
22
  import { fetchTrendInput } from './feed_price_source.js';
25
23
  import { getErrorMessage } from '../../modules/utils/errors.js';
26
- 'use strict';
24
+ // Static import (previously a lazy createRequire fallback): lazy require()
25
+ // bypasses the ESM loader hooks that compiled tests use for module mocking,
26
+ // and the analyzer module carries no circular-import risk.
27
+ import { KalmanTrendAnalyzer } from '../../market_adapter/core/signals/kalman_trend_analyzer.js';
27
28
 
28
29
 
29
- // Lazy-load KalmanTrendAnalyzer to avoid circular dependency issues at startup
30
- let KalmanTrendAnalyzer: any = null;
31
30
  function getTrendAnalyzer() {
32
- if (!KalmanTrendAnalyzer) {
33
- KalmanTrendAnalyzer = require('../../market_adapter/core/signals/kalman_trend_analyzer').KalmanTrendAnalyzer;
34
- }
35
31
  return KalmanTrendAnalyzer;
36
32
  }
37
33
 
@@ -41,13 +41,13 @@ function getDexbot2Root() {
41
41
  function resolveDexbot2Path(relativePath: string) {
42
42
  const root = getDexbot2Root();
43
43
  const normalizedPath = String(relativePath || '');
44
- const candidates = [path.join(root, normalizedPath)];
45
44
 
46
- if (normalizedPath.endsWith('.js')) {
47
- candidates.push(path.join(root, normalizedPath.replace(/\.js$/, '.ts')));
48
- }
49
-
50
- candidates.push(path.join(root, BUILD_DIR, normalizedPath));
45
+ // Compiled build first: under plain node there is no tsx-style .js→.ts
46
+ // interception, so resolving to the source tree would break require().
47
+ const candidates = [
48
+ path.join(root, BUILD_DIR, normalizedPath),
49
+ path.join(root, normalizedPath),
50
+ ];
51
51
 
52
52
  for (const candidate of candidates) {
53
53
  if (candidateExists(candidate)) {
@@ -55,7 +55,7 @@ function resolveDexbot2Path(relativePath: string) {
55
55
  }
56
56
  }
57
57
 
58
- return candidates[candidates.length - 1];
58
+ return candidates[0];
59
59
  }
60
60
 
61
61
  function requireDexbot2Module(relativePath: string) {