dexbot 1.3.3 → 1.4.0

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 (736) hide show
  1. package/dist/analysis/chart_utils.d.ts +11 -9
  2. package/dist/analysis/chart_utils.d.ts.map +1 -1
  3. package/dist/analysis/chart_utils.js +21 -16
  4. package/dist/analysis/chart_utils.js.map +1 -1
  5. package/dist/analysis/math_utils.d.ts +4 -13
  6. package/dist/analysis/math_utils.d.ts.map +1 -1
  7. package/dist/analysis/math_utils.js +16 -18
  8. package/dist/analysis/math_utils.js.map +1 -1
  9. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +3 -7
  10. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
  11. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +38 -34
  12. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
  13. package/dist/analysis/trend_detection/hurst_analyzer.d.ts +1 -4
  14. package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -1
  15. package/dist/analysis/trend_detection/hurst_analyzer.js +10 -7
  16. package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
  17. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +6 -6
  18. package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -1
  19. package/dist/analysis/trend_detection/kalman_trend_analyzer.js +23 -15
  20. package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -1
  21. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +12 -13
  22. package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -1
  23. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +16 -16
  24. package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -1
  25. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +1 -4
  26. package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -1
  27. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +10 -7
  28. package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -1
  29. package/dist/bot.d.ts.map +1 -1
  30. package/dist/bot.js +6 -13
  31. package/dist/bot.js.map +1 -1
  32. package/dist/credential-daemon.d.ts.map +1 -1
  33. package/dist/credential-daemon.js +21 -22
  34. package/dist/credential-daemon.js.map +1 -1
  35. package/dist/dexbot.d.ts.map +1 -1
  36. package/dist/dexbot.js +16 -15
  37. package/dist/dexbot.js.map +1 -1
  38. package/dist/market_adapter/ama_signal_runner.d.ts +1 -1
  39. package/dist/market_adapter/ama_signal_runner.d.ts.map +1 -1
  40. package/dist/market_adapter/ama_signal_runner.js +8 -20
  41. package/dist/market_adapter/ama_signal_runner.js.map +1 -1
  42. package/dist/market_adapter/candle_utils.d.ts +2 -10
  43. package/dist/market_adapter/candle_utils.d.ts.map +1 -1
  44. package/dist/market_adapter/candle_utils.js +7 -8
  45. package/dist/market_adapter/candle_utils.js.map +1 -1
  46. package/dist/market_adapter/core/asymmetric_bounds.d.ts +12 -7
  47. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -1
  48. package/dist/market_adapter/core/asymmetric_bounds.js +4 -5
  49. package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
  50. package/dist/market_adapter/core/config_normalizers.d.ts +4 -9
  51. package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -1
  52. package/dist/market_adapter/core/config_normalizers.js +9 -9
  53. package/dist/market_adapter/core/config_normalizers.js.map +1 -1
  54. package/dist/market_adapter/core/kibana_candles.d.ts +16 -20
  55. package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -1
  56. package/dist/market_adapter/core/kibana_candles.js +16 -15
  57. package/dist/market_adapter/core/kibana_candles.js.map +1 -1
  58. package/dist/market_adapter/core/kibana_client.d.ts +8 -11
  59. package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
  60. package/dist/market_adapter/core/kibana_client.js +13 -11
  61. package/dist/market_adapter/core/kibana_client.js.map +1 -1
  62. package/dist/market_adapter/core/kibana_market_candles.d.ts +5 -12
  63. package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -1
  64. package/dist/market_adapter/core/kibana_market_candles.js +12 -21
  65. package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
  66. package/dist/market_adapter/core/market_adapter_service.d.ts +75 -53
  67. package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
  68. package/dist/market_adapter/core/market_adapter_service.js +102 -98
  69. package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
  70. package/dist/market_adapter/core/strategies/ama.d.ts +21 -1
  71. package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -1
  72. package/dist/market_adapter/core/strategies/ama.js +10 -10
  73. package/dist/market_adapter/core/strategies/ama.js.map +1 -1
  74. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +7 -11
  75. package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -1
  76. package/dist/market_adapter/core/strategies/ama_slope_model.js +23 -30
  77. package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
  78. package/dist/market_adapter/core/strategies/atr/calculator.d.ts +5 -4
  79. package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -1
  80. package/dist/market_adapter/core/strategies/atr/calculator.js +5 -3
  81. package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
  82. package/dist/market_adapter/core/strategies/collateral_manager.d.ts +4 -7
  83. package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -1
  84. package/dist/market_adapter/core/strategies/collateral_manager.js +5 -4
  85. package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
  86. package/dist/market_adapter/core/strategies/regime_gate.d.ts +11 -19
  87. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
  88. package/dist/market_adapter/core/strategies/regime_gate.js +22 -22
  89. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
  90. package/dist/market_adapter/index.d.ts +24 -2
  91. package/dist/market_adapter/index.d.ts.map +1 -1
  92. package/dist/market_adapter/index.js +82 -56
  93. package/dist/market_adapter/index.js.map +1 -1
  94. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +26 -37
  95. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
  96. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +4 -12
  97. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
  98. package/dist/market_adapter/inputs/fetch_lp_data.js +100 -66
  99. package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
  100. package/dist/market_adapter/inputs/kibana_source.d.ts +4 -9
  101. package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
  102. package/dist/market_adapter/inputs/kibana_source.js +17 -18
  103. package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
  104. package/dist/market_adapter/interval_utils.d.ts +1 -4
  105. package/dist/market_adapter/interval_utils.d.ts.map +1 -1
  106. package/dist/market_adapter/interval_utils.js +2 -3
  107. package/dist/market_adapter/interval_utils.js.map +1 -1
  108. package/dist/market_adapter/log_format.d.ts +1 -9
  109. package/dist/market_adapter/log_format.d.ts.map +1 -1
  110. package/dist/market_adapter/log_format.js +7 -8
  111. package/dist/market_adapter/log_format.js.map +1 -1
  112. package/dist/market_adapter/lp_chart_core.d.ts +1 -4
  113. package/dist/market_adapter/lp_chart_core.d.ts.map +1 -1
  114. package/dist/market_adapter/lp_chart_core.js +22 -20
  115. package/dist/market_adapter/lp_chart_core.js.map +1 -1
  116. package/dist/market_adapter/lp_chart_runner.d.ts +13 -24
  117. package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
  118. package/dist/market_adapter/lp_chart_runner.js +58 -56
  119. package/dist/market_adapter/lp_chart_runner.js.map +1 -1
  120. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +4 -17
  121. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -1
  122. package/dist/market_adapter/lp_chart_strategy_loader.js +36 -36
  123. package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
  124. package/dist/market_adapter/market_adapter.d.ts +51 -72
  125. package/dist/market_adapter/market_adapter.d.ts.map +1 -1
  126. package/dist/market_adapter/market_adapter.js +227 -192
  127. package/dist/market_adapter/market_adapter.js.map +1 -1
  128. package/dist/market_adapter/merge_lp_data.js +17 -16
  129. package/dist/market_adapter/merge_lp_data.js.map +1 -1
  130. package/dist/market_adapter/test_helpers.d.ts +9 -13
  131. package/dist/market_adapter/test_helpers.d.ts.map +1 -1
  132. package/dist/market_adapter/test_helpers.js +14 -14
  133. package/dist/market_adapter/test_helpers.js.map +1 -1
  134. package/dist/market_adapter/utils/adapter_client.d.ts +6 -14
  135. package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -1
  136. package/dist/market_adapter/utils/adapter_client.js +16 -15
  137. package/dist/market_adapter/utils/adapter_client.js.map +1 -1
  138. package/dist/market_adapter/utils/atomic_write.d.ts +2 -5
  139. package/dist/market_adapter/utils/atomic_write.d.ts.map +1 -1
  140. package/dist/market_adapter/utils/atomic_write.js +5 -5
  141. package/dist/market_adapter/utils/atomic_write.js.map +1 -1
  142. package/dist/market_adapter/utils/chain.d.ts +19 -21
  143. package/dist/market_adapter/utils/chain.d.ts.map +1 -1
  144. package/dist/market_adapter/utils/chain.js +15 -16
  145. package/dist/market_adapter/utils/chain.js.map +1 -1
  146. package/dist/market_adapter/utils/data_discovery.d.ts +1 -4
  147. package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -1
  148. package/dist/market_adapter/utils/data_discovery.js +10 -10
  149. package/dist/market_adapter/utils/data_discovery.js.map +1 -1
  150. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +1 -6
  151. package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
  152. package/dist/market_adapter/utils/dynamic_grid_snapshot.js +14 -14
  153. package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
  154. package/dist/market_adapter/utils/file_lock.d.ts +1 -7
  155. package/dist/market_adapter/utils/file_lock.d.ts.map +1 -1
  156. package/dist/market_adapter/utils/file_lock.js +21 -25
  157. package/dist/market_adapter/utils/file_lock.js.map +1 -1
  158. package/dist/market_adapter/utils/native_history.d.ts +12 -12
  159. package/dist/market_adapter/utils/native_history.d.ts.map +1 -1
  160. package/dist/market_adapter/utils/native_history.js +15 -15
  161. package/dist/market_adapter/utils/native_history.js.map +1 -1
  162. package/dist/market_adapter/utils/paths.d.ts +2 -4
  163. package/dist/market_adapter/utils/paths.d.ts.map +1 -1
  164. package/dist/market_adapter/utils/paths.js +6 -5
  165. package/dist/market_adapter/utils/paths.js.map +1 -1
  166. package/dist/modules/account_bots.d.ts +7 -8
  167. package/dist/modules/account_bots.d.ts.map +1 -1
  168. package/dist/modules/account_bots.js +92 -114
  169. package/dist/modules/account_bots.js.map +1 -1
  170. package/dist/modules/account_orders.d.ts +5 -9
  171. package/dist/modules/account_orders.d.ts.map +1 -1
  172. package/dist/modules/account_orders.js +69 -32
  173. package/dist/modules/account_orders.js.map +1 -1
  174. package/dist/modules/authority_resolver.d.ts +32 -1
  175. package/dist/modules/authority_resolver.d.ts.map +1 -1
  176. package/dist/modules/authority_resolver.js +18 -12
  177. package/dist/modules/authority_resolver.js.map +1 -1
  178. package/dist/modules/bitshares-native/chain_client.d.ts +3 -8
  179. package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -1
  180. package/dist/modules/bitshares-native/chain_client.js +21 -16
  181. package/dist/modules/bitshares-native/chain_client.js.map +1 -1
  182. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +21 -29
  183. package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -1
  184. package/dist/modules/bitshares-native/crypto/ecc.browser.js +72 -38
  185. package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
  186. package/dist/modules/bitshares-native/crypto/ecc.d.ts +9 -36
  187. package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +1 -1
  188. package/dist/modules/bitshares-native/crypto/ecc.js +40 -83
  189. package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -1
  190. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +14 -1
  191. package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -1
  192. package/dist/modules/bitshares-native/crypto/ecc_selector.js +5 -3
  193. package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
  194. package/dist/modules/bitshares-native/index.d.ts +10 -2
  195. package/dist/modules/bitshares-native/index.d.ts.map +1 -1
  196. package/dist/modules/bitshares-native/index.js +68 -31
  197. package/dist/modules/bitshares-native/index.js.map +1 -1
  198. package/dist/modules/bitshares-native/lru_cache.d.ts +1 -4
  199. package/dist/modules/bitshares-native/lru_cache.d.ts.map +1 -1
  200. package/dist/modules/bitshares-native/lru_cache.js +6 -3
  201. package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
  202. package/dist/modules/bitshares-native/resolvers.d.ts +3 -6
  203. package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -1
  204. package/dist/modules/bitshares-native/resolvers.js +11 -9
  205. package/dist/modules/bitshares-native/resolvers.js.map +1 -1
  206. package/dist/modules/bitshares-native/serial/chain_constants.d.ts +53 -55
  207. package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +1 -1
  208. package/dist/modules/bitshares-native/serial/chain_constants.js +28 -27
  209. package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
  210. package/dist/modules/bitshares-native/serial/index.d.ts +5 -9
  211. package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
  212. package/dist/modules/bitshares-native/serial/index.js +46 -12
  213. package/dist/modules/bitshares-native/serial/index.js.map +1 -1
  214. package/dist/modules/bitshares-native/serial/operations.d.ts +102 -100
  215. package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
  216. package/dist/modules/bitshares-native/serial/operations.js +473 -471
  217. package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
  218. package/dist/modules/bitshares-native/serial/serializer.d.ts +2 -7
  219. package/dist/modules/bitshares-native/serial/serializer.d.ts.map +1 -1
  220. package/dist/modules/bitshares-native/serial/serializer.js +8 -3
  221. package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
  222. package/dist/modules/bitshares-native/serial/types.d.ts +26 -41
  223. package/dist/modules/bitshares-native/serial/types.d.ts.map +1 -1
  224. package/dist/modules/bitshares-native/serial/types.js +76 -42
  225. package/dist/modules/bitshares-native/serial/types.js.map +1 -1
  226. package/dist/modules/bitshares-native/signing_client.d.ts +1 -5
  227. package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -1
  228. package/dist/modules/bitshares-native/signing_client.js +49 -11
  229. package/dist/modules/bitshares-native/signing_client.js.map +1 -1
  230. package/dist/modules/bitshares-native/subscriptions.d.ts +1 -4
  231. package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
  232. package/dist/modules/bitshares-native/subscriptions.js +47 -84
  233. package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
  234. package/dist/modules/bitshares-native/transport.d.ts +1 -8
  235. package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
  236. package/dist/modules/bitshares-native/transport.js +22 -15
  237. package/dist/modules/bitshares-native/transport.js.map +1 -1
  238. package/dist/modules/bitshares-native/tx/builder.d.ts +3 -8
  239. package/dist/modules/bitshares-native/tx/builder.d.ts.map +1 -1
  240. package/dist/modules/bitshares-native/tx/builder.js +61 -23
  241. package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
  242. package/dist/modules/bitshares-native/tx/tx_cache.d.ts +1 -8
  243. package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +1 -1
  244. package/dist/modules/bitshares-native/tx/tx_cache.js +21 -17
  245. package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
  246. package/dist/modules/bitshares_client.d.ts +12 -23
  247. package/dist/modules/bitshares_client.d.ts.map +1 -1
  248. package/dist/modules/bitshares_client.js +109 -56
  249. package/dist/modules/bitshares_client.js.map +1 -1
  250. package/dist/modules/bot_settings.d.ts +1 -13
  251. package/dist/modules/bot_settings.d.ts.map +1 -1
  252. package/dist/modules/bot_settings.js +34 -34
  253. package/dist/modules/bot_settings.js.map +1 -1
  254. package/dist/modules/bots_file_lock.d.ts +3 -9
  255. package/dist/modules/bots_file_lock.d.ts.map +1 -1
  256. package/dist/modules/bots_file_lock.js +8 -9
  257. package/dist/modules/bots_file_lock.js.map +1 -1
  258. package/dist/modules/chain_keys.d.ts +7 -39
  259. package/dist/modules/chain_keys.d.ts.map +1 -1
  260. package/dist/modules/chain_keys.js +126 -90
  261. package/dist/modules/chain_keys.js.map +1 -1
  262. package/dist/modules/chain_orders.d.ts +46 -52
  263. package/dist/modules/chain_orders.d.ts.map +1 -1
  264. package/dist/modules/chain_orders.js +152 -104
  265. package/dist/modules/chain_orders.js.map +1 -1
  266. package/dist/modules/config.d.ts +50 -57
  267. package/dist/modules/config.d.ts.map +1 -1
  268. package/dist/modules/config.js +28 -24
  269. package/dist/modules/config.js.map +1 -1
  270. package/dist/modules/constants.d.ts +492 -494
  271. package/dist/modules/constants.d.ts.map +1 -1
  272. package/dist/modules/constants.js +69 -39
  273. package/dist/modules/constants.js.map +1 -1
  274. package/dist/modules/cr_planner.d.ts +1 -13
  275. package/dist/modules/cr_planner.d.ts.map +1 -1
  276. package/dist/modules/cr_planner.js +28 -28
  277. package/dist/modules/cr_planner.js.map +1 -1
  278. package/dist/modules/credential_policy.d.ts +18 -33
  279. package/dist/modules/credential_policy.d.ts.map +1 -1
  280. package/dist/modules/credential_policy.js +114 -87
  281. package/dist/modules/credential_policy.js.map +1 -1
  282. package/dist/modules/credential_runtime.d.ts +11 -21
  283. package/dist/modules/credential_runtime.d.ts.map +1 -1
  284. package/dist/modules/credential_runtime.js +40 -40
  285. package/dist/modules/credential_runtime.js.map +1 -1
  286. package/dist/modules/credential_session_cache.d.ts +8 -8
  287. package/dist/modules/credential_session_cache.d.ts.map +1 -1
  288. package/dist/modules/credential_session_cache.js +41 -8
  289. package/dist/modules/credential_session_cache.js.map +1 -1
  290. package/dist/modules/credit_runtime.d.ts +51 -316
  291. package/dist/modules/credit_runtime.d.ts.map +1 -1
  292. package/dist/modules/credit_runtime.js +257 -183
  293. package/dist/modules/credit_runtime.js.map +1 -1
  294. package/dist/modules/crypto/browser_provider.js +6 -6
  295. package/dist/modules/crypto/browser_provider.js.map +1 -1
  296. package/dist/modules/crypto/index.d.ts.map +1 -1
  297. package/dist/modules/crypto/index.js +2 -0
  298. package/dist/modules/crypto/index.js.map +1 -1
  299. package/dist/modules/crypto/sync.js +3 -3
  300. package/dist/modules/crypto/sync.js.map +1 -1
  301. package/dist/modules/dexbot_class.d.ts +262 -81
  302. package/dist/modules/dexbot_class.d.ts.map +1 -1
  303. package/dist/modules/dexbot_class.js +156 -123
  304. package/dist/modules/dexbot_class.js.map +1 -1
  305. package/dist/modules/dexbot_cow_runtime.d.ts +12 -9
  306. package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
  307. package/dist/modules/dexbot_cow_runtime.js +132 -60
  308. package/dist/modules/dexbot_cow_runtime.js.map +1 -1
  309. package/dist/modules/dexbot_credential_client.d.ts +5 -11
  310. package/dist/modules/dexbot_credential_client.d.ts.map +1 -1
  311. package/dist/modules/dexbot_credential_client.js +32 -30
  312. package/dist/modules/dexbot_credential_client.js.map +1 -1
  313. package/dist/modules/dexbot_fill_runtime.d.ts +5 -20
  314. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
  315. package/dist/modules/dexbot_fill_runtime.js +55 -116
  316. package/dist/modules/dexbot_fill_runtime.js.map +1 -1
  317. package/dist/modules/dexbot_maintenance_runtime.d.ts +12 -12
  318. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
  319. package/dist/modules/dexbot_maintenance_runtime.js +55 -45
  320. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
  321. package/dist/modules/dexbot_startup_runtime.d.ts +2 -6
  322. package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
  323. package/dist/modules/dexbot_startup_runtime.js +115 -79
  324. package/dist/modules/dexbot_startup_runtime.js.map +1 -1
  325. package/dist/modules/dexbot_state_recovery.d.ts +11 -24
  326. package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
  327. package/dist/modules/dexbot_state_recovery.js +62 -28
  328. package/dist/modules/dexbot_state_recovery.js.map +1 -1
  329. package/dist/modules/fund_registry.d.ts +1 -13
  330. package/dist/modules/fund_registry.d.ts.map +1 -1
  331. package/dist/modules/fund_registry.js +23 -21
  332. package/dist/modules/fund_registry.js.map +1 -1
  333. package/dist/modules/general_settings.d.ts +3 -7
  334. package/dist/modules/general_settings.d.ts.map +1 -1
  335. package/dist/modules/general_settings.js +15 -14
  336. package/dist/modules/general_settings.js.map +1 -1
  337. package/dist/modules/graceful_shutdown.d.ts +1 -6
  338. package/dist/modules/graceful_shutdown.d.ts.map +1 -1
  339. package/dist/modules/graceful_shutdown.js +19 -16
  340. package/dist/modules/graceful_shutdown.js.map +1 -1
  341. package/dist/modules/key_store.d.ts.map +1 -1
  342. package/dist/modules/key_store.js +53 -19
  343. package/dist/modules/key_store.js.map +1 -1
  344. package/dist/modules/launcher/bot_supervisor.d.ts +23 -66
  345. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
  346. package/dist/modules/launcher/bot_supervisor.js +115 -107
  347. package/dist/modules/launcher/bot_supervisor.js.map +1 -1
  348. package/dist/modules/launcher/child_env.d.ts +2 -5
  349. package/dist/modules/launcher/child_env.d.ts.map +1 -1
  350. package/dist/modules/launcher/child_env.js +4 -4
  351. package/dist/modules/launcher/child_env.js.map +1 -1
  352. package/dist/modules/launcher/credential_bootstrap.d.ts +4 -8
  353. package/dist/modules/launcher/credential_bootstrap.d.ts.map +1 -1
  354. package/dist/modules/launcher/credential_bootstrap.js +30 -26
  355. package/dist/modules/launcher/credential_bootstrap.js.map +1 -1
  356. package/dist/modules/launcher/credential_daemon.d.ts +8 -15
  357. package/dist/modules/launcher/credential_daemon.d.ts.map +1 -1
  358. package/dist/modules/launcher/credential_daemon.js +72 -41
  359. package/dist/modules/launcher/credential_daemon.js.map +1 -1
  360. package/dist/modules/launcher/credential_secret.d.ts +1 -4
  361. package/dist/modules/launcher/credential_secret.d.ts.map +1 -1
  362. package/dist/modules/launcher/credential_secret.js +36 -4
  363. package/dist/modules/launcher/credential_secret.js.map +1 -1
  364. package/dist/modules/launcher/foreign_cred_daemon.d.ts +32 -1
  365. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
  366. package/dist/modules/launcher/foreign_cred_daemon.js +25 -28
  367. package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
  368. package/dist/modules/launcher/headless_password.d.ts +1 -4
  369. package/dist/modules/launcher/headless_password.d.ts.map +1 -1
  370. package/dist/modules/launcher/headless_password.js +11 -11
  371. package/dist/modules/launcher/headless_password.js.map +1 -1
  372. package/dist/modules/launcher/launch_modes.d.ts +15 -14
  373. package/dist/modules/launcher/launch_modes.d.ts.map +1 -1
  374. package/dist/modules/launcher/launch_modes.js +8 -8
  375. package/dist/modules/launcher/launch_modes.js.map +1 -1
  376. package/dist/modules/launcher/market_adapter_runtime.d.ts +10 -19
  377. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
  378. package/dist/modules/launcher/market_adapter_runtime.js +33 -33
  379. package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
  380. package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -17
  381. package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
  382. package/dist/modules/launcher/market_adapter_watchdog.js +42 -38
  383. package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
  384. package/dist/modules/launcher/monolithic_runtime.d.ts +28 -57
  385. package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
  386. package/dist/modules/launcher/monolithic_runtime.js +135 -108
  387. package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
  388. package/dist/modules/launcher/runtime_entry.d.ts +5 -10
  389. package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
  390. package/dist/modules/launcher/runtime_entry.js +14 -14
  391. package/dist/modules/launcher/runtime_entry.js.map +1 -1
  392. package/dist/modules/launcher/status_reporting.d.ts +17 -37
  393. package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
  394. package/dist/modules/launcher/status_reporting.js +35 -34
  395. package/dist/modules/launcher/status_reporting.js.map +1 -1
  396. package/dist/modules/launcher/supervisor_control.d.ts +1 -4
  397. package/dist/modules/launcher/supervisor_control.d.ts.map +1 -1
  398. package/dist/modules/launcher/supervisor_control.js +9 -4
  399. package/dist/modules/launcher/supervisor_control.js.map +1 -1
  400. package/dist/modules/logger.d.ts +3 -1
  401. package/dist/modules/logger.d.ts.map +1 -1
  402. package/dist/modules/logger.js +38 -28
  403. package/dist/modules/logger.js.map +1 -1
  404. package/dist/modules/market_adapter_whitelist.d.ts +2 -10
  405. package/dist/modules/market_adapter_whitelist.d.ts.map +1 -1
  406. package/dist/modules/market_adapter_whitelist.js +18 -16
  407. package/dist/modules/market_adapter_whitelist.js.map +1 -1
  408. package/dist/modules/node_health_cache.d.ts +2 -12
  409. package/dist/modules/node_health_cache.d.ts.map +1 -1
  410. package/dist/modules/node_health_cache.js +24 -24
  411. package/dist/modules/node_health_cache.js.map +1 -1
  412. package/dist/modules/node_manager.d.ts +1 -1
  413. package/dist/modules/node_manager.d.ts.map +1 -1
  414. package/dist/modules/node_manager.js +44 -38
  415. package/dist/modules/node_manager.js.map +1 -1
  416. package/dist/modules/order/accounting.d.ts +12 -12
  417. package/dist/modules/order/accounting.d.ts.map +1 -1
  418. package/dist/modules/order/accounting.js +111 -76
  419. package/dist/modules/order/accounting.js.map +1 -1
  420. package/dist/modules/order/async_lock.d.ts +1 -2
  421. package/dist/modules/order/async_lock.d.ts.map +1 -1
  422. package/dist/modules/order/async_lock.js +4 -4
  423. package/dist/modules/order/async_lock.js.map +1 -1
  424. package/dist/modules/order/export.d.ts +8 -14
  425. package/dist/modules/order/export.d.ts.map +1 -1
  426. package/dist/modules/order/export.js +77 -42
  427. package/dist/modules/order/export.js.map +1 -1
  428. package/dist/modules/order/format.d.ts +17 -22
  429. package/dist/modules/order/format.d.ts.map +1 -1
  430. package/dist/modules/order/format.js +25 -31
  431. package/dist/modules/order/format.js.map +1 -1
  432. package/dist/modules/order/grid.d.ts +18 -104
  433. package/dist/modules/order/grid.d.ts.map +1 -1
  434. package/dist/modules/order/grid.js +246 -188
  435. package/dist/modules/order/grid.js.map +1 -1
  436. package/dist/modules/order/grid_reconcile.d.ts +8 -8
  437. package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
  438. package/dist/modules/order/grid_reconcile.js +24 -23
  439. package/dist/modules/order/grid_reconcile.js.map +1 -1
  440. package/dist/modules/order/grid_reconcile_internal.d.ts +224 -1
  441. package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
  442. package/dist/modules/order/grid_reconcile_internal.js +145 -72
  443. package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
  444. package/dist/modules/order/index.d.ts +1 -1
  445. package/dist/modules/order/index.d.ts.map +1 -1
  446. package/dist/modules/order/index.js +42 -7
  447. package/dist/modules/order/index.js.map +1 -1
  448. package/dist/modules/order/logger.d.ts +6 -16
  449. package/dist/modules/order/logger.d.ts.map +1 -1
  450. package/dist/modules/order/logger.js +76 -53
  451. package/dist/modules/order/logger.js.map +1 -1
  452. package/dist/modules/order/logger_state.d.ts +4 -4
  453. package/dist/modules/order/logger_state.d.ts.map +1 -1
  454. package/dist/modules/order/logger_state.js +3 -1
  455. package/dist/modules/order/logger_state.js.map +1 -1
  456. package/dist/modules/order/manager.d.ts +160 -37
  457. package/dist/modules/order/manager.d.ts.map +1 -1
  458. package/dist/modules/order/manager.js +166 -128
  459. package/dist/modules/order/manager.js.map +1 -1
  460. package/dist/modules/order/processed_fill_store.d.ts +6 -10
  461. package/dist/modules/order/processed_fill_store.d.ts.map +1 -1
  462. package/dist/modules/order/processed_fill_store.js +10 -9
  463. package/dist/modules/order/processed_fill_store.js.map +1 -1
  464. package/dist/modules/order/strategy.d.ts +3 -3
  465. package/dist/modules/order/strategy.d.ts.map +1 -1
  466. package/dist/modules/order/strategy.js +29 -27
  467. package/dist/modules/order/strategy.js.map +1 -1
  468. package/dist/modules/order/sync_engine.d.ts +9 -19
  469. package/dist/modules/order/sync_engine.d.ts.map +1 -1
  470. package/dist/modules/order/sync_engine.js +176 -126
  471. package/dist/modules/order/sync_engine.js.map +1 -1
  472. package/dist/modules/order/utils/math.d.ts +55 -85
  473. package/dist/modules/order/utils/math.d.ts.map +1 -1
  474. package/dist/modules/order/utils/math.js +155 -88
  475. package/dist/modules/order/utils/math.js.map +1 -1
  476. package/dist/modules/order/utils/order.d.ts +27 -72
  477. package/dist/modules/order/utils/order.d.ts.map +1 -1
  478. package/dist/modules/order/utils/order.js +144 -105
  479. package/dist/modules/order/utils/order.js.map +1 -1
  480. package/dist/modules/order/utils/system.d.ts +74 -44
  481. package/dist/modules/order/utils/system.d.ts.map +1 -1
  482. package/dist/modules/order/utils/system.js +188 -149
  483. package/dist/modules/order/utils/system.js.map +1 -1
  484. package/dist/modules/order/utils/validate.d.ts +21 -43
  485. package/dist/modules/order/utils/validate.d.ts.map +1 -1
  486. package/dist/modules/order/utils/validate.js +140 -109
  487. package/dist/modules/order/utils/validate.js.map +1 -1
  488. package/dist/modules/order/working_grid.d.ts +1 -4
  489. package/dist/modules/order/working_grid.d.ts.map +1 -1
  490. package/dist/modules/order/working_grid.js +9 -7
  491. package/dist/modules/order/working_grid.js.map +1 -1
  492. package/dist/modules/path_api.js +2 -2
  493. package/dist/modules/path_api.js.map +1 -1
  494. package/dist/modules/paths.d.ts +50 -56
  495. package/dist/modules/paths.d.ts.map +1 -1
  496. package/dist/modules/paths.js +66 -57
  497. package/dist/modules/paths.js.map +1 -1
  498. package/dist/modules/process_discovery.d.ts +1 -1
  499. package/dist/modules/process_discovery.d.ts.map +1 -1
  500. package/dist/modules/process_discovery.js +7 -7
  501. package/dist/modules/process_discovery.js.map +1 -1
  502. package/dist/modules/runtime.d.ts +1 -1
  503. package/dist/modules/runtime.d.ts.map +1 -1
  504. package/dist/modules/runtime.js +4 -4
  505. package/dist/modules/runtime.js.map +1 -1
  506. package/dist/modules/runtime_settings.d.ts +1 -0
  507. package/dist/modules/runtime_settings.d.ts.map +1 -1
  508. package/dist/modules/runtime_settings.js +15 -10
  509. package/dist/modules/runtime_settings.js.map +1 -1
  510. package/dist/modules/settings_merge.d.ts +1 -4
  511. package/dist/modules/settings_merge.d.ts.map +1 -1
  512. package/dist/modules/settings_merge.js +2 -1
  513. package/dist/modules/settings_merge.js.map +1 -1
  514. package/dist/modules/storage/browser_adapter.d.ts +7 -3
  515. package/dist/modules/storage/browser_adapter.d.ts.map +1 -1
  516. package/dist/modules/storage/browser_adapter.js +2 -0
  517. package/dist/modules/storage/browser_adapter.js.map +1 -1
  518. package/dist/modules/storage/index.d.ts +2 -2
  519. package/dist/modules/storage/index.d.ts.map +1 -1
  520. package/dist/modules/storage/index.js +2 -5
  521. package/dist/modules/storage/index.js.map +1 -1
  522. package/dist/modules/storage/node_adapter.d.ts +3 -3
  523. package/dist/modules/storage/node_adapter.d.ts.map +1 -1
  524. package/dist/modules/storage/node_adapter.js +9 -7
  525. package/dist/modules/storage/node_adapter.js.map +1 -1
  526. package/dist/modules/storage/types.d.ts +13 -10
  527. package/dist/modules/storage/types.d.ts.map +1 -1
  528. package/dist/modules/types.d.ts +0 -2
  529. package/dist/modules/types.d.ts.map +1 -1
  530. package/dist/modules/utils/base58check.d.ts +1 -9
  531. package/dist/modules/utils/base58check.d.ts.map +1 -1
  532. package/dist/modules/utils/base58check.js +14 -16
  533. package/dist/modules/utils/base58check.js.map +1 -1
  534. package/dist/modules/utils/build_dir.d.ts +2 -5
  535. package/dist/modules/utils/build_dir.d.ts.map +1 -1
  536. package/dist/modules/utils/build_dir.js +6 -3
  537. package/dist/modules/utils/build_dir.js.map +1 -1
  538. package/dist/modules/utils/errors.d.ts +2 -0
  539. package/dist/modules/utils/errors.d.ts.map +1 -0
  540. package/dist/modules/utils/errors.js +12 -0
  541. package/dist/modules/utils/errors.js.map +1 -0
  542. package/dist/modules/utils/fs_utils.d.ts +1 -8
  543. package/dist/modules/utils/fs_utils.d.ts.map +1 -1
  544. package/dist/modules/utils/fs_utils.js +8 -3
  545. package/dist/modules/utils/fs_utils.js.map +1 -1
  546. package/dist/modules/utils/math_utils.d.ts +2 -6
  547. package/dist/modules/utils/math_utils.d.ts.map +1 -1
  548. package/dist/modules/utils/math_utils.js +6 -2
  549. package/dist/modules/utils/math_utils.js.map +1 -1
  550. package/dist/modules/validate_profiles.d.ts +1 -11
  551. package/dist/modules/validate_profiles.d.ts.map +1 -1
  552. package/dist/modules/validate_profiles.js +25 -27
  553. package/dist/modules/validate_profiles.js.map +1 -1
  554. package/dist/pm2.d.ts +7 -6
  555. package/dist/pm2.d.ts.map +1 -1
  556. package/dist/pm2.js +132 -106
  557. package/dist/pm2.js.map +1 -1
  558. package/dist/scripts/analyze-git.d.ts.map +1 -1
  559. package/dist/scripts/analyze-git.js +15 -11
  560. package/dist/scripts/analyze-git.js.map +1 -1
  561. package/dist/scripts/analyze-orders.d.ts +146 -1
  562. package/dist/scripts/analyze-orders.d.ts.map +1 -1
  563. package/dist/scripts/analyze-orders.js +81 -105
  564. package/dist/scripts/analyze-orders.js.map +1 -1
  565. package/dist/scripts/diagnose-pool-history.d.ts.map +1 -1
  566. package/dist/scripts/diagnose-pool-history.js +9 -8
  567. package/dist/scripts/diagnose-pool-history.js.map +1 -1
  568. package/dist/scripts/divergence-calc.d.ts.map +1 -1
  569. package/dist/scripts/divergence-calc.js +11 -8
  570. package/dist/scripts/divergence-calc.js.map +1 -1
  571. package/dist/scripts/fix-err-message.d.ts +3 -0
  572. package/dist/scripts/fix-err-message.d.ts.map +1 -0
  573. package/dist/scripts/fix-err-message.js +198 -0
  574. package/dist/scripts/fix-err-message.js.map +1 -0
  575. package/dist/scripts/generate_lp_chart.d.ts +2 -9
  576. package/dist/scripts/generate_lp_chart.d.ts.map +1 -1
  577. package/dist/scripts/generate_lp_chart.js +14 -10
  578. package/dist/scripts/generate_lp_chart.js.map +1 -1
  579. package/dist/scripts/generate_mainnet_corpus_report.js +4 -4
  580. package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -1
  581. package/dist/scripts/generate_market_adapter_whitelist.d.ts +17 -1
  582. package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -1
  583. package/dist/scripts/generate_market_adapter_whitelist.js +23 -20
  584. package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -1
  585. package/dist/scripts/migrate_bot_keys.d.ts +1 -4
  586. package/dist/scripts/migrate_bot_keys.d.ts.map +1 -1
  587. package/dist/scripts/migrate_bot_keys.js +48 -124
  588. package/dist/scripts/migrate_bot_keys.js.map +1 -1
  589. package/dist/scripts/native_release_gates.d.ts.map +1 -1
  590. package/dist/scripts/native_release_gates.js +18 -14
  591. package/dist/scripts/native_release_gates.js.map +1 -1
  592. package/dist/scripts/print_grid.js +1 -1
  593. package/dist/scripts/print_grid.js.map +1 -1
  594. package/dist/scripts/run-tests.js +1 -0
  595. package/dist/scripts/run-tests.js.map +1 -1
  596. package/dist/scripts/runner.d.ts +1 -11
  597. package/dist/scripts/runner.d.ts.map +1 -1
  598. package/dist/scripts/runner.js +21 -19
  599. package/dist/scripts/runner.js.map +1 -1
  600. package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
  601. package/dist/scripts/test-credit-renewal.js +2 -1
  602. package/dist/scripts/test-credit-renewal.js.map +1 -1
  603. package/dist/scripts/update.d.ts.map +1 -1
  604. package/dist/scripts/update.js +85 -79
  605. package/dist/scripts/update.js.map +1 -1
  606. package/dist/scripts/validate_bots.js +2 -2
  607. package/dist/scripts/validate_bots.js.map +1 -1
  608. package/dist/unlock.d.ts +4 -17
  609. package/dist/unlock.d.ts.map +1 -1
  610. package/dist/unlock.js +141 -108
  611. package/dist/unlock.js.map +1 -1
  612. package/package.json +1 -1
  613. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +0 -3
  614. package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
  615. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +0 -149
  616. package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
  617. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +0 -3
  618. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
  619. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +0 -387
  620. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
  621. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +0 -3
  622. package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
  623. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -200
  624. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
  625. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +0 -3
  626. package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
  627. package/dist/analysis/ama_fitting/fetch_lp_candles.js +0 -212
  628. package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
  629. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +0 -31
  630. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
  631. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +0 -249
  632. package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
  633. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +0 -2
  634. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
  635. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +0 -782
  636. package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
  637. package/dist/analysis/analyze_derivatives.d.ts +0 -95
  638. package/dist/analysis/analyze_derivatives.d.ts.map +0 -1
  639. package/dist/analysis/analyze_derivatives.js +0 -295
  640. package/dist/analysis/analyze_derivatives.js.map +0 -1
  641. package/dist/analysis/analyze_dynamic_weight.d.ts +0 -14
  642. package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
  643. package/dist/analysis/analyze_dynamic_weight.js +0 -207
  644. package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
  645. package/dist/analysis/analyze_kalman.d.ts +0 -13
  646. package/dist/analysis/analyze_kalman.d.ts.map +0 -1
  647. package/dist/analysis/analyze_kalman.js +0 -123
  648. package/dist/analysis/analyze_kalman.js.map +0 -1
  649. package/dist/analysis/analyze_regime.d.ts +0 -20
  650. package/dist/analysis/analyze_regime.d.ts.map +0 -1
  651. package/dist/analysis/analyze_regime.js +0 -139
  652. package/dist/analysis/analyze_regime.js.map +0 -1
  653. package/dist/analysis/analyze_regime_windows.d.ts +0 -19
  654. package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
  655. package/dist/analysis/analyze_regime_windows.js +0 -413
  656. package/dist/analysis/analyze_regime_windows.js.map +0 -1
  657. package/dist/analysis/analyze_risk_profile.d.ts +0 -3
  658. package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
  659. package/dist/analysis/analyze_risk_profile.js +0 -159
  660. package/dist/analysis/analyze_risk_profile.js.map +0 -1
  661. package/dist/analysis/analyze_trade_heatmap.d.ts +0 -3
  662. package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
  663. package/dist/analysis/analyze_trade_heatmap.js +0 -367
  664. package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
  665. package/dist/analysis/analyze_volatility.d.ts +0 -22
  666. package/dist/analysis/analyze_volatility.d.ts.map +0 -1
  667. package/dist/analysis/analyze_volatility.js +0 -172
  668. package/dist/analysis/analyze_volatility.js.map +0 -1
  669. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +0 -99
  670. package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
  671. package/dist/analysis/bot_fitting/backtest_ama_sweep.js +0 -804
  672. package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
  673. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +0 -2
  674. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
  675. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +0 -347
  676. package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
  677. package/dist/analysis/bot_fitting/shared_utils.d.ts +0 -15
  678. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
  679. package/dist/analysis/bot_fitting/shared_utils.js +0 -48
  680. package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
  681. package/dist/analysis/bot_key_utils.d.ts +0 -22
  682. package/dist/analysis/bot_key_utils.d.ts.map +0 -1
  683. package/dist/analysis/bot_key_utils.js +0 -162
  684. package/dist/analysis/bot_key_utils.js.map +0 -1
  685. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +0 -3
  686. package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
  687. package/dist/analysis/bot_usage/discover_bot_accounts.js +0 -498
  688. package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
  689. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +0 -546
  690. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
  691. package/dist/analysis/bot_usage/kibana_bot_queries.js +0 -427
  692. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
  693. package/dist/analysis/derivative_chart_generator.d.ts +0 -18
  694. package/dist/analysis/derivative_chart_generator.d.ts.map +0 -1
  695. package/dist/analysis/derivative_chart_generator.js +0 -896
  696. package/dist/analysis/derivative_chart_generator.js.map +0 -1
  697. package/dist/analysis/price_sources.d.ts +0 -34
  698. package/dist/analysis/price_sources.d.ts.map +0 -1
  699. package/dist/analysis/price_sources.js +0 -103
  700. package/dist/analysis/price_sources.js.map +0 -1
  701. package/dist/analysis/trade_profitability.d.ts +0 -115
  702. package/dist/analysis/trade_profitability.d.ts.map +0 -1
  703. package/dist/analysis/trade_profitability.js +0 -1247
  704. package/dist/analysis/trade_profitability.js.map +0 -1
  705. package/dist/analysis/tradingview/analyze_tradingview.d.ts +0 -36
  706. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
  707. package/dist/analysis/tradingview/analyze_tradingview.js +0 -172
  708. package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
  709. package/dist/analysis/trend_detection/derivative_analyzer.d.ts +0 -250
  710. package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +0 -1
  711. package/dist/analysis/trend_detection/derivative_analyzer.js +0 -903
  712. package/dist/analysis/trend_detection/derivative_analyzer.js.map +0 -1
  713. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +0 -6
  714. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
  715. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +0 -1450
  716. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
  717. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +0 -6
  718. package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
  719. package/dist/analysis/trend_detection/kalman_chart_generator.js +0 -408
  720. package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
  721. package/dist/analysis/trend_detection/regime_chart_generator.d.ts +0 -6
  722. package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
  723. package/dist/analysis/trend_detection/regime_chart_generator.js +0 -345
  724. package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
  725. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
  726. package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
  727. package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -130
  728. package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
  729. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
  730. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
  731. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -38
  732. package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
  733. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +0 -6
  734. package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
  735. package/dist/analysis/trend_detection/volatility_chart_generator.js +0 -732
  736. package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
