@reefclaw/connect 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (415) hide show
  1. package/assets/bridge/bridge.d.ts +96 -0
  2. package/assets/bridge/bridge.js +969 -0
  3. package/assets/bridge/config.d.ts +43 -0
  4. package/assets/bridge/config.js +176 -0
  5. package/assets/bridge/connector.d.ts +52 -0
  6. package/assets/bridge/connector.js +293 -0
  7. package/assets/bridge/event-replay-buffer.d.ts +43 -0
  8. package/assets/bridge/event-replay-buffer.js +109 -0
  9. package/assets/bridge/gateway/event-parser.d.ts +209 -0
  10. package/assets/bridge/gateway/event-parser.js +793 -0
  11. package/assets/bridge/gateway/gateway-config.d.ts +39 -0
  12. package/assets/bridge/gateway/gateway-config.js +86 -0
  13. package/assets/bridge/gateway/gateway-http-client.d.ts +50 -0
  14. package/assets/bridge/gateway/gateway-http-client.js +165 -0
  15. package/assets/bridge/gateway/gateway-ws-client.d.ts +116 -0
  16. package/assets/bridge/gateway/gateway-ws-client.js +417 -0
  17. package/assets/bridge/gateway/poller.d.ts +146 -0
  18. package/assets/bridge/gateway/poller.js +505 -0
  19. package/assets/bridge/gateway/tool-discovery.d.ts +25 -0
  20. package/assets/bridge/gateway/tool-discovery.js +198 -0
  21. package/assets/bridge/index.d.ts +2 -0
  22. package/assets/bridge/index.js +253 -0
  23. package/assets/bridge/logger.d.ts +2 -0
  24. package/assets/bridge/logger.js +2 -0
  25. package/assets/bridge/provider.d.ts +156 -0
  26. package/assets/bridge/provider.js +2 -0
  27. package/assets/bridge/providers/emergency-commands.d.ts +54 -0
  28. package/assets/bridge/providers/emergency-commands.js +235 -0
  29. package/assets/bridge/providers/gateway.d.ts +322 -0
  30. package/assets/bridge/providers/gateway.js +2302 -0
  31. package/assets/bridge/providers/mock.d.ts +37 -0
  32. package/assets/bridge/providers/mock.js +385 -0
  33. package/assets/bridge/providers/onboarding-commands.d.ts +83 -0
  34. package/assets/bridge/providers/onboarding-commands.js +213 -0
  35. package/assets/bridge/providers/risk-calculator.d.ts +96 -0
  36. package/assets/bridge/providers/risk-calculator.js +369 -0
  37. package/assets/bridge/setup.d.ts +32 -0
  38. package/assets/bridge/setup.js +226 -0
  39. package/assets/bridge/types.d.ts +584 -0
  40. package/assets/bridge/types.js +50 -0
  41. package/assets/bridge/utils/reconnect.d.ts +6 -0
  42. package/assets/bridge/utils/reconnect.js +6 -0
  43. package/assets/bridge/utils/skill-signing.d.ts +51 -0
  44. package/assets/bridge/utils/skill-signing.js +138 -0
  45. package/assets/bridge/utils/skill-version.d.ts +17 -0
  46. package/assets/bridge/utils/skill-version.js +71 -0
  47. package/assets/plugin/audit/mode-transition-audit.d.ts +11 -0
  48. package/assets/plugin/audit/mode-transition-audit.js +29 -0
  49. package/assets/plugin/balance-utils.d.ts +36 -0
  50. package/assets/plugin/balance-utils.js +98 -0
  51. package/assets/plugin/ccxt/binance-ban-gate.d.ts +47 -0
  52. package/assets/plugin/ccxt/binance-ban-gate.js +409 -0
  53. package/assets/plugin/ccxt/binance-private.d.ts +325 -0
  54. package/assets/plugin/ccxt/binance-private.js +1415 -0
  55. package/assets/plugin/ccxt/binance-public.d.ts +18 -0
  56. package/assets/plugin/ccxt/binance-public.js +147 -0
  57. package/assets/plugin/config/agent-config-client.d.ts +55 -0
  58. package/assets/plugin/config/agent-config-client.js +145 -0
  59. package/assets/plugin/config/agent-config-poller.d.ts +25 -0
  60. package/assets/plugin/config/agent-config-poller.js +100 -0
  61. package/assets/plugin/config/brackets-config.d.ts +22 -0
  62. package/assets/plugin/config/brackets-config.js +58 -0
  63. package/assets/plugin/config/gate-store.d.ts +18 -0
  64. package/assets/plugin/config/gate-store.js +61 -0
  65. package/assets/plugin/config/plugin-config-io.d.ts +175 -0
  66. package/assets/plugin/config/plugin-config-io.js +84 -0
  67. package/assets/plugin/config/position-review-config.d.ts +35 -0
  68. package/assets/plugin/config/position-review-config.js +105 -0
  69. package/assets/plugin/config/tool-gate.d.ts +53 -0
  70. package/assets/plugin/config/tool-gate.js +125 -0
  71. package/assets/plugin/config/user-data-stream-config.d.ts +85 -0
  72. package/assets/plugin/config/user-data-stream-config.js +224 -0
  73. package/assets/plugin/exchange-adapter.d.ts +49 -0
  74. package/assets/plugin/exchange-adapter.js +4 -0
  75. package/assets/plugin/index.d.ts +30 -0
  76. package/assets/plugin/index.js +1989 -0
  77. package/assets/plugin/ingest/pending-entry-metadata.d.ts +52 -0
  78. package/assets/plugin/ingest/pending-entry-metadata.js +182 -0
  79. package/assets/plugin/ingest/position-auto-capture.d.ts +98 -0
  80. package/assets/plugin/ingest/position-auto-capture.js +394 -0
  81. package/assets/plugin/ingest/position-decisions-client.d.ts +318 -0
  82. package/assets/plugin/ingest/position-decisions-client.js +296 -0
  83. package/assets/plugin/ingest/reconcile-db-vs-exchange.d.ts +13 -0
  84. package/assets/plugin/ingest/reconcile-db-vs-exchange.js +114 -0
  85. package/assets/plugin/ingest/reconciler-cleanup.d.ts +37 -0
  86. package/assets/plugin/ingest/reconciler-cleanup.js +147 -0
  87. package/assets/plugin/ingest/rest-gap-filler.d.ts +191 -0
  88. package/assets/plugin/ingest/rest-gap-filler.js +565 -0
  89. package/assets/plugin/ingest/touched-symbols-store.d.ts +25 -0
  90. package/assets/plugin/ingest/touched-symbols-store.js +96 -0
  91. package/assets/plugin/ingest/trade-store-client.d.ts +40 -0
  92. package/assets/plugin/ingest/trade-store-client.js +125 -0
  93. package/assets/plugin/ingest/ws-ingest.d.ts +43 -0
  94. package/assets/plugin/ingest/ws-ingest.js +126 -0
  95. package/assets/plugin/learning/setup-family.d.ts +21 -0
  96. package/assets/plugin/learning/setup-family.js +103 -0
  97. package/assets/plugin/lifecycle/install-signal-handlers.d.ts +33 -0
  98. package/assets/plugin/lifecycle/install-signal-handlers.js +112 -0
  99. package/assets/plugin/lifecycle/shutdown-coordinator.d.ts +43 -0
  100. package/assets/plugin/lifecycle/shutdown-coordinator.js +131 -0
  101. package/assets/plugin/live/bracket-id.d.ts +18 -0
  102. package/assets/plugin/live/bracket-id.js +81 -0
  103. package/assets/plugin/live/bracket-ledger.d.ts +54 -0
  104. package/assets/plugin/live/bracket-ledger.js +267 -0
  105. package/assets/plugin/live/bracket-manager.d.ts +82 -0
  106. package/assets/plugin/live/bracket-manager.js +478 -0
  107. package/assets/plugin/live/bracket-params.d.ts +22 -0
  108. package/assets/plugin/live/bracket-params.js +124 -0
  109. package/assets/plugin/live/bracket-reconciler.d.ts +95 -0
  110. package/assets/plugin/live/bracket-reconciler.js +573 -0
  111. package/assets/plugin/live/bracket-types.d.ts +102 -0
  112. package/assets/plugin/live/bracket-types.js +8 -0
  113. package/assets/plugin/live/deposit-tracker.d.ts +62 -0
  114. package/assets/plugin/live/deposit-tracker.js +97 -0
  115. package/assets/plugin/live/emergency-controls.d.ts +32 -0
  116. package/assets/plugin/live/emergency-controls.js +226 -0
  117. package/assets/plugin/live/exchange-errors.d.ts +12 -0
  118. package/assets/plugin/live/exchange-errors.js +130 -0
  119. package/assets/plugin/live/exchange-info-cache.d.ts +35 -0
  120. package/assets/plugin/live/exchange-info-cache.js +119 -0
  121. package/assets/plugin/live/fact-subscriber.d.ts +78 -0
  122. package/assets/plugin/live/fact-subscriber.js +182 -0
  123. package/assets/plugin/live/intent-journal.d.ts +42 -0
  124. package/assets/plugin/live/intent-journal.js +122 -0
  125. package/assets/plugin/live/listen-key-manager.d.ts +70 -0
  126. package/assets/plugin/live/listen-key-manager.js +169 -0
  127. package/assets/plugin/live/live-adapter.d.ts +264 -0
  128. package/assets/plugin/live/live-adapter.js +1665 -0
  129. package/assets/plugin/live/live-balance-enricher.d.ts +32 -0
  130. package/assets/plugin/live/live-balance-enricher.js +104 -0
  131. package/assets/plugin/live/live-bracket-api.d.ts +13 -0
  132. package/assets/plugin/live/live-bracket-api.js +20 -0
  133. package/assets/plugin/live/live-state-store.d.ts +194 -0
  134. package/assets/plugin/live/live-state-store.js +450 -0
  135. package/assets/plugin/live/local-signal-service.d.ts +57 -0
  136. package/assets/plugin/live/local-signal-service.js +146 -0
  137. package/assets/plugin/live/local-strategy-evaluator.d.ts +62 -0
  138. package/assets/plugin/live/local-strategy-evaluator.js +127 -0
  139. package/assets/plugin/live/microstructure-assembler.d.ts +54 -0
  140. package/assets/plugin/live/microstructure-assembler.js +148 -0
  141. package/assets/plugin/live/order-poller.d.ts +29 -0
  142. package/assets/plugin/live/order-poller.js +125 -0
  143. package/assets/plugin/live/position-state-store.d.ts +83 -0
  144. package/assets/plugin/live/position-state-store.js +237 -0
  145. package/assets/plugin/live/proposal-decision-listener.d.ts +64 -0
  146. package/assets/plugin/live/proposal-decision-listener.js +288 -0
  147. package/assets/plugin/live/proposal-manager.d.ts +76 -0
  148. package/assets/plugin/live/proposal-manager.js +140 -0
  149. package/assets/plugin/live/rate-limiter.d.ts +47 -0
  150. package/assets/plugin/live/rate-limiter.js +159 -0
  151. package/assets/plugin/live/reconciler.d.ts +39 -0
  152. package/assets/plugin/live/reconciler.js +175 -0
  153. package/assets/plugin/live/setup-buckets.d.ts +7 -0
  154. package/assets/plugin/live/setup-buckets.js +33 -0
  155. package/assets/plugin/live/slippage-tracker.d.ts +45 -0
  156. package/assets/plugin/live/slippage-tracker.js +78 -0
  157. package/assets/plugin/live/stop-watcher.d.ts +34 -0
  158. package/assets/plugin/live/stop-watcher.js +158 -0
  159. package/assets/plugin/live/user-data-active-probe.d.ts +54 -0
  160. package/assets/plugin/live/user-data-active-probe.js +180 -0
  161. package/assets/plugin/live/user-data-stream-controller.d.ts +200 -0
  162. package/assets/plugin/live/user-data-stream-controller.js +579 -0
  163. package/assets/plugin/live/user-data-stream-ws.d.ts +22 -0
  164. package/assets/plugin/live/user-data-stream-ws.js +63 -0
  165. package/assets/plugin/live/user-data-stream.d.ts +243 -0
  166. package/assets/plugin/live/user-data-stream.js +704 -0
  167. package/assets/plugin/logger.d.ts +2 -0
  168. package/assets/plugin/logger.js +2 -0
  169. package/assets/plugin/mfe.d.ts +21 -0
  170. package/assets/plugin/mfe.js +68 -0
  171. package/assets/plugin/onboarding/mode-ladder.d.ts +1 -0
  172. package/assets/plugin/onboarding/mode-ladder.js +3 -0
  173. package/assets/plugin/onboarding/runtime.d.ts +71 -0
  174. package/assets/plugin/onboarding/runtime.js +153 -0
  175. package/assets/plugin/openclaw.plugin.json +91 -0
  176. package/assets/plugin/paper-adapter.d.ts +24 -0
  177. package/assets/plugin/paper-adapter.js +91 -0
  178. package/assets/plugin/persistence/state-manager.d.ts +42 -0
  179. package/assets/plugin/persistence/state-manager.js +164 -0
  180. package/assets/plugin/pinned-plan.d.ts +9 -0
  181. package/assets/plugin/pinned-plan.js +23 -0
  182. package/assets/plugin/risk/pre-trade-check.d.ts +38 -0
  183. package/assets/plugin/risk/pre-trade-check.js +345 -0
  184. package/assets/plugin/risk/pre-trade-types.d.ts +60 -0
  185. package/assets/plugin/risk/pre-trade-types.js +3 -0
  186. package/assets/plugin/shadow/shadow-tracker.d.ts +36 -0
  187. package/assets/plugin/shadow/shadow-tracker.js +151 -0
  188. package/assets/plugin/shadow/types.d.ts +42 -0
  189. package/assets/plugin/shadow/types.js +20 -0
  190. package/assets/plugin/shared/indicators-extended.d.ts +52 -0
  191. package/assets/plugin/shared/indicators-extended.js +291 -0
  192. package/assets/plugin/shared/indicators.d.ts +15 -0
  193. package/assets/plugin/shared/indicators.js +114 -0
  194. package/assets/plugin/signals/conditions/registry.d.ts +16 -0
  195. package/assets/plugin/signals/conditions/registry.js +1274 -0
  196. package/assets/plugin/signals/conditions/types.d.ts +1 -0
  197. package/assets/plugin/signals/conditions/types.js +4 -0
  198. package/assets/plugin/signals/direction-rules.d.ts +3 -0
  199. package/assets/plugin/signals/direction-rules.js +24 -0
  200. package/assets/plugin/signals/entry-rules.d.ts +6 -0
  201. package/assets/plugin/signals/entry-rules.js +33 -0
  202. package/assets/plugin/signals/serialize-context.d.ts +4 -0
  203. package/assets/plugin/signals/serialize-context.js +39 -0
  204. package/assets/plugin/signals/stop-rules.d.ts +3 -0
  205. package/assets/plugin/signals/stop-rules.js +48 -0
  206. package/assets/plugin/signals/strategy-adapter.d.ts +14 -0
  207. package/assets/plugin/signals/strategy-adapter.js +122 -0
  208. package/assets/plugin/signals/types.d.ts +1 -0
  209. package/assets/plugin/signals/types.js +8 -0
  210. package/assets/plugin/simulator/exchange-simulator.d.ts +93 -0
  211. package/assets/plugin/simulator/exchange-simulator.js +684 -0
  212. package/assets/plugin/simulator/fill-engine.d.ts +53 -0
  213. package/assets/plugin/simulator/fill-engine.js +276 -0
  214. package/assets/plugin/simulator/paper-market-feed.d.ts +26 -0
  215. package/assets/plugin/simulator/paper-market-feed.js +104 -0
  216. package/assets/plugin/simulator/realistic-fills.d.ts +59 -0
  217. package/assets/plugin/simulator/realistic-fills.js +175 -0
  218. package/assets/plugin/simulator/types.d.ts +219 -0
  219. package/assets/plugin/simulator/types.js +43 -0
  220. package/assets/plugin/strategy/builtin-strategies.d.ts +2 -0
  221. package/assets/plugin/strategy/builtin-strategies.js +109 -0
  222. package/assets/plugin/strategy/condition-registry.d.ts +3 -0
  223. package/assets/plugin/strategy/condition-registry.js +153 -0
  224. package/assets/plugin/strategy/evaluator.d.ts +67 -0
  225. package/assets/plugin/strategy/evaluator.js +93 -0
  226. package/assets/plugin/tools/assessment-validation.d.ts +118 -0
  227. package/assets/plugin/tools/assessment-validation.js +415 -0
  228. package/assets/plugin/tools/attach-brackets.d.ts +34 -0
  229. package/assets/plugin/tools/attach-brackets.js +363 -0
  230. package/assets/plugin/tools/audit-bracket-protection.d.ts +49 -0
  231. package/assets/plugin/tools/audit-bracket-protection.js +527 -0
  232. package/assets/plugin/tools/cancel-all-orders.d.ts +7 -0
  233. package/assets/plugin/tools/cancel-all-orders.js +5 -0
  234. package/assets/plugin/tools/cancel-order.d.ts +10 -0
  235. package/assets/plugin/tools/cancel-order.js +14 -0
  236. package/assets/plugin/tools/check-position-health.d.ts +46 -0
  237. package/assets/plugin/tools/check-position-health.js +194 -0
  238. package/assets/plugin/tools/clear-exchange-credentials.d.ts +24 -0
  239. package/assets/plugin/tools/clear-exchange-credentials.js +70 -0
  240. package/assets/plugin/tools/close-position.d.ts +22 -0
  241. package/assets/plugin/tools/close-position.js +449 -0
  242. package/assets/plugin/tools/create-order.d.ts +54 -0
  243. package/assets/plugin/tools/create-order.js +338 -0
  244. package/assets/plugin/tools/exit-gate.d.ts +58 -0
  245. package/assets/plugin/tools/exit-gate.js +162 -0
  246. package/assets/plugin/tools/fetch-balance.d.ts +5 -0
  247. package/assets/plugin/tools/fetch-balance.js +4 -0
  248. package/assets/plugin/tools/fetch-ohlcv.d.ts +11 -0
  249. package/assets/plugin/tools/fetch-ohlcv.js +8 -0
  250. package/assets/plugin/tools/fetch-open-orders.d.ts +7 -0
  251. package/assets/plugin/tools/fetch-open-orders.js +4 -0
  252. package/assets/plugin/tools/fetch-positions.d.ts +7 -0
  253. package/assets/plugin/tools/fetch-positions.js +4 -0
  254. package/assets/plugin/tools/fetch-ticker.d.ts +11 -0
  255. package/assets/plugin/tools/fetch-ticker.js +5 -0
  256. package/assets/plugin/tools/get-agent-profile.d.ts +4 -0
  257. package/assets/plugin/tools/get-agent-profile.js +6 -0
  258. package/assets/plugin/tools/get-analytics.d.ts +6 -0
  259. package/assets/plugin/tools/get-analytics.js +7 -0
  260. package/assets/plugin/tools/get-backtest.d.ts +12 -0
  261. package/assets/plugin/tools/get-backtest.js +91 -0
  262. package/assets/plugin/tools/get-basis.d.ts +7 -0
  263. package/assets/plugin/tools/get-basis.js +7 -0
  264. package/assets/plugin/tools/get-bracket-config.d.ts +11 -0
  265. package/assets/plugin/tools/get-bracket-config.js +24 -0
  266. package/assets/plugin/tools/get-cascade-risk.d.ts +7 -0
  267. package/assets/plugin/tools/get-cascade-risk.js +8 -0
  268. package/assets/plugin/tools/get-crypto-metrics.d.ts +18 -0
  269. package/assets/plugin/tools/get-crypto-metrics.js +45 -0
  270. package/assets/plugin/tools/get-cvd.d.ts +6 -0
  271. package/assets/plugin/tools/get-cvd.js +6 -0
  272. package/assets/plugin/tools/get-divergences.d.ts +6 -0
  273. package/assets/plugin/tools/get-divergences.js +6 -0
  274. package/assets/plugin/tools/get-funding-context.d.ts +6 -0
  275. package/assets/plugin/tools/get-funding-context.js +16 -0
  276. package/assets/plugin/tools/get-liquidation-levels.d.ts +7 -0
  277. package/assets/plugin/tools/get-liquidation-levels.js +7 -0
  278. package/assets/plugin/tools/get-liquidation-pulse.d.ts +9 -0
  279. package/assets/plugin/tools/get-liquidation-pulse.js +22 -0
  280. package/assets/plugin/tools/get-market-breadth.d.ts +6 -0
  281. package/assets/plugin/tools/get-market-breadth.js +8 -0
  282. package/assets/plugin/tools/get-market-intel.d.ts +19 -0
  283. package/assets/plugin/tools/get-market-intel.js +116 -0
  284. package/assets/plugin/tools/get-market-structure.d.ts +47 -0
  285. package/assets/plugin/tools/get-market-structure.js +198 -0
  286. package/assets/plugin/tools/get-my-mined-patterns.d.ts +20 -0
  287. package/assets/plugin/tools/get-my-mined-patterns.js +61 -0
  288. package/assets/plugin/tools/get-my-proposed-learnings.d.ts +20 -0
  289. package/assets/plugin/tools/get-my-proposed-learnings.js +55 -0
  290. package/assets/plugin/tools/get-my-recent-reviews.d.ts +22 -0
  291. package/assets/plugin/tools/get-my-recent-reviews.js +66 -0
  292. package/assets/plugin/tools/get-orderbook.d.ts +21 -0
  293. package/assets/plugin/tools/get-orderbook.js +32 -0
  294. package/assets/plugin/tools/get-pattern-scan.d.ts +7 -0
  295. package/assets/plugin/tools/get-pattern-scan.js +8 -0
  296. package/assets/plugin/tools/get-regime.d.ts +6 -0
  297. package/assets/plugin/tools/get-regime.js +7 -0
  298. package/assets/plugin/tools/get-relevant-learnings.d.ts +21 -0
  299. package/assets/plugin/tools/get-relevant-learnings.js +65 -0
  300. package/assets/plugin/tools/get-resting-liquidity.d.ts +6 -0
  301. package/assets/plugin/tools/get-resting-liquidity.js +11 -0
  302. package/assets/plugin/tools/get-risk-scenario.d.ts +29 -0
  303. package/assets/plugin/tools/get-risk-scenario.js +47 -0
  304. package/assets/plugin/tools/get-risk-summary.d.ts +51 -0
  305. package/assets/plugin/tools/get-risk-summary.js +118 -0
  306. package/assets/plugin/tools/get-sentiment.d.ts +4 -0
  307. package/assets/plugin/tools/get-sentiment.js +6 -0
  308. package/assets/plugin/tools/get-session-review.d.ts +7 -0
  309. package/assets/plugin/tools/get-session-review.js +8 -0
  310. package/assets/plugin/tools/get-setup-detail.d.ts +7 -0
  311. package/assets/plugin/tools/get-setup-detail.js +303 -0
  312. package/assets/plugin/tools/get-signals.d.ts +15 -0
  313. package/assets/plugin/tools/get-signals.js +54 -0
  314. package/assets/plugin/tools/get-sizing.d.ts +6 -0
  315. package/assets/plugin/tools/get-sizing.js +6 -0
  316. package/assets/plugin/tools/get-trade-feedback.d.ts +7 -0
  317. package/assets/plugin/tools/get-trade-feedback.js +8 -0
  318. package/assets/plugin/tools/get-trade-flow.d.ts +7 -0
  319. package/assets/plugin/tools/get-trade-flow.js +7 -0
  320. package/assets/plugin/tools/get-volume-analysis.d.ts +21 -0
  321. package/assets/plugin/tools/get-volume-analysis.js +74 -0
  322. package/assets/plugin/tools/get-volume-profile.d.ts +7 -0
  323. package/assets/plugin/tools/get-volume-profile.js +7 -0
  324. package/assets/plugin/tools/helpers.d.ts +25 -0
  325. package/assets/plugin/tools/helpers.js +38 -0
  326. package/assets/plugin/tools/intel-api.d.ts +14 -0
  327. package/assets/plugin/tools/intel-api.js +52 -0
  328. package/assets/plugin/tools/intel-cache.d.ts +25 -0
  329. package/assets/plugin/tools/intel-cache.js +133 -0
  330. package/assets/plugin/tools/list-strategies.d.ts +7 -0
  331. package/assets/plugin/tools/list-strategies.js +6 -0
  332. package/assets/plugin/tools/modify-stop.d.ts +17 -0
  333. package/assets/plugin/tools/modify-stop.js +81 -0
  334. package/assets/plugin/tools/modify-target.d.ts +17 -0
  335. package/assets/plugin/tools/modify-target.js +71 -0
  336. package/assets/plugin/tools/propose-learning.d.ts +22 -0
  337. package/assets/plugin/tools/propose-learning.js +65 -0
  338. package/assets/plugin/tools/query-review-outcomes.d.ts +30 -0
  339. package/assets/plugin/tools/query-review-outcomes.js +64 -0
  340. package/assets/plugin/tools/query-trades.d.ts +21 -0
  341. package/assets/plugin/tools/query-trades.js +37 -0
  342. package/assets/plugin/tools/record-position-reviews.d.ts +38 -0
  343. package/assets/plugin/tools/record-position-reviews.js +147 -0
  344. package/assets/plugin/tools/save-strategy.d.ts +16 -0
  345. package/assets/plugin/tools/save-strategy.js +46 -0
  346. package/assets/plugin/tools/scan-pairs.d.ts +18 -0
  347. package/assets/plugin/tools/scan-pairs.js +220 -0
  348. package/assets/plugin/tools/score-setup.d.ts +31 -0
  349. package/assets/plugin/tools/score-setup.js +268 -0
  350. package/assets/plugin/tools/set-bracket-requirement.d.ts +18 -0
  351. package/assets/plugin/tools/set-bracket-requirement.js +81 -0
  352. package/assets/plugin/tools/set-exchange-credentials.d.ts +25 -0
  353. package/assets/plugin/tools/set-exchange-credentials.js +80 -0
  354. package/assets/plugin/tools/set-trading-mode.d.ts +26 -0
  355. package/assets/plugin/tools/set-trading-mode.js +135 -0
  356. package/assets/plugin/tools/test-exchange-credentials.d.ts +16 -0
  357. package/assets/plugin/tools/test-exchange-credentials.js +100 -0
  358. package/assets/plugin/tools/toggle-strategy.d.ts +8 -0
  359. package/assets/plugin/tools/toggle-strategy.js +8 -0
  360. package/assets/plugin/trading-params-cache.d.ts +26 -0
  361. package/assets/plugin/trading-params-cache.js +52 -0
  362. package/assets/plugin/types.d.ts +110 -0
  363. package/assets/plugin/types.js +7 -0
  364. package/assets/plugin/util/plugin-paths.d.ts +3 -0
  365. package/assets/plugin/util/plugin-paths.js +15 -0
  366. package/assets/shared/fills.d.ts +36 -0
  367. package/assets/shared/fills.js +20 -0
  368. package/assets/shared/index.d.ts +10 -0
  369. package/assets/shared/index.js +5 -0
  370. package/assets/shared/logger.d.ts +10 -0
  371. package/assets/shared/logger.js +34 -0
  372. package/assets/shared/protocol.d.ts +29 -0
  373. package/assets/shared/protocol.js +14 -0
  374. package/assets/shared/redact.d.ts +6 -0
  375. package/assets/shared/redact.js +31 -0
  376. package/assets/shared/shared/indicators-extended.d.ts +52 -0
  377. package/assets/shared/shared/indicators-extended.js +284 -0
  378. package/assets/shared/shared/indicators.d.ts +15 -0
  379. package/assets/shared/shared/indicators.js +107 -0
  380. package/assets/shared/signals/conditions/registry.d.ts +16 -0
  381. package/assets/shared/signals/conditions/registry.js +1267 -0
  382. package/assets/shared/signals/conditions/types.d.ts +65 -0
  383. package/assets/shared/signals/conditions/types.js +8 -0
  384. package/assets/shared/signals/direction-rules.d.ts +3 -0
  385. package/assets/shared/signals/direction-rules.js +18 -0
  386. package/assets/shared/signals/entry-rules.d.ts +6 -0
  387. package/assets/shared/signals/entry-rules.js +26 -0
  388. package/assets/shared/signals/indicators-extended.d.ts +52 -0
  389. package/assets/shared/signals/indicators-extended.js +284 -0
  390. package/assets/shared/signals/indicators.d.ts +15 -0
  391. package/assets/shared/signals/indicators.js +107 -0
  392. package/assets/shared/signals/serialize-context.d.ts +4 -0
  393. package/assets/shared/signals/serialize-context.js +41 -0
  394. package/assets/shared/signals/stop-rules.d.ts +3 -0
  395. package/assets/shared/signals/stop-rules.js +41 -0
  396. package/assets/shared/signals/strategy-adapter.d.ts +14 -0
  397. package/assets/shared/signals/strategy-adapter.js +117 -0
  398. package/assets/shared/signals/types.d.ts +187 -0
  399. package/assets/shared/signals/types.js +9 -0
  400. package/assets/shared/trading-mode.d.ts +16 -0
  401. package/assets/shared/trading-mode.js +49 -0
  402. package/assets/skill/SKILL.md +1357 -0
  403. package/dist/bridge.js +25 -0
  404. package/dist/bundle.js +33 -0
  405. package/dist/cli.js +120 -0
  406. package/dist/daemon.js +104 -0
  407. package/dist/deps.js +41 -0
  408. package/dist/exec.js +28 -0
  409. package/dist/openclaw.js +153 -0
  410. package/dist/paths.js +23 -0
  411. package/dist/plugin.js +48 -0
  412. package/dist/skill.js +35 -0
  413. package/dist/ui.js +29 -0
  414. package/dist/validate.js +28 -0
  415. package/package.json +32 -0
