@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,107 +0,0 @@
1
- // ⚠️ GENERATED FILE — DO NOT EDIT.
2
- // Canonical source of truth: shared/src/venues/symbols.ts
3
- // Regenerate: node scripts/sync-shared-code.mjs (enforced by shared-code-sync.test.ts)
4
- //
5
- // This copy exists because this package builds with tsc and deploys as a
6
- // self-contained tree that strips workspace deps, so it cannot import
7
- // @reefclaw/shared runtime code across the deploy boundary.
8
- export const VENUE_IDS = ['binance', 'hyperliquid'];
9
- export function isVenueId(value) {
10
- return value === 'binance' || value === 'hyperliquid';
11
- }
12
- /** Parse a raw config value into a venue.
13
- * Absent/empty → 'binance' (every pre-venue config file keeps today's
14
- * behavior byte-identically). An unrecognized string is surfaced to the
15
- * caller instead of being silently coerced — mis-spelling a venue must be
16
- * loud, never quietly become "trade on Binance". */
17
- export function parseVenue(raw) {
18
- if (raw === undefined || raw === null || raw === '')
19
- return { venue: 'binance' };
20
- if (isVenueId(raw))
21
- return { venue: raw };
22
- return { venue: 'binance', unrecognized: String(raw) };
23
- }
24
- /** `FillEvent.exchange` / webapp `trades.exchange` value — half of the
25
- * audit-trail idempotency key `(exchange, exchange_trade_id)` (migration
26
- * 0042). 'binance_futures' is the historical literal on every existing row;
27
- * NEVER change these strings once a venue has written rows. */
28
- export const FILL_EXCHANGE_ID = {
29
- binance: 'binance_futures',
30
- hyperliquid: 'hyperliquid',
31
- };
32
- export function fillExchangeId(venue) {
33
- return FILL_EXCHANGE_ID[venue];
34
- }
35
- /** Quote/settle asset of the venue's linear perps. */
36
- export const VENUE_QUOTE_ASSET = {
37
- binance: 'USDT',
38
- hyperliquid: 'USDC',
39
- };
40
- /** Prefix that namespaces Hyperliquid rows inside the intel symbol column. */
41
- export const HL_INTEL_PREFIX = 'HL_';
42
- /** Strip a CCXT settle suffix ('BTC/USDT:USDT' → 'BTC/USDT'). Same regex as
43
- * webapp/src/lib/symbols.ts normalizeSymbol — kept inline so this module has
44
- * zero imports and survives the sync-copy deploy boundary. */
45
- function stripSettleSuffix(symbol) {
46
- return symbol.replace(/:[A-Z]+$/, '');
47
- }
48
- function splitCanonical(canonical) {
49
- const stripped = stripSettleSuffix(canonical.trim());
50
- const parts = stripped.split('/');
51
- if (parts.length !== 2 || parts[0].length === 0 || parts[1].length === 0) {
52
- throw new Error(`Not a canonical BASE/QUOTE symbol: '${canonical}'`);
53
- }
54
- return { base: parts[0], quote: parts[1] };
55
- }
56
- /** Canonical symbol → the venue's CCXT unified symbol.
57
- * 'BTC/USDT' (binance) → 'BTC/USDT:USDT'; 'BTC/USDC' (hyperliquid) →
58
- * 'BTC/USDC:USDC'. Accepts an already-suffixed input (idempotent). */
59
- export function toCcxtSymbol(venue, canonical) {
60
- const { base, quote } = splitCanonical(canonical);
61
- if (quote !== VENUE_QUOTE_ASSET[venue]) {
62
- throw new Error(`Symbol '${canonical}' is not ${VENUE_QUOTE_ASSET[venue]}-quoted — not a ${venue} linear perp`);
63
- }
64
- return `${base}/${quote}:${quote}`;
65
- }
66
- /** Canonical symbol → intel DB symbol.
67
- * binance: 'BTC/USDT' → 'BTCUSDT' (the historical concatenated form intel has
68
- * always stored); hyperliquid: 'BTC/USDC' → 'HL_BTC' (namespaced coin, case
69
- * preserved). */
70
- export function toIntelSymbol(venue, canonical) {
71
- const { base, quote } = splitCanonical(canonical);
72
- if (venue === 'hyperliquid') {
73
- if (quote !== VENUE_QUOTE_ASSET.hyperliquid) {
74
- throw new Error(`Symbol '${canonical}' is not USDC-quoted — not a Hyperliquid perp`);
75
- }
76
- return `${HL_INTEL_PREFIX}${base}`;
77
- }
78
- return `${base}${quote}`;
79
- }
80
- /** Inverse of toIntelSymbol. 'HL_'-prefixed → hyperliquid; everything else is
81
- * the historical Binance namespace. Binance symbols that are not
82
- * USDT-concatenated (none exist in INTEL_SYMBOLS today) come back verbatim as
83
- * canonical — honest passthrough, not a guess. */
84
- export function fromIntelSymbol(intelSymbol) {
85
- if (intelSymbol.startsWith(HL_INTEL_PREFIX)) {
86
- const coin = intelSymbol.slice(HL_INTEL_PREFIX.length);
87
- if (coin.length === 0) {
88
- throw new Error(`Malformed intel symbol '${intelSymbol}' — empty coin after HL_ prefix`);
89
- }
90
- return { venue: 'hyperliquid', canonical: `${coin}/${VENUE_QUOTE_ASSET.hyperliquid}` };
91
- }
92
- if (intelSymbol.endsWith(VENUE_QUOTE_ASSET.binance) && intelSymbol.length > 4) {
93
- const base = intelSymbol.slice(0, -VENUE_QUOTE_ASSET.binance.length);
94
- return { venue: 'binance', canonical: `${base}/${VENUE_QUOTE_ASSET.binance}` };
95
- }
96
- return { venue: 'binance', canonical: intelSymbol };
97
- }
98
- /** The Hyperliquid venue-native coin name for a canonical symbol
99
- * ('BTC/USDC' → 'BTC'). Orders address assets by integer index resolved from
100
- * `meta.universe` at runtime — the coin name is the stable half. */
101
- export function toHyperliquidCoin(canonical) {
102
- const { base, quote } = splitCanonical(canonical);
103
- if (quote !== VENUE_QUOTE_ASSET.hyperliquid) {
104
- throw new Error(`Symbol '${canonical}' is not USDC-quoted — not a Hyperliquid perp`);
105
- }
106
- return base;
107
- }
@@ -1,67 +0,0 @@
1
- import type { IExchangeAdapter } from '../exchange-adapter.js';
2
- import { type Wave9ExecutionMode } from './paper-admission-guard.js';
3
- import { type Wave9LiveExecutionLedger } from './live-execution-ledger.js';
4
- export interface Wave9NativeStopObservation {
5
- verified: boolean;
6
- reason: string;
7
- bracketId: string | null;
8
- bracketState: string | null;
9
- entryClientOrderId: string | null;
10
- stopClientOrderId: string | null;
11
- exchangeOrderId: string | null;
12
- entrySide: 'buy' | 'sell' | null;
13
- stopSide: 'buy' | 'sell' | null;
14
- stopPrice: number | null;
15
- bracketQuantity: number | null;
16
- closePosition: boolean | null;
17
- liveness: 'live' | 'terminal' | 'unknown' | null;
18
- }
19
- export interface Wave9LiveStopConfirmationInput {
20
- candidateId: string;
21
- symbol: string;
22
- entryClientOrderId: string;
23
- entrySide: 'buy' | 'sell';
24
- stopPrice: number;
25
- filledQuantity: number;
26
- }
27
- export interface Wave9LiveObservedPosition {
28
- symbol: string;
29
- side: 'long' | 'short';
30
- quantity: number;
31
- entryPrice: number;
32
- markPrice: number;
33
- stopPrice?: number;
34
- missionId?: string;
35
- setupType?: string;
36
- candidateId?: string;
37
- strategy?: 'tsmom_28d_long_flat_reversal_1d' | 'tsmom_28d_short_flat_reversal_1d';
38
- accruedFundingUsd?: number;
39
- openedAt?: string;
40
- initialStopPrice?: number;
41
- nativeStop?: Wave9NativeStopObservation;
42
- positionFingerprint?: string;
43
- }
44
- export interface Wave9LiveAccountCapture {
45
- fingerprint: string;
46
- cashEquityUsd: number;
47
- positions: Wave9LiveObservedPosition[];
48
- pendingExposureOrderCount: number;
49
- executedCandidateIds: string[];
50
- nativeStopProtectionComplete: boolean;
51
- nativeStopIssues: string[];
52
- authoritative: true;
53
- runtimeParity: false;
54
- provenance: 'live_exchange_structural_snapshot_and_durable_wave9_ledger';
55
- }
56
- /** One-shot post-fill confirmation used after the bracket row becomes active. */
57
- export declare function confirmWave9LiveNativeStop(adapter: IExchangeAdapter, input: Wave9LiveStopConfirmationInput): Promise<boolean>;
58
- /**
59
- * Capture exchange-authoritative LIVE geometry without volatile mark prices in
60
- * the authorization fingerprint. Wallet cash, positions, pending
61
- * exposure-increasing orders, and durable Wave 9 identities are all bound.
62
- */
63
- export declare function captureWave9LiveAccount(adapter: IExchangeAdapter, ledger: Wave9LiveExecutionLedger, mode: Wave9ExecutionMode): Promise<Wave9LiveAccountCapture>;
64
- export declare function captureWave9LivePosition(adapter: IExchangeAdapter, ledger: Wave9LiveExecutionLedger, mode: Wave9ExecutionMode, symbol: string): Promise<{
65
- fingerprint: string;
66
- position: Wave9LiveObservedPosition;
67
- }>;
@@ -1,435 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { getQuoteWalletBalance } from '../balance-utils.js';
3
- import { parseBracketCid } from '../live/bracket-id.js';
4
- import { WAVE9_BUNDLE_SETUP_TYPE, } from './paper-admission-guard.js';
5
- import { wave9ClientOrderId, } from './live-execution-ledger.js';
6
- function canonicalSymbol(symbol) {
7
- return symbol.toUpperCase().replace(/[^A-Z0-9]/g, '').replace(/USDTUSDT$/, 'USDT');
8
- }
9
- function finitePositive(value, label) {
10
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
11
- throw new Error(`Wave 9 live snapshot requires positive ${label}`);
12
- }
13
- return value;
14
- }
15
- function nearlyEqual(left, right) {
16
- return Math.abs(left - right) <= 1e-9 * Math.max(1, Math.abs(left), Math.abs(right));
17
- }
18
- /**
19
- * Binance may tick-normalize the submitted trigger while the local bracket
20
- * row retains the requested ATR-derived value. One basis point matches the
21
- * existing bracket idempotency tolerance, admits normal tick rounding, and
22
- * still rejects any materially different stop.
23
- */
24
- function exchangeStopPriceMatches(actual, requested) {
25
- return Math.abs(actual - requested)
26
- <= Math.max(1e-12, Math.abs(requested) * 1e-4);
27
- }
28
- function asNativeStopAdapter(adapter) {
29
- const candidate = adapter;
30
- return typeof candidate.getBracketLedger === 'function'
31
- && typeof candidate.resolveBracketLegLiveness === 'function'
32
- ? candidate
33
- : null;
34
- }
35
- function openWave9Record(ledger, symbol, side) {
36
- const canonical = canonicalSymbol(symbol);
37
- const orderSide = side === 'long' ? 'buy' : 'sell';
38
- const matches = ledger.getAll().filter((record) => record.state === 'open'
39
- && record.symbol === canonical
40
- && record.side === orderSide);
41
- matches.sort((left, right) => right.updatedAt - left.updatedAt || right.candidateId.localeCompare(left.candidateId));
42
- return matches[0];
43
- }
44
- function emptyStopObservation(reason) {
45
- return {
46
- verified: false,
47
- reason,
48
- bracketId: null,
49
- bracketState: null,
50
- entryClientOrderId: null,
51
- stopClientOrderId: null,
52
- exchangeOrderId: null,
53
- entrySide: null,
54
- stopSide: null,
55
- stopPrice: null,
56
- bracketQuantity: null,
57
- closePosition: null,
58
- liveness: null,
59
- };
60
- }
61
- function rawOrderField(order, key) {
62
- const direct = order.info?.[key];
63
- if (direct !== undefined)
64
- return direct;
65
- const nested = order.info?.info;
66
- return typeof nested === 'object' && nested !== null && !Array.isArray(nested)
67
- ? nested[key]
68
- : undefined;
69
- }
70
- function boolField(value) {
71
- if (value === true || value === 'true' || value === 'TRUE')
72
- return true;
73
- if (value === false || value === 'false' || value === 'FALSE')
74
- return false;
75
- return null;
76
- }
77
- function finiteOrderStopPrice(order) {
78
- if (!order)
79
- return null;
80
- const candidates = [order.price, rawOrderField(order, 'triggerPrice'), rawOrderField(order, 'stopPrice')];
81
- for (const value of candidates) {
82
- const parsed = typeof value === 'number' ? value : Number(value);
83
- if (Number.isFinite(parsed) && parsed > 0)
84
- return parsed;
85
- }
86
- return null;
87
- }
88
- function proofLiveness(proof) {
89
- if (!proof)
90
- return 'unknown';
91
- if (proof.algoStatus === 'NEW'
92
- || proof.algoStatus === 'WORKING'
93
- || proof.algoStatus === 'TRIGGERING')
94
- return 'live';
95
- if (proof.algoStatus === 'TRIGGERED'
96
- || proof.algoStatus === 'CANCELED'
97
- || proof.algoStatus === 'FINISHED'
98
- || proof.algoStatus === 'EXPIRED'
99
- || proof.algoStatus === 'REJECTED')
100
- return 'terminal';
101
- return 'unknown';
102
- }
103
- /**
104
- * Bind one durable Wave 9 execution identity to the exact exchange-native
105
- * stop currently protecting it. A failed observation remains structural data
106
- * (so ownership/reversal handling survives) but can never authorize admission.
107
- */
108
- async function observeNativeStop(adapter, openOrders, expectation) {
109
- const native = asNativeStopAdapter(adapter);
110
- if (!native)
111
- return emptyStopObservation('native_stop_adapter_unavailable');
112
- const bracket = native.getBracketLedger()?.getBySymbol(expectation.symbol);
113
- if (!bracket)
114
- return emptyStopObservation('native_stop_ledger_row_missing');
115
- const stopOrders = bracket.slCid
116
- ? openOrders.filter((order) => order.clientOrderId === bracket.slCid)
117
- : [];
118
- const stopOrder = stopOrders.length === 1 ? stopOrders[0] : undefined;
119
- const directProofRequired = !expectation.requireExchangeOrderDetails;
120
- let directProof = null;
121
- let liveness = null;
122
- if (bracket.slCid) {
123
- if (directProofRequired) {
124
- try {
125
- directProof = await native.resolveBracketLegProof?.(bracket.slCid) ?? null;
126
- }
127
- catch {
128
- directProof = null;
129
- }
130
- liveness = proofLiveness(directProof);
131
- }
132
- else {
133
- try {
134
- liveness = await native.resolveBracketLegLiveness(bracket.slCid);
135
- }
136
- catch {
137
- liveness = 'unknown';
138
- }
139
- }
140
- }
141
- const exchangeStopPrice = directProofRequired
142
- ? directProof?.triggerPrice ?? null
143
- : finiteOrderStopPrice(stopOrder);
144
- const closePosition = directProofRequired
145
- ? directProof?.closePosition ?? null
146
- : stopOrder ? boolField(rawOrderField(stopOrder, 'closePosition')) : null;
147
- const exchangeSymbol = directProofRequired ? directProof?.symbol : stopOrder?.symbol;
148
- const exchangeSide = directProofRequired ? directProof?.side : stopOrder?.side;
149
- const orderType = directProofRequired
150
- ? directProof?.orderType ?? ''
151
- : stopOrder ? String(rawOrderField(stopOrder, 'orderType') ?? '').toUpperCase() : '';
152
- const observation = {
153
- verified: false,
154
- reason: 'native_stop_unverified',
155
- bracketId: bracket.bracketId,
156
- bracketState: bracket.state,
157
- entryClientOrderId: bracket.entryCid,
158
- stopClientOrderId: bracket.slCid ?? null,
159
- exchangeOrderId: directProofRequired ? directProof?.algoId ?? null : stopOrder?.id ?? null,
160
- entrySide: bracket.entrySide,
161
- stopSide: exchangeSide ?? null,
162
- stopPrice: exchangeStopPrice ?? (Number.isFinite(bracket.stopPrice) ? bracket.stopPrice : null),
163
- bracketQuantity: Number.isFinite(bracket.qty) ? bracket.qty : null,
164
- closePosition,
165
- liveness,
166
- };
167
- const parsedStopCid = bracket.slCid ? parseBracketCid(bracket.slCid) : null;
168
- const expectedStopSide = expectation.entrySide === 'buy' ? 'sell' : 'buy';
169
- const expectedEntryCid = wave9ClientOrderId(expectation.candidateId);
170
- const quantityTolerance = 1e-9 * Math.max(1, expectation.currentPositionQuantity, expectation.filledQuantity, typeof bracket.qty === 'number' ? Math.abs(bracket.qty) : 0);
171
- const exactCurrentQuantity = nearlyEqual(expectation.currentPositionQuantity, expectation.filledQuantity);
172
- const bracketQuantityValid = typeof bracket.qty === 'number'
173
- && Number.isFinite(bracket.qty)
174
- && bracket.qty > 0
175
- && (expectation.requireExactPositionQuantity
176
- ? nearlyEqual(bracket.qty, expectation.filledQuantity)
177
- : bracket.qty + quantityTolerance >= expectation.currentPositionQuantity
178
- && bracket.qty <= expectation.filledQuantity + quantityTolerance);
179
- if (expectation.entryClientOrderId !== expectedEntryCid) {
180
- observation.reason = 'expected_entry_client_order_id_is_not_candidate_bound';
181
- }
182
- else if (bracket.state !== 'active' && bracket.state !== 'partial') {
183
- observation.reason = 'native_stop_bracket_not_active';
184
- }
185
- else if (bracket.entryCid !== expectation.entryClientOrderId) {
186
- observation.reason = 'native_stop_entry_client_order_id_mismatch';
187
- }
188
- else if (bracket.entrySide !== expectation.entrySide) {
189
- observation.reason = 'native_stop_entry_side_mismatch';
190
- }
191
- else if (!bracket.slCid || parsedStopCid?.role !== 'stop'
192
- || parsedStopCid.bracketId !== bracket.bracketId) {
193
- observation.reason = 'native_stop_client_order_id_invalid';
194
- }
195
- else if (typeof bracket.stopPrice !== 'number'
196
- || !Number.isFinite(bracket.stopPrice)
197
- || !nearlyEqual(bracket.stopPrice, expectation.stopPrice)) {
198
- observation.reason = 'native_stop_ledger_price_mismatch';
199
- }
200
- else if (expectation.currentPositionQuantity
201
- > expectation.filledQuantity + quantityTolerance
202
- || (expectation.requireExactPositionQuantity && !exactCurrentQuantity)) {
203
- observation.reason = 'native_stop_position_quantity_not_covered';
204
- }
205
- else if (!bracketQuantityValid) {
206
- observation.reason = 'native_stop_bracket_quantity_mismatch';
207
- }
208
- else if (directProofRequired && !directProof) {
209
- observation.reason = 'native_stop_exact_exchange_proof_unavailable';
210
- }
211
- else if (directProofRequired && directProof?.clientAlgoId !== bracket.slCid) {
212
- observation.reason = 'native_stop_exact_exchange_identity_mismatch';
213
- }
214
- else if (liveness !== 'live') {
215
- observation.reason = 'native_stop_exchange_liveness_unverified';
216
- }
217
- else if (!directProofRequired
218
- && (stopOrders.length !== 1 || !stopOrder || stopOrder.status !== 'open')) {
219
- observation.reason = 'native_stop_exchange_order_missing';
220
- }
221
- else if (!exchangeSymbol
222
- || canonicalSymbol(exchangeSymbol) !== canonicalSymbol(expectation.symbol)) {
223
- observation.reason = 'native_stop_exchange_symbol_mismatch';
224
- }
225
- else if (exchangeSide !== expectedStopSide) {
226
- observation.reason = 'native_stop_exchange_side_mismatch';
227
- }
228
- else if (orderType !== 'STOP_MARKET') {
229
- observation.reason = 'native_stop_exchange_type_mismatch';
230
- }
231
- else if (exchangeStopPrice === null
232
- || !exchangeStopPriceMatches(exchangeStopPrice, expectation.stopPrice)) {
233
- observation.reason = 'native_stop_exchange_price_mismatch';
234
- }
235
- else if (closePosition !== true) {
236
- observation.reason = 'native_stop_is_not_close_all_position';
237
- }
238
- else {
239
- observation.verified = true;
240
- observation.reason = 'verified_exchange_native_close_all_stop';
241
- }
242
- return observation;
243
- }
244
- /** One-shot post-fill confirmation used after the bracket row becomes active. */
245
- export async function confirmWave9LiveNativeStop(adapter, input) {
246
- if (!adapter.isLive || adapter.mode !== 'LIVE' || adapter.readiness !== 'READY')
247
- return false;
248
- const observation = await observeNativeStop(adapter, [], {
249
- ...input,
250
- currentPositionQuantity: input.filledQuantity,
251
- requireExactPositionQuantity: true,
252
- requireExchangeOrderDetails: false,
253
- });
254
- return observation.verified;
255
- }
256
- function validatePositions(positions) {
257
- for (const position of positions) {
258
- if (typeof position.symbol !== 'string' || position.symbol.length === 0) {
259
- throw new Error('Wave 9 live snapshot contains a malformed position symbol');
260
- }
261
- if (position.side !== 'long' && position.side !== 'short') {
262
- throw new Error(`Wave 9 live snapshot contains a malformed ${position.symbol} side`);
263
- }
264
- if (typeof position.contracts !== 'number'
265
- || !Number.isFinite(position.contracts)
266
- || position.contracts < 0) {
267
- throw new Error(`Wave 9 live snapshot contains malformed ${position.symbol} contracts`);
268
- }
269
- }
270
- }
271
- function isProtectiveOrder(order) {
272
- if (order.clientOrderId) {
273
- const parsed = parseBracketCid(order.clientOrderId);
274
- if (parsed?.role === 'stop' || parsed?.role === 'target')
275
- return true;
276
- }
277
- const info = order.info ?? {};
278
- if (info.reduceOnly === true || info.closePosition === true)
279
- return true;
280
- const orderType = String(info.orderType ?? info.type ?? '').toUpperCase();
281
- return Boolean((orderType === 'STOP_MARKET' || orderType === 'TAKE_PROFIT_MARKET')
282
- && (info.closePosition === true || info.reduceOnly === true));
283
- }
284
- function structuralPosition(position) {
285
- return {
286
- symbol: canonicalSymbol(position.symbol),
287
- side: position.side,
288
- contracts: position.contracts,
289
- entryPrice: position.entryPrice,
290
- };
291
- }
292
- function structuralOrder(order) {
293
- return {
294
- id: order.id,
295
- clientOrderId: order.clientOrderId ?? null,
296
- symbol: canonicalSymbol(order.symbol),
297
- side: order.side,
298
- type: order.type,
299
- amount: order.amount,
300
- filled: order.filled,
301
- price: order.price,
302
- };
303
- }
304
- function positionFingerprint(position) {
305
- const structural = {
306
- symbol: canonicalSymbol(position.symbol),
307
- side: position.side,
308
- quantity: position.quantity,
309
- entryPrice: position.entryPrice,
310
- stopPrice: position.stopPrice ?? null,
311
- missionId: position.missionId ?? null,
312
- setupType: position.setupType ?? null,
313
- candidateId: position.candidateId ?? null,
314
- strategy: position.strategy ?? null,
315
- openedAt: position.openedAt ?? null,
316
- nativeStop: position.nativeStop ?? null,
317
- };
318
- return createHash('sha256').update(JSON.stringify(structural)).digest('hex');
319
- }
320
- /**
321
- * Capture exchange-authoritative LIVE geometry without volatile mark prices in
322
- * the authorization fingerprint. Wallet cash, positions, pending
323
- * exposure-increasing orders, and durable Wave 9 identities are all bound.
324
- */
325
- export async function captureWave9LiveAccount(adapter, ledger, mode) {
326
- if (!adapter.isLive || mode !== 'LIVE' || adapter.mode !== 'LIVE') {
327
- throw new Error('Wave 9 live snapshot requires a LIVE adapter in LIVE mode');
328
- }
329
- if (adapter.readiness !== 'READY') {
330
- throw new Error(`Wave 9 live snapshot requires adapter READY (got ${adapter.readiness})`);
331
- }
332
- const [balance, positions, openOrders] = await Promise.all([
333
- adapter.getBalance(),
334
- adapter.getPositionsOrNull(),
335
- adapter.getOpenOrders(),
336
- ]);
337
- if (positions === null) {
338
- throw new Error('Wave 9 live position snapshot is unavailable');
339
- }
340
- validatePositions(positions);
341
- const cashEquityUsd = finitePositive(getQuoteWalletBalance(balance), 'wallet cash');
342
- const pendingExposureOrders = openOrders
343
- .filter((order) => order.status === 'open' && !isProtectiveOrder(order))
344
- .sort((left, right) => left.id.localeCompare(right.id));
345
- const observed = await Promise.all(positions
346
- .filter((position) => Number.isFinite(position.contracts) && position.contracts > 0)
347
- .map(async (position) => {
348
- const record = openWave9Record(ledger, position.symbol, position.side);
349
- const row = {
350
- symbol: position.symbol,
351
- side: position.side,
352
- quantity: finitePositive(position.contracts, `${position.symbol} contracts`),
353
- entryPrice: finitePositive(position.entryPrice, `${position.symbol} entry price`),
354
- markPrice: finitePositive(position.markPrice, `${position.symbol} mark price`),
355
- };
356
- if (!record)
357
- return row;
358
- const nativeStop = await observeNativeStop(adapter, openOrders, {
359
- candidateId: record.candidateId,
360
- symbol: position.symbol,
361
- entryClientOrderId: record.clientOrderId,
362
- entrySide: record.side,
363
- stopPrice: record.initialStop,
364
- filledQuantity: record.filledQuantity ?? record.quantity,
365
- currentPositionQuantity: position.contracts,
366
- requireExactPositionQuantity: false,
367
- requireExchangeOrderDetails: true,
368
- });
369
- row.initialStopPrice = record.initialStop;
370
- if (nativeStop.stopPrice !== null)
371
- row.stopPrice = nativeStop.stopPrice;
372
- row.missionId = record.missionId;
373
- row.setupType = WAVE9_BUNDLE_SETUP_TYPE;
374
- row.candidateId = record.candidateId;
375
- row.strategy = record.strategy;
376
- row.accruedFundingUsd = 0;
377
- row.openedAt = new Date(record.openedAt ?? record.attemptedAt).toISOString();
378
- row.nativeStop = nativeStop;
379
- row.positionFingerprint = positionFingerprint(row);
380
- return row;
381
- }));
382
- observed
383
- .sort((left, right) => canonicalSymbol(left.symbol).localeCompare(canonicalSymbol(right.symbol)));
384
- const executedCandidateIds = ledger.getExecutedCandidateIds().sort((a, b) => a.localeCompare(b));
385
- const ownedPositions = observed.filter((position) => position.candidateId);
386
- const nativeStopIssues = ownedPositions
387
- .filter((position) => position.nativeStop?.verified !== true)
388
- .map((position) => `${position.candidateId}:${position.nativeStop?.reason ?? 'native_stop_missing'}`)
389
- .sort((left, right) => left.localeCompare(right));
390
- const structural = {
391
- schema: 'wave9-live-account-v1',
392
- mode,
393
- walletCashUsd: cashEquityUsd,
394
- positions: positions
395
- .filter((position) => Number.isFinite(position.contracts) && position.contracts > 0)
396
- .map(structuralPosition)
397
- .sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right))),
398
- pendingExposureOrders: pendingExposureOrders.map(structuralOrder),
399
- wave9Identities: ledger.getAll().map((record) => ({
400
- candidateId: record.candidateId,
401
- missionId: record.missionId,
402
- symbol: record.symbol,
403
- side: record.side,
404
- quantity: record.quantity,
405
- initialStop: record.initialStop,
406
- state: record.state,
407
- })),
408
- wave9NativeStops: ownedPositions.map((position) => ({
409
- candidateId: position.candidateId,
410
- nativeStop: position.nativeStop ?? null,
411
- })),
412
- executedCandidateIds,
413
- };
414
- return {
415
- fingerprint: createHash('sha256').update(JSON.stringify(structural)).digest('hex'),
416
- cashEquityUsd,
417
- positions: observed,
418
- pendingExposureOrderCount: pendingExposureOrders.length,
419
- executedCandidateIds,
420
- nativeStopProtectionComplete: nativeStopIssues.length === 0,
421
- nativeStopIssues,
422
- authoritative: true,
423
- runtimeParity: false,
424
- provenance: 'live_exchange_structural_snapshot_and_durable_wave9_ledger',
425
- };
426
- }
427
- export async function captureWave9LivePosition(adapter, ledger, mode, symbol) {
428
- const account = await captureWave9LiveAccount(adapter, ledger, mode);
429
- const canonical = canonicalSymbol(symbol);
430
- const matches = account.positions.filter((position) => canonicalSymbol(position.symbol) === canonical && position.candidateId);
431
- if (matches.length !== 1 || !matches[0].positionFingerprint) {
432
- throw new Error(`Wave 9 live position snapshot requires exactly one durable ${canonical} position`);
433
- }
434
- return { fingerprint: matches[0].positionFingerprint, position: matches[0] };
435
- }
@@ -1,39 +0,0 @@
1
- import type { IExchangeAdapter } from '../exchange-adapter.js';
2
- import type { Wave9LiveExecutionLedger } from './live-execution-ledger.js';
3
- import { type Wave9LiveFlatConfirmation, type Wave9LiveFlatConfirmationOptions } from './live-position-confirmation.js';
4
- import { reprotectWave9LiveResidual, type Wave9LiveResidualProtectionResult } from './live-residual-protection.js';
5
- export interface Wave9LiveFlatRecoveryResult {
6
- status: 'flat';
7
- detail: string;
8
- candidateId: string;
9
- symbol: string;
10
- }
11
- export type Wave9LiveAutonomousProtectionResult = Wave9LiveFlatRecoveryResult | Wave9LiveResidualProtectionResult;
12
- /** Test seams are optional; production callers always use the exact defaults. */
13
- export interface Wave9LiveAutonomousProtectionOptions {
14
- flatConfirmation?: Wave9LiveFlatConfirmationOptions;
15
- confirmFlat?: (adapter: IExchangeAdapter, symbol: string, options?: Wave9LiveFlatConfirmationOptions) => Promise<Wave9LiveFlatConfirmation>;
16
- reprotect?: typeof reprotectWave9LiveResidual;
17
- /**
18
- * Optional crash-recovery identity fence. Startup reconciliation supplies
19
- * this after binding the durable candidate to its exact exchange entry CID.
20
- * It is re-evaluated immediately before every operation that may cancel,
21
- * replace, or close same-symbol exposure. A failed/unknown fence leaves the
22
- * durable row unresolved and performs no exchange mutation.
23
- */
24
- authorizeExposureMutation?: () => Promise<{
25
- authorized: boolean;
26
- detail: string;
27
- }>;
28
- }
29
- /**
30
- * Resolve a Wave 9 LIVE exposure after a close acknowledgement or a native
31
- * stop-loss event. The only successful terminal state is stable exchange
32
- * flatness persisted to the durable execution ledger. Otherwise the exact
33
- * frozen candidate stop is proven/re-armed. If that cannot be done, issue one
34
- * emergency reduce-only close, prove flatness again, and make one final
35
- * re-protection attempt for any residual. Every unresolved state stays OPEN.
36
- *
37
- * The caller must hold the shared trading-operation lock for the whole call.
38
- */
39
- export declare function recoverWave9LiveExposure(adapter: IExchangeAdapter, executionLedger: Wave9LiveExecutionLedger, candidateId: string, symbol: string, options?: Wave9LiveAutonomousProtectionOptions): Promise<Wave9LiveAutonomousProtectionResult>;