dexbot 1.6.11 → 1.6.12

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 (354) hide show
  1. package/CHANGELOG.md +35 -4
  2. package/README.md +2 -1
  3. package/analysis/README.md +2 -0
  4. package/analysis/tradingview/README.md +1 -1
  5. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +3 -3
  6. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
  7. package/claw/modules/chain_broadcast.ts +7 -1
  8. package/claw/modules/claw_launcher.ts +1 -1
  9. package/claw/modules/launcher_mode_detector.ts +9 -2
  10. package/claw/package.json +1 -1
  11. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  12. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  13. package/dist/analysis/account_resolver.d.ts +1 -1
  14. package/dist/analysis/account_resolver.js +2 -1
  15. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
  16. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -7
  17. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
  18. package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
  19. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
  20. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
  21. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
  22. package/dist/analysis/analyze_args.d.ts +31 -0
  23. package/dist/analysis/analyze_args.js +41 -0
  24. package/dist/analysis/analyze_dynamic_weight.js +7 -17
  25. package/dist/analysis/analyze_kalman.js +7 -17
  26. package/dist/analysis/analyze_regime.js +7 -17
  27. package/dist/analysis/analyze_regime_windows.js +8 -18
  28. package/dist/analysis/analyze_risk_profile.js +8 -18
  29. package/dist/analysis/analyze_trade_heatmap.js +7 -17
  30. package/dist/analysis/analyze_volatility.js +7 -17
  31. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +220 -12
  32. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +6 -5
  33. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
  34. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +11 -63
  35. package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
  36. package/dist/analysis/bot_fitting/shared_utils.js +2 -2
  37. package/dist/analysis/bot_key_utils.d.ts +18 -10
  38. package/dist/analysis/bot_key_utils.js +7 -4
  39. package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
  40. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
  41. package/dist/analysis/chain_pool.d.ts +3 -1
  42. package/dist/analysis/chart_ui.d.ts +5 -2
  43. package/dist/analysis/chart_ui.js +6 -3
  44. package/dist/analysis/chart_utils.d.ts +5 -5
  45. package/dist/analysis/chart_utils.js +9 -0
  46. package/dist/analysis/fills_cache.d.ts +1 -1
  47. package/dist/analysis/fills_source.d.ts +2 -2
  48. package/dist/analysis/fills_source.js +14 -12
  49. package/dist/analysis/grid_correction_check.d.ts +1 -1
  50. package/dist/analysis/grid_correction_check.js +12 -11
  51. package/dist/analysis/math_utils.d.ts +7 -6
  52. package/dist/analysis/math_utils.js +5 -8
  53. package/dist/analysis/pnl_report.js +29 -29
  54. package/dist/analysis/price_sources.d.ts +8 -8
  55. package/dist/analysis/price_sources.js +5 -4
  56. package/dist/analysis/resolve_bot_accounts.js +2 -2
  57. package/dist/analysis/resolve_source.d.ts +1 -1
  58. package/dist/analysis/trade_profitability.d.ts +23 -2
  59. package/dist/analysis/trade_profitability.js +50 -50
  60. package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
  61. package/dist/analysis/tradingview/analyze_tradingview.js +6 -5
  62. package/dist/analysis/tradingview/grid_reset_config.d.ts +41 -32
  63. package/dist/analysis/tradingview/grid_reset_config.js +23 -11
  64. package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -9
  65. package/dist/analysis/tradingview/grid_reset_sim.js +4 -3
  66. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
  67. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +18 -19
  68. package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -1
  69. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +5 -5
  70. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
  71. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +5 -4
  72. package/dist/analysis/trend_detection/huber_scale_variants.d.ts +9 -3
  73. package/dist/analysis/trend_detection/huber_scale_variants.js +4 -4
  74. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
  75. package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
  76. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
  77. package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
  78. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
  79. package/dist/credential-daemon.js +34 -20
  80. package/dist/dexbot.js +11 -11
  81. package/dist/market_adapter/candle_utils.d.ts +22 -18
  82. package/dist/market_adapter/candle_utils.js +24 -20
  83. package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
  84. package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
  85. package/dist/market_adapter/core/kibana_candles.d.ts +53 -18
  86. package/dist/market_adapter/core/kibana_candles.js +9 -7
  87. package/dist/market_adapter/core/kibana_client.d.ts +9 -1
  88. package/dist/market_adapter/core/kibana_client.js +8 -7
  89. package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
  90. package/dist/market_adapter/core/market_adapter_service.d.ts +284 -117
  91. package/dist/market_adapter/core/market_adapter_service.js +137 -113
  92. package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
  93. package/dist/market_adapter/core/strategies/ama.js +2 -4
  94. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
  95. package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
  96. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
  97. package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
  98. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
  99. package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
  100. package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +34 -6
  101. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +7 -7
  102. package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
  103. package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
  104. package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
  105. package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
  106. package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
  107. package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
  108. package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
  109. package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
  110. package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
  111. package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
  112. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +96 -224
  113. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
  114. package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
  115. package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
  116. package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
  117. package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
  118. package/dist/market_adapter/inputs/kibana_source.js +2 -2
  119. package/dist/market_adapter/inputs/window_cache.d.ts +99 -94
  120. package/dist/market_adapter/inputs/window_cache.js +8 -8
  121. package/dist/market_adapter/interval_utils.d.ts +4 -4
  122. package/dist/market_adapter/log_format.d.ts +6 -6
  123. package/dist/market_adapter/log_format.js +28 -21
  124. package/dist/market_adapter/lp_chart_core.d.ts +22 -1
  125. package/dist/market_adapter/lp_chart_core.js +26 -192
  126. package/dist/market_adapter/lp_chart_runner.d.ts +7 -7
  127. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
  128. package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
  129. package/dist/market_adapter/market_adapter.d.ts +94 -32
  130. package/dist/market_adapter/market_adapter.js +67 -48
  131. package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
  132. package/dist/market_adapter/utils/adapter_client.js +2 -2
  133. package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
  134. package/dist/market_adapter/utils/chain.d.ts +50 -41
  135. package/dist/market_adapter/utils/chain.js +40 -46
  136. package/dist/market_adapter/utils/data_discovery.d.ts +4 -1
  137. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
  138. package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
  139. package/dist/market_adapter/utils/file_lock.d.ts +28 -14
  140. package/dist/market_adapter/utils/file_lock.js +36 -32
  141. package/dist/market_adapter/utils/native_history.d.ts +9 -2
  142. package/dist/market_adapter/utils/native_history.js +35 -28
  143. package/dist/modules/account_bots.d.ts +577 -21
  144. package/dist/modules/account_bots.js +182 -158
  145. package/dist/modules/account_orders.d.ts +66 -30
  146. package/dist/modules/account_orders.js +22 -20
  147. package/dist/modules/authority_resolver.d.ts +12 -2
  148. package/dist/modules/authority_resolver.js +15 -8
  149. package/dist/modules/bitshares-native/chain_client.d.ts +38 -3
  150. package/dist/modules/bitshares-native/chain_client.js +45 -46
  151. package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
  152. package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
  153. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
  154. package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
  155. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
  156. package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
  157. package/dist/modules/bitshares-native/index.d.ts +1 -1
  158. package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
  159. package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
  160. package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
  161. package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
  162. package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
  163. package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
  164. package/dist/modules/bitshares-native/serial/serializer.js +7 -13
  165. package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
  166. package/dist/modules/bitshares-native/serial/types.js +55 -62
  167. package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
  168. package/dist/modules/bitshares-native/signing_client.js +19 -14
  169. package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
  170. package/dist/modules/bitshares-native/subscriptions.js +12 -12
  171. package/dist/modules/bitshares-native/transport.d.ts +5 -4
  172. package/dist/modules/bitshares-native/transport.js +5 -4
  173. package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
  174. package/dist/modules/bitshares-native/tx/builder.js +4 -3
  175. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
  176. package/dist/modules/bitshares_client.d.ts +45 -13
  177. package/dist/modules/bitshares_client.js +28 -19
  178. package/dist/modules/bot_defaults.d.ts +6 -15
  179. package/dist/modules/bot_defaults.js +1 -5
  180. package/dist/modules/bot_settings.d.ts +44 -10
  181. package/dist/modules/bot_settings.js +11 -8
  182. package/dist/modules/bots_file_lock.d.ts +6 -6
  183. package/dist/modules/bots_file_lock.js +16 -12
  184. package/dist/modules/broadcast_failure.d.ts +2 -2
  185. package/dist/modules/broadcast_failure.js +5 -4
  186. package/dist/modules/chain_keys.d.ts +42 -40
  187. package/dist/modules/chain_keys.js +53 -45
  188. package/dist/modules/chain_orders.d.ts +93 -59
  189. package/dist/modules/chain_orders.js +31 -23
  190. package/dist/modules/constants.d.ts +527 -31
  191. package/dist/modules/constants.js +15 -47
  192. package/dist/modules/cr_planner.d.ts +40 -2
  193. package/dist/modules/credential_policy.d.ts +68 -8
  194. package/dist/modules/credential_policy.js +37 -31
  195. package/dist/modules/credential_session_cache.d.ts +2 -2
  196. package/dist/modules/credit_pricing.d.ts +42 -6
  197. package/dist/modules/credit_pricing.js +44 -30
  198. package/dist/modules/credit_runtime.d.ts +276 -118
  199. package/dist/modules/credit_runtime.js +462 -165
  200. package/dist/modules/crypto/browser_provider.js +6 -4
  201. package/dist/modules/crypto/node_provider.js +1 -1
  202. package/dist/modules/crypto/pure_scrypt.js +35 -4
  203. package/dist/modules/crypto/pure_secp256k1.js +72 -26
  204. package/dist/modules/crypto/sync.d.ts +9 -9
  205. package/dist/modules/crypto/sync.js +16 -9
  206. package/dist/modules/dexbot_class.d.ts +195 -139
  207. package/dist/modules/dexbot_class.js +78 -28
  208. package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
  209. package/dist/modules/dexbot_cow_runtime.js +248 -206
  210. package/dist/modules/dexbot_credential_client.d.ts +19 -11
  211. package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
  212. package/dist/modules/dexbot_fill_runtime.js +48 -41
  213. package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
  214. package/dist/modules/dexbot_maintenance_runtime.js +108 -83
  215. package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
  216. package/dist/modules/dexbot_startup_runtime.js +43 -43
  217. package/dist/modules/dexbot_state_recovery.d.ts +13 -12
  218. package/dist/modules/dexbot_state_recovery.js +18 -13
  219. package/dist/modules/fund_registry.d.ts +4 -2
  220. package/dist/modules/fund_registry.js +10 -10
  221. package/dist/modules/general_settings.d.ts +30 -4
  222. package/dist/modules/graceful_shutdown.d.ts +3 -3
  223. package/dist/modules/graceful_shutdown.js +2 -2
  224. package/dist/modules/grid_price_source.d.ts +1 -1
  225. package/dist/modules/key_store.d.ts +14 -8
  226. package/dist/modules/key_store.js +7 -6
  227. package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
  228. package/dist/modules/launcher/adapter_requirement.js +5 -5
  229. package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
  230. package/dist/modules/launcher/bot_supervisor.js +12 -11
  231. package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
  232. package/dist/modules/launcher/credential_bootstrap.js +1 -1
  233. package/dist/modules/launcher/credential_daemon.d.ts +4 -4
  234. package/dist/modules/launcher/credential_daemon.js +2 -2
  235. package/dist/modules/launcher/credential_secret.d.ts +1 -1
  236. package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
  237. package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
  238. package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
  239. package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
  240. package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
  241. package/dist/modules/launcher/status_reporting.d.ts +22 -14
  242. package/dist/modules/launcher/supervisor_control.d.ts +8 -1
  243. package/dist/modules/launcher/supervisor_control.js +4 -2
  244. package/dist/modules/market_adapter_whitelist.d.ts +9 -3
  245. package/dist/modules/market_adapter_whitelist.js +15 -3
  246. package/dist/modules/node_manager.d.ts +41 -11
  247. package/dist/modules/node_manager.js +5 -4
  248. package/dist/modules/order/accounting.d.ts +53 -24
  249. package/dist/modules/order/accounting.js +16 -15
  250. package/dist/modules/order/async_lock.d.ts +5 -2
  251. package/dist/modules/order/async_lock.js +1 -1
  252. package/dist/modules/order/export.d.ts +7 -6
  253. package/dist/modules/order/export.js +1 -7
  254. package/dist/modules/order/format.d.ts +4 -4
  255. package/dist/modules/order/genesis_policy.d.ts +21 -18
  256. package/dist/modules/order/genesis_policy.js +12 -8
  257. package/dist/modules/order/grid.d.ts +142 -36
  258. package/dist/modules/order/grid.js +148 -123
  259. package/dist/modules/order/grid_reconcile.d.ts +21 -20
  260. package/dist/modules/order/grid_reconcile.js +13 -12
  261. package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
  262. package/dist/modules/order/grid_reconcile_internal.js +28 -19
  263. package/dist/modules/order/index.d.ts +263 -1
  264. package/dist/modules/order/logger.d.ts +45 -11
  265. package/dist/modules/order/logger.js +38 -40
  266. package/dist/modules/order/logger_state.d.ts +4 -4
  267. package/dist/modules/order/manager.d.ts +225 -180
  268. package/dist/modules/order/manager.js +80 -83
  269. package/dist/modules/order/processed_fill_store.d.ts +18 -3
  270. package/dist/modules/order/processed_fill_store.js +16 -27
  271. package/dist/modules/order/strategy.d.ts +21 -13
  272. package/dist/modules/order/strategy.js +5 -6
  273. package/dist/modules/order/sync_engine.d.ts +91 -33
  274. package/dist/modules/order/sync_engine.js +84 -53
  275. package/dist/modules/order/utils/math.d.ts +157 -102
  276. package/dist/modules/order/utils/math.js +77 -38
  277. package/dist/modules/order/utils/order.d.ts +310 -110
  278. package/dist/modules/order/utils/order.js +122 -99
  279. package/dist/modules/order/utils/slot.d.ts +1 -1
  280. package/dist/modules/order/utils/system.d.ts +176 -26
  281. package/dist/modules/order/utils/system.js +86 -69
  282. package/dist/modules/order/utils/validate.d.ts +89 -41
  283. package/dist/modules/order/utils/validate.js +24 -22
  284. package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
  285. package/dist/modules/order/utils/withPoolRef.js +18 -12
  286. package/dist/modules/order/working_grid.d.ts +14 -13
  287. package/dist/modules/paths.d.ts +1 -4
  288. package/dist/modules/paths.js +1 -27
  289. package/dist/modules/process_discovery.d.ts +1 -1
  290. package/dist/modules/process_discovery.js +2 -1
  291. package/dist/modules/runtime.d.ts +7 -3
  292. package/dist/modules/runtime.js +4 -3
  293. package/dist/modules/runtime_settings.d.ts +15 -10
  294. package/dist/modules/runtime_settings.js +30 -24
  295. package/dist/modules/settings_merge.d.ts +29 -3
  296. package/dist/modules/settings_merge.js +56 -78
  297. package/dist/modules/socket_json_client.d.ts +7 -4
  298. package/dist/modules/storage/browser_adapter.d.ts +38 -53
  299. package/dist/modules/storage/browser_adapter.js +7 -30
  300. package/dist/modules/storage/index.d.ts +1 -1
  301. package/dist/modules/storage/node_adapter.d.ts +45 -27
  302. package/dist/modules/storage/node_adapter.js +9 -9
  303. package/dist/modules/storage/types.d.ts +5 -4
  304. package/dist/modules/types.d.ts +1071 -2
  305. package/dist/modules/types.js +4 -1
  306. package/dist/modules/utils/asset_symbols.d.ts +2 -1
  307. package/dist/modules/utils/asset_symbols.js +2 -1
  308. package/dist/modules/utils/errors.d.ts +9 -0
  309. package/dist/modules/utils/errors.js +23 -1
  310. package/dist/modules/utils/time_range.d.ts +1 -12
  311. package/dist/modules/utils/time_range.js +1 -1
  312. package/dist/modules/validate_profiles.js +53 -43
  313. package/dist/modules/version_notice.d.ts +14 -3
  314. package/dist/modules/version_notice.js +6 -4
  315. package/dist/pm2.d.ts +29 -27
  316. package/dist/pm2.js +5 -5
  317. package/dist/scripts/analyze-credit.d.ts +2 -1
  318. package/dist/scripts/analyze-credit.js +23 -24
  319. package/dist/scripts/analyze-orders.d.ts +77 -9
  320. package/dist/scripts/analyze-orders.js +65 -40
  321. package/dist/scripts/chart_command.d.ts +27 -18
  322. package/dist/scripts/chart_command.js +13 -11
  323. package/dist/scripts/check_any.d.ts +18 -0
  324. package/dist/scripts/check_any.js +126 -0
  325. package/dist/scripts/diagnose-pool-history.js +12 -7
  326. package/dist/scripts/print_grid.js +0 -1
  327. package/dist/scripts/run-tests.js +39 -7
  328. package/dist/scripts/runner.js +1 -1
  329. package/dist/scripts/test-credit-renewal.js +30 -21
  330. package/dist/scripts/update.d.ts +10 -5
  331. package/dist/scripts/update.js +168 -103
  332. package/dist/scripts/update_dist_freshness.js +1 -0
  333. package/dist/scripts/update_layout.d.ts +61 -0
  334. package/dist/scripts/update_layout.js +180 -0
  335. package/dist/scripts/validate_bots.js +2 -1
  336. package/dist/scripts/verify-browser-bundle.js +8 -0
  337. package/dist/unlock.d.ts +28 -3
  338. package/dist/unlock.js +63 -35
  339. package/docs/BITSHARES_ONBOARDING.md +2 -0
  340. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
  341. package/docs/COW_INVARIANTS.md +13 -6
  342. package/docs/DEXBOT_COMPARISON.md +8 -8
  343. package/docs/EVOLUTION.md +10 -9
  344. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
  345. package/docs/GRID_RECALCULATION.md +4 -2
  346. package/docs/GRID_RECONCILE.md +14 -3
  347. package/docs/LIFECYCLE.md +11 -11
  348. package/docs/MPA_CREDIT_USAGE.md +22 -3
  349. package/docs/README.md +14 -3
  350. package/docs/architecture.md +12 -9
  351. package/docs/developer_guide.md +6 -6
  352. package/market_adapter/README.md +6 -1
  353. package/modules/README.md +4 -1
  354. package/package.json +4 -1
