@reefclaw/connect 0.1.12 → 0.1.14
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.
- package/assets/plugin/audit/mode-transition-audit.d.ts +11 -0
- package/assets/plugin/audit/mode-transition-audit.js +29 -0
- package/assets/plugin/balance-utils.d.ts +36 -0
- package/assets/plugin/balance-utils.js +98 -0
- package/assets/plugin/ccxt/binance-ban-gate.d.ts +47 -0
- package/assets/plugin/ccxt/binance-ban-gate.js +420 -0
- package/assets/plugin/ccxt/binance-private.d.ts +346 -0
- package/assets/plugin/ccxt/binance-private.js +1525 -0
- package/assets/plugin/ccxt/binance-public.d.ts +34 -0
- package/assets/plugin/ccxt/binance-public.js +180 -0
- package/assets/plugin/ccxt/intel-public.d.ts +25 -0
- package/assets/plugin/ccxt/intel-public.js +80 -0
- package/assets/plugin/ccxt/public-market-data-api.d.ts +26 -0
- package/assets/plugin/ccxt/public-market-data-api.js +23 -0
- package/assets/plugin/config/agent-config-client.d.ts +77 -0
- package/assets/plugin/config/agent-config-client.js +188 -0
- package/assets/plugin/config/agent-config-poller.d.ts +32 -0
- package/assets/plugin/config/agent-config-poller.js +101 -0
- package/assets/plugin/config/brackets-config.d.ts +22 -0
- package/assets/plugin/config/brackets-config.js +58 -0
- package/assets/plugin/config/entitlement-gate.d.ts +51 -0
- package/assets/plugin/config/entitlement-gate.js +137 -0
- package/assets/plugin/config/gate-store.d.ts +18 -0
- package/assets/plugin/config/gate-store.js +61 -0
- package/assets/plugin/config/plugin-config-io.d.ts +222 -0
- package/assets/plugin/config/plugin-config-io.js +126 -0
- package/assets/plugin/config/position-review-config.d.ts +35 -0
- package/assets/plugin/config/position-review-config.js +105 -0
- package/assets/plugin/config/tool-gate.d.ts +53 -0
- package/assets/plugin/config/tool-gate.js +128 -0
- package/assets/plugin/config/user-data-stream-config.d.ts +89 -0
- package/assets/plugin/config/user-data-stream-config.js +239 -0
- package/assets/plugin/connector-supervisor.d.ts +36 -0
- package/assets/plugin/connector-supervisor.js +149 -0
- package/assets/plugin/exchange-adapter.d.ts +65 -0
- package/assets/plugin/exchange-adapter.js +4 -0
- package/assets/plugin/index.d.ts +30 -0
- package/assets/plugin/index.js +2763 -0
- package/assets/plugin/ingest/pending-entry-metadata.d.ts +74 -0
- package/assets/plugin/ingest/pending-entry-metadata.js +236 -0
- package/assets/plugin/ingest/position-auto-capture.d.ts +171 -0
- package/assets/plugin/ingest/position-auto-capture.js +709 -0
- package/assets/plugin/ingest/position-decisions-client.d.ts +327 -0
- package/assets/plugin/ingest/position-decisions-client.js +306 -0
- package/assets/plugin/ingest/readiness-reporter.d.ts +42 -0
- package/assets/plugin/ingest/readiness-reporter.js +163 -0
- package/assets/plugin/ingest/reconcile-db-vs-exchange.d.ts +51 -0
- package/assets/plugin/ingest/reconcile-db-vs-exchange.js +170 -0
- package/assets/plugin/ingest/reconciler-cleanup.d.ts +37 -0
- package/assets/plugin/ingest/reconciler-cleanup.js +147 -0
- package/assets/plugin/ingest/rest-gap-filler.d.ts +191 -0
- package/assets/plugin/ingest/rest-gap-filler.js +565 -0
- package/assets/plugin/ingest/touched-symbols-store.d.ts +25 -0
- package/assets/plugin/ingest/touched-symbols-store.js +96 -0
- package/assets/plugin/ingest/trade-store-client.d.ts +40 -0
- package/assets/plugin/ingest/trade-store-client.js +125 -0
- package/assets/plugin/ingest/ws-ingest.d.ts +43 -0
- package/assets/plugin/ingest/ws-ingest.js +126 -0
- package/assets/plugin/learning/setup-family.d.ts +21 -0
- package/assets/plugin/learning/setup-family.js +103 -0
- package/assets/plugin/lifecycle/install-signal-handlers.d.ts +33 -0
- package/assets/plugin/lifecycle/install-signal-handlers.js +112 -0
- package/assets/plugin/lifecycle/shutdown-coordinator.d.ts +43 -0
- package/assets/plugin/lifecycle/shutdown-coordinator.js +131 -0
- package/assets/plugin/lifecycle/trading-operation-lock.d.ts +17 -0
- package/assets/plugin/lifecycle/trading-operation-lock.js +14 -0
- package/assets/plugin/live/bracket-id.d.ts +26 -0
- package/assets/plugin/live/bracket-id.js +112 -0
- package/assets/plugin/live/bracket-ledger.d.ts +54 -0
- package/assets/plugin/live/bracket-ledger.js +267 -0
- package/assets/plugin/live/bracket-manager.d.ts +82 -0
- package/assets/plugin/live/bracket-manager.js +478 -0
- package/assets/plugin/live/bracket-params.d.ts +22 -0
- package/assets/plugin/live/bracket-params.js +124 -0
- package/assets/plugin/live/bracket-reconciler.d.ts +95 -0
- package/assets/plugin/live/bracket-reconciler.js +573 -0
- package/assets/plugin/live/bracket-types.d.ts +102 -0
- package/assets/plugin/live/bracket-types.js +8 -0
- package/assets/plugin/live/deposit-tracker.d.ts +62 -0
- package/assets/plugin/live/deposit-tracker.js +97 -0
- package/assets/plugin/live/emergency-controls.d.ts +32 -0
- package/assets/plugin/live/emergency-controls.js +226 -0
- package/assets/plugin/live/exchange-errors.d.ts +12 -0
- package/assets/plugin/live/exchange-errors.js +130 -0
- package/assets/plugin/live/exchange-info-cache.d.ts +37 -0
- package/assets/plugin/live/exchange-info-cache.js +134 -0
- package/assets/plugin/live/fact-subscriber.d.ts +78 -0
- package/assets/plugin/live/fact-subscriber.js +182 -0
- package/assets/plugin/live/fill-price.d.ts +13 -0
- package/assets/plugin/live/fill-price.js +37 -0
- package/assets/plugin/live/intent-journal.d.ts +42 -0
- package/assets/plugin/live/intent-journal.js +122 -0
- package/assets/plugin/live/listen-key-manager.d.ts +70 -0
- package/assets/plugin/live/listen-key-manager.js +169 -0
- package/assets/plugin/live/live-adapter.d.ts +319 -0
- package/assets/plugin/live/live-adapter.js +1906 -0
- package/assets/plugin/live/live-balance-enricher.d.ts +32 -0
- package/assets/plugin/live/live-balance-enricher.js +104 -0
- package/assets/plugin/live/live-bracket-api.d.ts +13 -0
- package/assets/plugin/live/live-bracket-api.js +20 -0
- package/assets/plugin/live/live-state-store.d.ts +194 -0
- package/assets/plugin/live/live-state-store.js +450 -0
- package/assets/plugin/live/local-signal-service.d.ts +57 -0
- package/assets/plugin/live/local-signal-service.js +151 -0
- package/assets/plugin/live/local-strategy-evaluator.d.ts +62 -0
- package/assets/plugin/live/local-strategy-evaluator.js +131 -0
- package/assets/plugin/live/microstructure-assembler.d.ts +54 -0
- package/assets/plugin/live/microstructure-assembler.js +148 -0
- package/assets/plugin/live/order-poller.d.ts +29 -0
- package/assets/plugin/live/order-poller.js +125 -0
- package/assets/plugin/live/position-state-store.d.ts +87 -0
- package/assets/plugin/live/position-state-store.js +237 -0
- package/assets/plugin/live/proposal-decision-listener.d.ts +70 -0
- package/assets/plugin/live/proposal-decision-listener.js +292 -0
- package/assets/plugin/live/proposal-manager.d.ts +76 -0
- package/assets/plugin/live/proposal-manager.js +140 -0
- package/assets/plugin/live/rate-limiter.d.ts +47 -0
- package/assets/plugin/live/rate-limiter.js +159 -0
- package/assets/plugin/live/reconciler.d.ts +39 -0
- package/assets/plugin/live/reconciler.js +175 -0
- package/assets/plugin/live/setup-buckets.d.ts +7 -0
- package/assets/plugin/live/setup-buckets.js +33 -0
- package/assets/plugin/live/slippage-tracker.d.ts +45 -0
- package/assets/plugin/live/slippage-tracker.js +78 -0
- package/assets/plugin/live/stop-watcher.d.ts +67 -0
- package/assets/plugin/live/stop-watcher.js +218 -0
- package/assets/plugin/live/user-data-active-probe.d.ts +54 -0
- package/assets/plugin/live/user-data-active-probe.js +180 -0
- package/assets/plugin/live/user-data-stream-controller.d.ts +200 -0
- package/assets/plugin/live/user-data-stream-controller.js +579 -0
- package/assets/plugin/live/user-data-stream-ws.d.ts +22 -0
- package/assets/plugin/live/user-data-stream-ws.js +63 -0
- package/assets/plugin/live/user-data-stream.d.ts +243 -0
- package/assets/plugin/live/user-data-stream.js +704 -0
- package/assets/plugin/logger.d.ts +2 -0
- package/assets/plugin/logger.js +2 -0
- package/assets/plugin/mfe.d.ts +21 -0
- package/assets/plugin/mfe.js +68 -0
- package/assets/plugin/onboarding/mode-ladder.d.ts +1 -0
- package/assets/plugin/onboarding/mode-ladder.js +3 -0
- package/assets/plugin/onboarding/runtime.d.ts +102 -0
- package/assets/plugin/onboarding/runtime.js +215 -0
- package/assets/plugin/openclaw.plugin.json +92 -0
- package/assets/plugin/paper-adapter.d.ts +24 -0
- package/assets/plugin/paper-adapter.js +91 -0
- package/assets/plugin/persistence/state-manager.d.ts +66 -0
- package/assets/plugin/persistence/state-manager.js +222 -0
- package/assets/plugin/pinned-plan.d.ts +9 -0
- package/assets/plugin/pinned-plan.js +23 -0
- package/assets/plugin/portfolio/reentry-tracker.d.ts +36 -0
- package/assets/plugin/portfolio/reentry-tracker.js +127 -0
- package/assets/plugin/portfolio/wave9-admission.d.ts +67 -0
- package/assets/plugin/portfolio/wave9-admission.js +262 -0
- package/assets/plugin/portfolio/wave9-policy.d.ts +36 -0
- package/assets/plugin/portfolio/wave9-policy.js +183 -0
- package/assets/plugin/risk/pre-trade-check.d.ts +38 -0
- package/assets/plugin/risk/pre-trade-check.js +345 -0
- package/assets/plugin/risk/pre-trade-types.d.ts +60 -0
- package/assets/plugin/risk/pre-trade-types.js +3 -0
- package/assets/plugin/shadow/shadow-tracker.d.ts +36 -0
- package/assets/plugin/shadow/shadow-tracker.js +151 -0
- package/assets/plugin/shadow/types.d.ts +42 -0
- package/assets/plugin/shadow/types.js +20 -0
- package/assets/plugin/shared/indicators-extended.d.ts +52 -0
- package/assets/plugin/shared/indicators-extended.js +291 -0
- package/assets/plugin/shared/indicators.d.ts +15 -0
- package/assets/plugin/shared/indicators.js +114 -0
- package/assets/plugin/signals/conditions/registry.d.ts +16 -0
- package/assets/plugin/signals/conditions/registry.js +1333 -0
- package/assets/plugin/signals/conditions/types.d.ts +1 -0
- package/assets/plugin/signals/conditions/types.js +4 -0
- package/assets/plugin/signals/direction-rules.d.ts +3 -0
- package/assets/plugin/signals/direction-rules.js +24 -0
- package/assets/plugin/signals/entry-rules.d.ts +6 -0
- package/assets/plugin/signals/entry-rules.js +33 -0
- package/assets/plugin/signals/serialize-context.d.ts +4 -0
- package/assets/plugin/signals/serialize-context.js +39 -0
- package/assets/plugin/signals/stop-rules.d.ts +3 -0
- package/assets/plugin/signals/stop-rules.js +48 -0
- package/assets/plugin/signals/strategy-adapter.d.ts +47 -0
- package/assets/plugin/signals/strategy-adapter.js +209 -0
- package/assets/plugin/signals/types.d.ts +1 -0
- package/assets/plugin/signals/types.js +8 -0
- package/assets/plugin/simulator/exchange-simulator.d.ts +105 -0
- package/assets/plugin/simulator/exchange-simulator.js +759 -0
- package/assets/plugin/simulator/fill-engine.d.ts +53 -0
- package/assets/plugin/simulator/fill-engine.js +280 -0
- package/assets/plugin/simulator/paper-market-feed.d.ts +26 -0
- package/assets/plugin/simulator/paper-market-feed.js +104 -0
- package/assets/plugin/simulator/realistic-fills.d.ts +59 -0
- package/assets/plugin/simulator/realistic-fills.js +175 -0
- package/assets/plugin/simulator/types.d.ts +228 -0
- package/assets/plugin/simulator/types.js +43 -0
- package/assets/plugin/strategy/builtin-strategies.d.ts +2 -0
- package/assets/plugin/strategy/builtin-strategies.js +113 -0
- package/assets/plugin/strategy/condition-registry.d.ts +3 -0
- package/assets/plugin/strategy/condition-registry.js +153 -0
- package/assets/plugin/strategy/evaluator.d.ts +70 -0
- package/assets/plugin/strategy/evaluator.js +98 -0
- package/assets/plugin/tools/assessment-validation.d.ts +141 -0
- package/assets/plugin/tools/assessment-validation.js +473 -0
- package/assets/plugin/tools/attach-brackets.d.ts +39 -0
- package/assets/plugin/tools/attach-brackets.js +564 -0
- package/assets/plugin/tools/audit-bracket-protection.d.ts +49 -0
- package/assets/plugin/tools/audit-bracket-protection.js +683 -0
- package/assets/plugin/tools/bracket-control.d.ts +12 -0
- package/assets/plugin/tools/bracket-control.js +35 -0
- package/assets/plugin/tools/cancel-all-orders.d.ts +9 -0
- package/assets/plugin/tools/cancel-all-orders.js +8 -0
- package/assets/plugin/tools/cancel-order.d.ts +14 -0
- package/assets/plugin/tools/cancel-order.js +60 -0
- package/assets/plugin/tools/check-position-health.d.ts +46 -0
- package/assets/plugin/tools/check-position-health.js +194 -0
- package/assets/plugin/tools/clear-exchange-credentials.d.ts +24 -0
- package/assets/plugin/tools/clear-exchange-credentials.js +70 -0
- package/assets/plugin/tools/close-position.d.ts +45 -0
- package/assets/plugin/tools/close-position.js +722 -0
- package/assets/plugin/tools/create-order.d.ts +89 -0
- package/assets/plugin/tools/create-order.js +1555 -0
- package/assets/plugin/tools/exit-gate.d.ts +58 -0
- package/assets/plugin/tools/exit-gate.js +162 -0
- package/assets/plugin/tools/fetch-balance.d.ts +5 -0
- package/assets/plugin/tools/fetch-balance.js +4 -0
- package/assets/plugin/tools/fetch-ohlcv.d.ts +11 -0
- package/assets/plugin/tools/fetch-ohlcv.js +8 -0
- package/assets/plugin/tools/fetch-open-orders.d.ts +7 -0
- package/assets/plugin/tools/fetch-open-orders.js +4 -0
- package/assets/plugin/tools/fetch-positions.d.ts +7 -0
- package/assets/plugin/tools/fetch-positions.js +4 -0
- package/assets/plugin/tools/fetch-ticker.d.ts +11 -0
- package/assets/plugin/tools/fetch-ticker.js +5 -0
- package/assets/plugin/tools/get-agent-profile.d.ts +4 -0
- package/assets/plugin/tools/get-agent-profile.js +6 -0
- package/assets/plugin/tools/get-analytics.d.ts +6 -0
- package/assets/plugin/tools/get-analytics.js +7 -0
- package/assets/plugin/tools/get-backtest.d.ts +12 -0
- package/assets/plugin/tools/get-backtest.js +91 -0
- package/assets/plugin/tools/get-basis.d.ts +7 -0
- package/assets/plugin/tools/get-basis.js +7 -0
- package/assets/plugin/tools/get-bracket-config.d.ts +11 -0
- package/assets/plugin/tools/get-bracket-config.js +24 -0
- package/assets/plugin/tools/get-cascade-risk.d.ts +7 -0
- package/assets/plugin/tools/get-cascade-risk.js +8 -0
- package/assets/plugin/tools/get-crypto-metrics.d.ts +18 -0
- package/assets/plugin/tools/get-crypto-metrics.js +62 -0
- package/assets/plugin/tools/get-cvd.d.ts +6 -0
- package/assets/plugin/tools/get-cvd.js +6 -0
- package/assets/plugin/tools/get-divergences.d.ts +6 -0
- package/assets/plugin/tools/get-divergences.js +6 -0
- package/assets/plugin/tools/get-funding-context.d.ts +6 -0
- package/assets/plugin/tools/get-funding-context.js +16 -0
- package/assets/plugin/tools/get-liquidation-levels.d.ts +7 -0
- package/assets/plugin/tools/get-liquidation-levels.js +7 -0
- package/assets/plugin/tools/get-liquidation-pulse.d.ts +9 -0
- package/assets/plugin/tools/get-liquidation-pulse.js +22 -0
- package/assets/plugin/tools/get-market-breadth.d.ts +6 -0
- package/assets/plugin/tools/get-market-breadth.js +8 -0
- package/assets/plugin/tools/get-market-intel.d.ts +19 -0
- package/assets/plugin/tools/get-market-intel.js +116 -0
- package/assets/plugin/tools/get-market-structure.d.ts +47 -0
- package/assets/plugin/tools/get-market-structure.js +198 -0
- package/assets/plugin/tools/get-my-mined-patterns.d.ts +20 -0
- package/assets/plugin/tools/get-my-mined-patterns.js +61 -0
- package/assets/plugin/tools/get-my-proposed-learnings.d.ts +20 -0
- package/assets/plugin/tools/get-my-proposed-learnings.js +55 -0
- package/assets/plugin/tools/get-my-recent-reviews.d.ts +22 -0
- package/assets/plugin/tools/get-my-recent-reviews.js +66 -0
- package/assets/plugin/tools/get-orderbook.d.ts +21 -0
- package/assets/plugin/tools/get-orderbook.js +32 -0
- package/assets/plugin/tools/get-pattern-scan.d.ts +7 -0
- package/assets/plugin/tools/get-pattern-scan.js +8 -0
- package/assets/plugin/tools/get-regime.d.ts +6 -0
- package/assets/plugin/tools/get-regime.js +7 -0
- package/assets/plugin/tools/get-relevant-learnings.d.ts +21 -0
- package/assets/plugin/tools/get-relevant-learnings.js +65 -0
- package/assets/plugin/tools/get-resting-liquidity.d.ts +6 -0
- package/assets/plugin/tools/get-resting-liquidity.js +11 -0
- package/assets/plugin/tools/get-risk-scenario.d.ts +29 -0
- package/assets/plugin/tools/get-risk-scenario.js +47 -0
- package/assets/plugin/tools/get-risk-summary.d.ts +51 -0
- package/assets/plugin/tools/get-risk-summary.js +118 -0
- package/assets/plugin/tools/get-sentiment.d.ts +4 -0
- package/assets/plugin/tools/get-sentiment.js +6 -0
- package/assets/plugin/tools/get-session-review.d.ts +7 -0
- package/assets/plugin/tools/get-session-review.js +8 -0
- package/assets/plugin/tools/get-setup-detail.d.ts +7 -0
- package/assets/plugin/tools/get-setup-detail.js +322 -0
- package/assets/plugin/tools/get-signals.d.ts +15 -0
- package/assets/plugin/tools/get-signals.js +54 -0
- package/assets/plugin/tools/get-sizing.d.ts +6 -0
- package/assets/plugin/tools/get-sizing.js +6 -0
- package/assets/plugin/tools/get-trade-feedback.d.ts +7 -0
- package/assets/plugin/tools/get-trade-feedback.js +8 -0
- package/assets/plugin/tools/get-trade-flow.d.ts +7 -0
- package/assets/plugin/tools/get-trade-flow.js +7 -0
- package/assets/plugin/tools/get-volume-analysis.d.ts +21 -0
- package/assets/plugin/tools/get-volume-analysis.js +74 -0
- package/assets/plugin/tools/get-volume-profile.d.ts +7 -0
- package/assets/plugin/tools/get-volume-profile.js +7 -0
- package/assets/plugin/tools/get-wave9-status.d.ts +127 -0
- package/assets/plugin/tools/get-wave9-status.js +796 -0
- package/assets/plugin/tools/helpers.d.ts +26 -0
- package/assets/plugin/tools/helpers.js +39 -0
- package/assets/plugin/tools/intel-api.d.ts +34 -0
- package/assets/plugin/tools/intel-api.js +119 -0
- package/assets/plugin/tools/intel-cache.d.ts +25 -0
- package/assets/plugin/tools/intel-cache.js +148 -0
- package/assets/plugin/tools/list-strategies.d.ts +17 -0
- package/assets/plugin/tools/list-strategies.js +23 -0
- package/assets/plugin/tools/modify-stop.d.ts +21 -0
- package/assets/plugin/tools/modify-stop.js +120 -0
- package/assets/plugin/tools/modify-target.d.ts +21 -0
- package/assets/plugin/tools/modify-target.js +110 -0
- package/assets/plugin/tools/propose-learning.d.ts +22 -0
- package/assets/plugin/tools/propose-learning.js +65 -0
- package/assets/plugin/tools/query-review-outcomes.d.ts +30 -0
- package/assets/plugin/tools/query-review-outcomes.js +64 -0
- package/assets/plugin/tools/query-trades.d.ts +21 -0
- package/assets/plugin/tools/query-trades.js +37 -0
- package/assets/plugin/tools/record-position-reviews.d.ts +38 -0
- package/assets/plugin/tools/record-position-reviews.js +147 -0
- package/assets/plugin/tools/save-strategy.d.ts +16 -0
- package/assets/plugin/tools/save-strategy.js +46 -0
- package/assets/plugin/tools/scan-pairs.d.ts +22 -0
- package/assets/plugin/tools/scan-pairs.js +234 -0
- package/assets/plugin/tools/score-setup.d.ts +31 -0
- package/assets/plugin/tools/score-setup.js +268 -0
- package/assets/plugin/tools/set-bracket-requirement.d.ts +18 -0
- package/assets/plugin/tools/set-bracket-requirement.js +81 -0
- package/assets/plugin/tools/set-exchange-credentials.d.ts +25 -0
- package/assets/plugin/tools/set-exchange-credentials.js +80 -0
- package/assets/plugin/tools/set-trading-mode.d.ts +26 -0
- package/assets/plugin/tools/set-trading-mode.js +152 -0
- package/assets/plugin/tools/test-exchange-credentials.d.ts +16 -0
- package/assets/plugin/tools/test-exchange-credentials.js +100 -0
- package/assets/plugin/tools/toggle-strategy.d.ts +8 -0
- package/assets/plugin/tools/toggle-strategy.js +15 -0
- package/assets/plugin/trading-params-cache.d.ts +26 -0
- package/assets/plugin/trading-params-cache.js +52 -0
- package/assets/plugin/types.d.ts +134 -0
- package/assets/plugin/types.js +7 -0
- package/assets/plugin/util/plugin-paths.d.ts +3 -0
- package/assets/plugin/util/plugin-paths.js +15 -0
- package/assets/plugin/venues/hyperliquid/hl-balance.d.ts +116 -0
- package/assets/plugin/venues/hyperliquid/hl-balance.js +145 -0
- package/assets/plugin/venues/hyperliquid/hl-bracket-coordinator.d.ts +123 -0
- package/assets/plugin/venues/hyperliquid/hl-bracket-coordinator.js +533 -0
- package/assets/plugin/venues/hyperliquid/hl-brackets.d.ts +102 -0
- package/assets/plugin/venues/hyperliquid/hl-brackets.js +172 -0
- package/assets/plugin/venues/hyperliquid/hl-cloid.d.ts +22 -0
- package/assets/plugin/venues/hyperliquid/hl-cloid.js +82 -0
- package/assets/plugin/venues/hyperliquid/hl-info-cache.d.ts +46 -0
- package/assets/plugin/venues/hyperliquid/hl-info-cache.js +125 -0
- package/assets/plugin/venues/hyperliquid/hl-live-adapter.d.ts +146 -0
- package/assets/plugin/venues/hyperliquid/hl-live-adapter.js +728 -0
- package/assets/plugin/venues/hyperliquid/hl-precision.d.ts +61 -0
- package/assets/plugin/venues/hyperliquid/hl-precision.js +176 -0
- package/assets/plugin/venues/hyperliquid/hl-private.d.ts +88 -0
- package/assets/plugin/venues/hyperliquid/hl-private.js +357 -0
- package/assets/plugin/venues/hyperliquid/hl-public.d.ts +79 -0
- package/assets/plugin/venues/hyperliquid/hl-public.js +436 -0
- package/assets/plugin/venues/hyperliquid/hl-rate-gate.d.ts +57 -0
- package/assets/plugin/venues/hyperliquid/hl-rate-gate.js +220 -0
- package/assets/plugin/venues/hyperliquid/hl-user-stream.d.ts +90 -0
- package/assets/plugin/venues/hyperliquid/hl-user-stream.js +220 -0
- package/assets/plugin/venues/registry.d.ts +38 -0
- package/assets/plugin/venues/registry.js +46 -0
- package/assets/plugin/venues/symbols.d.ts +43 -0
- package/assets/plugin/venues/symbols.js +107 -0
- package/assets/plugin/wave9/live-account-capture.d.ts +67 -0
- package/assets/plugin/wave9/live-account-capture.js +435 -0
- package/assets/plugin/wave9/live-autonomous-protection.d.ts +39 -0
- package/assets/plugin/wave9/live-autonomous-protection.js +112 -0
- package/assets/plugin/wave9/live-durable-reconciliation-scheduler.d.ts +33 -0
- package/assets/plugin/wave9/live-durable-reconciliation-scheduler.js +115 -0
- package/assets/plugin/wave9/live-execution-ledger.d.ts +107 -0
- package/assets/plugin/wave9/live-execution-ledger.js +498 -0
- package/assets/plugin/wave9/live-position-confirmation.d.ts +18 -0
- package/assets/plugin/wave9/live-position-confirmation.js +111 -0
- package/assets/plugin/wave9/live-residual-protection.d.ts +18 -0
- package/assets/plugin/wave9/live-residual-protection.js +250 -0
- package/assets/plugin/wave9/live-startup-reconciliation.d.ts +38 -0
- package/assets/plugin/wave9/live-startup-reconciliation.js +454 -0
- package/assets/plugin/wave9/live-symbol-ownership.d.ts +20 -0
- package/assets/plugin/wave9/live-symbol-ownership.js +132 -0
- package/assets/plugin/wave9/paper-admission-guard.d.ts +199 -0
- package/assets/plugin/wave9/paper-admission-guard.js +650 -0
- package/assets/plugin/wave9/usdm-evidence-provider.d.ts +42 -0
- package/assets/plugin/wave9/usdm-evidence-provider.js +133 -0
- package/dist/plugin.js +24 -15
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { ConditionResult, ConditionContext, ConditionFn, ConditionConfig, EntryRuleConfig, StopRuleConfig, DirectionRule, PrimaryTimeframe, StrategyConfig, } from '@reefclaw/shared';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// ⚠️ GENERATED FILE — DO NOT EDIT.
|
|
2
|
+
// Canonical source of truth: shared/src/signals/direction-rules.ts
|
|
3
|
+
// Regenerate: node scripts/sync-shared-code.mjs (enforced by shared-code-sync.test.ts)
|
|
4
|
+
//
|
|
5
|
+
// This copy exists because this package builds with tsc and deploys as a
|
|
6
|
+
// self-contained tree that strips workspace deps, so it cannot import
|
|
7
|
+
// @reefclaw/shared runtime code across the deploy boundary.
|
|
8
|
+
export function resolveDirection(rule, ctx, condCtx) {
|
|
9
|
+
switch (rule) {
|
|
10
|
+
case 'from_regime':
|
|
11
|
+
return ctx.regime === 'TREND_UP' ? 'LONG' : ctx.regime === 'TREND_DOWN' ? 'SHORT' : null;
|
|
12
|
+
case 'from_sweep':
|
|
13
|
+
return condCtx.sweptDirection ?? null;
|
|
14
|
+
case 'from_funding':
|
|
15
|
+
// funding_extreme condition sets sweptDirection to the contra direction
|
|
16
|
+
return condCtx.sweptDirection ?? null;
|
|
17
|
+
case 'fixed_long':
|
|
18
|
+
return 'LONG';
|
|
19
|
+
case 'fixed_short':
|
|
20
|
+
return 'SHORT';
|
|
21
|
+
default:
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { MarketContext, Direction } from './types.js';
|
|
2
|
+
import type { EntryRuleConfig, ConditionContext } from './conditions/types.js';
|
|
3
|
+
export declare function computeEntry(rule: EntryRuleConfig, ctx: MarketContext, direction: Direction, condCtx: ConditionContext): {
|
|
4
|
+
low: number;
|
|
5
|
+
high: number;
|
|
6
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// ⚠️ GENERATED FILE — DO NOT EDIT.
|
|
2
|
+
// Canonical source of truth: shared/src/signals/entry-rules.ts
|
|
3
|
+
// Regenerate: node scripts/sync-shared-code.mjs (enforced by shared-code-sync.test.ts)
|
|
4
|
+
//
|
|
5
|
+
// This copy exists because this package builds with tsc and deploys as a
|
|
6
|
+
// self-contained tree that strips workspace deps, so it cannot import
|
|
7
|
+
// @reefclaw/shared runtime code across the deploy boundary.
|
|
8
|
+
// Entry zone calculation for declarative strategies.
|
|
9
|
+
import { computeEMA } from '../shared/indicators.js';
|
|
10
|
+
export function computeEntry(rule, ctx, direction, condCtx) {
|
|
11
|
+
switch (rule.type) {
|
|
12
|
+
case 'ema_offset': {
|
|
13
|
+
const period = rule.params.period ?? 21;
|
|
14
|
+
const atrFraction = (rule.params.atrFraction ?? 0.3) * ctx.atr14;
|
|
15
|
+
const ema = condCtx.ema21 && period === 21
|
|
16
|
+
? condCtx.ema21
|
|
17
|
+
: computeEMA(ctx.ohlcv1h.map(b => b.close), period);
|
|
18
|
+
return { low: ema - atrFraction, high: ema + atrFraction };
|
|
19
|
+
}
|
|
20
|
+
case 'sweep_range': {
|
|
21
|
+
const sweepLevel = condCtx.sweepLevel ?? ctx.currentPrice;
|
|
22
|
+
return direction === 'LONG'
|
|
23
|
+
? { low: sweepLevel, high: ctx.currentPrice }
|
|
24
|
+
: { low: ctx.currentPrice, high: sweepLevel };
|
|
25
|
+
}
|
|
26
|
+
case 'atr_offset': {
|
|
27
|
+
const atrFraction = (rule.params.atrFraction ?? 0.2) * ctx.atr14;
|
|
28
|
+
return { low: ctx.currentPrice - atrFraction, high: ctx.currentPrice + atrFraction };
|
|
29
|
+
}
|
|
30
|
+
default:
|
|
31
|
+
return { low: ctx.currentPrice - ctx.atr14 * 0.3, high: ctx.currentPrice + ctx.atr14 * 0.3 };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { MarketContext } from './types.js';
|
|
2
|
+
export declare function serializeContext(ctx: MarketContext): string;
|
|
3
|
+
/** Parse a streamed context and rehydrate every Date field. Throws on bad JSON. */
|
|
4
|
+
export declare function deserializeContext(raw: string): MarketContext;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// ⚠️ GENERATED FILE — DO NOT EDIT.
|
|
2
|
+
// Canonical source of truth: shared/src/signals/serialize-context.ts
|
|
3
|
+
// Regenerate: node scripts/sync-shared-code.mjs (enforced by shared-code-sync.test.ts)
|
|
4
|
+
//
|
|
5
|
+
// This copy exists because this package builds with tsc and deploys as a
|
|
6
|
+
// self-contained tree that strips workspace deps, so it cannot import
|
|
7
|
+
// @reefclaw/shared runtime code across the deploy boundary.
|
|
8
|
+
export function serializeContext(ctx) {
|
|
9
|
+
return JSON.stringify(ctx);
|
|
10
|
+
}
|
|
11
|
+
function reviveBars(bars) {
|
|
12
|
+
if (!Array.isArray(bars))
|
|
13
|
+
return undefined;
|
|
14
|
+
return bars.map((b) => ({ ...b, time: new Date(b.time) }));
|
|
15
|
+
}
|
|
16
|
+
/** Parse a streamed context and rehydrate every Date field. Throws on bad JSON. */
|
|
17
|
+
export function deserializeContext(raw) {
|
|
18
|
+
const o = JSON.parse(raw);
|
|
19
|
+
o.timestamp = new Date(o.timestamp);
|
|
20
|
+
const oh1 = reviveBars(o.ohlcv1h);
|
|
21
|
+
if (oh1)
|
|
22
|
+
o.ohlcv1h = oh1;
|
|
23
|
+
const oh5 = reviveBars(o.ohlcv5m);
|
|
24
|
+
if (oh5)
|
|
25
|
+
o.ohlcv5m = oh5;
|
|
26
|
+
const oh4 = reviveBars(o.ohlcv4h);
|
|
27
|
+
if (oh4)
|
|
28
|
+
o.ohlcv4h = oh4;
|
|
29
|
+
const oh1d = reviveBars(o.ohlcv1d);
|
|
30
|
+
if (oh1d)
|
|
31
|
+
o.ohlcv1d = oh1d;
|
|
32
|
+
if (Array.isArray(o.tradeFlow)) {
|
|
33
|
+
o.tradeFlow = o.tradeFlow.map((t) => ({ ...t, bucket: new Date(t.bucket) }));
|
|
34
|
+
}
|
|
35
|
+
if (o.globalContext?.btcRsi14_1d_at) {
|
|
36
|
+
o.globalContext.btcRsi14_1d_at = new Date(o.globalContext.btcRsi14_1d_at);
|
|
37
|
+
}
|
|
38
|
+
return o;
|
|
39
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MarketContext, Direction } from './types.js';
|
|
2
|
+
import type { StopRuleConfig, ConditionContext } from './conditions/types.js';
|
|
3
|
+
export declare function computeStop(rule: StopRuleConfig, ctx: MarketContext, direction: Direction, condCtx: ConditionContext): number;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// ⚠️ GENERATED FILE — DO NOT EDIT.
|
|
2
|
+
// Canonical source of truth: shared/src/signals/stop-rules.ts
|
|
3
|
+
// Regenerate: node scripts/sync-shared-code.mjs (enforced by shared-code-sync.test.ts)
|
|
4
|
+
//
|
|
5
|
+
// This copy exists because this package builds with tsc and deploys as a
|
|
6
|
+
// self-contained tree that strips workspace deps, so it cannot import
|
|
7
|
+
// @reefclaw/shared runtime code across the deploy boundary.
|
|
8
|
+
// Stop level calculation for declarative strategies.
|
|
9
|
+
import { findSwingPoints } from '../shared/indicators.js';
|
|
10
|
+
export function computeStop(rule, ctx, direction, condCtx) {
|
|
11
|
+
switch (rule.type) {
|
|
12
|
+
case 'swing_atr': {
|
|
13
|
+
const swingCount = rule.params.swingCount ?? 3;
|
|
14
|
+
const atrFraction = (rule.params.atrFraction ?? 0.3) * ctx.atr14;
|
|
15
|
+
const fallbackAtrMult = rule.params.fallbackAtrMultiple ?? 2;
|
|
16
|
+
const swings = findSwingPoints(ctx.ohlcv1h.slice(-48), 3);
|
|
17
|
+
if (direction === 'LONG') {
|
|
18
|
+
return swings.lows.length > 0
|
|
19
|
+
? Math.min(...swings.lows.slice(-swingCount)) - atrFraction
|
|
20
|
+
: ctx.currentPrice - ctx.atr14 * fallbackAtrMult;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return swings.highs.length > 0
|
|
24
|
+
? Math.max(...swings.highs.slice(-swingCount)) + atrFraction
|
|
25
|
+
: ctx.currentPrice + ctx.atr14 * fallbackAtrMult;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
case 'recent_extreme_atr': {
|
|
29
|
+
const atrFraction = (rule.params.atrFraction ?? 0.5) * ctx.atr14;
|
|
30
|
+
if (direction === 'LONG') {
|
|
31
|
+
return (condCtx.recentLow ?? ctx.currentPrice - ctx.atr14) - atrFraction;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return (condCtx.recentHigh ?? ctx.currentPrice + ctx.atr14) + atrFraction;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
case 'fixed_atr': {
|
|
38
|
+
const atrMultiple = rule.params.atrMultiple ?? 1.5;
|
|
39
|
+
return direction === 'LONG'
|
|
40
|
+
? ctx.currentPrice - ctx.atr14 * atrMultiple
|
|
41
|
+
: ctx.currentPrice + ctx.atr14 * atrMultiple;
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
return direction === 'LONG'
|
|
45
|
+
? ctx.currentPrice - ctx.atr14 * 2
|
|
46
|
+
: ctx.currentPrice + ctx.atr14 * 2;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { StrategyDefinition, MarketContext, OhlcvBar } from './types.js';
|
|
2
|
+
import type { StrategyConfig, PrimaryTimeframe } from './conditions/types.js';
|
|
3
|
+
export declare function clearStrategyGatingState(): void;
|
|
4
|
+
/**
|
|
5
|
+
* Live parity for higher-timeframe strategies (the tfHours-aware-stops fix,
|
|
6
|
+
* 2026-07 — see docs/STRATEGY_RESEARCH_2026-07.md §6.4 / CLAUDE.md ★).
|
|
7
|
+
*
|
|
8
|
+
* Every implicit bar read in this engine — stop rules
|
|
9
|
+
* (`findSwingPoints(ctx.ohlcv1h.slice(-48))`), entry rules
|
|
10
|
+
* (`computeEMA(ctx.ohlcv1h…)`), conditions without a `tfHours` param
|
|
11
|
+
* (ema_proximity, stoch_rsi_extreme, adx_*, …) and `ctx.atr14` — targets the
|
|
12
|
+
* `ohlcv1h` slot. The backtest engine feeds MAIN-timeframe bars into that
|
|
13
|
+
* slot (and computes atr14 from them), so a 4h/1d strategy backtests against
|
|
14
|
+
* primary-timeframe geometry. LIVE contexts put real 1h bars there, so the
|
|
15
|
+
* same strategy would compute stops/EMAs/ATR from 1h data — a 1d ATR is ~8×
|
|
16
|
+
* the 1h ATR, so live stops came out ~8× too tight. This helper gives the
|
|
17
|
+
* evaluation the exact context shape the backtest validated: primary bars in
|
|
18
|
+
* the `ohlcv1h` slot, atr14 recomputed from them (same computeATR the
|
|
19
|
+
* backtest and live context builders use).
|
|
20
|
+
*
|
|
21
|
+
* Detection, not configuration: when the `ohlcv1h` slot already carries
|
|
22
|
+
* primary-cadence bars (median spacing ≥ 90% of the primary bar duration —
|
|
23
|
+
* i.e. a backtest context), the context is returned UNTOUCHED, so backtest
|
|
24
|
+
* behaviour is byte-identical by construction (including warm-up: the
|
|
25
|
+
* backtest engine already refuses to build a context below 50 main bars).
|
|
26
|
+
* A live 1h series can only look primary-spaced through a data gap, in
|
|
27
|
+
* which case we fall back to the untouched context (pre-fix behaviour)
|
|
28
|
+
* rather than guessing.
|
|
29
|
+
*
|
|
30
|
+
* Returns null for a LIVE context whose primary-timeframe history is below
|
|
31
|
+
* the backtest's 50-bar warm-up — the caller skips evaluation, mirroring
|
|
32
|
+
* the backtest's null-context warm-up window.
|
|
33
|
+
*
|
|
34
|
+
* Exported for tests.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolvePrimaryContext(ctx: MarketContext, tf: PrimaryTimeframe, tfBars: OhlcvBar[]): MarketContext | null;
|
|
37
|
+
/**
|
|
38
|
+
* Convert a declarative StrategyConfig into a StrategyDefinition
|
|
39
|
+
* that the signal engine and backtest engine can evaluate.
|
|
40
|
+
*
|
|
41
|
+
* `gateNamespace` scopes the module-global HTF tick-gate to the calling tenant
|
|
42
|
+
* (pass the strategy-cache key — `global` for the background pass, the user key
|
|
43
|
+
* for a per-user pass). Omit it for single-tenant callers (backtests, the
|
|
44
|
+
* plugin's local evaluator) — they keep the original un-namespaced gate key,
|
|
45
|
+
* so their behaviour is byte-identical.
|
|
46
|
+
*/
|
|
47
|
+
export declare function adaptStrategy(config: StrategyConfig, gateNamespace?: string): StrategyDefinition;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// ⚠️ GENERATED FILE — DO NOT EDIT.
|
|
2
|
+
// Canonical source of truth: shared/src/signals/strategy-adapter.ts
|
|
3
|
+
// Regenerate: node scripts/sync-shared-code.mjs (enforced by shared-code-sync.test.ts)
|
|
4
|
+
//
|
|
5
|
+
// This copy exists because this package builds with tsc and deploys as a
|
|
6
|
+
// self-contained tree that strips workspace deps, so it cannot import
|
|
7
|
+
// @reefclaw/shared runtime code across the deploy boundary.
|
|
8
|
+
import { evaluateConditions } from './conditions/registry.js';
|
|
9
|
+
import { resolveDirection } from './direction-rules.js';
|
|
10
|
+
import { computeEntry } from './entry-rules.js';
|
|
11
|
+
import { computeStop } from './stop-rules.js';
|
|
12
|
+
import { computeATR } from '../shared/indicators.js';
|
|
13
|
+
/**
|
|
14
|
+
* Higher-timeframe tick gating state, keyed by
|
|
15
|
+
* `${gateNamespace}\x1f${strategyName}:${symbol}`.
|
|
16
|
+
*
|
|
17
|
+
* Lives at module scope because the strategy cache (strategy-store.ts) builds
|
|
18
|
+
* a fresh adapter every 60s, so closure-based state would reset constantly
|
|
19
|
+
* and 1d-primary strategies would re-evaluate on every tick instead of once
|
|
20
|
+
* per closed bar. Module-level state survives the cache refresh.
|
|
21
|
+
*
|
|
22
|
+
* ★ Multi-tenant: because the map is module-global, the key MUST carry a
|
|
23
|
+
* per-tenant `gateNamespace` (the caller's strategy-cache key — `global` vs a
|
|
24
|
+
* per-user key). Without it, two tenants running same-named strategies on the
|
|
25
|
+
* same symbol shared ONE gate: whichever evaluated first marked the bar
|
|
26
|
+
* consumed and the other tenant's strategy was silently SKIPPED until the next
|
|
27
|
+
* primary-timeframe bar closed (a full day for a 1d strategy). A `\x1f` (unit
|
|
28
|
+
* separator, never present in a UUID / strategy name / symbol) joins the
|
|
29
|
+
* namespace so distinct tenants can never collide.
|
|
30
|
+
*
|
|
31
|
+
* Backtests should call `clearStrategyGatingState()` between runs to avoid
|
|
32
|
+
* leakage across tests / sequential backtests.
|
|
33
|
+
*/
|
|
34
|
+
const lastEvaluatedBarTime = new Map();
|
|
35
|
+
export function clearStrategyGatingState() {
|
|
36
|
+
lastEvaluatedBarTime.clear();
|
|
37
|
+
}
|
|
38
|
+
function pickTimeframeBars(ctx, tf) {
|
|
39
|
+
if (tf === '1d')
|
|
40
|
+
return ctx.ohlcv1d ?? [];
|
|
41
|
+
if (tf === '4h')
|
|
42
|
+
return ctx.ohlcv4h ?? [];
|
|
43
|
+
return ctx.ohlcv1h;
|
|
44
|
+
}
|
|
45
|
+
const TF_MS = {
|
|
46
|
+
'1h': 3_600_000,
|
|
47
|
+
'4h': 4 * 3_600_000,
|
|
48
|
+
'1d': 24 * 3_600_000,
|
|
49
|
+
};
|
|
50
|
+
/** Median spacing of the last few bars — robust bar-cadence probe. */
|
|
51
|
+
function barSpacingMs(bars) {
|
|
52
|
+
const n = bars.length;
|
|
53
|
+
if (n < 2)
|
|
54
|
+
return 0;
|
|
55
|
+
const deltas = [];
|
|
56
|
+
for (let i = Math.max(1, n - 4); i < n; i++) {
|
|
57
|
+
deltas.push(bars[i].time.getTime() - bars[i - 1].time.getTime());
|
|
58
|
+
}
|
|
59
|
+
deltas.sort((a, b) => a - b);
|
|
60
|
+
return deltas[Math.floor(deltas.length / 2)];
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Live parity for higher-timeframe strategies (the tfHours-aware-stops fix,
|
|
64
|
+
* 2026-07 — see docs/STRATEGY_RESEARCH_2026-07.md §6.4 / CLAUDE.md ★).
|
|
65
|
+
*
|
|
66
|
+
* Every implicit bar read in this engine — stop rules
|
|
67
|
+
* (`findSwingPoints(ctx.ohlcv1h.slice(-48))`), entry rules
|
|
68
|
+
* (`computeEMA(ctx.ohlcv1h…)`), conditions without a `tfHours` param
|
|
69
|
+
* (ema_proximity, stoch_rsi_extreme, adx_*, …) and `ctx.atr14` — targets the
|
|
70
|
+
* `ohlcv1h` slot. The backtest engine feeds MAIN-timeframe bars into that
|
|
71
|
+
* slot (and computes atr14 from them), so a 4h/1d strategy backtests against
|
|
72
|
+
* primary-timeframe geometry. LIVE contexts put real 1h bars there, so the
|
|
73
|
+
* same strategy would compute stops/EMAs/ATR from 1h data — a 1d ATR is ~8×
|
|
74
|
+
* the 1h ATR, so live stops came out ~8× too tight. This helper gives the
|
|
75
|
+
* evaluation the exact context shape the backtest validated: primary bars in
|
|
76
|
+
* the `ohlcv1h` slot, atr14 recomputed from them (same computeATR the
|
|
77
|
+
* backtest and live context builders use).
|
|
78
|
+
*
|
|
79
|
+
* Detection, not configuration: when the `ohlcv1h` slot already carries
|
|
80
|
+
* primary-cadence bars (median spacing ≥ 90% of the primary bar duration —
|
|
81
|
+
* i.e. a backtest context), the context is returned UNTOUCHED, so backtest
|
|
82
|
+
* behaviour is byte-identical by construction (including warm-up: the
|
|
83
|
+
* backtest engine already refuses to build a context below 50 main bars).
|
|
84
|
+
* A live 1h series can only look primary-spaced through a data gap, in
|
|
85
|
+
* which case we fall back to the untouched context (pre-fix behaviour)
|
|
86
|
+
* rather than guessing.
|
|
87
|
+
*
|
|
88
|
+
* Returns null for a LIVE context whose primary-timeframe history is below
|
|
89
|
+
* the backtest's 50-bar warm-up — the caller skips evaluation, mirroring
|
|
90
|
+
* the backtest's null-context warm-up window.
|
|
91
|
+
*
|
|
92
|
+
* Exported for tests.
|
|
93
|
+
*/
|
|
94
|
+
export function resolvePrimaryContext(ctx, tf, tfBars) {
|
|
95
|
+
if (tf === '1h')
|
|
96
|
+
return ctx;
|
|
97
|
+
const spacing = barSpacingMs(ctx.ohlcv1h);
|
|
98
|
+
if (spacing === 0 || spacing >= TF_MS[tf] * 0.9)
|
|
99
|
+
return ctx; // already primary (backtest) or undecidable
|
|
100
|
+
if (tfBars.length < 50)
|
|
101
|
+
return null; // live warm-up parity with the backtest engine
|
|
102
|
+
const highs = tfBars.map(b => b.high);
|
|
103
|
+
const lows = tfBars.map(b => b.low);
|
|
104
|
+
const closes = tfBars.map(b => b.close);
|
|
105
|
+
const atr14 = computeATR(highs, lows, closes, 14);
|
|
106
|
+
return {
|
|
107
|
+
...ctx,
|
|
108
|
+
ohlcv1h: tfBars,
|
|
109
|
+
atr14: Number.isFinite(atr14) && atr14 > 0 ? atr14 : ctx.atr14,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** Empty no-signal evaluation — used when gating skips a strategy. */
|
|
113
|
+
const SKIPPED = { direction: null, conditions: [], trade: undefined };
|
|
114
|
+
/**
|
|
115
|
+
* Convert a declarative StrategyConfig into a StrategyDefinition
|
|
116
|
+
* that the signal engine and backtest engine can evaluate.
|
|
117
|
+
*
|
|
118
|
+
* `gateNamespace` scopes the module-global HTF tick-gate to the calling tenant
|
|
119
|
+
* (pass the strategy-cache key — `global` for the background pass, the user key
|
|
120
|
+
* for a per-user pass). Omit it for single-tenant callers (backtests, the
|
|
121
|
+
* plugin's local evaluator) — they keep the original un-namespaced gate key,
|
|
122
|
+
* so their behaviour is byte-identical.
|
|
123
|
+
*/
|
|
124
|
+
export function adaptStrategy(config, gateNamespace) {
|
|
125
|
+
return {
|
|
126
|
+
name: config.name,
|
|
127
|
+
regimeWhitelist: config.regimeWhitelist,
|
|
128
|
+
minConfidence: config.minConfidence,
|
|
129
|
+
async evaluate(ctx) {
|
|
130
|
+
// ─── Tick gating ───────────────────────────────────────────────
|
|
131
|
+
// Only re-evaluate when a new bar of the strategy's primary
|
|
132
|
+
// timeframe has closed since the last evaluation for this
|
|
133
|
+
// strategy/symbol pair. Defaults to '1h' so existing strategies
|
|
134
|
+
// are unaffected.
|
|
135
|
+
const tf = config.primaryTimeframe ?? '1h';
|
|
136
|
+
const tfBars = pickTimeframeBars(ctx, tf);
|
|
137
|
+
if (tfBars.length === 0)
|
|
138
|
+
return SKIPPED;
|
|
139
|
+
const latestBarTime = tfBars[tfBars.length - 1].time.getTime();
|
|
140
|
+
// Namespaced per tenant (see lastEvaluatedBarTime doc) so same-named
|
|
141
|
+
// strategies across tenants never share a gate. Un-namespaced when
|
|
142
|
+
// gateNamespace is omitted — byte-identical to the original key.
|
|
143
|
+
const gateKey = gateNamespace
|
|
144
|
+
? `${gateNamespace}\x1f${config.name}:${ctx.symbol}`
|
|
145
|
+
: `${config.name}:${ctx.symbol}`;
|
|
146
|
+
const lastBarTime = lastEvaluatedBarTime.get(gateKey);
|
|
147
|
+
if (lastBarTime !== undefined && latestBarTime === lastBarTime) {
|
|
148
|
+
return SKIPPED;
|
|
149
|
+
}
|
|
150
|
+
lastEvaluatedBarTime.set(gateKey, latestBarTime);
|
|
151
|
+
// ─── Higher-timeframe live parity ──────────────────────────────
|
|
152
|
+
// Evaluate against a context whose implicit-1h slot carries
|
|
153
|
+
// primary-timeframe bars — see resolvePrimaryContext. Backtest
|
|
154
|
+
// contexts pass through untouched; only live contexts for 4h/1d
|
|
155
|
+
// strategies are adapted, and a live context below the backtest's
|
|
156
|
+
// 50-bar warm-up resolves to null → skip.
|
|
157
|
+
const ectx = resolvePrimaryContext(ctx, tf, tfBars);
|
|
158
|
+
if (ectx === null)
|
|
159
|
+
return SKIPPED;
|
|
160
|
+
// ─── SkipIf gates ──────────────────────────────────────────────
|
|
161
|
+
// Portfolio-wide / cross-symbol filters. If any are met the
|
|
162
|
+
// strategy is skipped this tick. Evaluated before main conditions
|
|
163
|
+
// so the bulk of the work is short-circuited.
|
|
164
|
+
if (config.skipIf && config.skipIf.length > 0) {
|
|
165
|
+
const { conditions: skipResults } = evaluateConditions(config.skipIf, ectx, null);
|
|
166
|
+
if (skipResults.some(c => c.met))
|
|
167
|
+
return SKIPPED;
|
|
168
|
+
}
|
|
169
|
+
// Pass 1: evaluate conditions with direction = null
|
|
170
|
+
const { conditions: pass1, condCtx } = evaluateConditions(config.conditions, ectx, null);
|
|
171
|
+
// Determine direction
|
|
172
|
+
const direction = resolveDirection(config.directionRule, ectx, condCtx);
|
|
173
|
+
// Pass 2: once the direction is known, re-evaluate the FULL condition
|
|
174
|
+
// array with it. Many registry conditions branch on `direction`
|
|
175
|
+
// (orderbook_imbalance, funding_contrarian, macd_crossover,
|
|
176
|
+
// bollinger_breakout, vwap_position, stoch_rsi_extreme, ichimoku_cloud,
|
|
177
|
+
// supertrend_direction, …) and their pass-1 result was computed against
|
|
178
|
+
// direction=null — typically the permissive either-side branch. A
|
|
179
|
+
// hand-curated allowlist here (the pre-fix 5-type set) silently drifted
|
|
180
|
+
// out of sync with the registry, so non-listed direction-dependent
|
|
181
|
+
// conditions kept their permissive pass-1 result forever (e.g. a
|
|
182
|
+
// fixed_long strategy's macd_crossover accepted a BEARISH crossover).
|
|
183
|
+
// Pass 2 always evaluated the whole array anyway — use it wholesale.
|
|
184
|
+
// Direction-insensitive conditions are pure functions of (ctx, params)
|
|
185
|
+
// and return identical results in both passes; entry/stop computation
|
|
186
|
+
// below deliberately keeps pass 1's condCtx (setter values don't depend
|
|
187
|
+
// on direction).
|
|
188
|
+
let finalConditions = pass1;
|
|
189
|
+
if (direction) {
|
|
190
|
+
const { conditions: pass2 } = evaluateConditions(config.conditions, ectx, direction);
|
|
191
|
+
finalConditions = pass2;
|
|
192
|
+
}
|
|
193
|
+
const allMet = finalConditions.every(c => c.met);
|
|
194
|
+
let trade;
|
|
195
|
+
if (allMet && direction) {
|
|
196
|
+
const entryZone = computeEntry(config.entryRule, ectx, direction, condCtx);
|
|
197
|
+
const stopLevel = computeStop(config.stopRule, ectx, direction, condCtx);
|
|
198
|
+
const risk = direction === 'LONG'
|
|
199
|
+
? ectx.currentPrice - stopLevel
|
|
200
|
+
: stopLevel - ectx.currentPrice;
|
|
201
|
+
const targets = config.targetRMultiples.map(rm => direction === 'LONG'
|
|
202
|
+
? ectx.currentPrice + risk * rm
|
|
203
|
+
: ectx.currentPrice - risk * rm);
|
|
204
|
+
trade = { entryZone, stopLevel, targets };
|
|
205
|
+
}
|
|
206
|
+
return { direction, conditions: finalConditions, trade };
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { Direction, OhlcvBar, TradeFlowBucket, GlobalMarketContext, MarketContext, SignalCondition, StrategyEvaluation, StrategyDefinition, SignalEvent, StrategyState, SignalSnapshot, } from '@reefclaw/shared';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Re-export shim for the plugin-side strategy evaluator (facts-out).
|
|
2
|
+
//
|
|
3
|
+
// The generated eval-core copies (registry, strategy-adapter, direction/entry/
|
|
4
|
+
// stop-rules) import their types from `./types.js`. The canonical definitions
|
|
5
|
+
// live in @reefclaw/shared (type-only → erased at runtime), so this shim makes
|
|
6
|
+
// those relative imports resolve inside the plugin tree without pulling any
|
|
7
|
+
// runtime dependency into the emitted JS. See docs/FACTS_OUT_ARCHITECTURE.md.
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { SimulatorState, OrderBookDepth, SimulationConfig, ExecutionStats, PositionMetadata, CloseReason } from './types.js';
|
|
3
|
+
import type { CcxtOrder, CcxtBalance, CcxtPosition, CcxtTicker } from '../types.js';
|
|
4
|
+
export declare class ExchangeSimulator extends EventEmitter {
|
|
5
|
+
private state;
|
|
6
|
+
private lastTicker;
|
|
7
|
+
private lastOrderBook;
|
|
8
|
+
private simulationConfig;
|
|
9
|
+
/** Metadata for pending limit orders, keyed by order ID. Cleaned up on fill/cancel. */
|
|
10
|
+
private pendingOrderMetadata;
|
|
11
|
+
private cachedVolFactor;
|
|
12
|
+
private baselineAtr;
|
|
13
|
+
private atrSampleCount;
|
|
14
|
+
private readonly startupTime;
|
|
15
|
+
private readonly hadPositionsAtStartup;
|
|
16
|
+
private static readonly STARTUP_LOCKOUT_MS;
|
|
17
|
+
constructor(initialState: SimulatorState, config?: SimulationConfig);
|
|
18
|
+
getSimulationConfig(): SimulationConfig;
|
|
19
|
+
setVolFactor(factor: number): void;
|
|
20
|
+
getVolFactor(): number;
|
|
21
|
+
/** Update baseline ATR using exponential moving average of samples. */
|
|
22
|
+
updateBaselineAtr(atr14: number): void;
|
|
23
|
+
getBaselineAtr(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Returns today's session-start NAV, lazily seeding it from current equity
|
|
26
|
+
* if unset or stale (different UTC day). This is the plugin-side anchor used
|
|
27
|
+
* by the pre-trade risk gate; a stale/missing anchor silently disables the
|
|
28
|
+
* drawdown zones, so callers must never see a zero.
|
|
29
|
+
*/
|
|
30
|
+
getSessionStartNav(): number;
|
|
31
|
+
setSessionStartNav(nav: number): void;
|
|
32
|
+
/** Seed sessionStartNav from current equity on the first check of each UTC day.
|
|
33
|
+
* Safe to call repeatedly — no-op once the anchor matches today's date. */
|
|
34
|
+
private ensureSessionAnchor;
|
|
35
|
+
/** Mark-to-market equity = walletTotal + for each open position, the
|
|
36
|
+
* collateral locked at entry + current unrealized P&L. Paper simulator is
|
|
37
|
+
* SPOT-collateral style: the full entry notional was deducted from wallet
|
|
38
|
+
* on open and is released on close, so we must add it back here. */
|
|
39
|
+
computeEquity(): number;
|
|
40
|
+
private getQuoteCurrency;
|
|
41
|
+
getBalance(): CcxtBalance;
|
|
42
|
+
getPositions(symbol?: string): CcxtPosition[];
|
|
43
|
+
getOpenOrders(symbol?: string): CcxtOrder[];
|
|
44
|
+
/** Get cumulative execution quality stats. */
|
|
45
|
+
getExecutionStats(): ExecutionStats | undefined;
|
|
46
|
+
/** Cache the latest order book snapshot for a symbol. */
|
|
47
|
+
updateOrderBook(symbol: string, orderbook: OrderBookDepth): void;
|
|
48
|
+
getLastOrderBook(symbol: string): OrderBookDepth | undefined;
|
|
49
|
+
createOrder(symbol: string, side: 'buy' | 'sell', type: 'market' | 'limit', amount: number, price?: number, metadata?: PositionMetadata): CcxtOrder;
|
|
50
|
+
cancelOrder(orderId: string): CcxtOrder;
|
|
51
|
+
cancelAllOrders(symbol?: string): CcxtOrder[];
|
|
52
|
+
closePosition(symbol: string, closeReason?: CloseReason): CcxtOrder;
|
|
53
|
+
/** Paper-only: move an open position's MUTABLE protective levels (stopPrice /
|
|
54
|
+
* targetPrice) in place and persist, WITHOUT the close+reopen round-trip
|
|
55
|
+
* (which pays an extra taker fee and resets the R/MFE denominators). The
|
|
56
|
+
* frozen originalStopPrice / originalEntryPrice are intentionally left
|
|
57
|
+
* untouched so R-multiples stay anchored at entry. The paper stop-watcher
|
|
58
|
+
* and getPositions both read metadata.stopPrice, so a moved stop takes
|
|
59
|
+
* effect on the next watcher tick. Throws if there is no open position. (M9) */
|
|
60
|
+
updatePositionMetadata(symbol: string, patch: {
|
|
61
|
+
stopPrice?: number;
|
|
62
|
+
targetPrice?: number;
|
|
63
|
+
}): void;
|
|
64
|
+
updateTicker(ticker: CcxtTicker): void;
|
|
65
|
+
getLastTicker(symbol: string): CcxtTicker | undefined;
|
|
66
|
+
/** Walk every position for `symbol` and refresh MFE / give-back from the
|
|
67
|
+
* latest mark. Idempotent — pure update of `metadata.mfePeakPrice` (only
|
|
68
|
+
* ratchets favourably) plus derived `mfeR` and `giveBackRatio`. Safe to
|
|
69
|
+
* call before any positions exist (no-op). */
|
|
70
|
+
private refreshMfeForSymbol;
|
|
71
|
+
/** Replace internal state with a fresh copy from disk.
|
|
72
|
+
* Used by the gateway process to pick up state saved by the agent process.
|
|
73
|
+
*
|
|
74
|
+
* Non-destructive for the MFE ratchet (M3): the disk copy can lag the live
|
|
75
|
+
* peak (refreshMfeForSymbol ratchets every tick; persistence coalesces), so
|
|
76
|
+
* a wholesale swap would discard it. For each position present in BOTH
|
|
77
|
+
* snapshots (same symbol+side+openedAt) we carry over the MORE-favourable
|
|
78
|
+
* monotone peak and recompute mfeR/giveBackRatio from the current mark, so a
|
|
79
|
+
* reload never regresses the agent's give-back signal. */
|
|
80
|
+
replaceState(newState: SimulatorState): void;
|
|
81
|
+
getState(): SimulatorState;
|
|
82
|
+
/** Default max quote age a NEW-exposure fill may price against (issue #202).
|
|
83
|
+
* Generous vs the 5s paper feed cadence; env RC_PAPER_MAX_QUOTE_AGE_MS
|
|
84
|
+
* overrides. */
|
|
85
|
+
static readonly DEFAULT_MAX_QUOTE_AGE_MS = 45000;
|
|
86
|
+
private maxQuoteAgeMs;
|
|
87
|
+
/** Quote age from the ticker's own timestamp. A missing/invalid timestamp
|
|
88
|
+
* reads as age 0 (fail-open — the guard cannot fire on it). */
|
|
89
|
+
private quoteAgeMs;
|
|
90
|
+
/** Reject fills that would OPEN or GROW exposure on a stale quote. Risk-
|
|
91
|
+
* reducing fills (closes/partials against an existing position) are always
|
|
92
|
+
* allowed — blocking a close on a broken feed compounds the risk. */
|
|
93
|
+
private assertQuoteFresh;
|
|
94
|
+
private shouldFillLimit;
|
|
95
|
+
private executeMarketFill;
|
|
96
|
+
private executeLimitFill;
|
|
97
|
+
/** Apply a fill result: update positions, record trade, track stats, emit state change. */
|
|
98
|
+
private applyFillResult;
|
|
99
|
+
private updatePosition;
|
|
100
|
+
private addTrade;
|
|
101
|
+
/** Update cumulative execution stats from a fill's execution quality. */
|
|
102
|
+
private updateExecutionStats;
|
|
103
|
+
private emitStateChanged;
|
|
104
|
+
private toCcxtOrder;
|
|
105
|
+
}
|