@reefclaw/connect 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (396) hide show
  1. package/assets/bridge/gateway/event-parser.d.ts +6 -1
  2. package/assets/bridge/gateway/event-parser.js +19 -2
  3. package/assets/bridge/gateway/heartbeat-cron.d.ts +27 -0
  4. package/assets/bridge/gateway/heartbeat-cron.js +85 -0
  5. package/assets/bridge/gateway/poller.d.ts +1 -0
  6. package/assets/bridge/gateway/poller.js +14 -2
  7. package/assets/bridge/providers/gateway.d.ts +24 -2
  8. package/assets/bridge/providers/gateway.js +124 -25
  9. package/assets/bridge/setup.js +6 -51
  10. package/assets/shared/signals/conditions/registry.js +11 -2
  11. package/assets/shared/signals/strategy-adapter.js +17 -7
  12. package/assets/skill/SKILL.md +2 -0
  13. package/dist/deps.js +2 -2
  14. package/dist/plugin.js +35 -7
  15. package/package.json +1 -1
  16. package/assets/plugin/audit/mode-transition-audit.d.ts +0 -11
  17. package/assets/plugin/audit/mode-transition-audit.js +0 -29
  18. package/assets/plugin/balance-utils.d.ts +0 -36
  19. package/assets/plugin/balance-utils.js +0 -98
  20. package/assets/plugin/ccxt/binance-ban-gate.d.ts +0 -47
  21. package/assets/plugin/ccxt/binance-ban-gate.js +0 -420
  22. package/assets/plugin/ccxt/binance-private.d.ts +0 -346
  23. package/assets/plugin/ccxt/binance-private.js +0 -1525
  24. package/assets/plugin/ccxt/binance-public.d.ts +0 -34
  25. package/assets/plugin/ccxt/binance-public.js +0 -180
  26. package/assets/plugin/ccxt/intel-public.d.ts +0 -25
  27. package/assets/plugin/ccxt/intel-public.js +0 -80
  28. package/assets/plugin/ccxt/public-market-data-api.d.ts +0 -12
  29. package/assets/plugin/ccxt/public-market-data-api.js +0 -9
  30. package/assets/plugin/config/agent-config-client.d.ts +0 -77
  31. package/assets/plugin/config/agent-config-client.js +0 -188
  32. package/assets/plugin/config/agent-config-poller.d.ts +0 -32
  33. package/assets/plugin/config/agent-config-poller.js +0 -101
  34. package/assets/plugin/config/brackets-config.d.ts +0 -22
  35. package/assets/plugin/config/brackets-config.js +0 -58
  36. package/assets/plugin/config/entitlement-gate.d.ts +0 -51
  37. package/assets/plugin/config/entitlement-gate.js +0 -137
  38. package/assets/plugin/config/gate-store.d.ts +0 -18
  39. package/assets/plugin/config/gate-store.js +0 -61
  40. package/assets/plugin/config/plugin-config-io.d.ts +0 -215
  41. package/assets/plugin/config/plugin-config-io.js +0 -111
  42. package/assets/plugin/config/position-review-config.d.ts +0 -35
  43. package/assets/plugin/config/position-review-config.js +0 -105
  44. package/assets/plugin/config/tool-gate.d.ts +0 -53
  45. package/assets/plugin/config/tool-gate.js +0 -128
  46. package/assets/plugin/config/user-data-stream-config.d.ts +0 -89
  47. package/assets/plugin/config/user-data-stream-config.js +0 -239
  48. package/assets/plugin/connector-supervisor.d.ts +0 -36
  49. package/assets/plugin/connector-supervisor.js +0 -149
  50. package/assets/plugin/exchange-adapter.d.ts +0 -65
  51. package/assets/plugin/exchange-adapter.js +0 -4
  52. package/assets/plugin/index.d.ts +0 -30
  53. package/assets/plugin/index.js +0 -2678
  54. package/assets/plugin/ingest/pending-entry-metadata.d.ts +0 -74
  55. package/assets/plugin/ingest/pending-entry-metadata.js +0 -236
  56. package/assets/plugin/ingest/position-auto-capture.d.ts +0 -103
  57. package/assets/plugin/ingest/position-auto-capture.js +0 -411
  58. package/assets/plugin/ingest/position-decisions-client.d.ts +0 -322
  59. package/assets/plugin/ingest/position-decisions-client.js +0 -296
  60. package/assets/plugin/ingest/readiness-reporter.d.ts +0 -42
  61. package/assets/plugin/ingest/readiness-reporter.js +0 -163
  62. package/assets/plugin/ingest/reconcile-db-vs-exchange.d.ts +0 -13
  63. package/assets/plugin/ingest/reconcile-db-vs-exchange.js +0 -114
  64. package/assets/plugin/ingest/reconciler-cleanup.d.ts +0 -37
  65. package/assets/plugin/ingest/reconciler-cleanup.js +0 -147
  66. package/assets/plugin/ingest/rest-gap-filler.d.ts +0 -191
  67. package/assets/plugin/ingest/rest-gap-filler.js +0 -565
  68. package/assets/plugin/ingest/touched-symbols-store.d.ts +0 -25
  69. package/assets/plugin/ingest/touched-symbols-store.js +0 -96
  70. package/assets/plugin/ingest/trade-store-client.d.ts +0 -40
  71. package/assets/plugin/ingest/trade-store-client.js +0 -125
  72. package/assets/plugin/ingest/ws-ingest.d.ts +0 -43
  73. package/assets/plugin/ingest/ws-ingest.js +0 -126
  74. package/assets/plugin/learning/setup-family.d.ts +0 -21
  75. package/assets/plugin/learning/setup-family.js +0 -103
  76. package/assets/plugin/lifecycle/install-signal-handlers.d.ts +0 -33
  77. package/assets/plugin/lifecycle/install-signal-handlers.js +0 -112
  78. package/assets/plugin/lifecycle/shutdown-coordinator.d.ts +0 -43
  79. package/assets/plugin/lifecycle/shutdown-coordinator.js +0 -131
  80. package/assets/plugin/lifecycle/trading-operation-lock.d.ts +0 -17
  81. package/assets/plugin/lifecycle/trading-operation-lock.js +0 -14
  82. package/assets/plugin/live/bracket-id.d.ts +0 -26
  83. package/assets/plugin/live/bracket-id.js +0 -112
  84. package/assets/plugin/live/bracket-ledger.d.ts +0 -54
  85. package/assets/plugin/live/bracket-ledger.js +0 -267
  86. package/assets/plugin/live/bracket-manager.d.ts +0 -82
  87. package/assets/plugin/live/bracket-manager.js +0 -478
  88. package/assets/plugin/live/bracket-params.d.ts +0 -22
  89. package/assets/plugin/live/bracket-params.js +0 -124
  90. package/assets/plugin/live/bracket-reconciler.d.ts +0 -95
  91. package/assets/plugin/live/bracket-reconciler.js +0 -573
  92. package/assets/plugin/live/bracket-types.d.ts +0 -102
  93. package/assets/plugin/live/bracket-types.js +0 -8
  94. package/assets/plugin/live/deposit-tracker.d.ts +0 -62
  95. package/assets/plugin/live/deposit-tracker.js +0 -97
  96. package/assets/plugin/live/emergency-controls.d.ts +0 -32
  97. package/assets/plugin/live/emergency-controls.js +0 -226
  98. package/assets/plugin/live/exchange-errors.d.ts +0 -12
  99. package/assets/plugin/live/exchange-errors.js +0 -130
  100. package/assets/plugin/live/exchange-info-cache.d.ts +0 -37
  101. package/assets/plugin/live/exchange-info-cache.js +0 -134
  102. package/assets/plugin/live/fact-subscriber.d.ts +0 -78
  103. package/assets/plugin/live/fact-subscriber.js +0 -182
  104. package/assets/plugin/live/intent-journal.d.ts +0 -42
  105. package/assets/plugin/live/intent-journal.js +0 -122
  106. package/assets/plugin/live/listen-key-manager.d.ts +0 -70
  107. package/assets/plugin/live/listen-key-manager.js +0 -169
  108. package/assets/plugin/live/live-adapter.d.ts +0 -287
  109. package/assets/plugin/live/live-adapter.js +0 -1777
  110. package/assets/plugin/live/live-balance-enricher.d.ts +0 -32
  111. package/assets/plugin/live/live-balance-enricher.js +0 -104
  112. package/assets/plugin/live/live-bracket-api.d.ts +0 -13
  113. package/assets/plugin/live/live-bracket-api.js +0 -20
  114. package/assets/plugin/live/live-state-store.d.ts +0 -194
  115. package/assets/plugin/live/live-state-store.js +0 -450
  116. package/assets/plugin/live/local-signal-service.d.ts +0 -57
  117. package/assets/plugin/live/local-signal-service.js +0 -151
  118. package/assets/plugin/live/local-strategy-evaluator.d.ts +0 -62
  119. package/assets/plugin/live/local-strategy-evaluator.js +0 -131
  120. package/assets/plugin/live/microstructure-assembler.d.ts +0 -54
  121. package/assets/plugin/live/microstructure-assembler.js +0 -148
  122. package/assets/plugin/live/order-poller.d.ts +0 -29
  123. package/assets/plugin/live/order-poller.js +0 -125
  124. package/assets/plugin/live/position-state-store.d.ts +0 -83
  125. package/assets/plugin/live/position-state-store.js +0 -237
  126. package/assets/plugin/live/proposal-decision-listener.d.ts +0 -70
  127. package/assets/plugin/live/proposal-decision-listener.js +0 -292
  128. package/assets/plugin/live/proposal-manager.d.ts +0 -76
  129. package/assets/plugin/live/proposal-manager.js +0 -140
  130. package/assets/plugin/live/rate-limiter.d.ts +0 -47
  131. package/assets/plugin/live/rate-limiter.js +0 -159
  132. package/assets/plugin/live/reconciler.d.ts +0 -39
  133. package/assets/plugin/live/reconciler.js +0 -175
  134. package/assets/plugin/live/setup-buckets.d.ts +0 -7
  135. package/assets/plugin/live/setup-buckets.js +0 -33
  136. package/assets/plugin/live/slippage-tracker.d.ts +0 -45
  137. package/assets/plugin/live/slippage-tracker.js +0 -78
  138. package/assets/plugin/live/stop-watcher.d.ts +0 -60
  139. package/assets/plugin/live/stop-watcher.js +0 -215
  140. package/assets/plugin/live/user-data-active-probe.d.ts +0 -54
  141. package/assets/plugin/live/user-data-active-probe.js +0 -180
  142. package/assets/plugin/live/user-data-stream-controller.d.ts +0 -200
  143. package/assets/plugin/live/user-data-stream-controller.js +0 -579
  144. package/assets/plugin/live/user-data-stream-ws.d.ts +0 -22
  145. package/assets/plugin/live/user-data-stream-ws.js +0 -63
  146. package/assets/plugin/live/user-data-stream.d.ts +0 -243
  147. package/assets/plugin/live/user-data-stream.js +0 -704
  148. package/assets/plugin/logger.d.ts +0 -2
  149. package/assets/plugin/logger.js +0 -2
  150. package/assets/plugin/mfe.d.ts +0 -21
  151. package/assets/plugin/mfe.js +0 -68
  152. package/assets/plugin/onboarding/mode-ladder.d.ts +0 -1
  153. package/assets/plugin/onboarding/mode-ladder.js +0 -3
  154. package/assets/plugin/onboarding/runtime.d.ts +0 -84
  155. package/assets/plugin/onboarding/runtime.js +0 -173
  156. package/assets/plugin/openclaw.plugin.json +0 -92
  157. package/assets/plugin/paper-adapter.d.ts +0 -24
  158. package/assets/plugin/paper-adapter.js +0 -91
  159. package/assets/plugin/persistence/state-manager.d.ts +0 -66
  160. package/assets/plugin/persistence/state-manager.js +0 -222
  161. package/assets/plugin/pinned-plan.d.ts +0 -9
  162. package/assets/plugin/pinned-plan.js +0 -23
  163. package/assets/plugin/portfolio/wave9-admission.d.ts +0 -67
  164. package/assets/plugin/portfolio/wave9-admission.js +0 -262
  165. package/assets/plugin/portfolio/wave9-policy.d.ts +0 -36
  166. package/assets/plugin/portfolio/wave9-policy.js +0 -183
  167. package/assets/plugin/risk/pre-trade-check.d.ts +0 -38
  168. package/assets/plugin/risk/pre-trade-check.js +0 -345
  169. package/assets/plugin/risk/pre-trade-types.d.ts +0 -60
  170. package/assets/plugin/risk/pre-trade-types.js +0 -3
  171. package/assets/plugin/shadow/shadow-tracker.d.ts +0 -36
  172. package/assets/plugin/shadow/shadow-tracker.js +0 -151
  173. package/assets/plugin/shadow/types.d.ts +0 -42
  174. package/assets/plugin/shadow/types.js +0 -20
  175. package/assets/plugin/shared/indicators-extended.d.ts +0 -52
  176. package/assets/plugin/shared/indicators-extended.js +0 -291
  177. package/assets/plugin/shared/indicators.d.ts +0 -15
  178. package/assets/plugin/shared/indicators.js +0 -114
  179. package/assets/plugin/signals/conditions/registry.d.ts +0 -16
  180. package/assets/plugin/signals/conditions/registry.js +0 -1324
  181. package/assets/plugin/signals/conditions/types.d.ts +0 -1
  182. package/assets/plugin/signals/conditions/types.js +0 -4
  183. package/assets/plugin/signals/direction-rules.d.ts +0 -3
  184. package/assets/plugin/signals/direction-rules.js +0 -24
  185. package/assets/plugin/signals/entry-rules.d.ts +0 -6
  186. package/assets/plugin/signals/entry-rules.js +0 -33
  187. package/assets/plugin/signals/serialize-context.d.ts +0 -4
  188. package/assets/plugin/signals/serialize-context.js +0 -39
  189. package/assets/plugin/signals/stop-rules.d.ts +0 -3
  190. package/assets/plugin/signals/stop-rules.js +0 -48
  191. package/assets/plugin/signals/strategy-adapter.d.ts +0 -47
  192. package/assets/plugin/signals/strategy-adapter.js +0 -199
  193. package/assets/plugin/signals/types.d.ts +0 -1
  194. package/assets/plugin/signals/types.js +0 -8
  195. package/assets/plugin/simulator/exchange-simulator.d.ts +0 -93
  196. package/assets/plugin/simulator/exchange-simulator.js +0 -689
  197. package/assets/plugin/simulator/fill-engine.d.ts +0 -53
  198. package/assets/plugin/simulator/fill-engine.js +0 -280
  199. package/assets/plugin/simulator/paper-market-feed.d.ts +0 -26
  200. package/assets/plugin/simulator/paper-market-feed.js +0 -104
  201. package/assets/plugin/simulator/realistic-fills.d.ts +0 -59
  202. package/assets/plugin/simulator/realistic-fills.js +0 -175
  203. package/assets/plugin/simulator/types.d.ts +0 -224
  204. package/assets/plugin/simulator/types.js +0 -43
  205. package/assets/plugin/strategy/builtin-strategies.d.ts +0 -2
  206. package/assets/plugin/strategy/builtin-strategies.js +0 -113
  207. package/assets/plugin/strategy/condition-registry.d.ts +0 -3
  208. package/assets/plugin/strategy/condition-registry.js +0 -153
  209. package/assets/plugin/strategy/evaluator.d.ts +0 -70
  210. package/assets/plugin/strategy/evaluator.js +0 -98
  211. package/assets/plugin/tools/assessment-validation.d.ts +0 -120
  212. package/assets/plugin/tools/assessment-validation.js +0 -415
  213. package/assets/plugin/tools/attach-brackets.d.ts +0 -39
  214. package/assets/plugin/tools/attach-brackets.js +0 -399
  215. package/assets/plugin/tools/audit-bracket-protection.d.ts +0 -49
  216. package/assets/plugin/tools/audit-bracket-protection.js +0 -527
  217. package/assets/plugin/tools/cancel-all-orders.d.ts +0 -9
  218. package/assets/plugin/tools/cancel-all-orders.js +0 -8
  219. package/assets/plugin/tools/cancel-order.d.ts +0 -14
  220. package/assets/plugin/tools/cancel-order.js +0 -60
  221. package/assets/plugin/tools/check-position-health.d.ts +0 -46
  222. package/assets/plugin/tools/check-position-health.js +0 -194
  223. package/assets/plugin/tools/clear-exchange-credentials.d.ts +0 -24
  224. package/assets/plugin/tools/clear-exchange-credentials.js +0 -70
  225. package/assets/plugin/tools/close-position.d.ts +0 -45
  226. package/assets/plugin/tools/close-position.js +0 -722
  227. package/assets/plugin/tools/create-order.d.ts +0 -82
  228. package/assets/plugin/tools/create-order.js +0 -1516
  229. package/assets/plugin/tools/exit-gate.d.ts +0 -58
  230. package/assets/plugin/tools/exit-gate.js +0 -162
  231. package/assets/plugin/tools/fetch-balance.d.ts +0 -5
  232. package/assets/plugin/tools/fetch-balance.js +0 -4
  233. package/assets/plugin/tools/fetch-ohlcv.d.ts +0 -11
  234. package/assets/plugin/tools/fetch-ohlcv.js +0 -8
  235. package/assets/plugin/tools/fetch-open-orders.d.ts +0 -7
  236. package/assets/plugin/tools/fetch-open-orders.js +0 -4
  237. package/assets/plugin/tools/fetch-positions.d.ts +0 -7
  238. package/assets/plugin/tools/fetch-positions.js +0 -4
  239. package/assets/plugin/tools/fetch-ticker.d.ts +0 -11
  240. package/assets/plugin/tools/fetch-ticker.js +0 -5
  241. package/assets/plugin/tools/get-agent-profile.d.ts +0 -4
  242. package/assets/plugin/tools/get-agent-profile.js +0 -6
  243. package/assets/plugin/tools/get-analytics.d.ts +0 -6
  244. package/assets/plugin/tools/get-analytics.js +0 -7
  245. package/assets/plugin/tools/get-backtest.d.ts +0 -12
  246. package/assets/plugin/tools/get-backtest.js +0 -91
  247. package/assets/plugin/tools/get-basis.d.ts +0 -7
  248. package/assets/plugin/tools/get-basis.js +0 -7
  249. package/assets/plugin/tools/get-bracket-config.d.ts +0 -11
  250. package/assets/plugin/tools/get-bracket-config.js +0 -24
  251. package/assets/plugin/tools/get-cascade-risk.d.ts +0 -7
  252. package/assets/plugin/tools/get-cascade-risk.js +0 -8
  253. package/assets/plugin/tools/get-crypto-metrics.d.ts +0 -18
  254. package/assets/plugin/tools/get-crypto-metrics.js +0 -62
  255. package/assets/plugin/tools/get-cvd.d.ts +0 -6
  256. package/assets/plugin/tools/get-cvd.js +0 -6
  257. package/assets/plugin/tools/get-divergences.d.ts +0 -6
  258. package/assets/plugin/tools/get-divergences.js +0 -6
  259. package/assets/plugin/tools/get-funding-context.d.ts +0 -6
  260. package/assets/plugin/tools/get-funding-context.js +0 -16
  261. package/assets/plugin/tools/get-liquidation-levels.d.ts +0 -7
  262. package/assets/plugin/tools/get-liquidation-levels.js +0 -7
  263. package/assets/plugin/tools/get-liquidation-pulse.d.ts +0 -9
  264. package/assets/plugin/tools/get-liquidation-pulse.js +0 -22
  265. package/assets/plugin/tools/get-market-breadth.d.ts +0 -6
  266. package/assets/plugin/tools/get-market-breadth.js +0 -8
  267. package/assets/plugin/tools/get-market-intel.d.ts +0 -19
  268. package/assets/plugin/tools/get-market-intel.js +0 -116
  269. package/assets/plugin/tools/get-market-structure.d.ts +0 -47
  270. package/assets/plugin/tools/get-market-structure.js +0 -198
  271. package/assets/plugin/tools/get-my-mined-patterns.d.ts +0 -20
  272. package/assets/plugin/tools/get-my-mined-patterns.js +0 -61
  273. package/assets/plugin/tools/get-my-proposed-learnings.d.ts +0 -20
  274. package/assets/plugin/tools/get-my-proposed-learnings.js +0 -55
  275. package/assets/plugin/tools/get-my-recent-reviews.d.ts +0 -22
  276. package/assets/plugin/tools/get-my-recent-reviews.js +0 -66
  277. package/assets/plugin/tools/get-orderbook.d.ts +0 -21
  278. package/assets/plugin/tools/get-orderbook.js +0 -32
  279. package/assets/plugin/tools/get-pattern-scan.d.ts +0 -7
  280. package/assets/plugin/tools/get-pattern-scan.js +0 -8
  281. package/assets/plugin/tools/get-regime.d.ts +0 -6
  282. package/assets/plugin/tools/get-regime.js +0 -7
  283. package/assets/plugin/tools/get-relevant-learnings.d.ts +0 -21
  284. package/assets/plugin/tools/get-relevant-learnings.js +0 -65
  285. package/assets/plugin/tools/get-resting-liquidity.d.ts +0 -6
  286. package/assets/plugin/tools/get-resting-liquidity.js +0 -11
  287. package/assets/plugin/tools/get-risk-scenario.d.ts +0 -29
  288. package/assets/plugin/tools/get-risk-scenario.js +0 -47
  289. package/assets/plugin/tools/get-risk-summary.d.ts +0 -51
  290. package/assets/plugin/tools/get-risk-summary.js +0 -118
  291. package/assets/plugin/tools/get-sentiment.d.ts +0 -4
  292. package/assets/plugin/tools/get-sentiment.js +0 -6
  293. package/assets/plugin/tools/get-session-review.d.ts +0 -7
  294. package/assets/plugin/tools/get-session-review.js +0 -8
  295. package/assets/plugin/tools/get-setup-detail.d.ts +0 -7
  296. package/assets/plugin/tools/get-setup-detail.js +0 -311
  297. package/assets/plugin/tools/get-signals.d.ts +0 -15
  298. package/assets/plugin/tools/get-signals.js +0 -54
  299. package/assets/plugin/tools/get-sizing.d.ts +0 -6
  300. package/assets/plugin/tools/get-sizing.js +0 -6
  301. package/assets/plugin/tools/get-trade-feedback.d.ts +0 -7
  302. package/assets/plugin/tools/get-trade-feedback.js +0 -8
  303. package/assets/plugin/tools/get-trade-flow.d.ts +0 -7
  304. package/assets/plugin/tools/get-trade-flow.js +0 -7
  305. package/assets/plugin/tools/get-volume-analysis.d.ts +0 -21
  306. package/assets/plugin/tools/get-volume-analysis.js +0 -74
  307. package/assets/plugin/tools/get-volume-profile.d.ts +0 -7
  308. package/assets/plugin/tools/get-volume-profile.js +0 -7
  309. package/assets/plugin/tools/get-wave9-status.d.ts +0 -127
  310. package/assets/plugin/tools/get-wave9-status.js +0 -796
  311. package/assets/plugin/tools/helpers.d.ts +0 -26
  312. package/assets/plugin/tools/helpers.js +0 -39
  313. package/assets/plugin/tools/intel-api.d.ts +0 -34
  314. package/assets/plugin/tools/intel-api.js +0 -119
  315. package/assets/plugin/tools/intel-cache.d.ts +0 -25
  316. package/assets/plugin/tools/intel-cache.js +0 -148
  317. package/assets/plugin/tools/list-strategies.d.ts +0 -17
  318. package/assets/plugin/tools/list-strategies.js +0 -23
  319. package/assets/plugin/tools/modify-stop.d.ts +0 -21
  320. package/assets/plugin/tools/modify-stop.js +0 -120
  321. package/assets/plugin/tools/modify-target.d.ts +0 -21
  322. package/assets/plugin/tools/modify-target.js +0 -110
  323. package/assets/plugin/tools/propose-learning.d.ts +0 -22
  324. package/assets/plugin/tools/propose-learning.js +0 -65
  325. package/assets/plugin/tools/query-review-outcomes.d.ts +0 -30
  326. package/assets/plugin/tools/query-review-outcomes.js +0 -64
  327. package/assets/plugin/tools/query-trades.d.ts +0 -21
  328. package/assets/plugin/tools/query-trades.js +0 -37
  329. package/assets/plugin/tools/record-position-reviews.d.ts +0 -38
  330. package/assets/plugin/tools/record-position-reviews.js +0 -147
  331. package/assets/plugin/tools/save-strategy.d.ts +0 -16
  332. package/assets/plugin/tools/save-strategy.js +0 -46
  333. package/assets/plugin/tools/scan-pairs.d.ts +0 -18
  334. package/assets/plugin/tools/scan-pairs.js +0 -231
  335. package/assets/plugin/tools/score-setup.d.ts +0 -31
  336. package/assets/plugin/tools/score-setup.js +0 -268
  337. package/assets/plugin/tools/set-bracket-requirement.d.ts +0 -18
  338. package/assets/plugin/tools/set-bracket-requirement.js +0 -81
  339. package/assets/plugin/tools/set-exchange-credentials.d.ts +0 -25
  340. package/assets/plugin/tools/set-exchange-credentials.js +0 -80
  341. package/assets/plugin/tools/set-trading-mode.d.ts +0 -26
  342. package/assets/plugin/tools/set-trading-mode.js +0 -135
  343. package/assets/plugin/tools/test-exchange-credentials.d.ts +0 -16
  344. package/assets/plugin/tools/test-exchange-credentials.js +0 -100
  345. package/assets/plugin/tools/toggle-strategy.d.ts +0 -8
  346. package/assets/plugin/tools/toggle-strategy.js +0 -15
  347. package/assets/plugin/trading-params-cache.d.ts +0 -26
  348. package/assets/plugin/trading-params-cache.js +0 -52
  349. package/assets/plugin/types.d.ts +0 -134
  350. package/assets/plugin/types.js +0 -7
  351. package/assets/plugin/util/plugin-paths.d.ts +0 -3
  352. package/assets/plugin/util/plugin-paths.js +0 -15
  353. package/assets/plugin/venues/hyperliquid/hl-balance.d.ts +0 -116
  354. package/assets/plugin/venues/hyperliquid/hl-balance.js +0 -145
  355. package/assets/plugin/venues/hyperliquid/hl-brackets.d.ts +0 -102
  356. package/assets/plugin/venues/hyperliquid/hl-brackets.js +0 -172
  357. package/assets/plugin/venues/hyperliquid/hl-cloid.d.ts +0 -22
  358. package/assets/plugin/venues/hyperliquid/hl-cloid.js +0 -82
  359. package/assets/plugin/venues/hyperliquid/hl-info-cache.d.ts +0 -46
  360. package/assets/plugin/venues/hyperliquid/hl-info-cache.js +0 -125
  361. package/assets/plugin/venues/hyperliquid/hl-live-adapter.d.ts +0 -88
  362. package/assets/plugin/venues/hyperliquid/hl-live-adapter.js +0 -353
  363. package/assets/plugin/venues/hyperliquid/hl-precision.d.ts +0 -61
  364. package/assets/plugin/venues/hyperliquid/hl-precision.js +0 -176
  365. package/assets/plugin/venues/hyperliquid/hl-private.d.ts +0 -88
  366. package/assets/plugin/venues/hyperliquid/hl-private.js +0 -357
  367. package/assets/plugin/venues/hyperliquid/hl-public.d.ts +0 -79
  368. package/assets/plugin/venues/hyperliquid/hl-public.js +0 -429
  369. package/assets/plugin/venues/hyperliquid/hl-rate-gate.d.ts +0 -57
  370. package/assets/plugin/venues/hyperliquid/hl-rate-gate.js +0 -220
  371. package/assets/plugin/venues/hyperliquid/hl-user-stream.d.ts +0 -90
  372. package/assets/plugin/venues/hyperliquid/hl-user-stream.js +0 -220
  373. package/assets/plugin/venues/registry.d.ts +0 -38
  374. package/assets/plugin/venues/registry.js +0 -46
  375. package/assets/plugin/venues/symbols.d.ts +0 -43
  376. package/assets/plugin/venues/symbols.js +0 -107
  377. package/assets/plugin/wave9/live-account-capture.d.ts +0 -67
  378. package/assets/plugin/wave9/live-account-capture.js +0 -435
  379. package/assets/plugin/wave9/live-autonomous-protection.d.ts +0 -39
  380. package/assets/plugin/wave9/live-autonomous-protection.js +0 -112
  381. package/assets/plugin/wave9/live-durable-reconciliation-scheduler.d.ts +0 -33
  382. package/assets/plugin/wave9/live-durable-reconciliation-scheduler.js +0 -115
  383. package/assets/plugin/wave9/live-execution-ledger.d.ts +0 -107
  384. package/assets/plugin/wave9/live-execution-ledger.js +0 -498
  385. package/assets/plugin/wave9/live-position-confirmation.d.ts +0 -18
  386. package/assets/plugin/wave9/live-position-confirmation.js +0 -111
  387. package/assets/plugin/wave9/live-residual-protection.d.ts +0 -18
  388. package/assets/plugin/wave9/live-residual-protection.js +0 -250
  389. package/assets/plugin/wave9/live-startup-reconciliation.d.ts +0 -38
  390. package/assets/plugin/wave9/live-startup-reconciliation.js +0 -454
  391. package/assets/plugin/wave9/live-symbol-ownership.d.ts +0 -20
  392. package/assets/plugin/wave9/live-symbol-ownership.js +0 -132
  393. package/assets/plugin/wave9/paper-admission-guard.d.ts +0 -199
  394. package/assets/plugin/wave9/paper-admission-guard.js +0 -650
  395. package/assets/plugin/wave9/usdm-evidence-provider.d.ts +0 -42
  396. package/assets/plugin/wave9/usdm-evidence-provider.js +0 -133