@@ -3,6 +3,40 @@ declare const WEIGHT_PROFILES: {
3
3
  neutral: number;
4
4
  mountain: number;
5
5
  };
6
+ declare function parseArgs(): {
7
+ dataPath: string | null;
8
+ resultsPath: string | null;
9
+ spreadValues: number[];
10
+ incrementValues: number[];
11
+ ratioValues: number[];
12
+ maxOrders: number;
13
+ feeRoundtripPct: number;
14
+ minSpreadFactor: number;
15
+ capital: number;
16
+ repositionPct: number;
17
+ asymmetricBounds: boolean;
18
+ btsCreateFee: number;
19
+ btsCancelFee: number;
20
+ makerCreateFactor: number;
21
+ txFeePrice: number;
22
+ topN: number;
23
+ lookbackBars: number | null;
24
+ };
25
+ interface AmaStrategy {
26
+ id: string;
27
+ name: string;
28
+ er: number;
29
+ fast: number;
30
+ slow: number;
31
+ }
32
+ interface GridOrder {
33
+ level: number;
34
+ price: number;
35
+ railIdx: number;
36
+ cooldownUntil: number;
37
+ size: number;
38
+ [key: string]: unknown;
39
+ }
6
40
  /**
7
41
  * Allocate capital across N levels using weight profile.
8
42
  * weight > 0: mountain (more near center, exponential decay outward)
@@ -27,9 +61,14 @@ declare function allocateFundsByWeights(totalFunds: number, n: number, weight: n
27
61
  *
28
62
  * Returns arrays of buy and sell order objects with fixed chain prices and sizes.
29
63
  */
