dexbot 1.1.10

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 (807) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +287 -0
  3. package/claw/README.md +513 -0
  4. package/claw/scripts/memu_runner.py +385 -0
  5. package/claw/skills/bitshares-guide/SKILL.md +14 -0
  6. package/claw/skills/bitshares-guide/references/example-skill-shells.md +18 -0
  7. package/claw/skills/bitshares-guide/references/presentation-patterns.md +19 -0
  8. package/claw/skills/bitshares-guide/references/scope-guardrails.md +9 -0
  9. package/claw/skills/launcher-ops/SKILL.md +18 -0
  10. package/claw/skills/launcher-ops/references/launcher-workflow.md +23 -0
  11. package/claw/skills/margin-trading/SKILL.md +23 -0
  12. package/claw/skills/margin-trading/references/honest-asset-list.md +74 -0
  13. package/claw/skills/margin-trading/references/honest-assets.md +44 -0
  14. package/claw/skills/margin-trading/references/position-management.md +203 -0
  15. package/claw/skills/margin-trading/references/trading-concepts.md +80 -0
  16. package/claw/skills/memu-memory/SKILL.md +218 -0
  17. package/claw/skills/shared/references/js-automation-overview.md +24 -0
  18. package/claw/skills/shared/references/safety-and-staleness.md +11 -0
  19. package/claw/skills/shared/references/skill-boundaries.md +17 -0
  20. package/claw/skills/trend-detection/SKILL.md +33 -0
  21. package/claw/skills/trend-detection/agents/openai.yaml +3 -0
  22. package/claw/skills/trend-detection/references/service.md +45 -0
  23. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +3 -0
  24. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +1 -0
  25. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +149 -0
  26. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +1 -0
  27. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +3 -0
  28. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +1 -0
  29. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +387 -0
  30. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -0
  31. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +3 -0
  32. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +1 -0
  33. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +200 -0
  34. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -0
  35. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +3 -0
  36. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +1 -0
  37. package/dist/analysis/ama_fitting/fetch_lp_candles.js +212 -0
  38. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -0
  39. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +31 -0
  40. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +1 -0
  41. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +249 -0
  42. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +1 -0
  43. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +2 -0
  44. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -0
  45. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +782 -0
  46. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -0
  47. package/dist/analysis/analyze_derivatives.d.ts +95 -0
  48. package/dist/analysis/analyze_derivatives.d.ts.map +1 -0
  49. package/dist/analysis/analyze_derivatives.js +295 -0
  50. package/dist/analysis/analyze_derivatives.js.map +1 -0
  51. package/dist/analysis/analyze_dynamic_weight.d.ts +14 -0
  52. package/dist/analysis/analyze_dynamic_weight.d.ts.map +1 -0
  53. package/dist/analysis/analyze_dynamic_weight.js +208 -0
  54. package/dist/analysis/analyze_dynamic_weight.js.map +1 -0
  55. package/dist/analysis/analyze_kalman.d.ts +13 -0
  56. package/dist/analysis/analyze_kalman.d.ts.map +1 -0
  57. package/dist/analysis/analyze_kalman.js +123 -0
  58. package/dist/analysis/analyze_kalman.js.map +1 -0
  59. package/dist/analysis/analyze_regime.d.ts +20 -0
  60. package/dist/analysis/analyze_regime.d.ts.map +1 -0
  61. package/dist/analysis/analyze_regime.js +139 -0
  62. package/dist/analysis/analyze_regime.js.map +1 -0
  63. package/dist/analysis/analyze_regime_windows.d.ts +19 -0
  64. package/dist/analysis/analyze_regime_windows.d.ts.map +1 -0
  65. package/dist/analysis/analyze_regime_windows.js +413 -0
  66. package/dist/analysis/analyze_regime_windows.js.map +1 -0
  67. package/dist/analysis/analyze_risk_profile.d.ts +3 -0
  68. package/dist/analysis/analyze_risk_profile.d.ts.map +1 -0
  69. package/dist/analysis/analyze_risk_profile.js +159 -0
  70. package/dist/analysis/analyze_risk_profile.js.map +1 -0
  71. package/dist/analysis/analyze_trade_heatmap.d.ts +3 -0
  72. package/dist/analysis/analyze_trade_heatmap.d.ts.map +1 -0
  73. package/dist/analysis/analyze_trade_heatmap.js +367 -0
  74. package/dist/analysis/analyze_trade_heatmap.js.map +1 -0
  75. package/dist/analysis/analyze_volatility.d.ts +22 -0
  76. package/dist/analysis/analyze_volatility.d.ts.map +1 -0
  77. package/dist/analysis/analyze_volatility.js +172 -0
  78. package/dist/analysis/analyze_volatility.js.map +1 -0
  79. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +99 -0
  80. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -0
  81. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +804 -0
  82. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -0
  83. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +2 -0
  84. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +1 -0
  85. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +347 -0
  86. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -0
  87. package/dist/analysis/bot_fitting/shared_utils.d.ts +15 -0
  88. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -0
  89. package/dist/analysis/bot_fitting/shared_utils.js +48 -0
  90. package/dist/analysis/bot_fitting/shared_utils.js.map +1 -0
  91. package/dist/analysis/bot_key_utils.d.ts +16 -0
  92. package/dist/analysis/bot_key_utils.d.ts.map +1 -0
  93. package/dist/analysis/bot_key_utils.js +61 -0
  94. package/dist/analysis/bot_key_utils.js.map +1 -0
  95. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +3 -0
  96. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +1 -0
  97. package/dist/analysis/bot_usage/discover_bot_accounts.js +498 -0
  98. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -0
  99. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +546 -0
  100. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -0
  101. package/dist/analysis/bot_usage/kibana_bot_queries.js +427 -0
  102. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -0
  103. package/dist/analysis/chart_utils.d.ts +13 -0
  104. package/dist/analysis/chart_utils.d.ts.map +1 -0
  105. package/dist/analysis/chart_utils.js +142 -0
  106. package/dist/analysis/chart_utils.js.map +1 -0
  107. package/dist/analysis/derivative_chart_generator.d.ts +18 -0
  108. package/dist/analysis/derivative_chart_generator.d.ts.map +1 -0
  109. package/dist/analysis/derivative_chart_generator.js +896 -0
  110. package/dist/analysis/derivative_chart_generator.js.map +1 -0
  111. package/dist/analysis/math_utils.d.ts +35 -0
  112. package/dist/analysis/math_utils.d.ts.map +1 -0
  113. package/dist/analysis/math_utils.js +121 -0
  114. package/dist/analysis/math_utils.js.map +1 -0
  115. package/dist/analysis/price_sources.d.ts +34 -0
  116. package/dist/analysis/price_sources.d.ts.map +1 -0
  117. package/dist/analysis/price_sources.js +103 -0
  118. package/dist/analysis/price_sources.js.map +1 -0
  119. package/dist/analysis/trade_profitability.d.ts +115 -0
  120. package/dist/analysis/trade_profitability.d.ts.map +1 -0
  121. package/dist/analysis/trade_profitability.js +1247 -0
  122. package/dist/analysis/trade_profitability.js.map +1 -0
  123. package/dist/analysis/tradingview/analyze_tradingview.d.ts +38 -0
  124. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -0
  125. package/dist/analysis/tradingview/analyze_tradingview.js +212 -0
  126. package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -0
  127. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +9 -0
  128. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -0
  129. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +1717 -0
  130. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -0
  131. package/dist/analysis/trend_detection/derivative_analyzer.d.ts +250 -0
  132. package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +1 -0
  133. package/dist/analysis/trend_detection/derivative_analyzer.js +903 -0
  134. package/dist/analysis/trend_detection/derivative_analyzer.js.map +1 -0
  135. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +6 -0
  136. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -0
  137. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +1449 -0
  138. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -0
  139. package/dist/analysis/trend_detection/hurst_analyzer.d.ts +42 -0
  140. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -0
  141. package/dist/analysis/trend_detection/hurst_analyzer.js +159 -0
  142. package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -0
  143. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +6 -0
  144. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -0
  145. package/dist/analysis/trend_detection/kalman_chart_generator.js +408 -0
  146. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -0
  147. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +103 -0
  148. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -0
  149. package/dist/analysis/trend_detection/kalman_trend_analyzer.js +229 -0
  150. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -0
  151. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +34 -0
  152. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -0
  153. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +89 -0
  154. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -0
  155. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +39 -0
  156. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -0
  157. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +132 -0
  158. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -0
  159. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +6 -0
  160. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -0
  161. package/dist/analysis/trend_detection/regime_chart_generator.js +345 -0
  162. package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -0
  163. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +2 -0
  164. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +1 -0
  165. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +130 -0
  166. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +1 -0
  167. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +2 -0
  168. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +1 -0
  169. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +38 -0
  170. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +1 -0
  171. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +6 -0
  172. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +1 -0
  173. package/dist/analysis/trend_detection/volatility_chart_generator.js +732 -0
  174. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -0
  175. package/dist/bot.d.ts +49 -0
  176. package/dist/bot.d.ts.map +1 -0
  177. package/dist/bot.js +221 -0
  178. package/dist/bot.js.map +1 -0
  179. package/dist/credential-daemon.d.ts +64 -0
  180. package/dist/credential-daemon.d.ts.map +1 -0
  181. package/dist/credential-daemon.js +987 -0
  182. package/dist/credential-daemon.js.map +1 -0
  183. package/dist/dexbot.d.ts +87 -0
  184. package/dist/dexbot.d.ts.map +1 -0
  185. package/dist/dexbot.js +1222 -0
  186. package/dist/dexbot.js.map +1 -0
  187. package/dist/market_adapter/ama_signal_runner.d.ts +3 -0
  188. package/dist/market_adapter/ama_signal_runner.d.ts.map +1 -0
  189. package/dist/market_adapter/ama_signal_runner.js +175 -0
  190. package/dist/market_adapter/ama_signal_runner.js.map +1 -0
  191. package/dist/market_adapter/candle_utils.d.ts +57 -0
  192. package/dist/market_adapter/candle_utils.d.ts.map +1 -0
  193. package/dist/market_adapter/candle_utils.js +252 -0
  194. package/dist/market_adapter/candle_utils.js.map +1 -0
  195. package/dist/market_adapter/core/asymmetric_bounds.d.ts +20 -0
  196. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -0
  197. package/dist/market_adapter/core/asymmetric_bounds.js +88 -0
  198. package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -0
  199. package/dist/market_adapter/core/config_normalizers.d.ts +10 -0
  200. package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -0
  201. package/dist/market_adapter/core/config_normalizers.js +24 -0
  202. package/dist/market_adapter/core/config_normalizers.js.map +1 -0
  203. package/dist/market_adapter/core/kibana_candles.d.ts +74 -0
  204. package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -0
  205. package/dist/market_adapter/core/kibana_candles.js +249 -0
  206. package/dist/market_adapter/core/kibana_candles.js.map +1 -0
  207. package/dist/market_adapter/core/kibana_client.d.ts +27 -0
  208. package/dist/market_adapter/core/kibana_client.d.ts.map +1 -0
  209. package/dist/market_adapter/core/kibana_client.js +120 -0
  210. package/dist/market_adapter/core/kibana_client.js.map +1 -0
  211. package/dist/market_adapter/core/kibana_market_candles.d.ts +143 -0
  212. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -0
  213. package/dist/market_adapter/core/kibana_market_candles.js +170 -0
  214. package/dist/market_adapter/core/kibana_market_candles.js.map +1 -0
  215. package/dist/market_adapter/core/market_adapter_service.d.ts +210 -0
  216. package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -0
  217. package/dist/market_adapter/core/market_adapter_service.js +2328 -0
  218. package/dist/market_adapter/core/market_adapter_service.js.map +1 -0
  219. package/dist/market_adapter/core/strategies/ama.d.ts +2 -0
  220. package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -0
  221. package/dist/market_adapter/core/strategies/ama.js +138 -0
  222. package/dist/market_adapter/core/strategies/ama.js.map +1 -0
  223. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +50 -0
  224. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -0
  225. package/dist/market_adapter/core/strategies/ama_slope_model.js +143 -0
  226. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -0
  227. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +12 -0
  228. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -0
  229. package/dist/market_adapter/core/strategies/atr/calculator.js +47 -0
  230. package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -0
  231. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +32 -0
  232. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -0
  233. package/dist/market_adapter/core/strategies/collateral_manager.js +68 -0
  234. package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -0
  235. package/dist/market_adapter/core/strategies/regime_gate.d.ts +66 -0
  236. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -0
  237. package/dist/market_adapter/core/strategies/regime_gate.js +189 -0
  238. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -0
  239. package/dist/market_adapter/index.d.ts +10 -0
  240. package/dist/market_adapter/index.d.ts.map +1 -0
  241. package/dist/market_adapter/index.js +71 -0
  242. package/dist/market_adapter/index.js.map +1 -0
  243. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts +3 -0
  244. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +1 -0
  245. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +1165 -0
  246. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -0
  247. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +54 -0
  248. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -0
  249. package/dist/market_adapter/inputs/fetch_lp_data.js +743 -0
  250. package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -0
  251. package/dist/market_adapter/inputs/kibana_source.d.ts +68 -0
  252. package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -0
  253. package/dist/market_adapter/inputs/kibana_source.js +143 -0
  254. package/dist/market_adapter/inputs/kibana_source.js.map +1 -0
  255. package/dist/market_adapter/interval_utils.d.ts +6 -0
  256. package/dist/market_adapter/interval_utils.d.ts.map +1 -0
  257. package/dist/market_adapter/interval_utils.js +14 -0
  258. package/dist/market_adapter/interval_utils.js.map +1 -0
  259. package/dist/market_adapter/log_format.d.ts +16 -0
  260. package/dist/market_adapter/log_format.d.ts.map +1 -0
  261. package/dist/market_adapter/log_format.js +72 -0
  262. package/dist/market_adapter/log_format.js.map +1 -0
  263. package/dist/market_adapter/lp_chart_core.d.ts +6 -0
  264. package/dist/market_adapter/lp_chart_core.d.ts.map +1 -0
  265. package/dist/market_adapter/lp_chart_core.js +874 -0
  266. package/dist/market_adapter/lp_chart_core.js.map +1 -0
  267. package/dist/market_adapter/lp_chart_runner.d.ts +135 -0
  268. package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -0
  269. package/dist/market_adapter/lp_chart_runner.js +337 -0
  270. package/dist/market_adapter/lp_chart_runner.js.map +1 -0
  271. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +23 -0
  272. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -0
  273. package/dist/market_adapter/lp_chart_strategy_loader.js +169 -0
  274. package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -0
  275. package/dist/market_adapter/market_adapter.d.ts +133 -0
  276. package/dist/market_adapter/market_adapter.d.ts.map +1 -0
  277. package/dist/market_adapter/market_adapter.js +1331 -0
  278. package/dist/market_adapter/market_adapter.js.map +1 -0
  279. package/dist/market_adapter/merge_lp_data.d.ts +3 -0
  280. package/dist/market_adapter/merge_lp_data.d.ts.map +1 -0
  281. package/dist/market_adapter/merge_lp_data.js +125 -0
  282. package/dist/market_adapter/merge_lp_data.js.map +1 -0
  283. package/dist/market_adapter/test_helpers.d.ts +14 -0
  284. package/dist/market_adapter/test_helpers.d.ts.map +1 -0
  285. package/dist/market_adapter/test_helpers.js +22 -0
  286. package/dist/market_adapter/test_helpers.js.map +1 -0
  287. package/dist/market_adapter/utils/adapter_client.d.ts +20 -0
  288. package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -0
  289. package/dist/market_adapter/utils/adapter_client.js +88 -0
  290. package/dist/market_adapter/utils/adapter_client.js.map +1 -0
  291. package/dist/market_adapter/utils/atomic_write.d.ts +9 -0
  292. package/dist/market_adapter/utils/atomic_write.d.ts.map +1 -0
  293. package/dist/market_adapter/utils/atomic_write.js +13 -0
  294. package/dist/market_adapter/utils/atomic_write.js.map +1 -0
  295. package/dist/market_adapter/utils/chain.d.ts +50 -0
  296. package/dist/market_adapter/utils/chain.d.ts.map +1 -0
  297. package/dist/market_adapter/utils/chain.js +196 -0
  298. package/dist/market_adapter/utils/chain.js.map +1 -0
  299. package/dist/market_adapter/utils/data_discovery.d.ts +6 -0
  300. package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -0
  301. package/dist/market_adapter/utils/data_discovery.js +35 -0
  302. package/dist/market_adapter/utils/data_discovery.js.map +1 -0
  303. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +15 -0
  304. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -0
  305. package/dist/market_adapter/utils/dynamic_grid_snapshot.js +60 -0
  306. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -0
  307. package/dist/market_adapter/utils/file_lock.d.ts +19 -0
  308. package/dist/market_adapter/utils/file_lock.d.ts.map +1 -0
  309. package/dist/market_adapter/utils/file_lock.js +191 -0
  310. package/dist/market_adapter/utils/file_lock.js.map +1 -0
  311. package/dist/market_adapter/utils/native_history.d.ts +19 -0
  312. package/dist/market_adapter/utils/native_history.d.ts.map +1 -0
  313. package/dist/market_adapter/utils/native_history.js +172 -0
  314. package/dist/market_adapter/utils/native_history.js.map +1 -0
  315. package/dist/market_adapter/utils/paths.d.ts +5 -0
  316. package/dist/market_adapter/utils/paths.d.ts.map +1 -0
  317. package/dist/market_adapter/utils/paths.js +7 -0
  318. package/dist/market_adapter/utils/paths.js.map +1 -0
  319. package/dist/modules/account_bots.d.ts +112 -0
  320. package/dist/modules/account_bots.d.ts.map +1 -0
  321. package/dist/modules/account_bots.js +1259 -0
  322. package/dist/modules/account_bots.js.map +1 -0
  323. package/dist/modules/account_orders.d.ts +273 -0
  324. package/dist/modules/account_orders.d.ts.map +1 -0
  325. package/dist/modules/account_orders.js +662 -0
  326. package/dist/modules/account_orders.js.map +1 -0
  327. package/dist/modules/authority_resolver.d.ts +2 -0
  328. package/dist/modules/authority_resolver.d.ts.map +1 -0
  329. package/dist/modules/authority_resolver.js +231 -0
  330. package/dist/modules/authority_resolver.js.map +1 -0
  331. package/dist/modules/bitshares-native/chain_client.d.ts +38 -0
  332. package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -0
  333. package/dist/modules/bitshares-native/chain_client.js +322 -0
  334. package/dist/modules/bitshares-native/chain_client.js.map +1 -0
  335. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +59 -0
  336. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -0
  337. package/dist/modules/bitshares-native/crypto/ecc.browser.js +456 -0
  338. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -0
  339. package/dist/modules/bitshares-native/crypto/ecc.d.ts +66 -0
  340. package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +1 -0
  341. package/dist/modules/bitshares-native/crypto/ecc.js +557 -0
  342. package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -0
  343. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -0
  344. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -0
  345. package/dist/modules/bitshares-native/crypto/ecc_selector.js +20 -0
  346. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -0
  347. package/dist/modules/bitshares-native/index.d.ts +3 -0
  348. package/dist/modules/bitshares-native/index.d.ts.map +1 -0
  349. package/dist/modules/bitshares-native/index.js +32 -0
  350. package/dist/modules/bitshares-native/index.js.map +1 -0
  351. package/dist/modules/bitshares-native/resolvers.d.ts +40 -0
  352. package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -0
  353. package/dist/modules/bitshares-native/resolvers.js +161 -0
  354. package/dist/modules/bitshares-native/resolvers.js.map +1 -0
  355. package/dist/modules/bitshares-native/serial/chain_constants.d.ts +56 -0
  356. package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +1 -0
  357. package/dist/modules/bitshares-native/serial/chain_constants.js +92 -0
  358. package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -0
  359. package/dist/modules/bitshares-native/serial/index.d.ts +10 -0
  360. package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -0
  361. package/dist/modules/bitshares-native/serial/index.js +14 -0
  362. package/dist/modules/bitshares-native/serial/index.js.map +1 -0
  363. package/dist/modules/bitshares-native/serial/operations.d.ts +102 -0
  364. package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -0
  365. package/dist/modules/bitshares-native/serial/operations.js +615 -0
  366. package/dist/modules/bitshares-native/serial/operations.js.map +1 -0
  367. package/dist/modules/bitshares-native/serial/serializer.d.ts +64 -0
  368. package/dist/modules/bitshares-native/serial/serializer.d.ts.map +1 -0
  369. package/dist/modules/bitshares-native/serial/serializer.js +252 -0
  370. package/dist/modules/bitshares-native/serial/serializer.js.map +1 -0
  371. package/dist/modules/bitshares-native/serial/types.d.ts +120 -0
  372. package/dist/modules/bitshares-native/serial/types.d.ts.map +1 -0
  373. package/dist/modules/bitshares-native/serial/types.js +837 -0
  374. package/dist/modules/bitshares-native/serial/types.js.map +1 -0
  375. package/dist/modules/bitshares-native/signing_client.d.ts +6 -0
  376. package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -0
  377. package/dist/modules/bitshares-native/signing_client.js +141 -0
  378. package/dist/modules/bitshares-native/signing_client.js.map +1 -0
  379. package/dist/modules/bitshares-native/subscriptions.d.ts +6 -0
  380. package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -0
  381. package/dist/modules/bitshares-native/subscriptions.js +865 -0
  382. package/dist/modules/bitshares-native/subscriptions.js.map +1 -0
  383. package/dist/modules/bitshares-native/transport.d.ts +51 -0
  384. package/dist/modules/bitshares-native/transport.d.ts.map +1 -0
  385. package/dist/modules/bitshares-native/transport.js +447 -0
  386. package/dist/modules/bitshares-native/transport.js.map +1 -0
  387. package/dist/modules/bitshares-native/tx/builder.d.ts +30 -0
  388. package/dist/modules/bitshares-native/tx/builder.d.ts.map +1 -0
  389. package/dist/modules/bitshares-native/tx/builder.js +262 -0
  390. package/dist/modules/bitshares-native/tx/builder.js.map +1 -0
  391. package/dist/modules/bitshares_client.d.ts +129 -0
  392. package/dist/modules/bitshares_client.d.ts.map +1 -0
  393. package/dist/modules/bitshares_client.js +627 -0
  394. package/dist/modules/bitshares_client.js.map +1 -0
  395. package/dist/modules/bot_settings.d.ts +33 -0
  396. package/dist/modules/bot_settings.d.ts.map +1 -0
  397. package/dist/modules/bot_settings.js +328 -0
  398. package/dist/modules/bot_settings.js.map +1 -0
  399. package/dist/modules/bots_file_lock.d.ts +88 -0
  400. package/dist/modules/bots_file_lock.d.ts.map +1 -0
  401. package/dist/modules/bots_file_lock.js +161 -0
  402. package/dist/modules/bots_file_lock.js.map +1 -0
  403. package/dist/modules/chain_keys.d.ts +302 -0
  404. package/dist/modules/chain_keys.d.ts.map +1 -0
  405. package/dist/modules/chain_keys.js +1095 -0
  406. package/dist/modules/chain_keys.js.map +1 -0
  407. package/dist/modules/chain_orders.d.ts +423 -0
  408. package/dist/modules/chain_orders.d.ts.map +1 -0
  409. package/dist/modules/chain_orders.js +1201 -0
  410. package/dist/modules/chain_orders.js.map +1 -0
  411. package/dist/modules/cli_whitelist_args.d.ts +6 -0
  412. package/dist/modules/cli_whitelist_args.d.ts.map +1 -0
  413. package/dist/modules/cli_whitelist_args.js +13 -0
  414. package/dist/modules/cli_whitelist_args.js.map +1 -0
  415. package/dist/modules/config.d.ts +57 -0
  416. package/dist/modules/config.d.ts.map +1 -0
  417. package/dist/modules/config.js +107 -0
  418. package/dist/modules/config.js.map +1 -0
  419. package/dist/modules/constants.d.ts +635 -0
  420. package/dist/modules/constants.d.ts.map +1 -0
  421. package/dist/modules/constants.js +1464 -0
  422. package/dist/modules/constants.js.map +1 -0
  423. package/dist/modules/cr_planner.d.ts +51 -0
  424. package/dist/modules/cr_planner.d.ts.map +1 -0
  425. package/dist/modules/cr_planner.js +299 -0
  426. package/dist/modules/cr_planner.js.map +1 -0
  427. package/dist/modules/credential_policy.d.ts +188 -0
  428. package/dist/modules/credential_policy.d.ts.map +1 -0
  429. package/dist/modules/credential_policy.js +1452 -0
  430. package/dist/modules/credential_policy.js.map +1 -0
  431. package/dist/modules/credential_runtime.d.ts +42 -0
  432. package/dist/modules/credential_runtime.d.ts.map +1 -0
  433. package/dist/modules/credential_runtime.js +148 -0
  434. package/dist/modules/credential_runtime.js.map +1 -0
  435. package/dist/modules/credential_session_cache.d.ts +36 -0
  436. package/dist/modules/credential_session_cache.d.ts.map +1 -0
  437. package/dist/modules/credential_session_cache.js +106 -0
  438. package/dist/modules/credential_session_cache.js.map +1 -0
  439. package/dist/modules/credit_runtime.d.ts +412 -0
  440. package/dist/modules/credit_runtime.d.ts.map +1 -0
  441. package/dist/modules/credit_runtime.js +2866 -0
  442. package/dist/modules/credit_runtime.js.map +1 -0
  443. package/dist/modules/crypto/browser_provider.d.ts +15 -0
  444. package/dist/modules/crypto/browser_provider.d.ts.map +1 -0
  445. package/dist/modules/crypto/browser_provider.js +113 -0
  446. package/dist/modules/crypto/browser_provider.js.map +1 -0
  447. package/dist/modules/crypto/index.d.ts +9 -0
  448. package/dist/modules/crypto/index.d.ts.map +1 -0
  449. package/dist/modules/crypto/index.js +44 -0
  450. package/dist/modules/crypto/index.js.map +1 -0
  451. package/dist/modules/crypto/node_provider.d.ts +15 -0
  452. package/dist/modules/crypto/node_provider.d.ts.map +1 -0
  453. package/dist/modules/crypto/node_provider.js +74 -0
  454. package/dist/modules/crypto/node_provider.js.map +1 -0
  455. package/dist/modules/crypto/provider.d.ts +34 -0
  456. package/dist/modules/crypto/provider.d.ts.map +1 -0
  457. package/dist/modules/crypto/provider.js +3 -0
  458. package/dist/modules/crypto/provider.js.map +1 -0
  459. package/dist/modules/crypto/pure_ripemd160.d.ts +8 -0
  460. package/dist/modules/crypto/pure_ripemd160.d.ts.map +1 -0
  461. package/dist/modules/crypto/pure_ripemd160.js +142 -0
  462. package/dist/modules/crypto/pure_ripemd160.js.map +1 -0
  463. package/dist/modules/crypto/pure_scrypt.d.ts +23 -0
  464. package/dist/modules/crypto/pure_scrypt.d.ts.map +1 -0
  465. package/dist/modules/crypto/pure_scrypt.js +161 -0
  466. package/dist/modules/crypto/pure_scrypt.js.map +1 -0
  467. package/dist/modules/crypto/pure_secp256k1.d.ts +29 -0
  468. package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -0
  469. package/dist/modules/crypto/pure_secp256k1.js +195 -0
  470. package/dist/modules/crypto/pure_secp256k1.js.map +1 -0
  471. package/dist/modules/crypto/sync.d.ts +13 -0
  472. package/dist/modules/crypto/sync.d.ts.map +1 -0
  473. package/dist/modules/crypto/sync.js +37 -0
  474. package/dist/modules/crypto/sync.js.map +1 -0
  475. package/dist/modules/dexbot_class.d.ts +1074 -0
  476. package/dist/modules/dexbot_class.d.ts.map +1 -0
  477. package/dist/modules/dexbot_class.js +4613 -0
  478. package/dist/modules/dexbot_class.js.map +1 -0
  479. package/dist/modules/dexbot_credential_client.d.ts +71 -0
  480. package/dist/modules/dexbot_credential_client.d.ts.map +1 -0
  481. package/dist/modules/dexbot_credential_client.js +224 -0
  482. package/dist/modules/dexbot_credential_client.js.map +1 -0
  483. package/dist/modules/dexbot_fill_runtime.d.ts +173 -0
  484. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -0
  485. package/dist/modules/dexbot_fill_runtime.js +217 -0
  486. package/dist/modules/dexbot_fill_runtime.js.map +1 -0
  487. package/dist/modules/dexbot_maintenance_runtime.d.ts +279 -0
  488. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -0
  489. package/dist/modules/dexbot_maintenance_runtime.js +1613 -0
  490. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -0
  491. package/dist/modules/env.d.ts +12 -0
  492. package/dist/modules/env.d.ts.map +1 -0
  493. package/dist/modules/env.js +57 -0
  494. package/dist/modules/env.js.map +1 -0
  495. package/dist/modules/fund_registry.d.ts +96 -0
  496. package/dist/modules/fund_registry.d.ts.map +1 -0
  497. package/dist/modules/fund_registry.js +261 -0
  498. package/dist/modules/fund_registry.js.map +1 -0
  499. package/dist/modules/general_settings.d.ts +36 -0
  500. package/dist/modules/general_settings.d.ts.map +1 -0
  501. package/dist/modules/general_settings.js +63 -0
  502. package/dist/modules/general_settings.js.map +1 -0
  503. package/dist/modules/graceful_shutdown.d.ts +86 -0
  504. package/dist/modules/graceful_shutdown.d.ts.map +1 -0
  505. package/dist/modules/graceful_shutdown.js +164 -0
  506. package/dist/modules/graceful_shutdown.js.map +1 -0
  507. package/dist/modules/key_store.d.ts +60 -0
  508. package/dist/modules/key_store.d.ts.map +1 -0
  509. package/dist/modules/key_store.js +215 -0
  510. package/dist/modules/key_store.js.map +1 -0
  511. package/dist/modules/launcher/bot_supervisor.d.ts +84 -0
  512. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -0
  513. package/dist/modules/launcher/bot_supervisor.js +1067 -0
  514. package/dist/modules/launcher/bot_supervisor.js.map +1 -0
  515. package/dist/modules/launcher/child_env.d.ts +9 -0
  516. package/dist/modules/launcher/child_env.d.ts.map +1 -0
  517. package/dist/modules/launcher/child_env.js +78 -0
  518. package/dist/modules/launcher/child_env.js.map +1 -0
  519. package/dist/modules/launcher/credential_bootstrap.d.ts +22 -0
  520. package/dist/modules/launcher/credential_bootstrap.d.ts.map +1 -0
  521. package/dist/modules/launcher/credential_bootstrap.js +303 -0
  522. package/dist/modules/launcher/credential_bootstrap.js.map +1 -0
  523. package/dist/modules/launcher/credential_daemon.d.ts +32 -0
  524. package/dist/modules/launcher/credential_daemon.d.ts.map +1 -0
  525. package/dist/modules/launcher/credential_daemon.js +173 -0
  526. package/dist/modules/launcher/credential_daemon.js.map +1 -0
  527. package/dist/modules/launcher/credential_secret.d.ts +6 -0
  528. package/dist/modules/launcher/credential_secret.d.ts.map +1 -0
  529. package/dist/modules/launcher/credential_secret.js +15 -0
  530. package/dist/modules/launcher/credential_secret.js.map +1 -0
  531. package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -0
  532. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -0
  533. package/dist/modules/launcher/foreign_cred_daemon.js +166 -0
  534. package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -0
  535. package/dist/modules/launcher/headless_password.d.ts +8 -0
  536. package/dist/modules/launcher/headless_password.d.ts.map +1 -0
  537. package/dist/modules/launcher/headless_password.js +33 -0
  538. package/dist/modules/launcher/headless_password.js.map +1 -0
  539. package/dist/modules/launcher/launch_modes.d.ts +36 -0
  540. package/dist/modules/launcher/launch_modes.d.ts.map +1 -0
  541. package/dist/modules/launcher/launch_modes.js +129 -0
  542. package/dist/modules/launcher/launch_modes.js.map +1 -0
  543. package/dist/modules/launcher/market_adapter_runtime.d.ts +43 -0
  544. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -0
  545. package/dist/modules/launcher/market_adapter_runtime.js +217 -0
  546. package/dist/modules/launcher/market_adapter_runtime.js.map +1 -0
  547. package/dist/modules/launcher/market_adapter_watchdog.d.ts +26 -0
  548. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -0
  549. package/dist/modules/launcher/market_adapter_watchdog.js +214 -0
  550. package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -0
  551. package/dist/modules/launcher/monolithic_runtime.d.ts +89 -0
  552. package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -0
  553. package/dist/modules/launcher/monolithic_runtime.js +425 -0
  554. package/dist/modules/launcher/monolithic_runtime.js.map +1 -0
  555. package/dist/modules/launcher/runtime_entry.d.ts +26 -0
  556. package/dist/modules/launcher/runtime_entry.d.ts.map +1 -0
  557. package/dist/modules/launcher/runtime_entry.js +49 -0
  558. package/dist/modules/launcher/runtime_entry.js.map +1 -0
  559. package/dist/modules/launcher/status_reporting.d.ts +48 -0
  560. package/dist/modules/launcher/status_reporting.d.ts.map +1 -0
  561. package/dist/modules/launcher/status_reporting.js +113 -0
  562. package/dist/modules/launcher/status_reporting.js.map +1 -0
  563. package/dist/modules/launcher/supervisor_control.d.ts +6 -0
  564. package/dist/modules/launcher/supervisor_control.d.ts.map +1 -0
  565. package/dist/modules/launcher/supervisor_control.js +59 -0
  566. package/dist/modules/launcher/supervisor_control.js.map +1 -0
  567. package/dist/modules/logger.d.ts +2 -0
  568. package/dist/modules/logger.d.ts.map +1 -0
  569. package/dist/modules/logger.js +71 -0
  570. package/dist/modules/logger.js.map +1 -0
  571. package/dist/modules/market_adapter_whitelist.d.ts +22 -0
  572. package/dist/modules/market_adapter_whitelist.d.ts.map +1 -0
  573. package/dist/modules/market_adapter_whitelist.js +82 -0
  574. package/dist/modules/market_adapter_whitelist.js.map +1 -0
  575. package/dist/modules/node_health_cache.d.ts +55 -0
  576. package/dist/modules/node_health_cache.d.ts.map +1 -0
  577. package/dist/modules/node_health_cache.js +134 -0
  578. package/dist/modules/node_health_cache.js.map +1 -0
  579. package/dist/modules/node_manager.d.ts +215 -0
  580. package/dist/modules/node_manager.d.ts.map +1 -0
  581. package/dist/modules/node_manager.js +628 -0
  582. package/dist/modules/node_manager.js.map +1 -0
  583. package/dist/modules/order/accounting.d.ts +349 -0
  584. package/dist/modules/order/accounting.d.ts.map +1 -0
  585. package/dist/modules/order/accounting.js +1191 -0
  586. package/dist/modules/order/accounting.js.map +1 -0
  587. package/dist/modules/order/async_lock.d.ts +126 -0
  588. package/dist/modules/order/async_lock.d.ts.map +1 -0
  589. package/dist/modules/order/async_lock.js +195 -0
  590. package/dist/modules/order/async_lock.js.map +1 -0
  591. package/dist/modules/order/export.d.ts +129 -0
  592. package/dist/modules/order/export.d.ts.map +1 -0
  593. package/dist/modules/order/export.js +316 -0
  594. package/dist/modules/order/export.js.map +1 -0
  595. package/dist/modules/order/format.d.ts +158 -0
  596. package/dist/modules/order/format.d.ts.map +1 -0
  597. package/dist/modules/order/format.js +232 -0
  598. package/dist/modules/order/format.js.map +1 -0
  599. package/dist/modules/order/grid.d.ts +549 -0
  600. package/dist/modules/order/grid.d.ts.map +1 -0
  601. package/dist/modules/order/grid.js +1746 -0
  602. package/dist/modules/order/grid.js.map +1 -0
  603. package/dist/modules/order/grid_reconcile.d.ts +154 -0
  604. package/dist/modules/order/grid_reconcile.d.ts.map +1 -0
  605. package/dist/modules/order/grid_reconcile.js +1192 -0
  606. package/dist/modules/order/grid_reconcile.js.map +1 -0
  607. package/dist/modules/order/index.d.ts +55 -0
  608. package/dist/modules/order/index.d.ts.map +1 -0
  609. package/dist/modules/order/index.js +79 -0
  610. package/dist/modules/order/index.js.map +1 -0
  611. package/dist/modules/order/logger.d.ts +136 -0
  612. package/dist/modules/order/logger.d.ts.map +1 -0
  613. package/dist/modules/order/logger.js +614 -0
  614. package/dist/modules/order/logger.js.map +1 -0
  615. package/dist/modules/order/logger_state.d.ts +133 -0
  616. package/dist/modules/order/logger_state.d.ts.map +1 -0
  617. package/dist/modules/order/logger_state.js +170 -0
  618. package/dist/modules/order/logger_state.js.map +1 -0
  619. package/dist/modules/order/manager.d.ts +413 -0
  620. package/dist/modules/order/manager.d.ts.map +1 -0
  621. package/dist/modules/order/manager.js +1605 -0
  622. package/dist/modules/order/manager.js.map +1 -0
  623. package/dist/modules/order/processed_fill_store.d.ts +135 -0
  624. package/dist/modules/order/processed_fill_store.d.ts.map +1 -0
  625. package/dist/modules/order/processed_fill_store.js +288 -0
  626. package/dist/modules/order/processed_fill_store.js.map +1 -0
  627. package/dist/modules/order/runner.d.ts +70 -0
  628. package/dist/modules/order/runner.d.ts.map +1 -0
  629. package/dist/modules/order/runner.js +140 -0
  630. package/dist/modules/order/runner.js.map +1 -0
  631. package/dist/modules/order/strategy.d.ts +196 -0
  632. package/dist/modules/order/strategy.d.ts.map +1 -0
  633. package/dist/modules/order/strategy.js +398 -0
  634. package/dist/modules/order/strategy.js.map +1 -0
  635. package/dist/modules/order/sync_engine.d.ts +386 -0
  636. package/dist/modules/order/sync_engine.d.ts.map +1 -0
  637. package/dist/modules/order/sync_engine.js +1459 -0
  638. package/dist/modules/order/sync_engine.js.map +1 -0
  639. package/dist/modules/order/utils/math.d.ts +677 -0
  640. package/dist/modules/order/utils/math.d.ts.map +1 -0
  641. package/dist/modules/order/utils/math.js +1172 -0
  642. package/dist/modules/order/utils/math.js.map +1 -0
  643. package/dist/modules/order/utils/order.d.ts +572 -0
  644. package/dist/modules/order/utils/order.d.ts.map +1 -0
  645. package/dist/modules/order/utils/order.js +1145 -0
  646. package/dist/modules/order/utils/order.js.map +1 -0
  647. package/dist/modules/order/utils/system.d.ts +268 -0
  648. package/dist/modules/order/utils/system.d.ts.map +1 -0
  649. package/dist/modules/order/utils/system.js +1261 -0
  650. package/dist/modules/order/utils/system.js.map +1 -0
  651. package/dist/modules/order/utils/validate.d.ts +280 -0
  652. package/dist/modules/order/utils/validate.d.ts.map +1 -0
  653. package/dist/modules/order/utils/validate.js +918 -0
  654. package/dist/modules/order/utils/validate.js.map +1 -0
  655. package/dist/modules/order/working_grid.d.ts +212 -0
  656. package/dist/modules/order/working_grid.d.ts.map +1 -0
  657. package/dist/modules/order/working_grid.js +279 -0
  658. package/dist/modules/order/working_grid.js.map +1 -0
  659. package/dist/modules/path_api.d.ts +32 -0
  660. package/dist/modules/path_api.d.ts.map +1 -0
  661. package/dist/modules/path_api.js +148 -0
  662. package/dist/modules/path_api.js.map +1 -0
  663. package/dist/modules/paths.d.ts +58 -0
  664. package/dist/modules/paths.d.ts.map +1 -0
  665. package/dist/modules/paths.js +82 -0
  666. package/dist/modules/paths.js.map +1 -0
  667. package/dist/modules/process_discovery.d.ts +58 -0
  668. package/dist/modules/process_discovery.d.ts.map +1 -0
  669. package/dist/modules/process_discovery.js +265 -0
  670. package/dist/modules/process_discovery.js.map +1 -0
  671. package/dist/modules/runtime.d.ts +34 -0
  672. package/dist/modules/runtime.d.ts.map +1 -0
  673. package/dist/modules/runtime.js +98 -0
  674. package/dist/modules/runtime.js.map +1 -0
  675. package/dist/modules/runtime_settings.d.ts +12 -0
  676. package/dist/modules/runtime_settings.d.ts.map +1 -0
  677. package/dist/modules/runtime_settings.js +122 -0
  678. package/dist/modules/runtime_settings.js.map +1 -0
  679. package/dist/modules/settings_merge.d.ts +38 -0
  680. package/dist/modules/settings_merge.d.ts.map +1 -0
  681. package/dist/modules/settings_merge.js +246 -0
  682. package/dist/modules/settings_merge.js.map +1 -0
  683. package/dist/modules/storage/browser_adapter.d.ts +56 -0
  684. package/dist/modules/storage/browser_adapter.d.ts.map +1 -0
  685. package/dist/modules/storage/browser_adapter.js +231 -0
  686. package/dist/modules/storage/browser_adapter.js.map +1 -0
  687. package/dist/modules/storage/index.d.ts +28 -0
  688. package/dist/modules/storage/index.d.ts.map +1 -0
  689. package/dist/modules/storage/index.js +52 -0
  690. package/dist/modules/storage/index.js.map +1 -0
  691. package/dist/modules/storage/node_adapter.d.ts +49 -0
  692. package/dist/modules/storage/node_adapter.d.ts.map +1 -0
  693. package/dist/modules/storage/node_adapter.js +167 -0
  694. package/dist/modules/storage/node_adapter.js.map +1 -0
  695. package/dist/modules/storage/types.d.ts +92 -0
  696. package/dist/modules/storage/types.d.ts.map +1 -0
  697. package/dist/modules/storage/types.js +3 -0
  698. package/dist/modules/storage/types.js.map +1 -0
  699. package/dist/modules/types.d.ts +1382 -0
  700. package/dist/modules/types.d.ts.map +1 -0
  701. package/dist/modules/types.js +11 -0
  702. package/dist/modules/types.js.map +1 -0
  703. package/dist/modules/utils/base58check.d.ts +12 -0
  704. package/dist/modules/utils/base58check.d.ts.map +1 -0
  705. package/dist/modules/utils/base58check.js +112 -0
  706. package/dist/modules/utils/base58check.js.map +1 -0
  707. package/dist/modules/utils/build_dir.d.ts +7 -0
  708. package/dist/modules/utils/build_dir.d.ts.map +1 -0
  709. package/dist/modules/utils/build_dir.js +8 -0
  710. package/dist/modules/utils/build_dir.js.map +1 -0
  711. package/dist/modules/utils/fs_utils.d.ts +25 -0
  712. package/dist/modules/utils/fs_utils.d.ts.map +1 -0
  713. package/dist/modules/utils/fs_utils.js +27 -0
  714. package/dist/modules/utils/fs_utils.js.map +1 -0
  715. package/dist/modules/utils/math_utils.d.ts +10 -0
  716. package/dist/modules/utils/math_utils.d.ts.map +1 -0
  717. package/dist/modules/utils/math_utils.js +17 -0
  718. package/dist/modules/utils/math_utils.js.map +1 -0
  719. package/dist/modules/validate_profiles.d.ts +37 -0
  720. package/dist/modules/validate_profiles.d.ts.map +1 -0
  721. package/dist/modules/validate_profiles.js +369 -0
  722. package/dist/modules/validate_profiles.js.map +1 -0
  723. package/dist/pm2.d.ts +167 -0
  724. package/dist/pm2.d.ts.map +1 -0
  725. package/dist/pm2.js +998 -0
  726. package/dist/pm2.js.map +1 -0
  727. package/dist/scripts/analyze-git.d.ts +11 -0
  728. package/dist/scripts/analyze-git.d.ts.map +1 -0
  729. package/dist/scripts/analyze-git.js +851 -0
  730. package/dist/scripts/analyze-git.js.map +1 -0
  731. package/dist/scripts/analyze-orders.d.ts +17 -0
  732. package/dist/scripts/analyze-orders.d.ts.map +1 -0
  733. package/dist/scripts/analyze-orders.js +1568 -0
  734. package/dist/scripts/analyze-orders.js.map +1 -0
  735. package/dist/scripts/diagnose-kibana-candles.d.ts +3 -0
  736. package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -0
  737. package/dist/scripts/diagnose-kibana-candles.js +82 -0
  738. package/dist/scripts/diagnose-kibana-candles.js.map +1 -0
  739. package/dist/scripts/diagnose-pool-history.d.ts +3 -0
  740. package/dist/scripts/diagnose-pool-history.d.ts.map +1 -0
  741. package/dist/scripts/diagnose-pool-history.js +296 -0
  742. package/dist/scripts/diagnose-pool-history.js.map +1 -0
  743. package/dist/scripts/divergence-calc.d.ts +26 -0
  744. package/dist/scripts/divergence-calc.d.ts.map +1 -0
  745. package/dist/scripts/divergence-calc.js +119 -0
  746. package/dist/scripts/divergence-calc.js.map +1 -0
  747. package/dist/scripts/generate_lp_chart.d.ts +31 -0
  748. package/dist/scripts/generate_lp_chart.d.ts.map +1 -0
  749. package/dist/scripts/generate_lp_chart.js +92 -0
  750. package/dist/scripts/generate_lp_chart.js.map +1 -0
  751. package/dist/scripts/generate_mainnet_corpus_report.d.ts +24 -0
  752. package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -0
  753. package/dist/scripts/generate_mainnet_corpus_report.js +237 -0
  754. package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -0
  755. package/dist/scripts/generate_market_adapter_whitelist.d.ts +2 -0
  756. package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -0
  757. package/dist/scripts/generate_market_adapter_whitelist.js +111 -0
  758. package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -0
  759. package/dist/scripts/migrate_bot_keys.d.ts +6 -0
  760. package/dist/scripts/migrate_bot_keys.d.ts.map +1 -0
  761. package/dist/scripts/migrate_bot_keys.js +301 -0
  762. package/dist/scripts/migrate_bot_keys.js.map +1 -0
  763. package/dist/scripts/native_release_gates.d.ts +3 -0
  764. package/dist/scripts/native_release_gates.d.ts.map +1 -0
  765. package/dist/scripts/native_release_gates.js +52 -0
  766. package/dist/scripts/native_release_gates.js.map +1 -0
  767. package/dist/scripts/print_grid.d.ts +16 -0
  768. package/dist/scripts/print_grid.d.ts.map +1 -0
  769. package/dist/scripts/print_grid.js +80 -0
  770. package/dist/scripts/print_grid.js.map +1 -0
  771. package/dist/scripts/run-tests.d.ts +2 -0
  772. package/dist/scripts/run-tests.d.ts.map +1 -0
  773. package/dist/scripts/run-tests.js +49 -0
  774. package/dist/scripts/run-tests.js.map +1 -0
  775. package/dist/scripts/sync-version.d.ts +14 -0
  776. package/dist/scripts/sync-version.d.ts.map +1 -0
  777. package/dist/scripts/sync-version.js +158 -0
  778. package/dist/scripts/sync-version.js.map +1 -0
  779. package/dist/scripts/test-credit-renewal.d.ts +2 -0
  780. package/dist/scripts/test-credit-renewal.d.ts.map +1 -0
  781. package/dist/scripts/test-credit-renewal.js +329 -0
  782. package/dist/scripts/test-credit-renewal.js.map +1 -0
  783. package/dist/scripts/update.d.ts +24 -0
  784. package/dist/scripts/update.d.ts.map +1 -0
  785. package/dist/scripts/update.js +650 -0
  786. package/dist/scripts/update.js.map +1 -0
  787. package/dist/scripts/validate_bots.d.ts +16 -0
  788. package/dist/scripts/validate_bots.d.ts.map +1 -0
  789. package/dist/scripts/validate_bots.js +106 -0
  790. package/dist/scripts/validate_bots.js.map +1 -0
  791. package/dist/scripts/verify-browser-bundle.d.ts +22 -0
  792. package/dist/scripts/verify-browser-bundle.d.ts.map +1 -0
  793. package/dist/scripts/verify-browser-bundle.js +339 -0
  794. package/dist/scripts/verify-browser-bundle.js.map +1 -0
  795. package/dist/unlock.d.ts +48 -0
  796. package/dist/unlock.d.ts.map +1 -0
  797. package/dist/unlock.js +925 -0
  798. package/dist/unlock.js.map +1 -0
  799. package/package.json +112 -0
  800. package/scripts/README.md +356 -0
  801. package/scripts/clear-all.sh +195 -0
  802. package/scripts/clear-logs.sh +95 -0
  803. package/scripts/clear-market-adapter.sh +196 -0
  804. package/scripts/clear-orders.sh +113 -0
  805. package/scripts/create-bot-symlinks.sh +51 -0
  806. package/scripts/postinstall.js +9 -0
  807. package/scripts/reset-settings.sh +118 -0
