dexbot 1.4.13 → 1.4.14

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 (312) hide show
  1. package/README.md +58 -34
  2. package/claw/data/positions.json +2487 -1
  3. package/claw/docs/AI_BOT_LIBRARY_API.md +1 -1
  4. package/claw/docs/POSITION_HEALTH.md +2 -2
  5. package/claw/modules/claw_catalog.ts +1 -3
  6. package/claw/modules/claw_launcher.ts +2 -3
  7. package/claw/modules/claw_skill_md.ts +1 -1
  8. package/claw/modules/decision_loop.ts +1 -1
  9. package/claw/modules/dexbot_profiles.ts +2 -33
  10. package/claw/modules/feed_price_source.ts +3 -32
  11. package/claw/modules/launcher_mode_detector.ts +1 -1
  12. package/claw/modules/mcp_utils.ts +1 -1
  13. package/claw/modules/mpa_utils.ts +36 -1
  14. package/claw/modules/position_discovery.ts +1 -28
  15. package/claw/modules/position_health.ts +1 -20
  16. package/claw/modules/position_manager.ts +3 -28
  17. package/claw/modules/skill_utils.ts +1 -1
  18. package/claw/modules/types.ts +0 -53
  19. package/claw/package.json +1 -1
  20. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  21. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  22. package/claw/skills/margin-trading/references/honest-assets.md +1 -1
  23. package/claw/skills/margin-trading/references/position-management.md +2 -2
  24. package/claw/skills/shared/references/js-automation-overview.md +2 -2
  25. package/claw/skills/trend-detection/references/service.md +24 -17
  26. package/claw/tests/test_claw_bridge.ts +47 -47
  27. package/claw/tests/test_claw_catalog_and_credentials.ts +9 -9
  28. package/claw/tests/test_claw_chain_layer.ts +54 -54
  29. package/claw/tests/test_claw_data_flow.ts +41 -41
  30. package/claw/tests/test_claw_domain_logic.ts +26 -26
  31. package/claw/tests/test_claw_manifest_and_matrix.ts +1 -1
  32. package/claw/tests/test_claw_mcp_transport.ts +16 -16
  33. package/claw/tests/test_claw_regressions.ts +43 -43
  34. package/claw/tests/test_claw_skill_generation.ts +1 -1
  35. package/claw/tests/test_claw_state_store.ts +2 -2
  36. package/claw/tests/test_dexbot_profiles.ts +4 -4
  37. package/claw/tests/test_memu_bridge.ts +3 -3
  38. package/claw/tests/test_nullclaw_tmp_integration.ts +1 -1
  39. package/claw/tests/test_position_health.ts +2 -2
  40. package/claw/tests/test_position_manager.ts +18 -18
  41. package/claw/tests/test_position_manager_watch_health.ts +2 -2
  42. package/claw/tests/test_short_mpa_strategy.ts +12 -12
  43. package/dist/analysis/chart_utils.d.ts +13 -1
  44. package/dist/analysis/chart_utils.d.ts.map +1 -1
  45. package/dist/analysis/chart_utils.js +16 -1
  46. package/dist/analysis/chart_utils.js.map +1 -1
  47. package/dist/analysis/math_utils.d.ts +8 -12
  48. package/dist/analysis/math_utils.d.ts.map +1 -1
  49. package/dist/analysis/math_utils.js +9 -75
  50. package/dist/analysis/math_utils.js.map +1 -1
  51. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +4 -4
  52. package/dist/dexbot.d.ts.map +1 -1
  53. package/dist/dexbot.js +37 -34
  54. package/dist/dexbot.js.map +1 -1
  55. package/dist/market_adapter/candle_utils.d.ts +18 -1
  56. package/dist/market_adapter/candle_utils.d.ts.map +1 -1
  57. package/dist/market_adapter/candle_utils.js +50 -1
  58. package/dist/market_adapter/candle_utils.js.map +1 -1
  59. package/dist/market_adapter/core/config_normalizers.js +1 -1
  60. package/dist/market_adapter/core/config_normalizers.js.map +1 -1
  61. package/dist/market_adapter/core/kibana_client.d.ts +2 -2
  62. package/dist/market_adapter/core/kibana_client.js +2 -2
  63. package/dist/market_adapter/core/kibana_market_candles.d.ts +1 -87
  64. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -1
  65. package/dist/market_adapter/core/kibana_market_candles.js +1 -80
  66. package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
  67. package/dist/market_adapter/core/market_adapter_service.d.ts +0 -8
  68. package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
  69. package/dist/market_adapter/core/market_adapter_service.js +28 -115
  70. package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
  71. package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +1 -0
  72. package/dist/{analysis/trend_detection → market_adapter/core/signals}/hurst_analyzer.js +2 -2
  73. package/dist/market_adapter/core/signals/hurst_analyzer.js.map +1 -0
  74. package/dist/{analysis/trend_detection → market_adapter/core/signals}/kalman_trend_analyzer.d.ts +0 -1
  75. package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +1 -0
  76. package/dist/{analysis/trend_detection → market_adapter/core/signals}/kalman_trend_analyzer.js +2 -4
  77. package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +1 -0
  78. package/dist/{analysis/trend_detection → market_adapter/core/signals}/kalman_velocity_smoothing.d.ts +25 -4
  79. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +1 -0
  80. package/dist/{analysis/trend_detection → market_adapter/core/signals}/kalman_velocity_smoothing.js +41 -19
  81. package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +1 -0
  82. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +1 -0
  83. package/dist/{analysis/trend_detection → market_adapter/core/signals}/permutation_entropy_analyzer.js +2 -2
  84. package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +1 -0
  85. package/dist/market_adapter/core/strategies/ama.d.ts +1 -19
  86. package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -1
  87. package/dist/market_adapter/core/strategies/ama.js +1 -1
  88. package/dist/market_adapter/core/strategies/ama.js.map +1 -1
  89. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +2 -13
  90. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -1
  91. package/dist/market_adapter/core/strategies/ama_slope_model.js +15 -26
  92. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
  93. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +38 -3
  94. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -1
  95. package/dist/market_adapter/core/strategies/atr/calculator.js +84 -24
  96. package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
  97. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +1 -1
  98. package/dist/market_adapter/core/strategies/collateral_manager.js +1 -1
  99. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +32 -0
  100. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +1 -0
  101. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +136 -0
  102. package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +1 -0
  103. package/dist/market_adapter/core/strategies/regime_gate.d.ts +6 -21
  104. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
  105. package/dist/market_adapter/core/strategies/regime_gate.js +11 -74
  106. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
  107. package/dist/market_adapter/core/strategies/regime_interp.d.ts +13 -0
  108. package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +1 -0
  109. package/dist/market_adapter/core/strategies/regime_interp.js +74 -0
  110. package/dist/market_adapter/core/strategies/regime_interp.js.map +1 -0
  111. package/dist/market_adapter/core/strategies/volatility_shift.d.ts +22 -0
  112. package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +1 -0
  113. package/dist/market_adapter/core/strategies/volatility_shift.js +37 -0
  114. package/dist/market_adapter/core/strategies/volatility_shift.js.map +1 -0
  115. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +3 -4
  116. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
  117. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +1 -10
  118. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
  119. package/dist/market_adapter/inputs/fetch_lp_data.js +1 -1
  120. package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
  121. package/dist/market_adapter/lp_chart_core.d.ts.map +1 -1
  122. package/dist/market_adapter/lp_chart_core.js +0 -10
  123. package/dist/market_adapter/lp_chart_core.js.map +1 -1
  124. package/dist/market_adapter/lp_chart_runner.d.ts +1 -16
  125. package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
  126. package/dist/market_adapter/lp_chart_runner.js +1 -15
  127. package/dist/market_adapter/lp_chart_runner.js.map +1 -1
  128. package/dist/market_adapter/market_adapter.d.ts +3 -3
  129. package/dist/market_adapter/market_adapter.d.ts.map +1 -1
  130. package/dist/market_adapter/market_adapter.js +6 -8
  131. package/dist/market_adapter/market_adapter.js.map +1 -1
  132. package/dist/market_adapter/merge_lp_data.js +5 -5
  133. package/dist/market_adapter/utils/adapter_client.d.ts +1 -3
  134. package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -1
  135. package/dist/market_adapter/utils/adapter_client.js +1 -14
  136. package/dist/market_adapter/utils/adapter_client.js.map +1 -1
  137. package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -1
  138. package/dist/market_adapter/utils/data_discovery.js +1 -2
  139. package/dist/market_adapter/utils/data_discovery.js.map +1 -1
  140. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +1 -3
  141. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
  142. package/dist/market_adapter/utils/dynamic_grid_snapshot.js +1 -1
  143. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
  144. package/dist/market_adapter/utils/file_lock.d.ts +10 -2
  145. package/dist/market_adapter/utils/file_lock.d.ts.map +1 -1
  146. package/dist/market_adapter/utils/file_lock.js +171 -102
  147. package/dist/market_adapter/utils/file_lock.js.map +1 -1
  148. package/dist/market_adapter/utils/native_history.d.ts +1 -9
  149. package/dist/market_adapter/utils/native_history.d.ts.map +1 -1
  150. package/dist/market_adapter/utils/native_history.js +1 -21
  151. package/dist/market_adapter/utils/native_history.js.map +1 -1
  152. package/dist/modules/account_bots.d.ts +16 -38
  153. package/dist/modules/account_bots.d.ts.map +1 -1
  154. package/dist/modules/account_bots.js +16 -38
  155. package/dist/modules/account_bots.js.map +1 -1
  156. package/dist/modules/account_orders.d.ts +11 -11
  157. package/dist/modules/account_orders.d.ts.map +1 -1
  158. package/dist/modules/account_orders.js +11 -18
  159. package/dist/modules/account_orders.js.map +1 -1
  160. package/dist/modules/bitshares_client.d.ts +5 -8
  161. package/dist/modules/bitshares_client.d.ts.map +1 -1
  162. package/dist/modules/bitshares_client.js +6 -10
  163. package/dist/modules/bitshares_client.js.map +1 -1
  164. package/dist/modules/bots_file_lock.d.ts +8 -5
  165. package/dist/modules/bots_file_lock.d.ts.map +1 -1
  166. package/dist/modules/bots_file_lock.js +8 -5
  167. package/dist/modules/bots_file_lock.js.map +1 -1
  168. package/dist/modules/chain_keys.d.ts +31 -22
  169. package/dist/modules/chain_keys.d.ts.map +1 -1
  170. package/dist/modules/chain_keys.js +31 -22
  171. package/dist/modules/chain_keys.js.map +1 -1
  172. package/dist/modules/chain_orders.d.ts +52 -48
  173. package/dist/modules/chain_orders.d.ts.map +1 -1
  174. package/dist/modules/chain_orders.js +124 -49
  175. package/dist/modules/chain_orders.js.map +1 -1
  176. package/dist/modules/constants.d.ts +17 -13
  177. package/dist/modules/constants.d.ts.map +1 -1
  178. package/dist/modules/constants.js +42 -21
  179. package/dist/modules/constants.js.map +1 -1
  180. package/dist/modules/cr_planner.d.ts +2 -1
  181. package/dist/modules/cr_planner.d.ts.map +1 -1
  182. package/dist/modules/cr_planner.js +1 -1
  183. package/dist/modules/cr_planner.js.map +1 -1
  184. package/dist/modules/credential_policy.d.ts +6 -4
  185. package/dist/modules/credential_policy.d.ts.map +1 -1
  186. package/dist/modules/credential_policy.js +6 -4
  187. package/dist/modules/credential_policy.js.map +1 -1
  188. package/dist/modules/credit_runtime.d.ts.map +1 -1
  189. package/dist/modules/credit_runtime.js +4 -8
  190. package/dist/modules/credit_runtime.js.map +1 -1
  191. package/dist/modules/dexbot_class.d.ts +33 -88
  192. package/dist/modules/dexbot_class.d.ts.map +1 -1
  193. package/dist/modules/dexbot_class.js +36 -68
  194. package/dist/modules/dexbot_class.js.map +1 -1
  195. package/dist/modules/dexbot_cow_runtime.d.ts +7 -7
  196. package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
  197. package/dist/modules/dexbot_cow_runtime.js +7 -7
  198. package/dist/modules/dexbot_cow_runtime.js.map +1 -1
  199. package/dist/modules/dexbot_credential_client.d.ts +3 -3
  200. package/dist/modules/dexbot_credential_client.js +3 -3
  201. package/dist/modules/dexbot_credential_client.js.map +1 -1
  202. package/dist/modules/dexbot_fill_runtime.d.ts +1 -7
  203. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
  204. package/dist/modules/dexbot_fill_runtime.js +1 -9
  205. package/dist/modules/dexbot_fill_runtime.js.map +1 -1
  206. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
  207. package/dist/modules/dexbot_maintenance_runtime.js +3 -1
  208. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
  209. package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
  210. package/dist/modules/dexbot_state_recovery.js +99 -1
  211. package/dist/modules/dexbot_state_recovery.js.map +1 -1
  212. package/dist/modules/graceful_shutdown.d.ts +4 -2
  213. package/dist/modules/graceful_shutdown.d.ts.map +1 -1
  214. package/dist/modules/graceful_shutdown.js +4 -2
  215. package/dist/modules/graceful_shutdown.js.map +1 -1
  216. package/dist/modules/launcher/bot_supervisor.d.ts +1 -1
  217. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
  218. package/dist/modules/launcher/bot_supervisor.js +1 -4
  219. package/dist/modules/launcher/bot_supervisor.js.map +1 -1
  220. package/dist/modules/market_adapter_whitelist.d.ts +1 -2
  221. package/dist/modules/market_adapter_whitelist.d.ts.map +1 -1
  222. package/dist/modules/market_adapter_whitelist.js +1 -4
  223. package/dist/modules/market_adapter_whitelist.js.map +1 -1
  224. package/dist/modules/node_health_cache.d.ts +12 -4
  225. package/dist/modules/node_health_cache.d.ts.map +1 -1
  226. package/dist/modules/node_health_cache.js +13 -13
  227. package/dist/modules/node_health_cache.js.map +1 -1
  228. package/dist/modules/node_manager.d.ts.map +1 -1
  229. package/dist/modules/node_manager.js +3 -6
  230. package/dist/modules/node_manager.js.map +1 -1
  231. package/dist/modules/order/accounting.d.ts +2 -37
  232. package/dist/modules/order/accounting.d.ts.map +1 -1
  233. package/dist/modules/order/accounting.js +2 -64
  234. package/dist/modules/order/accounting.js.map +1 -1
  235. package/dist/modules/order/export.d.ts +1 -37
  236. package/dist/modules/order/export.d.ts.map +1 -1
  237. package/dist/modules/order/export.js +1 -1
  238. package/dist/modules/order/export.js.map +1 -1
  239. package/dist/modules/order/format.d.ts +28 -14
  240. package/dist/modules/order/format.d.ts.map +1 -1
  241. package/dist/modules/order/format.js +73 -18
  242. package/dist/modules/order/format.js.map +1 -1
  243. package/dist/modules/order/grid.d.ts +11 -5
  244. package/dist/modules/order/grid.d.ts.map +1 -1
  245. package/dist/modules/order/grid.js +79 -37
  246. package/dist/modules/order/grid.js.map +1 -1
  247. package/dist/modules/order/grid_reconcile_internal.js +2 -2
  248. package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
  249. package/dist/modules/order/logger_state.d.ts +3 -45
  250. package/dist/modules/order/logger_state.d.ts.map +1 -1
  251. package/dist/modules/order/logger_state.js +3 -55
  252. package/dist/modules/order/logger_state.js.map +1 -1
  253. package/dist/modules/order/manager.d.ts +0 -4
  254. package/dist/modules/order/manager.d.ts.map +1 -1
  255. package/dist/modules/order/manager.js +3 -9
  256. package/dist/modules/order/manager.js.map +1 -1
  257. package/dist/modules/order/sync_engine.d.ts +0 -2
  258. package/dist/modules/order/sync_engine.d.ts.map +1 -1
  259. package/dist/modules/order/sync_engine.js +1 -4
  260. package/dist/modules/order/sync_engine.js.map +1 -1
  261. package/dist/modules/order/utils/math.d.ts +2 -11
  262. package/dist/modules/order/utils/math.d.ts.map +1 -1
  263. package/dist/modules/order/utils/math.js +3 -14
  264. package/dist/modules/order/utils/math.js.map +1 -1
  265. package/dist/modules/order/utils/order.d.ts +1 -17
  266. package/dist/modules/order/utils/order.d.ts.map +1 -1
  267. package/dist/modules/order/utils/order.js +3 -21
  268. package/dist/modules/order/utils/order.js.map +1 -1
  269. package/dist/modules/order/utils/system.d.ts +1 -11
  270. package/dist/modules/order/utils/system.d.ts.map +1 -1
  271. package/dist/modules/order/utils/system.js +3 -3
  272. package/dist/modules/order/utils/system.js.map +1 -1
  273. package/dist/modules/order/utils/validate.d.ts +1 -26
  274. package/dist/modules/order/utils/validate.d.ts.map +1 -1
  275. package/dist/modules/order/utils/validate.js +1 -1
  276. package/dist/modules/order/utils/validate.js.map +1 -1
  277. package/dist/modules/order/working_grid.d.ts +3 -9
  278. package/dist/modules/order/working_grid.d.ts.map +1 -1
  279. package/dist/modules/order/working_grid.js +3 -11
  280. package/dist/modules/order/working_grid.js.map +1 -1
  281. package/dist/modules/runtime_settings.js +1 -1
  282. package/dist/modules/runtime_settings.js.map +1 -1
  283. package/dist/pm2.d.ts +1 -1
  284. package/dist/pm2.d.ts.map +1 -1
  285. package/dist/pm2.js +1 -4
  286. package/dist/pm2.js.map +1 -1
  287. package/dist/scripts/analyze-orders.d.ts.map +1 -1
  288. package/dist/scripts/analyze-orders.js +36 -45
  289. package/dist/scripts/analyze-orders.js.map +1 -1
  290. package/dist/scripts/sync-version.js +22 -0
  291. package/dist/scripts/sync-version.js.map +1 -1
  292. package/ecosystem.config.cjs +32 -0
  293. package/package.json +3 -1
  294. package/scripts/README.md +4 -4
  295. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
  296. package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
  297. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
  298. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
  299. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
  300. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
  301. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
  302. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
  303. package/dist/market_adapter/index.d.ts +0 -32
  304. package/dist/market_adapter/index.d.ts.map +0 -1
  305. package/dist/market_adapter/index.js +0 -39
  306. package/dist/market_adapter/index.js.map +0 -1
  307. package/dist/scripts/fix-err-message.d.ts +0 -3
  308. package/dist/scripts/fix-err-message.d.ts.map +0 -1
  309. package/dist/scripts/fix-err-message.js +0 -193
  310. package/dist/scripts/fix-err-message.js.map +0 -1
  311. /package/dist/{analysis/trend_detection → market_adapter/core/signals}/hurst_analyzer.d.ts +0 -0
  312. /package/dist/{analysis/trend_detection → market_adapter/core/signals}/permutation_entropy_analyzer.d.ts +0 -0