@@ -1,804 +0,0 @@
1
- 'use strict';
2
- /**
3
- * AMA SWEEP BACKTEST — persistent grid simulation
4
- *
5
- * Models the real bot mechanics:
6
- * - Orders sit at FIXED chain prices until canceled or filled
7
- * - When AMA drifts past reposition threshold, grid re-centers
8
- * - Grid compression: AMA shift pushes one side's orders closer to market
9
- * - Order sizing depends on capital, ratio (range width), and weight profile
10
- * - Three weight profiles: valley, neutral, mountain (symmetric buy/sell)
11
- *
12
- * Usage:
13
- * tsx analysis/bot_fitting/backtest_ama_sweep.ts --data <path-to-lp-candles.json>
14
- * tsx analysis/bot_fitting/backtest_ama_sweep.ts --data <path-to-lp-candles.json> --spread 4:16:1 --increment 0.5:4:0.25
15
- */
16
- const fs = require('fs');
17
- const path = require('path');
18
- const os = require('os');
19
- const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
20
- const { calculateAMA } = require('../../market_adapter/core/strategies/ama');
21
- const { range } = require('../math_utils');
22
- const { parseListOrRange, loadLpData, fmt } = require('./shared_utils');
23
- const { readJSON, writeJSON } = require('../../modules/utils/fs_utils');
24
- const DEFAULT_MAX_ORDERS = 20; // matches bot default activeOrders per side
25
- const DEFAULT_FEE_ROUNDTRIP_PCT = 0.20;
26
- const DEFAULT_MIN_SPREAD_FACTOR = 2.1;
27
- const DEFAULT_CAPITAL = 10000; // notional units per side
28
- const DEFAULT_BTS_CREATE_FEE = 0.48260;
29
- const DEFAULT_BTS_CANCEL_FEE = 0.00482;
30
- const DEFAULT_BTS_MAKER_CREATE_FACTOR = 0.10;
31
- const DEFAULT_TX_FEE_PRICE = 1.0;
32
- // Weight profiles (symmetric for both sides)
33
- // valley: heavier at edges (outer levels), lighter near center
34
- // neutral: equal across all levels
35
- // mountain: heavier near center, lighter at edges
36
- const WEIGHT_PROFILES = {
37
- valley: -0.8, // negative = invert decay → outer levels get more
38
- neutral: 0, // flat = equal distribution
39
- mountain: 1.5, // strong decay → inner levels get more
40
- };
41
- // Search grid defaults — centered around bot defaults (spread=2%, increment=0.5%)
42
- // Spread = distance from center to first order on each side (half the bid-ask gap)
43
- // Increment = distance between successive orders on the same side
44
- const DEFAULT_SPREAD_VALUES = [...range(0.5, 4, 0.25), ...range(5, 12, 1)];
45
- const DEFAULT_INCREMENT_VALUES = [...range(0.2, 2, 0.1), ...range(2.5, 8, 0.5)];
46
- const DEFAULT_RATIO_VALUES = [1.05, 1.1, 1.15, 1.2, 1.3, 1.5, 2, 3, 5, 10];
47
- // Reposition threshold: AMA must move this fraction from last grid center to trigger re-center
48
- const DEFAULT_REPOSITION_PCT = 2.5;
49
- function jsonSafe(key, val) {
50
- if (val === -Infinity || val === Infinity)
51
- return null;
52
- return val;
53
- }
54
- function parseArgs() {
55
- const args = process.argv.slice(2);
56
- const out = {
57
- dataPath: null,
58
- resultsPath: null,
59
- spreadValues: DEFAULT_SPREAD_VALUES,
60
- incrementValues: DEFAULT_INCREMENT_VALUES,
61
- ratioValues: DEFAULT_RATIO_VALUES,
62
- maxOrders: DEFAULT_MAX_ORDERS,
63
- feeRoundtripPct: DEFAULT_FEE_ROUNDTRIP_PCT,
64
- minSpreadFactor: DEFAULT_MIN_SPREAD_FACTOR,
65
- capital: DEFAULT_CAPITAL,
66
- repositionPct: DEFAULT_REPOSITION_PCT,
67
- btsCreateFee: DEFAULT_BTS_CREATE_FEE,
68
- btsCancelFee: DEFAULT_BTS_CANCEL_FEE,
69
- makerCreateFactor: DEFAULT_BTS_MAKER_CREATE_FACTOR,
70
- txFeePrice: DEFAULT_TX_FEE_PRICE,
71
- topN: 15,
72
- };
73
- for (let i = 0; i < args.length; i++) {
74
- const arg = args[i];
75
- const val = args[i + 1];
76
- if (arg === '--help' || arg === '-h') {
77
- printHelp();
78
- process.exit(0);
79
- }
80
- if (!val)
81
- continue;
82
- switch (arg) {
83
- case '--data':
84
- out.dataPath = path.resolve(val);
85
- i++;
86
- break;
87
- case '--results':
88
- out.resultsPath = path.resolve(val);
89
- i++;
90
- break;
91
- case '--spread':
92
- out.spreadValues = parseListOrRange(val, DEFAULT_SPREAD_VALUES);
93
- i++;
94
- break;
95
- case '--increment':
96
- out.incrementValues = parseListOrRange(val, DEFAULT_INCREMENT_VALUES);
97
- i++;
98
- break;
99
- case '--ratio':
100
- out.ratioValues = parseListOrRange(val, DEFAULT_RATIO_VALUES);
101
- i++;
102
- break;
103
- case '--max-orders':
104
- out.maxOrders = Number(val);
105
- i++;
106
- break;
107
- case '--fee':
108
- out.feeRoundtripPct = Number(val);
109
- i++;
110
- break;
111
- case '--min-spread-factor':
112
- out.minSpreadFactor = Number(val);
113
- i++;
114
- break;
115
- case '--capital':
116
- out.capital = Number(val);
117
- i++;
118
- break;
119
- case '--reposition':
120
- out.repositionPct = Number(val);
121
- i++;
122
- break;
123
- case '--bts-create-fee':
124
- out.btsCreateFee = Number(val);
125
- i++;
126
- break;
127
- case '--bts-cancel-fee':
128
- out.btsCancelFee = Number(val);
129
- i++;
130
- break;
131
- case '--maker-create-factor':
132
- out.makerCreateFactor = Number(val);
133
- i++;
134
- break;
135
- case '--tx-fee-price':
136
- out.txFeePrice = Number(val);
137
- i++;
138
- break;
139
- case '--top':
140
- out.topN = Number(val);
141
- i++;
142
- break;
143
- }
144
- }
145
- if (!out.dataPath) {
146
- throw new Error('--data <path-to-lp-candles.json> is required');
147
- }
148
- if (!out.resultsPath) {
149
- throw new Error('--results <path-to-optimization-results.json> is required');
150
- }
151
- return out;
152
- }
153
- function printHelp() {
154
- console.log('AMA Sweep Backtest — persistent grid simulation with weight profiles');
155
- console.log('');
156
- console.log('Usage:');
157
- console.log(' tsx analysis/bot_fitting/backtest_ama_sweep.ts [options]');
158
- console.log('');
159
- console.log('Options:');
160
- console.log(' --data <path> LP candle JSON');
161
- console.log(' --results <path> AMA optimizer results JSON');
162
- console.log(' --spread <spec> Spread values (% ): 1:10:0.5 or 2,4,8');
163
- console.log(' --increment <spec> Increment values (%): 0.5:5:0.5 or 1,2,3');
164
- console.log(' --ratio <spec> Max/min ratio: 1.5,2,3,5');
165
- console.log(' --max-orders <n> Max orders per side (default: 20, actual limited by ratio+increment)');
166
- console.log(' --fee <pct> Round-trip fee % (default: 0.20)');
167
- console.log(' --min-spread-factor <n> Spread >= factor * increment (default: 2.1)');
168
- console.log(' --capital <n> Notional capital per side (default: 10000)');
169
- console.log(' --reposition <pct> AMA drift % to trigger re-center (default: 2.5)');
170
- console.log(' --bts-create-fee <n> BTS create fee (default: 0.48260)');
171
- console.log(' --bts-cancel-fee <n> BTS cancel fee (default: 0.00482)');
172
- console.log(' --maker-create-factor Maker share of create fee (default: 0.10)');
173
- console.log(' --tx-fee-price <n> Convert BTS fees into backtest units (default: 1.0)');
174
- console.log(' --top <n> Show top N results (default: 15)');
175
- }
176
- function loadAmaStrategies(resultsPath) {
177
- const json = readJSON(resultsPath);
178
- const amas = json.meta?.amas;
179
- if (!amas)
180
- throw new Error('No meta.amas found in results file.');
181
- const out = [];
182
- for (const [key, val] of Object.entries(amas)) {
183
- const v = val;
184
- if (!v || !Number.isFinite(v.er))
185
- continue;
186
- out.push({ id: key, name: v.label || key, er: v.er, fast: v.fast, slow: v.slow });
187
- }
188
- out.sort((a, b) => a.id.localeCompare(b.id));
189
- if (out.length === 0)
190
- throw new Error('No valid AMA strategies found');
191
- return out;
192
- }
193
- // ── Order sizing with weight profiles ────────────────────────────────────────
194
- /**
195
- * Allocate capital across N levels using weight profile.
196
- * weight > 0: mountain (more near center, exponential decay outward)
197
- * weight = 0: neutral (equal)
198
- * weight < 0: valley (more at edges, inverted decay)
199
- *
200
- * @param {number} totalFunds Capital for this side
201
- * @param {number} n Number of levels
202
- * @param {number} weight Profile weight factor
203
- * @param {number} incrementFactor Increment as fraction (e.g. 0.02 for 2%)
204
- * @returns {number[]} Size per level, index 0 = closest to center
205
- */
206
- function allocateFundsByWeights(totalFunds, n, weight, incrementFactor) {
207
- if (n <= 0)
208
- return [];
209
- if (weight === 0) {
210
- const sz = totalFunds / n;
211
- return new Array(n).fill(sz);
212
- }
213
- const base = 1 - incrementFactor;
214
- const absWeight = Math.abs(weight);
215
- const raw = new Array(n);
216
- for (let i = 0; i < n; i++) {
217
- // i=0 is closest to center
218
- raw[i] = Math.pow(base, i * absWeight);
219
- }
220
- if (weight < 0) {
221
- // Valley: reverse so outer levels (high i) get the large weights
222
- raw.reverse();
223
- }
224
- const total = raw.reduce((s, w) => s + w, 0) || 1;
225
- return raw.map((w) => (w / total) * totalFunds);
226
- }
227
- // ── Persistent grid simulation ───────────────────────────────────────────────
228
- /**
229
- * Build a fresh grid centered at `center`.
230
- *
231
- * Grid placement (matches real bot):
232
- * Level k (1-based):
233
- * offset_k = spreadPct/2/100 + (k-1) * incrementPct
234
- * buyPrice = center * (1 - offset_k)
235
- * sellPrice = center * (1 + offset_k)
236
- *
237
- * So spread controls the dead zone around center (no orders within spread/2),
238
- * and increment is the gap between successive orders on the same side.
239
- *
240
- * Returns arrays of buy and sell order objects with fixed chain prices and sizes.
241
- */
242
- function buildGrid(center, params, capitalPerSide, weightFactor) {
243
- const { incrementPct, maxMinRatio, maxOrders, spreadPct } = params;
244
- const minBound = center / maxMinRatio;
245
- const maxBound = center * maxMinRatio;
246
- const halfSpread = spreadPct / 200; // as fraction
247
- const buys = [];
248
- const sells = [];
249
- // Fill as many levels as fit within ratio bounds (up to maxOrders cap)
250
- for (let k = 1; k <= maxOrders; k++) {
251
- const offset = halfSpread + (k - 1) * incrementPct;
252
- if (offset >= 0.95)
253
- continue;
254
- const buyPrice = center * (1 - offset);
255
- const sellPrice = center * (1 + offset);
256
- // Bounds check — skip levels outside ratio range
257
- if (buyPrice < minBound || sellPrice > maxBound)
258
- continue;
259
- buys.push({ level: k, price: buyPrice, filledBar: -1 });
260
- sells.push({ level: k, price: sellPrice, filledBar: -1 });
261
- }
262
- // Size allocation — index 0 = closest to center
263
- const buySizes = allocateFundsByWeights(capitalPerSide, buys.length, weightFactor, incrementPct);
264
- const sellSizes = allocateFundsByWeights(capitalPerSide, sells.length, weightFactor, incrementPct);
265
- buys.forEach((o, i) => { o.size = buySizes[i] || 0; });
266
- sells.forEach((o, i) => { o.size = sellSizes[i] || 0; });
267
- return { buys, sells };
268
- }
269
- function closeFilledInventoryAtPrice(openBuys, openSells, exitPrice, feeRoundtripPct) {
270
- if (!Number.isFinite(exitPrice) || exitPrice <= 0) {
271
- return { grossUnits: 0, profitUnits: 0, closedOrders: 0 };
272
- }
273
- let grossUnits = 0;
274
- let profitUnits = 0;
275
- let closedOrders = 0;
276
- for (const order of openBuys.values()) {
277
- if (!order?.filled || !Number.isFinite(order.price) || order.price <= 0)
278
- continue;
279
- if (!Number.isFinite(order.size) || order.size <= 0)
280
- continue;
281
- const grossPct = (exitPrice / order.price - 1) * 100;
282
- const netPct = grossPct - feeRoundtripPct;
283
- grossUnits += order.size * (grossPct / 100);
284
- profitUnits += order.size * (netPct / 100);
285
- closedOrders++;
286
- }
287
- for (const order of openSells.values()) {
288
- if (!order?.filled || !Number.isFinite(order.price) || order.price <= 0)
289
- continue;
290
- if (!Number.isFinite(order.size) || order.size <= 0)
291
- continue;
292
- const grossPct = (order.price / exitPrice - 1) * 100;
293
- const netPct = grossPct - feeRoundtripPct;
294
- grossUnits += order.size * (grossPct / 100);
295
- profitUnits += order.size * (netPct / 100);
296
- closedOrders++;
297
- }
298
- return { grossUnits, profitUnits, closedOrders };
299
- }
300
- function countCancelableOrders(openBuys, openSells) {
301
- let count = 0;
302
- for (const order of openBuys.values()) {
303
- if (!order?.filled)
304
- count++;
305
- }
306
- for (const order of openSells.values()) {
307
- if (!order?.filled)
308
- count++;
309
- }
310
- return count;
311
- }
312
- function simulatePersistentGrid(candles, amaValues, params, weightName, weightFactor) {
313
- const { spreadPct, incrementPct, maxMinRatio, maxOrders, feeRoundtripPct, capital, repositionThreshold, btsCreateFee, btsCancelFee, makerCreateFactor, txFeePrice } = params;
314
- const skip = Math.max(20, Math.floor(candles.length * 0.1));
315
- const capitalPerSide = capital;
316
- // State
317
- let gridCenter = amaValues[skip];
318
- let grid = buildGrid(gridCenter, params, capitalPerSide, weightFactor);
319
- let lastRepositionBar = skip;
320
- // Open orders: maps level -> { price, size, bar, side }
321
- const openBuys = new Map();
322
- const openSells = new Map();
323
- // Place initial orders
324
- for (const o of grid.buys)
325
- openBuys.set(o.level, { price: o.price, size: o.size, bar: skip });
326
- for (const o of grid.sells)
327
- openSells.set(o.level, { price: o.price, size: o.size, bar: skip });
328
- let matchedPairs = 0;
329
- let totalProfitUnits = 0; // profit in capital units (size * netPct)
330
- let totalGrossUnits = 0;
331
- let touchedOrders = 0;
332
- let canceledOnReposition = 0;
333
- let repositionCount = 0;
334
- let peakOpenOrders = 0;
335
- let imbalanceSum = 0;
336
- let imbalanceSamples = 0;
337
- let matchedOpenDurationBars = 0;
338
- let gridAgeSumBars = 0;
339
- let maxGridAgeBars = 0;
340
- let centerDriftSumPct = 0;
341
- let maxCenterDriftPct = 0;
342
- let nearThresholdBars = 0;
343
- let triggerDriftSumPct = 0;
344
- let runningProfit = 0;
345
- let peakEquityProfit = 0;
346
- let maxDrawdown = 0;
347
- // Track inventory risk: net exposure from filled-but-unmatched orders
348
- let inventoryExposure = 0; // positive = long (bought), negative = short (sold)
349
- let maxInventoryExposure = 0;
350
- const liveBars = candles.length - skip - 1;
351
- const ordersPerSide = grid.buys.length; // actual orders placed per side (clipped by ratio)
352
- const makerCreateFeeBts = btsCreateFee * makerCreateFactor;
353
- const newOrdersPerReposition = ordersPerSide * 2;
354
- for (let i = skip + 1; i < candles.length; i++) {
355
- const ama = amaValues[i];
356
- const hi = candles[i].high;
357
- const lo = candles[i].low;
358
- const gridAgeBars = i - lastRepositionBar;
359
- // ── Reposition check: AMA drifted too far from grid center ──────
360
- const drift = Math.abs(ama - gridCenter) / gridCenter;
361
- const driftPct = drift * 100;
362
- centerDriftSumPct += driftPct;
363
- if (driftPct > maxCenterDriftPct)
364
- maxCenterDriftPct = driftPct;
365
- gridAgeSumBars += gridAgeBars;
366
- if (gridAgeBars > maxGridAgeBars)
367
- maxGridAgeBars = gridAgeBars;
368
- if (drift >= repositionThreshold * 0.5)
369
- nearThresholdBars++;
370
- if (drift >= repositionThreshold) {
371
- triggerDriftSumPct += driftPct;
372
- canceledOnReposition += countCancelableOrders(openBuys, openSells);
373
- repositionCount++;
374
- const exitPrice = Number.isFinite(ama) && ama > 0 ? ama : candles[i].close;
375
- const forcedClose = closeFilledInventoryAtPrice(openBuys, openSells, exitPrice, feeRoundtripPct);
376
- totalGrossUnits += forcedClose.grossUnits;
377
- totalProfitUnits += forcedClose.profitUnits;
378
- runningProfit += forcedClose.profitUnits;
379
- // Unmatched inventory is realized on reposition (position closed at market)
380
- inventoryExposure = 0;
381
- openBuys.clear();
382
- openSells.clear();
383
- // Re-center grid
384
- gridCenter = ama;
385
- grid = buildGrid(gridCenter, params, capitalPerSide, weightFactor);
386
- lastRepositionBar = i;
387
- for (const o of grid.buys)
388
- openBuys.set(o.level, { price: o.price, size: o.size, bar: i });
389
- for (const o of grid.sells)
390
- openSells.set(o.level, { price: o.price, size: o.size, bar: i });
391
- }
392
- // ── Track imbalance & peak ──────────────────────────────────────
393
- const currentOpen = openBuys.size + openSells.size;
394
- if (currentOpen > peakOpenOrders)
395
- peakOpenOrders = currentOpen;
396
- imbalanceSum += Math.abs(openBuys.size - openSells.size);
397
- imbalanceSamples++;
398
- // ── Check fills on PERSISTENT orders (fixed chain prices) ───────
399
- // Only check UNFILLED orders (skip already-filled pending match)
400
- const filledBuysThisBar = [];
401
- const filledSellsThisBar = [];
402
- for (const [lvl, order] of openBuys) {
403
- if (!order.filled && lo <= order.price) {
404
- filledBuysThisBar.push({ lvl, order });
405
- }
406
- }
407
- for (const [lvl, order] of openSells) {
408
- if (!order.filled && hi >= order.price) {
409
- filledSellsThisBar.push({ lvl, order });
410
- }
411
- }
412
- // Process buy fills
413
- for (const fb of filledBuysThisBar) {
414
- touchedOrders++;
415
- inventoryExposure += fb.order.size; // bought → long exposure
416
- // Mark as filled, waiting for paired sell at same level
417
- openBuys.set(fb.lvl, { ...fb.order, filled: true, filledBar: i, side: 'buy' });
418
- }
419
- // Process sell fills
420
- for (const fs of filledSellsThisBar) {
421
- touchedOrders++;
422
- inventoryExposure -= fs.order.size; // sold → short exposure
423
- // Mark as filled, waiting for paired buy at same level
424
- openSells.set(fs.lvl, { ...fs.order, filled: true, filledBar: i, side: 'sell' });
425
- }
426
- // Match completed pairs: both buy AND sell at same level are filled
427
- for (let k = 1; k <= maxOrders; k++) {
428
- const buyEntry = openBuys.get(k);
429
- const sellEntry = openSells.get(k);
430
- if (!buyEntry?.filled || !sellEntry?.filled)
431
- continue;
432
- // Matched pair!
433
- openBuys.delete(k);
434
- openSells.delete(k);
435
- matchedPairs++;
436
- const duration = Math.abs(sellEntry.filledBar - buyEntry.filledBar);
437
- matchedOpenDurationBars += duration;
438
- const avgSize = (buyEntry.size + sellEntry.size) / 2;
439
- const pairGrossPct = (sellEntry.price / buyEntry.price - 1) * 100;
440
- const pairNetPct = pairGrossPct - feeRoundtripPct;
441
- const profitUnits = avgSize * (pairNetPct / 100);
442
- totalGrossUnits += avgSize * (pairGrossPct / 100);
443
- totalProfitUnits += profitUnits;
444
- runningProfit += profitUnits;
445
- }
446
- // Track max inventory exposure
447
- const absExposure = Math.abs(inventoryExposure);
448
- if (absExposure > maxInventoryExposure)
449
- maxInventoryExposure = absExposure;
450
- // ── Drawdown tracking ───────────────────────────────────────────
451
- const markPrice = Number.isFinite(candles[i].close) && candles[i].close > 0
452
- ? candles[i].close
453
- : ((Number.isFinite(ama) && ama > 0) ? ama : gridCenter);
454
- const unrealized = closeFilledInventoryAtPrice(openBuys, openSells, markPrice, feeRoundtripPct).profitUnits;
455
- const equityProfit = runningProfit + unrealized;
456
- if (equityProfit > peakEquityProfit)
457
- peakEquityProfit = equityProfit;
458
- const dd = peakEquityProfit - equityProfit;
459
- if (dd > maxDrawdown)
460
- maxDrawdown = dd;
461
- }
462
- const fillEfficiency = touchedOrders > 0 ? (matchedPairs / touchedOrders) * 100 : 0;
463
- const pairsPerDay = liveBars > 0 ? matchedPairs / (liveBars / 24) : 0;
464
- const avgOpenDurationBars = matchedPairs > 0 ? matchedOpenDurationBars / matchedPairs : 0;
465
- const avgImbalance = imbalanceSamples > 0 ? imbalanceSum / imbalanceSamples : 0;
466
- const avgProfitPerPair = matchedPairs > 0 ? totalProfitUnits / matchedPairs : 0;
467
- const profitPerCapital = capital > 0 ? totalProfitUnits / (capital * 2) : 0; // total capital = 2 sides
468
- const maxDrawdownPct = capital > 0 ? (maxDrawdown / (capital * 2)) * 100 : 0;
469
- const avgGridAgeBars = liveBars > 0 ? gridAgeSumBars / liveBars : 0;
470
- const avgCenterDriftPct = liveBars > 0 ? centerDriftSumPct / liveBars : 0;
471
- const nearThresholdBarsPct = liveBars > 0 ? (nearThresholdBars / liveBars) * 100 : 0;
472
- const avgTriggerDriftPct = repositionCount > 0 ? triggerDriftSumPct / repositionCount : 0;
473
- const avgCancelOrdersPerReposition = repositionCount > 0 ? canceledOnReposition / repositionCount : 0;
474
- const estimatedFeePerRepositionBts = newOrdersPerReposition * makerCreateFeeBts + avgCancelOrdersPerReposition * btsCancelFee;
475
- const totalRepositionFeesBts = repositionCount * estimatedFeePerRepositionBts;
476
- const feePerDayBts = liveBars > 0 ? totalRepositionFeesBts / (liveBars / 24) : 0;
477
- const totalRepositionFeeUnits = totalRepositionFeesBts * txFeePrice;
478
- const netProfitUnits = totalProfitUnits - totalRepositionFeeUnits;
479
- const netProfitPerCapital = capital > 0 ? netProfitUnits / (capital * 2) : 0;
480
- // Score: profit per capital scaled by activity (log pairs to avoid pure frequency chasing)
481
- const activityBonus = matchedPairs > 0 ? Math.log10(matchedPairs) : null;
482
- const grossScore = activityBonus == null ? -Infinity : (profitPerCapital * 100 * activityBonus - maxDrawdownPct * 0.5);
483
- const netScore = activityBonus == null ? -Infinity : (netProfitPerCapital * 100 * activityBonus - maxDrawdownPct * 0.5);
484
- const score = netScore;
485
- return {
486
- weightName,
487
- spreadPct,
488
- incrementPct: incrementPct * 100, // store as %
489
- maxMinRatio,
490
- matchedPairs,
491
- touchedOrders,
492
- fillEfficiency,
493
- totalProfitUnits,
494
- totalGrossUnits,
495
- profitPerCapital,
496
- pairsPerDay,
497
- avgOpenDurationBars,
498
- avgProfitPerPair,
499
- peakOpenOrders,
500
- avgImbalance,
501
- canceledOnReposition,
502
- repositionCount,
503
- maxDrawdown,
504
- maxDrawdownPct,
505
- maxInventoryExposure,
506
- avgGridAgeBars,
507
- maxGridAgeBars,
508
- avgCenterDriftPct,
509
- maxCenterDriftPct,
510
- nearThresholdBarsPct,
511
- avgTriggerDriftPct,
512
- makerCreateFeeBts,
513
- btsCancelFee,
514
- avgCancelOrdersPerReposition,
515
- estimatedFeePerRepositionBts,
516
- totalRepositionFeesBts,
517
- feePerDayBts,
518
- netProfitUnits,
519
- netProfitPerCapital,
520
- ordersPerSide,
521
- grossScore,
522
- netScore,
523
- score,
524
- };
525
- }
526
- // ── Per-AMA sweep logic (runs in main thread or worker) ─────────────────────
527
- function sweepOneAma(strategy, candles, closes, weightEntries, cfg) {
528
- const amaValues = calculateAMA(closes, { erPeriod: strategy.er, fastPeriod: strategy.fast, slowPeriod: strategy.slow });
529
- let best = null;
530
- const top5 = [];
531
- const allSims = [];
532
- let evaluated = 0;
533
- const minSpreadFactor = Number.isFinite(cfg.minSpreadFactor) && cfg.minSpreadFactor > 0 ? cfg.minSpreadFactor : null;
534
- for (const spreadPct of cfg.spreadValues) {
535
- for (const incrementPctRaw of cfg.incrementValues) {
536
- if (spreadPct < cfg.feeRoundtripPct + 0.01)
537
- continue;
538
- if (minSpreadFactor != null && spreadPct < (incrementPctRaw * minSpreadFactor))
539
- continue;
540
- for (const maxMinRatio of cfg.ratioValues) {
541
- for (const [weightName, weightFactor] of weightEntries) {
542
- evaluated++;
543
- const sim = simulatePersistentGrid(candles, amaValues, {
544
- spreadPct,
545
- incrementPct: incrementPctRaw / 100,
546
- maxMinRatio,
547
- maxOrders: cfg.maxOrders,
548
- feeRoundtripPct: cfg.feeRoundtripPct,
549
- capital: cfg.capital,
550
- repositionThreshold: cfg.repositionPct / 100,
551
- btsCreateFee: cfg.btsCreateFee,
552
- btsCancelFee: cfg.btsCancelFee,
553
- makerCreateFactor: cfg.makerCreateFactor,
554
- txFeePrice: cfg.txFeePrice,
555
- }, weightName, weightFactor);
556
- if (!best || sim.score > best.score)
557
- best = sim;
558
- if (sim.matchedPairs > 0) {
559
- const t5key = `${sim.spreadPct}|${sim.incrementPct}|${sim.maxMinRatio}|${sim.weightName}`;
560
- const existing = top5.findIndex((t) => `${t.spreadPct}|${t.incrementPct}|${t.maxMinRatio}|${t.weightName}` === t5key);
561
- if (existing < 0) {
562
- top5.push(sim);
563
- top5.sort((a, b) => b.score - a.score);
564
- if (top5.length > 5)
565
- top5.length = 5;
566
- }
567
- allSims.push(sim);
568
- }
569
- }
570
- }
571
- }
572
- }
573
- return { strategy, best, top5, allSims, evaluated };
574
- }
575
- // ── Worker thread handler ───────────────────────────────────────────────────
576
- if (!isMainThread) {
577
- const { strategy, candles, closes, weightEntries, cfg } = workerData;
578
- const result = sweepOneAma(strategy, candles, closes, weightEntries, cfg);
579
- parentPort.postMessage(result);
580
- process.exit(0);
581
- }
582
- // ── Parallel dispatch (main thread) ─────────────────────────────────────────
583
- function runParallel(strategies, candles, closes, weightEntries, cfg) {
584
- const numCpus = Math.min(os.cpus().length, strategies.length);
585
- console.log(` Workers: ${numCpus} threads (${os.cpus().length} CPUs available)\n`);
586
- return Promise.all(strategies.map((strategy) => {
587
- return new Promise((resolve, reject) => {
588
- const worker = new Worker(__filename, {
589
- workerData: { strategy, candles, closes, weightEntries, cfg },
590
- });
591
- worker.on('message', resolve);
592
- worker.on('error', reject);
593
- worker.on('exit', (code) => {
594
- if (code !== 0)
595
- reject(new Error(`Worker exited with code ${code}`));
596
- });
597
- });
598
- }));
599
- }
600
- // ── Main ────────────────────────────────────────────────────────────────────
601
- async function run() {
602
- const cfg = parseArgs();
603
- const loaded = loadLpData(cfg.dataPath);
604
- const candles = loaded.candles;
605
- const closes = candles.map((c) => c.close);
606
- const strategies = loadAmaStrategies(cfg.resultsPath);
607
- const weightEntries = Object.entries(WEIGHT_PROFILES);
608
- const totalCombos = cfg.spreadValues.length * cfg.incrementValues.length *
609
- cfg.ratioValues.length * weightEntries.length;
610
- console.log('================================================================================');
611
- console.log(' AMA SWEEP BACKTEST — persistent grid + weight profiles');
612
- console.log('================================================================================');
613
- console.log(` Data: ${path.basename(cfg.dataPath)} (${candles.length} candles, ~${(candles.length / 24).toFixed(0)} days)`);
614
- console.log(` AMAs: ${strategies.map((s) => s.id).join(', ')}`);
615
- console.log(` Weights: ${weightEntries.map(([n, w]) => `${n}(${w})`).join(', ')}`);
616
- console.log(` Spread: ${cfg.spreadValues[0]}..${cfg.spreadValues[cfg.spreadValues.length - 1]}% (${cfg.spreadValues.length})`);
617
- console.log(` Increment: ${cfg.incrementValues[0]}..${cfg.incrementValues[cfg.incrementValues.length - 1]}% (${cfg.incrementValues.length})`);
618
- console.log(` Ratio: ${cfg.ratioValues[0]}..${cfg.ratioValues[cfg.ratioValues.length - 1]} (${cfg.ratioValues.length})`);
619
- console.log(` Max orders: ${cfg.maxOrders}/side (actual count from ratio+increment) | Capital: ${cfg.capital}/side | Fee: ${cfg.feeRoundtripPct}%`);
620
- console.log(` Spread floor: > fee (${cfg.feeRoundtripPct}%)`);
621
- console.log(` Reposition: ${cfg.repositionPct}% AMA drift from grid center`);
622
- console.log(` Tx model: create=${fmt(cfg.btsCreateFee, 5)} BTS, cancel=${fmt(cfg.btsCancelFee, 5)} BTS, maker=${fmt(cfg.makerCreateFactor * 100, 1)}%, 1 BTS=${fmt(cfg.txFeePrice, 2)} units`);
623
- console.log(` Combos/AMA: ${totalCombos} | Total: ${totalCombos * strategies.length}\n`);
624
- // ── Run AMA sweeps in parallel (one worker per AMA strategy) ──────
625
- const byAma = [];
626
- const allResults = [];
627
- const workerResults = await runParallel(strategies, candles, closes, weightEntries, cfg);
628
- for (const wr of workerResults) {
629
- byAma.push(wr);
630
- for (const sim of wr.allSims) {
631
- allResults.push({ strategy: wr.strategy, sim });
632
- }
633
- const b = wr.best;
634
- const bestLabel = b && b.matchedPairs > 0
635
- ? `score=${fmt(b.score, 1)} pairs=${b.matchedPairs} net/cap=${fmt(b.netProfitPerCapital * 100, 1)}% gross=${fmt(b.profitPerCapital * 100, 1)}%`
636
- : 'no fills';
637
- process.stdout.write(` ${wr.strategy.id} (ER=${wr.strategy.er}, F=${wr.strategy.fast}, S=${wr.strategy.slow}): ${wr.evaluated} combos, ${bestLabel}\n`);
638
- }
639
- // ── Per-AMA best ────────────────────────────────────────────────────────
640
- console.log('\n================================================================================');
641
- console.log(' BEST PARAMS PER AMA');
642
- console.log('================================================================================');
643
- console.log('AMA | wt | spr% | inc% | ratio | nOrd | pairs | net/cap | gross/cap | drift | fee/d | score');
644
- console.log('------+-------+-------+-------+-------+------+--------+---------+-----------+-------+-------+------');
645
- for (const row of byAma) {
646
- const b = row.best;
647
- if (!b || b.matchedPairs === 0) {
648
- console.log(`${row.strategy.id.padEnd(5)} | (no fills)`);
649
- continue;
650
- }
651
- console.log(`${row.strategy.id.padEnd(5)} | ` +
652
- `${b.weightName.padEnd(5)} | ` +
653
- `${fmt(b.spreadPct, 1).padStart(5)} | ` +
654
- `${fmt(b.incrementPct, 1).padStart(5)} | ` +
655
- `${fmt(b.maxMinRatio, 2).padStart(5)} | ` +
656
- `${String(b.ordersPerSide).padStart(4)} | ` +
657
- `${String(b.matchedPairs).padStart(6)} | ` +
658
- `${fmt(b.netProfitPerCapital * 100, 2).padStart(7)}% | ` +
659
- `${fmt(b.profitPerCapital * 100, 2).padStart(10)}% | ` +
660
- `${fmt(b.avgCenterDriftPct, 2).padStart(5)}% | ` +
661
- `${fmt(b.feePerDayBts, 2).padStart(5)} | ` +
662
- `${fmt(b.score, 1).padStart(6)}`);
663
- }
664
- // ── Top 5 per AMA ───────────────────────────────────────────────────────
665
- for (const row of byAma) {
666
- if (row.top5.length === 0)
667
- continue;
668
- console.log(`\n ${row.strategy.id} — Top 5:`);
669
- console.log(' # | wt | spr% | inc% | ratio | nOrd | pairs | net/cap | drift | gAge | fee/d | score');
670
- console.log(' --+-------+-------+-------+-------+------+--------+---------+-------+------+-------+------');
671
- row.top5.forEach((b, idx) => {
672
- console.log(` ${idx + 1} | ` +
673
- `${b.weightName.padEnd(5)} | ` +
674
- `${fmt(b.spreadPct, 1).padStart(5)} | ` +
675
- `${fmt(b.incrementPct, 1).padStart(5)} | ` +
676
- `${fmt(b.maxMinRatio, 2).padStart(5)} | ` +
677
- `${String(b.ordersPerSide).padStart(4)} | ` +
678
- `${String(b.matchedPairs).padStart(6)} | ` +
679
- `${fmt(b.netProfitPerCapital * 100, 2).padStart(7)}% | ` +
680
- `${fmt(b.avgCenterDriftPct, 2).padStart(5)}% | ` +
681
- `${fmt(b.avgGridAgeBars, 0).padStart(4)} | ` +
682
- `${fmt(b.feePerDayBts, 2).padStart(5)} | ` +
683
- `${fmt(b.score, 1).padStart(6)}`);
684
- });
685
- }
686
- // ── Global ranking (deduplicated) ───────────────────────────────────────
687
- allResults.sort((a, b) => b.sim.score - a.sim.score);
688
- const seen = new Set();
689
- const deduped = [];
690
- for (const r of allResults) {
691
- const key = `${r.strategy.id}|${r.sim.spreadPct}|${r.sim.incrementPct}|${r.sim.maxMinRatio}|${r.sim.weightName}`;
692
- if (seen.has(key))
693
- continue;
694
- seen.add(key);
695
- deduped.push(r);
696
- }
697
- if (deduped.length === 0) {
698
- console.log('\n NO CONFIGURATIONS PRODUCED ANY MATCHED PAIRS.');
699
- return;
700
- }
701
- const topN = Math.min(cfg.topN, deduped.length);
702
- console.log(`\n================================================================================`);
703
- console.log(` GLOBAL TOP ${topN}`);
704
- console.log('================================================================================');
705
- console.log('# | AMA | wt | spr% | inc% | ratio | nOrd | pairs | net/cap | drift | fee/d | score');
706
- console.log('---+-------+-------+-------+-------+-------+------+--------+---------+-------+-------+------');
707
- for (let i = 0; i < topN; i++) {
708
- const { strategy, sim } = deduped[i];
709
- console.log(`${String(i + 1).padStart(2)} | ` +
710
- `${strategy.id.padEnd(5)} | ` +
711
- `${sim.weightName.padEnd(5)} | ` +
712
- `${fmt(sim.spreadPct, 1).padStart(5)} | ` +
713
- `${fmt(sim.incrementPct, 1).padStart(5)} | ` +
714
- `${fmt(sim.maxMinRatio, 2).padStart(5)} | ` +
715
- `${String(sim.ordersPerSide).padStart(4)} | ` +
716
- `${String(sim.matchedPairs).padStart(6)} | ` +
717
- `${fmt(sim.netProfitPerCapital * 100, 2).padStart(7)}% | ` +
718
- `${fmt(sim.avgCenterDriftPct, 2).padStart(5)}% | ` +
719
- `${fmt(sim.feePerDayBts, 2).padStart(5)} | ` +
720
- `${fmt(sim.score, 1).padStart(6)}`);
721
- }
722
- // ── Winner ──────────────────────────────────────────────────────────────
723
- const winner = deduped[0];
724
- console.log(`\n================================================================================`);
725
- console.log(` WINNER`);
726
- console.log('================================================================================');
727
- console.log(` AMA: ${winner.strategy.id} (ER=${winner.strategy.er}, Fast=${winner.strategy.fast}, Slow=${winner.strategy.slow})`);
728
- console.log(` Weight: ${winner.sim.weightName} (${WEIGHT_PROFILES[winner.sim.weightName]})`);
729
- console.log(` Spread: ${fmt(winner.sim.spreadPct, 1)}%`);
730
- console.log(` Increment: ${fmt(winner.sim.incrementPct, 1)}%`);
731
- console.log(` Ratio: ${fmt(winner.sim.maxMinRatio, 1)}x`);
732
- console.log(` Pairs: ${winner.sim.matchedPairs} (${fmt(winner.sim.pairsPerDay, 2)}/day)`);
733
- console.log(` Fill eff: ${fmt(winner.sim.fillEfficiency, 1)}%`);
734
- console.log(` Profit/cap: gross ${fmt(winner.sim.profitPerCapital * 100, 2)}% | net ${fmt(winner.sim.netProfitPerCapital * 100, 2)}%`);
735
- console.log(` Net profit: ${fmt(winner.sim.netProfitUnits, 0)} units after ${fmt(winner.sim.totalRepositionFeesBts, 1)} BTS reposition fees`);
736
- console.log(` Avg/pair: ${fmt(winner.sim.avgProfitPerPair, 2)} units`);
737
- console.log(` Max DD: ${fmt(winner.sim.maxDrawdownPct, 2)}%`);
738
- console.log(` Repositions: ${winner.sim.repositionCount}`);
739
- console.log(` Grid age: avg ${fmt(winner.sim.avgGridAgeBars, 1)} bars | max ${fmt(winner.sim.maxGridAgeBars, 0)} bars`);
740
- console.log(` Drift: avg ${fmt(winner.sim.avgCenterDriftPct, 2)}% | max ${fmt(winner.sim.maxCenterDriftPct, 2)}% | near-threshold ${fmt(winner.sim.nearThresholdBarsPct, 1)}%`);
741
- console.log(` Tx burn: ${fmt(winner.sim.estimatedFeePerRepositionBts, 4)} BTS/reposition | ${fmt(winner.sim.feePerDayBts, 2)} BTS/day`);
742
- console.log(` Score: ${fmt(winner.sim.score, 2)}`);
743
- // ── Save JSON ───────────────────────────────────────────────────────────
744
- const outName = `ama_sweep_results_${path.basename(cfg.dataPath, '.json')}.json`;
745
- const outPath = path.join(__dirname, outName);
746
- writeJSON(outPath, {
747
- meta: {
748
- generatedAt: new Date().toISOString(),
749
- dataPath: path.relative(process.cwd(), cfg.dataPath),
750
- resultsPath: path.relative(process.cwd(), cfg.resultsPath),
751
- candles: candles.length,
752
- days: candles.length / 24,
753
- maxOrders: cfg.maxOrders,
754
- capitalPerSide: cfg.capital,
755
- feeRoundtripPct: cfg.feeRoundtripPct,
756
- repositionPct: cfg.repositionPct,
757
- btsCreateFee: cfg.btsCreateFee,
758
- btsCancelFee: cfg.btsCancelFee,
759
- makerCreateFactor: cfg.makerCreateFactor,
760
- txFeePrice: cfg.txFeePrice,
761
- weightProfiles: WEIGHT_PROFILES,
762
- search: {
763
- spreadValues: cfg.spreadValues,
764
- incrementValues: cfg.incrementValues,
765
- ratioValues: cfg.ratioValues,
766
- minSpreadFactor: cfg.minSpreadFactor,
767
- combosPerAma: totalCombos,
768
- totalCombos: totalCombos * strategies.length,
769
- },
770
- scoring: 'netProfitPerCapital * 100 * log10(max(1, matchedPairs)) - maxDrawdownPct * 0.5',
771
- },
772
- strategies,
773
- perAma: byAma.map((row) => ({
774
- strategy: row.strategy,
775
- evaluated: row.evaluated,
776
- best: row.best,
777
- top5: row.top5,
778
- })),
779
- globalTop: deduped.slice(0, Math.max(cfg.topN, 20)).map(({ strategy, sim }) => ({
780
- ama: strategy.id,
781
- amaParams: { er: strategy.er, fast: strategy.fast, slow: strategy.slow },
782
- ...sim,
783
- })),
784
- winner: {
785
- ama: winner.strategy.id,
786
- amaParams: { er: winner.strategy.er, fast: winner.strategy.fast, slow: winner.strategy.slow },
787
- ...winner.sim,
788
- },
789
- });
790
- console.log(`\nSaved: ${path.relative(process.cwd(), outPath)}`);
791
- }
792
- if (require.main === module) {
793
- run().catch((err) => { console.error(err); process.exit(1); });
794
- }
795
- module.exports = {
796
- WEIGHT_PROFILES,
797
- allocateFundsByWeights,
798
- buildGrid,
799
- closeFilledInventoryAtPrice,
800
- countCancelableOrders,
801
- simulatePersistentGrid,
802
- sweepOneAma,
803
- };
804
- //# sourceMappingURL=backtest_ama_sweep.js.map