@@ -0,0 +1,5 @@
1
+ // @reefclaw/shared — canonical types and utilities for the ReefClaw monorepo.
2
+ export { VALID_CHANNELS, VALID_EMERGENCY_ACTIONS } from './protocol.js';
3
+ export { logger, setLogLevel, formatError } from './logger.js';
4
+ export { VALID_TRADING_MODES, isTradingMode, validateModeTransition, modeRequiresCredentials, } from './trading-mode.js';
5
+ export { redactTokens, redactTokensInPayload, REDACTED_TOKEN } from './redact.js';
@@ -0,0 +1,10 @@
1
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
2
+ export declare function setLogLevel(level: LogLevel): void;
3
+ export declare const logger: {
4
+ debug: (tag: string, msg: string, data?: unknown) => void;
5
+ info: (tag: string, msg: string, data?: unknown) => void;
6
+ warn: (tag: string, msg: string, data?: unknown) => void;
7
+ error: (tag: string, msg: string, data?: unknown) => void;
8
+ };
9
+ /** Extract a readable error message from an unknown thrown value. */
10
+ export declare function formatError(err: unknown): string;
@@ -0,0 +1,34 @@
1
+ // Unified structured console logging with timestamps and levels.
2
+ // Merged from skill/src/logger.ts + plugin/src/logger.ts.
3
+ const LEVEL_ORDER = {
4
+ debug: 0,
5
+ info: 1,
6
+ warn: 2,
7
+ error: 3,
8
+ };
9
+ let minLevel = 'info';
10
+ export function setLogLevel(level) {
11
+ minLevel = level;
12
+ }
13
+ function log(level, tag, message, data) {
14
+ if (LEVEL_ORDER[level] < LEVEL_ORDER[minLevel])
15
+ return;
16
+ const ts = new Date().toISOString();
17
+ const prefix = `${ts} [${level.toUpperCase()}] [${tag}]`;
18
+ if (data !== undefined) {
19
+ console[level === 'debug' ? 'log' : level](`${prefix} ${message}`, data);
20
+ }
21
+ else {
22
+ console[level === 'debug' ? 'log' : level](`${prefix} ${message}`);
23
+ }
24
+ }
25
+ export const logger = {
26
+ debug: (tag, msg, data) => log('debug', tag, msg, data),
27
+ info: (tag, msg, data) => log('info', tag, msg, data),
28
+ warn: (tag, msg, data) => log('warn', tag, msg, data),
29
+ error: (tag, msg, data) => log('error', tag, msg, data),
30
+ };
31
+ /** Extract a readable error message from an unknown thrown value. */
32
+ export function formatError(err) {
33
+ return err instanceof Error ? err.message : String(err);
34
+ }
@@ -0,0 +1,29 @@
1
+ export type Channel = 'market_data' | 'trade_events' | 'agent_state' | 'chat';
2
+ export declare const VALID_CHANNELS: Channel[];
3
+ export interface RequestFrame {
4
+ type: 'req';
5
+ id: string;
6
+ method: string;
7
+ params?: Record<string, unknown>;
8
+ }
9
+ export interface ResponseFrame {
10
+ type: 'res';
11
+ id: string;
12
+ ok: boolean;
13
+ payload?: unknown;
14
+ error?: {
15
+ code: number;
16
+ message: string;
17
+ data?: unknown;
18
+ };
19
+ }
20
+ export interface EventFrame {
21
+ type: 'event';
22
+ event: string;
23
+ channel: Channel;
24
+ payload: unknown;
25
+ seq: number;
26
+ }
27
+ export type Frame = RequestFrame | ResponseFrame | EventFrame;
28
+ export type EmergencyAction = 'kill' | 'flatten' | 'pause' | 'resume';
29
+ export declare const VALID_EMERGENCY_ACTIONS: EmergencyAction[];
@@ -0,0 +1,14 @@
1
+ // Canonical protocol types for the ReefClaw monorepo.
2
+ // All packages re-export from here — this is the single source of truth.
3
+ export const VALID_CHANNELS = [
4
+ 'market_data',
5
+ 'trade_events',
6
+ 'agent_state',
7
+ 'chat',
8
+ ];
9
+ export const VALID_EMERGENCY_ACTIONS = [
10
+ 'kill',
11
+ 'flatten',
12
+ 'pause',
13
+ 'resume',
14
+ ];
@@ -0,0 +1,6 @@
1
+ export declare const REDACTED_TOKEN = "rc_***";
2
+ /** Replace every full-length connection token in `s` with `rc_***`. */
3
+ export declare function redactTokens(s: string): string;
4
+ /** Walk an arbitrary JSON-shaped value, redacting tokens in every string leaf.
5
+ * Returns a new structure; the input is not mutated. */
6
+ export declare function redactTokensInPayload(value: unknown): unknown;
@@ -0,0 +1,31 @@
1
+ // Token redaction for chat ingress paths.
2
+ //
3
+ // Connection tokens are `rc_` + nanoid(32) (see webapp/src/lib/utils/tokens.ts).
4
+ // nanoid's default alphabet is URL-safe: [A-Za-z0-9_-]. Total length 35.
5
+ //
6
+ // Onboarding instructs users to paste their token into "the agent chat", which
7
+ // some operators read as the ReefClaw dashboard chat panel. To make accidental
8
+ // leaks non-catastrophic, every chat ingress (DB row, audit row, log line,
9
+ // localStorage blob) runs the content through redactTokens before persistence.
10
+ const TOKEN_RE = /rc_[A-Za-z0-9_-]{32}/g;
11
+ export const REDACTED_TOKEN = 'rc_***';
12
+ /** Replace every full-length connection token in `s` with `rc_***`. */
13
+ export function redactTokens(s) {
14
+ return s.replace(TOKEN_RE, REDACTED_TOKEN);
15
+ }
16
+ /** Walk an arbitrary JSON-shaped value, redacting tokens in every string leaf.
17
+ * Returns a new structure; the input is not mutated. */
18
+ export function redactTokensInPayload(value) {
19
+ if (typeof value === 'string')
20
+ return redactTokens(value);
21
+ if (Array.isArray(value))
22
+ return value.map(redactTokensInPayload);
23
+ if (value && typeof value === 'object') {
24
+ const out = {};
25
+ for (const [k, v] of Object.entries(value)) {
26
+ out[k] = redactTokensInPayload(v);
27
+ }
28
+ return out;
29
+ }
30
+ return value;
31
+ }
@@ -0,0 +1,52 @@
1
+ export interface OhlcvInput {
2
+ open: number;
3
+ high: number;
4
+ low: number;
5
+ close: number;
6
+ volume: number;
7
+ }
8
+ export interface MACDResult {
9
+ line: number;
10
+ signal: number;
11
+ histogram: number;
12
+ crossover: 'bullish' | 'bearish' | 'none';
13
+ }
14
+ export interface BollingerResult {
15
+ upper: number;
16
+ middle: number;
17
+ lower: number;
18
+ bandwidth: number;
19
+ percentB: number;
20
+ }
21
+ export interface StochRSIResult {
22
+ k: number;
23
+ d: number;
24
+ }
25
+ export interface IchimokuResult {
26
+ tenkan: number;
27
+ kijun: number;
28
+ senkouA: number;
29
+ senkouB: number;
30
+ chikou: number;
31
+ cloudPosition: 'above' | 'below' | 'inside';
32
+ }
33
+ export interface SupertrendResult {
34
+ value: number;
35
+ direction: 'bullish' | 'bearish';
36
+ }
37
+ export declare function computeMACD(closes: number[], fast?: number, slow?: number, signal?: number): MACDResult;
38
+ export declare function computeBollingerBands(closes: number[], period?: number, stdDev?: number): BollingerResult;
39
+ export declare function computeVWAP(bars: OhlcvInput[]): number;
40
+ export declare function computeStochRSI(closes: number[], rsiPeriod?: number, stochPeriod?: number, kSmooth?: number, dSmooth?: number): StochRSIResult;
41
+ export declare function computeADX(highs: number[], lows: number[], closes: number[], period?: number): {
42
+ adx: number;
43
+ plusDI: number;
44
+ minusDI: number;
45
+ };
46
+ export declare function computeIchimoku(highs: number[], lows: number[], closes: number[], tenkanPeriod?: number, kijunPeriod?: number, senkouBPeriod?: number): IchimokuResult;
47
+ export declare function computeOBV(closes: number[], volumes: number[]): {
48
+ obv: number;
49
+ slope: 'rising' | 'falling' | 'flat';
50
+ };
51
+ export declare function computeSupertrend(highs: number[], lows: number[], closes: number[], period?: number, multiplier?: number): SupertrendResult;
52
+ export declare function computeWilliamsR(highs: number[], lows: number[], closes: number[], period?: number): number;
@@ -0,0 +1,284 @@
1
+ // Extended indicator computations for Phase 13 — Expanded Indicators.
2
+ // Wraps technicalindicators library + custom implementations.
3
+ // All functions take OHLCV arrays (oldest first) and return latest values.
4
+ import { computeATRSeries, computeRSI, mean, computeStd } from './indicators.js';
5
+ // ─── MACD (12, 26, 9) ──────────────────────────────────────────────────
6
+ export function computeMACD(closes, fast = 12, slow = 26, signal = 9) {
7
+ if (closes.length < slow + signal) {
8
+ return { line: 0, signal: 0, histogram: 0, crossover: 'none' };
9
+ }
10
+ // Compute full EMA series (both aligned to start at index `slow - 1`)
11
+ const emaFastSeries = emaSeries(closes, fast);
12
+ const emaSlowSeries = emaSeries(closes, slow);
13
+ // Align: fast series starts earlier, so take the tail matching slow series length
14
+ const offset = emaFastSeries.length - emaSlowSeries.length;
15
+ const macdLine = [];
16
+ for (let i = 0; i < emaSlowSeries.length; i++) {
17
+ macdLine.push(emaFastSeries[i + offset] - emaSlowSeries[i]);
18
+ }
19
+ // Signal line = EMA of MACD line
20
+ const signalSeries = emaSeries(macdLine, signal);
21
+ const sigOffset = macdLine.length - signalSeries.length;
22
+ const currentLine = macdLine[macdLine.length - 1];
23
+ const currentSignal = signalSeries[signalSeries.length - 1];
24
+ const prevLine = macdLine.length >= 2 ? macdLine[macdLine.length - 2] : currentLine;
25
+ const prevSignalIdx = signalSeries.length >= 2 ? signalSeries.length - 2 : signalSeries.length - 1;
26
+ const prevSignal = signalSeries[prevSignalIdx];
27
+ let crossover = 'none';
28
+ if (prevLine <= prevSignal && currentLine > currentSignal)
29
+ crossover = 'bullish';
30
+ else if (prevLine >= prevSignal && currentLine < currentSignal)
31
+ crossover = 'bearish';
32
+ return {
33
+ line: currentLine,
34
+ signal: currentSignal,
35
+ histogram: currentLine - currentSignal,
36
+ crossover,
37
+ };
38
+ }
39
+ // ─── Bollinger Bands (20, 2σ) ───────────────────────────────────────────
40
+ export function computeBollingerBands(closes, period = 20, stdDev = 2) {
41
+ if (closes.length < period) {
42
+ const p = closes[closes.length - 1] ?? 0;
43
+ return { upper: p, middle: p, lower: p, bandwidth: 0, percentB: 0.5 };
44
+ }
45
+ const slice = closes.slice(-period);
46
+ const middle = mean(slice);
47
+ const std = computeStd(slice);
48
+ const upper = middle + stdDev * std;
49
+ const lower = middle - stdDev * std;
50
+ const bandwidth = middle > 0 ? ((upper - lower) / middle) * 100 : 0;
51
+ const price = closes[closes.length - 1];
52
+ const percentB = upper !== lower ? (price - lower) / (upper - lower) : 0.5;
53
+ return { upper, middle, lower, bandwidth, percentB };
54
+ }
55
+ // ─── VWAP ───────────────────────────────────────────────────────────────
56
+ export function computeVWAP(bars) {
57
+ if (bars.length === 0)
58
+ return 0;
59
+ let cumVolume = 0;
60
+ let cumTPxVol = 0;
61
+ for (const bar of bars) {
62
+ const tp = (bar.high + bar.low + bar.close) / 3;
63
+ cumVolume += bar.volume;
64
+ cumTPxVol += tp * bar.volume;
65
+ }
66
+ return cumVolume > 0 ? cumTPxVol / cumVolume : bars[bars.length - 1].close;
67
+ }
68
+ // ─── Stochastic RSI (14, 14, 3, 3) ─────────────────────────────────────
69
+ export function computeStochRSI(closes, rsiPeriod = 14, stochPeriod = 14, kSmooth = 3, dSmooth = 3) {
70
+ if (closes.length < rsiPeriod + stochPeriod + dSmooth) {
71
+ return { k: 50, d: 50 };
72
+ }
73
+ // Compute RSI series
74
+ const rsiValues = [];
75
+ for (let i = rsiPeriod + 1; i <= closes.length; i++) {
76
+ rsiValues.push(computeRSI(closes.slice(0, i), rsiPeriod));
77
+ }
78
+ if (rsiValues.length < stochPeriod)
79
+ return { k: 50, d: 50 };
80
+ // Stochastic of RSI
81
+ const rawK = [];
82
+ for (let i = stochPeriod - 1; i < rsiValues.length; i++) {
83
+ const window = rsiValues.slice(i - stochPeriod + 1, i + 1);
84
+ const min = Math.min(...window);
85
+ const max = Math.max(...window);
86
+ rawK.push(max !== min ? ((rsiValues[i] - min) / (max - min)) * 100 : 50);
87
+ }
88
+ // %K = SMA of raw stochastic
89
+ const kValues = sma(rawK, kSmooth);
90
+ // %D = SMA of %K
91
+ const dValues = sma(kValues, dSmooth);
92
+ return {
93
+ k: Math.round(kValues[kValues.length - 1] ?? 50),
94
+ d: Math.round(dValues[dValues.length - 1] ?? 50),
95
+ };
96
+ }
97
+ // ─── ADX (14) ───────────────────────────────────────────────────────────
98
+ export function computeADX(highs, lows, closes, period = 14) {
99
+ if (highs.length < period * 2 + 1) {
100
+ return { adx: 0, plusDI: 0, minusDI: 0 };
101
+ }
102
+ const plusDM = [];
103
+ const minusDM = [];
104
+ const tr = [];
105
+ for (let i = 1; i < highs.length; i++) {
106
+ const upMove = highs[i] - highs[i - 1];
107
+ const downMove = lows[i - 1] - lows[i];
108
+ plusDM.push(upMove > downMove && upMove > 0 ? upMove : 0);
109
+ minusDM.push(downMove > upMove && downMove > 0 ? downMove : 0);
110
+ tr.push(Math.max(highs[i] - lows[i], Math.abs(highs[i] - closes[i - 1]), Math.abs(lows[i] - closes[i - 1])));
111
+ }
112
+ // Smooth with Wilder's smoothing (equivalent to EMA with alpha=1/period)
113
+ const smoothPlusDM = wilderSmooth(plusDM, period);
114
+ const smoothMinusDM = wilderSmooth(minusDM, period);
115
+ const smoothTR = wilderSmooth(tr, period);
116
+ // +DI and -DI series
117
+ const plusDISeries = [];
118
+ const minusDISeries = [];
119
+ for (let i = 0; i < smoothTR.length; i++) {
120
+ plusDISeries.push(smoothTR[i] > 0 ? (smoothPlusDM[i] / smoothTR[i]) * 100 : 0);
121
+ minusDISeries.push(smoothTR[i] > 0 ? (smoothMinusDM[i] / smoothTR[i]) * 100 : 0);
122
+ }
123
+ // DX series
124
+ const dxSeries = [];
125
+ for (let i = 0; i < plusDISeries.length; i++) {
126
+ const sum = plusDISeries[i] + minusDISeries[i];
127
+ dxSeries.push(sum > 0 ? (Math.abs(plusDISeries[i] - minusDISeries[i]) / sum) * 100 : 0);
128
+ }
129
+ // ADX = Wilder smooth of DX
130
+ const adxSeries = wilderSmooth(dxSeries, period);
131
+ return {
132
+ adx: Math.round(adxSeries[adxSeries.length - 1] ?? 0),
133
+ plusDI: Math.round(plusDISeries[plusDISeries.length - 1] ?? 0),
134
+ minusDI: Math.round(minusDISeries[minusDISeries.length - 1] ?? 0),
135
+ };
136
+ }
137
+ // ─── Ichimoku Cloud ─────────────────────────────────────────────────────
138
+ export function computeIchimoku(highs, lows, closes, tenkanPeriod = 9, kijunPeriod = 26, senkouBPeriod = 52) {
139
+ const n = highs.length;
140
+ if (n < senkouBPeriod) {
141
+ const p = closes[n - 1] ?? 0;
142
+ return { tenkan: p, kijun: p, senkouA: p, senkouB: p, chikou: p, cloudPosition: 'inside' };
143
+ }
144
+ const midpoint = (arr, period, end) => {
145
+ const slice = arr.slice(Math.max(0, end - period + 1), end + 1);
146
+ return (Math.max(...slice) + Math.min(...slice)) / 2;
147
+ };
148
+ const tenkan = midpoint(highs.concat().map((h, i) => Math.max(h, lows[i])), tenkanPeriod, n - 1);
149
+ const kijun = midpoint(highs.concat().map((h, i) => Math.max(h, lows[i])), kijunPeriod, n - 1);
150
+ // Recalculate properly using highs and lows separately
151
+ const tenkanH = Math.max(...highs.slice(-tenkanPeriod));
152
+ const tenkanL = Math.min(...lows.slice(-tenkanPeriod));
153
+ const tenkanVal = (tenkanH + tenkanL) / 2;
154
+ const kijunH = Math.max(...highs.slice(-kijunPeriod));
155
+ const kijunL = Math.min(...lows.slice(-kijunPeriod));
156
+ const kijunVal = (kijunH + kijunL) / 2;
157
+ const senkouA = (tenkanVal + kijunVal) / 2;
158
+ const senkouBH = Math.max(...highs.slice(-senkouBPeriod));
159
+ const senkouBL = Math.min(...lows.slice(-senkouBPeriod));
160
+ const senkouB = (senkouBH + senkouBL) / 2;
161
+ const chikou = closes[n - 1]; // Current close (projected back 26 periods)
162
+ const price = closes[n - 1];
163
+ const cloudTop = Math.max(senkouA, senkouB);
164
+ const cloudBottom = Math.min(senkouA, senkouB);
165
+ const cloudPosition = price > cloudTop ? 'above' : price < cloudBottom ? 'below' : 'inside';
166
+ return { tenkan: tenkanVal, kijun: kijunVal, senkouA, senkouB, chikou, cloudPosition };
167
+ }
168
+ // ─── OBV (On-Balance Volume) ────────────────────────────────────────────
169
+ export function computeOBV(closes, volumes) {
170
+ if (closes.length < 2)
171
+ return { obv: 0, slope: 'flat' };
172
+ let obv = 0;
173
+ const obvSeries = [0];
174
+ for (let i = 1; i < closes.length; i++) {
175
+ if (closes[i] > closes[i - 1])
176
+ obv += volumes[i];
177
+ else if (closes[i] < closes[i - 1])
178
+ obv -= volumes[i];
179
+ obvSeries.push(obv);
180
+ }
181
+ // Slope over last 10 bars
182
+ const lookback = Math.min(10, obvSeries.length);
183
+ const recent = obvSeries.slice(-lookback);
184
+ const first = recent[0];
185
+ const last = recent[recent.length - 1];
186
+ const threshold = Math.abs(first) * 0.01; // 1% threshold
187
+ const slope = last - first > threshold ? 'rising' : last - first < -threshold ? 'falling' : 'flat';
188
+ return { obv, slope };
189
+ }
190
+ // ─── Supertrend (10, 3) ─────────────────────────────────────────────────
191
+ export function computeSupertrend(highs, lows, closes, period = 10, multiplier = 3) {
192
+ const atrSeries = computeATRSeries(highs, lows, closes, period);
193
+ if (atrSeries.length === 0) {
194
+ return { value: closes[closes.length - 1] ?? 0, direction: 'bullish' };
195
+ }
196
+ // ATR series starts at index 1 (needs previous close for TR)
197
+ // Align: atrSeries[i] corresponds to bar index i+1
198
+ let upperBand = 0;
199
+ let lowerBand = 0;
200
+ let supertrend = 0;
201
+ let direction = 'bullish';
202
+ for (let i = 0; i < atrSeries.length; i++) {
203
+ const barIdx = i + 1; // offset for TR calculation
204
+ const hl2 = (highs[barIdx] + lows[barIdx]) / 2;
205
+ const atr = atrSeries[i];
206
+ const basicUpper = hl2 + multiplier * atr;
207
+ const basicLower = hl2 - multiplier * atr;
208
+ upperBand = i > 0 && basicUpper < upperBand && closes[barIdx - 1] > upperBand ? upperBand : basicUpper;
209
+ lowerBand = i > 0 && basicLower > lowerBand && closes[barIdx - 1] < lowerBand ? lowerBand : basicLower;
210
+ if (i === 0) {
211
+ supertrend = closes[barIdx] > upperBand ? lowerBand : upperBand;
212
+ direction = closes[barIdx] > upperBand ? 'bullish' : 'bearish';
213
+ }
214
+ else {
215
+ if (direction === 'bullish') {
216
+ if (closes[barIdx] < lowerBand) {
217
+ direction = 'bearish';
218
+ supertrend = upperBand;
219
+ }
220
+ else {
221
+ supertrend = lowerBand;
222
+ }
223
+ }
224
+ else {
225
+ if (closes[barIdx] > upperBand) {
226
+ direction = 'bullish';
227
+ supertrend = lowerBand;
228
+ }
229
+ else {
230
+ supertrend = upperBand;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ return { value: supertrend, direction };
236
+ }
237
+ // ─── Williams %R (14) ───────────────────────────────────────────────────
238
+ export function computeWilliamsR(highs, lows, closes, period = 14) {
239
+ if (highs.length < period)
240
+ return -50;
241
+ const recentHighs = highs.slice(-period);
242
+ const recentLows = lows.slice(-period);
243
+ const hh = Math.max(...recentHighs);
244
+ const ll = Math.min(...recentLows);
245
+ const close = closes[closes.length - 1];
246
+ return hh !== ll ? ((hh - close) / (hh - ll)) * -100 : -50;
247
+ }
248
+ // ─── Helper: EMA series ─────────────────────────────────────────────────
249
+ function emaSeries(data, period) {
250
+ if (data.length === 0)
251
+ return [];
252
+ if (data.length < period)
253
+ return [data[data.length - 1]];
254
+ const k = 2 / (period + 1);
255
+ const result = [];
256
+ let ema = mean(data.slice(0, period));
257
+ result.push(ema);
258
+ for (let i = period; i < data.length; i++) {
259
+ ema = data[i] * k + ema * (1 - k);
260
+ result.push(ema);
261
+ }
262
+ return result;
263
+ }
264
+ // ─── Helper: SMA series ─────────────────────────────────────────────────
265
+ function sma(data, period) {
266
+ if (data.length < period)
267
+ return data.length > 0 ? [mean(data)] : [];
268
+ const result = [];
269
+ for (let i = period - 1; i < data.length; i++) {
270
+ result.push(mean(data.slice(i - period + 1, i + 1)));
271
+ }
272
+ return result;
273
+ }
274
+ // ─── Helper: Wilder's smoothing ─────────────────────────────────────────
275
+ function wilderSmooth(data, period) {
276
+ if (data.length < period)
277
+ return [];
278
+ const result = [];
279
+ result.push(mean(data.slice(0, period)));
280
+ for (let i = period; i < data.length; i++) {
281
+ result.push((result[result.length - 1] * (period - 1) + data[i]) / period);
282
+ }
283
+ return result;
284
+ }
@@ -0,0 +1,15 @@
1
+ export declare function computeEMA(data: number[], period: number): number;
2
+ export declare function computeATR(highs: number[], lows: number[], closes: number[], period: number): number;
3
+ export declare function computeATRSeries(highs: number[], lows: number[], closes: number[], period: number): number[];
4
+ export declare function computeRSI(closes: number[], period: number): number;
5
+ export declare function linearSlope(y: number[], x?: number[]): number;
6
+ export declare function computeStd(data: number[]): number;
7
+ export declare function mean(data: number[]): number;
8
+ /** Find swing highs and lows from OHLCV bars (simple pivot-point method). */
9
+ export declare function findSwingPoints(bars: {
10
+ high: number;
11
+ low: number;
12
+ }[], lookback?: number): {
13
+ highs: number[];
14
+ lows: number[];
15
+ };
@@ -0,0 +1,107 @@
1
+ // Shared indicator computation helpers.
2
+ // Used by both regime feature engineering and signal condition evaluation.
3
+ export function computeEMA(data, period) {
4
+ if (data.length < period)
5
+ return data[data.length - 1] ?? 0;
6
+ const k = 2 / (period + 1);
7
+ let ema = mean(data.slice(0, period));
8
+ for (let i = period; i < data.length; i++) {
9
+ ema = data[i] * k + ema * (1 - k);
10
+ }
11
+ return ema;
12
+ }
13
+ export function computeATR(highs, lows, closes, period) {
14
+ const series = computeATRSeries(highs, lows, closes, period);
15
+ return series[series.length - 1] ?? 0;
16
+ }
17
+ export function computeATRSeries(highs, lows, closes, period) {
18
+ if (highs.length < 2)
19
+ return [];
20
+ const tr = [];
21
+ for (let i = 1; i < highs.length; i++) {
22
+ tr.push(Math.max(highs[i] - lows[i], Math.abs(highs[i] - closes[i - 1]), Math.abs(lows[i] - closes[i - 1])));
23
+ }
24
+ const atr = [];
25
+ atr[0] = mean(tr.slice(0, period));
26
+ for (let i = 1; i < tr.length; i++) {
27
+ atr[i] = (atr[i - 1] * (period - 1) + tr[i]) / period;
28
+ }
29
+ return atr;
30
+ }
31
+ export function computeRSI(closes, period) {
32
+ if (closes.length < period + 1)
33
+ return 50;
34
+ const changes = [];
35
+ for (let i = 1; i < closes.length; i++) {
36
+ changes.push(closes[i] - closes[i - 1]);
37
+ }
38
+ let avgGain = 0;
39
+ let avgLoss = 0;
40
+ for (let i = 0; i < period; i++) {
41
+ if (changes[i] > 0)
42
+ avgGain += changes[i];
43
+ else
44
+ avgLoss -= changes[i];
45
+ }
46
+ avgGain /= period;
47
+ avgLoss /= period;
48
+ for (let i = period; i < changes.length; i++) {
49
+ const gain = changes[i] > 0 ? changes[i] : 0;
50
+ const loss = changes[i] < 0 ? -changes[i] : 0;
51
+ avgGain = (avgGain * (period - 1) + gain) / period;
52
+ avgLoss = (avgLoss * (period - 1) + loss) / period;
53
+ }
54
+ if (avgLoss === 0)
55
+ return 100;
56
+ const rs = avgGain / avgLoss;
57
+ return 100 - 100 / (1 + rs);
58
+ }
59
+ export function linearSlope(y, x) {
60
+ const n = y.length;
61
+ if (n < 2)
62
+ return 0;
63
+ const xs = x ?? Array.from({ length: n }, (_, i) => i);
64
+ const mx = mean(xs);
65
+ const my = mean(y);
66
+ let num = 0;
67
+ let den = 0;
68
+ for (let i = 0; i < n; i++) {
69
+ num += (xs[i] - mx) * (y[i] - my);
70
+ den += (xs[i] - mx) ** 2;
71
+ }
72
+ return den > 0 ? num / den : 0;
73
+ }
74
+ export function computeStd(data) {
75
+ if (data.length < 2)
76
+ return 0;
77
+ const avg = mean(data);
78
+ const variance = data.reduce((s, v) => s + (v - avg) ** 2, 0) / (data.length - 1);
79
+ return Math.sqrt(variance);
80
+ }
81
+ export function mean(data) {
82
+ if (data.length === 0)
83
+ return 0;
84
+ return data.reduce((s, v) => s + v, 0) / data.length;
85
+ }
86
+ /** Find swing highs and lows from OHLCV bars (simple pivot-point method). */
87
+ export function findSwingPoints(bars, lookback = 5) {
88
+ const highs = [];
89
+ const lows = [];
90
+ for (let i = lookback; i < bars.length - lookback; i++) {
91
+ let isHigh = true;
92
+ let isLow = true;
93
+ for (let j = i - lookback; j <= i + lookback; j++) {
94
+ if (j === i)
95
+ continue;
96
+ if (bars[j].high >= bars[i].high)
97
+ isHigh = false;
98
+ if (bars[j].low <= bars[i].low)
99
+ isLow = false;
100
+ }
101
+ if (isHigh)
102
+ highs.push(bars[i].high);
103
+ if (isLow)
104
+ lows.push(bars[i].low);
105
+ }
106
+ return { highs, lows };
107
+ }
@@ -0,0 +1,16 @@
1
+ import type { MarketContext, Direction } from '../types.js';
2
+ import type { ConditionFn, ConditionConfig, ConditionContext } from './types.js';
3
+ export declare function getConditionFn(type: string): ConditionFn | undefined;
4
+ export declare function hasCondition(type: string): boolean;
5
+ export declare function listConditionTypes(): string[];
6
+ /** Evaluate an array of condition configs. Returns SignalCondition[] + shared context. */
7
+ export declare function evaluateConditions(configs: ConditionConfig[], ctx: MarketContext, direction: Direction | null): {
8
+ conditions: Array<{
9
+ name: string;
10
+ met: boolean;
11
+ currentValue: number;
12
+ threshold: number;
13
+ description: string;
14
+ }>;
15
+ condCtx: ConditionContext;
16
+ };