@@ -317,7 +317,7 @@ type ConstraintSet = {
317
317
 
318
318
  ## Public API
319
319
 
320
- All functions below are implemented and exported from the modules cited under "Core Types" or their headers. Signatures reflect the runtime types; see [../modules/types.ts](../modules/types.ts) for the authoritative TypeScript interfaces.
320
+ All functions below are implemented in the modules cited under "Core Types" or their headers and are reachable through the adapters/factories they document. Standalone names are exported from the cited modules; methods like `getBotSettings`, `previewBotSettingsUpdate`, `applyBotSettingsPatch`, and `getClawProfileContext` are closures returned by `createDexbotProfileAdapter` (not module-level exports). Signatures reflect the runtime types; see [../modules/types.ts](../modules/types.ts) for the authoritative TypeScript interfaces.
321
321
 
322
322
  ### 1. `createRuntimeContext(options)`
323
323
 
@@ -63,7 +63,7 @@ When a trend signal is available, the assessor checks whether the position direc
63
63
 
64
64
  ## CR Adjustment Planning
65
65
 
66
- CR math is handled by the shared planner at `modules/cr_planner.ts` (root level, not claw), which provides `debtDeltaForTargetCr()` and `collateralDeltaForTargetCr()`. Claw's position health module consumes these through the planner interface. Any executed CR adjustment should be followed by a grid rebuild, because the available-funds baseline is no longer valid after the debt or collateral leg changes.
66
+ CR math is handled by the shared planner at `modules/cr_planner.ts` (root level, not claw), which provides `debtDeltaForTargetCr()` and `collateralDeltaForTargetCr()`. Any executed CR adjustment should be followed by a grid rebuild, because the available-funds baseline is no longer valid after the debt or collateral leg changes.
67
67
 
68
68
  ## Decision Loop Planning
69
69
 
@@ -108,7 +108,7 @@ npm run service:position-watch -- --account your-account
108
108
 
109
109
  The executable behavior lives in the modules. This document should be kept aligned with:
110
110
 
111
- - `../cr_planner.ts` (root level)
111
+ - `modules/cr_planner.ts` (root level)
112
112
  - `modules/position_health.ts`
113
113
  - `modules/position_discovery.ts`
114
114
  - `modules/decision_loop.ts`
@@ -1,6 +1,4 @@
1
- function shellQuote(value: any) {
2
- return `'${String(value).replace(/'/g, `'\"'\"'`)}'`;
3
- }
1
+ import { shellQuote } from './skill_utils.js';
4
2
 
5
3
  const SUPPORTED_RUNTIMES = ['openclaw', 'hermes', 'openfang', 'nanobot', 'picoclaw', 'nanoclaw', 'zeroclaw', 'nullclaw', 'memu'];
6
4
 
@@ -241,8 +241,7 @@ async function launcherPm2Start(botName: string | null, options: Record<string,
241
241
  }
242
242
 
243
243
  // Generate ecosystem config and get apps array
244
- getPM2Module().generateEcosystemConfig({ clawOnly: false, exitOnError: false });
245
- const apps = getPM2Module().buildEcosystemApps({ clawOnly: false });
244
+ const apps = getPM2Module().generateEcosystemConfig({ clawOnly: false, exitOnError: false });
246
245
 
247
246
  // Filter apps if specific bot requested
248
247
  let appsToStart = apps;
@@ -448,5 +447,5 @@ async function launcherUnlockStart(botName: string | null, options: Record<strin
448
447
  };
449
448
  }