30
- declare function buildGrid(center: number, params: any, capitalPerSide: number, weightFactor: number): {
31
- buys: any[];
32
- sells: any[];
64
+ declare function buildGrid(center: number, params: {
65
+ incrementPct: number;
66
+ maxMinRatio: number;
67
+ maxOrders: number;
68
+ spreadPct: number;
69
+ }, capitalPerSide: number, weightFactor: number): {
70
+ buys: GridOrder[];
71
+ sells: GridOrder[];
33
72
  rail: number[];
34
73
  };
35
74
  /**
@@ -47,11 +86,36 @@ declare function markInventoryAtPrice(inventory: {
47
86
  grossUnits: number;
48
87
  profitUnits: number;
49
88
  };
50
- declare function simulatePersistentGrid(candles: any[], amaValues: number[], params: any, weightName: string, weightFactor: number): {
89
+ interface SimCandle {
90
+ open?: number;
91
+ high: number;
92
+ low: number;
93
+ close: number;
94
+ time?: number;
95
+ [key: string]: unknown;
96
+ }
97
+ interface SimParams {
98
+ spreadPct: number;
99
+ incrementPct: number;
100
+ maxMinRatio: number;
101
+ maxOrders: number;
102
+ feeRoundtripPct: number;
103
+ capital: number;
104
+ repositionThreshold: number;
105
+ asymmetricBounds: boolean;
106
+ btsCreateFee: number;
107
+ btsCancelFee: number;
108
+ makerCreateFactor: number;
109
+ txFeePrice: number;
110
+ warmupBars: number;
111
+ lookbackBars: number;
112
+ [key: string]: unknown;
113
+ }
114
+ declare function simulatePersistentGrid(candles: SimCandle[], amaValues: number[], params: SimParams, weightName: string, weightFactor: number): {
51
115
  weightName: string;
52
- spreadPct: any;
116
+ spreadPct: number;
53
117
  incrementPct: number;
54
- maxMinRatio: any;
118
+ maxMinRatio: number;
55
119
  matchedPairs: number;
56
120
  cyclesTotal: number;
57
121
  rotationCount: number;
@@ -84,7 +148,7 @@ declare function simulatePersistentGrid(candles: any[], amaValues: number[], par
84
148
  avgTriggerDriftPct: number;
85
149
  offsetAppliedCount: number;
86
150
  makerCreateFeeBts: number;
87
- btsCancelFee: any;
151
+ btsCancelFee: number;
88
152
  avgCancelOrdersPerReposition: number;
89
153
  estimatedFeePerRepositionBts: number;
90
154
  totalRepositionFeesBts: number;
@@ -96,11 +160,155 @@ declare function simulatePersistentGrid(candles: any[], amaValues: number[], par
96
160
  netScore: number;
97
161
  score: number;
98
162
  };
99
- declare function sweepOneAma(strategy: any, candles: any[], closes: number[], weightEntries: [string, number][], cfg: any): {
100
- strategy: any;
101
- best: any;
102
- top5: any[];
103
- allSims: any[];
163
+ declare function sweepOneAma(strategy: AmaStrategy, candles: SimCandle[], closes: number[], weightEntries: [string, number][], cfg: ReturnType<typeof parseArgs>): {
164
+ strategy: AmaStrategy;
165
+ best: {
166
+ weightName: string;
167
+ spreadPct: number;
168
+ incrementPct: number;
169
+ maxMinRatio: number;
170
+ matchedPairs: number;
171
+ cyclesTotal: number;
172
+ rotationCount: number;
173
+ inventorySaleCount: number;
174
+ touchedOrders: number;
175
+ fillEfficiency: number;
176
+ totalProfitUnits: number;
177
+ totalGrossUnits: number;
178
+ finalInventoryUnits: number;
179
+ finalInventoryAvgEntry: number;
180
+ finalInventoryMarkUnits: number;
181
+ profitPerCapital: number;
182
+ pairsPerDay: number;
183
+ avgOpenDurationBars: number;
184
+ avgProfitPerPair: number;
185
+ peakOpenOrders: number;
186
+ avgImbalance: number;
187
+ canceledOnReposition: number;
188
+ repositionCount: number;
189
+ driftTriggerCount: number;
190
+ slopeTriggerCount: number;
191
+ maxDrawdown: number;
192
+ maxDrawdownPct: number;
193
+ maxInventoryExposure: number;
194
+ avgGridAgeBars: number;
195
+ maxGridAgeBars: number;
196
+ avgCenterDriftPct: number;
197
+ maxCenterDriftPct: number;
198
+ nearThresholdBarsPct: number;
199
+ avgTriggerDriftPct: number;
200
+ offsetAppliedCount: number;
201
+ makerCreateFeeBts: number;
202
+ btsCancelFee: number;
203
+ avgCancelOrdersPerReposition: number;
204
+ estimatedFeePerRepositionBts: number;
205
+ totalRepositionFeesBts: number;
206
+ feePerDayBts: number;
207
+ netProfitUnits: number;
208
+ netProfitPerCapital: number;
209
+ ordersPerSide: number;
210
+ grossScore: number;
211
+ netScore: number;
212
+ score: number;
213
+ } | null;
214
+ top5: {
215
+ weightName: string;
216
+ spreadPct: number;
217
+ incrementPct: number;
218
+ maxMinRatio: number;
219
+ matchedPairs: number;
220
+ cyclesTotal: number;
221
+ rotationCount: number;
222
+ inventorySaleCount: number;
223
+ touchedOrders: number;
224
+ fillEfficiency: number;
225
+ totalProfitUnits: number;
226
+ totalGrossUnits: number;
227
+ finalInventoryUnits: number;
228
+ finalInventoryAvgEntry: number;
229
+ finalInventoryMarkUnits: number;
230
+ profitPerCapital: number;
231
+ pairsPerDay: number;
232
+ avgOpenDurationBars: number;
233
+ avgProfitPerPair: number;
234
+ peakOpenOrders: number;
235
+ avgImbalance: number;
236
+ canceledOnReposition: number;
237
+ repositionCount: number;
238
+ driftTriggerCount: number;
239
+ slopeTriggerCount: number;
240
+ maxDrawdown: number;
241
+ maxDrawdownPct: number;
242
+ maxInventoryExposure: number;
243
+ avgGridAgeBars: number;
244
+ maxGridAgeBars: number;
245
+ avgCenterDriftPct: number;
246
+ maxCenterDriftPct: number;
247
+ nearThresholdBarsPct: number;
248
+ avgTriggerDriftPct: number;
249
+ offsetAppliedCount: number;
250
+ makerCreateFeeBts: number;
251
+ btsCancelFee: number;
252
+ avgCancelOrdersPerReposition: number;
253
+ estimatedFeePerRepositionBts: number;
254
+ totalRepositionFeesBts: number;
255
+ feePerDayBts: number;
256
+ netProfitUnits: number;
257
+ netProfitPerCapital: number;
258
+ ordersPerSide: number;
259
+ grossScore: number;
260
+ netScore: number;
261
+ score: number;
262
+ }[];
263
+ allSims: {
264
+ weightName: string;
265
+ spreadPct: number;
266
+ incrementPct: number;
267
+ maxMinRatio: number;
268
+ matchedPairs: number;
269
+ cyclesTotal: number;
270
+ rotationCount: number;
271
+ inventorySaleCount: number;
272
+ touchedOrders: number;
273
+ fillEfficiency: number;
274
+ totalProfitUnits: number;
275
+ totalGrossUnits: number;
276
+ finalInventoryUnits: number;
277
+ finalInventoryAvgEntry: number;
278
+ finalInventoryMarkUnits: number;
279
+ profitPerCapital: number;
280
+ pairsPerDay: number;
281
+ avgOpenDurationBars: number;
282
+ avgProfitPerPair: number;
283
+ peakOpenOrders: number;
284
+ avgImbalance: number;
285
+ canceledOnReposition: number;
286
+ repositionCount: number;
287
+ driftTriggerCount: number;
288
+ slopeTriggerCount: number;
289
+ maxDrawdown: number;
290
+ maxDrawdownPct: number;
291
+ maxInventoryExposure: number;
292
+ avgGridAgeBars: number;
293
+ maxGridAgeBars: number;
294
+ avgCenterDriftPct: number;
295
+ maxCenterDriftPct: number;
296
+ nearThresholdBarsPct: number;
297
+ avgTriggerDriftPct: number;
298
+ offsetAppliedCount: number;
299
+ makerCreateFeeBts: number;
300
+ btsCancelFee: number;
301
+ avgCancelOrdersPerReposition: number;
302
+ estimatedFeePerRepositionBts: number;
303
+ totalRepositionFeesBts: number;
304
+ feePerDayBts: number;
305
+ netProfitUnits: number;
306
+ netProfitPerCapital: number;
307
+ ordersPerSide: number;
308
+ grossScore: number;
309
+ netScore: number;
310
+ score: number;
311
+ }[];
104
312
  evaluated: number;
105
313
  };
106
314
  export { WEIGHT_PROFILES, allocateFundsByWeights, buildGrid, markInventoryAtPrice, simulatePersistentGrid, sweepOneAma };
@@ -207,9 +207,9 @@ function loadAmaStrategies(resultsPath) {
207
207
  const out = [];
208
208
  for (const [key, val] of Object.entries(amas)) {
209
209
  const v = val;
210
- if (!v || !Number.isFinite(v.er))
210
+ if (!v || !Number.isFinite(Number(v.er)))
211
211
  continue;
212
- out.push({ id: key, name: v.label || key, er: v.er, fast: v.fast, slow: v.slow });
212
+ out.push({ id: key, name: String(v.label || key), er: Number(v.er), fast: Number(v.fast), slow: Number(v.slow) });
213
213
  }
214
214
  out.sort((a, b) => a.id.localeCompare(b.id));
215
215
  if (out.length === 0)
@@ -301,8 +301,9 @@ function simulatePersistentGrid(candles, amaValues, params, weightName, weightFa
301
301
  // Slope-delta persistence gate: follow the production default (constants)
302
302
  // unless the caller pins a value, so the sweep's reset path matches live
303
303
  // whenever asymmetricBounds enables trigger B.
304
- const slopePersistBars = Number.isFinite(params.slopePersistBars) && params.slopePersistBars >= 1
305
- ? Math.round(params.slopePersistBars)
304
+ const slopePersistBarsRaw = Number(params.slopePersistBars);
305
+ const slopePersistBars = Number.isFinite(slopePersistBarsRaw) && slopePersistBarsRaw >= 1
306
+ ? Math.round(slopePersistBarsRaw)
306
307
  : (MARKET_ADAPTER.AMA_SLOPE_PERSIST_ENABLED === true && Number(MARKET_ADAPTER.AMA_SLOPE_PERSIST_BARS) >= 1
307
308
  ? Math.round(Number(MARKET_ADAPTER.AMA_SLOPE_PERSIST_BARS))
308
309
  : 1);
@@ -758,7 +759,7 @@ function runParallel(strategies, candles, closes, weightEntries, cfg) {
758
759
  const worker = new Worker(fileURLToPath(import.meta.url), {
759
760
  workerData: { strategy, candles, closes, weightEntries, cfg },
760
761
  });
761
- worker.on('message', resolve);
762
+ worker.on('message', (msg) => resolve(msg));
762
763
  worker.on('error', reject);
763
764
  worker.on('exit', (code) => {
764
765
  if (code !== 0)
@@ -100,10 +100,40 @@ declare function buildProductionGrid(center: number, spreadPct: number, incremen
100
100
  * #10 pool-price fills (no book depth/slippage);
101
101
  * #11 no consolidation/dust-cancel/COW/collision mechanics.
102
102
  */
103
- declare function simulateForParams(candles: any, amaValues: any, params: any): {
104
- spreadPct: any;
105
- incrementPct: any;
106
- maxMinRatio: any;
103
+ interface SimCandle {
104
+ open?: number;
105
+ high: number;
106
+ low: number;
107
+ close: number;
108
+ time?: number;
109
+ [key: string]: unknown;
110
+ }
111
+ interface SimParams {
112
+ spreadPct: number;
113
+ incrementPct: number;
114
+ maxMinRatio: number;
115
+ activeOrders: number;
116
+ feeRoundtripPct: number;
117
+ repositionThresholdPct: number;
118
+ asymmetricBounds: boolean;
119
+ risk: {
120
+ duration: number;
121
+ peakOpen: number;
122
+ imbalance: number;
123
+ cancel: number;
124
+ };
125
+ btsCreateFee: number;
126
+ btsCancelFee: number;
127
+ makerCreateFactor: number;
128
+ txFeePrice: number;
129
+ btsFeeCapital: number;
130
+ warmupBars: number;
131
+ [key: string]: unknown;
132
+ }
133
+ declare function simulateForParams(candles: SimCandle[], amaValues: number[], params: SimParams): {
134
+ spreadPct: number;
135
+ incrementPct: number;
136
+ maxMinRatio: number;
107
137
  touchedOrders: number;
108
138
  matchedPairs: number;
109
139
  cyclesTotal: number;
@@ -219,19 +219,19 @@ function resolveAutoResultsPath(dataPath) {
219
219
  }
220
220
  function loadAmaStrategies(resultsPath) {
221
221
  const json = readJSON(resultsPath);
222
- const amas = (json.meta?.amas ?? {});
222
+ const amas = json.meta?.amas ?? {};
223
223
  const labels = { AMA1: 'AMA1', AMA2: 'AMA2', AMA3: 'AMA3', AMA4: 'AMA4' };
224
224
  const out = [];
225
225
  for (const [key, val] of Object.entries(amas)) {
226
226
  const a = val;
227
- if (!a || !Number.isFinite(a.er) || !Number.isFinite(a.fast) || !Number.isFinite(a.slow))
227
+ if (!a || !Number.isFinite(Number(a.er)) || !Number.isFinite(Number(a.fast)) || !Number.isFinite(Number(a.slow)))
228
228
  continue;
229
229
  out.push({
230
230
  id: key,
231
231
  name: labels[key] ?? key,
232
- er: a.er,
233
- fast: a.fast,
234
- slow: a.slow,
232
+ er: Number(a.er),
233
+ fast: Number(a.fast),
234
+ slow: Number(a.slow),
235
235
  });
236
236
  }
237
237
  if (out.length !== 4) {
@@ -336,60 +336,6 @@ function buildProductionGrid(center, spreadPct, incrementPctFrac, maxMinRatio, a
336
336
  sellStartIdx,
337
337
  };
338
338
  }
339
- /**
340
- * Slot-rotation simulation with FIXED chain prices, mirroring production
341
- * anchor-&-refill (strategy.ts) on top of the createOrderGrid geometry:
342
- *
343
- * - Initial grid built once at the post-warmup AMA (createOrderGrid geometry
344
- * via buildProductionGrid); order prices never follow AMA afterwards. When
345
- * asymmetricBounds is enabled the placement center is shifted by the
346
- * slope-ratio offset (#3) exactly like the live startPrice offset.
347
- * - Rotation economics (#1/#2/#15): a FILLED BUY at rail node k instantly
348
- * re-offers that base at the ADJACENT MASTER-RAIL NODE k+1; when that
349
- * refill sells, the rotation books exactly one rail hop minus the
350
- * round-trip fee, and the freed quote re-bids the node k-1 below. Slots
351
- * cycle on small oscillations between resets — the earnings model of a
352
- * refilled live slot, not a cross-gap differential.
353
- * - Inventory-funded selling: an INITIAL (unlinked) sell can only execute
354
- * against held inventory — it books its proceeds against the weighted
355
- * average entry of the position (the live bot funds sells from real
356
- * balances; unfundable sells stay open and retry, never shorting). Base
357
- * bought in the SAME bar does not fund unlinked sales until the next bar
358
- * (live balance updates propagate on the next maintenance tick).
359
- * - Same-bar guard: newly armed/refill orders carry a one-bar cooldown, so
360
- * a slot that just cycled cannot fill again inside the completion bar.
361
- * - Grid reset fires on EITHER production trigger:
362
- * (A) |AMA − recordedCenter| / recordedCenter ≥ repositionThresholdPct
363
- * (ratchet: recordedCenter updates only when the trigger fires),
364
- * (B) slope-delta reset, ONLY when asymmetricBounds (whitelist gate):
365
- * |slopePct_now − slopeBaseline| ≥ slopeDeltaThresholdPct
366
- * (= AMA_SLOPE_DELTA_THRESHOLD_PERCENT/100 ×
367
- * DYNAMIC_WEIGHT_AMA_MAX_SLOPE_PCT), where slopePct is the
368
- * DYNAMIC_WEIGHT_AMA_LOOKBACK_BARS average-slope series and
369
- * slopeBaseline mirrors botState.gridRangeScalingAmaSlope — seeded
370
- * at start and re-seeded on every reset.
371
- * On reset ALL unfilled orders are canceled (counted); bought-and-held
372
- * base REMAINS as inventory (live resync never market-sells) and merges
373
- * into the weighted-average-entry pool; a fresh grid is placed at the
374
- * new center.
375
- * - Scoring uses REALIZED rotations and op fees ONLY. The end-of-run
376
- * inventory position (units × mark-vs-avg-entry) is reported as an
377
- * informational field — it is real carried risk, but including unrealized
378
- * bag marks in the ranking objective let trend-following combos dump
379
- * phantom paper profit into the score.
380
- * - BTS operation fees (#9): every order placement (initial grid + every
381
- * armed refill/rebid) pays makerCreateFee × btsCreateFee, every reset
382
- * cancel pays btsCancelFee; totals are converted to percentage points
383
- * against the --bts-fee-capital reference and deducted from net capture.
384
- *
385
- * Differences from production (by design, documented):
386
- * #6 bar-granularity triggers and reset-vs-fill ordering (OHLC sim);
387
- * #7 all-or-nothing fills on raw hi/lo touch (no partial fills/dust/queue);
388
- * #8 unit sizes / percentage-point accounting instead of capital-weighted
389
- * dynamic sizing;
390
- * #10 pool-price fills (no book depth/slippage);
391
- * #11 no consolidation/dust-cancel/COW/collision mechanics.
392
- */
393
339
  function simulateForParams(candles, amaValues, params) {
394
340
  const { spreadPct, incrementPct, maxMinRatio, activeOrders, feeRoundtripPct, repositionThresholdPct, asymmetricBounds, risk, btsCreateFee, btsCancelFee, makerCreateFactor, txFeePrice, btsFeeCapital } = params;
395
341
  // Warmup follows production AMA seeding/convergence (getAmaWarmupBars)
@@ -405,10 +351,12 @@ function simulateForParams(candles, amaValues, params) {
405
351
  // reset path matches live whenever asymmetricBounds enables trigger B.
406
352
  // slopePersistBars persistence gate on trigger B
407
353
  // bandTilt apply applyAsymmetricBounds to the built band
408
- const slopeLookbackBars = Number.isFinite(params.slopeLookbackBars) && params.slopeLookbackBars >= 2
409
- ? Math.round(params.slopeLookbackBars) : SLOPE_LOOKBACK_BARS;
410
- const slopePersistBars = Number.isFinite(params.slopePersistBars) && params.slopePersistBars >= 1
411
- ? Math.round(params.slopePersistBars)
354
+ const slopeLookbackRaw = Number(params.slopeLookbackBars);
355
+ const slopeLookbackBars = Number.isFinite(slopeLookbackRaw) && slopeLookbackRaw >= 2
356
+ ? Math.round(slopeLookbackRaw) : SLOPE_LOOKBACK_BARS;
357
+ const slopePersistRaw = Number(params.slopePersistBars);
358
+ const slopePersistBars = Number.isFinite(slopePersistRaw) && slopePersistRaw >= 1
359
+ ? Math.round(slopePersistRaw)
412
360
  : (MARKET_ADAPTER.AMA_SLOPE_PERSIST_ENABLED === true && Number(MARKET_ADAPTER.AMA_SLOPE_PERSIST_BARS) >= 1
413
361
  ? Math.round(Number(MARKET_ADAPTER.AMA_SLOPE_PERSIST_BARS)) : 1);
414
362
  const bandTilt = params.bandTilt === true;
@@ -1,14 +1,14 @@
1
- declare function parseListOrRange(spec: any, fallback: any): any;
1
+ declare function parseListOrRange(spec: string | null | undefined, fallback: number[]): number[];
2
2
  declare function loadLpData(filePath: string): {
3
3
  candles: {
4
4
  timestamp: number;
5
- open: any;
6
- high: any;
7
- low: any;
8
- close: any;
9
- volume: any;
5
+ open: number;
6
+ high: number;
7
+ low: number;
8
+ close: number;
9
+ volume: number;
10
10
  }[];
11
- meta: any;
11
+ meta: {} | null;
12
12
  };
13
13
  declare function fmt(x: number, d?: number): string;
14
14
  export { parseListOrRange, loadLpData, fmt };
@@ -10,7 +10,7 @@ function toCandles(arr) {
10
10
  // instead of hand-rolled array indexing.
11
11
  return arr
12
12
  .map((c) => normalizeCandle(c))
13
- .filter(Boolean)
13
+ .filter((c) => c != null)
14
14
  .map((c) => ({
15
15
  timestamp: c.time * 1000,
16
16
  open: c.open,
@@ -37,7 +37,7 @@ function parseListOrRange(spec, fallback) {
37
37
  }
38
38
  function loadLpData(filePath) {
39
39
  const json = readJSON(filePath);
40
- return { candles: toCandles(json.candles ?? json), meta: json.meta ?? null };
40
+ return { candles: toCandles((json.candles ?? json)), meta: json.meta ?? null };
41
41
  }
42
42
  function fmt(x, d = 2) {
43
43
  if (!Number.isFinite(x))
@@ -1,10 +1,18 @@
1
1
  import { sanitizeKey } from '../modules/utils/sanitize_key.js';
2
- declare function loadBotSettings(filePath?: string): any;
3
- declare function computeBotKey(bot: any, index: number): string;
4
- declare function resolveBotKey(botName: any, filePath?: string): string | null;
2
+ type BotEntry = Record<string, unknown>;
3
+ interface AmaConfig {
4
+ erPeriod: number;
5
+ fastPeriod: number;
6
+ slowPeriod: number;
7
+ }
8
+ declare function loadBotSettings(filePath?: string): {
9
+ bots?: BotEntry[];
10
+ } | null;
11
+ declare function computeBotKey(bot: unknown, index: number): string;
12
+ declare function resolveBotKey(botName: unknown, filePath?: string): string | null;
5
13
  declare function candleFileForBot(botKey: string, intervalLabel: string, dataDir?: string): string;
6
14
  declare function resolveCandleFile(botKey: string, intervalLabel: string, dataDir?: string, botsFile?: string): string | null;
7
- declare function loadBotMeta(botKey: any, filePath?: string): any;
15
+ declare function loadBotMeta(botKey: unknown, filePath?: string): BotEntry | null;
8
16
  /**
9
17
  * Persist a resolved account name → ID mapping onto the bot entry in
10
18
  * profiles/bots.json (`accountId` next to `preferredAccount`), so analysis
@@ -14,25 +22,25 @@ declare function loadBotMeta(botKey: any, filePath?: string): any;
14
22
  * same atomic writeJSON serialization the bot editor uses. Returns true when
15
23
  * the file was updated.
16
24
  */
17
- declare function persistBotAccountId(botKey: any, accountId: string, filePath?: string): boolean;
25
+ declare function persistBotAccountId(botKey: unknown, accountId: string, filePath?: string): boolean;
18
26
  /**
19
27
  * Return the stored chain account ID for a bot key, or null when none is
20
28
  * stamped yet. When expectedRef is given, the stored ID is only returned if
21
29
  * the entry's current preferredAccount still matches it — a rename must
22
30
  * never silently reuse a stale ID.
23
31
  */
24
- declare function getStoredBotAccountId(botKey: any, expectedRef?: string | null, filePath?: string): string | null;
32
+ declare function getStoredBotAccountId(botKey: unknown, expectedRef?: string | null, filePath?: string): string | null;
25
33
  /**
26
34
  * Find the bot entry whose preferredAccount matches a raw account reference
27
35
  * (case-insensitive). Used by tools that accept a bare account name to locate
28
36
  * the stored accountId and the persist target. Returns null for 1.2.x input
29
37
  * or when no bot claims the name.
30
38
  */
31
- declare function findBotKeyByAccountRef(ref: any, filePath?: string): {
39
+ declare function findBotKeyByAccountRef(ref: unknown, filePath?: string): {
32
40
  botKey: string;
33
- meta: any;
41
+ meta: BotEntry;
34
42
  } | null;
35
- declare function resolveAmaConfig(botKey: any): any;
36
- declare function resolveAmaKey(botKey: any): string;
43
+ declare function resolveAmaConfig(botKey: unknown): AmaConfig;
44
+ declare function resolveAmaKey(botKey: unknown): string;
37
45
  export { loadBotSettings, sanitizeKey, computeBotKey, resolveBotKey, candleFileForBot, resolveCandleFile, loadBotMeta, getStoredBotAccountId, findBotKeyByAccountRef, persistBotAccountId, resolveAmaConfig, resolveAmaKey };
38
46
  //# sourceMappingURL=bot_key_utils.d.ts.map
@@ -424,7 +424,10 @@ function getStoredBotAccountId(botKey, expectedRef, filePath = PATHS.PROFILES.BO
424
424
  catch (_) {
425
425
  return null;
426
426
  }
427
- const stored = meta && /^1\.2\.\d+$/.test(String(meta.accountId ?? '')) ? String(meta.accountId) : null;
427
+ if (!meta)
428
+ return null;
429
+ const accountIdRaw = String(meta.accountId ?? '');
430
+ const stored = /^1\.2\.\d+$/.test(accountIdRaw) ? accountIdRaw : null;
428
431
  if (!stored)
429
432
  return null;
430
433
  if (expectedRef != null && String(meta.preferredAccount ?? '').toLowerCase() !== String(expectedRef).toLowerCase())
@@ -463,7 +466,7 @@ function resolveAmaConfig(botKey) {
463
466
  return { ...MARKET_ADAPTER.AMAS.AMA3 };
464
467
  const rawGridPrice = String(botMeta?.gridPrice || '').trim().toLowerCase();
465
468
  const isAmaKeyword = AMA_KEYWORDS.has(rawGridPrice);
466
- const botAmaInline = (botMeta?.ama && typeof botMeta.ama === 'object') ? botMeta.ama : null;
469
+ const botAmaInline = (botMeta.ama && typeof botMeta.ama === 'object') ? botMeta.ama : null;
467
470
  // Priority: inline bot.ama overrides market profile for analysis visibility.
468
471
  // Production inverts this (profiles first, inline as fallback — market_adapter.ts:694-730).
469
472
  if (botAmaInline) {
@@ -501,11 +504,11 @@ function resolveAmaConfig(botKey) {
501
504
  // Pair match is case-insensitive: market_profiles.json and bots.json are
502
505
  // hand-edited, and a case-only difference must not silently drop the
503
506
  // profile (a strict === here made the AMA/grid config vanish).
504
- const selectedProfile = marketProfiles?.profiles
507
+ const selectedProfile = (marketProfiles?.profiles
505
508
  ? marketProfiles.profiles.find((entry) => isSameAssetSymbol(entry.assetA, botMeta.assetA) &&
506
509
  isSameAssetSymbol(entry.assetB, botMeta.assetB) &&
507
510
  Number(entry.intervalSeconds) === 3600)
508
- : null;
511
+ : null);
509
512
  if (selectedProfile?.amas) {
510
513
  const fallbackKey = selectedProfile.defaultAma || DEFAULT_AMA_KEY;
511
514
  const requestedKey = isAmaKeyword