@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,399 +0,0 @@
1
- // Tool: attach_brackets — bootstrap exchange-side protection on an existing
2
- // open live position that is currently naked (no STOP_MARKET / TAKE_PROFIT_MARKET
3
- // order). Complements modify_stop / modify_target, which can only MOVE an
4
- // already-active bracket — they can't attach one from nothing.
5
- //
6
- // Why this tool exists (2026-04-21 naked-position incident): kill-switch
7
- // sweeps were stripping bracket protective orders off open positions without
8
- // flattening them. The agent then had no recovery path because modify_*
9
- // requires state ∈ {active, partial}. This tool + the bracket-preserving
10
- // cancel filter in BinancePrivateApi together close the loop.
11
- //
12
- // Responsibilities:
13
- // 1. Validate inputs + mode (live only, brackets enabled).
14
- // 2. Confirm an open position exists with >0 contracts.
15
- // 3. Sanity-check stop / target direction vs the position side.
16
- // 4. Reject if a fresh bracket is already active (caller wants modify_*).
17
- // 5. Clear any stale bracket orders on the exchange for this symbol.
18
- // 6. Register a new bracket + attach it. Retries inherit BracketManager policy.
19
- //
20
- // Paper mode: rejected with an explanatory error (paper uses per-position
21
- // metadata + stop-watcher, not exchange orders).
22
- import { generateBracketId, buildBracketCid } from '../live/bracket-id.js';
23
- import { validateStopDirection, validateTargetDirection } from '../live/bracket-params.js';
24
- import { formatError, logger } from '../logger.js';
25
- const TAG = 'attach-brackets';
26
- export async function attachBracketsTool(args, deps) {
27
- // ---- 1. Argument validation ----
28
- if (!args.symbol || typeof args.symbol !== 'string') {
29
- return { error: 'symbol is required.' };
30
- }
31
- if (args.stop_price === undefined && args.target_price === undefined) {
32
- return { error: 'at least one of stop_price or target_price must be provided.' };
33
- }
34
- if (args.stop_price !== undefined && (!Number.isFinite(args.stop_price) || args.stop_price <= 0)) {
35
- return { error: 'stop_price must be a positive finite number.' };
36
- }
37
- if (args.target_price !== undefined && (!Number.isFinite(args.target_price) || args.target_price <= 0)) {
38
- return { error: 'target_price must be a positive finite number.' };
39
- }
40
- // ---- 2. Mode gate ----
41
- if (!deps.adapter.isLive) {
42
- return { error: 'attach_brackets is live-mode only (it places exchange-side STOP/TP orders). In paper mode, use modify_stop / modify_target to set or move the position\'s protective levels in place — the paper stop-watcher enforces metadata.stopPrice.' };
43
- }
44
- if (deps.checkWave9LiveSymbolOwnership && !deps.operationLock) {
45
- return {
46
- error: 'Live attach_brackets refused: the shared trading operation lock is required ' +
47
- 'while Wave 9 LIVE ownership checks are enabled.',
48
- };
49
- }
50
- const attachLive = () => attachBracketsLive(args, deps);
51
- try {
52
- return deps.operationLock
53
- ? await deps.operationLock.withAccountLock(`generic-attach-brackets-final:${args.symbol}`, attachLive)
54
- : await attachLive();
55
- }
56
- catch (err) {
57
- return { error: formatError(err) };
58
- }
59
- }
60
- async function attachBracketsLive(args, deps) {
61
- if (deps.checkWave9LiveSymbolOwnership) {
62
- let ownership;
63
- try {
64
- ownership = await deps.checkWave9LiveSymbolOwnership(args.symbol);
65
- }
66
- catch (err) {
67
- return {
68
- error: `attach_brackets refused at mutation boundary: Wave 9 LIVE ownership check failed ` +
69
- `for ${args.symbol} (${formatError(err)}).`,
70
- };
71
- }
72
- if (ownership.status === 'owned' || ownership.status === 'ambiguous') {
73
- return {
74
- error: `attach_brackets refused at mutation boundary: ${args.symbol} has ` +
75
- `${ownership.status} Wave 9 LIVE ownership (${ownership.reason}). ` +
76
- 'Wave 9 protection is candidate-bound and cannot be replaced by the generic bracket tool.',
77
- };
78
- }
79
- }
80
- const live = deps.adapter;
81
- const mgr = live.getBracketManager?.();
82
- const ledger = live.getBracketLedger?.();
83
- if (!mgr || !ledger) {
84
- return { error: 'Bracket orders are not enabled. Set brackets.mode in plugin-config.json to "observe" or "enforce".' };
85
- }
86
- // ---- 3. Position must exist ----
87
- // getPositionsOrNull() returns null when the fetch FAILED (429 / weight-
88
- // paced / transient) — position state is UNKNOWN, NOT "no position". If
89
- // we collapsed null→[] here, attach_brackets would tell the agent "No open
90
- // position" for a position that is actually live and NAKED on Binance; the
91
- // agent reads that as "nothing to protect", stops trying, and the naked
92
- // position rides unprotected. Distinct error → agent retries next
93
- // heartbeat. Same null≠empty contract as audit/closePosition/flatten.
94
- const positions = await deps.adapter.getPositionsOrNull(args.symbol);
95
- if (positions === null) {
96
- return {
97
- error: `Exchange data unavailable for ${args.symbol} (likely Binance 429 or transient ` +
98
- `network) — position state UNKNOWN. NOT treating this as "no position"; ` +
99
- `bracket attach skipped this cycle. Retry on next heartbeat.`,
100
- };
101
- }
102
- const position = positions.find(p => p.symbol === args.symbol) ?? positions[0];
103
- if (!position || position.contracts <= 0) {
104
- return { error: `No open position for ${args.symbol}.` };
105
- }
106
- const entrySide = position.side === 'long' ? 'buy' : 'sell';
107
- // ---- 4. Direction sanity check vs entry price ----
108
- const refPrice = position.entryPrice > 0 ? position.entryPrice : await deps.adapter.getLastPrice(position.symbol);
109
- if (refPrice != null && refPrice > 0) {
110
- if (args.stop_price !== undefined) {
111
- const msg = validateStopDirection(entrySide, refPrice, args.stop_price);
112
- if (msg)
113
- return { error: msg };
114
- }
115
- if (args.target_price !== undefined) {
116
- const msg = validateTargetDirection(entrySide, refPrice, args.target_price);
117
- if (msg)
118
- return { error: msg };
119
- }
120
- }
121
- // ---- 5. Handle existing ledger row ----
122
- // If the ledger has a non-terminal row AND its stored SL/TP cids correspond
123
- // to live exchange orders, a fresh bracket really is active. Two sub-cases:
124
- // (a) Caller passed the SAME prices the ledger already stores → idempotent
125
- // no-op success. This is the agent's defensive re-attach pattern: it
126
- // sees a flickery audit verdict, calls attach_brackets to "repair",
127
- // passes the same stop/target it remembers from the entry. Pre-fix
128
- // this returned an error, the agent escalated to close_position
129
- // (bracket_integrity), and we lost ~$3 of bracket-integrity flushes
130
- // on 2026-05-15. With idempotency, the defensive re-call costs
131
- // nothing and the position survives.
132
- // (b) Caller passed DIFFERENT prices → they want to change levels. Point
133
- // them at modify_stop / modify_target so we don't have two paths
134
- // that mutate the bracket geometry.
135
- //
136
- // If the ledger is non-terminal but the cids do NOT match any live exchange
137
- // order, the row is stale (exchange brackets got cancelled out-of-band,
138
- // plugin restart + lost attach, etc.). Force the row terminal so
139
- // registerEntry below can seed a fresh pending_entry. Without this, stale
140
- // rows deadlock recovery: audit reports has_stop=false (no exchange match),
141
- // attach refuses (ledger says active), agent can't resolve. Incident:
142
- // 2026-04-21 ADA death loop — 12 cycles panic-closed in 3 hours.
143
- const existing = ledger.getBySymbol(position.symbol);
144
- let clearedStaleLedgerRow = false;
145
- if (existing && NON_TERMINAL_STATES.has(existing.state)) {
146
- // Tri-state classification. `unknown` means we COULD NOT positively
147
- // confirm the ledger's cids against live exchange orders — getOpenOrders
148
- // threw (429 / weight-paced / sticky cooldown), OR the row has no cids to
149
- // check (in-flight pending_entry/attaching). We must NOT collapse
150
- // "unverifiable" into "live" — doing so makes attach_brackets return
151
- // idempotent_no_op / "already active" for a position that is actually
152
- // NAKED on the exchange, and the agent files a complacent hold/protected
153
- // review on an unprotected live position. 2026-05-15 NEAR incident: a
154
- // weight-paced getOpenOrders → verifyLedgerStale safe-defaulted to "not
155
- // stale" → idempotent_no_op on an `attaching` row whose brackets were
156
- // never placed. Same null≠empty / never-coerce-unverifiable-to-a-positive-
157
- // safety-claim contract as getOpenOrders / getPositions / closePosition.
158
- const cls = await classifyLedgerVsExchange(live, position.symbol, existing.slCid, existing.tpCid);
159
- if (cls === 'unknown') {
160
- logger.warn(TAG, `CANNOT CONFIRM bracket protection for ${position.symbol}: ledger row ` +
161
- `state=${existing.state} (slCid=${existing.slCid ?? '-'}, tpCid=${existing.tpCid ?? '-'}) ` +
162
- `but getOpenOrders unavailable or no cids to verify. Refusing to claim ` +
163
- `protected; NOT clearing/reattaching (could race an in-flight attach).`);
164
- return {
165
- error: `Cannot confirm whether ${position.symbol} brackets are live on the exchange ` +
166
- `(getOpenOrders unavailable — Binance 429 / weight-paced / transient — or the ` +
167
- `ledger row is still in-flight with no cids yet). NOT assuming the position is ` +
168
- `protected and NOT reattaching this cycle. Retry on the next heartbeat. If this ` +
169
- `persists, treat the position as potentially NAKED: verify on the exchange and ` +
170
- `place a manual stop. Do NOT record a hold/protected review on the basis of this call.`,
171
- };
172
- }
173
- if (cls === 'live') {
174
- // Idempotency check: same protection levels = no-op success.
175
- if (pricesMatch(args.stop_price, existing.stopPrice)
176
- && pricesMatch(args.target_price, existing.targetPrice)) {
177
- logger.info(TAG, `idempotent no-op for ${position.symbol}: bracket already ${existing.state} ` +
178
- `at stop=${existing.stopPrice ?? 'none'} target=${existing.targetPrice ?? 'none'} ` +
179
- `(slCid=${existing.slCid ?? '-'}, tpCid=${existing.tpCid ?? '-'})`);
180
- return {
181
- ok: true,
182
- symbol: position.symbol,
183
- bracket_id: existing.bracketId,
184
- entry_side: entrySide,
185
- stop_price: existing.stopPrice,
186
- target_price: existing.targetPrice,
187
- sl_cid: existing.slCid,
188
- tp_cid: existing.tpCid,
189
- attach_latency_ms: 0,
190
- cancelled_stale_bracket_orders: 0,
191
- cleared_stale_ledger_row: false,
192
- attempts: 0,
193
- idempotent_no_op: true,
194
- note: `Bracket already ${existing.state} on exchange with matching prices — no-op. If the audit reports has_stop=false anyway, suspect audit unreliability, not protection loss.`,
195
- };
196
- }
197
- return {
198
- error: `Bracket already ${existing.state} for ${position.symbol} ` +
199
- `at stop=${formatPrice(existing.stopPrice)} target=${formatPrice(existing.targetPrice)}. ` +
200
- `Use modify_stop / modify_target to change levels, or close_position to exit.`,
201
- };
202
- }
203
- logger.warn(TAG, `Ledger row for ${position.symbol} is stale (state=${existing.state}, slCid=${existing.slCid}, tpCid=${existing.tpCid} not on exchange); forcing terminal to re-attach`);
204
- try {
205
- ledger.markState(position.symbol, 'cancelled', {
206
- closeReason: 'cancelled_auto',
207
- lastError: 'stale_ledger_detected_by_attach_brackets',
208
- });
209
- clearedStaleLedgerRow = true;
210
- }
211
- catch (err) {
212
- return { error: `failed to clear stale ledger row: ${formatError(err)}` };
213
- }
214
- }
215
- // ---- 6. Clear any stale bracket orders on the exchange for this symbol ----
216
- // The ledger row (if any) is terminal at this point; its stored SL/TP cids
217
- // may or may not still be live on the exchange. Orphan bracket orders not
218
- // tracked by the ledger may also exist. Cancel all bracket-cid orders on
219
- // this symbol so only our fresh pair remains after attach.
220
- let cancelledOrphans = 0;
221
- try {
222
- cancelledOrphans = await live.cancelSymbolBracketOrders(position.symbol);
223
- }
224
- catch (err) {
225
- logger.warn(TAG, `orphan cleanup failed for ${position.symbol}: ${formatError(err)}`);
226
- }
227
- // ---- 7. Register + attach ----
228
- // BracketManager.registerEntry auto-clears terminal rows for the same symbol
229
- // (see ledger-hygiene change landed alongside this tool).
230
- const bracketId = generateBracketId();
231
- try {
232
- mgr.registerEntry({
233
- symbol: position.symbol,
234
- side: entrySide,
235
- stopPrice: args.stop_price,
236
- targetPrice: args.target_price,
237
- }, bracketId, buildBracketCid(bracketId, 'entry'));
238
- }
239
- catch (err) {
240
- return { error: `registerEntry failed: ${formatError(err)}` };
241
- }
242
- let attachResult;
243
- try {
244
- attachResult = await mgr.attachBrackets(position.symbol, position.contracts);
245
- }
246
- catch (err) {
247
- return { error: `attachBrackets threw: ${formatError(err)}` };
248
- }
249
- if (!attachResult.ok) {
250
- return {
251
- error: `Bracket attach failed after ${attachResult.attempts} attempt(s): ${attachResult.error ?? 'unknown error'}. ` +
252
- `Position remains open. Try again with adjusted levels, or close_position to exit.`,
253
- };
254
- }
255
- return {
256
- ok: true,
257
- symbol: position.symbol,
258
- bracket_id: bracketId,
259
- entry_side: entrySide,
260
- stop_price: args.stop_price,
261
- target_price: args.target_price,
262
- sl_cid: attachResult.slCid,
263
- tp_cid: attachResult.tpCid,
264
- attach_latency_ms: attachResult.latencyMs,
265
- cancelled_stale_bracket_orders: cancelledOrphans,
266
- cleared_stale_ledger_row: clearedStaleLedgerRow || (!!existing && !NON_TERMINAL_STATES.has(existing.state)),
267
- attempts: attachResult.attempts,
268
- };
269
- }
270
- // Non-terminal bracket states — a row in any of these means brackets are
271
- // either in-flight or fully live; attach_brackets refuses to clobber them
272
- // UNLESS the ledger cids don't match any live exchange order (stale row).
273
- const NON_TERMINAL_STATES = new Set([
274
- 'pending_entry',
275
- 'attaching',
276
- 'active',
277
- 'partial',
278
- ]);
279
- /** Classify a non-terminal ledger row against live exchange open orders.
280
- *
281
- * - `'live'` — getOpenOrders SUCCEEDED and at least one stored cid is
282
- * positively present in the live open orders. Only this
283
- * result may produce an idempotent_no_op / "already active"
284
- * reply: protection is PROVEN on the exchange.
285
- * - `'stale'` — getOpenOrders SUCCEEDED and NONE of the stored cids are
286
- * present. The exchange definitively does not have our
287
- * brackets → clear the row and re-attach.
288
- * - `'unknown'` — we could NOT positively verify: getOpenOrders threw
289
- * (429 / weight-paced / sticky cooldown / transient), OR the
290
- * row has no cids to check (in-flight pending_entry/attaching
291
- * whose attach hasn't assigned cids yet). We must NOT treat
292
- * this as `live` (false "protected" on a possibly-naked
293
- * position — the 2026-05-15 NEAR incident) NOR as `stale`
294
- * (clearing + reattaching could race a genuine in-flight
295
- * attach and double up). The caller refuses honestly and
296
- * tells the agent to retry / verify manually.
297
- *
298
- * Same null≠empty / never-coerce-unverifiable-into-a-positive-safety-claim
299
- * contract as getOpenOrders / getPositions / closePosition / the reconciler. */
300
- async function classifyLedgerVsExchange(live, symbol, slCid, tpCid) {
301
- if (!slCid && !tpCid)
302
- return 'unknown';
303
- // Cheap positive check first: a stored cid present in a SUCCESSFUL,
304
- // non-empty getOpenOrders is immediate, zero-extra-weight proof of life.
305
- // This keeps the common happy-path free. A throw or an empty set is NOT
306
- // disconfirmation — fall through to the authoritative per-leg resolver.
307
- try {
308
- const openOrders = await live.getOpenOrders(symbol);
309
- const liveCids = new Set();
310
- for (const o of openOrders) {
311
- if (o.clientOrderId)
312
- liveCids.add(o.clientOrderId);
313
- }
314
- if ((slCid && liveCids.has(slCid)) || (tpCid && liveCids.has(tpCid))) {
315
- return 'live';
316
- }
317
- }
318
- catch (err) {
319
- logger.warn(TAG, `classifyLedgerVsExchange: getOpenOrders(${symbol}) unavailable ` +
320
- `(${formatError(err)}) — deferring to the per-leg liveness resolver, ` +
321
- `NOT assuming protected or stale`);
322
- }
323
- // No positive snapshot match (empty, threw, or non-empty-without-our-cids).
324
- // The SOL/INJ spiral root: a *successful* empty /fapi/v1/openAlgoOrders is
325
- // NOT proof a leg is gone. Ask the authoritative per-leg resolver instead
326
- // of inferring from absence — trusted-WS fast-path → weight-1 REST
327
- // /fapi/v1/algoOrder → 'unknown' floor:
328
- // any leg 'live' → 'live' (do NOT clobber)
329
- // ALL present legs 'terminal' → 'stale' (POSITIVELY confirmed gone —
330
- // the only state that licenses repair)
331
- // otherwise (any 'unknown') → 'unknown' (d59e51b safe floor)
332
- const cids = [slCid, tpCid].filter((c) => !!c);
333
- const verdicts = await Promise.all(cids.map(c => live.resolveBracketLegLiveness(c)));
334
- if (verdicts.some(v => v === 'live'))
335
- return 'live';
336
- if (verdicts.length > 0 && verdicts.every(v => v === 'terminal')) {
337
- // #2 — AUTHORITATIVE action-layer spiral guard (2026-05-16 INJ).
338
- // The LEDGER's cids are positively terminal — but that is NOT proof the
339
- // position is unprotected. A prior reattach's FRESH bracket may be live
340
- // on the exchange under a NEW cid the ledger never caught up to.
341
- // Returning 'stale' here licenses the clear+reattach that cancels that
342
- // live bracket → naked → audit unprotected → attach → spiral. Before
343
- // licensing repair, positively prove NO other rc-* leg for this symbol
344
- // is live. Only positive evidence licenses the destructive action —
345
- // same invariant as d59e51b / getOpenOrders / the reconciler.
346
- const sweep = live.findTrustedLiveBracketCidsForSymbol(symbol);
347
- if (sweep.trusted && sweep.liveCids.length > 0) {
348
- logger.warn(TAG, `classifyLedgerVsExchange: ${symbol} ledger cids (slCid=${slCid ?? '-'}, ` +
349
- `tpCid=${tpCid ?? '-'}) are terminal BUT the trusted WS shows live ` +
350
- `rc-* leg(s) under other cid(s) [${sweep.liveCids.join(', ')}] — a prior ` +
351
- `reattach's fresh bracket is live and the ledger row lagged. Returning ` +
352
- `'live' (NOT 'stale') to break the clear+reattach spiral; the position ` +
353
- `IS protected on the exchange.`);
354
- return 'live';
355
- }
356
- if (!sweep.trusted) {
357
- // WS store untrusted → we cannot rule out a live fresh bracket under
358
- // an untracked cid using the zero-weight signal, and the spiral REST
359
- // is weight-paced. Refuse the destructive 'stale' (retry next cycle);
360
- // a genuinely-naked position is still caught by the reconciler /
361
- // ALGO_UPDATE / audit backstops. Worst case is a one-cycle delayed
362
- // repair — far safer than cancelling a live bracket on a false 'stale'.
363
- logger.warn(TAG, `classifyLedgerVsExchange: ${symbol} ledger cids REST-confirmed terminal ` +
364
- `but the WS store is UNTRUSTED — cannot positively rule out a live fresh ` +
365
- `bracket under an untracked cid (weight-paced REST can't either). ` +
366
- `Returning 'unknown' (NOT 'stale'); no force-reattach this cycle.`);
367
- return 'unknown';
368
- }
369
- logger.info(TAG, `classifyLedgerVsExchange: ${symbol} legs POSITIVELY confirmed terminal ` +
370
- `via per-leg resolver AND the trusted WS shows no other live rc-* leg ` +
371
- `(slCid=${slCid ?? '-'}, tpCid=${tpCid ?? '-'}) — 'stale', safe to ` +
372
- `clear+reattach.`);
373
- return 'stale';
374
- }
375
- logger.warn(TAG, `classifyLedgerVsExchange: ${symbol} bracket liveness UNVERIFIABLE ` +
376
- `(slCid=${slCid ?? '-'}, tpCid=${tpCid ?? '-'}; verdicts=${JSON.stringify(verdicts)}) ` +
377
- `— returning 'unknown', NOT 'stale'. No force-reattach this cycle.`);
378
- return 'unknown';
379
- }
380
- /** Compare a requested price against the ledger's stored price for the same
381
- * bracket leg. Match means: both undefined (caller didn't ask for that leg
382
- * and ledger doesn't have it) OR both defined within 0.01% relative
383
- * tolerance (covers exchange rounding of trigger prices vs the operator's
384
- * request). Any other shape is a mismatch — interpret as the caller wanting
385
- * to CHANGE the level, route to modify_*. */
386
- function pricesMatch(requested, stored) {
387
- if (requested === undefined && stored === undefined)
388
- return true;
389
- if (requested === undefined || stored === undefined)
390
- return false;
391
- if (!Number.isFinite(requested) || !Number.isFinite(stored))
392
- return false;
393
- if (stored === 0)
394
- return requested === 0;
395
- return Math.abs(requested - stored) / Math.abs(stored) <= 1e-4;
396
- }
397
- function formatPrice(p) {
398
- return p === undefined ? 'none' : String(p);
399
- }
@@ -1,49 +0,0 @@
1
- import type { IExchangeAdapter } from '../exchange-adapter.js';
2
- import type { BracketState } from '../live/bracket-types.js';
3
- type ProtectionReason = 'bracket_active' | 'manual_order_protecting' | 'no_protective_order' | 'brackets_disabled' | 'stale_ledger_row' | 'ledger_terminal_no_order';
4
- interface PositionAuditEntry {
5
- symbol: string;
6
- side: 'long' | 'short';
7
- contracts: number;
8
- entry_price: number;
9
- mark_price: number;
10
- has_stop: boolean;
11
- has_target: boolean;
12
- stop_price?: number;
13
- target_price?: number;
14
- ledger_state: BracketState | 'no_ledger_row';
15
- reason: ProtectionReason;
16
- recommended_action: 'none' | 'attach_brackets' | 'close_position' | 'enable_brackets_mode';
17
- }
18
- interface AuditBracketProtectionResult {
19
- ok: true;
20
- mode: 'paper' | 'live';
21
- brackets_enabled: boolean;
22
- total_positions: number;
23
- protected_count: number;
24
- unprotected_count: number;
25
- positions: PositionAuditEntry[];
26
- }
27
- export declare function auditBracketProtectionTool(_args: Record<string, never>, deps: {
28
- adapter: IExchangeAdapter;
29
- }): Promise<AuditBracketProtectionResult | {
30
- error: string;
31
- }>;
32
- /** Public getter — returns the recent audit verdict samples for a symbol so
33
- * close_position can copy them into the position's close record for the
34
- * dashboard Position Timeline drawer. Read-only snapshot; mutating the
35
- * return value does not affect internal state. */
36
- export declare function getRecentAuditVerdictHistory(symbol: string): ReadonlyArray<{
37
- ts: number;
38
- protected: boolean;
39
- }>;
40
- /** Test seam — clears the in-memory flicker history between unit tests. */
41
- export declare const __testing__: {
42
- resetFlickerHistory(): void;
43
- /** Inspect current history for a symbol — used by tests to assert state. */
44
- getHistory(symbol: string): ReadonlyArray<{
45
- ts: number;
46
- protected: boolean;
47
- }>;
48
- };
49
- export {};