450
449
 
451
- export { launcherRun, launcherStart, launcherDrystart, launcherReset, launcherDisable, launcherPm2Start, launcherPm2Stop, launcherPm2Delete, launcherPm2Restart, launcherClawOnly, launcherUnlockStart }
450
+ export { launcherRun, launcherStart, launcherDrystart, launcherReset, launcherDisable, launcherPm2Start, launcherPm2Stop, launcherPm2Delete, launcherPm2Restart }
452
451
 
@@ -7,7 +7,7 @@ import { buildBridgeCommand, buildSkillTomlLines, createTool, normalizeRepoRoot,
7
7
  const storage = getStorage();
8
8
 
9
9
  function normalizeClawRepoRoot(repoRoot: string) {
10
- return normalizeRepoRoot('claw-skill-md', repoRoot);
10
+ return normalizeRepoRoot(repoRoot);
11
11
  }
12
12
 
13
13
  function buildToolSummary(runtimeName: string) {
@@ -30,7 +30,7 @@ import { getErrorMessage } from '../../modules/utils/errors.js';
30
30
  let KalmanTrendAnalyzer: any = null;
31
31
  function getTrendAnalyzer() {
32
32
  if (!KalmanTrendAnalyzer) {
33
- KalmanTrendAnalyzer = require('../../analysis/trend_detection/kalman_trend_analyzer').KalmanTrendAnalyzer;
33
+ KalmanTrendAnalyzer = require('../../market_adapter/core/signals/kalman_trend_analyzer').KalmanTrendAnalyzer;
34
34
  }
35
35
  return KalmanTrendAnalyzer;
36
36
  }
@@ -4,7 +4,7 @@ import { getStorage } from '../../modules/storage/index.js';
4
4
  import { DEFAULT_CONFIG, GRID_LIMITS, INCREMENT_BOUNDS } from '../../modules/constants.js';
5
5
  import { resolveRelativePrice } from '../../modules/order/utils/math.js';
6
6
  import { Config } from '../../modules/config.js';
7
- import { PATHS, getRecalculateTriggerFile } from '../../modules/paths.js';
7
+ import { PATHS } from '../../modules/paths.js';
8
8
  import { writeJsonFileAtomic as baseWriteJsonFileAtomic } from '../../modules/bots_file_lock.js';
9
9
  import { acquireFileLock } from '../../market_adapter/utils/file_lock.js';
10
10
  import { assertNoDuplicateBotKeys } from '../../modules/bot_settings.js';
@@ -1235,34 +1235,6 @@ function createDexbotProfileAdapter(profileRoot: string | null, options: Partial
1235
1235
  });
1236
1236
  }
