@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,498 +0,0 @@
1
- // Durable Wave 9 live-execution identity and replay ledger.
2
- //
3
- // A live market-order outcome can become ambiguous across a process crash: the
4
- // exchange may have accepted the order even when the local caller never saw the
5
- // acknowledgement. Therefore an attempt is persisted before submission and is
6
- // permanently treated as executed for same-event replay prevention. Terminal
7
- // rows are retained so a restart cannot forget a candidate that already ran.
8
- import { createHash } from 'node:crypto';
9
- import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
10
- import { join } from 'node:path';
11
- import { DAY_MS, WAVE9_LONG_STRATEGY, WAVE9_SHORT_STRATEGY, WAVE9_SYMBOL_PRIORITY, } from '../portfolio/wave9-policy.js';
12
- import { resolvePluginsBaseDir } from '../util/plugin-paths.js';
13
- const DEFAULT_PLUGIN_ID = 'reefclaw-paper-trading';
14
- const LEDGER_FILENAME = 'wave9-live-execution-ledger.json';
15
- const SCHEMA_VERSION = 1;
16
- const MAX_TEXT_LENGTH = 512;
17
- const CLIENT_ORDER_ID_PATTERN = /^w9e[a-f0-9]{32}$/;
18
- /** Stable Binance-compatible client order id (35 chars; Binance max is 36). */
19
- export function wave9ClientOrderId(candidateId) {
20
- requireText(candidateId, 'candidateId');
21
- return `w9e${createHash('sha256').update(candidateId).digest('hex').slice(0, 32)}`;
22
- }
23
- /** Backwards-compatible descriptive alias. */
24
- export const wave9LiveClientOrderId = wave9ClientOrderId;
25
- /** Stable Wave 9 mission identity, mirrored from the status authorization path. */
26
- function expectedMissionId(candidateId) {
27
- return `wave9_${createHash('sha256').update(candidateId).digest('hex').slice(0, 32)}`;
28
- }
29
- function canonicalSymbol(value) {
30
- requireText(value, 'symbol');
31
- return value.toUpperCase().replace(/[^A-Z0-9]/g, '').replace(/USDTUSDT$/, 'USDT');
32
- }
33
- function requireText(value, label) {
34
- if (typeof value !== 'string'
35
- || value.length === 0
36
- || value.length > MAX_TEXT_LENGTH
37
- || value.trim() !== value) {
38
- throw new Error(`wave9-live-execution-ledger: ${label} is malformed`);
39
- }
40
- }
41
- function requirePositiveFinite(value, label) {
42
- if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
43
- throw new Error(`wave9-live-execution-ledger: ${label} must be positive and finite`);
44
- }
45
- }
46
- function requireTimestamp(value, label) {
47
- if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) {
48
- throw new Error(`wave9-live-execution-ledger: ${label} must be a non-negative safe integer`);
49
- }
50
- }
51
- function isRecord(value) {
52
- return typeof value === 'object' && value !== null && !Array.isArray(value);
53
- }
54
- function assertExactKeys(value, required, optional, label) {
55
- const allowed = new Set([...required, ...optional]);
56
- for (const key of required) {
57
- if (!(key in value))
58
- throw new Error(`wave9-live-execution-ledger: ${label} missing ${key}`);
59
- }
60
- for (const key of Object.keys(value)) {
61
- if (!allowed.has(key))
62
- throw new Error(`wave9-live-execution-ledger: ${label} has unknown field ${key}`);
63
- }
64
- }
65
- function cloneRecord(record) {
66
- return { ...record };
67
- }
68
- function sameOptional(left, right) {
69
- return left === right;
70
- }
71
- export class Wave9LiveExecutionLedger {
72
- filePath;
73
- dir;
74
- now;
75
- entries = new Map();
76
- constructor(options = {}) {
77
- const base = resolvePluginsBaseDir(options.basePath);
78
- this.dir = join(base, options.pluginId ?? DEFAULT_PLUGIN_ID);
79
- this.filePath = join(this.dir, LEDGER_FILENAME);
80
- this.now = options.now ?? Date.now;
81
- if (!existsSync(this.dir))
82
- mkdirSync(this.dir, { recursive: true });
83
- this.loadOrInit();
84
- }
85
- /**
86
- * Persist an execution attempt before exchange submission. Repeating the
87
- * exact immutable authorization is idempotent; any mismatch fails closed.
88
- */
89
- recordAttempt(input) {
90
- const normalized = this.validateAttemptInput(input);
91
- const existing = this.entries.get(normalized.candidateId);
92
- if (existing) {
93
- if (!this.sameAttempt(existing, normalized)) {
94
- throw new Error(`wave9-live-execution-ledger: candidate ${normalized.candidateId} already exists with different authorization`);
95
- }
96
- return cloneRecord(existing);
97
- }
98
- const attemptedAt = this.currentTimestamp('attemptedAt');
99
- const record = {
100
- ...normalized,
101
- state: 'attempted',
102
- attemptedAt,
103
- updatedAt: attemptedAt,
104
- };
105
- if ([...this.entries.values()].some((row) => row.clientOrderId === record.clientOrderId)) {
106
- throw new Error('wave9-live-execution-ledger: deterministic clientOrderId collision');
107
- }
108
- this.entries.set(record.candidateId, record);
109
- this.persist();
110
- return cloneRecord(record);
111
- }
112
- /** Mark a confirmed fill. Repeating the exact confirmation is idempotent. */
113
- markOpen(candidateId, input = {}) {
114
- requireText(candidateId, 'candidateId');
115
- const existing = this.requireCandidate(candidateId);
116
- const normalized = this.validateOpenInput(existing, input);
117
- if (existing.state === 'closed') {
118
- throw new Error(`wave9-live-execution-ledger: closed candidate ${candidateId} cannot reopen`);
119
- }
120
- if (existing.state === 'open') {
121
- if (!sameOptional(existing.filledQuantity, normalized.filledQuantity)
122
- || !sameOptional(existing.entryPrice, normalized.entryPrice)
123
- || !sameOptional(existing.exchangeOrderId, normalized.exchangeOrderId)) {
124
- throw new Error(`wave9-live-execution-ledger: candidate ${candidateId} already open with different fill`);
125
- }
126
- return cloneRecord(existing);
127
- }
128
- const openedAt = this.currentTimestamp('openedAt');
129
- if (openedAt < existing.attemptedAt) {
130
- throw new Error('wave9-live-execution-ledger: openedAt precedes attemptedAt');
131
- }
132
- const updated = {
133
- ...existing,
134
- ...normalized,
135
- state: 'open',
136
- openedAt,
137
- updatedAt: openedAt,
138
- };
139
- this.entries.set(candidateId, updated);
140
- this.persist();
141
- return cloneRecord(updated);
142
- }
143
- /**
144
- * Enrich an already-OPEN row after an exact deterministic entry lookup has
145
- * proven the order terminal. This is deliberately narrower than markOpen:
146
- * the final fill may populate a previously missing value or increase a
147
- * crash-time partial fill, but it can never decrease, exceed authorization,
148
- * or replace an already-bound exchange order identity.
149
- */
150
- reconcileOpenFillFromExactOrder(candidateId, input) {
151
- requireText(candidateId, 'candidateId');
152
- const existing = this.requireCandidate(candidateId);
153
- if (existing.state !== 'open') {
154
- throw new Error(`wave9-live-execution-ledger: exact-order fill reconciliation requires OPEN candidate ${candidateId}`);
155
- }
156
- if (!isRecord(input)) {
157
- throw new Error('wave9-live-execution-ledger: exact-order fill is not an object');
158
- }
159
- assertExactKeys(input, ['filledQuantity', 'exchangeOrderId'], ['entryPrice'], 'exact-order fill');
160
- requirePositiveFinite(input.filledQuantity, 'filledQuantity');
161
- if (input.filledQuantity > existing.quantity) {
162
- throw new Error('wave9-live-execution-ledger: exact-order fill exceeds authorized quantity');
163
- }
164
- requireText(input.exchangeOrderId, 'exchangeOrderId');
165
- if (existing.exchangeOrderId !== undefined
166
- && existing.exchangeOrderId !== input.exchangeOrderId) {
167
- throw new Error('wave9-live-execution-ledger: exact-order exchangeOrderId disagrees with durable identity');
168
- }
169
- if (existing.filledQuantity !== undefined
170
- && input.filledQuantity < existing.filledQuantity) {
171
- throw new Error('wave9-live-execution-ledger: exact-order fill cannot decrease');
172
- }
173
- if (input.entryPrice !== undefined) {
174
- this.validateOpenInput(existing, { entryPrice: input.entryPrice });
175
- if (existing.filledQuantity === input.filledQuantity
176
- && existing.entryPrice !== undefined
177
- && existing.entryPrice !== input.entryPrice) {
178
- throw new Error('wave9-live-execution-ledger: exact-order entryPrice changed without a larger final fill');
179
- }
180
- }
181
- const nextEntryPrice = input.entryPrice ?? existing.entryPrice;
182
- const unchanged = existing.filledQuantity === input.filledQuantity
183
- && existing.exchangeOrderId === input.exchangeOrderId
184
- && existing.entryPrice === nextEntryPrice;
185
- if (unchanged)
186
- return cloneRecord(existing);
187
- const updatedAt = this.currentTimestamp('updatedAt');
188
- if (updatedAt < (existing.openedAt ?? existing.attemptedAt)) {
189
- throw new Error('wave9-live-execution-ledger: updatedAt precedes the execution lifecycle');
190
- }
191
- const updated = {
192
- ...existing,
193
- filledQuantity: input.filledQuantity,
194
- exchangeOrderId: input.exchangeOrderId,
195
- ...(nextEntryPrice !== undefined ? { entryPrice: nextEntryPrice } : {}),
196
- updatedAt,
197
- };
198
- this.entries.set(candidateId, updated);
199
- try {
200
- this.persist();
201
- }
202
- catch (error) {
203
- // Do not let a failed disk replace make this process believe a final
204
- // fill that the next process cannot load.
205
- this.entries.set(candidateId, existing);
206
- throw error;
207
- }
208
- return cloneRecord(updated);
209
- }
210
- /** Mark an attempted/open record terminal. Terminal rows are never deleted. */
211
- markClosed(candidateId) {
212
- requireText(candidateId, 'candidateId');
213
- const existing = this.requireCandidate(candidateId);
214
- if (existing.state === 'closed')
215
- return cloneRecord(existing);
216
- const closedAt = this.currentTimestamp('closedAt');
217
- if (closedAt < existing.attemptedAt || (existing.openedAt !== undefined && closedAt < existing.openedAt)) {
218
- throw new Error('wave9-live-execution-ledger: closedAt precedes the execution lifecycle');
219
- }
220
- const updated = {
221
- ...existing,
222
- state: 'closed',
223
- closedAt,
224
- updatedAt: closedAt,
225
- };
226
- this.entries.set(candidateId, updated);
227
- this.persist();
228
- return cloneRecord(updated);
229
- }
230
- getByCandidateId(candidateId) {
231
- const record = this.entries.get(candidateId);
232
- return record ? cloneRecord(record) : undefined;
233
- }
234
- /**
235
- * Latest confirmed-open row matching an exchange position.
236
- *
237
- * An `attempted` row is a durable replay tombstone: the exchange outcome
238
- * may be ambiguous, so the candidate must never execute again, but the row
239
- * is not proof that a later same-symbol/same-side position belongs to Wave 9.
240
- * Only `markOpen()` establishes durable position ownership.
241
- */
242
- findLatestForPosition(symbol, side) {
243
- const canonical = canonicalSymbol(symbol);
244
- if (side !== 'long' && side !== 'short' && side !== 'buy' && side !== 'sell') {
245
- throw new Error('wave9-live-execution-ledger: position side is malformed');
246
- }
247
- const orderSide = side === 'long' || side === 'buy' ? 'buy' : 'sell';
248
- const matches = [...this.entries.values()].filter((row) => row.state === 'open' && row.symbol === canonical && row.side === orderSide);
249
- matches.sort((left, right) => right.attemptedAt - left.attemptedAt
250
- || right.updatedAt - left.updatedAt
251
- || right.candidateId.localeCompare(left.candidateId));
252
- return matches[0] ? cloneRecord(matches[0]) : undefined;
253
- }
254
- /** Attempts count as executed because exchange outcome can be crash-ambiguous. */
255
- getExecutedCandidateIds() {
256
- return [...this.entries.keys()].sort((left, right) => left.localeCompare(right));
257
- }
258
- getAll() {
259
- return [...this.entries.values()]
260
- .sort((left, right) => left.attemptedAt - right.attemptedAt
261
- || left.candidateId.localeCompare(right.candidateId))
262
- .map(cloneRecord);
263
- }
264
- getFilePath() {
265
- return this.filePath;
266
- }
267
- currentTimestamp(label) {
268
- const value = this.now();
269
- requireTimestamp(value, label);
270
- return value;
271
- }
272
- requireCandidate(candidateId) {
273
- const record = this.entries.get(candidateId);
274
- if (!record)
275
- throw new Error(`wave9-live-execution-ledger: unknown candidate ${candidateId}`);
276
- return record;
277
- }
278
- validateAttemptInput(input) {
279
- if (!isRecord(input))
280
- throw new Error('wave9-live-execution-ledger: attempt is not an object');
281
- assertExactKeys(input, [
282
- 'candidateId', 'missionId', 'eventTime', 'symbol', 'strategy',
283
- 'direction', 'side', 'quantity', 'initialStop', 'clientOrderId',
284
- ], [], 'attempt');
285
- requireText(input.candidateId, 'candidateId');
286
- requireText(input.missionId, 'missionId');
287
- requireText(input.eventTime, 'eventTime');
288
- const eventMs = Date.parse(input.eventTime);
289
- if (!Number.isFinite(eventMs)
290
- || new Date(eventMs).toISOString() !== input.eventTime
291
- || eventMs % DAY_MS !== 0) {
292
- throw new Error('wave9-live-execution-ledger: eventTime must be a UTC daily boundary');
293
- }
294
- const symbol = canonicalSymbol(input.symbol);
295
- if (!WAVE9_SYMBOL_PRIORITY.includes(symbol)) {
296
- throw new Error(`wave9-live-execution-ledger: unsupported Wave 9 symbol ${symbol}`);
297
- }
298
- if (input.strategy !== WAVE9_LONG_STRATEGY && input.strategy !== WAVE9_SHORT_STRATEGY) {
299
- throw new Error('wave9-live-execution-ledger: unsupported Wave 9 strategy');
300
- }
301
- if (input.direction !== 'LONG' && input.direction !== 'SHORT') {
302
- throw new Error('wave9-live-execution-ledger: direction is malformed');
303
- }
304
- if (input.side !== 'buy' && input.side !== 'sell') {
305
- throw new Error('wave9-live-execution-ledger: side is malformed');
306
- }
307
- const expectedDirection = input.strategy === WAVE9_LONG_STRATEGY ? 'LONG' : 'SHORT';
308
- const expectedSide = expectedDirection === 'LONG' ? 'buy' : 'sell';
309
- if (input.direction !== expectedDirection || input.side !== expectedSide) {
310
- throw new Error('wave9-live-execution-ledger: strategy, direction, and side disagree');
311
- }
312
- const expectedCandidateId = `${input.eventTime}|${symbol}|${input.strategy}|${input.direction}`;
313
- if (input.candidateId !== expectedCandidateId) {
314
- throw new Error('wave9-live-execution-ledger: candidateId does not match its frozen identity');
315
- }
316
- if (input.missionId !== expectedMissionId(input.candidateId)) {
317
- throw new Error('wave9-live-execution-ledger: missionId does not match candidateId');
318
- }
319
- requirePositiveFinite(input.quantity, 'quantity');
320
- requirePositiveFinite(input.initialStop, 'initialStop');
321
- requireText(input.clientOrderId, 'clientOrderId');
322
- if (!CLIENT_ORDER_ID_PATTERN.test(input.clientOrderId)
323
- || input.clientOrderId !== wave9ClientOrderId(input.candidateId)) {
324
- throw new Error('wave9-live-execution-ledger: clientOrderId is not deterministic');
325
- }
326
- return {
327
- ...input,
328
- symbol,
329
- };
330
- }
331
- validateOpenInput(record, input) {
332
- if (!isRecord(input))
333
- throw new Error('wave9-live-execution-ledger: open confirmation is not an object');
334
- assertExactKeys(input, [], ['filledQuantity', 'entryPrice', 'exchangeOrderId'], 'open confirmation');
335
- if (input.filledQuantity !== undefined) {
336
- requirePositiveFinite(input.filledQuantity, 'filledQuantity');
337
- if (input.filledQuantity > record.quantity * (1 + 1e-9)) {
338
- throw new Error('wave9-live-execution-ledger: filledQuantity exceeds authorized quantity');
339
- }
340
- }
341
- if (input.entryPrice !== undefined) {
342
- requirePositiveFinite(input.entryPrice, 'entryPrice');
343
- if ((record.direction === 'LONG' && record.initialStop >= input.entryPrice)
344
- || (record.direction === 'SHORT' && record.initialStop <= input.entryPrice)) {
345
- throw new Error('wave9-live-execution-ledger: fill/initial-stop geometry is invalid');
346
- }
347
- }
348
- if (input.exchangeOrderId !== undefined)
349
- requireText(input.exchangeOrderId, 'exchangeOrderId');
350
- return { ...input };
351
- }
352
- sameAttempt(existing, input) {
353
- return existing.candidateId === input.candidateId
354
- && existing.missionId === input.missionId
355
- && existing.eventTime === input.eventTime
356
- && existing.symbol === input.symbol
357
- && existing.strategy === input.strategy
358
- && existing.direction === input.direction
359
- && existing.side === input.side
360
- && existing.quantity === input.quantity
361
- && existing.initialStop === input.initialStop
362
- && existing.clientOrderId === input.clientOrderId
363
- && existing.clientOrderId === wave9ClientOrderId(input.candidateId);
364
- }
365
- loadOrInit() {
366
- if (!existsSync(this.filePath))
367
- return;
368
- let parsed;
369
- try {
370
- parsed = JSON.parse(readFileSync(this.filePath, 'utf8'));
371
- }
372
- catch (error) {
373
- throw new Error(`wave9-live-execution-ledger: failed to read valid JSON from ${this.filePath}: ${error instanceof Error ? error.message : String(error)}`);
374
- }
375
- const file = this.validateFile(parsed);
376
- const clientOrderIds = new Set();
377
- for (const entry of file.entries) {
378
- if (this.entries.has(entry.candidateId)) {
379
- throw new Error(`wave9-live-execution-ledger: duplicate candidate ${entry.candidateId}`);
380
- }
381
- if (clientOrderIds.has(entry.clientOrderId)) {
382
- throw new Error(`wave9-live-execution-ledger: duplicate clientOrderId ${entry.clientOrderId}`);
383
- }
384
- this.entries.set(entry.candidateId, entry);
385
- clientOrderIds.add(entry.clientOrderId);
386
- }
387
- }
388
- persist() {
389
- const file = {
390
- schemaVersion: SCHEMA_VERSION,
391
- entries: this.getAll(),
392
- };
393
- const tempPath = `${this.filePath}.tmp`;
394
- writeFileSync(tempPath, JSON.stringify(file, null, 2), { mode: 0o600 });
395
- renameSync(tempPath, this.filePath);
396
- }
397
- validateFile(raw) {
398
- if (!isRecord(raw))
399
- throw new Error('wave9-live-execution-ledger: file root is not an object');
400
- assertExactKeys(raw, ['schemaVersion', 'entries'], [], 'file');
401
- if (raw.schemaVersion !== SCHEMA_VERSION) {
402
- throw new Error(`wave9-live-execution-ledger: unsupported schemaVersion ${String(raw.schemaVersion)} (expected ${SCHEMA_VERSION})`);
403
- }
404
- if (!Array.isArray(raw.entries)) {
405
- throw new Error('wave9-live-execution-ledger: entries is not an array');
406
- }
407
- return {
408
- schemaVersion: SCHEMA_VERSION,
409
- entries: raw.entries.map((entry) => this.validateStoredRecord(entry)),
410
- };
411
- }
412
- validateStoredRecord(raw) {
413
- if (!isRecord(raw))
414
- throw new Error('wave9-live-execution-ledger: stored entry is not an object');
415
- assertExactKeys(raw, [
416
- 'candidateId', 'missionId', 'eventTime', 'symbol', 'strategy', 'direction',
417
- 'side', 'quantity', 'initialStop', 'clientOrderId', 'state',
418
- 'attemptedAt', 'updatedAt',
419
- ], ['openedAt', 'closedAt', 'filledQuantity', 'entryPrice', 'exchangeOrderId'], 'stored entry');
420
- const attempt = this.validateAttemptInput({
421
- candidateId: raw.candidateId,
422
- missionId: raw.missionId,
423
- eventTime: raw.eventTime,
424
- symbol: raw.symbol,
425
- strategy: raw.strategy,
426
- direction: raw.direction,
427
- side: raw.side,
428
- quantity: raw.quantity,
429
- initialStop: raw.initialStop,
430
- clientOrderId: raw.clientOrderId,
431
- });
432
- requireText(raw.clientOrderId, 'clientOrderId');
433
- if (!CLIENT_ORDER_ID_PATTERN.test(raw.clientOrderId)
434
- || raw.clientOrderId !== wave9ClientOrderId(attempt.candidateId)) {
435
- throw new Error('wave9-live-execution-ledger: clientOrderId is not deterministic');
436
- }
437
- if (raw.state !== 'attempted' && raw.state !== 'open' && raw.state !== 'closed') {
438
- throw new Error('wave9-live-execution-ledger: state is malformed');
439
- }
440
- requireTimestamp(raw.attemptedAt, 'attemptedAt');
441
- requireTimestamp(raw.updatedAt, 'updatedAt');
442
- if (raw.updatedAt < raw.attemptedAt) {
443
- throw new Error('wave9-live-execution-ledger: updatedAt precedes attemptedAt');
444
- }
445
- const openInput = this.validateOpenInput(attempt, {
446
- ...(raw.filledQuantity !== undefined ? { filledQuantity: raw.filledQuantity } : {}),
447
- ...(raw.entryPrice !== undefined ? { entryPrice: raw.entryPrice } : {}),
448
- ...(raw.exchangeOrderId !== undefined ? { exchangeOrderId: raw.exchangeOrderId } : {}),
449
- });
450
- if (raw.openedAt !== undefined)
451
- requireTimestamp(raw.openedAt, 'openedAt');
452
- if (raw.closedAt !== undefined)
453
- requireTimestamp(raw.closedAt, 'closedAt');
454
- if (raw.state === 'attempted'
455
- && (raw.openedAt !== undefined || raw.closedAt !== undefined || Object.keys(openInput).length > 0)) {
456
- throw new Error('wave9-live-execution-ledger: attempted entry contains fill/terminal fields');
457
- }
458
- if (raw.state === 'open' && raw.openedAt === undefined) {
459
- throw new Error('wave9-live-execution-ledger: open entry is missing openedAt');
460
- }
461
- if (raw.state === 'open' && raw.closedAt !== undefined) {
462
- throw new Error('wave9-live-execution-ledger: open entry contains closedAt');
463
- }
464
- if (raw.state === 'closed' && raw.closedAt === undefined) {
465
- throw new Error('wave9-live-execution-ledger: closed entry is missing closedAt');
466
- }
467
- if (raw.openedAt !== undefined && raw.openedAt < raw.attemptedAt) {
468
- throw new Error('wave9-live-execution-ledger: openedAt precedes attemptedAt');
469
- }
470
- if (raw.closedAt !== undefined
471
- && (raw.closedAt < raw.attemptedAt
472
- || (raw.openedAt !== undefined && raw.closedAt < raw.openedAt))) {
473
- throw new Error('wave9-live-execution-ledger: closedAt precedes the execution lifecycle');
474
- }
475
- if (Object.keys(openInput).length > 0 && raw.openedAt === undefined) {
476
- throw new Error('wave9-live-execution-ledger: fill fields require openedAt');
477
- }
478
- if (raw.state === 'attempted' && raw.updatedAt !== raw.attemptedAt) {
479
- throw new Error('wave9-live-execution-ledger: updatedAt does not match attemptedAt');
480
- }
481
- if (raw.state === 'open' && raw.updatedAt < raw.openedAt) {
482
- throw new Error('wave9-live-execution-ledger: OPEN updatedAt precedes openedAt');
483
- }
484
- if (raw.state === 'closed' && raw.updatedAt !== raw.closedAt) {
485
- throw new Error('wave9-live-execution-ledger: CLOSED updatedAt does not match closedAt');
486
- }
487
- return {
488
- ...attempt,
489
- clientOrderId: raw.clientOrderId,
490
- state: raw.state,
491
- attemptedAt: raw.attemptedAt,
492
- updatedAt: raw.updatedAt,
493
- ...(raw.openedAt !== undefined ? { openedAt: raw.openedAt } : {}),
494
- ...(raw.closedAt !== undefined ? { closedAt: raw.closedAt } : {}),
495
- ...openInput,
496
- };
497
- }
498
- }
@@ -1,18 +0,0 @@
1
- import type { IExchangeAdapter } from '../exchange-adapter.js';
2
- export interface Wave9LiveFlatConfirmation {
3
- confirmed: boolean;
4
- detail: string;
5
- }
6
- export interface Wave9LiveFlatConfirmationOptions {
7
- attempts?: number;
8
- delayMs?: number;
9
- requiredFlatSnapshots?: number;
10
- minStableMs?: number;
11
- now?: () => number;
12
- }
13
- /**
14
- * Confirm a symbol is absent from a trusted exchange position snapshot.
15
- * A close-order response is not sufficient: partial fills, asynchronous
16
- * settlement, malformed rows, and failed reads all remain non-terminal.
17
- */
18
- export declare function confirmWave9LivePositionFlat(adapter: IExchangeAdapter, symbol: string, options?: Wave9LiveFlatConfirmationOptions): Promise<Wave9LiveFlatConfirmation>;
@@ -1,111 +0,0 @@
1
- import { formatError } from '../logger.js';
2
- const DEFAULT_ATTEMPTS = 16;
3
- const DEFAULT_DELAY_MS = 250;
4
- const DEFAULT_REQUIRED_FLAT_SNAPSHOTS = 3;
5
- const DEFAULT_MIN_STABLE_MS = 1_000;
6
- function canonicalSymbol(value) {
7
- return value.toUpperCase().replace(/[^A-Z0-9]/g, '').replace(/USDTUSDT$/, 'USDT');
8
- }
9
- function wait(delayMs) {
10
- return new Promise((resolve) => setTimeout(resolve, delayMs));
11
- }
12
- /**
13
- * Confirm a symbol is absent from a trusted exchange position snapshot.
14
- * A close-order response is not sufficient: partial fills, asynchronous
15
- * settlement, malformed rows, and failed reads all remain non-terminal.
16
- */
17
- export async function confirmWave9LivePositionFlat(adapter, symbol, options = {}) {
18
- const target = canonicalSymbol(symbol);
19
- const attempts = options.attempts ?? DEFAULT_ATTEMPTS;
20
- const delayMs = options.delayMs ?? DEFAULT_DELAY_MS;
21
- const requiredFlatSnapshots = options.requiredFlatSnapshots ?? DEFAULT_REQUIRED_FLAT_SNAPSHOTS;
22
- const minStableMs = options.minStableMs ?? DEFAULT_MIN_STABLE_MS;
23
- const now = options.now ?? Date.now;
24
- if (!Number.isInteger(attempts) || attempts <= 0) {
25
- throw new Error('Wave 9 LIVE flat confirmation attempts must be a positive integer');
26
- }
27
- if (!Number.isFinite(delayMs) || delayMs < 0) {
28
- throw new Error('Wave 9 LIVE flat confirmation delay must be finite and non-negative');
29
- }
30
- if (!Number.isInteger(requiredFlatSnapshots) || requiredFlatSnapshots < 2) {
31
- throw new Error('Wave 9 LIVE flat confirmation requires at least two stable snapshots');
32
- }
33
- if (!Number.isFinite(minStableMs) || minStableMs < 0) {
34
- throw new Error('Wave 9 LIVE flat confirmation stable window must be finite and non-negative');
35
- }
36
- if (attempts < requiredFlatSnapshots) {
37
- throw new Error('Wave 9 LIVE flat confirmation attempts cannot be shorter than its stable streak');
38
- }
39
- let detail = 'no trusted position snapshot was returned';
40
- let consecutiveFlatSnapshots = 0;
41
- let flatSince;
42
- for (let attempt = 0; attempt < attempts; attempt += 1) {
43
- let trustedFlat = false;
44
- try {
45
- const positions = await adapter.getPositionsOrNull(symbol);
46
- if (Array.isArray(positions)) {
47
- let malformed = false;
48
- let residualContracts = 0;
49
- for (const position of positions) {
50
- if (!position
51
- || typeof position.symbol !== 'string'
52
- || typeof position.contracts !== 'number'
53
- || !Number.isFinite(position.contracts)) {
54
- malformed = true;
55
- continue;
56
- }
57
- if (canonicalSymbol(position.symbol) === target) {
58
- residualContracts += Math.abs(position.contracts);
59
- }
60
- }
61
- if (!malformed && residualContracts > 0) {
62
- return {
63
- confirmed: false,
64
- detail: `exchange still reports ${residualContracts} contracts`,
65
- };
66
- }
67
- if (!malformed && residualContracts === 0) {
68
- const observedAt = now();
69
- if (!Number.isFinite(observedAt)) {
70
- throw new Error('flat confirmation clock returned a non-finite timestamp');
71
- }
72
- if (flatSince !== undefined && observedAt < flatSince) {
73
- throw new Error('flat confirmation clock moved backwards');
74
- }
75
- trustedFlat = true;
76
- if (consecutiveFlatSnapshots === 0)
77
- flatSince = observedAt;
78
- consecutiveFlatSnapshots += 1;
79
- const stableForMs = observedAt - (flatSince ?? observedAt);
80
- detail = `trusted flat streak ${consecutiveFlatSnapshots}/${requiredFlatSnapshots} ` +
81
- `stable for ${stableForMs}/${minStableMs}ms`;
82
- if (consecutiveFlatSnapshots >= requiredFlatSnapshots && stableForMs >= minStableMs) {
83
- return {
84
- confirmed: true,
85
- detail: `trusted exchange position snapshot remained flat across ` +
86
- `${consecutiveFlatSnapshots} reads for ${stableForMs}ms`,
87
- };
88
- }
89
- }
90
- if (!trustedFlat) {
91
- detail = malformed
92
- ? 'exchange position snapshot contained malformed rows'
93
- : `exchange still reports ${residualContracts} contracts`;
94
- }
95
- }
96
- else {
97
- detail = 'exchange position state is unknown';
98
- }
99
- }
100
- catch (err) {
101
- detail = `position confirmation failed: ${formatError(err)}`;
102
- }
103
- if (!trustedFlat) {
104
- consecutiveFlatSnapshots = 0;
105
- flatSince = undefined;
106
- }
107
- if (attempt + 1 < attempts)
108
- await wait(delayMs);
109
- }
110
- return { confirmed: false, detail };
111
- }
@@ -1,18 +0,0 @@
1
- import type { IExchangeAdapter } from '../exchange-adapter.js';
2
- import type { Wave9LiveExecutionLedger } from './live-execution-ledger.js';
3
- export interface Wave9LiveResidualProtectionResult {
4
- status: 'protected' | 'manual_intervention';
5
- detail: string;
6
- candidateId: string;
7
- symbol: string;
8
- stopPrice: number;
9
- residualQuantity?: number;
10
- stopClientOrderId?: string;
11
- }
12
- /**
13
- * Re-arm the exact frozen Wave 9 stop after a reduce-only close leaves a
14
- * residual. Success means one current residual was observed and its newly
15
- * candidate-bound native close-all STOP_MARKET was proven by exact CID.
16
- * Every unverifiable state remains OPEN and escalates manual intervention.
17
- */
18
- export declare function reprotectWave9LiveResidual(adapter: IExchangeAdapter, executionLedger: Wave9LiveExecutionLedger, candidateId: string, symbol: string): Promise<Wave9LiveResidualProtectionResult>;