@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.
- package/assets/bridge/bridge.d.ts +96 -0
- package/assets/bridge/bridge.js +969 -0
- package/assets/bridge/config.d.ts +43 -0
- package/assets/bridge/config.js +176 -0
- package/assets/bridge/connector.d.ts +52 -0
- package/assets/bridge/connector.js +293 -0
- package/assets/bridge/event-replay-buffer.d.ts +43 -0
- package/assets/bridge/event-replay-buffer.js +109 -0
- package/assets/bridge/gateway/event-parser.d.ts +209 -0
- package/assets/bridge/gateway/event-parser.js +793 -0
- package/assets/bridge/gateway/gateway-config.d.ts +39 -0
- package/assets/bridge/gateway/gateway-config.js +86 -0
- package/assets/bridge/gateway/gateway-http-client.d.ts +50 -0
- package/assets/bridge/gateway/gateway-http-client.js +165 -0
- package/assets/bridge/gateway/gateway-ws-client.d.ts +116 -0
- package/assets/bridge/gateway/gateway-ws-client.js +417 -0
- package/assets/bridge/gateway/poller.d.ts +146 -0
- package/assets/bridge/gateway/poller.js +505 -0
- package/assets/bridge/gateway/tool-discovery.d.ts +25 -0
- package/assets/bridge/gateway/tool-discovery.js +198 -0
- package/assets/bridge/index.d.ts +2 -0
- package/assets/bridge/index.js +253 -0
- package/assets/bridge/logger.d.ts +2 -0
- package/assets/bridge/logger.js +2 -0
- package/assets/bridge/provider.d.ts +156 -0
- package/assets/bridge/provider.js +2 -0
- package/assets/bridge/providers/emergency-commands.d.ts +54 -0
- package/assets/bridge/providers/emergency-commands.js +235 -0
- package/assets/bridge/providers/gateway.d.ts +322 -0
- package/assets/bridge/providers/gateway.js +2302 -0
- package/assets/bridge/providers/mock.d.ts +37 -0
- package/assets/bridge/providers/mock.js +385 -0
- package/assets/bridge/providers/onboarding-commands.d.ts +83 -0
- package/assets/bridge/providers/onboarding-commands.js +213 -0
- package/assets/bridge/providers/risk-calculator.d.ts +96 -0
- package/assets/bridge/providers/risk-calculator.js +369 -0
- package/assets/bridge/setup.d.ts +32 -0
- package/assets/bridge/setup.js +226 -0
- package/assets/bridge/types.d.ts +584 -0
- package/assets/bridge/types.js +50 -0
- package/assets/bridge/utils/reconnect.d.ts +6 -0
- package/assets/bridge/utils/reconnect.js +6 -0
- package/assets/bridge/utils/skill-signing.d.ts +51 -0
- package/assets/bridge/utils/skill-signing.js +138 -0
- package/assets/bridge/utils/skill-version.d.ts +17 -0
- package/assets/bridge/utils/skill-version.js +71 -0
- 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 +409 -0
- package/assets/plugin/ccxt/binance-private.d.ts +325 -0
- package/assets/plugin/ccxt/binance-private.js +1415 -0
- package/assets/plugin/ccxt/binance-public.d.ts +18 -0
- package/assets/plugin/ccxt/binance-public.js +147 -0
- package/assets/plugin/config/agent-config-client.d.ts +55 -0
- package/assets/plugin/config/agent-config-client.js +145 -0
- package/assets/plugin/config/agent-config-poller.d.ts +25 -0
- package/assets/plugin/config/agent-config-poller.js +100 -0
- package/assets/plugin/config/brackets-config.d.ts +22 -0
- package/assets/plugin/config/brackets-config.js +58 -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 +175 -0
- package/assets/plugin/config/plugin-config-io.js +84 -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 +125 -0
- package/assets/plugin/config/user-data-stream-config.d.ts +85 -0
- package/assets/plugin/config/user-data-stream-config.js +224 -0
- package/assets/plugin/exchange-adapter.d.ts +49 -0
- package/assets/plugin/exchange-adapter.js +4 -0
- package/assets/plugin/index.d.ts +30 -0
- package/assets/plugin/index.js +1989 -0
- package/assets/plugin/ingest/pending-entry-metadata.d.ts +52 -0
- package/assets/plugin/ingest/pending-entry-metadata.js +182 -0
- package/assets/plugin/ingest/position-auto-capture.d.ts +98 -0
- package/assets/plugin/ingest/position-auto-capture.js +394 -0
- package/assets/plugin/ingest/position-decisions-client.d.ts +318 -0
- package/assets/plugin/ingest/position-decisions-client.js +296 -0
- package/assets/plugin/ingest/reconcile-db-vs-exchange.d.ts +13 -0
- package/assets/plugin/ingest/reconcile-db-vs-exchange.js +114 -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/live/bracket-id.d.ts +18 -0
- package/assets/plugin/live/bracket-id.js +81 -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 +35 -0
- package/assets/plugin/live/exchange-info-cache.js +119 -0
- package/assets/plugin/live/fact-subscriber.d.ts +78 -0
- package/assets/plugin/live/fact-subscriber.js +182 -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 +264 -0
- package/assets/plugin/live/live-adapter.js +1665 -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 +146 -0
- package/assets/plugin/live/local-strategy-evaluator.d.ts +62 -0
- package/assets/plugin/live/local-strategy-evaluator.js +127 -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 +83 -0
- package/assets/plugin/live/position-state-store.js +237 -0
- package/assets/plugin/live/proposal-decision-listener.d.ts +64 -0
- package/assets/plugin/live/proposal-decision-listener.js +288 -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 +34 -0
- package/assets/plugin/live/stop-watcher.js +158 -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 +71 -0
- package/assets/plugin/onboarding/runtime.js +153 -0
- package/assets/plugin/openclaw.plugin.json +91 -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 +42 -0
- package/assets/plugin/persistence/state-manager.js +164 -0
- package/assets/plugin/pinned-plan.d.ts +9 -0
- package/assets/plugin/pinned-plan.js +23 -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 +1274 -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 +14 -0
- package/assets/plugin/signals/strategy-adapter.js +122 -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 +93 -0
- package/assets/plugin/simulator/exchange-simulator.js +684 -0
- package/assets/plugin/simulator/fill-engine.d.ts +53 -0
- package/assets/plugin/simulator/fill-engine.js +276 -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 +219 -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 +109 -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 +67 -0
- package/assets/plugin/strategy/evaluator.js +93 -0
- package/assets/plugin/tools/assessment-validation.d.ts +118 -0
- package/assets/plugin/tools/assessment-validation.js +415 -0
- package/assets/plugin/tools/attach-brackets.d.ts +34 -0
- package/assets/plugin/tools/attach-brackets.js +363 -0
- package/assets/plugin/tools/audit-bracket-protection.d.ts +49 -0
- package/assets/plugin/tools/audit-bracket-protection.js +527 -0
- package/assets/plugin/tools/cancel-all-orders.d.ts +7 -0
- package/assets/plugin/tools/cancel-all-orders.js +5 -0
- package/assets/plugin/tools/cancel-order.d.ts +10 -0
- package/assets/plugin/tools/cancel-order.js +14 -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 +22 -0
- package/assets/plugin/tools/close-position.js +449 -0
- package/assets/plugin/tools/create-order.d.ts +54 -0
- package/assets/plugin/tools/create-order.js +338 -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 +45 -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 +303 -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/helpers.d.ts +25 -0
- package/assets/plugin/tools/helpers.js +38 -0
- package/assets/plugin/tools/intel-api.d.ts +14 -0
- package/assets/plugin/tools/intel-api.js +52 -0
- package/assets/plugin/tools/intel-cache.d.ts +25 -0
- package/assets/plugin/tools/intel-cache.js +133 -0
- package/assets/plugin/tools/list-strategies.d.ts +7 -0
- package/assets/plugin/tools/list-strategies.js +6 -0
- package/assets/plugin/tools/modify-stop.d.ts +17 -0
- package/assets/plugin/tools/modify-stop.js +81 -0
- package/assets/plugin/tools/modify-target.d.ts +17 -0
- package/assets/plugin/tools/modify-target.js +71 -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 +18 -0
- package/assets/plugin/tools/scan-pairs.js +220 -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 +135 -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 +8 -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 +110 -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/shared/fills.d.ts +36 -0
- package/assets/shared/fills.js +20 -0
- package/assets/shared/index.d.ts +10 -0
- package/assets/shared/index.js +5 -0
- package/assets/shared/logger.d.ts +10 -0
- package/assets/shared/logger.js +34 -0
- package/assets/shared/protocol.d.ts +29 -0
- package/assets/shared/protocol.js +14 -0
- package/assets/shared/redact.d.ts +6 -0
- package/assets/shared/redact.js +31 -0
- package/assets/shared/shared/indicators-extended.d.ts +52 -0
- package/assets/shared/shared/indicators-extended.js +284 -0
- package/assets/shared/shared/indicators.d.ts +15 -0
- package/assets/shared/shared/indicators.js +107 -0
- package/assets/shared/signals/conditions/registry.d.ts +16 -0
- package/assets/shared/signals/conditions/registry.js +1267 -0
- package/assets/shared/signals/conditions/types.d.ts +65 -0
- package/assets/shared/signals/conditions/types.js +8 -0
- package/assets/shared/signals/direction-rules.d.ts +3 -0
- package/assets/shared/signals/direction-rules.js +18 -0
- package/assets/shared/signals/entry-rules.d.ts +6 -0
- package/assets/shared/signals/entry-rules.js +26 -0
- package/assets/shared/signals/indicators-extended.d.ts +52 -0
- package/assets/shared/signals/indicators-extended.js +284 -0
- package/assets/shared/signals/indicators.d.ts +15 -0
- package/assets/shared/signals/indicators.js +107 -0
- package/assets/shared/signals/serialize-context.d.ts +4 -0
- package/assets/shared/signals/serialize-context.js +41 -0
- package/assets/shared/signals/stop-rules.d.ts +3 -0
- package/assets/shared/signals/stop-rules.js +41 -0
- package/assets/shared/signals/strategy-adapter.d.ts +14 -0
- package/assets/shared/signals/strategy-adapter.js +117 -0
- package/assets/shared/signals/types.d.ts +187 -0
- package/assets/shared/signals/types.js +9 -0
- package/assets/shared/trading-mode.d.ts +16 -0
- package/assets/shared/trading-mode.js +49 -0
- package/assets/skill/SKILL.md +1357 -0
- package/dist/bridge.js +25 -0
- package/dist/bundle.js +33 -0
- package/dist/cli.js +120 -0
- package/dist/daemon.js +104 -0
- package/dist/deps.js +41 -0
- package/dist/exec.js +28 -0
- package/dist/openclaw.js +153 -0
- package/dist/paths.js +23 -0
- package/dist/plugin.js +48 -0
- package/dist/skill.js +35 -0
- package/dist/ui.js +29 -0
- package/dist/validate.js +28 -0
- package/package.json +32 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { MarketContext, Direction } from '../types.js';
|
|
2
|
+
/** Result from evaluating a single condition */
|
|
3
|
+
export interface ConditionResult {
|
|
4
|
+
met: boolean;
|
|
5
|
+
value: number;
|
|
6
|
+
threshold: number;
|
|
7
|
+
description: string;
|
|
8
|
+
}
|
|
9
|
+
/** Shared context passed between conditions in a single evaluation.
|
|
10
|
+
* Some conditions produce data needed by entry/stop rules (e.g., sweep level). */
|
|
11
|
+
export interface ConditionContext {
|
|
12
|
+
sweepLevel?: number;
|
|
13
|
+
recentLow?: number;
|
|
14
|
+
recentHigh?: number;
|
|
15
|
+
sweptDirection?: Direction | null;
|
|
16
|
+
ema21?: number;
|
|
17
|
+
}
|
|
18
|
+
/** A condition function: takes market context + params, returns result */
|
|
19
|
+
export type ConditionFn = (ctx: MarketContext, params: Record<string, number>, direction: Direction | null, condCtx: ConditionContext) => ConditionResult;
|
|
20
|
+
/** Config for a single condition in a strategy */
|
|
21
|
+
export interface ConditionConfig {
|
|
22
|
+
type: string;
|
|
23
|
+
params: Record<string, number>;
|
|
24
|
+
}
|
|
25
|
+
/** Entry zone calculation rule */
|
|
26
|
+
export interface EntryRuleConfig {
|
|
27
|
+
type: 'ema_offset' | 'sweep_range' | 'atr_offset';
|
|
28
|
+
params: Record<string, number>;
|
|
29
|
+
}
|
|
30
|
+
/** Stop level calculation rule */
|
|
31
|
+
export interface StopRuleConfig {
|
|
32
|
+
type: 'swing_atr' | 'recent_extreme_atr' | 'fixed_atr';
|
|
33
|
+
params: Record<string, number>;
|
|
34
|
+
}
|
|
35
|
+
/** Direction determination rule */
|
|
36
|
+
export type DirectionRule = 'from_regime' | 'from_sweep' | 'from_funding' | 'fixed_long' | 'fixed_short';
|
|
37
|
+
/** Primary timeframe a strategy operates on. Default '1h' (the only
|
|
38
|
+
* timeframe the live engine fetched before Phase B). When set to '4h' or
|
|
39
|
+
* '1d', the strategy adapter will only re-evaluate the strategy when a new
|
|
40
|
+
* bar at that timeframe has closed since the last evaluation, and
|
|
41
|
+
* conditions inside the strategy are expected to read from
|
|
42
|
+
* ctx.ohlcv4h/ohlcv1d rather than ctx.ohlcv1h. */
|
|
43
|
+
export type PrimaryTimeframe = '1h' | '4h' | '1d';
|
|
44
|
+
/** Full declarative strategy configuration (stored as JSON in DB) */
|
|
45
|
+
export interface StrategyConfig {
|
|
46
|
+
name: string;
|
|
47
|
+
description: string;
|
|
48
|
+
version: number;
|
|
49
|
+
regimeWhitelist: string[];
|
|
50
|
+
minConfidence: number;
|
|
51
|
+
directionRule: DirectionRule;
|
|
52
|
+
conditions: ConditionConfig[];
|
|
53
|
+
entryRule: EntryRuleConfig;
|
|
54
|
+
stopRule: StopRuleConfig;
|
|
55
|
+
targetRMultiples: number[];
|
|
56
|
+
expiryMs?: number;
|
|
57
|
+
cooldownMs?: number;
|
|
58
|
+
/** Higher-timeframe gating. When set, the strategy is only re-evaluated
|
|
59
|
+
* on closed bars of that timeframe. Defaults to '1h'. */
|
|
60
|
+
primaryTimeframe?: PrimaryTimeframe;
|
|
61
|
+
/** Conditions that, if ANY are met, cause the strategy to be skipped this
|
|
62
|
+
* tick. Evaluated before the main `conditions` list. Used for global
|
|
63
|
+
* filters like "skip if BTC daily RSI > 70". */
|
|
64
|
+
skipIf?: ConditionConfig[];
|
|
65
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Condition-library + strategy-config types — canonical source of truth shared
|
|
2
|
+
// by the intel signal engine and the plugin-side evaluator (facts-out). The
|
|
3
|
+
// DB/backtest-only types (StrategyBacktestResult, BacktestResultMap, StrategyRow)
|
|
4
|
+
// stay intel-side in intelligence/src/signals/conditions/types.ts, which
|
|
5
|
+
// re-exports everything here.
|
|
6
|
+
//
|
|
7
|
+
// PURE TYPES ONLY — erase at runtime.
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Direction determination rules for declarative strategies.
|
|
2
|
+
export function resolveDirection(rule, ctx, condCtx) {
|
|
3
|
+
switch (rule) {
|
|
4
|
+
case 'from_regime':
|
|
5
|
+
return ctx.regime === 'TREND_UP' ? 'LONG' : ctx.regime === 'TREND_DOWN' ? 'SHORT' : null;
|
|
6
|
+
case 'from_sweep':
|
|
7
|
+
return condCtx.sweptDirection ?? null;
|
|
8
|
+
case 'from_funding':
|
|
9
|
+
// funding_extreme condition sets sweptDirection to the contra direction
|
|
10
|
+
return condCtx.sweptDirection ?? null;
|
|
11
|
+
case 'fixed_long':
|
|
12
|
+
return 'LONG';
|
|
13
|
+
case 'fixed_short':
|
|
14
|
+
return 'SHORT';
|
|
15
|
+
default:
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -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,26 @@
|
|
|
1
|
+
// Entry zone calculation for declarative strategies.
|
|
2
|
+
import { computeEMA } from '../shared/indicators.js';
|
|
3
|
+
export function computeEntry(rule, ctx, direction, condCtx) {
|
|
4
|
+
switch (rule.type) {
|
|
5
|
+
case 'ema_offset': {
|
|
6
|
+
const period = rule.params.period ?? 21;
|
|
7
|
+
const atrFraction = (rule.params.atrFraction ?? 0.3) * ctx.atr14;
|
|
8
|
+
const ema = condCtx.ema21 && period === 21
|
|
9
|
+
? condCtx.ema21
|
|
10
|
+
: computeEMA(ctx.ohlcv1h.map(b => b.close), period);
|
|
11
|
+
return { low: ema - atrFraction, high: ema + atrFraction };
|
|
12
|
+
}
|
|
13
|
+
case 'sweep_range': {
|
|
14
|
+
const sweepLevel = condCtx.sweepLevel ?? ctx.currentPrice;
|
|
15
|
+
return direction === 'LONG'
|
|
16
|
+
? { low: sweepLevel, high: ctx.currentPrice }
|
|
17
|
+
: { low: ctx.currentPrice, high: sweepLevel };
|
|
18
|
+
}
|
|
19
|
+
case 'atr_offset': {
|
|
20
|
+
const atrFraction = (rule.params.atrFraction ?? 0.2) * ctx.atr14;
|
|
21
|
+
return { low: ctx.currentPrice - atrFraction, high: ctx.currentPrice + atrFraction };
|
|
22
|
+
}
|
|
23
|
+
default:
|
|
24
|
+
return { low: ctx.currentPrice - ctx.atr14 * 0.3, high: ctx.currentPrice + ctx.atr14 * 0.3 };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -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,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,41 @@
|
|
|
1
|
+
// Matched (de)serializer for streaming a MarketContext over the fact stream
|
|
2
|
+
// (facts-out step 4). Canonical runtime code shared by the intel broadcaster
|
|
3
|
+
// and the plugin subscriber so the wire round-trip is byte-identical.
|
|
4
|
+
//
|
|
5
|
+
// The Date rehydration is the same hazard guarded in the Redis context-cache:
|
|
6
|
+
// JSON.parse returns Date fields (timestamp, every ohlcv*[].time,
|
|
7
|
+
// tradeFlow[].bucket, globalContext.btcRsi14_1d_at) as STRINGS — handing the
|
|
8
|
+
// strategy evaluator string-dates would corrupt indicators. deserializeContext
|
|
9
|
+
// restores them. serialize is plain JSON (Dates → ISO via Date#toJSON).
|
|
10
|
+
export function serializeContext(ctx) {
|
|
11
|
+
return JSON.stringify(ctx);
|
|
12
|
+
}
|
|
13
|
+
function reviveBars(bars) {
|
|
14
|
+
if (!Array.isArray(bars))
|
|
15
|
+
return undefined;
|
|
16
|
+
return bars.map((b) => ({ ...b, time: new Date(b.time) }));
|
|
17
|
+
}
|
|
18
|
+
/** Parse a streamed context and rehydrate every Date field. Throws on bad JSON. */
|
|
19
|
+
export function deserializeContext(raw) {
|
|
20
|
+
const o = JSON.parse(raw);
|
|
21
|
+
o.timestamp = new Date(o.timestamp);
|
|
22
|
+
const oh1 = reviveBars(o.ohlcv1h);
|
|
23
|
+
if (oh1)
|
|
24
|
+
o.ohlcv1h = oh1;
|
|
25
|
+
const oh5 = reviveBars(o.ohlcv5m);
|
|
26
|
+
if (oh5)
|
|
27
|
+
o.ohlcv5m = oh5;
|
|
28
|
+
const oh4 = reviveBars(o.ohlcv4h);
|
|
29
|
+
if (oh4)
|
|
30
|
+
o.ohlcv4h = oh4;
|
|
31
|
+
const oh1d = reviveBars(o.ohlcv1d);
|
|
32
|
+
if (oh1d)
|
|
33
|
+
o.ohlcv1d = oh1d;
|
|
34
|
+
if (Array.isArray(o.tradeFlow)) {
|
|
35
|
+
o.tradeFlow = o.tradeFlow.map((t) => ({ ...t, bucket: new Date(t.bucket) }));
|
|
36
|
+
}
|
|
37
|
+
if (o.globalContext?.btcRsi14_1d_at) {
|
|
38
|
+
o.globalContext.btcRsi14_1d_at = new Date(o.globalContext.btcRsi14_1d_at);
|
|
39
|
+
}
|
|
40
|
+
return o;
|
|
41
|
+
}
|
|
@@ -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;
|