1237
1237
 
1238
- async function listOrderArtifacts(forceReload = false) {
1239
- const bundle = await loadBundle(forceReload);
1240
- return Promise.all(bundle.orderFiles.map(async (fileName: any) => {
1241
- const fullPath = path.join(bundle.ordersDir, fileName);
1242
- if (fileName.endsWith('.json')) {
1243
- return { fileName, fullPath, json: await readJsonFile(fullPath) };
1244
- }
1245
- return { fileName, fullPath, json: null };
1246
- }));
1247
- }
1248
-
1249
- function consumeTrigger(botKey: any) {
1250
- const triggerPath = path.join(getProfilesDir(), `recalculate.${botKey}.trigger`);
1251
- const trigger = readTriggerFile(triggerPath);
1252
- if (!trigger.exists) {
1253
- return { consumed: false, payload: null };
1254
- }
1255
- storage.unlink(triggerPath);
1256
- return { consumed: true, payload: trigger.payload };
1257
- }
1258
-
1259
- function writeTrigger(botKey: any, payload: any = null) {
1260
- const triggerPath = path.join(getProfilesDir(), `recalculate.${botKey}.trigger`);
1261
- const content = payload ? JSON.stringify(payload, null, 2) : '';
1262
- storage.ensureDir(path.dirname(triggerPath));
1263
- writeTextPayload(triggerPath, content);
1264
- }
1265
-
1266
1238
  async function updateBotSettings(identifier: any, patch: any) {
1267
1239
  if (!isPlainObject(patch)) {
1268
1240
  throw new Error('patch must be a non-null object');
@@ -1320,19 +1292,16 @@ function createDexbotProfileAdapter(profileRoot: string | null, options: Partial
1320
1292
  return {
1321
1293
  buildClawProfileContext: (bundle: any, contextOptions = {}) => buildClawProfileContext(bundle, contextOptions),
1322
1294
  applyBotSettingsPatch,
1323
- consumeTrigger,
1324
1295
  findBot,
1325
1296
  getBotBundle,
1326
1297
  getBotSettings,
1327
1298
  getClawProfileContext,
1328
1299
  getProfilesDir,
1329
1300
  listBots,
1330
- listOrderArtifacts,
1331
1301
  loadBundle,
1332
1302
  previewBotSettingsUpdate,
1333
1303
  resolveProfilesDir: () => resolveProfilesDir(profileRoot || options.profileRoot),
1334
- updateBotSettings,
1335
- writeTrigger
1304
+ updateBotSettings
1336
1305
  };
1337
1306
  }
1338
1307
 
@@ -10,45 +10,16 @@
10
10
 
11
11
 
12
12
  import { getAsset, getBackingAsset, getBitassetData, dbCall } from './chain_queries.js';
13
- import { loadDexbotOrderUtils } from './dexbot_bridge.js';
13
+ import { computeBtsPerMpa } from './mpa_utils.js';
14
14
  import { roundTo } from '../../modules/utils/math_utils.js';
15
15
  'use strict';
16
16
 
17
17
 
18
- function getBlockchainToFloat() {
19
- return loadDexbotOrderUtils().blockchainToFloat;
20
- }
21
-
22
18
  /**
23
19
  * Extract BTS-per-MPA from the settlement price object.
24
- * Replicates the logic in position_manager (computeBtsPerMpaFromSettlement)
25
- * but as a standalone utility.
20
+ * Re-exported alias of the canonical computeBtsPerMpa in mpa_utils.
26
21
  */
27
- function parseBtsPerMpa(settlementPrice: any, mpaAsset: any, backingAsset: any) {
28
- const base = settlementPrice?.base;
29
- const quote = settlementPrice?.quote;
30
- if (!base || !quote) return null;
31
-
32
- const blockchainToFloat = getBlockchainToFloat();
33
- const baseAmount = blockchainToFloat(
34
- base.amount,
35
- base.asset_id === mpaAsset.id ? mpaAsset.precision : backingAsset.precision
36
- );
37
- const quoteAmount = blockchainToFloat(
38
- quote.amount,
39
- quote.asset_id === mpaAsset.id ? mpaAsset.precision : backingAsset.precision
40
- );
41
- if (!baseAmount || !quoteAmount) return null;
42
-
43
- // BTS per MPA
44
- if (base.asset_id === backingAsset.id && quote.asset_id === mpaAsset.id) {
45
- return baseAmount / quoteAmount;
46
- }
47
- if (base.asset_id === mpaAsset.id && quote.asset_id === backingAsset.id) {
48
- return quoteAmount / baseAmount;
49
- }
50
- return null;
51
- }
22
+ const parseBtsPerMpa = computeBtsPerMpa;
52
23
 
53
24
  /**
54
25
  * Fetch the current feed price for an MPA.
@@ -188,5 +188,5 @@ function describeModeChoice(mode: string) {
188
188
  return descriptions[mode] || mode;
189
189
  }
190
190
 
191
- export { normalizeMode, detectMode, setPreferredMode, loadConfig, saveConfig, hasActiveBots, describeModeChoice }
191
+ export { normalizeMode, detectMode, setPreferredMode, describeModeChoice }
192
192
 
@@ -2,7 +2,7 @@ import { hasProcess } from '../../modules/env.js';
2
2
  import { Config } from '../../modules/config.js';
3
3
  import { runtime } from '../../modules/runtime.js';
4
4
 
5
- export function writeMessage(message: any) {
5
+ function writeMessage(message: any) {
6
6
  if (!hasProcess()) {
7
7
  return Promise.reject(new Error('MCP stdio transport not available in this environment'));
8
8
  }
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  import { getAsset, getBackingAsset } from './chain_queries.js';
4
+ import { loadDexbotOrderUtils } from './dexbot_bridge.js';
4
5
 
5
6
  const CORE_SYMBOL = 'BTS';
6
7
 
@@ -27,5 +28,39 @@ async function requireBtsBackedMpa(mpaSymbolOrId: any) {
27
28
  };
28
29
  }
29
30
 
30
- export { CORE_SYMBOL, requireBtsBackedMpa }
31
+ function getBlockchainToFloat() {
32
+ return loadDexbotOrderUtils().blockchainToFloat;
33
+ }
34
+
35
+ /**
36
+ * Compute BTS-per-MPA from a settlement price object.
37
+ * Canonical implementation shared by position discovery, position manager,
38
+ * and the feed price source.
39
+ */
40
+ function computeBtsPerMpa(settlementPrice: any, mpaAsset: any, backingAsset: any) {
41
+ const base = settlementPrice?.base;
42
+ const quote = settlementPrice?.quote;
43
+ if (!base || !quote) return null;
44
+
45
+ const blockchainToFloat = getBlockchainToFloat();
46
+ const baseAmount = blockchainToFloat(
47
+ base.amount,
48
+ base.asset_id === mpaAsset.id ? mpaAsset.precision : backingAsset.precision
49
+ );
50
+ const quoteAmount = blockchainToFloat(
51
+ quote.amount,
52
+ quote.asset_id === mpaAsset.id ? mpaAsset.precision : backingAsset.precision
53
+ );
54
+ if (!baseAmount || !quoteAmount) return null;
55
+
56
+ if (base.asset_id === backingAsset.id && quote.asset_id === mpaAsset.id) {
57
+ return baseAmount / quoteAmount;
58
+ }
59
+ if (base.asset_id === mpaAsset.id && quote.asset_id === backingAsset.id) {
60
+ return quoteAmount / baseAmount;
61
+ }
62
+ return null;
63
+ }
64
+
65
+ export { CORE_SYMBOL, computeBtsPerMpa, requireBtsBackedMpa }
31
66
 
@@ -10,6 +10,7 @@
10
10
 
11
11
 
12
12
  import { loadDexbotOrderUtils } from './dexbot_bridge.js';
13
+ import { computeBtsPerMpa } from './mpa_utils.js';
13
14
  import { roundTo } from '../../modules/utils/math_utils.js';
14
15
  'use strict';
15
16
 
@@ -19,34 +20,6 @@ function getBlockchainToFloat() {
19
20
  return loadDexbotOrderUtils().blockchainToFloat;
20
21
  }
21
22
 
22
- /**
23
- * Compute BTS-per-MPA from settlement price.
24
- */
25
- function computeBtsPerMpa(settlementPrice: any, mpaAsset: any, backingAsset: any) {
26
- const base = settlementPrice?.base;
27
- const quote = settlementPrice?.quote;
28
- if (!base || !quote) return null;
29
-
30
- const blockchainToFloat = getBlockchainToFloat();
31
- const baseAmount = blockchainToFloat(
32
- base.amount,
33
- base.asset_id === mpaAsset.id ? mpaAsset.precision : backingAsset.precision
34
- );
35
- const quoteAmount = blockchainToFloat(
36
- quote.amount,
37
- quote.asset_id === mpaAsset.id ? mpaAsset.precision : backingAsset.precision
38
- );
39
- if (!baseAmount || !quoteAmount) return null;
40
-
41
- if (base.asset_id === backingAsset.id && quote.asset_id === mpaAsset.id) {
42
- return baseAmount / quoteAmount;
43
- }
44
- if (base.asset_id === mpaAsset.id && quote.asset_id === backingAsset.id) {
45
- return quoteAmount / baseAmount;
46
- }
47
- return null;
48
- }
49
-
50
23
  /**
51
24
  * Normalize a raw call order into a position object compatible with
52
25
  * assessPosition() from position_health.ts.
@@ -123,17 +123,6 @@ function assessPosition(position: any, trendSignal: Record<string, any> | null =
123
123
  return assessment;
124
124
  }
125
125
 
126
- /**
127
- * Assess all positions from a PositionManager state.
128
- *
129
- * @param {Array} positions – Array of position objects
130
- * @param {Object} [trendSignal] – Optional trend signal to apply to all
131
- * @returns {Array} Array of health assessments
132
- */
133
- function assessAllPositions(positions: any[], trendSignal: Record<string, any> | null = null) {
134
- return (positions || []).map((p) => assessPosition(p, trendSignal));
135
- }
136
-
137
126
  /**
138
127
  * Parse a ratio value from a string (e.g. "3x") or numeric price ratio.
139
128
  * Returns null if the value cannot be parsed.
@@ -155,14 +144,6 @@ function parseRatioValue(value: any, referencePrice: any, mode: string) {
155
144
  return mode === 'min' ? reference / numeric : numeric / reference;
156
145
  }
157
146
 
158
- /**
159
- * Format a numeric ratio as a human-readable multiplier string (e.g. 3.00x).
160
- */
161
- function formatRatioAsMultiplier(ratio: any) {
162
- const rounded = roundToDecimals(ratio, 2);
163
- return `${rounded}x`;
164
- }
165
-
166
147
  /**
167
148
  * Classify a price range ratio into a descriptive category.
168
149
  * Categories: very_competitive (< 2), competitive (2–3), conservative (3–3.25), very_conservative (> 3.25).
@@ -356,5 +337,5 @@ function computeOrderWeightBias(trend = 'NEUTRAL', confidence = 0) {
356
337
  };
357
338
  }
358
339
 
359
- export { CR_ZONES, assessAllPositions, assessPosition, checkTrendAlignment, classifyCrZone, classifyPriceRangeRatio, computePriceRangeRatioPlan, computeOrderWeightBias, crWeight, trendWeight }
340
+ export { CR_ZONES, assessPosition, checkTrendAlignment, classifyCrZone, classifyPriceRangeRatio, computePriceRangeRatioPlan, computeOrderWeightBias, crWeight, trendWeight }
360
341
 
@@ -3,7 +3,7 @@ import { getStorage } from '../../modules/storage/index.js';
3
3
  import { path } from '../../modules/path_api.js';
4
4
  import { PATHS } from '../../modules/paths.js';
5
5
  import { Config } from '../../modules/config.js';
6
- import { requireBtsBackedMpa } from './mpa_utils.js';
6
+ import { requireBtsBackedMpa, computeBtsPerMpa } from './mpa_utils.js';
7
7
  import { listenForFills } from './chain_actions.js';
8
8
  import { writeJsonFileAtomic } from './dexbot_profiles.js';
9
9
  import { loadDexbotOrderUtils } from './dexbot_bridge.js';
@@ -12,7 +12,7 @@ const storage = getStorage();
12
12
  import { closeShortOnBts, openShortOnBts, placeTakeProfitBuyOrderOnBts } from './short_mpa_strategy.js';
13
13
  import { getAsset, getBackingAsset, getBalances, getBitassetData, getFullAccount } from './chain_queries.js';
14
14
 
15
- import type { ShortPositionOptions, PositionManagerOptions, PositionData, AssetData, ChainPosition } from './types.js';
15
+ import type { ShortPositionOptions, PositionManagerOptions } from './types.js';
16
16
 
17
17
  function getBlockchainToFloat() {
18
18
  return loadDexbotOrderUtils().blockchainToFloat;
@@ -263,31 +263,6 @@ function refreshPositionPnl(position: any) {
263
263
  position.pnl.updatedAt = nowIso();
264
264
  }
265
265
 
266
- function computeBtsPerMpaFromSettlement(settlementPrice: any, mpaAsset: any, backingAsset: any) {
267
- const base = settlementPrice?.base;
268
- const quote = settlementPrice?.quote;
269
- if (!base || !quote) {
270
- return null;
271
- }
272
-
273
- const blockchainToFloat = getBlockchainToFloat();
274
- const baseAmount = blockchainToFloat(base.amount, base.asset_id === mpaAsset.id ? mpaAsset.precision : backingAsset.precision);
275
- const quoteAmount = blockchainToFloat(quote.amount, quote.asset_id === mpaAsset.id ? mpaAsset.precision : backingAsset.precision);
276
- if (!baseAmount || !quoteAmount) {
277
- return null;
278
- }
279
-
280
- if (base.asset_id === backingAsset.id && quote.asset_id === mpaAsset.id) {
281
- return baseAmount / quoteAmount;
282
- }
283
-
284
- if (base.asset_id === mpaAsset.id && quote.asset_id === backingAsset.id) {
285
- return quoteAmount / baseAmount;
286
- }
287
-
288
- return null;
289
- }
290
-
291
266
  function normalizeCallPosition(callOrder: any, mpaAsset: any, backingAsset: any, bitassetData: any) {
292
267
  if (!callOrder) {
293
268
  return {
@@ -303,7 +278,7 @@ function normalizeCallPosition(callOrder: any, mpaAsset: any, backingAsset: any,
303
278
  const blockchainToFloat = getBlockchainToFloat();
304
279
  const debtAmount = blockchainToFloat(callOrder.debt, mpaAsset.precision);
305
280
  const collateralAmount = blockchainToFloat(callOrder.collateral, backingAsset.precision);
306
- const btsPerMpa = computeBtsPerMpaFromSettlement(bitassetData?.current_feed?.settlement_price, mpaAsset, backingAsset);
281
+ const btsPerMpa = computeBtsPerMpa(bitassetData?.current_feed?.settlement_price, mpaAsset, backingAsset);
307
282
  const debtValueInBts = debtAmount && btsPerMpa ? debtAmount * btsPerMpa : 0;
308
283
  const collateralRatio = debtValueInBts > 0 ? collateralAmount / debtValueInBts : null;
309
284
 
@@ -5,7 +5,7 @@ import { path } from '../../modules/path_api.js';
5
5
  import { PATHS } from '../../modules/paths.js';
6
6
  const { version: DEXBOT_VERSION } = require(path.join(PATHS.PROJECT_ROOT, 'package.json'));
7
7
 
8
- export function normalizeRepoRoot(variableName: string, repoRoot?: string) {
8
+ export function normalizeRepoRoot(repoRoot?: string) {
9
9
  return path.resolve(repoRoot || PATHS.CLAW.DIR);
10
10
  }
11
11
 
@@ -161,59 +161,6 @@ export interface PositionManagerOptions {
161
161
  statePath?: string;
162
162
  }
163
163
 
164
- export interface VariantBridgeOptions {
165
- runtime?: { name?: string };
166
- runtimeName?: string;
167
- }
168
-
169
- export interface AssetData {
170
- id: string;
171
- symbol: string;
172
- precision: number;
173
- }
174
-
175
- export interface PriceData {
176
- base: { amount: number; asset_id: string };
177
- quote: { amount: number; asset_id: string };
178
- }
179
-
180
- export interface ChainOrder {
181
- id: string;
182
- for_sale: number;
183
- sell_price: PriceData;
184
- filled_amount?: number;
185
- }
186
-
187
- export interface ChainPosition {
188
- id: string;
189
- borrower: string;
190
- collateral: number;
191
- debt: number;
192
- call_price: PriceData;
193
- target_collateral_ratio?: number;
194
- }
195
-
196
- export interface FillEvent {
197
- order_id: string;
198
- pays: { amount: number; asset_id: string };
199
- receives: { amount: number; asset_id: string };
200
- is_maker: boolean;
201
- }
202
-
203
- export interface PositionData {
204
- id: string;
205
- market: string;
206
- mpaSymbol: string;
207
- onChain: {
208
- debtAmount: number;
209
- collateralAmount: number;
210
- sellPriceInBts?: number;
211
- targetCollateralRatio?: number | null;
212
- };
213
- accountName?: string;
214
- privateKey?: string;
215
- }
216
-
217
164
  export interface ClawProfileBundle {
218
165
  profileRoot?: string;
219
166
  botsFile?: string;
package/claw/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dexbot2-claw",
3
- "version": "1.4.13",
3
+ "version": "1.4.14",
4
4
  "private": true,
5
5
  "description": "Claw bridge and runtime integration layer for BitShares and DEXBot2.",
6
6
  "type": "module",
@@ -2,7 +2,7 @@
2
2
  "id": "bitshares-claw",
3
3
  "name": "BitShares Claw",
4
4
  "description": "Native BitShares and DEXBot2 tools from the DEXBot2 claw integration",
5
- "version": "1.4.13",
5
+ "version": "1.4.14",
6
6
  "skills": [
7
7
  "skills"
8
8
  ],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bitshares-claw-openclaw-plugin",
3
3
  "private": true,
4
- "version": "1.4.13",
4
+ "version": "1.4.14",
5
5
  "type": "module",
6
6
  "main": "index.js"
7
7
  }
@@ -11,7 +11,7 @@ HONEST.Assets are Market Pegged Assets (MPAs) on the BitShares DEX backed by BTS
11
11
 
12
12
  All HONEST.Assets share the same parameters except HONEST.USD which has a higher taker fee.
13
13
 
14
- Order operation fees (create, update, cancel) are approximately 0.1 BTS each.
14
+ Order operation fees (create, update, cancel) are charged in BTS and are dynamic — the bot caches them at startup in `profiles/fee_cache.json` (e.g. create 0.4826, update 0.375, cancel 0.00482 BTS).
15
15
 
16
16
  ## Collateral
17
17
 
@@ -43,7 +43,7 @@ A position profits when the market moves in the direction the position is expose
43
43
  - **Short** profits when the MPA price (in BTS) decreases — the MPA bought back cheaper than it was sold
44
44
  - **Long** profits when the MPA price (in BTS) increases — the MPA sold higher than it was bought
45
45
 
46
- The shared trend-detection service provides signals based on AMA deviation from the feed price and the instantaneous premium/discount. These signals indicate which direction the smoothed market is moving relative to the feed anchor.
46
+ The shared trend-detection service provides signals based on a Kalman-filter trend state (velocity/displacement from the order-book mid price relative to the feed anchor) plus the instantaneous premium/discount. These signals indicate which direction the smoothed market is moving relative to the feed anchor.
47
47
 
48
48
  Combining position direction with the trend signal:
49
49
 
@@ -182,7 +182,7 @@ Total BTS
182
182
  ├── Pending (proceeds from fills, not yet redeployed)
183
183
  │ └── Target: minimize time in this state
184
184
  └── Reserve (fee budget for operations)
185
- └── ~0.1 BTS per order operation
185
+ └── BTS fees per order op (dynamic — see `profiles/fee_cache.json`; e.g. create 0.48, update 0.38, cancel 0.005 BTS)
186
186
  ```
187
187
 
188
188
  MPA holdings follow the same logic — MPA sitting in wallet balance is idle. MPA placed as a sell order or used to repay debt is working.
@@ -11,12 +11,12 @@ Focus on the practical module split:
11
11
 
12
12
  Keep the implementation reference explicit:
13
13
 
14
- - DEXBot2 shows a real Node.js/CommonJS bot runtime with shared reads, per-account signing, persistence, and reconciliation
14
+ - DEXBot2 shows a real Node.js/ES Modules bot runtime with shared reads, per-account signing, persistence, and reconciliation
15
15
  - AI-Bot should reuse that pattern rather than duplicating it
16
16
 
17
17
  Preferred baseline:
18
18
 
19
- - `Node.js` / CommonJS first
19
+ - `Node.js` / ES Modules first (the DEXBot2 codebase is ESM, `"type": "module"`, Node >= 22.12)
20
20
  - DEXBot2 native BitShares client for chain connectivity
21
21
  - shared read connection for market and account state
22
22
  - dedicated account client for signing and broadcast
@@ -2,34 +2,41 @@
2
2
 
3
3
  ## Scope
4
4
 
5
- This is the shared DEXBot/Claw trend service. It is independent of margin-trading and should be used for any bot that needs candle-driven signal generation, parameter tuning, and bot-setting updates.
5
+ This is the shared DEXBot/Claw trend service. It is independent of margin-trading and should be used for any bot that needs signal generation, parameter tuning, and bot-setting updates.
6
6
 
7
7
  ## Signal Flow
8
8
 
9
- 1. `market_adapter/market_adapter.ts` keeps candles current and emits the per-bot center/state snapshot.
10
- 2. `analysis/trend_detection/kalman_trend_analyzer.ts` turns candle input plus feed price into trend output.
11
- 3. The service monitors the signal output, premium/discount, and price-ratio context.
9
+ 1. `claw/modules/feed_price_source.ts` fetches the **order-book mid price** (`get_order_book`) and the **feed price** for a market, computing the premium/discount.
10
+ 2. `claw/modules/decision_loop.ts` feeds those prices into `KalmanTrendAnalyzer` (per market) and uses the resulting trend for position health assessment.
11
+ 3. `market_adapter/core/signals/kalman_trend_analyzer.ts` is the canonical analyzer implementation; `analysis/trend_detection/kalman_trend_analyzer.ts` re-exports it so production, analysis tooling, and tests resolve one shared module.
12
12
  4. Claw applies supported setting changes through `bot-settings-preview` and `bot-settings-apply`.
13
13
 
14
+ Note: the analyzer input is the live order-book mid price plus the feed price — **not** candles.
15
+
14
16
  ## Inputs
15
17
 
16
- - Candle history from the market adapter
17
- - Feed price / settlement reference
18
- - Trend analyzer parameters:
19
- - `erPeriod`
20
- - `fastPeriod`
21
- - `slowPeriod`
22
- - `thresholdPercent`
23
- - `minBarsForConfirmation`
24
- - `deadZonePercent`
18
+ - Order-book mid price from `fetchMidPrice('BTS', mpaSymbol)`
19
+ - Feed price / settlement reference (`fetchFeedPrice`)
20
+ - Trend analyzer configuration (`KalmanTrendConfig`):
21
+ - `rNoise` — measurement noise (default `0.05`)
22
+ - `qTactical` — tactical filter process noise (default `qNoise` or `0.01`)
23
+ - `qModal` — modal filter process noise (default `qNoise` or `0.0001`)
24
+ - `qNoise` — shared process-noise fallback for both filters
25
+ - `beamCount` — max projected trajectory beams (default `100`)
26
+ - `dt` — time step per update (default `1`)
27
+ - `warmupBars` — warmup updates before `isReady` (default `20`)
25
28
  - Bot settings fields that the signal may update:
26
29
  - `weightDistribution`
30
+
27
31
  ## Outputs
28
32
 
29
- - `UP`, `DOWN`, or `NEUTRAL`
30
- - Confidence score
33
+ - `trend`: `UP`, `DOWN`, or `FLAT` (from tactical velocity sign)
34
+ - `signal`: `BULLISH_DISPLACEMENT`, `BEARISH_DISPLACEMENT`, `EQUILIBRIUM`, or `NEUTRAL`
35
+ - `confidence`: 0–100 (warmup progress + velocity magnitude)
36
+ - `velocityPct` / `velocityFilteredPct` — raw and smoothed velocity
37
+ - `displacementPct` — price offset from the modal (long-term) estimate
31
38
  - Premium / discount signal
32
- - Oscillation / range context
39
+ - Oscillation / range context (beams + projections)
33
40
  - Proposed bot-setting patch for the next cycle
34
41
 
35
42
  ## Control Surfaces
@@ -42,4 +49,4 @@ This is the shared DEXBot/Claw trend service. It is independent of margin-tradin
42
49
 
43
50
  ## Operating Rule
44
51
 
45
- Treat the trend signal as configuration input, not as trading logic. The shared service can tune bot settings and trigger recalculation, but it should not own order placement or margin-position policy.
52
+ Treat the trend signal as configuration input, not as trading logic. The shared service can tune bot settings and trigger recalculation, but it should not own order placement or margin-position policy.