@reefclaw/openclaw-plugin 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/.gitignore +8 -0
- package/audit/mode-transition-audit.d.ts +11 -0
- package/audit/mode-transition-audit.js +29 -0
- package/balance-utils.d.ts +36 -0
- package/balance-utils.js +98 -0
- package/bridge/bridge.d.ts +109 -0
- package/bridge/bridge.js +1036 -0
- package/bridge/config.d.ts +43 -0
- package/bridge/config.js +176 -0
- package/bridge/connector.d.ts +52 -0
- package/bridge/connector.js +293 -0
- package/bridge/event-replay-buffer.d.ts +43 -0
- package/bridge/event-replay-buffer.js +109 -0
- package/bridge/gateway/event-parser.d.ts +209 -0
- package/bridge/gateway/event-parser.js +793 -0
- package/bridge/gateway/gateway-config.d.ts +39 -0
- package/bridge/gateway/gateway-config.js +86 -0
- package/bridge/gateway/gateway-http-client.d.ts +50 -0
- package/bridge/gateway/gateway-http-client.js +165 -0
- package/bridge/gateway/gateway-ws-client.d.ts +116 -0
- package/bridge/gateway/gateway-ws-client.js +417 -0
- package/bridge/gateway/poller.d.ts +146 -0
- package/bridge/gateway/poller.js +505 -0
- package/bridge/gateway/tool-discovery.d.ts +25 -0
- package/bridge/gateway/tool-discovery.js +198 -0
- package/bridge/index.d.ts +2 -0
- package/bridge/index.js +253 -0
- package/bridge/logger.d.ts +2 -0
- package/bridge/logger.js +2 -0
- package/bridge/provider.d.ts +156 -0
- package/bridge/provider.js +2 -0
- package/bridge/providers/emergency-commands.d.ts +54 -0
- package/bridge/providers/emergency-commands.js +235 -0
- package/bridge/providers/gateway.d.ts +322 -0
- package/bridge/providers/gateway.js +2302 -0
- package/bridge/providers/mock.d.ts +37 -0
- package/bridge/providers/mock.js +385 -0
- package/bridge/providers/onboarding-commands.d.ts +83 -0
- package/bridge/providers/onboarding-commands.js +213 -0
- package/bridge/providers/risk-calculator.d.ts +96 -0
- package/bridge/providers/risk-calculator.js +369 -0
- package/bridge/setup.d.ts +32 -0
- package/bridge/setup.js +226 -0
- package/bridge/types.d.ts +584 -0
- package/bridge/types.js +50 -0
- package/bridge/utils/reconnect.d.ts +6 -0
- package/bridge/utils/reconnect.js +6 -0
- package/bridge/utils/skill-signing.d.ts +51 -0
- package/bridge/utils/skill-signing.js +138 -0
- package/bridge/utils/skill-version.d.ts +17 -0
- package/bridge/utils/skill-version.js +74 -0
- package/ccxt/binance-ban-gate.d.ts +47 -0
- package/ccxt/binance-ban-gate.js +409 -0
- package/ccxt/binance-private.d.ts +325 -0
- package/ccxt/binance-private.js +1415 -0
- package/ccxt/binance-public.d.ts +18 -0
- package/ccxt/binance-public.js +147 -0
- package/config/agent-config-client.d.ts +55 -0
- package/config/agent-config-client.js +145 -0
- package/config/agent-config-poller.d.ts +25 -0
- package/config/agent-config-poller.js +100 -0
- package/config/brackets-config.d.ts +22 -0
- package/config/brackets-config.js +58 -0
- package/config/gate-store.d.ts +18 -0
- package/config/gate-store.js +61 -0
- package/config/plugin-config-io.d.ts +181 -0
- package/config/plugin-config-io.js +84 -0
- package/config/position-review-config.d.ts +35 -0
- package/config/position-review-config.js +105 -0
- package/config/tool-gate.d.ts +53 -0
- package/config/tool-gate.js +125 -0
- package/config/user-data-stream-config.d.ts +85 -0
- package/config/user-data-stream-config.js +224 -0
- package/connector-supervisor.d.ts +36 -0
- package/connector-supervisor.js +149 -0
- package/exchange-adapter.d.ts +49 -0
- package/exchange-adapter.js +4 -0
- package/index.d.ts +30 -0
- package/index.js +2030 -0
- package/ingest/pending-entry-metadata.d.ts +52 -0
- package/ingest/pending-entry-metadata.js +182 -0
- package/ingest/position-auto-capture.d.ts +98 -0
- package/ingest/position-auto-capture.js +394 -0
- package/ingest/position-decisions-client.d.ts +318 -0
- package/ingest/position-decisions-client.js +296 -0
- package/ingest/reconcile-db-vs-exchange.d.ts +13 -0
- package/ingest/reconcile-db-vs-exchange.js +114 -0
- package/ingest/reconciler-cleanup.d.ts +37 -0
- package/ingest/reconciler-cleanup.js +147 -0
- package/ingest/rest-gap-filler.d.ts +191 -0
- package/ingest/rest-gap-filler.js +565 -0
- package/ingest/touched-symbols-store.d.ts +25 -0
- package/ingest/touched-symbols-store.js +96 -0
- package/ingest/trade-store-client.d.ts +40 -0
- package/ingest/trade-store-client.js +125 -0
- package/ingest/ws-ingest.d.ts +43 -0
- package/ingest/ws-ingest.js +126 -0
- package/learning/setup-family.d.ts +21 -0
- package/learning/setup-family.js +103 -0
- package/lifecycle/install-signal-handlers.d.ts +33 -0
- package/lifecycle/install-signal-handlers.js +112 -0
- package/lifecycle/shutdown-coordinator.d.ts +43 -0
- package/lifecycle/shutdown-coordinator.js +131 -0
- package/live/bracket-id.d.ts +18 -0
- package/live/bracket-id.js +81 -0
- package/live/bracket-ledger.d.ts +54 -0
- package/live/bracket-ledger.js +267 -0
- package/live/bracket-manager.d.ts +82 -0
- package/live/bracket-manager.js +478 -0
- package/live/bracket-params.d.ts +22 -0
- package/live/bracket-params.js +124 -0
- package/live/bracket-reconciler.d.ts +95 -0
- package/live/bracket-reconciler.js +573 -0
- package/live/bracket-types.d.ts +102 -0
- package/live/bracket-types.js +8 -0
- package/live/deposit-tracker.d.ts +62 -0
- package/live/deposit-tracker.js +97 -0
- package/live/emergency-controls.d.ts +32 -0
- package/live/emergency-controls.js +226 -0
- package/live/exchange-errors.d.ts +12 -0
- package/live/exchange-errors.js +130 -0
- package/live/exchange-info-cache.d.ts +35 -0
- package/live/exchange-info-cache.js +119 -0
- package/live/fact-subscriber.d.ts +78 -0
- package/live/fact-subscriber.js +182 -0
- package/live/intent-journal.d.ts +42 -0
- package/live/intent-journal.js +122 -0
- package/live/listen-key-manager.d.ts +70 -0
- package/live/listen-key-manager.js +169 -0
- package/live/live-adapter.d.ts +264 -0
- package/live/live-adapter.js +1665 -0
- package/live/live-balance-enricher.d.ts +32 -0
- package/live/live-balance-enricher.js +104 -0
- package/live/live-bracket-api.d.ts +13 -0
- package/live/live-bracket-api.js +20 -0
- package/live/live-state-store.d.ts +194 -0
- package/live/live-state-store.js +450 -0
- package/live/local-signal-service.d.ts +57 -0
- package/live/local-signal-service.js +146 -0
- package/live/local-strategy-evaluator.d.ts +62 -0
- package/live/local-strategy-evaluator.js +127 -0
- package/live/microstructure-assembler.d.ts +54 -0
- package/live/microstructure-assembler.js +148 -0
- package/live/order-poller.d.ts +29 -0
- package/live/order-poller.js +125 -0
- package/live/position-state-store.d.ts +83 -0
- package/live/position-state-store.js +237 -0
- package/live/proposal-decision-listener.d.ts +64 -0
- package/live/proposal-decision-listener.js +288 -0
- package/live/proposal-manager.d.ts +76 -0
- package/live/proposal-manager.js +140 -0
- package/live/rate-limiter.d.ts +47 -0
- package/live/rate-limiter.js +159 -0
- package/live/reconciler.d.ts +39 -0
- package/live/reconciler.js +175 -0
- package/live/setup-buckets.d.ts +7 -0
- package/live/setup-buckets.js +33 -0
- package/live/slippage-tracker.d.ts +45 -0
- package/live/slippage-tracker.js +78 -0
- package/live/stop-watcher.d.ts +34 -0
- package/live/stop-watcher.js +158 -0
- package/live/user-data-active-probe.d.ts +54 -0
- package/live/user-data-active-probe.js +180 -0
- package/live/user-data-stream-controller.d.ts +200 -0
- package/live/user-data-stream-controller.js +579 -0
- package/live/user-data-stream-ws.d.ts +22 -0
- package/live/user-data-stream-ws.js +63 -0
- package/live/user-data-stream.d.ts +243 -0
- package/live/user-data-stream.js +704 -0
- package/logger.d.ts +2 -0
- package/logger.js +2 -0
- package/mfe.d.ts +21 -0
- package/mfe.js +68 -0
- package/onboarding/mode-ladder.d.ts +1 -0
- package/onboarding/mode-ladder.js +3 -0
- package/onboarding/runtime.d.ts +71 -0
- package/onboarding/runtime.js +153 -0
- package/openclaw.plugin.json +94 -0
- package/package.json +27 -0
- package/paper-adapter.d.ts +24 -0
- package/paper-adapter.js +91 -0
- package/persistence/state-manager.d.ts +42 -0
- package/persistence/state-manager.js +164 -0
- package/pinned-plan.d.ts +9 -0
- package/pinned-plan.js +23 -0
- package/risk/pre-trade-check.d.ts +38 -0
- package/risk/pre-trade-check.js +345 -0
- package/risk/pre-trade-types.d.ts +60 -0
- package/risk/pre-trade-types.js +3 -0
- package/scripts/assemble.mjs +114 -0
- package/shadow/shadow-tracker.d.ts +36 -0
- package/shadow/shadow-tracker.js +151 -0
- package/shadow/types.d.ts +42 -0
- package/shadow/types.js +20 -0
- package/shared/indicators-extended.d.ts +52 -0
- package/shared/indicators-extended.js +291 -0
- package/shared/indicators.d.ts +15 -0
- package/shared/indicators.js +114 -0
- package/signals/conditions/registry.d.ts +16 -0
- package/signals/conditions/registry.js +1274 -0
- package/signals/conditions/types.d.ts +1 -0
- package/signals/conditions/types.js +4 -0
- package/signals/direction-rules.d.ts +3 -0
- package/signals/direction-rules.js +24 -0
- package/signals/entry-rules.d.ts +6 -0
- package/signals/entry-rules.js +33 -0
- package/signals/serialize-context.d.ts +4 -0
- package/signals/serialize-context.js +39 -0
- package/signals/stop-rules.d.ts +3 -0
- package/signals/stop-rules.js +48 -0
- package/signals/strategy-adapter.d.ts +14 -0
- package/signals/strategy-adapter.js +122 -0
- package/signals/types.d.ts +1 -0
- package/signals/types.js +8 -0
- package/simulator/exchange-simulator.d.ts +93 -0
- package/simulator/exchange-simulator.js +684 -0
- package/simulator/fill-engine.d.ts +53 -0
- package/simulator/fill-engine.js +276 -0
- package/simulator/paper-market-feed.d.ts +26 -0
- package/simulator/paper-market-feed.js +104 -0
- package/simulator/realistic-fills.d.ts +59 -0
- package/simulator/realistic-fills.js +175 -0
- package/simulator/types.d.ts +219 -0
- package/simulator/types.js +43 -0
- package/skills/reefclaw/SKILL.md +97 -0
- package/strategy/builtin-strategies.d.ts +2 -0
- package/strategy/builtin-strategies.js +109 -0
- package/strategy/condition-registry.d.ts +3 -0
- package/strategy/condition-registry.js +153 -0
- package/strategy/evaluator.d.ts +67 -0
- package/strategy/evaluator.js +93 -0
- package/tools/assessment-validation.d.ts +118 -0
- package/tools/assessment-validation.js +415 -0
- package/tools/attach-brackets.d.ts +34 -0
- package/tools/attach-brackets.js +363 -0
- package/tools/audit-bracket-protection.d.ts +49 -0
- package/tools/audit-bracket-protection.js +527 -0
- package/tools/cancel-all-orders.d.ts +7 -0
- package/tools/cancel-all-orders.js +5 -0
- package/tools/cancel-order.d.ts +10 -0
- package/tools/cancel-order.js +14 -0
- package/tools/check-position-health.d.ts +46 -0
- package/tools/check-position-health.js +194 -0
- package/tools/clear-exchange-credentials.d.ts +24 -0
- package/tools/clear-exchange-credentials.js +70 -0
- package/tools/close-position.d.ts +22 -0
- package/tools/close-position.js +449 -0
- package/tools/create-order.d.ts +54 -0
- package/tools/create-order.js +338 -0
- package/tools/exit-gate.d.ts +58 -0
- package/tools/exit-gate.js +162 -0
- package/tools/fetch-balance.d.ts +5 -0
- package/tools/fetch-balance.js +4 -0
- package/tools/fetch-ohlcv.d.ts +11 -0
- package/tools/fetch-ohlcv.js +8 -0
- package/tools/fetch-open-orders.d.ts +7 -0
- package/tools/fetch-open-orders.js +4 -0
- package/tools/fetch-positions.d.ts +7 -0
- package/tools/fetch-positions.js +4 -0
- package/tools/fetch-ticker.d.ts +11 -0
- package/tools/fetch-ticker.js +5 -0
- package/tools/get-agent-profile.d.ts +4 -0
- package/tools/get-agent-profile.js +6 -0
- package/tools/get-analytics.d.ts +6 -0
- package/tools/get-analytics.js +7 -0
- package/tools/get-backtest.d.ts +12 -0
- package/tools/get-backtest.js +91 -0
- package/tools/get-basis.d.ts +7 -0
- package/tools/get-basis.js +7 -0
- package/tools/get-bracket-config.d.ts +11 -0
- package/tools/get-bracket-config.js +24 -0
- package/tools/get-cascade-risk.d.ts +7 -0
- package/tools/get-cascade-risk.js +8 -0
- package/tools/get-crypto-metrics.d.ts +18 -0
- package/tools/get-crypto-metrics.js +45 -0
- package/tools/get-cvd.d.ts +6 -0
- package/tools/get-cvd.js +6 -0
- package/tools/get-divergences.d.ts +6 -0
- package/tools/get-divergences.js +6 -0
- package/tools/get-funding-context.d.ts +6 -0
- package/tools/get-funding-context.js +16 -0
- package/tools/get-liquidation-levels.d.ts +7 -0
- package/tools/get-liquidation-levels.js +7 -0
- package/tools/get-liquidation-pulse.d.ts +9 -0
- package/tools/get-liquidation-pulse.js +22 -0
- package/tools/get-market-breadth.d.ts +6 -0
- package/tools/get-market-breadth.js +8 -0
- package/tools/get-market-intel.d.ts +19 -0
- package/tools/get-market-intel.js +116 -0
- package/tools/get-market-structure.d.ts +47 -0
- package/tools/get-market-structure.js +198 -0
- package/tools/get-my-mined-patterns.d.ts +20 -0
- package/tools/get-my-mined-patterns.js +61 -0
- package/tools/get-my-proposed-learnings.d.ts +20 -0
- package/tools/get-my-proposed-learnings.js +55 -0
- package/tools/get-my-recent-reviews.d.ts +22 -0
- package/tools/get-my-recent-reviews.js +66 -0
- package/tools/get-orderbook.d.ts +21 -0
- package/tools/get-orderbook.js +32 -0
- package/tools/get-pattern-scan.d.ts +7 -0
- package/tools/get-pattern-scan.js +8 -0
- package/tools/get-regime.d.ts +6 -0
- package/tools/get-regime.js +7 -0
- package/tools/get-relevant-learnings.d.ts +21 -0
- package/tools/get-relevant-learnings.js +65 -0
- package/tools/get-resting-liquidity.d.ts +6 -0
- package/tools/get-resting-liquidity.js +11 -0
- package/tools/get-risk-scenario.d.ts +29 -0
- package/tools/get-risk-scenario.js +47 -0
- package/tools/get-risk-summary.d.ts +51 -0
- package/tools/get-risk-summary.js +118 -0
- package/tools/get-sentiment.d.ts +4 -0
- package/tools/get-sentiment.js +6 -0
- package/tools/get-session-review.d.ts +7 -0
- package/tools/get-session-review.js +8 -0
- package/tools/get-setup-detail.d.ts +7 -0
- package/tools/get-setup-detail.js +303 -0
- package/tools/get-signals.d.ts +15 -0
- package/tools/get-signals.js +54 -0
- package/tools/get-sizing.d.ts +6 -0
- package/tools/get-sizing.js +6 -0
- package/tools/get-trade-feedback.d.ts +7 -0
- package/tools/get-trade-feedback.js +8 -0
- package/tools/get-trade-flow.d.ts +7 -0
- package/tools/get-trade-flow.js +7 -0
- package/tools/get-volume-analysis.d.ts +21 -0
- package/tools/get-volume-analysis.js +74 -0
- package/tools/get-volume-profile.d.ts +7 -0
- package/tools/get-volume-profile.js +7 -0
- package/tools/helpers.d.ts +25 -0
- package/tools/helpers.js +38 -0
- package/tools/intel-api.d.ts +14 -0
- package/tools/intel-api.js +52 -0
- package/tools/intel-cache.d.ts +25 -0
- package/tools/intel-cache.js +133 -0
- package/tools/list-strategies.d.ts +7 -0
- package/tools/list-strategies.js +6 -0
- package/tools/modify-stop.d.ts +17 -0
- package/tools/modify-stop.js +81 -0
- package/tools/modify-target.d.ts +17 -0
- package/tools/modify-target.js +71 -0
- package/tools/propose-learning.d.ts +22 -0
- package/tools/propose-learning.js +65 -0
- package/tools/query-review-outcomes.d.ts +30 -0
- package/tools/query-review-outcomes.js +64 -0
- package/tools/query-trades.d.ts +21 -0
- package/tools/query-trades.js +37 -0
- package/tools/record-position-reviews.d.ts +38 -0
- package/tools/record-position-reviews.js +147 -0
- package/tools/save-strategy.d.ts +16 -0
- package/tools/save-strategy.js +46 -0
- package/tools/scan-pairs.d.ts +18 -0
- package/tools/scan-pairs.js +220 -0
- package/tools/score-setup.d.ts +31 -0
- package/tools/score-setup.js +268 -0
- package/tools/set-bracket-requirement.d.ts +18 -0
- package/tools/set-bracket-requirement.js +81 -0
- package/tools/set-exchange-credentials.d.ts +25 -0
- package/tools/set-exchange-credentials.js +80 -0
- package/tools/set-trading-mode.d.ts +26 -0
- package/tools/set-trading-mode.js +135 -0
- package/tools/test-exchange-credentials.d.ts +16 -0
- package/tools/test-exchange-credentials.js +100 -0
- package/tools/toggle-strategy.d.ts +8 -0
- package/tools/toggle-strategy.js +8 -0
- package/trading-params-cache.d.ts +26 -0
- package/trading-params-cache.js +52 -0
- package/types.d.ts +110 -0
- package/types.js +7 -0
- package/util/plugin-paths.d.ts +3 -0
- package/util/plugin-paths.js +15 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// Plugin-side condition registry — lightweight evaluators that read pre-computed facts.
|
|
2
|
+
// Each evaluator reads booleans from fact.conditions and/or compares indicator values
|
|
3
|
+
// against strategy params. Does NOT duplicate the full condition logic from intelligence.
|
|
4
|
+
export const CONDITION_EVALUATORS = new Map();
|
|
5
|
+
function register(type, fn) {
|
|
6
|
+
CONDITION_EVALUATORS.set(type, fn);
|
|
7
|
+
}
|
|
8
|
+
// ─── Helper to read indicator values ────────────────────────────────────
|
|
9
|
+
function ind(fact, key) {
|
|
10
|
+
return fact.indicators[key];
|
|
11
|
+
}
|
|
12
|
+
function indNum(fact, key) {
|
|
13
|
+
return Number(fact.indicators[key] ?? 0);
|
|
14
|
+
}
|
|
15
|
+
// ─── Original 12 conditions (read booleans from fact.conditions) ────────
|
|
16
|
+
// 1. ema_proximity — checks against parameterized threshold
|
|
17
|
+
register('ema_proximity', (fact, params) => {
|
|
18
|
+
const period = params.period ?? 21;
|
|
19
|
+
const key = period <= 30 ? 'ema_proximity_20' : 'ema_proximity_50';
|
|
20
|
+
return { name: 'ema_proximity', met: fact.conditions[key] ?? false };
|
|
21
|
+
});
|
|
22
|
+
// 2. orderbook_imbalance
|
|
23
|
+
register('orderbook_imbalance', (fact) => {
|
|
24
|
+
const bid = fact.conditions.orderbook_imbalance_bid ?? false;
|
|
25
|
+
const ask = fact.conditions.orderbook_imbalance_ask ?? false;
|
|
26
|
+
return { name: 'orderbook_imbalance', met: bid || ask };
|
|
27
|
+
});
|
|
28
|
+
// 3. funding_not_crowded
|
|
29
|
+
register('funding_not_crowded', (fact) => ({
|
|
30
|
+
name: 'funding_not_crowded',
|
|
31
|
+
met: fact.conditions.funding_not_crowded ?? false,
|
|
32
|
+
value: indNum(fact, 'fundingZScore'),
|
|
33
|
+
}));
|
|
34
|
+
// 4. oi_slope
|
|
35
|
+
register('oi_slope', (fact) => ({
|
|
36
|
+
name: 'oi_slope',
|
|
37
|
+
met: fact.conditions.oi_slope_up ?? false,
|
|
38
|
+
}));
|
|
39
|
+
// 5. no_liquidation_cluster — always passes in scan context (no live data)
|
|
40
|
+
register('no_liquidation_cluster', () => ({
|
|
41
|
+
name: 'no_liquidation_cluster',
|
|
42
|
+
met: true,
|
|
43
|
+
}));
|
|
44
|
+
// 6. price_sweep
|
|
45
|
+
register('price_sweep', (fact) => ({
|
|
46
|
+
name: 'price_sweep',
|
|
47
|
+
met: (fact.conditions.price_sweep_high ?? false) || (fact.conditions.price_sweep_low ?? false),
|
|
48
|
+
}));
|
|
49
|
+
// 7. liquidations_at_sweep — always passes in scan context
|
|
50
|
+
register('liquidations_at_sweep', () => ({
|
|
51
|
+
name: 'liquidations_at_sweep',
|
|
52
|
+
met: true,
|
|
53
|
+
}));
|
|
54
|
+
// 8. order_flow_absorption
|
|
55
|
+
register('order_flow_absorption', (fact) => ({
|
|
56
|
+
name: 'order_flow_absorption',
|
|
57
|
+
met: fact.conditions.orderbook_imbalance_bid ?? false, // Proxy via orderbook data
|
|
58
|
+
}));
|
|
59
|
+
// 9. funding_contrarian
|
|
60
|
+
register('funding_contrarian', (fact) => ({
|
|
61
|
+
name: 'funding_contrarian',
|
|
62
|
+
met: fact.conditions.funding_not_crowded ?? false,
|
|
63
|
+
value: indNum(fact, 'fundingZScore'),
|
|
64
|
+
}));
|
|
65
|
+
// 10. funding_extreme
|
|
66
|
+
register('funding_extreme', (fact) => ({
|
|
67
|
+
name: 'funding_extreme',
|
|
68
|
+
met: fact.conditions.funding_extreme ?? false,
|
|
69
|
+
value: indNum(fact, 'fundingZScore'),
|
|
70
|
+
}));
|
|
71
|
+
// 11. oi_elevated
|
|
72
|
+
register('oi_elevated', (fact) => ({
|
|
73
|
+
name: 'oi_elevated',
|
|
74
|
+
met: fact.conditions.oi_elevated ?? false,
|
|
75
|
+
value: indNum(fact, 'oiRatio'),
|
|
76
|
+
}));
|
|
77
|
+
// 12. price_at_level
|
|
78
|
+
register('price_at_level', (fact) => ({
|
|
79
|
+
name: 'price_at_level',
|
|
80
|
+
met: fact.conditions.ema_proximity_50 ?? false, // Closest proxy
|
|
81
|
+
}));
|
|
82
|
+
// ─── New 11 conditions (Phase 13) ──────────────────────────────────────
|
|
83
|
+
// 13. macd_crossover
|
|
84
|
+
register('macd_crossover', (fact) => ({
|
|
85
|
+
name: 'macd_crossover',
|
|
86
|
+
met: fact.conditions.macd_crossover ?? false,
|
|
87
|
+
}));
|
|
88
|
+
// 14. macd_divergence
|
|
89
|
+
register('macd_divergence', (fact) => ({
|
|
90
|
+
name: 'macd_divergence',
|
|
91
|
+
met: fact.conditions.macd_divergence ?? false,
|
|
92
|
+
}));
|
|
93
|
+
// 15. bollinger_squeeze — supports custom maxBandwidth param
|
|
94
|
+
register('bollinger_squeeze', (fact, params) => {
|
|
95
|
+
const maxBW = params.maxBandwidth ?? 3.0;
|
|
96
|
+
const bb = ind(fact, 'bb');
|
|
97
|
+
const bw = bb?.bandwidth ?? 0;
|
|
98
|
+
return {
|
|
99
|
+
name: 'bollinger_squeeze',
|
|
100
|
+
met: bw > 0 && bw < maxBW,
|
|
101
|
+
value: bw,
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
// 16. bollinger_breakout
|
|
105
|
+
register('bollinger_breakout', (fact) => ({
|
|
106
|
+
name: 'bollinger_breakout',
|
|
107
|
+
met: fact.conditions.bollinger_breakout ?? false,
|
|
108
|
+
}));
|
|
109
|
+
// 17. vwap_position
|
|
110
|
+
register('vwap_position', (fact) => ({
|
|
111
|
+
name: 'vwap_position',
|
|
112
|
+
met: fact.conditions.vwap_position_above ?? fact.conditions.vwap_position_below ?? false,
|
|
113
|
+
}));
|
|
114
|
+
// 18. stoch_rsi_extreme
|
|
115
|
+
register('stoch_rsi_extreme', (fact) => ({
|
|
116
|
+
name: 'stoch_rsi_extreme',
|
|
117
|
+
met: (fact.conditions.stoch_rsi_oversold ?? false) || (fact.conditions.stoch_rsi_overbought ?? false),
|
|
118
|
+
}));
|
|
119
|
+
// 19. adx_trending
|
|
120
|
+
register('adx_trending', (fact, params) => {
|
|
121
|
+
const minAdx = params.minAdx ?? 25;
|
|
122
|
+
const adx = indNum(fact, 'adx');
|
|
123
|
+
return {
|
|
124
|
+
name: 'adx_trending',
|
|
125
|
+
met: adx > minAdx,
|
|
126
|
+
value: adx,
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
// 20. adx_ranging
|
|
130
|
+
register('adx_ranging', (fact, params) => {
|
|
131
|
+
const maxAdx = params.maxAdx ?? 20;
|
|
132
|
+
const adx = indNum(fact, 'adx');
|
|
133
|
+
return {
|
|
134
|
+
name: 'adx_ranging',
|
|
135
|
+
met: adx < maxAdx,
|
|
136
|
+
value: adx,
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
// 21. ichimoku_cloud
|
|
140
|
+
register('ichimoku_cloud', (fact) => ({
|
|
141
|
+
name: 'ichimoku_cloud',
|
|
142
|
+
met: (fact.conditions.ichimoku_bullish ?? false) || (fact.conditions.ichimoku_bearish ?? false),
|
|
143
|
+
}));
|
|
144
|
+
// 22. obv_divergence
|
|
145
|
+
register('obv_divergence', (fact) => ({
|
|
146
|
+
name: 'obv_divergence',
|
|
147
|
+
met: (fact.conditions.obv_divergence_bullish ?? false) || (fact.conditions.obv_divergence_bearish ?? false),
|
|
148
|
+
}));
|
|
149
|
+
// 23. supertrend_direction
|
|
150
|
+
register('supertrend_direction', (fact) => ({
|
|
151
|
+
name: 'supertrend_direction',
|
|
152
|
+
met: (fact.conditions.supertrend_bullish ?? false) || (fact.conditions.supertrend_bearish ?? false),
|
|
153
|
+
}));
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export interface SymbolFact {
|
|
2
|
+
symbol: string;
|
|
3
|
+
time: string;
|
|
4
|
+
indicators: Record<string, unknown>;
|
|
5
|
+
conditions: Record<string, boolean>;
|
|
6
|
+
regime: string;
|
|
7
|
+
regime_confidence: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ConditionConfig {
|
|
10
|
+
type: string;
|
|
11
|
+
params: Record<string, number>;
|
|
12
|
+
}
|
|
13
|
+
export interface StrategyConfig {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
version: number;
|
|
17
|
+
regimeWhitelist: string[];
|
|
18
|
+
minConfidence: number;
|
|
19
|
+
directionRule: string;
|
|
20
|
+
conditions: ConditionConfig[];
|
|
21
|
+
entryRule: {
|
|
22
|
+
type: string;
|
|
23
|
+
params: Record<string, number>;
|
|
24
|
+
};
|
|
25
|
+
stopRule: {
|
|
26
|
+
type: string;
|
|
27
|
+
params: Record<string, number>;
|
|
28
|
+
};
|
|
29
|
+
targetRMultiples: number[];
|
|
30
|
+
}
|
|
31
|
+
export interface StrategyRow {
|
|
32
|
+
id: number;
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
config: StrategyConfig;
|
|
36
|
+
is_builtin: boolean;
|
|
37
|
+
is_active: boolean;
|
|
38
|
+
backtest_result: unknown | null;
|
|
39
|
+
created_at: string;
|
|
40
|
+
updated_at: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ConditionEvalResult {
|
|
43
|
+
name: string;
|
|
44
|
+
met: boolean;
|
|
45
|
+
value?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface StrategyEvalResult {
|
|
48
|
+
strategy: string;
|
|
49
|
+
symbol: string;
|
|
50
|
+
score: number;
|
|
51
|
+
conditionsMet: number;
|
|
52
|
+
conditionsTotal: number;
|
|
53
|
+
conditions: ConditionEvalResult[];
|
|
54
|
+
regime: string;
|
|
55
|
+
regime_confidence: number;
|
|
56
|
+
summary: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Evaluate a strategy against a symbol's fact object.
|
|
60
|
+
* Returns null if the strategy is regime-gated and the symbol's regime doesn't match.
|
|
61
|
+
*/
|
|
62
|
+
export declare function evaluateStrategy(strategy: StrategyConfig, fact: SymbolFact): StrategyEvalResult | null;
|
|
63
|
+
/**
|
|
64
|
+
* Evaluate all active strategies against all symbol facts.
|
|
65
|
+
* Returns ranked results above minScore.
|
|
66
|
+
*/
|
|
67
|
+
export declare function scanAllPairs(strategies: StrategyConfig[], facts: SymbolFact[], minScore?: number): StrategyEvalResult[];
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Lightweight strategy evaluator for plugin-side condition checking.
|
|
2
|
+
// Reads pre-computed fact objects from intelligence service (boolean conditions + indicator values).
|
|
3
|
+
// Does NOT duplicate the full condition logic from intelligence — reads pre-evaluated booleans
|
|
4
|
+
// and optionally checks threshold-based conditions against indicator values.
|
|
5
|
+
import { CONDITION_EVALUATORS } from './condition-registry.js';
|
|
6
|
+
import { getCachedTradingParams } from '../trading-params-cache.js';
|
|
7
|
+
// ─── Evaluator ──────────────────────────────────────────────────────────
|
|
8
|
+
/**
|
|
9
|
+
* Evaluate a strategy against a symbol's fact object.
|
|
10
|
+
* Returns null if the strategy is regime-gated and the symbol's regime doesn't match.
|
|
11
|
+
*/
|
|
12
|
+
export function evaluateStrategy(strategy, fact) {
|
|
13
|
+
// Check regime gate
|
|
14
|
+
if (strategy.regimeWhitelist.length > 0) {
|
|
15
|
+
const matchesRegime = strategy.regimeWhitelist.some(r => r === fact.regime || r === 'ANY');
|
|
16
|
+
if (!matchesRegime)
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
// Check regime confidence — use the LOWER of strategy minConfidence and user's global floor
|
|
20
|
+
const tp = getCachedTradingParams();
|
|
21
|
+
const effectiveMinConf = Math.min(strategy.minConfidence, tp.regimeConfidenceFloor || strategy.minConfidence);
|
|
22
|
+
if (fact.regime_confidence < effectiveMinConf)
|
|
23
|
+
return null;
|
|
24
|
+
// Evaluate each condition
|
|
25
|
+
const results = [];
|
|
26
|
+
for (const cond of strategy.conditions) {
|
|
27
|
+
const evaluator = CONDITION_EVALUATORS.get(cond.type);
|
|
28
|
+
if (evaluator) {
|
|
29
|
+
results.push(evaluator(fact, cond.params));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Fallback: try to read directly from fact.conditions map
|
|
33
|
+
const boolKey = cond.type;
|
|
34
|
+
const met = fact.conditions[boolKey] ?? false;
|
|
35
|
+
results.push({ name: cond.type, met });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const conditionsMet = results.filter(r => r.met).length;
|
|
39
|
+
const conditionsTotal = results.length;
|
|
40
|
+
const score = conditionsTotal > 0 ? (conditionsMet / conditionsTotal) * 10 : 0;
|
|
41
|
+
// Build summary
|
|
42
|
+
const metNames = results.filter(r => r.met).map(r => r.name).join(', ');
|
|
43
|
+
const summary = buildSummary(strategy, fact, results);
|
|
44
|
+
return {
|
|
45
|
+
strategy: strategy.name,
|
|
46
|
+
symbol: fact.symbol,
|
|
47
|
+
score: Math.round(score * 10) / 10,
|
|
48
|
+
conditionsMet,
|
|
49
|
+
conditionsTotal,
|
|
50
|
+
conditions: results,
|
|
51
|
+
regime: fact.regime,
|
|
52
|
+
regime_confidence: fact.regime_confidence,
|
|
53
|
+
summary,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Evaluate all active strategies against all symbol facts.
|
|
58
|
+
* Returns ranked results above minScore.
|
|
59
|
+
*/
|
|
60
|
+
export function scanAllPairs(strategies, facts, minScore = 4) {
|
|
61
|
+
const results = [];
|
|
62
|
+
for (const fact of facts) {
|
|
63
|
+
for (const strategy of strategies) {
|
|
64
|
+
const result = evaluateStrategy(strategy, fact);
|
|
65
|
+
if (result && result.score >= minScore) {
|
|
66
|
+
results.push(result);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Sort by score descending
|
|
71
|
+
results.sort((a, b) => b.score - a.score);
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
74
|
+
// ─── Summary builder ────────────────────────────────────────────────────
|
|
75
|
+
function buildSummary(strategy, fact, results) {
|
|
76
|
+
const ind = fact.indicators;
|
|
77
|
+
const parts = [];
|
|
78
|
+
// Regime context
|
|
79
|
+
parts.push(`${fact.regime} (${(fact.regime_confidence * 100).toFixed(0)}%)`);
|
|
80
|
+
// Key indicator values
|
|
81
|
+
if (ind.rsi14 !== undefined)
|
|
82
|
+
parts.push(`RSI ${ind.rsi14}`);
|
|
83
|
+
if (ind.adx !== undefined)
|
|
84
|
+
parts.push(`ADX ${ind.adx}`);
|
|
85
|
+
const macd = ind.macd;
|
|
86
|
+
if (macd?.crossover && macd.crossover !== 'none') {
|
|
87
|
+
parts.push(`MACD ${macd.crossover}`);
|
|
88
|
+
}
|
|
89
|
+
const funding = ind.fundingZScore;
|
|
90
|
+
if (funding !== undefined)
|
|
91
|
+
parts.push(`Funding ${funding > 0 ? '+' : ''}${funding.toFixed(1)}σ`);
|
|
92
|
+
return parts.join(', ');
|
|
93
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { RealizationRule } from '../simulator/types.js';
|
|
2
|
+
/** The five legitimate reasons to manually close an otherwise-bracketed
|
|
3
|
+
* position (see SKILL.md v2.10.0 Position Management Discipline). Any other
|
|
4
|
+
* value is rejected. */
|
|
5
|
+
export declare const CLOSE_REASONS: readonly ["regime_flip", "risk_limit", "bracket_integrity", "operator_command"];
|
|
6
|
+
export type CloseReason = (typeof CLOSE_REASONS)[number];
|
|
7
|
+
export interface CloseAssessment {
|
|
8
|
+
/** Scorecard confluence score at entry (0-10). */
|
|
9
|
+
entry_score?: number;
|
|
10
|
+
/** Current scorecard confluence score from this heartbeat's fresh analysis. */
|
|
11
|
+
current_score?: number;
|
|
12
|
+
/** Regime at entry, e.g. 'RANGE_WIDE', 'TREND_UP'. */
|
|
13
|
+
entry_regime?: string;
|
|
14
|
+
/** Regime right now, from this heartbeat's fresh analysis. */
|
|
15
|
+
current_regime?: string;
|
|
16
|
+
/** Free-text naming the specific metric that flipped. Required for
|
|
17
|
+
* regime_flip, risk_limit, and bracket_integrity. */
|
|
18
|
+
contradicting_metric?: string;
|
|
19
|
+
/** Telemetry only — position age in seconds. Not gated. */
|
|
20
|
+
position_age_seconds?: number;
|
|
21
|
+
/** Telemetry only — R-multiple at close (= current_r in exit-gate inputs). */
|
|
22
|
+
r_multiple_at_close?: number;
|
|
23
|
+
/** Max favorable excursion in R-multiples ever reached during this position's
|
|
24
|
+
* lifetime. Drives the exit-gate tier classification (see
|
|
25
|
+
* docs/EXIT_GATE_DESIGN.md §3). Optional for backwards compatibility — the
|
|
26
|
+
* gate falls back to PASS('inputs_unavailable_mfe') when absent so the
|
|
27
|
+
* shadow soak can surface plumbing gaps before enforce. */
|
|
28
|
+
mfe_r_peak?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface ClosePositionArgs {
|
|
31
|
+
symbol: string;
|
|
32
|
+
reason?: string;
|
|
33
|
+
assessment?: CloseAssessment;
|
|
34
|
+
}
|
|
35
|
+
export interface ValidationResult {
|
|
36
|
+
ok: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Validate a `close_position` call against the SKILL.md v2.10.0 contract.
|
|
40
|
+
* Returns {ok:true} to proceed or {ok:false, error} to reject the tool call.
|
|
41
|
+
*
|
|
42
|
+
* Philosophy: force the agent to submit structured proof that a real
|
|
43
|
+
* reassessment happened. No time gate — a 60-second close is legal if the
|
|
44
|
+
* assessment holds up. But blank or inconsistent fields mean no reasoning,
|
|
45
|
+
* so we refuse.
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateClosePosition(args: ClosePositionArgs): ValidationResult;
|
|
48
|
+
export interface CreateOrderArgs {
|
|
49
|
+
symbol: string;
|
|
50
|
+
side: string;
|
|
51
|
+
type: string;
|
|
52
|
+
amount: number;
|
|
53
|
+
price?: number;
|
|
54
|
+
stopPrice?: number;
|
|
55
|
+
setup_type?: string;
|
|
56
|
+
thesis?: string;
|
|
57
|
+
target_price?: number;
|
|
58
|
+
regime?: string;
|
|
59
|
+
regime_confidence?: number;
|
|
60
|
+
scorecard_verdict?: string;
|
|
61
|
+
confluence_score?: number;
|
|
62
|
+
invalidation_price?: number;
|
|
63
|
+
realization_rule?: unknown;
|
|
64
|
+
}
|
|
65
|
+
/** Validate a `create_order` call against the SKILL.md v2.10.0 contract.
|
|
66
|
+
* Only enforced in LIVE mode — paper mode is for exploration and allows
|
|
67
|
+
* missing metadata so the agent can probe without full reasoning. Live
|
|
68
|
+
* mode = real money = must show your work.
|
|
69
|
+
*/
|
|
70
|
+
export declare function validateCreateOrder(args: CreateOrderArgs, isLive: boolean): ValidationResult;
|
|
71
|
+
/** Coerce the agent-supplied `realization_rule` (snake_case from the tool
|
|
72
|
+
* schema) into a clean RealizationRule, dropping garbage. Permissive by
|
|
73
|
+
* design — this is the agent's stated PLAN (indication), not an enforced
|
|
74
|
+
* mechanic, so we keep whatever is well-formed and default an unknown `type`
|
|
75
|
+
* to 'manual' rather than rejecting. Returns undefined for non-objects. */
|
|
76
|
+
export declare function sanitizeRealizationRule(raw: unknown): RealizationRule | undefined;
|
|
77
|
+
/** Verdicts the agent can file at heartbeat for an open position. `trim` is
|
|
78
|
+
* intentionally absent until `partial_close` exists as a real action — see
|
|
79
|
+
* POSITION_DECISION_JOURNAL_PLAN.md §3 redirect #4. */
|
|
80
|
+
export declare const REVIEW_VERDICTS: readonly ["hold", "add_on", "close_recommended"];
|
|
81
|
+
export type ReviewVerdict = (typeof REVIEW_VERDICTS)[number];
|
|
82
|
+
export declare const THESIS_STATUSES: readonly ["intact", "weakening", "invalidated", "evolving"];
|
|
83
|
+
export type ThesisStatus = (typeof THESIS_STATUSES)[number];
|
|
84
|
+
export interface PositionReviewItem {
|
|
85
|
+
symbol?: string;
|
|
86
|
+
position_open_at?: number;
|
|
87
|
+
verdict?: string;
|
|
88
|
+
thesis_status?: string;
|
|
89
|
+
entry_score?: number;
|
|
90
|
+
current_score?: number;
|
|
91
|
+
score_delta?: number;
|
|
92
|
+
confluence_components?: Record<string, unknown>;
|
|
93
|
+
regime_entry?: string;
|
|
94
|
+
regime_current?: string;
|
|
95
|
+
regime_confidence?: number;
|
|
96
|
+
r_multiple?: number;
|
|
97
|
+
distance_to_stop_bps?: number;
|
|
98
|
+
distance_to_target_bps?: number;
|
|
99
|
+
time_in_position_minutes?: number;
|
|
100
|
+
mfe_r?: number;
|
|
101
|
+
give_back_pct?: number;
|
|
102
|
+
what_changed?: string;
|
|
103
|
+
invalidation_trigger?: string;
|
|
104
|
+
}
|
|
105
|
+
export interface RecordPositionReviewsArgs {
|
|
106
|
+
reviews?: unknown;
|
|
107
|
+
}
|
|
108
|
+
/** Validate a `record_position_reviews` call. Per-review rules from
|
|
109
|
+
* POSITION_REVIEW_PLAN.md §7.2 plus a top-level superset rule when the caller
|
|
110
|
+
* passes the open-positions snapshot.
|
|
111
|
+
*
|
|
112
|
+
* Returns either {ok:true} (proceed) or {ok:false, error} (reject the whole
|
|
113
|
+
* call — partial-success would corrupt the audit trail).
|
|
114
|
+
*/
|
|
115
|
+
export declare function validatePositionReviews(args: RecordPositionReviewsArgs, ctx?: {
|
|
116
|
+
openSymbols?: ReadonlySet<string>;
|
|
117
|
+
gateMode?: 'off' | 'shadow' | 'observe' | 'enforce';
|
|
118
|
+
}): ValidationResult;
|