@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,325 @@
|
|
|
1
|
+
import type { CcxtOrder, CcxtBalance, CcxtPosition, CcxtTicker, ExchangeConfig } from '../types.js';
|
|
2
|
+
import type { OrderBookDepth } from '../simulator/types.js';
|
|
3
|
+
/** Result of API permission validation. */
|
|
4
|
+
export interface PermissionCheckResult {
|
|
5
|
+
canReadBalance: boolean;
|
|
6
|
+
canReadPositions: boolean;
|
|
7
|
+
canTrade: boolean;
|
|
8
|
+
errors: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare class BinancePrivateApi {
|
|
11
|
+
private exchange;
|
|
12
|
+
private testnet;
|
|
13
|
+
constructor(credentials: ExchangeConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Validate API key permissions by making test API calls.
|
|
16
|
+
* Best-effort — never throws.
|
|
17
|
+
*/
|
|
18
|
+
validatePermissions(): Promise<PermissionCheckResult>;
|
|
19
|
+
/** Fetch real account balance. Returns null on error. */
|
|
20
|
+
fetchBalance(): Promise<CcxtBalance | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Fetch account-transfer income entries (deposits/withdrawals into/out of the
|
|
23
|
+
* Futures wallet) between two timestamps. These surface as `incomeType=TRANSFER`
|
|
24
|
+
* on Binance's `/fapi/v1/income` endpoint; positive `income` = inflow to
|
|
25
|
+
* futures, negative = outflow. Used by DepositTracker to re-anchor
|
|
26
|
+
* sessionStartNav so capital flows never show up as Day P&L.
|
|
27
|
+
*/
|
|
28
|
+
fetchTransfers(startMs: number, endMs: number): Promise<Array<{
|
|
29
|
+
tranId: string;
|
|
30
|
+
time: number;
|
|
31
|
+
amount: number;
|
|
32
|
+
asset: string;
|
|
33
|
+
}>>;
|
|
34
|
+
/**
|
|
35
|
+
* Sum trading-effect income (every incomeType EXCEPT TRANSFER) since
|
|
36
|
+
* `sinceMs` — i.e. net wallet change from trading. This matches Binance
|
|
37
|
+
* mobile app's "Today's Realized PNL" line (verified 2026-05-14).
|
|
38
|
+
*
|
|
39
|
+
* An earlier comment here claimed Binance's UI uses GROSS REALIZED_PNL
|
|
40
|
+
* only and that the gross/net values "no longer match" — that was based
|
|
41
|
+
* on a faulty assumption that propagated into the live-adapter and
|
|
42
|
+
* caused dashboard Realized to show $2.28 less negative than Binance's
|
|
43
|
+
* own UI. Reverted: gross is for debug only, net is what the user sees.
|
|
44
|
+
*
|
|
45
|
+
* Single REST call, weight=30. Returns `null` (NOT 0) on a failed/paced
|
|
46
|
+
* fetch — null≠empty: a non-answer must never collapse to a zero the
|
|
47
|
+
* caller would treat as real (2026-05-16 KPI incident). Unused in prod
|
|
48
|
+
* (kept for parity / ad-hoc reconciliation).
|
|
49
|
+
*
|
|
50
|
+
* Spec: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Income-History
|
|
51
|
+
*/
|
|
52
|
+
fetchRealizedPnlSince(sinceMs: number): Promise<number | null>;
|
|
53
|
+
/**
|
|
54
|
+
* One income-history call, two numbers:
|
|
55
|
+
* - `realizedPnlGross`: sum of `incomeType === 'REALIZED_PNL'` only.
|
|
56
|
+
* KEPT FOR DEBUG / RECONCILIATION ONLY — despite an earlier comment
|
|
57
|
+
* claiming this matches Binance's "Today's Realized PNL" UI line,
|
|
58
|
+
* the mobile app verification on 2026-05-14 showed Binance reports
|
|
59
|
+
* the NET figure (-$5.98 in the test) while gross was -$3.70. Do
|
|
60
|
+
* NOT surface this number in the dashboard Realized KPI.
|
|
61
|
+
* - `netNonTransfer`: sum of EVERY non-TRANSFER incomeType (REALIZED_PNL +
|
|
62
|
+
* COMMISSION + FUNDING_FEE + rebates). This equals today's net wallet
|
|
63
|
+
* change from trading and matches the Binance mobile app's
|
|
64
|
+
* "Today's Realized PNL" line. Used for BOTH the Realized KPI display
|
|
65
|
+
* AND the `sessionStartNav` anchor so Day P&L reflects total NAV
|
|
66
|
+
* change since UTC midnight.
|
|
67
|
+
*
|
|
68
|
+
* Both numbers refresh together. Caller throttles. Single page (limit=1000)
|
|
69
|
+
* — > 1000 income rows in a UTC day is unrealistic for a single account.
|
|
70
|
+
*
|
|
71
|
+
* Return contract (null≠empty — same rule as getOpenOrders /
|
|
72
|
+
* closePosition / the bracket reconciler):
|
|
73
|
+
* - `{realizedPnlGross, netNonTransfer}` on a successful parse, INCLUDING
|
|
74
|
+
* a genuine empty income history (`{0,0}` = Binance confirms no income
|
|
75
|
+
* today — a real zero the caller can anchor on: wallet − 0).
|
|
76
|
+
* - `null` on a failed/paced/garbled fetch (rate-limit, 418, network,
|
|
77
|
+
* non-array body). It is "today's income UNKNOWN", NOT "zero". The
|
|
78
|
+
* caller MUST keep its last good anchor. Coercing this to `{0,0}`
|
|
79
|
+
* pinned `sessionStartNav` to `wallet_now` and zeroed Day P&L — the
|
|
80
|
+
* 2026-05-16 KPI incident this contract exists to prevent.
|
|
81
|
+
*
|
|
82
|
+
* `opts.forced` selects the never-paced ban-gate context — pass it ONLY
|
|
83
|
+
* for the boot + UTC-day-rollover anchor (the values that actually change
|
|
84
|
+
* within a UTC day). Routine same-day refreshes leave it false so they
|
|
85
|
+
* stay cosmetic/sheddable; a shed there is now a harmless no-op because
|
|
86
|
+
* the caller keeps the (invariant) last good anchor.
|
|
87
|
+
*
|
|
88
|
+
* Spec: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Income-History
|
|
89
|
+
*/
|
|
90
|
+
fetchTodayIncomeBreakdown(sinceMs: number, opts?: {
|
|
91
|
+
forced?: boolean;
|
|
92
|
+
}): Promise<{
|
|
93
|
+
realizedPnlGross: number;
|
|
94
|
+
netNonTransfer: number;
|
|
95
|
+
} | null>;
|
|
96
|
+
/**
|
|
97
|
+
* Discover symbols that had any trade-tagged income activity since `sinceMs`.
|
|
98
|
+
*
|
|
99
|
+
* /fapi/v1/income (no incomeType filter) returns up to 1000 entries spanning
|
|
100
|
+
* REALIZED_PNL, COMMISSION, FUNDING_FEE, etc. — every entry that originates
|
|
101
|
+
* from a trade carries a non-empty `symbol`. We collect the unique symbols
|
|
102
|
+
* and translate each raw Binance id ('BTCUSDT') into the CCXT-unified form
|
|
103
|
+
* ('BTC/USDT:USDT') via the same `resolveUnifiedSymbol` helper used elsewhere
|
|
104
|
+
* in this file, so callers can store / compare them under one canonical key.
|
|
105
|
+
*
|
|
106
|
+
* Used by RestGapFiller at startup to recover symbols traded during plugin
|
|
107
|
+
* downtime that aren't in the persisted touched-symbols cache (Codex
|
|
108
|
+
* finding 4 follow-up). Single REST call, weight=30 — well below the 2400/min
|
|
109
|
+
* budget. Single page; > 1000 income rows in the window is rare and would
|
|
110
|
+
* indicate a multi-hour outage that needs an operator-driven backfill anyway.
|
|
111
|
+
*
|
|
112
|
+
* Spec: https://developers.binance.com/docs/derivatives/usds-margined-futures/account/rest-api/Get-Income-History
|
|
113
|
+
*/
|
|
114
|
+
fetchRecentTradedSymbols(sinceMs: number): Promise<string[]>;
|
|
115
|
+
/** Fetch real open positions. Returns null on error. */
|
|
116
|
+
fetchPositions(symbol?: string): Promise<CcxtPosition[] | null>;
|
|
117
|
+
/** Fetch real open orders — REGULAR + ALGO (conditional) orders merged.
|
|
118
|
+
*
|
|
119
|
+
* Binance Futures splits orders into two namespaces:
|
|
120
|
+
* - Regular orders (`/fapi/v1/openOrders`) — limit, market, etc.
|
|
121
|
+
* - Algo orders (`/fapi/v1/openAlgoOrders`) — STOP_MARKET,
|
|
122
|
+
* TAKE_PROFIT_MARKET, TRAILING_STOP_MARKET. CCXT submits these via
|
|
123
|
+
* `createOrder` but the unified `fetchOpenOrders` does NOT include them.
|
|
124
|
+
* The bracket-orders feature lives entirely in the algo bucket, so we
|
|
125
|
+
* fetch both and merge the results so downstream consumers (reconciler,
|
|
126
|
+
* dashboard) see a single list. Algo orders are normalised into the same
|
|
127
|
+
* CcxtOrder shape with `clientAlgoId` → `clientOrderId`. */
|
|
128
|
+
fetchOpenOrders(symbol?: string): Promise<CcxtOrder[] | null>;
|
|
129
|
+
/** Fetch open algo (conditional) orders. Used by fetchOpenOrders to merge
|
|
130
|
+
* STOP_MARKET / TAKE_PROFIT_MARKET orders into the unified list. Best-effort:
|
|
131
|
+
* returns [] on endpoint error so the caller degrades gracefully. */
|
|
132
|
+
private fetchOpenAlgoOrders;
|
|
133
|
+
/** Query the live status of a SINGLE algo (conditional) order by its
|
|
134
|
+
* clientAlgoId via GET /fapi/v1/algoOrder (weight 1, doc-verified
|
|
135
|
+
* developers.binance.com/.../Query-Algo-Order, 2026-05-15).
|
|
136
|
+
*
|
|
137
|
+
* This is the authoritative per-order disambiguator for the bracket-spiral
|
|
138
|
+
* class. A broad /fapi/v1/openAlgoOrders empty result is NOT proof a
|
|
139
|
+
* specific bracket leg is gone — Binance returns a *successful* [] under
|
|
140
|
+
* weight pressure / eventual-consistency. This call asks Binance a DIRECT
|
|
141
|
+
* question about one exact order id and returns its `algoStatus`.
|
|
142
|
+
*
|
|
143
|
+
* Returns the UPPERCASE algoStatus on success — one of (doc-verified enum):
|
|
144
|
+
* NEW | WORKING | TRIGGERED | CANCELED | FINISHED | EXPIRED | REJECTED.
|
|
145
|
+
* Returns `null` on ANY non-answer: CCXT implicit method absent
|
|
146
|
+
* (non-algo/paper key — stable capability gap), ban / weight-paced,
|
|
147
|
+
* 429 / network, order-not-found (-2013 or aged-out per Binance's
|
|
148
|
+
* 3-day / 90-day retention rule), or a garbled / unparseable response.
|
|
149
|
+
*
|
|
150
|
+
* `null` is the explicit "could not get an answer" — the SAME null≠empty
|
|
151
|
+
* contract as the rest of the bracket path. Callers MUST map `null` to
|
|
152
|
+
* 'unknown' and never to a destructive decision. Best-effort by design:
|
|
153
|
+
* never throws into the caller (a thrown ban/pace is swallowed to `null`
|
|
154
|
+
* because "I was rate-limited" is just another flavour of "no answer").
|
|
155
|
+
* Ships dark in Phase 1 — no call sites yet. */
|
|
156
|
+
queryAlgoOrderStatus(clientAlgoId: string): Promise<string | null>;
|
|
157
|
+
/** Fetch historical fills (trades) for a symbol via GET /fapi/v1/userTrades.
|
|
158
|
+
* Used by the REST gap-filler (rest-gap-filler.ts) to backfill any fills
|
|
159
|
+
* that landed during a WS blind window — when the user-data stream was
|
|
160
|
+
* between reconnects, ORDER_TRADE_UPDATE events for that interval are
|
|
161
|
+
* unreachable from the WS side. Binance requires a symbol per call; the
|
|
162
|
+
* gap-filler iterates over every symbol it's seen this session.
|
|
163
|
+
*
|
|
164
|
+
* Returns raw CCXT trade objects (permissive shape — caller extracts the
|
|
165
|
+
* fields it needs). `since` is epoch milliseconds. Binance caps `limit` at
|
|
166
|
+
* 1000 per request. Falls back to [] on error so the caller keeps going
|
|
167
|
+
* rather than aborting the whole reconnect flow.
|
|
168
|
+
*
|
|
169
|
+
* `opts.endTime` (epoch ms) bounds the upper end of the window. CCXT 4.5.x
|
|
170
|
+
* reads it from params (`safeInteger2(params, 'until', 'endTime')`) and maps
|
|
171
|
+
* it onto the `/fapi/v1/userTrades` `endTime` query param; the gap-filler's
|
|
172
|
+
* startup deep-fill passes it to chunk a multi-day lookback into the ≤7-day
|
|
173
|
+
* windows Binance requires (the span between startTime and endTime cannot
|
|
174
|
+
* exceed 7 days). Without it, CCXT auto-clamps a `since` older than 7 days to
|
|
175
|
+
* `since + 7d` for linear futures, so only the first week would ever return.
|
|
176
|
+
*
|
|
177
|
+
* Spec: https://developers.binance.com/docs/derivatives/usds-margined-futures/trade/rest-api/Account-Trade-List */
|
|
178
|
+
fetchMyTrades(symbol: string, since?: number, limit?: number, opts?: {
|
|
179
|
+
endTime?: number;
|
|
180
|
+
}): Promise<any[]>;
|
|
181
|
+
/** Null-returning variant of fetchMyTrades — the null≠empty contract
|
|
182
|
+
* (same rule as getPositionsOrNull / fetchOpenOrders):
|
|
183
|
+
* - array (possibly empty) ONLY on a successful response — a real `[]`
|
|
184
|
+
* means Binance CONFIRMS no trades in the queried range;
|
|
185
|
+
* - `null` on ANY non-answer (ban/pace, 429, network, garbled non-array
|
|
186
|
+
* body). Callers must treat null as "trades UNKNOWN" and must NOT
|
|
187
|
+
* advance a pagination cursor or mark a backfill window complete.
|
|
188
|
+
*
|
|
189
|
+
* `opts.fromId` pages by Binance trade id (ascending, inclusive) instead
|
|
190
|
+
* of by time. Doc-verified (Account-Trade-List, 2026-07-02): "The
|
|
191
|
+
* parameter fromId cannot be sent with startTime or endTime", so a fromId
|
|
192
|
+
* call must omit `since`/`endTime` — enforced here rather than silently
|
|
193
|
+
* sending a request Binance rejects. Weight is 5 in all variants (same
|
|
194
|
+
* endpoint), so the existing ban-gate context accounting is unchanged. */
|
|
195
|
+
fetchMyTradesOrNull(symbol: string, since?: number, limit?: number, opts?: {
|
|
196
|
+
endTime?: number;
|
|
197
|
+
fromId?: number;
|
|
198
|
+
}): Promise<any[] | null>;
|
|
199
|
+
/** Fetch order book depth (same data as public, validates auth path). */
|
|
200
|
+
fetchOrderBook(symbol: string, limit?: number): Promise<OrderBookDepth | null>;
|
|
201
|
+
/** Fetch ticker. Returns null on error. */
|
|
202
|
+
fetchTicker(symbol: string): Promise<CcxtTicker | null>;
|
|
203
|
+
/**
|
|
204
|
+
* Submit a real order to the exchange.
|
|
205
|
+
* Used in micro-live and live modes only. NOT called in shadow mode.
|
|
206
|
+
*
|
|
207
|
+
* @param params — extra CCXT params forwarded to Binance (e.g. newClientOrderId, reduceOnly, positionSide).
|
|
208
|
+
*/
|
|
209
|
+
createOrder(symbol: string, side: 'buy' | 'sell', type: 'market' | 'limit', amount: number, price?: number, params?: Record<string, any>): Promise<CcxtOrder>;
|
|
210
|
+
/** Fetch a single order by ID. Used for fill polling and idempotency checks. */
|
|
211
|
+
fetchOrder(orderId: string, symbol?: string): Promise<CcxtOrder | null>;
|
|
212
|
+
/**
|
|
213
|
+
* Fetch a single order by clientOrderId. Used for idempotency recovery
|
|
214
|
+
* after network timeouts — check if the order went through before retrying.
|
|
215
|
+
*/
|
|
216
|
+
fetchOrderByClientId(clientOrderId: string, symbol: string): Promise<CcxtOrder | null>;
|
|
217
|
+
/** Cancel a real order on the exchange. Binance Futures splits orders across
|
|
218
|
+
* two endpoints — regular (`/fapi/v1/order`) and algo/conditional
|
|
219
|
+
* (`/fapi/v1/algoOrder`). Bracket SL/TP live in the algo bucket.
|
|
220
|
+
* The caller usually can't tell which bucket a given id belongs to, so we
|
|
221
|
+
* try regular first, then fall back to algo by algoId on "not found".
|
|
222
|
+
* Symbol is resolved from open-orders snapshot if the caller omits it. */
|
|
223
|
+
cancelOrder(orderId: string, symbol?: string): Promise<CcxtOrder>;
|
|
224
|
+
private normalizeCanceledOrder;
|
|
225
|
+
private fabricateCanceledOrder;
|
|
226
|
+
/**
|
|
227
|
+
* Submit a bracket leg (STOP_MARKET or TAKE_PROFIT_MARKET). Sibling of
|
|
228
|
+
* `createOrder` that widens the `type` parameter to the Binance-specific
|
|
229
|
+
* trigger-order types. Used by BracketManager to attach SL/TP to an
|
|
230
|
+
* already-open position.
|
|
231
|
+
*/
|
|
232
|
+
createBracketOrder(symbol: string, type: 'STOP_MARKET' | 'TAKE_PROFIT_MARKET', side: 'buy' | 'sell', amount: number, params: Record<string, any>): Promise<CcxtOrder>;
|
|
233
|
+
/**
|
|
234
|
+
* Cancel an order by its clientOrderId (not exchange id). Idempotent:
|
|
235
|
+
* "order does not exist" is treated as success since the intent was to
|
|
236
|
+
* remove the order. Binance returns -2011 when the order is already gone.
|
|
237
|
+
*
|
|
238
|
+
* Tries the regular-order cancel first, then the algo-order cancel on
|
|
239
|
+
* failure, because Binance Futures splits the two endpoints and we can't
|
|
240
|
+
* tell from the clientOrderId alone which bucket the order landed in.
|
|
241
|
+
*/
|
|
242
|
+
/** MANDATORY ALGO-CANCEL CHOKEPOINT TRACE (2026-05-16, widened after the
|
|
243
|
+
* Dropbox-revert blinded the cancelOrderByClientId-only tracer).
|
|
244
|
+
*
|
|
245
|
+
* EVERY bracket SL/TP is a Binance *algo* order; EVERY cancel of one that
|
|
246
|
+
* reaches the exchange goes through `fapiPrivateDeleteAlgoOrder` — no
|
|
247
|
+
* matter which higher-level method ordered it (cancelOrder by algoId,
|
|
248
|
+
* cancelOrderByClientId by cid, cancelSymbolBracketOrders, cancelBrackets,
|
|
249
|
+
* modify_*, the reconciler, the agent, anything). Logging the caller stack
|
|
250
|
+
* at THIS one REST chokepoint makes the next bracket disappearance
|
|
251
|
+
* unambiguous, and — critically — if a bracket leg goes `X:CANCELED` on
|
|
252
|
+
* the user-data WS with NO chokepoint log around that timestamp, then it
|
|
253
|
+
* was NOT cancelled by our code at all (Binance-side auto-cancel — a
|
|
254
|
+
* fundamentally different fix). Pure observability, zero behaviour change.
|
|
255
|
+
* Remove once the proven source is fixed and soaked. */
|
|
256
|
+
private logAlgoCancelChokepoint;
|
|
257
|
+
cancelOrderByClientId(clientOrderId: string, symbol: string): Promise<void>;
|
|
258
|
+
/** Cancel all orders on the exchange for a symbol (or everything, if omitted).
|
|
259
|
+
* Covers BOTH regular orders and algo/conditional orders via per-order
|
|
260
|
+
* cancellation through `cancelOrderByClientId`, which internally falls
|
|
261
|
+
* back across both buckets.
|
|
262
|
+
*
|
|
263
|
+
* **Bracket protection is preserved by default.** Orders whose
|
|
264
|
+
* clientOrderId parses as a bracket stop/target (`rc-<16hex>-s` or `-t`)
|
|
265
|
+
* are NEVER cancelled by this method — otherwise a kill-switch fire or an
|
|
266
|
+
* agent-initiated `cancel_all_orders` would strip exchange-side protection
|
|
267
|
+
* off open positions and leave them naked. This was the root cause of
|
|
268
|
+
* the 2026-04-21 naked-position incident (4 live positions ran without
|
|
269
|
+
* stops for hours after kill-switch cancels swept their brackets).
|
|
270
|
+
*
|
|
271
|
+
* Callers that explicitly need to cancel brackets (e.g. `closePosition`
|
|
272
|
+
* after flattening the position) must go through
|
|
273
|
+
* `BracketManager.cancelBrackets(symbol)` which is symbol-scoped and
|
|
274
|
+
* tracks the cancellation in the ledger. */
|
|
275
|
+
cancelAllOrders(symbol?: string): Promise<void>;
|
|
276
|
+
/** Disable Binance's per-symbol `countdownCancelAll` "dead-man's-switch"
|
|
277
|
+
* (POST /fapi/v1/countdownCancelAll, countdownTime=0).
|
|
278
|
+
*
|
|
279
|
+
* ROOT-CAUSE FIX 2026-05-16. A countdownCancelAll timer was armed on this
|
|
280
|
+
* account from OUTSIDE our codebase (verified: nothing in plugin/skill/
|
|
281
|
+
* scripts/OpenClaw-gateway/ccxt ever sets it). When armed, Binance purges
|
|
282
|
+
* EVERY open order for the symbol when the countdown lapses — server-side,
|
|
283
|
+
* empty reason, NOT via the cancel endpoint — which is why every bracket
|
|
284
|
+
* (both order forms, all symbols) was auto-cancelled ~17-53s after
|
|
285
|
+
* placement and no instrumentation ever caught a caller. Proven decisively:
|
|
286
|
+
* a clean order placed with the switch disabled survived 5 min when every
|
|
287
|
+
* churned bracket died in ~25s. countdownTime=0 is Binance's documented
|
|
288
|
+
* DISABLE value; purely protective (cannot cancel/modify/close anything),
|
|
289
|
+
* idempotent, harmless no-op if none is armed. We proactively disable it
|
|
290
|
+
* per active symbol so an externally-armed switch can never again strip
|
|
291
|
+
* protection. Best-effort + safety-critical: like order paths it is NOT
|
|
292
|
+
* pre-gated (must never be blocked) but arms the ban gate on error. */
|
|
293
|
+
disableCountdownCancelAll(symbol: string): Promise<void>;
|
|
294
|
+
/** Translate a Binance market ID (e.g. `BTCUSDT`) back to the unified
|
|
295
|
+
* CCXT symbol (e.g. `BTC/USDT:USDT`, with the `:SETTLE` suffix stripped
|
|
296
|
+
* to match the rest of the system's un-suffixed format). Used when parsing
|
|
297
|
+
* user-data WebSocket events — Binance sends raw market IDs, but the
|
|
298
|
+
* plugin's state store + downstream consumers use unified symbols.
|
|
299
|
+
* Falls back to the raw id if the market isn't in CCXT's cache. */
|
|
300
|
+
symbolFromMarketId(marketId: string): string;
|
|
301
|
+
/** Create a user-data listenKey via POST /fapi/v1/listenKey. The returned
|
|
302
|
+
* key is the authentication token for the user-data WebSocket stream
|
|
303
|
+
* (`wss://fstream.binance.com/private/ws/<listenKey>`). Keys expire after 60 min
|
|
304
|
+
* of inactivity — callers must schedule `keepAliveListenKey` every ~25 min. */
|
|
305
|
+
createListenKey(): Promise<string>;
|
|
306
|
+
/** Keep-alive the current listenKey via PUT /fapi/v1/listenKey. Must be
|
|
307
|
+
* called within 60 min of the last keep-alive; 25-min cadence gives a 2x
|
|
308
|
+
* safety margin. Binance does not require the key to be passed — the
|
|
309
|
+
* endpoint acts on whichever key the API key last minted. */
|
|
310
|
+
keepAliveListenKey(): Promise<void>;
|
|
311
|
+
/** Close the current listenKey via DELETE /fapi/v1/listenKey. Polite
|
|
312
|
+
* teardown on graceful shutdown; Binance will otherwise expire the key
|
|
313
|
+
* after 60 min of inactivity. */
|
|
314
|
+
closeListenKey(): Promise<void>;
|
|
315
|
+
/** Whether this instance is connected to testnet. */
|
|
316
|
+
isTestnet(): boolean;
|
|
317
|
+
/** Get the underlying CCXT exchange instance (for loadMarkets, position mode detection, etc.). */
|
|
318
|
+
getExchange(): any;
|
|
319
|
+
/**
|
|
320
|
+
* Get rate-limit headers from the last exchange response.
|
|
321
|
+
* CCXT stores these on the exchange instance after each request.
|
|
322
|
+
* Returns empty object if not available.
|
|
323
|
+
*/
|
|
324
|
+
getLastResponseHeaders(): Record<string, string>;
|
|
325
|
+
}
|