@reefclaw/connect 0.1.10 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/bridge/gateway/event-parser.d.ts +6 -1
- package/assets/bridge/gateway/event-parser.js +19 -2
- package/assets/bridge/gateway/heartbeat-cron.d.ts +27 -0
- package/assets/bridge/gateway/heartbeat-cron.js +85 -0
- package/assets/bridge/gateway/poller.d.ts +1 -0
- package/assets/bridge/gateway/poller.js +14 -2
- package/assets/bridge/providers/gateway.d.ts +24 -2
- package/assets/bridge/providers/gateway.js +124 -25
- package/assets/bridge/setup.js +6 -51
- package/assets/shared/signals/conditions/registry.js +11 -2
- package/assets/shared/signals/strategy-adapter.js +17 -7
- package/assets/skill/SKILL.md +2 -0
- package/dist/deps.js +2 -2
- package/dist/plugin.js +35 -7
- package/package.json +1 -1
- package/assets/plugin/audit/mode-transition-audit.d.ts +0 -11
- package/assets/plugin/audit/mode-transition-audit.js +0 -29
- package/assets/plugin/balance-utils.d.ts +0 -36
- package/assets/plugin/balance-utils.js +0 -98
- package/assets/plugin/ccxt/binance-ban-gate.d.ts +0 -47
- package/assets/plugin/ccxt/binance-ban-gate.js +0 -420
- package/assets/plugin/ccxt/binance-private.d.ts +0 -346
- package/assets/plugin/ccxt/binance-private.js +0 -1525
- package/assets/plugin/ccxt/binance-public.d.ts +0 -34
- package/assets/plugin/ccxt/binance-public.js +0 -180
- package/assets/plugin/ccxt/intel-public.d.ts +0 -25
- package/assets/plugin/ccxt/intel-public.js +0 -80
- package/assets/plugin/ccxt/public-market-data-api.d.ts +0 -12
- package/assets/plugin/ccxt/public-market-data-api.js +0 -9
- package/assets/plugin/config/agent-config-client.d.ts +0 -77
- package/assets/plugin/config/agent-config-client.js +0 -188
- package/assets/plugin/config/agent-config-poller.d.ts +0 -32
- package/assets/plugin/config/agent-config-poller.js +0 -101
- package/assets/plugin/config/brackets-config.d.ts +0 -22
- package/assets/plugin/config/brackets-config.js +0 -58
- package/assets/plugin/config/entitlement-gate.d.ts +0 -51
- package/assets/plugin/config/entitlement-gate.js +0 -137
- package/assets/plugin/config/gate-store.d.ts +0 -18
- package/assets/plugin/config/gate-store.js +0 -61
- package/assets/plugin/config/plugin-config-io.d.ts +0 -215
- package/assets/plugin/config/plugin-config-io.js +0 -111
- package/assets/plugin/config/position-review-config.d.ts +0 -35
- package/assets/plugin/config/position-review-config.js +0 -105
- package/assets/plugin/config/tool-gate.d.ts +0 -53
- package/assets/plugin/config/tool-gate.js +0 -128
- package/assets/plugin/config/user-data-stream-config.d.ts +0 -89
- package/assets/plugin/config/user-data-stream-config.js +0 -239
- package/assets/plugin/connector-supervisor.d.ts +0 -36
- package/assets/plugin/connector-supervisor.js +0 -149
- package/assets/plugin/exchange-adapter.d.ts +0 -65
- package/assets/plugin/exchange-adapter.js +0 -4
- package/assets/plugin/index.d.ts +0 -30
- package/assets/plugin/index.js +0 -2678
- package/assets/plugin/ingest/pending-entry-metadata.d.ts +0 -74
- package/assets/plugin/ingest/pending-entry-metadata.js +0 -236
- package/assets/plugin/ingest/position-auto-capture.d.ts +0 -103
- package/assets/plugin/ingest/position-auto-capture.js +0 -411
- package/assets/plugin/ingest/position-decisions-client.d.ts +0 -322
- package/assets/plugin/ingest/position-decisions-client.js +0 -296
- package/assets/plugin/ingest/readiness-reporter.d.ts +0 -42
- package/assets/plugin/ingest/readiness-reporter.js +0 -163
- package/assets/plugin/ingest/reconcile-db-vs-exchange.d.ts +0 -13
- package/assets/plugin/ingest/reconcile-db-vs-exchange.js +0 -114
- package/assets/plugin/ingest/reconciler-cleanup.d.ts +0 -37
- package/assets/plugin/ingest/reconciler-cleanup.js +0 -147
- package/assets/plugin/ingest/rest-gap-filler.d.ts +0 -191
- package/assets/plugin/ingest/rest-gap-filler.js +0 -565
- package/assets/plugin/ingest/touched-symbols-store.d.ts +0 -25
- package/assets/plugin/ingest/touched-symbols-store.js +0 -96
- package/assets/plugin/ingest/trade-store-client.d.ts +0 -40
- package/assets/plugin/ingest/trade-store-client.js +0 -125
- package/assets/plugin/ingest/ws-ingest.d.ts +0 -43
- package/assets/plugin/ingest/ws-ingest.js +0 -126
- package/assets/plugin/learning/setup-family.d.ts +0 -21
- package/assets/plugin/learning/setup-family.js +0 -103
- package/assets/plugin/lifecycle/install-signal-handlers.d.ts +0 -33
- package/assets/plugin/lifecycle/install-signal-handlers.js +0 -112
- package/assets/plugin/lifecycle/shutdown-coordinator.d.ts +0 -43
- package/assets/plugin/lifecycle/shutdown-coordinator.js +0 -131
- package/assets/plugin/lifecycle/trading-operation-lock.d.ts +0 -17
- package/assets/plugin/lifecycle/trading-operation-lock.js +0 -14
- package/assets/plugin/live/bracket-id.d.ts +0 -26
- package/assets/plugin/live/bracket-id.js +0 -112
- package/assets/plugin/live/bracket-ledger.d.ts +0 -54
- package/assets/plugin/live/bracket-ledger.js +0 -267
- package/assets/plugin/live/bracket-manager.d.ts +0 -82
- package/assets/plugin/live/bracket-manager.js +0 -478
- package/assets/plugin/live/bracket-params.d.ts +0 -22
- package/assets/plugin/live/bracket-params.js +0 -124
- package/assets/plugin/live/bracket-reconciler.d.ts +0 -95
- package/assets/plugin/live/bracket-reconciler.js +0 -573
- package/assets/plugin/live/bracket-types.d.ts +0 -102
- package/assets/plugin/live/bracket-types.js +0 -8
- package/assets/plugin/live/deposit-tracker.d.ts +0 -62
- package/assets/plugin/live/deposit-tracker.js +0 -97
- package/assets/plugin/live/emergency-controls.d.ts +0 -32
- package/assets/plugin/live/emergency-controls.js +0 -226
- package/assets/plugin/live/exchange-errors.d.ts +0 -12
- package/assets/plugin/live/exchange-errors.js +0 -130
- package/assets/plugin/live/exchange-info-cache.d.ts +0 -37
- package/assets/plugin/live/exchange-info-cache.js +0 -134
- package/assets/plugin/live/fact-subscriber.d.ts +0 -78
- package/assets/plugin/live/fact-subscriber.js +0 -182
- package/assets/plugin/live/intent-journal.d.ts +0 -42
- package/assets/plugin/live/intent-journal.js +0 -122
- package/assets/plugin/live/listen-key-manager.d.ts +0 -70
- package/assets/plugin/live/listen-key-manager.js +0 -169
- package/assets/plugin/live/live-adapter.d.ts +0 -287
- package/assets/plugin/live/live-adapter.js +0 -1777
- package/assets/plugin/live/live-balance-enricher.d.ts +0 -32
- package/assets/plugin/live/live-balance-enricher.js +0 -104
- package/assets/plugin/live/live-bracket-api.d.ts +0 -13
- package/assets/plugin/live/live-bracket-api.js +0 -20
- package/assets/plugin/live/live-state-store.d.ts +0 -194
- package/assets/plugin/live/live-state-store.js +0 -450
- package/assets/plugin/live/local-signal-service.d.ts +0 -57
- package/assets/plugin/live/local-signal-service.js +0 -151
- package/assets/plugin/live/local-strategy-evaluator.d.ts +0 -62
- package/assets/plugin/live/local-strategy-evaluator.js +0 -131
- package/assets/plugin/live/microstructure-assembler.d.ts +0 -54
- package/assets/plugin/live/microstructure-assembler.js +0 -148
- package/assets/plugin/live/order-poller.d.ts +0 -29
- package/assets/plugin/live/order-poller.js +0 -125
- package/assets/plugin/live/position-state-store.d.ts +0 -83
- package/assets/plugin/live/position-state-store.js +0 -237
- package/assets/plugin/live/proposal-decision-listener.d.ts +0 -70
- package/assets/plugin/live/proposal-decision-listener.js +0 -292
- package/assets/plugin/live/proposal-manager.d.ts +0 -76
- package/assets/plugin/live/proposal-manager.js +0 -140
- package/assets/plugin/live/rate-limiter.d.ts +0 -47
- package/assets/plugin/live/rate-limiter.js +0 -159
- package/assets/plugin/live/reconciler.d.ts +0 -39
- package/assets/plugin/live/reconciler.js +0 -175
- package/assets/plugin/live/setup-buckets.d.ts +0 -7
- package/assets/plugin/live/setup-buckets.js +0 -33
- package/assets/plugin/live/slippage-tracker.d.ts +0 -45
- package/assets/plugin/live/slippage-tracker.js +0 -78
- package/assets/plugin/live/stop-watcher.d.ts +0 -60
- package/assets/plugin/live/stop-watcher.js +0 -215
- package/assets/plugin/live/user-data-active-probe.d.ts +0 -54
- package/assets/plugin/live/user-data-active-probe.js +0 -180
- package/assets/plugin/live/user-data-stream-controller.d.ts +0 -200
- package/assets/plugin/live/user-data-stream-controller.js +0 -579
- package/assets/plugin/live/user-data-stream-ws.d.ts +0 -22
- package/assets/plugin/live/user-data-stream-ws.js +0 -63
- package/assets/plugin/live/user-data-stream.d.ts +0 -243
- package/assets/plugin/live/user-data-stream.js +0 -704
- package/assets/plugin/logger.d.ts +0 -2
- package/assets/plugin/logger.js +0 -2
- package/assets/plugin/mfe.d.ts +0 -21
- package/assets/plugin/mfe.js +0 -68
- package/assets/plugin/onboarding/mode-ladder.d.ts +0 -1
- package/assets/plugin/onboarding/mode-ladder.js +0 -3
- package/assets/plugin/onboarding/runtime.d.ts +0 -84
- package/assets/plugin/onboarding/runtime.js +0 -173
- package/assets/plugin/openclaw.plugin.json +0 -92
- package/assets/plugin/paper-adapter.d.ts +0 -24
- package/assets/plugin/paper-adapter.js +0 -91
- package/assets/plugin/persistence/state-manager.d.ts +0 -66
- package/assets/plugin/persistence/state-manager.js +0 -222
- package/assets/plugin/pinned-plan.d.ts +0 -9
- package/assets/plugin/pinned-plan.js +0 -23
- package/assets/plugin/portfolio/wave9-admission.d.ts +0 -67
- package/assets/plugin/portfolio/wave9-admission.js +0 -262
- package/assets/plugin/portfolio/wave9-policy.d.ts +0 -36
- package/assets/plugin/portfolio/wave9-policy.js +0 -183
- package/assets/plugin/risk/pre-trade-check.d.ts +0 -38
- package/assets/plugin/risk/pre-trade-check.js +0 -345
- package/assets/plugin/risk/pre-trade-types.d.ts +0 -60
- package/assets/plugin/risk/pre-trade-types.js +0 -3
- package/assets/plugin/shadow/shadow-tracker.d.ts +0 -36
- package/assets/plugin/shadow/shadow-tracker.js +0 -151
- package/assets/plugin/shadow/types.d.ts +0 -42
- package/assets/plugin/shadow/types.js +0 -20
- package/assets/plugin/shared/indicators-extended.d.ts +0 -52
- package/assets/plugin/shared/indicators-extended.js +0 -291
- package/assets/plugin/shared/indicators.d.ts +0 -15
- package/assets/plugin/shared/indicators.js +0 -114
- package/assets/plugin/signals/conditions/registry.d.ts +0 -16
- package/assets/plugin/signals/conditions/registry.js +0 -1324
- package/assets/plugin/signals/conditions/types.d.ts +0 -1
- package/assets/plugin/signals/conditions/types.js +0 -4
- package/assets/plugin/signals/direction-rules.d.ts +0 -3
- package/assets/plugin/signals/direction-rules.js +0 -24
- package/assets/plugin/signals/entry-rules.d.ts +0 -6
- package/assets/plugin/signals/entry-rules.js +0 -33
- package/assets/plugin/signals/serialize-context.d.ts +0 -4
- package/assets/plugin/signals/serialize-context.js +0 -39
- package/assets/plugin/signals/stop-rules.d.ts +0 -3
- package/assets/plugin/signals/stop-rules.js +0 -48
- package/assets/plugin/signals/strategy-adapter.d.ts +0 -47
- package/assets/plugin/signals/strategy-adapter.js +0 -199
- package/assets/plugin/signals/types.d.ts +0 -1
- package/assets/plugin/signals/types.js +0 -8
- package/assets/plugin/simulator/exchange-simulator.d.ts +0 -93
- package/assets/plugin/simulator/exchange-simulator.js +0 -689
- package/assets/plugin/simulator/fill-engine.d.ts +0 -53
- package/assets/plugin/simulator/fill-engine.js +0 -280
- package/assets/plugin/simulator/paper-market-feed.d.ts +0 -26
- package/assets/plugin/simulator/paper-market-feed.js +0 -104
- package/assets/plugin/simulator/realistic-fills.d.ts +0 -59
- package/assets/plugin/simulator/realistic-fills.js +0 -175
- package/assets/plugin/simulator/types.d.ts +0 -224
- package/assets/plugin/simulator/types.js +0 -43
- package/assets/plugin/strategy/builtin-strategies.d.ts +0 -2
- package/assets/plugin/strategy/builtin-strategies.js +0 -113
- package/assets/plugin/strategy/condition-registry.d.ts +0 -3
- package/assets/plugin/strategy/condition-registry.js +0 -153
- package/assets/plugin/strategy/evaluator.d.ts +0 -70
- package/assets/plugin/strategy/evaluator.js +0 -98
- package/assets/plugin/tools/assessment-validation.d.ts +0 -120
- package/assets/plugin/tools/assessment-validation.js +0 -415
- package/assets/plugin/tools/attach-brackets.d.ts +0 -39
- package/assets/plugin/tools/attach-brackets.js +0 -399
- package/assets/plugin/tools/audit-bracket-protection.d.ts +0 -49
- package/assets/plugin/tools/audit-bracket-protection.js +0 -527
- package/assets/plugin/tools/cancel-all-orders.d.ts +0 -9
- package/assets/plugin/tools/cancel-all-orders.js +0 -8
- package/assets/plugin/tools/cancel-order.d.ts +0 -14
- package/assets/plugin/tools/cancel-order.js +0 -60
- package/assets/plugin/tools/check-position-health.d.ts +0 -46
- package/assets/plugin/tools/check-position-health.js +0 -194
- package/assets/plugin/tools/clear-exchange-credentials.d.ts +0 -24
- package/assets/plugin/tools/clear-exchange-credentials.js +0 -70
- package/assets/plugin/tools/close-position.d.ts +0 -45
- package/assets/plugin/tools/close-position.js +0 -722
- package/assets/plugin/tools/create-order.d.ts +0 -82
- package/assets/plugin/tools/create-order.js +0 -1516
- package/assets/plugin/tools/exit-gate.d.ts +0 -58
- package/assets/plugin/tools/exit-gate.js +0 -162
- package/assets/plugin/tools/fetch-balance.d.ts +0 -5
- package/assets/plugin/tools/fetch-balance.js +0 -4
- package/assets/plugin/tools/fetch-ohlcv.d.ts +0 -11
- package/assets/plugin/tools/fetch-ohlcv.js +0 -8
- package/assets/plugin/tools/fetch-open-orders.d.ts +0 -7
- package/assets/plugin/tools/fetch-open-orders.js +0 -4
- package/assets/plugin/tools/fetch-positions.d.ts +0 -7
- package/assets/plugin/tools/fetch-positions.js +0 -4
- package/assets/plugin/tools/fetch-ticker.d.ts +0 -11
- package/assets/plugin/tools/fetch-ticker.js +0 -5
- package/assets/plugin/tools/get-agent-profile.d.ts +0 -4
- package/assets/plugin/tools/get-agent-profile.js +0 -6
- package/assets/plugin/tools/get-analytics.d.ts +0 -6
- package/assets/plugin/tools/get-analytics.js +0 -7
- package/assets/plugin/tools/get-backtest.d.ts +0 -12
- package/assets/plugin/tools/get-backtest.js +0 -91
- package/assets/plugin/tools/get-basis.d.ts +0 -7
- package/assets/plugin/tools/get-basis.js +0 -7
- package/assets/plugin/tools/get-bracket-config.d.ts +0 -11
- package/assets/plugin/tools/get-bracket-config.js +0 -24
- package/assets/plugin/tools/get-cascade-risk.d.ts +0 -7
- package/assets/plugin/tools/get-cascade-risk.js +0 -8
- package/assets/plugin/tools/get-crypto-metrics.d.ts +0 -18
- package/assets/plugin/tools/get-crypto-metrics.js +0 -62
- package/assets/plugin/tools/get-cvd.d.ts +0 -6
- package/assets/plugin/tools/get-cvd.js +0 -6
- package/assets/plugin/tools/get-divergences.d.ts +0 -6
- package/assets/plugin/tools/get-divergences.js +0 -6
- package/assets/plugin/tools/get-funding-context.d.ts +0 -6
- package/assets/plugin/tools/get-funding-context.js +0 -16
- package/assets/plugin/tools/get-liquidation-levels.d.ts +0 -7
- package/assets/plugin/tools/get-liquidation-levels.js +0 -7
- package/assets/plugin/tools/get-liquidation-pulse.d.ts +0 -9
- package/assets/plugin/tools/get-liquidation-pulse.js +0 -22
- package/assets/plugin/tools/get-market-breadth.d.ts +0 -6
- package/assets/plugin/tools/get-market-breadth.js +0 -8
- package/assets/plugin/tools/get-market-intel.d.ts +0 -19
- package/assets/plugin/tools/get-market-intel.js +0 -116
- package/assets/plugin/tools/get-market-structure.d.ts +0 -47
- package/assets/plugin/tools/get-market-structure.js +0 -198
- package/assets/plugin/tools/get-my-mined-patterns.d.ts +0 -20
- package/assets/plugin/tools/get-my-mined-patterns.js +0 -61
- package/assets/plugin/tools/get-my-proposed-learnings.d.ts +0 -20
- package/assets/plugin/tools/get-my-proposed-learnings.js +0 -55
- package/assets/plugin/tools/get-my-recent-reviews.d.ts +0 -22
- package/assets/plugin/tools/get-my-recent-reviews.js +0 -66
- package/assets/plugin/tools/get-orderbook.d.ts +0 -21
- package/assets/plugin/tools/get-orderbook.js +0 -32
- package/assets/plugin/tools/get-pattern-scan.d.ts +0 -7
- package/assets/plugin/tools/get-pattern-scan.js +0 -8
- package/assets/plugin/tools/get-regime.d.ts +0 -6
- package/assets/plugin/tools/get-regime.js +0 -7
- package/assets/plugin/tools/get-relevant-learnings.d.ts +0 -21
- package/assets/plugin/tools/get-relevant-learnings.js +0 -65
- package/assets/plugin/tools/get-resting-liquidity.d.ts +0 -6
- package/assets/plugin/tools/get-resting-liquidity.js +0 -11
- package/assets/plugin/tools/get-risk-scenario.d.ts +0 -29
- package/assets/plugin/tools/get-risk-scenario.js +0 -47
- package/assets/plugin/tools/get-risk-summary.d.ts +0 -51
- package/assets/plugin/tools/get-risk-summary.js +0 -118
- package/assets/plugin/tools/get-sentiment.d.ts +0 -4
- package/assets/plugin/tools/get-sentiment.js +0 -6
- package/assets/plugin/tools/get-session-review.d.ts +0 -7
- package/assets/plugin/tools/get-session-review.js +0 -8
- package/assets/plugin/tools/get-setup-detail.d.ts +0 -7
- package/assets/plugin/tools/get-setup-detail.js +0 -311
- package/assets/plugin/tools/get-signals.d.ts +0 -15
- package/assets/plugin/tools/get-signals.js +0 -54
- package/assets/plugin/tools/get-sizing.d.ts +0 -6
- package/assets/plugin/tools/get-sizing.js +0 -6
- package/assets/plugin/tools/get-trade-feedback.d.ts +0 -7
- package/assets/plugin/tools/get-trade-feedback.js +0 -8
- package/assets/plugin/tools/get-trade-flow.d.ts +0 -7
- package/assets/plugin/tools/get-trade-flow.js +0 -7
- package/assets/plugin/tools/get-volume-analysis.d.ts +0 -21
- package/assets/plugin/tools/get-volume-analysis.js +0 -74
- package/assets/plugin/tools/get-volume-profile.d.ts +0 -7
- package/assets/plugin/tools/get-volume-profile.js +0 -7
- package/assets/plugin/tools/get-wave9-status.d.ts +0 -127
- package/assets/plugin/tools/get-wave9-status.js +0 -796
- package/assets/plugin/tools/helpers.d.ts +0 -26
- package/assets/plugin/tools/helpers.js +0 -39
- package/assets/plugin/tools/intel-api.d.ts +0 -34
- package/assets/plugin/tools/intel-api.js +0 -119
- package/assets/plugin/tools/intel-cache.d.ts +0 -25
- package/assets/plugin/tools/intel-cache.js +0 -148
- package/assets/plugin/tools/list-strategies.d.ts +0 -17
- package/assets/plugin/tools/list-strategies.js +0 -23
- package/assets/plugin/tools/modify-stop.d.ts +0 -21
- package/assets/plugin/tools/modify-stop.js +0 -120
- package/assets/plugin/tools/modify-target.d.ts +0 -21
- package/assets/plugin/tools/modify-target.js +0 -110
- package/assets/plugin/tools/propose-learning.d.ts +0 -22
- package/assets/plugin/tools/propose-learning.js +0 -65
- package/assets/plugin/tools/query-review-outcomes.d.ts +0 -30
- package/assets/plugin/tools/query-review-outcomes.js +0 -64
- package/assets/plugin/tools/query-trades.d.ts +0 -21
- package/assets/plugin/tools/query-trades.js +0 -37
- package/assets/plugin/tools/record-position-reviews.d.ts +0 -38
- package/assets/plugin/tools/record-position-reviews.js +0 -147
- package/assets/plugin/tools/save-strategy.d.ts +0 -16
- package/assets/plugin/tools/save-strategy.js +0 -46
- package/assets/plugin/tools/scan-pairs.d.ts +0 -18
- package/assets/plugin/tools/scan-pairs.js +0 -231
- package/assets/plugin/tools/score-setup.d.ts +0 -31
- package/assets/plugin/tools/score-setup.js +0 -268
- package/assets/plugin/tools/set-bracket-requirement.d.ts +0 -18
- package/assets/plugin/tools/set-bracket-requirement.js +0 -81
- package/assets/plugin/tools/set-exchange-credentials.d.ts +0 -25
- package/assets/plugin/tools/set-exchange-credentials.js +0 -80
- package/assets/plugin/tools/set-trading-mode.d.ts +0 -26
- package/assets/plugin/tools/set-trading-mode.js +0 -135
- package/assets/plugin/tools/test-exchange-credentials.d.ts +0 -16
- package/assets/plugin/tools/test-exchange-credentials.js +0 -100
- package/assets/plugin/tools/toggle-strategy.d.ts +0 -8
- package/assets/plugin/tools/toggle-strategy.js +0 -15
- package/assets/plugin/trading-params-cache.d.ts +0 -26
- package/assets/plugin/trading-params-cache.js +0 -52
- package/assets/plugin/types.d.ts +0 -134
- package/assets/plugin/types.js +0 -7
- package/assets/plugin/util/plugin-paths.d.ts +0 -3
- package/assets/plugin/util/plugin-paths.js +0 -15
- package/assets/plugin/venues/hyperliquid/hl-balance.d.ts +0 -116
- package/assets/plugin/venues/hyperliquid/hl-balance.js +0 -145
- package/assets/plugin/venues/hyperliquid/hl-brackets.d.ts +0 -102
- package/assets/plugin/venues/hyperliquid/hl-brackets.js +0 -172
- package/assets/plugin/venues/hyperliquid/hl-cloid.d.ts +0 -22
- package/assets/plugin/venues/hyperliquid/hl-cloid.js +0 -82
- package/assets/plugin/venues/hyperliquid/hl-info-cache.d.ts +0 -46
- package/assets/plugin/venues/hyperliquid/hl-info-cache.js +0 -125
- package/assets/plugin/venues/hyperliquid/hl-live-adapter.d.ts +0 -88
- package/assets/plugin/venues/hyperliquid/hl-live-adapter.js +0 -353
- package/assets/plugin/venues/hyperliquid/hl-precision.d.ts +0 -61
- package/assets/plugin/venues/hyperliquid/hl-precision.js +0 -176
- package/assets/plugin/venues/hyperliquid/hl-private.d.ts +0 -88
- package/assets/plugin/venues/hyperliquid/hl-private.js +0 -357
- package/assets/plugin/venues/hyperliquid/hl-public.d.ts +0 -79
- package/assets/plugin/venues/hyperliquid/hl-public.js +0 -429
- package/assets/plugin/venues/hyperliquid/hl-rate-gate.d.ts +0 -57
- package/assets/plugin/venues/hyperliquid/hl-rate-gate.js +0 -220
- package/assets/plugin/venues/hyperliquid/hl-user-stream.d.ts +0 -90
- package/assets/plugin/venues/hyperliquid/hl-user-stream.js +0 -220
- package/assets/plugin/venues/registry.d.ts +0 -38
- package/assets/plugin/venues/registry.js +0 -46
- package/assets/plugin/venues/symbols.d.ts +0 -43
- package/assets/plugin/venues/symbols.js +0 -107
- package/assets/plugin/wave9/live-account-capture.d.ts +0 -67
- package/assets/plugin/wave9/live-account-capture.js +0 -435
- package/assets/plugin/wave9/live-autonomous-protection.d.ts +0 -39
- package/assets/plugin/wave9/live-autonomous-protection.js +0 -112
- package/assets/plugin/wave9/live-durable-reconciliation-scheduler.d.ts +0 -33
- package/assets/plugin/wave9/live-durable-reconciliation-scheduler.js +0 -115
- package/assets/plugin/wave9/live-execution-ledger.d.ts +0 -107
- package/assets/plugin/wave9/live-execution-ledger.js +0 -498
- package/assets/plugin/wave9/live-position-confirmation.d.ts +0 -18
- package/assets/plugin/wave9/live-position-confirmation.js +0 -111
- package/assets/plugin/wave9/live-residual-protection.d.ts +0 -18
- package/assets/plugin/wave9/live-residual-protection.js +0 -250
- package/assets/plugin/wave9/live-startup-reconciliation.d.ts +0 -38
- package/assets/plugin/wave9/live-startup-reconciliation.js +0 -454
- package/assets/plugin/wave9/live-symbol-ownership.d.ts +0 -20
- package/assets/plugin/wave9/live-symbol-ownership.js +0 -132
- package/assets/plugin/wave9/paper-admission-guard.d.ts +0 -199
- package/assets/plugin/wave9/paper-admission-guard.js +0 -650
- package/assets/plugin/wave9/usdm-evidence-provider.d.ts +0 -42
- package/assets/plugin/wave9/usdm-evidence-provider.js +0 -133
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
// ⚠️ GENERATED FILE — DO NOT EDIT.
|
|
2
|
-
// Canonical source of truth: shared/src/portfolio/wave9-policy.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
|
-
// Canonical frozen Wave 9 daily signal policy used by the default-off runtime parity
|
|
9
|
-
// observer. This deliberately calls the same generated condition registry and
|
|
10
|
-
// ATR implementation as the intelligence backtest instead of reimplementing
|
|
11
|
-
// momentum semantics in the plugin.
|
|
12
|
-
import { computeATR } from '../shared/indicators.js';
|
|
13
|
-
import { evaluateConditions } from '../signals/conditions/registry.js';
|
|
14
|
-
export const DAY_MS = 24 * 60 * 60 * 1_000;
|
|
15
|
-
export const WAVE9_LOOKBACK_DAYS = 28;
|
|
16
|
-
export const WAVE9_ATR_PERIOD = 14;
|
|
17
|
-
export const WAVE9_ATR_MULTIPLE = 3;
|
|
18
|
-
export const WAVE9_CONTEXT_BARS = 250;
|
|
19
|
-
export const WAVE9_LONG_STRATEGY = 'tsmom_28d_long_flat_reversal_1d';
|
|
20
|
-
export const WAVE9_SHORT_STRATEGY = 'tsmom_28d_short_flat_reversal_1d';
|
|
21
|
-
export const WAVE9_SYMBOL_PRIORITY = [
|
|
22
|
-
'BTCUSDT',
|
|
23
|
-
'ETHUSDT',
|
|
24
|
-
'SOLUSDT',
|
|
25
|
-
'BNBUSDT',
|
|
26
|
-
'XRPUSDT',
|
|
27
|
-
'DOGEUSDT',
|
|
28
|
-
'ADAUSDT',
|
|
29
|
-
'LINKUSDT',
|
|
30
|
-
];
|
|
31
|
-
export const WAVE9_STRATEGY_PRIORITY = [
|
|
32
|
-
WAVE9_LONG_STRATEGY,
|
|
33
|
-
WAVE9_SHORT_STRATEGY,
|
|
34
|
-
];
|
|
35
|
-
function requireFinitePositive(value, label) {
|
|
36
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
37
|
-
throw new Error(`${label} must be a positive finite number`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Return the exact completed-daily context visible at a UTC daily boundary.
|
|
42
|
-
* The function is intentionally fail-closed: unordered, duplicated, gapped,
|
|
43
|
-
* non-UTC, or stale candles are rejected rather than silently repaired.
|
|
44
|
-
*/
|
|
45
|
-
export function completedDailyContext(rawBars, eventTime) {
|
|
46
|
-
const eventMs = eventTime.getTime();
|
|
47
|
-
if (!Number.isFinite(eventMs) || eventMs % DAY_MS !== 0) {
|
|
48
|
-
throw new Error('Wave 9 evaluation time must be a finite UTC daily boundary');
|
|
49
|
-
}
|
|
50
|
-
let previous = Number.NEGATIVE_INFINITY;
|
|
51
|
-
for (const [index, bar] of rawBars.entries()) {
|
|
52
|
-
const time = bar.time.getTime();
|
|
53
|
-
if (!Number.isFinite(time) || time % DAY_MS !== 0) {
|
|
54
|
-
throw new Error(`daily bar ${index} is not aligned to UTC midnight`);
|
|
55
|
-
}
|
|
56
|
-
if (time <= previous) {
|
|
57
|
-
throw new Error('daily bars must be strictly chronological and unique');
|
|
58
|
-
}
|
|
59
|
-
previous = time;
|
|
60
|
-
requireFinitePositive(bar.open, `daily bar ${index} open`);
|
|
61
|
-
requireFinitePositive(bar.high, `daily bar ${index} high`);
|
|
62
|
-
requireFinitePositive(bar.low, `daily bar ${index} low`);
|
|
63
|
-
requireFinitePositive(bar.close, `daily bar ${index} close`);
|
|
64
|
-
if (!Number.isFinite(bar.volume) || bar.volume < 0) {
|
|
65
|
-
throw new Error(`daily bar ${index} volume must be finite and non-negative`);
|
|
66
|
-
}
|
|
67
|
-
if (bar.high < Math.max(bar.open, bar.close) || bar.low > Math.min(bar.open, bar.close)) {
|
|
68
|
-
throw new Error(`daily bar ${index} has invalid OHLC geometry`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const completed = rawBars
|
|
72
|
-
.filter((bar) => bar.time.getTime() + DAY_MS <= eventMs)
|
|
73
|
-
.slice(-WAVE9_CONTEXT_BARS);
|
|
74
|
-
if (completed.length <= WAVE9_LOOKBACK_DAYS + 1) {
|
|
75
|
-
throw new Error(`Wave 9 requires at least ${WAVE9_LOOKBACK_DAYS + 2} completed daily bars`);
|
|
76
|
-
}
|
|
77
|
-
const expectedLastOpen = eventMs - DAY_MS;
|
|
78
|
-
const lastOpen = completed[completed.length - 1].time.getTime();
|
|
79
|
-
if (lastOpen !== expectedLastOpen) {
|
|
80
|
-
throw new Error(`latest completed daily bar must open at ${new Date(expectedLastOpen).toISOString()}`);
|
|
81
|
-
}
|
|
82
|
-
for (let index = 1; index < completed.length; index++) {
|
|
83
|
-
const prior = completed[index - 1].time.getTime();
|
|
84
|
-
const current = completed[index].time.getTime();
|
|
85
|
-
if (current - prior !== DAY_MS) {
|
|
86
|
-
throw new Error(`daily history has a gap between ${completed[index - 1].time.toISOString()} and ${completed[index].time.toISOString()}`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return completed.map((bar) => ({ ...bar, time: new Date(bar.time) }));
|
|
90
|
-
}
|
|
91
|
-
function makeContext(bars, atr14) {
|
|
92
|
-
const latest = bars[bars.length - 1];
|
|
93
|
-
return {
|
|
94
|
-
symbol: 'WAVE9',
|
|
95
|
-
timestamp: new Date(latest.time.getTime() + DAY_MS),
|
|
96
|
-
ohlcv1h: bars,
|
|
97
|
-
ohlcv5m: [],
|
|
98
|
-
ohlcv4h: [],
|
|
99
|
-
ohlcv1d: bars,
|
|
100
|
-
currentPrice: latest.close,
|
|
101
|
-
atr14,
|
|
102
|
-
obImbalance: 0.5,
|
|
103
|
-
fundingRates: [],
|
|
104
|
-
fundingMean: 0,
|
|
105
|
-
fundingStd: 0.0001,
|
|
106
|
-
oiValues: [],
|
|
107
|
-
liqNearEntry: 0,
|
|
108
|
-
tradeFlow: [],
|
|
109
|
-
regime: 'UNKNOWN',
|
|
110
|
-
regimeConfidence: 0,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function conditionMet(context, type, params, direction) {
|
|
114
|
-
const result = evaluateConditions([{ type, params }], context, direction);
|
|
115
|
-
if (result.conditions.length !== 1 || result.conditions[0].name !== type) {
|
|
116
|
-
throw new Error(`canonical condition registry did not evaluate ${type}`);
|
|
117
|
-
}
|
|
118
|
-
return result.conditions[0].met;
|
|
119
|
-
}
|
|
120
|
-
/** Evaluate the exact Wave 9 entry-transition and signal-reversal semantics. */
|
|
121
|
-
export function evaluateWave9Daily(rawBars, eventTime) {
|
|
122
|
-
const bars = completedDailyContext(rawBars, eventTime);
|
|
123
|
-
const highs = bars.map((bar) => bar.high);
|
|
124
|
-
const lows = bars.map((bar) => bar.low);
|
|
125
|
-
const closes = bars.map((bar) => bar.close);
|
|
126
|
-
const atr14 = computeATR(highs, lows, closes, WAVE9_ATR_PERIOD);
|
|
127
|
-
requireFinitePositive(atr14, 'Wave 9 daily ATR(14)');
|
|
128
|
-
const context = makeContext(bars, atr14);
|
|
129
|
-
const currentClose = closes[closes.length - 1];
|
|
130
|
-
const currentPrior = closes[closes.length - 1 - WAVE9_LOOKBACK_DAYS];
|
|
131
|
-
const previousClose = closes[closes.length - 2];
|
|
132
|
-
const previousPrior = closes[closes.length - 2 - WAVE9_LOOKBACK_DAYS];
|
|
133
|
-
const currentReturn = (currentClose - currentPrior) / currentPrior;
|
|
134
|
-
const previousReturn = (previousClose - previousPrior) / previousPrior;
|
|
135
|
-
if (!Number.isFinite(currentReturn) || !Number.isFinite(previousReturn)) {
|
|
136
|
-
throw new Error('Wave 9 momentum inputs are not finite');
|
|
137
|
-
}
|
|
138
|
-
const longEntry = conditionMet(context, 'return_momentum_zero_cross', { tfHours: 24, lookback: WAVE9_LOOKBACK_DAYS, dirSign: 1 }, 'LONG');
|
|
139
|
-
const shortEntry = conditionMet(context, 'return_momentum_zero_cross', { tfHours: 24, lookback: WAVE9_LOOKBACK_DAYS, dirSign: -1 }, 'SHORT');
|
|
140
|
-
const exitLong = conditionMet(context, 'return_momentum', {
|
|
141
|
-
tfHours: 24,
|
|
142
|
-
lookback: WAVE9_LOOKBACK_DAYS,
|
|
143
|
-
minReturnPct: 0,
|
|
144
|
-
maxAbsReturnPct: 0,
|
|
145
|
-
dirSign: -1,
|
|
146
|
-
mode: 1,
|
|
147
|
-
}, 'SHORT');
|
|
148
|
-
const exitShort = conditionMet(context, 'return_momentum', {
|
|
149
|
-
tfHours: 24,
|
|
150
|
-
lookback: WAVE9_LOOKBACK_DAYS,
|
|
151
|
-
minReturnPct: 0,
|
|
152
|
-
maxAbsReturnPct: 0,
|
|
153
|
-
dirSign: 1,
|
|
154
|
-
mode: 1,
|
|
155
|
-
}, 'LONG');
|
|
156
|
-
const entries = [];
|
|
157
|
-
if (longEntry) {
|
|
158
|
-
entries.push({
|
|
159
|
-
strategy: WAVE9_LONG_STRATEGY,
|
|
160
|
-
direction: 'LONG',
|
|
161
|
-
stopPrice: currentClose - atr14 * WAVE9_ATR_MULTIPLE,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
if (shortEntry) {
|
|
165
|
-
entries.push({
|
|
166
|
-
strategy: WAVE9_SHORT_STRATEGY,
|
|
167
|
-
direction: 'SHORT',
|
|
168
|
-
stopPrice: currentClose + atr14 * WAVE9_ATR_MULTIPLE,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
return {
|
|
172
|
-
eventTime: eventTime.toISOString(),
|
|
173
|
-
completedDailyOpen: bars[bars.length - 1].time.toISOString(),
|
|
174
|
-
currentReturn,
|
|
175
|
-
previousReturn,
|
|
176
|
-
atr14,
|
|
177
|
-
referencePrice: currentClose,
|
|
178
|
-
entries,
|
|
179
|
-
exitLong,
|
|
180
|
-
exitShort,
|
|
181
|
-
sourceBarCount: bars.length,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { DrawdownZone, PreTradeRiskLimits, PreTradeResult, ProposedOrder, PortfolioSnapshot, PreTradeOptions } from './pre-trade-types.js';
|
|
2
|
-
export declare function getDefaultPreTradeLimits(): PreTradeRiskLimits;
|
|
3
|
-
/** @deprecated Use getDefaultPreTradeLimits() for dynamic values */
|
|
4
|
-
export declare const DEFAULT_PRE_TRADE_LIMITS: PreTradeRiskLimits;
|
|
5
|
-
export declare function getDrawdownThresholds(): {
|
|
6
|
-
YELLOW: number;
|
|
7
|
-
ORANGE: number;
|
|
8
|
-
RED: number;
|
|
9
|
-
};
|
|
10
|
-
export declare const DRAWDOWN_ZONE_THRESHOLDS: {
|
|
11
|
-
readonly YELLOW: -0.01;
|
|
12
|
-
readonly ORANGE: -0.02;
|
|
13
|
-
readonly RED: -0.025;
|
|
14
|
-
};
|
|
15
|
-
/** Determine drawdown zone from drawdown ratio (e.g. -0.015 = -1.5%). */
|
|
16
|
-
export declare function getDrawdownZone(drawdownRatio: number): DrawdownZone;
|
|
17
|
-
/** Compute volatility factor from current ATR vs baseline. Clamped [0.5, 3.0]. */
|
|
18
|
-
export declare function computeVolFactor(currentAtr: number, baselineAtr: number): number;
|
|
19
|
-
/** Adjust a limit value by volatility factor. Higher vol = tighter limit. */
|
|
20
|
-
export declare function adjustLimitByVol(defaultLimit: number, volFactor: number): number;
|
|
21
|
-
/** Check if an order is closing an existing position (partial or full). */
|
|
22
|
-
export declare function isClosingOrder(order: ProposedOrder, positions: PortfolioSnapshot['positions']): boolean;
|
|
23
|
-
export declare const EQUITY_FLOOR: {
|
|
24
|
-
/** Max single-position notional as a fraction of equity.
|
|
25
|
-
* Raised 0.25 → 0.40 on 2026-04-20 so small live accounts ($186) can fit
|
|
26
|
-
* BTC's ~$75 min-lot. Still protects against all-in entries. Tracked for
|
|
27
|
-
* promotion to operator-configurable trading param in the next session. */
|
|
28
|
-
readonly MAX_POSITION_PCT: 0.4;
|
|
29
|
-
/** Max per-trade risk (expected loss) as a fraction of equity. */
|
|
30
|
-
readonly MAX_PER_TRADE_LOSS_PCT: 0.02;
|
|
31
|
-
/** Presumed adverse move when an order has no explicit stopPrice. */
|
|
32
|
-
readonly NO_STOP_ASSUMED_ADVERSE: 0.05;
|
|
33
|
-
};
|
|
34
|
-
export declare function preTradeRiskCheck(order: ProposedOrder, portfolio: PortfolioSnapshot, limits?: PreTradeRiskLimits, options?: PreTradeOptions): PreTradeResult;
|
|
35
|
-
/** Count consecutive losses from the end of a trade history array. */
|
|
36
|
-
export declare function computeConsecutiveLosses(trades: Array<{
|
|
37
|
-
realizedPnl: number;
|
|
38
|
-
}>): number;
|
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
// Pre-trade risk gate — pure function.
|
|
2
|
-
// Validates a proposed order against portfolio limits, drawdown zones, and volatility.
|
|
3
|
-
// Lives in the plugin (synchronous access to simulator state).
|
|
4
|
-
import { getCachedTradingParams } from '../trading-params-cache.js';
|
|
5
|
-
// ---- Default pre-trade limits (now read from trading params cache) ----
|
|
6
|
-
export function getDefaultPreTradeLimits() {
|
|
7
|
-
const tp = getCachedTradingParams();
|
|
8
|
-
return {
|
|
9
|
-
maxPositionSize: tp.maxPositionSize,
|
|
10
|
-
maxOpenPositions: tp.maxOpenPositions,
|
|
11
|
-
maxGrossExposure: tp.maxGrossExposure,
|
|
12
|
-
maxPerTradeLoss: tp.maxPerTradeLoss,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/** @deprecated Use getDefaultPreTradeLimits() for dynamic values */
|
|
16
|
-
export const DEFAULT_PRE_TRADE_LIMITS = {
|
|
17
|
-
maxPositionSize: 10_000,
|
|
18
|
-
maxOpenPositions: 5,
|
|
19
|
-
maxGrossExposure: 1.5,
|
|
20
|
-
maxPerTradeLoss: 500,
|
|
21
|
-
};
|
|
22
|
-
// ---- Drawdown zone thresholds (now read from trading params cache) ----
|
|
23
|
-
export function getDrawdownThresholds() {
|
|
24
|
-
const tp = getCachedTradingParams();
|
|
25
|
-
return {
|
|
26
|
-
YELLOW: tp.drawdownYellow,
|
|
27
|
-
ORANGE: tp.drawdownOrange,
|
|
28
|
-
RED: tp.drawdownRed,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
export const DRAWDOWN_ZONE_THRESHOLDS = {
|
|
32
|
-
YELLOW: -0.01, // -1%
|
|
33
|
-
ORANGE: -0.02, // -2%
|
|
34
|
-
RED: -0.025, // -2.5%
|
|
35
|
-
};
|
|
36
|
-
// ---- Pure helpers ----
|
|
37
|
-
/** Determine drawdown zone from drawdown ratio (e.g. -0.015 = -1.5%). */
|
|
38
|
-
export function getDrawdownZone(drawdownRatio) {
|
|
39
|
-
const thresholds = getDrawdownThresholds();
|
|
40
|
-
if (drawdownRatio <= thresholds.RED)
|
|
41
|
-
return 'RED';
|
|
42
|
-
if (drawdownRatio <= thresholds.ORANGE)
|
|
43
|
-
return 'ORANGE';
|
|
44
|
-
if (drawdownRatio <= thresholds.YELLOW)
|
|
45
|
-
return 'YELLOW';
|
|
46
|
-
return 'GREEN';
|
|
47
|
-
}
|
|
48
|
-
/** Compute volatility factor from current ATR vs baseline. Clamped [0.5, 3.0]. */
|
|
49
|
-
export function computeVolFactor(currentAtr, baselineAtr) {
|
|
50
|
-
if (baselineAtr <= 0 || currentAtr <= 0)
|
|
51
|
-
return 1.0;
|
|
52
|
-
return Math.max(0.5, Math.min(3.0, currentAtr / baselineAtr));
|
|
53
|
-
}
|
|
54
|
-
/** Adjust a limit value by volatility factor. Higher vol = tighter limit. */
|
|
55
|
-
export function adjustLimitByVol(defaultLimit, volFactor) {
|
|
56
|
-
if (volFactor <= 1.0)
|
|
57
|
-
return defaultLimit;
|
|
58
|
-
return defaultLimit / volFactor;
|
|
59
|
-
}
|
|
60
|
-
/** Check if an order is closing an existing position (partial or full). */
|
|
61
|
-
export function isClosingOrder(order, positions) {
|
|
62
|
-
const pos = positions.find(p => p.symbol === order.symbol);
|
|
63
|
-
if (!pos)
|
|
64
|
-
return false;
|
|
65
|
-
// Sell against a long = closing; buy against a short = closing
|
|
66
|
-
return (pos.side === 'long' && order.side === 'sell') ||
|
|
67
|
-
(pos.side === 'short' && order.side === 'buy');
|
|
68
|
-
}
|
|
69
|
-
// ---- Main pre-trade gate ----
|
|
70
|
-
// ---- Equity-proportional floors (safety net for tiny accounts) ----
|
|
71
|
-
// These are independent of the configurable trading params and exist so that
|
|
72
|
-
// a $10,000 static `maxPositionSize` default can't allow a $289 account to
|
|
73
|
-
// open an $8,000 position. They shrink the effective caps relative to current
|
|
74
|
-
// equity; the tighter of (absolute limit, equity-proportional floor) wins.
|
|
75
|
-
export const EQUITY_FLOOR = {
|
|
76
|
-
/** Max single-position notional as a fraction of equity.
|
|
77
|
-
* Raised 0.25 → 0.40 on 2026-04-20 so small live accounts ($186) can fit
|
|
78
|
-
* BTC's ~$75 min-lot. Still protects against all-in entries. Tracked for
|
|
79
|
-
* promotion to operator-configurable trading param in the next session. */
|
|
80
|
-
MAX_POSITION_PCT: 0.40,
|
|
81
|
-
/** Max per-trade risk (expected loss) as a fraction of equity. */
|
|
82
|
-
MAX_PER_TRADE_LOSS_PCT: 0.02,
|
|
83
|
-
/** Presumed adverse move when an order has no explicit stopPrice. */
|
|
84
|
-
NO_STOP_ASSUMED_ADVERSE: 0.05,
|
|
85
|
-
};
|
|
86
|
-
export function preTradeRiskCheck(order, portfolio, limits = DEFAULT_PRE_TRADE_LIMITS, options = {}) {
|
|
87
|
-
const violations = [];
|
|
88
|
-
const volFactor = options.volFactor ?? 1.0;
|
|
89
|
-
// Caller-provided equity is authoritative; fall back to local compute for
|
|
90
|
-
// legacy test callers that don't supply it.
|
|
91
|
-
const currentEquity = portfolio.equity ?? computePortfolioEquity(portfolio);
|
|
92
|
-
// Drawdown anchor: prefer sessionStartNav, fall back to current equity.
|
|
93
|
-
const nav = portfolio.sessionStartNav > 0 ? portfolio.sessionStartNav : currentEquity;
|
|
94
|
-
const drawdownRatio = nav > 0 ? (currentEquity - nav) / nav : 0;
|
|
95
|
-
const zone = getDrawdownZone(drawdownRatio);
|
|
96
|
-
// Classify the order against any same-symbol position BEFORE the zone gates:
|
|
97
|
-
// - pure reduce / full close → "closing": exempt from entry gates (exits
|
|
98
|
-
// must always work, even in RED/ORANGE).
|
|
99
|
-
// - flip (over-close) → closes the old leg AND opens a NEW opposite
|
|
100
|
-
// leg; the NEW leg must clear every entry gate (drawdown zone, size,
|
|
101
|
-
// gross, per-trade-loss, bracket requirement). Previously a flip took the
|
|
102
|
-
// exit exemption and opened unchecked, possibly oversized, stop-less
|
|
103
|
-
// exposure — even in the RED zone (M6).
|
|
104
|
-
// - same-direction add (scale-in) / fresh entry → full entry checks (M5).
|
|
105
|
-
// Emergency flatten bypasses this function entirely (EmergencyControls → adapter.createOrder).
|
|
106
|
-
const closingPos = portfolio.positions.find(p => p.symbol === order.symbol &&
|
|
107
|
-
((p.side === 'long' && order.side === 'sell') || (p.side === 'short' && order.side === 'buy')));
|
|
108
|
-
const flipAmount = closingPos ? order.amount - closingPos.quantity : 0;
|
|
109
|
-
const isFlip = closingPos != null && flipAmount > 1e-9 * Math.max(closingPos.quantity, 1);
|
|
110
|
-
const closing = closingPos != null && !isFlip; // reduce/close, opens no new exposure
|
|
111
|
-
// The leg that opens new exposure and must clear the entry gates. For a flip
|
|
112
|
-
// it's ONLY the excess beyond the closed position; otherwise the whole order.
|
|
113
|
-
// stopPrice/targetPrice carry over so the per-trade-loss and live
|
|
114
|
-
// bracket-requirement gates evaluate against the new leg's real stop.
|
|
115
|
-
const entryOrder = isFlip ? { ...order, amount: flipAmount } : order;
|
|
116
|
-
// Bracket requirement gates — only apply to entries (not closes) when the
|
|
117
|
-
// caller explicitly passes `bracketEnforcement`. Closes are exempt so
|
|
118
|
-
// operators can always exit, even if the entry broke the policy.
|
|
119
|
-
if (!closing && options.bracketEnforcement) {
|
|
120
|
-
const { requireStopLoss, requireTakeProfit } = options.bracketEnforcement;
|
|
121
|
-
if (requireStopLoss && (order.stopPrice === undefined || !(order.stopPrice > 0))) {
|
|
122
|
-
violations.push({
|
|
123
|
-
rule: 'requireStopLoss',
|
|
124
|
-
message: 'Live trades require a stopPrice. Disable requireStopLoss in Trading Parameters to override (not recommended).',
|
|
125
|
-
current: 0,
|
|
126
|
-
limit: 1,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
if (requireTakeProfit && (order.targetPrice === undefined || !(order.targetPrice > 0))) {
|
|
130
|
-
violations.push({
|
|
131
|
-
rule: 'requireTakeProfit',
|
|
132
|
-
message: 'Live trades require a target_price. Disable requireTakeProfit in Trading Parameters to override.',
|
|
133
|
-
current: 0,
|
|
134
|
-
limit: 1,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
if (violations.length > 0) {
|
|
138
|
-
return {
|
|
139
|
-
allowed: false,
|
|
140
|
-
violations,
|
|
141
|
-
drawdownZone: zone,
|
|
142
|
-
effectiveMaxPositionSize: 0,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// Exits are always allowed regardless of drawdown zone
|
|
147
|
-
if (closing) {
|
|
148
|
-
const effectiveMax = computeEffectivePositionSize(limits.maxPositionSize, volFactor, zone);
|
|
149
|
-
return {
|
|
150
|
-
allowed: true,
|
|
151
|
-
violations: [],
|
|
152
|
-
drawdownZone: zone,
|
|
153
|
-
effectiveMaxPositionSize: effectiveMax,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
// RED zone: reject new entries (exits already handled above)
|
|
157
|
-
if (zone === 'RED') {
|
|
158
|
-
violations.push({
|
|
159
|
-
rule: 'drawdownZone',
|
|
160
|
-
message: `RED zone (${(drawdownRatio * 100).toFixed(2)}% drawdown) — new entries rejected`,
|
|
161
|
-
current: drawdownRatio,
|
|
162
|
-
limit: DRAWDOWN_ZONE_THRESHOLDS.RED,
|
|
163
|
-
});
|
|
164
|
-
return {
|
|
165
|
-
allowed: false,
|
|
166
|
-
violations,
|
|
167
|
-
drawdownZone: zone,
|
|
168
|
-
effectiveMaxPositionSize: 0,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
// ORANGE zone: only exits allowed (already handled above)
|
|
172
|
-
if (zone === 'ORANGE') {
|
|
173
|
-
violations.push({
|
|
174
|
-
rule: 'drawdownZone',
|
|
175
|
-
message: `ORANGE zone (${(drawdownRatio * 100).toFixed(2)}% drawdown) — new entries blocked, exits only`,
|
|
176
|
-
current: drawdownRatio,
|
|
177
|
-
limit: DRAWDOWN_ZONE_THRESHOLDS.ORANGE,
|
|
178
|
-
});
|
|
179
|
-
return {
|
|
180
|
-
allowed: false,
|
|
181
|
-
violations,
|
|
182
|
-
drawdownZone: zone,
|
|
183
|
-
effectiveMaxPositionSize: 0,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
// ---- Entry checks (GREEN/YELLOW) ----
|
|
187
|
-
const streak = options.consecutiveLosses ?? 0;
|
|
188
|
-
const tp = getCachedTradingParams();
|
|
189
|
-
// Equity-proportional floor — shrinks the static cap on small accounts.
|
|
190
|
-
// A $10k default `maxPositionSize` is useless on a $289 account; cap to
|
|
191
|
-
// `EQUITY_FLOOR.MAX_POSITION_PCT` of current equity. The tighter of the two wins.
|
|
192
|
-
const equityPositionCap = currentEquity > 0
|
|
193
|
-
? currentEquity * EQUITY_FLOOR.MAX_POSITION_PCT
|
|
194
|
-
: limits.maxPositionSize;
|
|
195
|
-
const scaledMaxPositionSize = Math.min(limits.maxPositionSize, equityPositionCap);
|
|
196
|
-
let effectiveMaxPositionSize = computeEffectivePositionSize(scaledMaxPositionSize, volFactor, zone);
|
|
197
|
-
// Graduated size reduction on loss streaks (never a hard block — that creates deadlocks)
|
|
198
|
-
// Ensure correct ordering: the harsher reduction (0.25x) needs the higher threshold
|
|
199
|
-
const quarterThreshold = Math.max(tp.lossStreakQuarterSize, tp.lossStreakHalfSize);
|
|
200
|
-
const halfThreshold = Math.min(tp.lossStreakQuarterSize, tp.lossStreakHalfSize);
|
|
201
|
-
if (streak >= quarterThreshold) {
|
|
202
|
-
effectiveMaxPositionSize *= 0.25;
|
|
203
|
-
}
|
|
204
|
-
else if (streak >= halfThreshold) {
|
|
205
|
-
effectiveMaxPositionSize *= 0.5;
|
|
206
|
-
}
|
|
207
|
-
// 1. Position size check — against the RESULTING position notional, not just
|
|
208
|
-
// this order's increment. A same-direction scale-in must include the
|
|
209
|
-
// existing leg, or repeated small adds each pass individually yet build a
|
|
210
|
-
// position far beyond the per-symbol cap (M5). A flip's resulting position
|
|
211
|
-
// is only the new opposite leg (the old leg is closed), so the existing
|
|
212
|
-
// notional is NOT added there.
|
|
213
|
-
const entryNotional = entryOrder.amount * order.price;
|
|
214
|
-
const sameSymbolPos = portfolio.positions.find(p => p.symbol === order.symbol);
|
|
215
|
-
const isScaleIn = sameSymbolPos != null &&
|
|
216
|
-
((sameSymbolPos.side === 'long' && order.side === 'buy') ||
|
|
217
|
-
(sameSymbolPos.side === 'short' && order.side === 'sell'));
|
|
218
|
-
const existingNotional = isScaleIn && sameSymbolPos
|
|
219
|
-
? sameSymbolPos.quantity * (sameSymbolPos.markPrice ?? sameSymbolPos.entryPrice)
|
|
220
|
-
: 0;
|
|
221
|
-
const resultingNotional = existingNotional + entryNotional;
|
|
222
|
-
if (resultingNotional > effectiveMaxPositionSize) {
|
|
223
|
-
violations.push({
|
|
224
|
-
rule: 'positionSize',
|
|
225
|
-
message: `Resulting position notional $${resultingNotional.toFixed(2)} (existing $${existingNotional.toFixed(2)} + order $${entryNotional.toFixed(2)}) exceeds effective max $${effectiveMaxPositionSize.toFixed(2)} (equity $${currentEquity.toFixed(2)}, cap ${(EQUITY_FLOOR.MAX_POSITION_PCT * 100).toFixed(0)}% of equity)`,
|
|
226
|
-
current: resultingNotional,
|
|
227
|
-
limit: effectiveMaxPositionSize,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
// 2. Open positions count (would a new symbol exceed limit?)
|
|
231
|
-
const existingSymbols = new Set(portfolio.positions.map(p => p.symbol));
|
|
232
|
-
if (!existingSymbols.has(order.symbol)) {
|
|
233
|
-
const newCount = existingSymbols.size + 1;
|
|
234
|
-
if (newCount > limits.maxOpenPositions) {
|
|
235
|
-
violations.push({
|
|
236
|
-
rule: 'openPositions',
|
|
237
|
-
message: `New position would bring count to ${newCount}, max is ${limits.maxOpenPositions}`,
|
|
238
|
-
current: newCount,
|
|
239
|
-
limit: limits.maxOpenPositions,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
// 3. Projected gross exposure. On a flip the closed leg leaves the book, so
|
|
244
|
-
// net it out — otherwise the projection double-counts the position we close.
|
|
245
|
-
if (nav > 0) {
|
|
246
|
-
const currentGross = computeGrossExposure(portfolio);
|
|
247
|
-
const closedLegNotional = isFlip && closingPos
|
|
248
|
-
? closingPos.quantity * (closingPos.markPrice ?? closingPos.entryPrice)
|
|
249
|
-
: 0;
|
|
250
|
-
const projectedGross = currentGross - closedLegNotional + entryNotional;
|
|
251
|
-
const projectedRatio = projectedGross / nav;
|
|
252
|
-
const effectiveMaxGross = adjustLimitByVol(limits.maxGrossExposure, volFactor);
|
|
253
|
-
if (projectedRatio > effectiveMaxGross) {
|
|
254
|
-
violations.push({
|
|
255
|
-
rule: 'grossExposure',
|
|
256
|
-
message: `Projected gross exposure ${projectedRatio.toFixed(2)}x exceeds limit ${effectiveMaxGross.toFixed(2)}x`,
|
|
257
|
-
current: projectedRatio,
|
|
258
|
-
limit: effectiveMaxGross,
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
// 4. Per-trade loss check — MANDATORY (was previously opt-in on stopPrice).
|
|
263
|
-
// Without a stop, we presume a 5% adverse move as the worst-case loss. This
|
|
264
|
-
// prevents the gate from waving through stopless entries on thin accounts.
|
|
265
|
-
if (!closing) {
|
|
266
|
-
// Use the opening leg's amount/notional (the flip's new leg, or the whole
|
|
267
|
-
// order for a fresh entry/scale-in) so the flip's new exposure is gated.
|
|
268
|
-
const expectedLoss = order.stopPrice != null
|
|
269
|
-
? Math.abs(order.price - order.stopPrice) * entryOrder.amount
|
|
270
|
-
: entryNotional * EQUITY_FLOOR.NO_STOP_ASSUMED_ADVERSE;
|
|
271
|
-
const equityLossCap = currentEquity > 0
|
|
272
|
-
? currentEquity * EQUITY_FLOOR.MAX_PER_TRADE_LOSS_PCT
|
|
273
|
-
: limits.maxPerTradeLoss;
|
|
274
|
-
const scaledPerTradeLoss = Math.min(limits.maxPerTradeLoss, equityLossCap);
|
|
275
|
-
if (expectedLoss > scaledPerTradeLoss) {
|
|
276
|
-
const stopNote = order.stopPrice != null
|
|
277
|
-
? `stop @ ${order.stopPrice}`
|
|
278
|
-
: `no stop — assumed ${(EQUITY_FLOOR.NO_STOP_ASSUMED_ADVERSE * 100).toFixed(0)}% adverse move`;
|
|
279
|
-
violations.push({
|
|
280
|
-
rule: 'perTradeLoss',
|
|
281
|
-
message: `Expected loss $${expectedLoss.toFixed(2)} (${stopNote}) exceeds per-trade limit $${scaledPerTradeLoss.toFixed(2)} (${(EQUITY_FLOOR.MAX_PER_TRADE_LOSS_PCT * 100).toFixed(0)}% of equity $${currentEquity.toFixed(2)})`,
|
|
282
|
-
current: expectedLoss,
|
|
283
|
-
limit: scaledPerTradeLoss,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return {
|
|
288
|
-
allowed: violations.length === 0,
|
|
289
|
-
violations,
|
|
290
|
-
drawdownZone: zone,
|
|
291
|
-
effectiveMaxPositionSize,
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
// ---- Exported helpers ----
|
|
295
|
-
/** Count consecutive losses from the end of a trade history array. */
|
|
296
|
-
export function computeConsecutiveLosses(trades) {
|
|
297
|
-
let streak = 0;
|
|
298
|
-
for (let i = trades.length - 1; i >= 0; i--) {
|
|
299
|
-
if (trades[i].realizedPnl < 0) {
|
|
300
|
-
streak++;
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
break;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return streak;
|
|
307
|
-
}
|
|
308
|
-
// ---- Internal helpers ----
|
|
309
|
-
function computeEffectivePositionSize(baseMax, volFactor, zone) {
|
|
310
|
-
let effective = adjustLimitByVol(baseMax, volFactor);
|
|
311
|
-
if (zone === 'YELLOW') {
|
|
312
|
-
effective *= 0.5; // YELLOW halves position sizes
|
|
313
|
-
}
|
|
314
|
-
return effective;
|
|
315
|
-
}
|
|
316
|
-
function computePortfolioEquity(portfolio) {
|
|
317
|
-
let equity = portfolio.walletTotal;
|
|
318
|
-
for (const pos of portfolio.positions) {
|
|
319
|
-
const mark = pos.markPrice ?? pos.entryPrice;
|
|
320
|
-
const pnl = pos.side === 'long'
|
|
321
|
-
? (mark - pos.entryPrice) * pos.quantity
|
|
322
|
-
: (pos.entryPrice - mark) * pos.quantity;
|
|
323
|
-
if (portfolio.isLive) {
|
|
324
|
-
// Live Binance: wallet already includes margin — add only unrealized P&L.
|
|
325
|
-
equity += pnl;
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
// Paper simulator (SPOT-collateral model): the full entry notional was
|
|
329
|
-
// deducted from wallet at open and is released on close, so we must add
|
|
330
|
-
// it back here. Same formula for longs and shorts — the previous
|
|
331
|
-
// `-qty*mark` short branch was arithmetically wrong and underrepresented
|
|
332
|
-
// equity by 2*entry*qty whenever the account held a short.
|
|
333
|
-
equity += pos.entryPrice * pos.quantity + pnl;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
return equity;
|
|
337
|
-
}
|
|
338
|
-
function computeGrossExposure(portfolio) {
|
|
339
|
-
let gross = 0;
|
|
340
|
-
for (const pos of portfolio.positions) {
|
|
341
|
-
const price = pos.markPrice ?? pos.entryPrice;
|
|
342
|
-
gross += Math.abs(pos.quantity * price);
|
|
343
|
-
}
|
|
344
|
-
return gross;
|
|
345
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export type DrawdownZone = 'GREEN' | 'YELLOW' | 'ORANGE' | 'RED';
|
|
2
|
-
export interface PreTradeRiskLimits {
|
|
3
|
-
maxPositionSize: number;
|
|
4
|
-
maxOpenPositions: number;
|
|
5
|
-
maxGrossExposure: number;
|
|
6
|
-
maxPerTradeLoss: number;
|
|
7
|
-
}
|
|
8
|
-
export interface ProposedOrder {
|
|
9
|
-
symbol: string;
|
|
10
|
-
side: 'buy' | 'sell';
|
|
11
|
-
type: 'market' | 'limit';
|
|
12
|
-
amount: number;
|
|
13
|
-
price: number;
|
|
14
|
-
stopPrice?: number;
|
|
15
|
-
targetPrice?: number;
|
|
16
|
-
}
|
|
17
|
-
export interface PortfolioSnapshot {
|
|
18
|
-
positions: Array<{
|
|
19
|
-
symbol: string;
|
|
20
|
-
side: 'long' | 'short';
|
|
21
|
-
quantity: number;
|
|
22
|
-
entryPrice: number;
|
|
23
|
-
markPrice?: number;
|
|
24
|
-
}>;
|
|
25
|
-
walletTotal: number;
|
|
26
|
-
walletAvailable: number;
|
|
27
|
-
sessionStartNav: number;
|
|
28
|
-
/** Mark-to-market total account value. If provided, takes precedence over
|
|
29
|
-
* the gate's own equity computation — the caller's value is authoritative
|
|
30
|
-
* because it has access to the real simulator/exchange state. When absent
|
|
31
|
-
* (legacy test callers), the gate falls back to an internal computation. */
|
|
32
|
-
equity?: number;
|
|
33
|
-
/** Paper simulator deducts notional from wallet at entry — equity = wallet + position value.
|
|
34
|
-
* Live Binance wallet already includes margin — equity = wallet + unrealized PnL only. */
|
|
35
|
-
isLive?: boolean;
|
|
36
|
-
}
|
|
37
|
-
export interface PreTradeViolation {
|
|
38
|
-
rule: string;
|
|
39
|
-
message: string;
|
|
40
|
-
current: number;
|
|
41
|
-
limit: number;
|
|
42
|
-
}
|
|
43
|
-
export interface PreTradeResult {
|
|
44
|
-
allowed: boolean;
|
|
45
|
-
violations: PreTradeViolation[];
|
|
46
|
-
drawdownZone: DrawdownZone;
|
|
47
|
-
effectiveMaxPositionSize: number;
|
|
48
|
-
}
|
|
49
|
-
export interface PreTradeOptions {
|
|
50
|
-
volFactor?: number;
|
|
51
|
-
consecutiveLosses?: number;
|
|
52
|
-
/** When true, the gate rejects entries without a stopPrice and/or targetPrice
|
|
53
|
-
* based on the flags below. Only meaningful in live mode with bracket orders
|
|
54
|
-
* enabled — in paper/off mode the stop-watcher handles protection and these
|
|
55
|
-
* flags don't apply (gate ignores them). */
|
|
56
|
-
bracketEnforcement?: {
|
|
57
|
-
requireStopLoss: boolean;
|
|
58
|
-
requireTakeProfit: boolean;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|