package/dist/dexbot.js ADDED
@@ -0,0 +1,1222 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // node-only entry point — primary CLI driver (process.argv, process.exit, process.stdout/stderr, process.stdin)
4
+ /**
5
+ * dexbot.ts - DEXBot2 Primary CLI Driver
6
+ *
7
+ * Main entry point for DEXBot2 grid trading bot system.
8
+ * Manages tracked bots and provides helper utilities (key/bot editors).
9
+ * Creates grid-based limit orders across price ranges and auto-replaces fills.
10
+ *
11
+ * ===============================================================================
12
+ * FEATURES
13
+ * ===============================================================================
14
+ *
15
+ * GRID TRADING:
16
+ * - Configurable grid spacing with geometric increments (e.g., 0.5%)
17
+ * - Independent BUY and SELL order counts per bot
18
+ * - Dynamic spread zone around market price
19
+ * - Automatic order replacement when fills occur
20
+ * - Fund allocation controls (percentage of wallet)
21
+ * - Copy-on-Write rebalancing: Safe concurrent updates with isolated working grids
22
+ * - Automatic grid reconciliation: Detects offline fills and syncs with blockchain
23
+ *
24
+ * SECURITY:
25
+ * - Master password encryption for stored private keys (AES-256-GCM)
26
+ * - Optional credential daemon for multi-bot key management
27
+ * - No private keys in environment variables
28
+ * - Per-bot configuration and state isolation
29
+ *
30
+ * OPERATION MODES:
31
+ * - Live trading: Real orders on blockchain
32
+ * - Dry-run mode: Simulate operations without broadcasting
33
+ * - Manual control: Enable/disable/reset individual bots
34
+ *
35
+ * ===============================================================================
36
+ * CLI COMMANDS
37
+ * ===============================================================================
38
+ *
39
+ * TRADING OPERATIONS:
40
+ * node dexbot test <bot-name> - Test-run single bot (live trading)
41
+ * node dexbot drystart <bot-name> - Start bot in dry-run mode (no transactions)
42
+ *
43
+ * 🛠️ BOT MANAGEMENT:
44
+ * node dexbot reset all - Reset all active bot grids (full regeneration)
45
+ * node dexbot reset <bot-name> - Reset bot grid (full regeneration)
46
+ * node dexbot default - Reset settings to defaults (deletes general.settings.json, market_profiles.json, market_adapter_settings.json)
47
+ * node dexbot disable all - Mark all bots inactive in config
48
+ * node dexbot disable <bot-name> - Mark bot inactive in config
49
+ * node dexbot clear - Clear all log files in profiles/logs/
50
+ *
51
+ * CONFIGURATION:
52
+ * node dexbot keys - Set up master password and keyring
53
+ * node dexbot bots - Interactive editor for bot definitions
54
+ *
55
+ * PM2 ORCHESTRATION:
56
+ * node dexbot pm2 - Start all bots via PM2 with daemon
57
+ * node dexbot pm2 stop all - Stop all PM2 bot processes
58
+ * node dexbot pm2 stop <bot-name> - Stop specific bot
59
+ * node dexbot pm2 delete all - Delete all bots from PM2
60
+ * node dexbot pm2 delete <bot-name>- Delete specific bot from PM2
61
+ * node dexbot pm2 help - Show PM2 command help
62
+ *
63
+ * STATUS:
64
+ * node dexbot status - Show bot runtime status (unlock monolithic/isolated or PM2)
65
+ *
66
+ * MAINTENANCE:
67
+ * node dexbot update - Update to latest version (pull + install + restart)
68
+ * node dexbot export <bot-name> - Export trading history to CSV/JSON for QTradeX
69
+ * node dexbot order - Analyze persisted order grids in profiles/orders/
70
+ * node dexbot order --export - Export order analysis as standalone HTML report
71
+ * node dexbot help - Show this help message
72
+ *
73
+ * NPM SCRIPTS (alternative invocation):
74
+ * npm run pm2:start - Start bots (requires ecosystem.config.js pre-generated)
75
+ * npm run pm2:stop - Stop all PM2 bots
76
+ *
77
+ * ===============================================================================
78
+ * CONFIGURATION
79
+ * ===============================================================================
80
+ *
81
+ * Bots: profiles/bots.json
82
+ * Keys: profiles/keys.json (gitignored, encrypted)
83
+ * State: profiles/orders/{botKey}.json (per-bot grid snapshots)
84
+ * Logs: profiles/logs/{botname}.log (managed by PM2)
85
+ *
86
+ * ===============================================================================
87
+ */
88
+ Object.defineProperty(exports, "__esModule", { value: true });
89
+ // Restrict default file permissions: files created by this process default to
90
+ // 0o600 (owner-only) unless explicitly opened with a wider mode. Protects
91
+ // keys.json and daemon-policies.json from world-readable exposure.
92
+ const { setUmask } = require('./modules/config');
93
+ setUmask(0o077);
94
+ const { BitShares, waitForConnected, setSuppressConnectionLog, disconnectClient } = require('./modules/bitshares_client');
95
+ const { path } = require('./modules/path_api');
96
+ const { getStorage } = require('./modules/storage');
97
+ const storage = getStorage();
98
+ const chainKeys = require('./modules/chain_keys');
99
+ const { initializeFeeCache, ensureProfilesDirectory, readInput } = require('./modules/order/utils/system');
100
+ const accountBots = require('./modules/account_bots');
101
+ const SharedDEXBot = require('./modules/dexbot_class');
102
+ const fundRegistry = require('./modules/fund_registry');
103
+ /**
104
+ * Resolve a collateral asset reference (symbol or ID) to its canonical asset ID.
105
+ * Uses the already-connected BitShares DB instance.
106
+ * Caches results per reference to avoid redundant lookups in the registration loop.
107
+ */
108
+ const _collateralAssetIdCache = new Map();
109
+ async function _resolveCollateralAssetId(ref) {
110
+ if (_collateralAssetIdCache.has(ref))
111
+ return _collateralAssetIdCache.get(ref) ?? null;
112
+ let result = null;
113
+ try {
114
+ if (typeof ref === 'string' && ref.startsWith('1.3.')) {
115
+ result = ref;
116
+ }
117
+ else if (typeof ref === 'string') {
118
+ const res = await BitShares.db.lookup_asset_symbols([ref]);
119
+ if (res && res[0] && res[0].id)
120
+ result = String(res[0].id);
121
+ }
122
+ }
123
+ catch (_err) {
124
+ result = null;
125
+ }
126
+ _collateralAssetIdCache.set(ref, result);
127
+ return result;
128
+ }
129
+ const { setupGracefulShutdown, registerCleanup, unregisterCleanup } = require('./modules/graceful_shutdown');
130
+ const { collectValidationIssues, loadSettingsFile, normalizeBotEntries, resolveRawBotEntries, saveSettingsFile, } = require('./modules/bot_settings');
131
+ const { buildRuntimeScriptArgs } = require('./modules/launcher/runtime_entry');
132
+ const { PATHS, getRecalculateTriggerFile } = require('./modules/paths');
133
+ const credentialPolicy = require('./modules/credential_policy');
134
+ const { Config } = require('./modules/config');
135
+ // Auto-migrate bot state files from old stable-ID key format to sanitized-name format
136
+ try {
137
+ const { runMigration } = require('./scripts/migrate_bot_keys');
138
+ runMigration();
139
+ }
140
+ catch (err) {
141
+ console.error(`\x1b[1;31mMigration error:\x1b[0m ${err?.message || err}`);
142
+ }
143
+ // Setup graceful shutdown handlers
144
+ setupGracefulShutdown();
145
+ // Verify keys file permissions early — refuse to run if keys.json is
146
+ // world-readable (would indicate a prior run with a permissive umask).
147
+ if (typeof chainKeys.checkKeysFileSecurity === 'function')
148
+ chainKeys.checkKeysFileSecurity();
149
+ // Same migration-aware check for daemon-policies.json.
150
+ if (typeof credentialPolicy.checkPolicyFileSecurity === 'function')
151
+ credentialPolicy.checkPolicyFileSecurity(PATHS.PROFILES.DAEMON_POLICIES_JSON);
152
+ // Note: accountOrders is now per-bot only. Each bot has its own AccountOrders instance
153
+ // created in DEXBot.start() in modules/dexbot_class.ts. This eliminates shared-file race conditions.
154
+ // Primary CLI driver that manages tracked bots and helper utilities such as key/bot editors.
155
+ const PROFILES_BOTS_FILE = PATHS.PROFILES.BOTS_JSON;
156
+ const PROFILES_DIR = PATHS.PROFILES_DIR;
157
+ const BUILD_DIR = 'dist';
158
+ const CLI_COMMANDS = ['start', 'test', 'reset', 'default', 'disable', 'drystart', 'keys', 'bots', 'pm2', 'update', 'export', 'order', 'clear', 'clear-orders', 'clear-market-adapter', 'clear-all', 'status', 'whitelist', 'unlock', 'help'];
159
+ const COMMAND_ALIASES = { orders: 'order', key: 'keys', bot: 'bots', white: 'whitelist', stat: 'status', stats: 'status', start: 'test', defaults: 'default' };
160
+ const CLI_HELP_FLAGS = ['-h', '--help'];
161
+ const CLI_EXAMPLES_FLAG = '--cli-examples';
162
+ const CLI_EXAMPLES = [
163
+ { title: 'Test-run a bot from the tracked config', command: 'dexbot test bot-name', notes: 'Targets the named entry in profiles/bots.json.' },
164
+ { title: 'Dry-run a bot without broadcasting', command: 'dexbot drystart bot-name', notes: 'Forces the run into dry-run mode even if the stored config was live.' },
165
+ { title: 'Disable a bot in config', command: 'dexbot disable bot-name', notes: 'Marks the bot inactive in config.' },
166
+ { title: 'Reset all active bot grids', command: 'dexbot reset all', notes: 'Triggers full grid regeneration for every active bot.' },
167
+ { title: 'Reset a bot grid', command: 'dexbot reset bot-name', notes: 'Triggers a full grid regeneration for the named bot.' },
168
+ { title: 'Manage keys', command: 'dexbot key', notes: 'Runs modules/chain_keys.ts to add or update master passwords.' },
169
+ { title: 'Edit bot definitions', command: 'dexbot bot', notes: 'Launches the interactive modules/account_bots.ts helper for the JSON config.' },
170
+ { title: 'Start bots with PM2', command: 'dexbot pm2', notes: 'Generates ecosystem config, authenticates, and starts PM2.' },
171
+ { title: 'Update DEXBot2', command: 'node dexbot update', notes: 'Fetches latest code, updates dependencies, and restarts PM2.' },
172
+ { title: 'Export bot trades for QTradeX', command: 'dexbot export bot-name', notes: 'Exports trading history and settings to CSV/JSON for backtesting.' },
173
+ { title: 'Analyze persisted order grids', command: 'dexbot order', notes: 'Runs the order analyzer across profiles/orders/ and prints spread/increment/funds/distribution metrics. Add --export for an HTML report.' },
174
+ { title: 'Clear all bot log files', command: 'dexbot clear', notes: 'Runs scripts/clear-logs.sh to remove log files from profiles/logs/.' },
175
+ { title: 'Reset settings to defaults', command: 'dexbot default', notes: 'Runs scripts/reset-settings.sh to delete general.settings.json, market_profiles.json, and market_adapter_settings.json.' }
176
+ ];
177
+ const STARTUP_COLORS = {
178
+ reset: '\x1b[0m',
179
+ ok: '\x1b[1;92m',
180
+ error: '\x1b[1;31m',
181
+ };
182
+ function colorStartupOutput(text, color, stream = process.stdout) {
183
+ return stream.isTTY && !Config.NO_COLOR
184
+ ? `${color}${text}${STARTUP_COLORS.reset}`
185
+ : text;
186
+ }
187
+ function startupSuccess(text) {
188
+ return colorStartupOutput(text, STARTUP_COLORS.ok);
189
+ }
190
+ function startupError(text) {
191
+ return colorStartupOutput(text, STARTUP_COLORS.error, process.stderr);
192
+ }
193
+ function colorStartupActiveBotName(name) {
194
+ return startupSuccess(name);
195
+ }
196
+ const cliArgs = process.argv.slice(2);
197
+ /**
198
+ * Show the CLI usage/help text when requested or upon invalid commands.
199
+ */
200
+ function printCLIUsage() {
201
+ console.log('Usage: dexbot [command] [bot-name]');
202
+ console.log('Commands:');
203
+ console.log(' test <bot> Test-run the named bot (one-shot, live trading).');
204
+ console.log(' start <bot> Alias for test (legacy).');
205
+ console.log(' drystart <bot> Same as test but forces dry-run execution.');
206
+ console.log(' reset all Trigger grid resets for all active bots.');
207
+ console.log(' reset <bot> Trigger a grid reset (auto-reloads if running, or applies on next start).');
208
+ console.log(' default, defaults Reset settings to defaults (deletes general.settings.json, market_profiles.json, market_adapter_settings.json).');
209
+ console.log(' disable all Mark all bots inactive in config.');
210
+ console.log(' disable <bot> Mark the bot inactive in config.');
211
+ console.log(' export <bot> Export bot trades and settings for QTradeX backtesting.');
212
+ console.log(' key Launch the chain key helper (modules/chain_keys.ts).');
213
+ console.log(' bot Launch the interactive bot configurator (modules/account_bots.ts).');
214
+ console.log(' pm2 Start all active bots with PM2 (authenticate + generate config + start).');
215
+ console.log(' update Update DEXBot2 from the repository and restart active bots.');
216
+ console.log(' order Analyze persisted order grids in profiles/orders/ (spread, increment, funds). Use --export for HTML.');
217
+ console.log(' status, stat, stats Show bot runtime status (unlock monolithic/isolated or PM2).');
218
+ console.log(' unlock Run credential daemon + bot (equivalent to `node unlock`).');
219
+ console.log(' whitelist, white Generate market adapter whitelist from AMA bot configs. Flags (--dynamic-weight, --no-asymmetric-bounds, --prune) are forwarded.');
220
+ console.log(' clear Remove all log files from profiles/logs/ (runs scripts/clear-logs.sh).');
221
+ console.log(' clear-orders Remove all persisted order files from profiles/orders/.');
222
+ console.log(' clear-market-adapter Remove market adapter data, state, and logs.');
223
+ console.log(' clear-all Remove orders, logs, and market adapter files (combines the above).');
224
+ console.log('Options:');
225
+ console.log(' --cli-examples Print curated CLI snippets.');
226
+ console.log(' -h, --help Show this help text.');
227
+ console.log('Envs: OPEN_ORDERS_SYNC_LOOP_MS controls the open-orders sync polling delay; LIVE_BOT_NAME or BOT_NAME selects a single entry.');
228
+ }
229
+ /**
230
+ * Print curated CLI snippets for quick reference.
231
+ */
232
+ function printCLIExamples() {
233
+ console.log('CLI Examples:');
234
+ CLI_EXAMPLES.forEach((example, index) => {
235
+ console.log(`${index + 1}. ${example.title}`);
236
+ console.log(` ${example.command}`);
237
+ if (example.notes)
238
+ console.log(` ${example.notes}`);
239
+ });
240
+ console.log(`Read the README "CLI usage" section for more details (file: ${PROFILES_BOTS_FILE}).`);
241
+ }
242
+ if (cliArgs.some(arg => CLI_HELP_FLAGS.includes(arg))) {
243
+ printCLIUsage();
244
+ process.exit(0);
245
+ }
246
+ if (cliArgs.includes(CLI_EXAMPLES_FLAG)) {
247
+ printCLIExamples();
248
+ process.exit(0);
249
+ }
250
+ // Connection handled centrally by modules/bitshares_client; use waitForConnected() when needed
251
+ /**
252
+ * DEXBot - Thin wrapper around SharedDEXBot for dexbot.ts CLI context.
253
+ * All trading lifecycle (grid, order management, sync) is handled by SharedDEXBot.
254
+ *
255
+ * @class
256
+ */
257
+ // Extend SharedDEXBot for dexbot.ts context (thin wrapper)
258
+ class DEXBot extends SharedDEXBot {
259
+ constructor(config) {
260
+ super(config, { logPrefix: '' });
261
+ }
262
+ }
263
+ // Register BitShares cleanup on shutdown
264
+ registerCleanup('BitShares connection', () => {
265
+ try {
266
+ disconnectClient();
267
+ }
268
+ catch (err) {
269
+ // BitShares may already be disconnected
270
+ }
271
+ });
272
+ // Track attempts to prevent infinite loops while allowing retries after key setup
273
+ let keySetupInProgress = false;
274
+ /**
275
+ * Launch the account key manager helper.
276
+ * @param {Object} [options={}] - Manager options.
277
+ * @param {boolean} [options.waitForConnection=false] - Whether to wait for BitShares connection.
278
+ * @param {boolean} [options.exitAfter=false] - Whether to exit the process after completion.
279
+ * @param {boolean} [options.disconnectAfter=false] - Whether to disconnect BitShares after completion.
280
+ * @returns {Promise<void>}
281
+ */
282
+ async function runAccountManager({ waitForConnection = false, exitAfter = false, disconnectAfter = false } = {}) {
283
+ if (waitForConnection) {
284
+ try {
285
+ await waitForConnected();
286
+ }
287
+ catch (err) {
288
+ console.warn('Timed out waiting for BitShares connection before launching key manager.');
289
+ }
290
+ }
291
+ let succeeded = false;
292
+ try {
293
+ await chainKeys.main();
294
+ succeeded = true;
295
+ }
296
+ finally {
297
+ if (disconnectAfter) {
298
+ try {
299
+ disconnectClient();
300
+ }
301
+ catch (err) {
302
+ console.warn('Failed to disconnect BitShares connection after key manager exited:', err.message || err);
303
+ }
304
+ }
305
+ }
306
+ if (exitAfter && succeeded) {
307
+ process.exit(0);
308
+ }
309
+ }
310
+ /**
311
+ * Handle master password authentication with auto-launch fallback.
312
+ * If no master password is set, automatically launches the key manager
313
+ * to guide the user through initial setup.
314
+ * @returns {Promise<string>} The authenticated master password
315
+ */
316
+ async function authenticateMasterPassword() {
317
+ try {
318
+ return await chainKeys.authenticate();
319
+ }
320
+ catch (err) {
321
+ if (!keySetupInProgress && err && err.message && err.message.includes('No master password set')) {
322
+ keySetupInProgress = true;
323
+ try {
324
+ await runAccountManager();
325
+ keySetupInProgress = false;
326
+ return await chainKeys.authenticate();
327
+ }
328
+ catch (setupErr) {
329
+ keySetupInProgress = false;
330
+ throw setupErr;
331
+ }
332
+ }
333
+ throw err;
334
+ }
335
+ }
336
+ function printStartLauncherHeader({ botName = null, dryRun = false } = {}) {
337
+ console.log('='.repeat(50));
338
+ console.log('DEXBot2 Start Launcher');
339
+ if (botName) {
340
+ console.log(`Starting bot: ${botName}`);
341
+ }
342
+ else {
343
+ console.log('Starting all bots');
344
+ }
345
+ if (dryRun) {
346
+ console.log('Dry-run mode enabled');
347
+ }
348
+ console.log('='.repeat(50));
349
+ console.log();
350
+ }
351
+ function printStartLauncherSuccess({ botName = null, dryRun = false } = {}) {
352
+ const dryrunFlag = dryRun ? ' --dryrun' : '';
353
+ console.log();
354
+ console.log('='.repeat(50));
355
+ console.log(startupSuccess('DEXBot2 started successfully!'));
356
+ if (botName) {
357
+ console.log(`If the bot stops, rerun \`node unlock${dryrunFlag} ${botName}\`.`);
358
+ }
359
+ else {
360
+ console.log(`If the bots stop, rerun \`node unlock${dryrunFlag}\`.`);
361
+ }
362
+ console.log('='.repeat(50));
363
+ console.log();
364
+ }
365
+ function printMasterPasswordFailure(err) {
366
+ console.error();
367
+ console.error(startupError(`❌ ${err.message}`));
368
+ }
369
+ /**
370
+ * Execute the provided bot entries after validation and authentication.
371
+ * This is the main orchestration function that:
372
+ * 1. Validates all bot configurations
373
+ * 2. Prompts for master password if any bot needs it
374
+ * 3. Creates DEXBot instances and starts them
375
+ *
376
+ * @param {Array} botEntries - Array of normalized bot configurations
377
+ * @param {Object} [options] - Execution options
378
+ * @param {boolean} [options.forceDryRun=false] - Force all bots into dry-run mode
379
+ * @param {string} [options.sourceName='settings'] - Source label for logging
380
+ * @param {Object} [options.launcherStyle=null] - Launcher presentation options
381
+ * @returns {Promise<Array>} Array of started DEXBot instances
382
+ */
383
+ async function runBotInstances(botEntries, { forceDryRun = false, sourceName = 'settings', launcherStyle } = {}) {
384
+ setSuppressConnectionLog(true);
385
+ const shouldAnnounceLauncher = !!launcherStyle;
386
+ const launcherBotName = launcherStyle?.botName || null;
387
+ const launcherDryRun = !!launcherStyle?.dryRun;
388
+ let connectionAnnounced = false;
389
+ let authenticationAnnounced = false;
390
+ const activeCount = (botEntries || []).filter((entry) => entry && entry.active !== false).length;
391
+ const announceConnection = () => {
392
+ if (shouldAnnounceLauncher && !connectionAnnounced) {
393
+ console.log(startupSuccess('Connected to BitShares'));
394
+ connectionAnnounced = true;
395
+ }
396
+ };
397
+ const announceAuthentication = () => {
398
+ if (shouldAnnounceLauncher && !authenticationAnnounced) {
399
+ console.log(startupSuccess('✓ Authentication successful'));
400
+ authenticationAnnounced = true;
401
+ }
402
+ };
403
+ try {
404
+ if (shouldAnnounceLauncher) {
405
+ printStartLauncherHeader({ botName: launcherBotName, dryRun: launcherDryRun });
406
+ }
407
+ if (!botEntries.length) {
408
+ console.log(`No bot entries were found in ${sourceName}.`);
409
+ return [];
410
+ }
411
+ const prepared = botEntries.map((entry) => ({
412
+ ...entry,
413
+ dryRun: forceDryRun ? true : entry.dryRun,
414
+ }));
415
+ // Note: each bot creates its own AccountOrders instance with per-bot file when it
416
+ // starts and syncs its own meta via syncMeta(). No shared initialization needed here.
417
+ const { errors } = collectValidationIssues(prepared, sourceName);
418
+ if (errors.length) {
419
+ console.error(startupError('ERROR: Invalid configuration for one or more **active** bots:'));
420
+ errors.forEach((e) => console.error(startupError(` - ${e}`)));
421
+ console.error(startupError('Fix the configuration problems in profiles/bots.json and restart. Aborting.'));
422
+ process.exit(1);
423
+ }
424
+ const needMaster = prepared.some((b) => b.active && b.preferredAccount);
425
+ let masterPassword = null;
426
+ if (needMaster) {
427
+ const daemonReady = await chainKeys.isDaemonResponsive();
428
+ try {
429
+ await waitForConnected();
430
+ announceConnection();
431
+ }
432
+ catch (err) {
433
+ // Continue; the bot startup path will retry through the normal runtime flow.
434
+ }
435
+ if (!daemonReady) {
436
+ try {
437
+ masterPassword = await authenticateMasterPassword();
438
+ announceAuthentication();
439
+ }
440
+ catch (err) {
441
+ if (chainKeys.isMasterPasswordFailure(err)) {
442
+ throw err;
443
+ }
444
+ masterPassword = null;
445
+ }
446
+ }
447
+ }
448
+ // Fee cache is required for fill processing (getAssetFees), including offline fill reconciliation at startup.
449
+ // Initialize it once per process for the assets used by active bots.
450
+ try {
451
+ await waitForConnected();
452
+ announceConnection();
453
+ await initializeFeeCache(prepared.filter((b) => b.active), BitShares);
454
+ }
455
+ catch (err) {
456
+ console.error(startupError(`Fee cache initialization failed: ${err.message}`));
457
+ console.error(startupError('Cannot proceed without fee cache for fill processing. Aborting.'));
458
+ process.exit(1);
459
+ }
460
+ if (shouldAnnounceLauncher) {
461
+ console.log(`Number active bots: ${activeCount}`);
462
+ if (activeCount > 0) {
463
+ console.log('Active bots:');
464
+ for (const entry of prepared) {
465
+ if (!entry.active) {
466
+ continue;
467
+ }
468
+ const botName = String(entry.name || entry.botKey || 'unnamed');
469
+ console.log(` - ${colorStartupActiveBotName(botName)}`);
470
+ }
471
+ }
472
+ console.log();
473
+ console.log('Starting bot runtime...');
474
+ }
475
+ // Phase 5: Atomic startup — pre-register all bot allocations before any bot starts.
476
+ // This ensures proportional fund allocation is computed correctly for shared accounts.
477
+ const activeBots = prepared.filter((e) => e.active);
478
+ const accountGroups = {};
479
+ for (const entry of activeBots) {
480
+ const account = entry.preferredAccount;
481
+ if (account) {
482
+ if (!accountGroups[account])
483
+ accountGroups[account] = [];
484
+ accountGroups[account].push(entry);
485
+ }
486
+ }
487
+ const sharedAccounts = Object.keys(accountGroups).filter((a) => accountGroups[a].length > 1);
488
+ if (sharedAccounts.length > 0) {
489
+ console.log(`Shared accounts detected: ${sharedAccounts.join(', ')} — pre-registering fund allocations atomically.`);
490
+ // Phase 5a: Collect all unique collateral asset refs and resolve them in bulk
491
+ const allCollateralRefs = new Set();
492
+ for (const entry of activeBots) {
493
+ if (entry.debtPolicy?.lending && (entry.preferredAccount && accountGroups[entry.preferredAccount]?.length > 1)) {
494
+ for (const item of entry.debtPolicy.lending) {
495
+ if (item.collateralAsset)
496
+ allCollateralRefs.add(item.collateralAsset);
497
+ }
498
+ }
499
+ }
500
+ if (allCollateralRefs.size > 0) {
501
+ await Promise.all([...allCollateralRefs].map(ref => _resolveCollateralAssetId(ref)));
502
+ }
503
+ for (const account of sharedAccounts) {
504
+ for (const entry of accountGroups[account]) {
505
+ const botName = entry.botKey;
506
+ if (botName && entry.botFunds) {
507
+ const sides = ['buy', 'sell'];
508
+ for (const side of sides) {
509
+ const pct = entry.botFunds[side];
510
+ if (pct !== undefined && pct !== null) {
511
+ await fundRegistry.registerAllocation(account, botName, side, pct);
512
+ }
513
+ }
514
+ }
515
+ // Register credit/MPA collateral allocations
516
+ if (botName && entry.debtPolicy?.lending) {
517
+ const dp = entry.debtPolicy;
518
+ const globalPct = dp.maxCollateralAmount ?? '100%';
519
+ for (const item of dp.lending) {
520
+ const collateralRef = item.collateralAsset;
521
+ if (!collateralRef)
522
+ continue;
523
+ const collateralAssetId = _collateralAssetIdCache.get(collateralRef) ?? null;
524
+ if (!collateralAssetId) {
525
+ console.error(` ERROR: unable to resolve collateral asset '${collateralRef}' for credit bot ${botName}. Credit bot will run WITHOUT proportional allocation. Check chain connectivity and asset configuration.`);
526
+ continue;
527
+ }
528
+ await fundRegistry.registerCollateralAllocation(account, botName, collateralAssetId, globalPct);
529
+ }
530
+ }
531
+ }
532
+ }
533
+ }
534
+ const instances = [];
535
+ for (const entry of prepared) {
536
+ if (!entry.active) {
537
+ continue;
538
+ }
539
+ const botCleanupName = `Bot: ${entry.name || entry.botKey || instances.length + 1}`;
540
+ let bot = null;
541
+ let botCleanupHandler = null;
542
+ try {
543
+ bot = new DEXBot(entry);
544
+ botCleanupHandler = () => bot.shutdown();
545
+ registerCleanup(botCleanupName, botCleanupHandler);
546
+ await bot.start(masterPassword);
547
+ instances.push(bot);
548
+ }
549
+ catch (err) {
550
+ // The bot's _runStartupSequence already invoked shutdown() once on
551
+ // the failure path. Remove the registered cleanup so the LIFO
552
+ // cleanup loop in graceful_shutdown.ts does not call shutdown() a
553
+ // second time, and avoid the "double graceful shutdown" log pattern.
554
+ if (botCleanupHandler) {
555
+ unregisterCleanup(botCleanupHandler);
556
+ }
557
+ // Attempt graceful cleanup before continuing. Idempotent via the
558
+ // _shutdownStarted guard, so a redundant call is a no-op.
559
+ if (bot) {
560
+ try {
561
+ await bot.shutdown();
562
+ }
563
+ catch (shutdownErr) {
564
+ console.error(startupError(`Error during cleanup: ${shutdownErr.message}`));
565
+ }
566
+ }
567
+ if (chainKeys.isMasterPasswordFailure(err)) {
568
+ printMasterPasswordFailure(err);
569
+ process.exit(1);
570
+ return;
571
+ }
572
+ console.error(startupError(`Failed to start bot: ${err.message}`));
573
+ if (err && err.message && String(err.message).toLowerCase().includes('marketprice')) {
574
+ console.info('Hint: startPrice could not be derived.');
575
+ console.info(' - If using profiles/bots.json with "pool" or "book" signals, ensure the chain contains a matching liquidity pool or orderbook for the configured pair.');
576
+ console.info(' - Alternatively, set a numeric `startPrice` directly in profiles/bots.json for this bot to avoid auto-derive.');
577
+ console.info(' - You can also set LIVE_BOT_NAME or BOT_NAME to select a different bot from the profiles settings.');
578
+ }
579
+ }
580
+ }
581
+ if (instances.length === 0) {
582
+ console.log('No active bots were started. Check bots.json and ensure at least one bot is active.');
583
+ return instances;
584
+ }
585
+ if (shouldAnnounceLauncher) {
586
+ printStartLauncherSuccess({ botName: launcherBotName, dryRun: launcherDryRun });
587
+ }
588
+ return instances;
589
+ }
590
+ finally {
591
+ setSuppressConnectionLog(false);
592
+ }
593
+ }
594
+ /**
595
+ * Start a specific bot by name or all active bots if no name provided.
596
+ * Looks up the bot in profiles/bots.json and starts it.
597
+ * @param {string|null|undefined} botName - Name of the bot to start, or null/undefined for all active
598
+ * @param {Object} [options] - Start options
599
+ * @param {boolean} [options.dryRun=false] - Run in dry-run mode (no broadcasts)
600
+ */
601
+ async function startBotByName(botName, { dryRun = false } = {}) {
602
+ if (!botName) {
603
+ return runDefaultBots({
604
+ forceDryRun: dryRun,
605
+ sourceName: dryRun ? 'CLI drystart (all)' : 'CLI start (all)',
606
+ launcherStyle: { botName: null, dryRun },
607
+ });
608
+ }
609
+ const { config } = loadSettingsFile(PROFILES_BOTS_FILE);
610
+ const entries = resolveRawBotEntries(config);
611
+ if (!entries.length) {
612
+ console.error(startupError('No bot definitions exist in the tracked settings.'));
613
+ process.exit(1);
614
+ }
615
+ const match = entries.find((b) => b.name === botName);
616
+ if (!match) {
617
+ console.error(startupError(`Could not find any bot named '${botName}' in the tracked settings.`));
618
+ process.exit(1);
619
+ }
620
+ const entryCopy = JSON.parse(JSON.stringify(match));
621
+ entryCopy.active = true;
622
+ if (dryRun)
623
+ entryCopy.dryRun = true;
624
+ const normalized = normalizeBotEntries([entryCopy]);
625
+ await runBotInstances(normalized, {
626
+ forceDryRun: dryRun,
627
+ sourceName: dryRun ? 'CLI drystart' : 'CLI start',
628
+ launcherStyle: { botName, dryRun },
629
+ });
630
+ }
631
+ /**
632
+ * Mark a bot (or all bots) as inactive in profiles/bots.json.
633
+ * Note: This only updates the config file; running processes must be
634
+ * stopped separately using pm2.js or Ctrl+C.
635
+ * @param {string|null|undefined} botName - Name of the bot to disable, or null/undefined for all
636
+ */
637
+ async function disableBotByName(botName) {
638
+ const { config, filePath } = loadSettingsFile(PROFILES_BOTS_FILE);
639
+ const entries = resolveRawBotEntries(config);
640
+ if (!botName) {
641
+ let updated = false;
642
+ entries.forEach((entry) => {
643
+ if (entry.active) {
644
+ entry.active = false;
645
+ updated = true;
646
+ }
647
+ });
648
+ if (!updated) {
649
+ console.log('No active bots were found to disable.');
650
+ return;
651
+ }
652
+ saveSettingsFile(config, filePath);
653
+ console.log(`Marked all bots inactive in ${path.basename(filePath)}.`);
654
+ return;
655
+ }
656
+ const match = entries.find((b) => b.name === botName);
657
+ if (!match) {
658
+ console.error(startupError(`Could not find any bot named '${botName}' to disable.`));
659
+ process.exit(1);
660
+ }
661
+ if (!match.active) {
662
+ console.log(`Bot '${botName}' is already inactive.`);
663
+ return;
664
+ }
665
+ match.active = false;
666
+ saveSettingsFile(config, filePath);
667
+ console.log(`Marked '${botName}' inactive in ${path.basename(filePath)}. Stop the PM2 process using 'node pm2 stop ${botName}'.`);
668
+ }
669
+ /**
670
+ * Reset a bot by regenerating its grid and starting it fresh.
671
+ * This method creates a trigger file that signals the bot instance
672
+ * (whether running locally or via PM2) to perform a full grid resync.
673
+ *
674
+ * 1. Creates profiles/recalculate.<botKey>.trigger
675
+ * 2. If bot is running, it detects file -> resyncs grid -> deletes file
676
+ * 3. If bot is stopped, it detects file on startup -> resyncs grid -> deletes file
677
+ *
678
+ * @param {string|null|undefined} botName - Name of the bot to reset, or null/undefined for all active
679
+ */
680
+ async function resetBotByName(botName) {
681
+ const { config } = loadSettingsFile(PROFILES_BOTS_FILE);
682
+ const entries = normalizeBotEntries(resolveRawBotEntries(config));
683
+ // Filter targets
684
+ const targets = botName ? entries.filter((b) => b.name === botName) : entries.filter((b) => b.active);
685
+ if (botName && targets.length === 0) {
686
+ console.error(startupError(`Could not find any bot named '${botName}' to reset.`));
687
+ process.exit(1);
688
+ }
689
+ console.log(`Setting regeneration trigger for ${targets.length} ${targets.length === 1 ? 'bot' : 'bots'}...`);
690
+ for (const bot of targets) {
691
+ try {
692
+ const triggerFile = getRecalculateTriggerFile(bot.botKey);
693
+ storage.writeFile(triggerFile, '');
694
+ console.log(startupSuccess(`✓ Trigger set for '${bot.name}' (${path.basename(triggerFile)})`));
695
+ }
696
+ catch (err) {
697
+ console.warn(`Failed to set trigger for '${bot.name}': ${err.message}`);
698
+ }
699
+ }
700
+ console.log();
701
+ console.log(startupSuccess('Action complete.'));
702
+ console.log('- If the bot is running (CLI or PM2), it will detect the trigger and reset automatically.');
703
+ console.log('- If the bot is stopped, the grid will be regenerated the next time you run `dexbot test`.');
704
+ }
705
+ /**
706
+ * Export bot trading history and settings for QTradeX
707
+ * @param {string|undefined} botName - Bot name; may be undefined from CLI when no target provided to export
708
+ */
709
+ async function exportBotTrades(botName) {
710
+ if (!botName) {
711
+ console.error(startupError('Please specify a bot name: dexbot export <bot-name>'));
712
+ process.exit(1);
713
+ }
714
+ try {
715
+ const exporter = require('./modules/order/export');
716
+ // Load bots configuration
717
+ const { config: botsData } = loadSettingsFile(PROFILES_BOTS_FILE);
718
+ const bot = resolveRawBotEntries(botsData).find((b) => b.name === botName);
719
+ if (!bot) {
720
+ console.error(startupError(`Bot '${botName}' not found in profiles/bots.json`));
721
+ process.exit(1);
722
+ }
723
+ console.log(`\n${'='.repeat(60)}`);
724
+ console.log(`Exporting bot: ${botName}`);
725
+ console.log(`${'='.repeat(60)}\n`);
726
+ // Create bot key from bot name (lowercase, replace spaces with hyphens)
727
+ const botKey = botName.toLowerCase().replace(/\s+/g, '-');
728
+ // Export trades and settings
729
+ const result = await exporter.exportBotTrades(botKey, bot, path.join(PATHS.PROFILES_DIR, 'exports'));
730
+ if (result.success) {
731
+ console.log(`\n${'='.repeat(60)}`);
732
+ console.log(startupSuccess(`✓ Export successful!`));
733
+ console.log(`${'='.repeat(60)}`);
734
+ console.log(`Bot: ${botName}`);
735
+ console.log(`Trades exported: ${result.trades_exported}`);
736
+ console.log(`CSV file: ${result.csv_path}`);
737
+ console.log(`Settings file: ${result.settings_path}`);
738
+ console.log(`Output directory: ${result.output_dir}`);
739
+ console.log(`Timestamp: ${result.timestamp}`);
740
+ console.log(`\nYou can now use these files with QTradeX for backtesting.\n`);
741
+ }
742
+ else {
743
+ console.error(startupError(`\n✗ Export failed: ${result.error || 'Unknown error'}\n`));
744
+ process.exit(1);
745
+ }
746
+ }
747
+ catch (err) {
748
+ console.error(startupError(`\nExport error: ${err.message}\n`));
749
+ process.exit(1);
750
+ }
751
+ }
752
+ /**
753
+ * Parse and execute CLI commands.
754
+ * Supported commands: test, drystart, reset, default, disable, keys, bots, pm2, update, export, order, clear, status, whitelist, unlock, help
755
+ * @returns {Promise<boolean>} True if a command was handled, false otherwise
756
+ */
757
+ async function handleCLICommands() {
758
+ if (!cliArgs.length)
759
+ return false;
760
+ const [rawCommand, target] = cliArgs;
761
+ const command = COMMAND_ALIASES[rawCommand] ?? rawCommand;
762
+ if (!CLI_COMMANDS.includes(command)) {
763
+ console.error(startupError(`Unknown command '${command}'.`));
764
+ printCLIUsage();
765
+ process.exit(1);
766
+ }
767
+ switch (command) {
768
+ case 'test':
769
+ await startBotByName(target, { dryRun: false });
770
+ return true;
771
+ case 'drystart':
772
+ await startBotByName(target, { dryRun: true });
773
+ return true;
774
+ case 'reset':
775
+ if (!target) {
776
+ console.error('Error: Target required. Specify "all" or a bot name.');
777
+ printCLIUsage();
778
+ process.exit(1);
779
+ }
780
+ await resetBotByName(target === 'all' ? null : target);
781
+ process.exit(0);
782
+ case 'default': {
783
+ const { spawnSync } = require('child_process');
784
+ const resetScript = path.join(PATHS.PROJECT_ROOT, 'scripts', 'reset-settings.sh');
785
+ const result = spawnSync('bash', [resetScript], {
786
+ cwd: PATHS.PROJECT_ROOT,
787
+ stdio: 'inherit',
788
+ });
789
+ if (result.error) {
790
+ console.error(`default: ${result.error.message}`);
791
+ process.exit(1);
792
+ }
793
+ process.exit(result.status ?? 0);
794
+ return true;
795
+ }
796
+ case 'disable':
797
+ if (!target) {
798
+ console.error('Error: Target required. Specify "all" or a bot name.');
799
+ printCLIUsage();
800
+ process.exit(1);
801
+ }
802
+ await disableBotByName(target === 'all' ? null : target);
803
+ process.exit(0);
804
+ case 'keys':
805
+ await runAccountManager({ exitAfter: true });
806
+ return true;
807
+ case 'bots':
808
+ setSuppressConnectionLog(true);
809
+ try {
810
+ await accountBots.main();
811
+ }
812
+ finally {
813
+ try {
814
+ disconnectClient();
815
+ }
816
+ catch (err) {
817
+ console.warn('Failed to disconnect BitShares after bot helper exit:', err && err.message ? err.message : err);
818
+ }
819
+ }
820
+ process.exit(0);
821
+ return true;
822
+ case 'pm2':
823
+ try {
824
+ const pm2Launcher = require('./pm2');
825
+ await pm2Launcher.main();
826
+ // Close stdin and exit cleanly after PM2 startup
827
+ if (process.stdin)
828
+ process.stdin.destroy();
829
+ process.exit(0);
830
+ }
831
+ catch (err) {
832
+ console.error('Error:', err.message);
833
+ process.exit(1);
834
+ }
835
+ return true;
836
+ case 'update':
837
+ setSuppressConnectionLog(true);
838
+ require('./scripts/update');
839
+ return true;
840
+ case 'export':
841
+ setSuppressConnectionLog(true);
842
+ await exportBotTrades(target);
843
+ process.exit(0);
844
+ return true;
845
+ case 'whitelist': {
846
+ const { spawnSync } = require('child_process');
847
+ const scriptArgs = buildRuntimeScriptArgs({
848
+ codeRoot: __dirname,
849
+ scriptSegments: ['scripts', 'generate_market_adapter_whitelist'],
850
+ scriptArgs: cliArgs.slice(1),
851
+ });
852
+ const result = spawnSync(Config.EXEC_PATH, scriptArgs, {
853
+ cwd: PATHS.PROJECT_ROOT,
854
+ stdio: 'inherit',
855
+ });
856
+ if (result.error) {
857
+ console.error(`whitelist: ${result.error.message}`);
858
+ process.exit(1);
859
+ }
860
+ process.exit(result.status ?? 0);
861
+ return true;
862
+ }
863
+ case 'order': {
864
+ const { spawnSync } = require('child_process');
865
+ const scriptArgs = buildRuntimeScriptArgs({
866
+ codeRoot: __dirname,
867
+ scriptSegments: ['scripts', 'analyze-orders'],
868
+ scriptArgs: cliArgs.slice(1),
869
+ });
870
+ const result = spawnSync(Config.EXEC_PATH, scriptArgs, {
871
+ cwd: PATHS.PROJECT_ROOT,
872
+ stdio: 'inherit',
873
+ });
874
+ if (result.error) {
875
+ console.error(`order: ${result.error.message}`);
876
+ process.exit(1);
877
+ }
878
+ process.exit(result.status ?? 0);
879
+ return true;
880
+ }
881
+ case 'unlock': {
882
+ const { spawnSync } = require('child_process');
883
+ const unlockScript = path.join(PATHS.PROJECT_ROOT, BUILD_DIR, 'unlock.js');
884
+ const unlockArgs = [unlockScript, ...cliArgs.slice(1)];
885
+ const result = spawnSync(Config.EXEC_PATH, unlockArgs, {
886
+ cwd: PATHS.PROJECT_ROOT,
887
+ stdio: 'inherit',
888
+ });
889
+ process.exit(result.status ?? 0);
890
+ return true;
891
+ }
892
+ case 'clear':
893
+ case 'clear-orders':
894
+ case 'clear-market-adapter':
895
+ case 'clear-all': {
896
+ const { spawnSync } = require('child_process');
897
+ const scriptMap = {
898
+ clear: 'clear-logs.sh',
899
+ 'clear-orders': 'clear-orders.sh',
900
+ 'clear-market-adapter': 'clear-market-adapter.sh',
901
+ 'clear-all': 'clear-all.sh',
902
+ };
903
+ const scriptName = scriptMap[command];
904
+ const scriptPath = path.join(PATHS.PROJECT_ROOT, 'scripts', scriptName);
905
+ const result = spawnSync('bash', [scriptPath], {
906
+ cwd: PATHS.PROJECT_ROOT,
907
+ stdio: 'inherit',
908
+ });
909
+ if (result.error) {
910
+ console.error(`${command}: ${result.error.message}`);
911
+ process.exit(1);
912
+ }
913
+ process.exit(result.status ?? 0);
914
+ return true;
915
+ }
916
+ case 'status': {
917
+ console.log(`DEXBot2 v${Config.VERSION}`);
918
+ console.log();
919
+ const { spawnSync, execSync } = require('child_process');
920
+ const MONOLITHIC_PID_FILE = PATHS.PROFILES.MONOLITHIC_PID;
921
+ const SUPERVISOR_SOCK = PATHS.PROFILES.SUPERVISOR_SOCK;
922
+ let unlockRunning = false;
923
+ if (storage.exists(MONOLITHIC_PID_FILE)) {
924
+ try {
925
+ const pid = Number(storage.readFile(MONOLITHIC_PID_FILE).trim());
926
+ if (Number.isInteger(pid) && pid > 0) {
927
+ try {
928
+ process.kill(pid, 0);
929
+ unlockRunning = true;
930
+ }
931
+ catch (err) {
932
+ if (err.code === 'EACCES') {
933
+ console.warn('[dexbot]', `process.kill(${pid}, 0) EACCES — process exists but permission denied`);
934
+ unlockRunning = true;
935
+ }
936
+ else if (err.code !== 'ESRCH') {
937
+ console.warn('[dexbot]', `process.kill(${pid}, 0) unexpected error: ${err.message}`);
938
+ }
939
+ }
940
+ }
941
+ }
942
+ catch (_) { }
943
+ }
944
+ if (!unlockRunning && storage.exists(SUPERVISOR_SOCK)) {
945
+ unlockRunning = true;
946
+ }
947
+ if (unlockRunning) {
948
+ const unlockScript = path.join(PATHS.PROJECT_ROOT, BUILD_DIR, 'unlock.js');
949
+ const result = spawnSync(Config.EXEC_PATH, [unlockScript, 'status'], {
950
+ cwd: PATHS.PROJECT_ROOT,
951
+ stdio: 'inherit',
952
+ });
953
+ process.exit(result.status ?? 0);
954
+ return true;
955
+ }
956
+ try {
957
+ const output = execSync('pm2 jlist 2>/dev/null', { encoding: 'utf8', timeout: 5000 }).toString().trim();
958
+ const jsonStart = output.indexOf('[');
959
+ if (jsonStart === -1) {
960
+ console.log('No DEXBot2 processes running.');
961
+ process.exit(0);
962
+ return true;
963
+ }
964
+ const allProcs = JSON.parse(output.slice(jsonStart));
965
+ if (!Array.isArray(allProcs) || allProcs.length === 0) {
966
+ console.log('No DEXBot2 processes running.');
967
+ process.exit(0);
968
+ return true;
969
+ }
970
+ const serviceNames = new Set(['dexbot-cred', 'dexbot-adapter', 'dexbot-update']);
971
+ const botNames = new Set();
972
+ try {
973
+ const { config } = loadSettingsFile(PROFILES_BOTS_FILE);
974
+ const entries = resolveRawBotEntries(config);
975
+ for (const b of entries) {
976
+ if (b.name)
977
+ botNames.add(b.name);
978
+ }
979
+ }
980
+ catch (_) { }
981
+ const dexbotProcs = allProcs.filter((p) => {
982
+ const name = String(p?.name || '');
983
+ return serviceNames.has(name) || botNames.has(name);
984
+ });
985
+ if (dexbotProcs.length === 0) {
986
+ console.log('No DEXBot2 processes running.');
987
+ process.exit(0);
988
+ return true;
989
+ }
990
+ console.log('='.repeat(50));
991
+ console.log('DEXBot2 PM2 Processes');
992
+ console.log('='.repeat(50));
993
+ console.log('');
994
+ const fmtUptime = (p) => {
995
+ if (!p?.pm2_env?.pm_uptime)
996
+ return '-';
997
+ const ms = Date.now() - new Date(p.pm2_env.pm_uptime).getTime();
998
+ const s = Math.floor(Math.abs(ms) / 1000);
999
+ if (s < 60)
1000
+ return `${s}s`;
1001
+ const m = Math.floor(s / 60);
1002
+ if (m < 60)
1003
+ return `${m}m ${s % 60}s`;
1004
+ const h = Math.floor(m / 60);
1005
+ if (h < 24)
1006
+ return `${h}h ${m % 60}m`;
1007
+ const d = Math.floor(h / 24);
1008
+ return `${d}d ${h % 24}h`;
1009
+ };
1010
+ const fmtMem = (p) => {
1011
+ const bytes = p?.monit?.memory;
1012
+ if (!bytes || bytes <= 0)
1013
+ return '-';
1014
+ if (bytes < 1024)
1015
+ return `${bytes}B`;
1016
+ if (bytes < 1024 * 1024)
1017
+ return `${(bytes / 1024).toFixed(1)}KB`;
1018
+ return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
1019
+ };
1020
+ const rows = dexbotProcs.map((p) => ({
1021
+ pid: String(p?.pid || '-'),
1022
+ name: String(p?.name || '-'),
1023
+ status: String(p?.pm2_env?.status || '-'),
1024
+ uptime: fmtUptime(p),
1025
+ mem: fmtMem(p),
1026
+ }));
1027
+ const nameWidth = Math.max(...rows.map(r => r.name.length), 4);
1028
+ const statusWidth = Math.max(...rows.map(r => r.status.length), 6);
1029
+ const header = `${'PID'.padEnd(8)} ${'NAME'.padEnd(nameWidth)} ${'STATUS'.padEnd(statusWidth)} ${'UPTIME'.padEnd(12)} ${'MEMORY'}`;
1030
+ console.log(header);
1031
+ console.log('-'.repeat(header.length));
1032
+ for (const r of rows) {
1033
+ console.log(`${r.pid.padEnd(8)} ${r.name.padEnd(nameWidth)} ${r.status.padEnd(statusWidth)} ${r.uptime.padEnd(12)} ${r.mem}`);
1034
+ }
1035
+ }
1036
+ catch {
1037
+ console.log('No DEXBot2 processes running.');
1038
+ }
1039
+ process.exit(0);
1040
+ return true;
1041
+ }
1042
+ case 'help':
1043
+ printCLIUsage();
1044
+ process.exit(0);
1045
+ default:
1046
+ printCLIUsage();
1047
+ process.exit(1);
1048
+ }
1049
+ }
1050
+ /**
1051
+ * Run all bots marked as active in settings.
1052
+ * @param {Object} [options={}] - Run options.
1053
+ * @param {boolean} [options.forceDryRun=false] - Force dry-run mode.
1054
+ * @param {string} [options.sourceName='settings'] - Source label.
1055
+ * @param {Object} [options.launcherStyle=null] - Launcher presentation options.
1056
+ * @returns {Promise<void>}
1057
+ */
1058
+ async function runDefaultBots({ forceDryRun = false, sourceName = 'settings', launcherStyle } = {}) {
1059
+ const { config } = loadSettingsFile(PROFILES_BOTS_FILE);
1060
+ const entries = resolveRawBotEntries(config);
1061
+ const normalized = normalizeBotEntries(entries);
1062
+ // Validate all profile files at startup (skip for PM2 child processes and tests)
1063
+ if (!Config.DEXBOT_SKIP_PROFILE_VALIDATION && !Config.PM2_HOME) {
1064
+ const { validateAllProfiles, printValidationProblems } = require('./modules/validate_profiles');
1065
+ const result = validateAllProfiles();
1066
+ const ok = printValidationProblems(result);
1067
+ if (!ok) {
1068
+ console.error(startupError('Fix the configuration errors above and restart.'));
1069
+ process.exit(1);
1070
+ }
1071
+ }
1072
+ await runBotInstances(normalized, { forceDryRun, sourceName, launcherStyle });
1073
+ }
1074
+ /**
1075
+ * Main application entry point for DEXBot2 CLI.
1076
+ * Handles initial setup, command routing, and starting active bots.
1077
+ * @returns {Promise<void>}
1078
+ */
1079
+ async function bootstrap() {
1080
+ // Ensure profiles directory exists
1081
+ let isNewSetup = false;
1082
+ try {
1083
+ isNewSetup = ensureProfilesDirectory(PROFILES_DIR);
1084
+ }
1085
+ catch (err) {
1086
+ if (err && (err.code === 'EACCES' || err.code === 'EPERM' || err.code === 'EROFS')) {
1087
+ const { homedir } = require('os');
1088
+ const { spawnSync: respawn } = require('child_process');
1089
+ const fallbackDir = path.join(homedir(), '.config', 'dexbot2');
1090
+ console.log(`Config directory not writable at: ${PROFILES_DIR}`);
1091
+ console.log(`Auto-using ${fallbackDir} instead. Set DEXBOT_PROFILE_ROOT to override.\n`);
1092
+ const newEnv = { ...process.env, DEXBOT_PROFILE_ROOT: fallbackDir };
1093
+ const respawnResult = respawn(Config.EXEC_PATH, [__filename, ...process.argv.slice(2)], {
1094
+ stdio: 'inherit',
1095
+ env: newEnv,
1096
+ });
1097
+ if (respawnResult.error) {
1098
+ console.error(`Respawn failed: ${respawnResult.error.message}`);
1099
+ process.exit(1);
1100
+ }
1101
+ process.exit(respawnResult.status ?? 0);
1102
+ return;
1103
+ }
1104
+ throw err;
1105
+ }
1106
+ // Handle CLI commands early — commands like 'update' must work even
1107
+ // when profiles/ was just cleaned (isNewSetup = true), otherwise the
1108
+ // new-setup wizard would block them before the CLI handler is reached.
1109
+ if (await handleCLICommands())
1110
+ return;
1111
+ // If this is a new setup, prompt to set up keys
1112
+ if (isNewSetup) {
1113
+ // Suppress BitShares connection log during first-time setup
1114
+ setSuppressConnectionLog(true);
1115
+ console.log();
1116
+ console.log('='.repeat(50));
1117
+ console.log('Welcome to DEXBot2!');
1118
+ console.log('='.repeat(50));
1119
+ console.log();
1120
+ // Generate default general.settings.json for new installations
1121
+ const SETTINGS_FILE = path.join(PROFILES_DIR, 'general.settings.json');
1122
+ const { LOG_LEVEL, GRID_LIMITS, TIMING, UPDATER, NODE_MANAGEMENT, MARKET_ADAPTER, DEFAULT_CONFIG, FILL_PROCESSING, PIPELINE_TIMING, CREDENTIAL_PROMPTS, MAINTENANCE, COW_PERFORMANCE, INCREMENT_BOUNDS, FEE_PARAMETERS, API_LIMITS, LOGGING_CONFIG, NATIVE_CLIENT, LAUNCHER, } = require('./modules/constants');
1123
+ const { writeJSON } = require('./modules/utils/fs_utils');
1124
+ // Create NODES config from NODE_MANAGEMENT constants
1125
+ const nodesConfig = {
1126
+ enabled: NODE_MANAGEMENT.DEFAULT_ENABLED,
1127
+ list: NODE_MANAGEMENT.DEFAULT_NODES,
1128
+ healthCheck: {
1129
+ enabled: true,
1130
+ intervalMs: NODE_MANAGEMENT.HEALTH_CHECK_INTERVAL_MS,
1131
+ timeoutMs: NODE_MANAGEMENT.HEALTH_CHECK_TIMEOUT_MS,
1132
+ maxPingMs: NODE_MANAGEMENT.MAX_PING_MS,
1133
+ blacklistThreshold: NODE_MANAGEMENT.BLACKLIST_THRESHOLD
1134
+ },
1135
+ selection: {
1136
+ strategy: NODE_MANAGEMENT.SELECTION_STRATEGY,
1137
+ preferredNode: null
1138
+ }
1139
+ };
1140
+ const defaultSettings = {
1141
+ LOG_LEVEL,
1142
+ NODES: nodesConfig,
1143
+ GRID_LIMITS: { ...GRID_LIMITS },
1144
+ TIMING: { ...TIMING },
1145
+ UPDATER: { ...UPDATER },
1146
+ MARKET_ADAPTER: { ...MARKET_ADAPTER },
1147
+ DEFAULT_CONFIG: { ...DEFAULT_CONFIG },
1148
+ FILL_PROCESSING: { ...FILL_PROCESSING },
1149
+ PIPELINE_TIMING: { ...PIPELINE_TIMING },
1150
+ CREDENTIAL_PROMPTS: { ...CREDENTIAL_PROMPTS },
1151
+ MAINTENANCE: { ...MAINTENANCE },
1152
+ COW_PERFORMANCE: { ...COW_PERFORMANCE },
1153
+ INCREMENT_BOUNDS: { ...INCREMENT_BOUNDS },
1154
+ FEE_PARAMETERS: { ...FEE_PARAMETERS },
1155
+ API_LIMITS: { ...API_LIMITS },
1156
+ LOGGING_CONFIG: { ...LOGGING_CONFIG },
1157
+ NATIVE_CLIENT: { ...NATIVE_CLIENT },
1158
+ LAUNCHER: { ...LAUNCHER },
1159
+ };
1160
+ writeJSON(SETTINGS_FILE, defaultSettings);
1161
+ console.log(startupSuccess('✓ Created default general.settings.json'));
1162
+ console.log();
1163
+ console.log('To get started, you need to configure your master password.');
1164
+ console.log('This password will encrypt your private keys.');
1165
+ console.log();
1166
+ const setupKeysAnswer = (await readInput('Set up master password now? [y/N]: ')).trim().toLowerCase();
1167
+ const setupKeys = setupKeysAnswer === 'y' || setupKeysAnswer === 'yes';
1168
+ if (setupKeys) {
1169
+ console.log();
1170
+ await chainKeys.main();
1171
+ console.log();
1172
+ console.log(startupSuccess('Master password configured! Now you can:'));
1173
+ console.log(' node dexbot bots - Create and manage bots');
1174
+ console.log(' node dexbot - Run your configured bots');
1175
+ console.log();
1176
+ }
1177
+ else {
1178
+ console.log();
1179
+ console.log('You can set up your master password later by running:');
1180
+ console.log(' node dexbot keys');
1181
+ console.log();
1182
+ }
1183
+ return;
1184
+ }
1185
+ // Check if bots.json exists - if not, guide user
1186
+ if (!storage.exists(PROFILES_BOTS_FILE)) {
1187
+ // Suppress BitShares connection log when no bots configured
1188
+ setSuppressConnectionLog(true);
1189
+ console.log();
1190
+ console.log('No bot configuration found.');
1191
+ console.log();
1192
+ console.log('First, set up your master password:');
1193
+ console.log(' node dexbot keys');
1194
+ console.log();
1195
+ console.log('Then, create your first bot:');
1196
+ console.log(' node dexbot bots');
1197
+ console.log();
1198
+ process.exit(0);
1199
+ }
1200
+ await runDefaultBots();
1201
+ }
1202
+ function handleFatalBootstrapError(err) {
1203
+ if (chainKeys.isMasterPasswordFailure(err)) {
1204
+ printMasterPasswordFailure(err);
1205
+ process.exit(1);
1206
+ return;
1207
+ }
1208
+ else if (err && err.message) {
1209
+ console.error(err.message);
1210
+ }
1211
+ else {
1212
+ console.error(err);
1213
+ }
1214
+ try {
1215
+ disconnectClient();
1216
+ }
1217
+ catch (disconnectErr) {
1218
+ }
1219
+ process.exit(1);
1220
+ }
1221
+ bootstrap().catch(handleFatalBootstrapError);
1222
+ //# sourceMappingURL=dexbot.js.map