@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,36 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import type { BinancePrivateApi } from '../ccxt/binance-private.js';
|
|
3
|
+
import type { ExchangeSimulator } from '../simulator/exchange-simulator.js';
|
|
4
|
+
import type { ShadowComparison, ShadowMetrics, ShadowConfig } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* ShadowTracker hooks into the ExchangeSimulator to compute
|
|
7
|
+
* shadow estimates for every paper fill.
|
|
8
|
+
*
|
|
9
|
+
* Events emitted:
|
|
10
|
+
* - 'shadowComparison': ShadowComparison — after each fill comparison
|
|
11
|
+
*/
|
|
12
|
+
export declare class ShadowTracker extends EventEmitter {
|
|
13
|
+
private privateApi;
|
|
14
|
+
private simulator;
|
|
15
|
+
private metrics;
|
|
16
|
+
private config;
|
|
17
|
+
private recentComparisons;
|
|
18
|
+
private active;
|
|
19
|
+
constructor(privateApi: BinancePrivateApi, simulator: ExchangeSimulator, config?: ShadowConfig, existingMetrics?: ShadowMetrics);
|
|
20
|
+
/** Start listening for simulator fill events. */
|
|
21
|
+
start(): void;
|
|
22
|
+
/** Stop listening. */
|
|
23
|
+
stop(): void;
|
|
24
|
+
/** Get current shadow metrics. */
|
|
25
|
+
getMetrics(): ShadowMetrics;
|
|
26
|
+
/** Get recent comparisons. */
|
|
27
|
+
getRecentComparisons(): ShadowComparison[];
|
|
28
|
+
/** Check if shadow mode criteria are met for mode upgrade. */
|
|
29
|
+
isReadyForUpgrade(): {
|
|
30
|
+
ready: boolean;
|
|
31
|
+
reasons: string[];
|
|
32
|
+
};
|
|
33
|
+
private onFill;
|
|
34
|
+
private computeShadowComparison;
|
|
35
|
+
private updateMetrics;
|
|
36
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Shadow Tracker — compares paper fills against live exchange estimates.
|
|
2
|
+
// Listens for fill events from the simulator, fetches real order book,
|
|
3
|
+
// computes what the live fill would have been, logs the comparison.
|
|
4
|
+
import { EventEmitter } from 'node:events';
|
|
5
|
+
import { logger } from '../logger.js';
|
|
6
|
+
import { priceToBps } from '../simulator/types.js';
|
|
7
|
+
import { computeBookAwareFillPrice } from '../simulator/realistic-fills.js';
|
|
8
|
+
import { createEmptyShadowMetrics, DEFAULT_SHADOW_CONFIG } from './types.js';
|
|
9
|
+
const TAG = 'shadow-tracker';
|
|
10
|
+
/** Maximum recent comparisons to keep in memory. */
|
|
11
|
+
const MAX_RECENT_COMPARISONS = 100;
|
|
12
|
+
/**
|
|
13
|
+
* ShadowTracker hooks into the ExchangeSimulator to compute
|
|
14
|
+
* shadow estimates for every paper fill.
|
|
15
|
+
*
|
|
16
|
+
* Events emitted:
|
|
17
|
+
* - 'shadowComparison': ShadowComparison — after each fill comparison
|
|
18
|
+
*/
|
|
19
|
+
export class ShadowTracker extends EventEmitter {
|
|
20
|
+
privateApi;
|
|
21
|
+
simulator;
|
|
22
|
+
metrics;
|
|
23
|
+
config;
|
|
24
|
+
recentComparisons = [];
|
|
25
|
+
active = false;
|
|
26
|
+
constructor(privateApi, simulator, config, existingMetrics) {
|
|
27
|
+
super();
|
|
28
|
+
this.privateApi = privateApi;
|
|
29
|
+
this.simulator = simulator;
|
|
30
|
+
this.config = config ?? DEFAULT_SHADOW_CONFIG;
|
|
31
|
+
this.metrics = existingMetrics ?? createEmptyShadowMetrics();
|
|
32
|
+
}
|
|
33
|
+
/** Start listening for simulator fill events. */
|
|
34
|
+
start() {
|
|
35
|
+
if (this.active)
|
|
36
|
+
return;
|
|
37
|
+
this.active = true;
|
|
38
|
+
this.simulator.on('fill', this.onFill);
|
|
39
|
+
logger.info(TAG, `Shadow tracker started (${this.metrics.totalShadowTrades} prior comparisons)`);
|
|
40
|
+
}
|
|
41
|
+
/** Stop listening. */
|
|
42
|
+
stop() {
|
|
43
|
+
if (!this.active)
|
|
44
|
+
return;
|
|
45
|
+
this.active = false;
|
|
46
|
+
this.simulator.off('fill', this.onFill);
|
|
47
|
+
logger.info(TAG, 'Shadow tracker stopped');
|
|
48
|
+
}
|
|
49
|
+
/** Get current shadow metrics. */
|
|
50
|
+
getMetrics() {
|
|
51
|
+
return { ...this.metrics };
|
|
52
|
+
}
|
|
53
|
+
/** Get recent comparisons. */
|
|
54
|
+
getRecentComparisons() {
|
|
55
|
+
return [...this.recentComparisons];
|
|
56
|
+
}
|
|
57
|
+
/** Check if shadow mode criteria are met for mode upgrade. */
|
|
58
|
+
isReadyForUpgrade() {
|
|
59
|
+
const reasons = [];
|
|
60
|
+
if (this.metrics.totalShadowTrades < this.config.minTrades) {
|
|
61
|
+
reasons.push(`Need ${this.config.minTrades} shadow trades, have ${this.metrics.totalShadowTrades}`);
|
|
62
|
+
}
|
|
63
|
+
if (this.metrics.tradingDays < this.config.minDays) {
|
|
64
|
+
reasons.push(`Need ${this.config.minDays} trading days, have ${this.metrics.tradingDays}`);
|
|
65
|
+
}
|
|
66
|
+
if (this.metrics.avgDeltaBps > this.config.maxAvgDeltaBps) {
|
|
67
|
+
reasons.push(`Avg delta ${this.metrics.avgDeltaBps.toFixed(2)}bps exceeds max ${this.config.maxAvgDeltaBps}bps`);
|
|
68
|
+
}
|
|
69
|
+
return { ready: reasons.length === 0, reasons };
|
|
70
|
+
}
|
|
71
|
+
// Arrow function to preserve `this` binding when used as event listener
|
|
72
|
+
onFill = (fillData) => {
|
|
73
|
+
// Only compare market order fills (limit orders fill at limit price, no comparison needed)
|
|
74
|
+
if (fillData.type !== 'market')
|
|
75
|
+
return;
|
|
76
|
+
// Fire and forget — shadow comparison is async but doesn't block the fill
|
|
77
|
+
this.computeShadowComparison(fillData).catch(err => {
|
|
78
|
+
logger.warn(TAG, `Shadow comparison failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
async computeShadowComparison(fillData) {
|
|
82
|
+
// Fetch fresh order book from the exchange (authenticated path)
|
|
83
|
+
const liveBook = await this.privateApi.fetchOrderBook(fillData.symbol, 20);
|
|
84
|
+
let shadowPrice;
|
|
85
|
+
let bookDepthUsed = 0;
|
|
86
|
+
let bookDepthAvailable = false;
|
|
87
|
+
if (liveBook && liveBook.asks.length > 0 && liveBook.bids.length > 0) {
|
|
88
|
+
// Walk the live book to compute shadow VWAP
|
|
89
|
+
const { vwap, levelsConsumed } = computeBookAwareFillPrice(fillData.side, fillData.amount, liveBook);
|
|
90
|
+
shadowPrice = vwap;
|
|
91
|
+
bookDepthUsed = levelsConsumed;
|
|
92
|
+
bookDepthAvailable = true;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// No live book available — use paper fill as shadow estimate
|
|
96
|
+
shadowPrice = fillData.fillPrice;
|
|
97
|
+
logger.warn(TAG, `No live order book for ${fillData.symbol} — shadow estimate equals paper`);
|
|
98
|
+
}
|
|
99
|
+
// Compute shadow fee (same taker rate as paper for fair comparison)
|
|
100
|
+
const simConfig = this.simulator.getSimulationConfig();
|
|
101
|
+
const shadowFee = fillData.amount * shadowPrice * simConfig.fees.takerRate;
|
|
102
|
+
// Delta: positive = live would be worse (pay more for buy, receive less for sell)
|
|
103
|
+
const deltaBps = priceToBps(shadowPrice, fillData.fillPrice);
|
|
104
|
+
const comparison = {
|
|
105
|
+
orderId: fillData.orderId,
|
|
106
|
+
symbol: fillData.symbol,
|
|
107
|
+
side: fillData.side,
|
|
108
|
+
type: fillData.type,
|
|
109
|
+
amount: fillData.amount,
|
|
110
|
+
paperFillPrice: fillData.fillPrice,
|
|
111
|
+
shadowEstimatePrice: shadowPrice,
|
|
112
|
+
deltaBps,
|
|
113
|
+
paperFee: fillData.fee,
|
|
114
|
+
shadowEstimateFee: shadowFee,
|
|
115
|
+
bookDepthUsed,
|
|
116
|
+
bookDepthAvailable,
|
|
117
|
+
timestamp: new Date().toISOString(),
|
|
118
|
+
};
|
|
119
|
+
// Update metrics
|
|
120
|
+
this.updateMetrics(comparison);
|
|
121
|
+
// Store recent comparison (match webapp slice pattern — slice instead of shift)
|
|
122
|
+
this.recentComparisons = [
|
|
123
|
+
...this.recentComparisons.slice(-(MAX_RECENT_COMPARISONS - 1)),
|
|
124
|
+
comparison,
|
|
125
|
+
];
|
|
126
|
+
// Emit event for skill/bridge pipeline
|
|
127
|
+
this.emit('shadowComparison', comparison);
|
|
128
|
+
logger.info(TAG, `Shadow comparison: ${fillData.side} ${fillData.amount} ${fillData.symbol}` +
|
|
129
|
+
` | Paper: ${fillData.fillPrice.toFixed(2)} | Shadow: ${shadowPrice.toFixed(2)}` +
|
|
130
|
+
` | Delta: ${deltaBps.toFixed(2)}bps` +
|
|
131
|
+
` | Book: ${bookDepthAvailable ? `${bookDepthUsed} levels` : 'unavailable'}`);
|
|
132
|
+
}
|
|
133
|
+
updateMetrics(comparison) {
|
|
134
|
+
const m = this.metrics;
|
|
135
|
+
m.totalShadowTrades++;
|
|
136
|
+
const absDelta = Math.abs(comparison.deltaBps);
|
|
137
|
+
m.totalDeltaBpsSum += absDelta;
|
|
138
|
+
m.avgDeltaBps = m.totalDeltaBpsSum / m.totalShadowTrades;
|
|
139
|
+
if (absDelta > m.worstDeltaBps) {
|
|
140
|
+
m.worstDeltaBps = absDelta;
|
|
141
|
+
}
|
|
142
|
+
m.paperTotalFees += comparison.paperFee;
|
|
143
|
+
m.shadowTotalFees += comparison.shadowEstimateFee;
|
|
144
|
+
// Track trading days
|
|
145
|
+
const today = comparison.timestamp.slice(0, 10);
|
|
146
|
+
if (today !== m.lastTradeDate) {
|
|
147
|
+
m.tradingDays++;
|
|
148
|
+
m.lastTradeDate = today;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TradingMode } from '../types.js';
|
|
2
|
+
export type { TradingMode };
|
|
3
|
+
/** A single shadow comparison record: paper fill vs live estimate. */
|
|
4
|
+
export interface ShadowComparison {
|
|
5
|
+
orderId: string;
|
|
6
|
+
symbol: string;
|
|
7
|
+
side: 'buy' | 'sell';
|
|
8
|
+
type: 'market' | 'limit';
|
|
9
|
+
amount: number;
|
|
10
|
+
paperFillPrice: number;
|
|
11
|
+
shadowEstimatePrice: number;
|
|
12
|
+
deltaBps: number;
|
|
13
|
+
paperFee: number;
|
|
14
|
+
shadowEstimateFee: number;
|
|
15
|
+
bookDepthUsed: number;
|
|
16
|
+
bookDepthAvailable: boolean;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
}
|
|
19
|
+
/** Aggregate shadow metrics across all shadow comparisons. */
|
|
20
|
+
export interface ShadowMetrics {
|
|
21
|
+
totalShadowTrades: number;
|
|
22
|
+
avgDeltaBps: number;
|
|
23
|
+
worstDeltaBps: number;
|
|
24
|
+
totalDeltaBpsSum: number;
|
|
25
|
+
paperTotalFees: number;
|
|
26
|
+
shadowTotalFees: number;
|
|
27
|
+
startedAt: string;
|
|
28
|
+
tradingDays: number;
|
|
29
|
+
lastTradeDate: string;
|
|
30
|
+
}
|
|
31
|
+
/** Shadow mode configuration thresholds. */
|
|
32
|
+
export interface ShadowConfig {
|
|
33
|
+
/** Minimum shadow trades before allowing mode upgrade (default: 50) */
|
|
34
|
+
minTrades: number;
|
|
35
|
+
/** Minimum days in shadow mode (default: 7) */
|
|
36
|
+
minDays: number;
|
|
37
|
+
/** Max acceptable average delta in bps (default: 5) */
|
|
38
|
+
maxAvgDeltaBps: number;
|
|
39
|
+
}
|
|
40
|
+
export declare const DEFAULT_SHADOW_CONFIG: ShadowConfig;
|
|
41
|
+
/** Create empty shadow metrics. */
|
|
42
|
+
export declare function createEmptyShadowMetrics(): ShadowMetrics;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Shadow mode types — tracking paper vs live fill comparison.
|
|
2
|
+
export const DEFAULT_SHADOW_CONFIG = {
|
|
3
|
+
minTrades: 50,
|
|
4
|
+
minDays: 7,
|
|
5
|
+
maxAvgDeltaBps: 5,
|
|
6
|
+
};
|
|
7
|
+
/** Create empty shadow metrics. */
|
|
8
|
+
export function createEmptyShadowMetrics() {
|
|
9
|
+
return {
|
|
10
|
+
totalShadowTrades: 0,
|
|
11
|
+
avgDeltaBps: 0,
|
|
12
|
+
worstDeltaBps: 0,
|
|
13
|
+
totalDeltaBpsSum: 0,
|
|
14
|
+
paperTotalFees: 0,
|
|
15
|
+
shadowTotalFees: 0,
|
|
16
|
+
startedAt: new Date().toISOString(),
|
|
17
|
+
tradingDays: 0,
|
|
18
|
+
lastTradeDate: '',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -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,291 @@
|
|
|
1
|
+
// ⚠️ GENERATED FILE — DO NOT EDIT.
|
|
2
|
+
// Canonical source of truth: shared/src/shared/indicators-extended.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
|
+
// Extended indicator computations for Phase 13 — Expanded Indicators.
|
|
9
|
+
// Wraps technicalindicators library + custom implementations.
|
|
10
|
+
// All functions take OHLCV arrays (oldest first) and return latest values.
|
|
11
|
+
import { computeATRSeries, computeRSI, mean, computeStd } from './indicators.js';
|
|
12
|
+
// ─── MACD (12, 26, 9) ──────────────────────────────────────────────────
|
|
13
|
+
export function computeMACD(closes, fast = 12, slow = 26, signal = 9) {
|
|
14
|
+
if (closes.length < slow + signal) {
|
|
15
|
+
return { line: 0, signal: 0, histogram: 0, crossover: 'none' };
|
|
16
|
+
}
|
|
17
|
+
// Compute full EMA series (both aligned to start at index `slow - 1`)
|
|
18
|
+
const emaFastSeries = emaSeries(closes, fast);
|
|
19
|
+
const emaSlowSeries = emaSeries(closes, slow);
|
|
20
|
+
// Align: fast series starts earlier, so take the tail matching slow series length
|
|
21
|
+
const offset = emaFastSeries.length - emaSlowSeries.length;
|
|
22
|
+
const macdLine = [];
|
|
23
|
+
for (let i = 0; i < emaSlowSeries.length; i++) {
|
|
24
|
+
macdLine.push(emaFastSeries[i + offset] - emaSlowSeries[i]);
|
|
25
|
+
}
|
|
26
|
+
// Signal line = EMA of MACD line
|
|
27
|
+
const signalSeries = emaSeries(macdLine, signal);
|
|
28
|
+
const sigOffset = macdLine.length - signalSeries.length;
|
|
29
|
+
const currentLine = macdLine[macdLine.length - 1];
|
|
30
|
+
const currentSignal = signalSeries[signalSeries.length - 1];
|
|
31
|
+
const prevLine = macdLine.length >= 2 ? macdLine[macdLine.length - 2] : currentLine;
|
|
32
|
+
const prevSignalIdx = signalSeries.length >= 2 ? signalSeries.length - 2 : signalSeries.length - 1;
|
|
33
|
+
const prevSignal = signalSeries[prevSignalIdx];
|
|
34
|
+
let crossover = 'none';
|
|
35
|
+
if (prevLine <= prevSignal && currentLine > currentSignal)
|
|
36
|
+
crossover = 'bullish';
|
|
37
|
+
else if (prevLine >= prevSignal && currentLine < currentSignal)
|
|
38
|
+
crossover = 'bearish';
|
|
39
|
+
return {
|
|
40
|
+
line: currentLine,
|
|
41
|
+
signal: currentSignal,
|
|
42
|
+
histogram: currentLine - currentSignal,
|
|
43
|
+
crossover,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// ─── Bollinger Bands (20, 2σ) ───────────────────────────────────────────
|
|
47
|
+
export function computeBollingerBands(closes, period = 20, stdDev = 2) {
|
|
48
|
+
if (closes.length < period) {
|
|
49
|
+
const p = closes[closes.length - 1] ?? 0;
|
|
50
|
+
return { upper: p, middle: p, lower: p, bandwidth: 0, percentB: 0.5 };
|
|
51
|
+
}
|
|
52
|
+
const slice = closes.slice(-period);
|
|
53
|
+
const middle = mean(slice);
|
|
54
|
+
const std = computeStd(slice);
|
|
55
|
+
const upper = middle + stdDev * std;
|
|
56
|
+
const lower = middle - stdDev * std;
|
|
57
|
+
const bandwidth = middle > 0 ? ((upper - lower) / middle) * 100 : 0;
|
|
58
|
+
const price = closes[closes.length - 1];
|
|
59
|
+
const percentB = upper !== lower ? (price - lower) / (upper - lower) : 0.5;
|
|
60
|
+
return { upper, middle, lower, bandwidth, percentB };
|
|
61
|
+
}
|
|
62
|
+
// ─── VWAP ───────────────────────────────────────────────────────────────
|
|
63
|
+
export function computeVWAP(bars) {
|
|
64
|
+
if (bars.length === 0)
|
|
65
|
+
return 0;
|
|
66
|
+
let cumVolume = 0;
|
|
67
|
+
let cumTPxVol = 0;
|
|
68
|
+
for (const bar of bars) {
|
|
69
|
+
const tp = (bar.high + bar.low + bar.close) / 3;
|
|
70
|
+
cumVolume += bar.volume;
|
|
71
|
+
cumTPxVol += tp * bar.volume;
|
|
72
|
+
}
|
|
73
|
+
return cumVolume > 0 ? cumTPxVol / cumVolume : bars[bars.length - 1].close;
|
|
74
|
+
}
|
|
75
|
+
// ─── Stochastic RSI (14, 14, 3, 3) ─────────────────────────────────────
|
|
76
|
+
export function computeStochRSI(closes, rsiPeriod = 14, stochPeriod = 14, kSmooth = 3, dSmooth = 3) {
|
|
77
|
+
if (closes.length < rsiPeriod + stochPeriod + dSmooth) {
|
|
78
|
+
return { k: 50, d: 50 };
|
|
79
|
+
}
|
|
80
|
+
// Compute RSI series
|
|
81
|
+
const rsiValues = [];
|
|
82
|
+
for (let i = rsiPeriod + 1; i <= closes.length; i++) {
|
|
83
|
+
rsiValues.push(computeRSI(closes.slice(0, i), rsiPeriod));
|
|
84
|
+
}
|
|
85
|
+
if (rsiValues.length < stochPeriod)
|
|
86
|
+
return { k: 50, d: 50 };
|
|
87
|
+
// Stochastic of RSI
|
|
88
|
+
const rawK = [];
|
|
89
|
+
for (let i = stochPeriod - 1; i < rsiValues.length; i++) {
|
|
90
|
+
const window = rsiValues.slice(i - stochPeriod + 1, i + 1);
|
|
91
|
+
const min = Math.min(...window);
|
|
92
|
+
const max = Math.max(...window);
|
|
93
|
+
rawK.push(max !== min ? ((rsiValues[i] - min) / (max - min)) * 100 : 50);
|
|
94
|
+
}
|
|
95
|
+
// %K = SMA of raw stochastic
|
|
96
|
+
const kValues = sma(rawK, kSmooth);
|
|
97
|
+
// %D = SMA of %K
|
|
98
|
+
const dValues = sma(kValues, dSmooth);
|
|
99
|
+
return {
|
|
100
|
+
k: Math.round(kValues[kValues.length - 1] ?? 50),
|
|
101
|
+
d: Math.round(dValues[dValues.length - 1] ?? 50),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
// ─── ADX (14) ───────────────────────────────────────────────────────────
|
|
105
|
+
export function computeADX(highs, lows, closes, period = 14) {
|
|
106
|
+
if (highs.length < period * 2 + 1) {
|
|
107
|
+
return { adx: 0, plusDI: 0, minusDI: 0 };
|
|
108
|
+
}
|
|
109
|
+
const plusDM = [];
|
|
110
|
+
const minusDM = [];
|
|
111
|
+
const tr = [];
|
|
112
|
+
for (let i = 1; i < highs.length; i++) {
|
|
113
|
+
const upMove = highs[i] - highs[i - 1];
|
|
114
|
+
const downMove = lows[i - 1] - lows[i];
|
|
115
|
+
plusDM.push(upMove > downMove && upMove > 0 ? upMove : 0);
|
|
116
|
+
minusDM.push(downMove > upMove && downMove > 0 ? downMove : 0);
|
|
117
|
+
tr.push(Math.max(highs[i] - lows[i], Math.abs(highs[i] - closes[i - 1]), Math.abs(lows[i] - closes[i - 1])));
|
|
118
|
+
}
|
|
119
|
+
// Smooth with Wilder's smoothing (equivalent to EMA with alpha=1/period)
|
|
120
|
+
const smoothPlusDM = wilderSmooth(plusDM, period);
|
|
121
|
+
const smoothMinusDM = wilderSmooth(minusDM, period);
|
|
122
|
+
const smoothTR = wilderSmooth(tr, period);
|
|
123
|
+
// +DI and -DI series
|
|
124
|
+
const plusDISeries = [];
|
|
125
|
+
const minusDISeries = [];
|
|
126
|
+
for (let i = 0; i < smoothTR.length; i++) {
|
|
127
|
+
plusDISeries.push(smoothTR[i] > 0 ? (smoothPlusDM[i] / smoothTR[i]) * 100 : 0);
|
|
128
|
+
minusDISeries.push(smoothTR[i] > 0 ? (smoothMinusDM[i] / smoothTR[i]) * 100 : 0);
|
|
129
|
+
}
|
|
130
|
+
// DX series
|
|
131
|
+
const dxSeries = [];
|
|
132
|
+
for (let i = 0; i < plusDISeries.length; i++) {
|
|
133
|
+
const sum = plusDISeries[i] + minusDISeries[i];
|
|
134
|
+
dxSeries.push(sum > 0 ? (Math.abs(plusDISeries[i] - minusDISeries[i]) / sum) * 100 : 0);
|
|
135
|
+
}
|
|
136
|
+
// ADX = Wilder smooth of DX
|
|
137
|
+
const adxSeries = wilderSmooth(dxSeries, period);
|
|
138
|
+
return {
|
|
139
|
+
adx: Math.round(adxSeries[adxSeries.length - 1] ?? 0),
|
|
140
|
+
plusDI: Math.round(plusDISeries[plusDISeries.length - 1] ?? 0),
|
|
141
|
+
minusDI: Math.round(minusDISeries[minusDISeries.length - 1] ?? 0),
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// ─── Ichimoku Cloud ─────────────────────────────────────────────────────
|
|
145
|
+
export function computeIchimoku(highs, lows, closes, tenkanPeriod = 9, kijunPeriod = 26, senkouBPeriod = 52) {
|
|
146
|
+
const n = highs.length;
|
|
147
|
+
if (n < senkouBPeriod) {
|
|
148
|
+
const p = closes[n - 1] ?? 0;
|
|
149
|
+
return { tenkan: p, kijun: p, senkouA: p, senkouB: p, chikou: p, cloudPosition: 'inside' };
|
|
150
|
+
}
|
|
151
|
+
const midpoint = (arr, period, end) => {
|
|
152
|
+
const slice = arr.slice(Math.max(0, end - period + 1), end + 1);
|
|
153
|
+
return (Math.max(...slice) + Math.min(...slice)) / 2;
|
|
154
|
+
};
|
|
155
|
+
const tenkan = midpoint(highs.concat().map((h, i) => Math.max(h, lows[i])), tenkanPeriod, n - 1);
|
|
156
|
+
const kijun = midpoint(highs.concat().map((h, i) => Math.max(h, lows[i])), kijunPeriod, n - 1);
|
|
157
|
+
// Recalculate properly using highs and lows separately
|
|
158
|
+
const tenkanH = Math.max(...highs.slice(-tenkanPeriod));
|
|
159
|
+
const tenkanL = Math.min(...lows.slice(-tenkanPeriod));
|
|
160
|
+
const tenkanVal = (tenkanH + tenkanL) / 2;
|
|
161
|
+
const kijunH = Math.max(...highs.slice(-kijunPeriod));
|
|
162
|
+
const kijunL = Math.min(...lows.slice(-kijunPeriod));
|
|
163
|
+
const kijunVal = (kijunH + kijunL) / 2;
|
|
164
|
+
const senkouA = (tenkanVal + kijunVal) / 2;
|
|
165
|
+
const senkouBH = Math.max(...highs.slice(-senkouBPeriod));
|
|
166
|
+
const senkouBL = Math.min(...lows.slice(-senkouBPeriod));
|
|
167
|
+
const senkouB = (senkouBH + senkouBL) / 2;
|
|
168
|
+
const chikou = closes[n - 1]; // Current close (projected back 26 periods)
|
|
169
|
+
const price = closes[n - 1];
|
|
170
|
+
const cloudTop = Math.max(senkouA, senkouB);
|
|
171
|
+
const cloudBottom = Math.min(senkouA, senkouB);
|
|
172
|
+
const cloudPosition = price > cloudTop ? 'above' : price < cloudBottom ? 'below' : 'inside';
|
|
173
|
+
return { tenkan: tenkanVal, kijun: kijunVal, senkouA, senkouB, chikou, cloudPosition };
|
|
174
|
+
}
|
|
175
|
+
// ─── OBV (On-Balance Volume) ────────────────────────────────────────────
|
|
176
|
+
export function computeOBV(closes, volumes) {
|
|
177
|
+
if (closes.length < 2)
|
|
178
|
+
return { obv: 0, slope: 'flat' };
|
|
179
|
+
let obv = 0;
|
|
180
|
+
const obvSeries = [0];
|
|
181
|
+
for (let i = 1; i < closes.length; i++) {
|
|
182
|
+
if (closes[i] > closes[i - 1])
|
|
183
|
+
obv += volumes[i];
|
|
184
|
+
else if (closes[i] < closes[i - 1])
|
|
185
|
+
obv -= volumes[i];
|
|
186
|
+
obvSeries.push(obv);
|
|
187
|
+
}
|
|
188
|
+
// Slope over last 10 bars
|
|
189
|
+
const lookback = Math.min(10, obvSeries.length);
|
|
190
|
+
const recent = obvSeries.slice(-lookback);
|
|
191
|
+
const first = recent[0];
|
|
192
|
+
const last = recent[recent.length - 1];
|
|
193
|
+
const threshold = Math.abs(first) * 0.01; // 1% threshold
|
|
194
|
+
const slope = last - first > threshold ? 'rising' : last - first < -threshold ? 'falling' : 'flat';
|
|
195
|
+
return { obv, slope };
|
|
196
|
+
}
|
|
197
|
+
// ─── Supertrend (10, 3) ─────────────────────────────────────────────────
|
|
198
|
+
export function computeSupertrend(highs, lows, closes, period = 10, multiplier = 3) {
|
|
199
|
+
const atrSeries = computeATRSeries(highs, lows, closes, period);
|
|
200
|
+
if (atrSeries.length === 0) {
|
|
201
|
+
return { value: closes[closes.length - 1] ?? 0, direction: 'bullish' };
|
|
202
|
+
}
|
|
203
|
+
// ATR series starts at index 1 (needs previous close for TR)
|
|
204
|
+
// Align: atrSeries[i] corresponds to bar index i+1
|
|
205
|
+
let upperBand = 0;
|
|
206
|
+
let lowerBand = 0;
|
|
207
|
+
let supertrend = 0;
|
|
208
|
+
let direction = 'bullish';
|
|
209
|
+
for (let i = 0; i < atrSeries.length; i++) {
|
|
210
|
+
const barIdx = i + 1; // offset for TR calculation
|
|
211
|
+
const hl2 = (highs[barIdx] + lows[barIdx]) / 2;
|
|
212
|
+
const atr = atrSeries[i];
|
|
213
|
+
const basicUpper = hl2 + multiplier * atr;
|
|
214
|
+
const basicLower = hl2 - multiplier * atr;
|
|
215
|
+
upperBand = i > 0 && basicUpper < upperBand && closes[barIdx - 1] > upperBand ? upperBand : basicUpper;
|
|
216
|
+
lowerBand = i > 0 && basicLower > lowerBand && closes[barIdx - 1] < lowerBand ? lowerBand : basicLower;
|
|
217
|
+
if (i === 0) {
|
|
218
|
+
supertrend = closes[barIdx] > upperBand ? lowerBand : upperBand;
|
|
219
|
+
direction = closes[barIdx] > upperBand ? 'bullish' : 'bearish';
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
if (direction === 'bullish') {
|
|
223
|
+
if (closes[barIdx] < lowerBand) {
|
|
224
|
+
direction = 'bearish';
|
|
225
|
+
supertrend = upperBand;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
supertrend = lowerBand;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
if (closes[barIdx] > upperBand) {
|
|
233
|
+
direction = 'bullish';
|
|
234
|
+
supertrend = lowerBand;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
supertrend = upperBand;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return { value: supertrend, direction };
|
|
243
|
+
}
|
|
244
|
+
// ─── Williams %R (14) ───────────────────────────────────────────────────
|
|
245
|
+
export function computeWilliamsR(highs, lows, closes, period = 14) {
|
|
246
|
+
if (highs.length < period)
|
|
247
|
+
return -50;
|
|
248
|
+
const recentHighs = highs.slice(-period);
|
|
249
|
+
const recentLows = lows.slice(-period);
|
|
250
|
+
const hh = Math.max(...recentHighs);
|
|
251
|
+
const ll = Math.min(...recentLows);
|
|
252
|
+
const close = closes[closes.length - 1];
|
|
253
|
+
return hh !== ll ? ((hh - close) / (hh - ll)) * -100 : -50;
|
|
254
|
+
}
|
|
255
|
+
// ─── Helper: EMA series ─────────────────────────────────────────────────
|
|
256
|
+
function emaSeries(data, period) {
|
|
257
|
+
if (data.length === 0)
|
|
258
|
+
return [];
|
|
259
|
+
if (data.length < period)
|
|
260
|
+
return [data[data.length - 1]];
|
|
261
|
+
const k = 2 / (period + 1);
|
|
262
|
+
const result = [];
|
|
263
|
+
let ema = mean(data.slice(0, period));
|
|
264
|
+
result.push(ema);
|
|
265
|
+
for (let i = period; i < data.length; i++) {
|
|
266
|
+
ema = data[i] * k + ema * (1 - k);
|
|
267
|
+
result.push(ema);
|
|
268
|
+
}
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
// ─── Helper: SMA series ─────────────────────────────────────────────────
|
|
272
|
+
function sma(data, period) {
|
|
273
|
+
if (data.length < period)
|
|
274
|
+
return data.length > 0 ? [mean(data)] : [];
|
|
275
|
+
const result = [];
|
|
276
|
+
for (let i = period - 1; i < data.length; i++) {
|
|
277
|
+
result.push(mean(data.slice(i - period + 1, i + 1)));
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
// ─── Helper: Wilder's smoothing ─────────────────────────────────────────
|
|
282
|
+
function wilderSmooth(data, period) {
|
|
283
|
+
if (data.length < period)
|
|
284
|
+
return [];
|
|
285
|
+
const result = [];
|
|
286
|
+
result.push(mean(data.slice(0, period)));
|
|
287
|
+
for (let i = period; i < data.length; i++) {
|
|
288
|
+
result.push((result[result.length - 1] * (period - 1) + data[i]) / period);
|
|
289
|
+
}
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
@@ -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
|
+
};
|