@@ -1,176 +0,0 @@
1
- // Hyperliquid price/size precision — the rule, implemented HERE, on strings.
2
- //
3
- // ★ WHY NOT CCXT: `priceToPrecision` has a known rounding bug in the [1,10)
4
- // range (ccxt#26132) and the whole point of a safety floor is that the stop
5
- // price we compute is the stop price the exchange gets. Plan §5.5: own the math.
6
- //
7
- // ★ WHY NOT decimal.js: it would become a runtime dependency of the PUBLISHED
8
- // plugin package. The rule below only needs exact DECIMAL-STRING manipulation
9
- // (truncate / count significant figures) — no arithmetic on values — so strings
10
- // are both exact and dependency-free. Every function takes and returns numbers at
11
- // the boundary but never rounds through binary floating point.
12
- //
13
- // THE RULE (docs, verified 2026-07-11; re-verified live 2026-07-12):
14
- // PRICE is valid iff
15
- // - it is an INTEGER (always allowed, regardless of sig figs), OR
16
- // - it has ≤ 5 significant figures AND ≤ (MAX_DECIMALS − szDecimals) decimals
17
- // where MAX_DECIMALS = 6 for perps.
18
- // SIZE is rounded DOWN to szDecimals (from `meta.universe`).
19
- // MIN NOTIONAL is $10 (observed live: "Order must have minimum value of $10").
20
- //
21
- // Rounding direction is explicit at every call site — never "nearest" by default
22
- // on a protective leg. `passive` semantics: a BUY rounds DOWN, a SELL rounds UP,
23
- // so a rounded limit never crosses further into the book than intended.
24
- const MAX_DECIMALS_PERP = 6;
25
- /** HL minimum order value in USDC. Observed live 2026-07-12 (a $6 order was
26
- * rejected: "Order must have minimum value of $10"). */
27
- export const HL_MIN_NOTIONAL_USD = 10;
28
- /** Split a finite number into its exact decimal string parts, expanding any
29
- * exponent form ("1e-7") that JS produces for small/large magnitudes — the
30
- * string rule below must never see an "e". */
31
- function toPlainDecimalString(value) {
32
- if (!Number.isFinite(value))
33
- throw new Error(`not finite: ${value}`);
34
- // toPrecision(17) is lossless for a double, and never yields exponent form for
35
- // the magnitudes we trade; Number() re-parses to drop trailing zeros.
36
- const s = String(value);
37
- if (!s.includes('e') && !s.includes('E'))
38
- return s;
39
- // Exponent form → expand via toFixed with enough decimals (bounded: HL prices
40
- // never need more than 20 decimals, and sizes are capped by szDecimals).
41
- return value.toFixed(20).replace(/0+$/, '').replace(/\.$/, '');
42
- }
43
- /** Count significant figures of a decimal string (leading zeros are not
44
- * significant; trailing zeros AFTER a decimal point are, but we always emit
45
- * trimmed strings so they never appear). */
46
- export function countSignificantFigures(value) {
47
- const s = toPlainDecimalString(Math.abs(value));
48
- const digits = s.replace('.', '').replace(/^0+/, '').replace(/0+$/, '');
49
- // An integer like 1200 has 2 sig figs by this measure — which is the
50
- // conservative reading, and integers are unconditionally allowed anyway.
51
- return digits.length === 0 ? 1 : digits.length;
52
- }
53
- /** Decimal places of a value (0 for integers). */
54
- export function decimalPlaces(value) {
55
- const s = toPlainDecimalString(Math.abs(value));
56
- const dot = s.indexOf('.');
57
- return dot === -1 ? 0 : s.length - dot - 1;
58
- }
59
- /** Truncate a decimal string to N decimals, rounding in the requested direction.
60
- * Exact — no binary float rounding anywhere. */
61
- function roundDecimals(value, decimals, dir) {
62
- if (decimals < 0)
63
- decimals = 0;
64
- const factor = 10 ** decimals;
65
- // Work in an integer domain scaled by `factor`; the +/- 1e-9 nudge absorbs the
66
- // classic 0.1*3 = 0.30000000000000004 representation error WITHOUT changing a
67
- // value that is genuinely on the boundary.
68
- const scaled = value * factor;
69
- const eps = 1e-9;
70
- const out = dir === 'down' ? Math.floor(scaled + eps) : Math.ceil(scaled - eps);
71
- return out / factor;
72
- }
73
- /** Round a value to at most `sig` significant figures, in the given direction. */
74
- function roundToSignificantFigures(value, sig, dir) {
75
- if (value === 0)
76
- return 0;
77
- const magnitude = Math.floor(Math.log10(Math.abs(value)));
78
- // decimals needed so that the value carries exactly `sig` significant figures
79
- const decimals = sig - 1 - magnitude;
80
- return roundDecimals(value, Math.max(decimals, 0), dir);
81
- }
82
- /** Is this price acceptable to Hyperliquid as-is? (The exact documented rule —
83
- * used by tests and as a post-round assertion, never as a substitute for
84
- * rounding.) */
85
- export function isValidHlPrice(price, szDecimals) {
86
- if (!Number.isFinite(price) || price <= 0)
87
- return false;
88
- if (Number.isInteger(price))
89
- return true; // integers always allowed
90
- const maxDecimals = MAX_DECIMALS_PERP - szDecimals;
91
- return countSignificantFigures(price) <= 5 && decimalPlaces(price) <= maxDecimals;
92
- }
93
- /** Round a price to the nearest HL-legal value in the requested direction.
94
- *
95
- * Applies BOTH constraints (≤5 sig figs AND ≤ MAX_DECIMALS−szDecimals decimals),
96
- * tightest-wins. An integer result is always legal, so the decimal cap can never
97
- * push a price to an illegal value. */
98
- export function roundHlPrice(price, szDecimals, dir) {
99
- if (!Number.isFinite(price) || price <= 0) {
100
- throw new Error(`Invalid HL price: ${price}`);
101
- }
102
- const maxDecimals = Math.max(MAX_DECIMALS_PERP - szDecimals, 0);
103
- // 1) cap significant figures
104
- let out = roundToSignificantFigures(price, 5, dir);
105
- // 2) cap decimals (may reduce sig figs further — that stays legal)
106
- if (decimalPlaces(out) > maxDecimals) {
107
- out = roundDecimals(out, maxDecimals, dir);
108
- }
109
- // A rounded-to-zero price is never legal — fall back to the smallest legal tick.
110
- if (out <= 0)
111
- out = 1 / 10 ** maxDecimals;
112
- return out;
113
- }
114
- /** Round an order size DOWN to szDecimals. Always DOWN: rounding a size up can
115
- * overshoot the position (a reduce-only leg sized above the position is rejected)
116
- * or exceed the intended risk. */
117
- export function roundHlSize(size, szDecimals) {
118
- if (!Number.isFinite(size) || size < 0) {
119
- throw new Error(`Invalid HL size: ${size}`);
120
- }
121
- return roundDecimals(size, szDecimals, 'down');
122
- }
123
- /** Pre-flight validation mirroring `ExchangeInfoCache.validate`'s contract
124
- * (same shape, same "round then check" order, same dollar-hint error copy) so
125
- * the adapter's call sites are venue-symmetric.
126
- *
127
- * @param side drives passive rounding of a limit price (buy → down, sell → up).
128
- * @param referencePrice mark/mid — used for the notional check when no limit
129
- * price is given (market orders). */
130
- export function validateHlOrder(args) {
131
- const { amount, price, referencePrice, rules, side } = args;
132
- const { szDecimals } = rules;
133
- const roundedAmount = roundHlSize(amount, szDecimals);
134
- if (roundedAmount <= 0) {
135
- return {
136
- valid: false,
137
- error: `Amount ${amount} rounds to zero at ${szDecimals} decimals — increase the size`,
138
- roundedAmount: 0,
139
- };
140
- }
141
- let roundedPrice;
142
- if (price !== undefined) {
143
- roundedPrice = roundHlPrice(price, szDecimals, side === 'buy' ? 'down' : 'up');
144
- }
145
- const notionalPrice = roundedPrice ?? referencePrice;
146
- if (notionalPrice !== undefined && notionalPrice > 0) {
147
- const notional = roundedAmount * notionalPrice;
148
- if (notional < HL_MIN_NOTIONAL_USD) {
149
- const minAmount = HL_MIN_NOTIONAL_USD / notionalPrice;
150
- return {
151
- valid: false,
152
- // Same dollar-hint shape the Binance path uses — the agent gets an
153
- // actionable number, not a rule citation.
154
- error: `Order value $${notional.toFixed(2)} is below Hyperliquid's $${HL_MIN_NOTIONAL_USD} minimum. ` +
155
- `Increase size to at least ${minAmount.toFixed(szDecimals + 1)} (≈$${HL_MIN_NOTIONAL_USD}).`,
156
- roundedAmount,
157
- roundedPrice,
158
- };
159
- }
160
- }
161
- return { valid: true, roundedAmount, roundedPrice };
162
- }
163
- /** The IOC price bound that emulates a market order (HL has no native market
164
- * order — plan §3.4). Explicit slippage ALWAYS — ccxt's `defaultSlippage: 0.05`
165
- * (5%!) is never relied upon. */
166
- export function marketIocPrice(args) {
167
- const { referencePrice, side, slippagePct, szDecimals } = args;
168
- if (!Number.isFinite(referencePrice) || referencePrice <= 0) {
169
- throw new Error(`marketIocPrice needs a positive reference price, got ${referencePrice}`);
170
- }
171
- const slip = Math.min(Math.max(slippagePct, 0), 0.02); // hard clamp ≤2%
172
- const raw = side === 'buy' ? referencePrice * (1 + slip) : referencePrice * (1 - slip);
173
- // Round the bound OUTWARD (buy up / sell down) so rounding never makes the
174
- // order less marketable than intended.
175
- return roundHlPrice(raw, szDecimals, side === 'buy' ? 'up' : 'down');
176
- }
@@ -1,88 +0,0 @@
1
- import type { CcxtOrder, CcxtPosition, CcxtBalance } from '../../types.js';
2
- export interface HlCredentials {
3
- /** MASTER account address (0x…). Queries always use this — an agent wallet
4
- * holds no balance and no positions (learned the hard way 2026-07-12). */
5
- walletAddress: string;
6
- /** AGENT (API) wallet private key — signs, never holds funds. */
7
- agentPrivateKey: string;
8
- testnet?: boolean;
9
- }
10
- /** The CCXT options that MUST be present on every authed HL client. Exported so
11
- * `hl-private.test.ts` can assert them — if a future ccxt bump changes the
12
- * option names, the test fails rather than the users paying a silent 1bp. */
13
- export declare const HL_REQUIRED_OPTIONS: {
14
- readonly builderFee: false;
15
- readonly refSet: true;
16
- };
17
- export interface HlTriggerParams {
18
- /** Trigger price (fires on MARK — HL has no workingType choice). */
19
- triggerPrice: number;
20
- /** 'sl' | 'tp' — HL's own naming. */
21
- tpsl: 'sl' | 'tp';
22
- reduceOnly: true;
23
- cloid?: string;
24
- }
25
- export interface HlOrderRequest {
26
- symbol: string;
27
- side: 'buy' | 'sell';
28
- /** 'market' is emulated: an IOC limit at `price` (the caller must have applied
29
- * the slippage bound via hl-precision.marketIocPrice). */
30
- type: 'market' | 'limit';
31
- amount: number;
32
- price: number;
33
- reduceOnly?: boolean;
34
- postOnly?: boolean;
35
- cloid?: string;
36
- trigger?: {
37
- triggerPrice: number;
38
- tpsl: 'sl' | 'tp';
39
- };
40
- }
41
- export declare class HyperliquidPrivateApi {
42
- private readonly creds;
43
- private readonly exchange;
44
- private readonly mutex;
45
- private marketsLoaded;
46
- constructor(creds: HlCredentials);
47
- /** Exposed for the options-pin test + diagnostics. */
48
- getExchange(): any;
49
- loadMarkets(): Promise<boolean>;
50
- /** Positions for the MASTER account. `null` = fetch failed (state unknown);
51
- * `[]` = the exchange confirmed flat. */
52
- fetchPositions(symbol?: string): Promise<CcxtPosition[] | null>;
53
- /** Open orders INCLUDING trigger/TPSL legs. CCXT's HL `fetchOpenOrders`
54
- * defaults to `frontendOpenOrders`, which is the only endpoint that returns
55
- * trigger orders (plan §3.6) — the analog of Binance's merged algo endpoints. */
56
- fetchOpenOrders(symbol?: string): Promise<CcxtOrder[] | null>;
57
- fetchBalance(): Promise<CcxtBalance | null>;
58
- /** Per-order status — the liveness resolver's REST tier (Tier 2 of the
59
- * 3-tier rule). Weight 2. `null` = lookup FAILED (unknown), which callers
60
- * must treat as "do not act", NOT as "gone". */
61
- fetchOrder(orderId: string, symbol?: string): Promise<CcxtOrder | null>;
62
- /** Own fills. WS is the authoritative ingress (plan + the audit-trail rule);
63
- * this is the gap-fill/truth-check path. NOTE: only the 10,000 most recent
64
- * fills exist server-side — deep history is NOT queryable on HL, which is why
65
- * the `trades` table must be WS-first. */
66
- fetchMyTrades(symbol?: string, since?: number, limit?: number): Promise<unknown[] | null>;
67
- /** Refresh the ADDRESS action budget (the starvation guard). Weight 20 — call
68
- * every ~5 min, never per-heartbeat. */
69
- refreshAddressBudget(): Promise<void>;
70
- /** Raw `POST /info` — for the handful of reads CCXT doesn't expose
71
- * (userRateLimit, userNonFundingLedgerUpdates, portfolio). Never used for
72
- * signed actions. */
73
- rawInfo(body: Record<string, unknown>): Promise<any>;
74
- /** Submit one order. Market orders are IOC-limit emulated — `price` is
75
- * MANDATORY (ccxt throws without it) and the caller must already have applied
76
- * the slippage bound + HL rounding (hl-precision). */
77
- submitOrder(req: HlOrderRequest): Promise<CcxtOrder | null>;
78
- /** Submit N orders as ONE signed action (one nonce, one `/exchange` call).
79
- * This is how a bracket pair (SL+TP) is placed: atomic-ish, and it costs 1 IP
80
- * weight unit but N address actions. */
81
- submitOrders(reqs: HlOrderRequest[]): Promise<CcxtOrder[] | null>;
82
- cancelOrder(orderId: string, symbol: string): Promise<CcxtOrder | null>;
83
- /** Cancel by cloid — the bracket path's cancel (we always know our own cloid,
84
- * and it survives a restart because it is derived, not stored). */
85
- cancelOrderByCloid(cloid: string, symbol: string): Promise<CcxtOrder | null>;
86
- private buildParams;
87
- get isMarketsLoaded(): boolean;
88
- }
@@ -1,357 +0,0 @@
1
- // Hyperliquid signed-action client — the HL mirror of `ccxt/binance-private.ts`.
2
- //
3
- // CONTRACTS THIS FILE INHERITS FROM THE BINANCE SIDE (non-negotiable — the shared
4
- // adapter-contract suite runs against both):
5
- // ★ null ≠ empty. EVERY read returns `null` on a FAILED fetch, never `[]`.
6
- // `[]` means "the exchange said: nothing". Callers make destructive decisions
7
- // (cancel a bracket, close a position, trust a snapshot) on that difference.
8
- // ★ Reads are pre-gated (`assertNotLimited`), order/cancel paths are NOT (an
9
- // exit must never be blocked by our own pacer) but every path arms the gate
10
- // via `noteError`.
11
- //
12
- // HYPERLIQUID-SPECIFIC LANDMINES (all verified live on testnet 2026-07-12):
13
- // ★ ccxt AUTO-MONETIZES an authed HL client — `initializeClient()` enrolls
14
- // CCXT's own builder fee (1bp/order) + referral code on the first signed call.
15
- // `options.{builderFee:false, refSet:true}` disables both. A test pins this.
16
- // ★ Market orders REQUIRE a reference price (ccxt derives the slippage cap from
17
- // it) — `createOrder(sym,'market',side,size)` with no price THROWS client-side.
18
- // There is no native market order on HL: it is an IOC limit at a bounded price.
19
- // ★ Signed actions carry a NONCE (epoch ms) and HL keeps only the 100 highest
20
- // per signer. Two actions signed in the same millisecond can collide → every
21
- // signed action goes through a monotonic-nonce MUTEX (one in-flight at a time,
22
- // strictly increasing ms). This is why `submitOrders` batches a bracket pair
23
- // into ONE action rather than firing two.
24
- // ★ Agent (API) wallets can only TRADE. `usdClassTransfer`/withdraw are
25
- // user-signed actions and fail with "Must deposit before performing actions"
26
- // when signed by an agent. We never call them.
27
- import { createRequire } from 'node:module';
28
- import { logger } from '../../logger.js';
29
- import { toCcxtSymbol } from '../symbols.js';
30
- import { assertNotLimited, noteError, noteSuccess, exchangeIpWeight, updateAddressBudget, } from './hl-rate-gate.js';
31
- import { isValidHlCloid } from './hl-cloid.js';
32
- // ccxt via CJS require — OpenClaw's ESM loader yields the wrong module shape
33
- // (same rationale as binance-private.ts / hl-public.ts).
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- let ccxtCjs;
36
- try {
37
- const _require = createRequire(import.meta.url);
38
- ccxtCjs = _require('ccxt');
39
- }
40
- catch {
41
- // eslint-disable-next-line @typescript-eslint/no-require-imports
42
- ccxtCjs = require('ccxt');
43
- }
44
- const TAG = 'hl-private';
45
- /** The CCXT options that MUST be present on every authed HL client. Exported so
46
- * `hl-private.test.ts` can assert them — if a future ccxt bump changes the
47
- * option names, the test fails rather than the users paying a silent 1bp. */
48
- export const HL_REQUIRED_OPTIONS = {
49
- builderFee: false,
50
- refSet: true,
51
- };
52
- /**
53
- * Serializes every signed action behind a monotonic nonce.
54
- *
55
- * HL keeps the 100 highest nonces per signer and rejects repeats; two actions
56
- * signed inside the same millisecond can therefore collide and one is silently
57
- * lost. Rather than hand-rolling nonces (ccxt owns that), we guarantee that no
58
- * two signed actions are ever *issued* in the same millisecond from this process:
59
- * each waits for the previous to settle AND for the clock to advance.
60
- */
61
- class NonceMutex {
62
- chain = Promise.resolve();
63
- lastIssuedMs = 0;
64
- run(fn) {
65
- const next = this.chain.then(async () => {
66
- const now = Date.now();
67
- if (now <= this.lastIssuedMs) {
68
- // Same-ms collision guard: wait out the millisecond.
69
- await new Promise((r) => setTimeout(r, this.lastIssuedMs - now + 1));
70
- }
71
- this.lastIssuedMs = Date.now();
72
- return fn();
73
- });
74
- // Keep the chain alive even when a link rejects (otherwise one failed action
75
- // would poison every later one).
76
- this.chain = next.then(() => undefined, () => undefined);
77
- return next;
78
- }
79
- }
80
- export class HyperliquidPrivateApi {
81
- creds;
82
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
83
- exchange;
84
- mutex = new NonceMutex();
85
- marketsLoaded = false;
86
- constructor(creds) {
87
- this.creds = creds;
88
- if (!creds.walletAddress || !creds.agentPrivateKey) {
89
- throw new Error('HyperliquidPrivateApi requires walletAddress + agentPrivateKey');
90
- }
91
- this.exchange = new ccxtCjs.hyperliquid({
92
- walletAddress: creds.walletAddress,
93
- privateKey: creds.agentPrivateKey,
94
- options: { ...HL_REQUIRED_OPTIONS },
95
- enableRateLimit: true,
96
- });
97
- if (creds.testnet) {
98
- this.exchange.setSandboxMode(true);
99
- const url = JSON.stringify(this.exchange.urls?.api ?? '');
100
- if (!url.includes('testnet')) {
101
- throw new Error(`HL testnet requested but sandbox URL is not testnet: ${url.slice(0, 80)}`);
102
- }
103
- }
104
- logger.info(TAG, `Hyperliquid private API initialized (${creds.testnet ? 'TESTNET' : 'MAINNET'}, master ${creds.walletAddress.slice(0, 8)}…)`);
105
- }
106
- /** Exposed for the options-pin test + diagnostics. */
107
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
- getExchange() {
109
- return this.exchange;
110
- }
111
- async loadMarkets() {
112
- try {
113
- assertNotLimited('meta');
114
- await this.exchange.loadMarkets();
115
- noteSuccess('meta');
116
- this.marketsLoaded = true;
117
- return true;
118
- }
119
- catch (err) {
120
- noteError(err, 'loadMarkets');
121
- logger.error(TAG, `loadMarkets failed: ${msg(err)}`);
122
- return false;
123
- }
124
- }
125
- // ---- Reads (null on failure — NEVER []) ----
126
- /** Positions for the MASTER account. `null` = fetch failed (state unknown);
127
- * `[]` = the exchange confirmed flat. */
128
- async fetchPositions(symbol) {
129
- try {
130
- assertNotLimited('clearinghouseState');
131
- const symbols = symbol ? [toCcxtSymbol('hyperliquid', symbol)] : undefined;
132
- const raw = await this.exchange.fetchPositions(symbols);
133
- noteSuccess('clearinghouseState');
134
- if (!Array.isArray(raw))
135
- return null;
136
- return raw.filter((p) => Math.abs(Number(p.contracts ?? 0)) > 0);
137
- }
138
- catch (err) {
139
- noteError(err, 'fetchPositions');
140
- logger.error(TAG, `fetchPositions failed: ${msg(err)}`);
141
- return null;
142
- }
143
- }
144
- /** Open orders INCLUDING trigger/TPSL legs. CCXT's HL `fetchOpenOrders`
145
- * defaults to `frontendOpenOrders`, which is the only endpoint that returns
146
- * trigger orders (plan §3.6) — the analog of Binance's merged algo endpoints. */
147
- async fetchOpenOrders(symbol) {
148
- try {
149
- assertNotLimited('frontendOpenOrders');
150
- const s = symbol ? toCcxtSymbol('hyperliquid', symbol) : undefined;
151
- const raw = await this.exchange.fetchOpenOrders(s);
152
- noteSuccess('frontendOpenOrders');
153
- return Array.isArray(raw) ? raw : null;
154
- }
155
- catch (err) {
156
- noteError(err, 'fetchOpenOrders');
157
- logger.error(TAG, `fetchOpenOrders failed: ${msg(err)}`);
158
- return null;
159
- }
160
- }
161
- async fetchBalance() {
162
- try {
163
- assertNotLimited('clearinghouseState');
164
- const raw = await this.exchange.fetchBalance();
165
- noteSuccess('clearinghouseState');
166
- return raw ?? null;
167
- }
168
- catch (err) {
169
- noteError(err, 'fetchBalance');
170
- logger.error(TAG, `fetchBalance failed: ${msg(err)}`);
171
- return null;
172
- }
173
- }
174
- /** Per-order status — the liveness resolver's REST tier (Tier 2 of the
175
- * 3-tier rule). Weight 2. `null` = lookup FAILED (unknown), which callers
176
- * must treat as "do not act", NOT as "gone". */
177
- async fetchOrder(orderId, symbol) {
178
- try {
179
- assertNotLimited('orderStatus');
180
- const s = symbol ? toCcxtSymbol('hyperliquid', symbol) : undefined;
181
- const raw = await this.exchange.fetchOrder(orderId, s);
182
- noteSuccess('orderStatus');
183
- return raw ?? null;
184
- }
185
- catch (err) {
186
- noteError(err, 'fetchOrder');
187
- logger.warn(TAG, `fetchOrder(${orderId}) failed: ${msg(err)}`);
188
- return null;
189
- }
190
- }
191
- /** Own fills. WS is the authoritative ingress (plan + the audit-trail rule);
192
- * this is the gap-fill/truth-check path. NOTE: only the 10,000 most recent
193
- * fills exist server-side — deep history is NOT queryable on HL, which is why
194
- * the `trades` table must be WS-first. */
195
- async fetchMyTrades(symbol, since, limit = 100) {
196
- try {
197
- assertNotLimited('userFills');
198
- const s = symbol ? toCcxtSymbol('hyperliquid', symbol) : undefined;
199
- const raw = await this.exchange.fetchMyTrades(s, since, limit);
200
- noteSuccess('userFills');
201
- return Array.isArray(raw) ? raw : null;
202
- }
203
- catch (err) {
204
- noteError(err, 'fetchMyTrades');
205
- logger.error(TAG, `fetchMyTrades failed: ${msg(err)}`);
206
- return null;
207
- }
208
- }
209
- /** Refresh the ADDRESS action budget (the starvation guard). Weight 20 — call
210
- * every ~5 min, never per-heartbeat. */
211
- async refreshAddressBudget() {
212
- try {
213
- assertNotLimited('userRateLimit');
214
- const res = await this.rawInfo({ type: 'userRateLimit', user: this.creds.walletAddress });
215
- noteSuccess('userRateLimit');
216
- const used = Number(res?.nRequestsUsed);
217
- const cap = Number(res?.nRequestsCap);
218
- if (Number.isFinite(used) && Number.isFinite(cap)) {
219
- updateAddressBudget({ nRequestsUsed: used, nRequestsCap: cap });
220
- }
221
- }
222
- catch (err) {
223
- noteError(err, 'userRateLimit');
224
- logger.warn(TAG, `refreshAddressBudget failed: ${msg(err)}`);
225
- }
226
- }
227
- /** Raw `POST /info` — for the handful of reads CCXT doesn't expose
228
- * (userRateLimit, userNonFundingLedgerUpdates, portfolio). Never used for
229
- * signed actions. */
230
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
- async rawInfo(body) {
232
- const base = this.creds.testnet
233
- ? 'https://api.hyperliquid-testnet.xyz'
234
- : 'https://api.hyperliquid.xyz';
235
- const res = await fetch(`${base}/info`, {
236
- method: 'POST',
237
- headers: { 'content-type': 'application/json' },
238
- body: JSON.stringify(body),
239
- signal: AbortSignal.timeout(15_000),
240
- });
241
- if (!res.ok)
242
- throw new Error(`POST /info ${String(body.type)} → ${res.status}`);
243
- return res.json();
244
- }
245
- // ---- Signed actions (NEVER pre-gated; always nonce-serialized) ----
246
- /** Submit one order. Market orders are IOC-limit emulated — `price` is
247
- * MANDATORY (ccxt throws without it) and the caller must already have applied
248
- * the slippage bound + HL rounding (hl-precision). */
249
- async submitOrder(req) {
250
- if (req.cloid && !isValidHlCloid(req.cloid)) {
251
- throw new Error(`Invalid HL cloid ${req.cloid} — must be 0x + 32 hex chars`);
252
- }
253
- return this.mutex.run(async () => {
254
- try {
255
- const params = this.buildParams(req);
256
- const order = await this.exchange.createOrder(toCcxtSymbol('hyperliquid', req.symbol), req.type === 'market' ? 'market' : 'limit', req.side, req.amount, req.price, // ★ always passed — ccxt needs it even for 'market'
257
- params);
258
- noteSuccess('exchange', { ipWeight: exchangeIpWeight(1), addressActions: 1 });
259
- return order ?? null;
260
- }
261
- catch (err) {
262
- noteError(err, 'submitOrder');
263
- // Order paths RETHROW (the caller must see a rejection) — unlike reads,
264
- // which collapse to null.
265
- throw err;
266
- }
267
- });
268
- }
269
- /** Submit N orders as ONE signed action (one nonce, one `/exchange` call).
270
- * This is how a bracket pair (SL+TP) is placed: atomic-ish, and it costs 1 IP
271
- * weight unit but N address actions. */
272
- async submitOrders(reqs) {
273
- if (reqs.length === 0)
274
- return [];
275
- for (const r of reqs) {
276
- if (r.cloid && !isValidHlCloid(r.cloid)) {
277
- throw new Error(`Invalid HL cloid ${r.cloid} — must be 0x + 32 hex chars`);
278
- }
279
- }
280
- return this.mutex.run(async () => {
281
- try {
282
- const ccxtReqs = reqs.map((r) => ({
283
- symbol: toCcxtSymbol('hyperliquid', r.symbol),
284
- type: r.type === 'market' ? 'market' : 'limit',
285
- side: r.side,
286
- amount: r.amount,
287
- price: r.price,
288
- params: this.buildParams(r),
289
- }));
290
- const orders = await this.exchange.createOrders(ccxtReqs);
291
- noteSuccess('exchange', {
292
- ipWeight: exchangeIpWeight(reqs.length),
293
- addressActions: reqs.length, // ★ batches cost n against the ADDRESS budget
294
- });
295
- return Array.isArray(orders) ? orders : null;
296
- }
297
- catch (err) {
298
- noteError(err, 'submitOrders');
299
- throw err;
300
- }
301
- });
302
- }
303
- async cancelOrder(orderId, symbol) {
304
- return this.mutex.run(async () => {
305
- try {
306
- const res = await this.exchange.cancelOrder(orderId, toCcxtSymbol('hyperliquid', symbol));
307
- noteSuccess('exchange', { ipWeight: exchangeIpWeight(1), addressActions: 1 });
308
- return res ?? null;
309
- }
310
- catch (err) {
311
- noteError(err, 'cancelOrder');
312
- throw err;
313
- }
314
- });
315
- }
316
- /** Cancel by cloid — the bracket path's cancel (we always know our own cloid,
317
- * and it survives a restart because it is derived, not stored). */
318
- async cancelOrderByCloid(cloid, symbol) {
319
- return this.mutex.run(async () => {
320
- try {
321
- const res = await this.exchange.cancelOrder(cloid, toCcxtSymbol('hyperliquid', symbol), { clientOrderId: cloid });
322
- noteSuccess('exchange', { ipWeight: exchangeIpWeight(1), addressActions: 1 });
323
- return res ?? null;
324
- }
325
- catch (err) {
326
- noteError(err, 'cancelOrderByCloid');
327
- throw err;
328
- }
329
- });
330
- }
331
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
332
- buildParams(req) {
333
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
334
- const params = {};
335
- if (req.reduceOnly)
336
- params.reduceOnly = true;
337
- if (req.postOnly)
338
- params.postOnly = true; // → ALO
339
- if (req.cloid)
340
- params.clientOrderId = req.cloid;
341
- if (req.trigger) {
342
- // HL trigger orders fire on MARK price only (no workingType choice).
343
- params.triggerPrice = req.trigger.triggerPrice;
344
- if (req.trigger.tpsl === 'tp')
345
- params.takeProfitPrice = req.trigger.triggerPrice;
346
- else
347
- params.stopLossPrice = req.trigger.triggerPrice;
348
- }
349
- return params;
350
- }
351
- get isMarketsLoaded() {
352
- return this.marketsLoaded;
353
- }
354
- }
355
- function msg(err) {
356
- return err instanceof Error ? err.message : String(err);
357
- }