@reefclaw/openclaw-plugin 0.1.5 → 0.1.6

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.
Files changed (122) hide show
  1. package/ccxt/binance-private.d.ts +21 -0
  2. package/ccxt/binance-private.js +132 -22
  3. package/config/plugin-config-io.d.ts +6 -0
  4. package/config/tool-gate.js +3 -0
  5. package/exchange-adapter.d.ts +16 -0
  6. package/index.js +551 -54
  7. package/lifecycle/trading-operation-lock.d.ts +17 -0
  8. package/lifecycle/trading-operation-lock.js +14 -0
  9. package/live/bracket-id.d.ts +2 -3
  10. package/live/bracket-id.js +22 -9
  11. package/live/live-adapter.d.ts +24 -1
  12. package/live/live-adapter.js +114 -2
  13. package/live/local-signal-service.js +11 -6
  14. package/live/local-strategy-evaluator.js +4 -0
  15. package/live/proposal-decision-listener.d.ts +6 -0
  16. package/live/proposal-decision-listener.js +4 -0
  17. package/live/stop-watcher.d.ts +27 -1
  18. package/live/stop-watcher.js +59 -2
  19. package/onboarding/runtime.d.ts +13 -0
  20. package/onboarding/runtime.js +22 -2
  21. package/openclaw.plugin.json +1 -0
  22. package/package.json +1 -1
  23. package/portfolio/wave9-admission.d.ts +67 -0
  24. package/portfolio/wave9-admission.js +262 -0
  25. package/portfolio/wave9-policy.d.ts +36 -0
  26. package/portfolio/wave9-policy.js +183 -0
  27. package/signals/conditions/registry.js +50 -0
  28. package/simulator/exchange-simulator.js +5 -0
  29. package/simulator/fill-engine.js +5 -1
  30. package/simulator/types.d.ts +6 -1
  31. package/strategy/evaluator.d.ts +3 -0
  32. package/strategy/evaluator.js +5 -0
  33. package/tools/assessment-validation.d.ts +2 -0
  34. package/tools/attach-brackets.d.ts +7 -2
  35. package/tools/attach-brackets.js +36 -0
  36. package/tools/cancel-all-orders.d.ts +2 -0
  37. package/tools/cancel-all-orders.js +4 -1
  38. package/tools/cancel-order.d.ts +4 -0
  39. package/tools/cancel-order.js +49 -3
  40. package/tools/close-position.d.ts +23 -0
  41. package/tools/close-position.js +286 -13
  42. package/tools/create-order.d.ts +28 -0
  43. package/tools/create-order.js +1364 -192
  44. package/tools/get-analytics.js +2 -2
  45. package/tools/get-basis.js +2 -2
  46. package/tools/get-cascade-risk.js +2 -2
  47. package/tools/get-crypto-metrics.js +14 -4
  48. package/tools/get-cvd.js +2 -2
  49. package/tools/get-divergences.js +2 -2
  50. package/tools/get-funding-context.js +2 -2
  51. package/tools/get-liquidation-levels.js +2 -2
  52. package/tools/get-liquidation-pulse.js +2 -2
  53. package/tools/get-pattern-scan.js +2 -2
  54. package/tools/get-regime.js +2 -2
  55. package/tools/get-resting-liquidity.js +2 -2
  56. package/tools/get-risk-scenario.js +2 -2
  57. package/tools/get-session-review.js +2 -2
  58. package/tools/get-setup-detail.js +9 -1
  59. package/tools/get-signals.js +2 -2
  60. package/tools/get-sizing.js +2 -2
  61. package/tools/get-trade-feedback.js +2 -2
  62. package/tools/get-trade-flow.js +2 -2
  63. package/tools/get-volume-profile.js +2 -2
  64. package/tools/get-wave9-status.d.ts +127 -0
  65. package/tools/get-wave9-status.js +796 -0
  66. package/tools/intel-api.d.ts +20 -0
  67. package/tools/intel-api.js +67 -0
  68. package/tools/intel-cache.d.ts +1 -1
  69. package/tools/intel-cache.js +20 -5
  70. package/tools/list-strategies.d.ts +11 -1
  71. package/tools/list-strategies.js +17 -0
  72. package/tools/modify-stop.d.ts +4 -0
  73. package/tools/modify-stop.js +63 -24
  74. package/tools/modify-target.d.ts +4 -0
  75. package/tools/modify-target.js +62 -23
  76. package/tools/scan-pairs.js +19 -8
  77. package/tools/toggle-strategy.js +7 -0
  78. package/types.d.ts +5 -0
  79. package/venues/hyperliquid/hl-balance.d.ts +116 -0
  80. package/venues/hyperliquid/hl-balance.js +145 -0
  81. package/venues/hyperliquid/hl-brackets.d.ts +102 -0
  82. package/venues/hyperliquid/hl-brackets.js +172 -0
  83. package/venues/hyperliquid/hl-cloid.d.ts +22 -0
  84. package/venues/hyperliquid/hl-cloid.js +82 -0
  85. package/venues/hyperliquid/hl-info-cache.d.ts +46 -0
  86. package/venues/hyperliquid/hl-info-cache.js +125 -0
  87. package/venues/hyperliquid/hl-live-adapter.d.ts +88 -0
  88. package/venues/hyperliquid/hl-live-adapter.js +353 -0
  89. package/venues/hyperliquid/hl-precision.d.ts +61 -0
  90. package/venues/hyperliquid/hl-precision.js +176 -0
  91. package/venues/hyperliquid/hl-private.d.ts +88 -0
  92. package/venues/hyperliquid/hl-private.js +357 -0
  93. package/venues/hyperliquid/hl-public.d.ts +31 -4
  94. package/venues/hyperliquid/hl-public.js +155 -11
  95. package/venues/hyperliquid/hl-rate-gate.d.ts +57 -0
  96. package/venues/hyperliquid/hl-rate-gate.js +220 -0
  97. package/venues/hyperliquid/hl-user-stream.d.ts +90 -0
  98. package/venues/hyperliquid/hl-user-stream.js +220 -0
  99. package/venues/registry.d.ts +23 -9
  100. package/venues/registry.js +12 -13
  101. package/venues/symbols.d.ts +43 -0
  102. package/venues/symbols.js +107 -0
  103. package/wave9/live-account-capture.d.ts +67 -0
  104. package/wave9/live-account-capture.js +435 -0
  105. package/wave9/live-autonomous-protection.d.ts +39 -0
  106. package/wave9/live-autonomous-protection.js +112 -0
  107. package/wave9/live-durable-reconciliation-scheduler.d.ts +33 -0
  108. package/wave9/live-durable-reconciliation-scheduler.js +115 -0
  109. package/wave9/live-execution-ledger.d.ts +107 -0
  110. package/wave9/live-execution-ledger.js +498 -0
  111. package/wave9/live-position-confirmation.d.ts +18 -0
  112. package/wave9/live-position-confirmation.js +111 -0
  113. package/wave9/live-residual-protection.d.ts +18 -0
  114. package/wave9/live-residual-protection.js +250 -0
  115. package/wave9/live-startup-reconciliation.d.ts +38 -0
  116. package/wave9/live-startup-reconciliation.js +454 -0
  117. package/wave9/live-symbol-ownership.d.ts +20 -0
  118. package/wave9/live-symbol-ownership.js +132 -0
  119. package/wave9/paper-admission-guard.d.ts +199 -0
  120. package/wave9/paper-admission-guard.js +650 -0
  121. package/wave9/usdm-evidence-provider.d.ts +42 -0
  122. package/wave9/usdm-evidence-provider.js +133 -0
@@ -0,0 +1,42 @@
1
+ import type { OhlcvBar } from '../signals/types.js';
2
+ export declare const FOUR_HOURS_MS: number;
3
+ export declare const FUNDING_INTERVAL_MS: number;
4
+ /** Binance has emitted historical funding timestamps three milliseconds after
5
+ * the nominal settlement boundary. Accept only tightly bounded source jitter,
6
+ * then canonicalize back to the exact research event identity. */
7
+ export declare const FUNDING_TIME_TOLERANCE_MS = 10;
8
+ export interface Wave9FundingSettlement {
9
+ time: Date;
10
+ rate: number;
11
+ }
12
+ export interface Wave9SymbolEvidence {
13
+ symbol: string;
14
+ venueSymbol: string;
15
+ dailyBars: OhlcvBar[];
16
+ fourHourBars: OhlcvBar[];
17
+ fundingSettlements: Wave9FundingSettlement[];
18
+ }
19
+ export interface Wave9EvidenceBatch {
20
+ venue: 'binance_usdm';
21
+ marketType: 'future';
22
+ eventTime: Date;
23
+ evidenceFromExclusive: Date;
24
+ symbols: Wave9SymbolEvidence[];
25
+ }
26
+ interface UsdmExchange {
27
+ id?: string;
28
+ options?: Record<string, unknown>;
29
+ fetchOHLCV(symbol: string, timeframe: string, since?: number, limit?: number): Promise<unknown[]>;
30
+ fetchFundingRateHistory(symbol: string, since?: number, limit?: number): Promise<unknown[]>;
31
+ }
32
+ export interface Wave9EvidenceProvider {
33
+ fetchAtomicBatch(eventTime: Date): Promise<Wave9EvidenceBatch>;
34
+ }
35
+ export declare class BinanceUsdmWave9EvidenceProvider implements Wave9EvidenceProvider {
36
+ private readonly exchange;
37
+ constructor(exchange: UsdmExchange);
38
+ fetchAtomicBatch(eventTime: Date): Promise<Wave9EvidenceBatch>;
39
+ }
40
+ /** Deliberately lazy: off mode imports this module but never loads/creates CCXT. */
41
+ export declare function createWave9UsdmEvidenceProvider(): Wave9EvidenceProvider;
42
+ export {};
@@ -0,0 +1,133 @@
1
+ import { createRequire } from 'node:module';
2
+ import { DAY_MS, WAVE9_CONTEXT_BARS, WAVE9_SYMBOL_PRIORITY, } from '../portfolio/wave9-policy.js';
3
+ export const FOUR_HOURS_MS = 4 * 60 * 60 * 1_000;
4
+ export const FUNDING_INTERVAL_MS = 8 * 60 * 60 * 1_000;
5
+ /** Binance has emitted historical funding timestamps three milliseconds after
6
+ * the nominal settlement boundary. Accept only tightly bounded source jitter,
7
+ * then canonicalize back to the exact research event identity. */
8
+ export const FUNDING_TIME_TOLERANCE_MS = 10;
9
+ function venueSymbol(symbol) {
10
+ if (!symbol.endsWith('USDT'))
11
+ throw new Error(`unsupported Wave 9 symbol ${symbol}`);
12
+ return `${symbol.slice(0, -4)}/USDT:USDT`;
13
+ }
14
+ function ohlcvRows(rows, label) {
15
+ return rows.map((raw, index) => {
16
+ if (!Array.isArray(raw) || raw.length < 6) {
17
+ throw new Error(`${label} row ${index} is not a complete OHLCV tuple`);
18
+ }
19
+ const values = raw.slice(0, 6).map(Number);
20
+ if (!values.every(Number.isFinite)) {
21
+ throw new Error(`${label} row ${index} contains a non-finite value`);
22
+ }
23
+ const [time, open, high, low, close, volume] = values;
24
+ if (open <= 0 || high <= 0 || low <= 0 || close <= 0 || volume < 0) {
25
+ throw new Error(`${label} row ${index} has invalid market values`);
26
+ }
27
+ if (high < Math.max(open, close) || low > Math.min(open, close)) {
28
+ throw new Error(`${label} row ${index} has invalid OHLC geometry`);
29
+ }
30
+ return { time: new Date(time), open, high, low, close, volume };
31
+ });
32
+ }
33
+ function fundingRows(rows, label) {
34
+ return rows.map((raw, index) => {
35
+ const row = raw;
36
+ const info = row?.info;
37
+ const time = Number(row?.timestamp ?? info?.fundingTime);
38
+ const rate = Number(row?.fundingRate ?? info?.fundingRate);
39
+ if (!Number.isFinite(time) || !Number.isFinite(rate)) {
40
+ throw new Error(`${label} funding row ${index} is incomplete`);
41
+ }
42
+ return { time: new Date(time), rate };
43
+ });
44
+ }
45
+ function requireExactTimes(actual, expected, label) {
46
+ const times = actual.map((row) => row.time.getTime());
47
+ if (times.length !== expected.length || times.some((time, index) => time !== expected[index])) {
48
+ throw new Error(`${label} is partial or stale: expected [${expected.map((time) => new Date(time).toISOString()).join(', ')}], got [${times.map((time) => new Date(time).toISOString()).join(', ')}]`);
49
+ }
50
+ }
51
+ function canonicalizeFundingTimes(actual, expected, label) {
52
+ const times = actual.map((row) => row.time.getTime());
53
+ const mismatched = times.length !== expected.length
54
+ || times.some((time, index) => Math.abs(time - expected[index]) > FUNDING_TIME_TOLERANCE_MS);
55
+ if (mismatched) {
56
+ throw new Error(`${label} is partial or stale: expected [${expected.map((time) => new Date(time).toISOString()).join(', ')}] `
57
+ + `within ${FUNDING_TIME_TOLERANCE_MS}ms, got [${times.map((time) => new Date(time).toISOString()).join(', ')}]`);
58
+ }
59
+ return actual.map((row, index) => ({ ...row, time: new Date(expected[index]) }));
60
+ }
61
+ export class BinanceUsdmWave9EvidenceProvider {
62
+ exchange;
63
+ constructor(exchange) {
64
+ this.exchange = exchange;
65
+ if (exchange.id !== 'binanceusdm' || exchange.options?.defaultType !== 'future') {
66
+ throw new Error('Wave 9 evidence provider requires Binance USD-M futures (binanceusdm/defaultType=future)');
67
+ }
68
+ }
69
+ async fetchAtomicBatch(eventTime) {
70
+ const eventMs = eventTime.getTime();
71
+ if (!Number.isFinite(eventMs) || eventMs % DAY_MS !== 0) {
72
+ throw new Error('Wave 9 event must be a UTC daily boundary');
73
+ }
74
+ const fromMs = eventMs - DAY_MS;
75
+ const expectedDaily = Array.from({ length: WAVE9_CONTEXT_BARS }, (_, index) => eventMs - (WAVE9_CONTEXT_BARS - index) * DAY_MS);
76
+ const expected4h = Array.from({ length: 7 }, (_, index) => fromMs + index * FOUR_HOURS_MS);
77
+ const expectedFunding = [fromMs + FUNDING_INTERVAL_MS, fromMs + 2 * FUNDING_INTERVAL_MS, eventMs];
78
+ // Promise.all is only a transport optimization. No caller sees a batch
79
+ // unless every one of the eight frozen symbols validates in full.
80
+ const symbols = await Promise.all(WAVE9_SYMBOL_PRIORITY.map(async (symbol) => {
81
+ const ccxtSymbol = venueSymbol(symbol);
82
+ const [dailyRaw, fourHourRaw, fundingRaw] = await Promise.all([
83
+ this.exchange.fetchOHLCV(ccxtSymbol, '1d', eventMs - (WAVE9_CONTEXT_BARS + 2) * DAY_MS, WAVE9_CONTEXT_BARS + 2),
84
+ this.exchange.fetchOHLCV(ccxtSymbol, '4h', fromMs, 7),
85
+ this.exchange.fetchFundingRateHistory(ccxtSymbol, fromMs + 1, 16),
86
+ ]);
87
+ const dailyBars = ohlcvRows(dailyRaw, `${symbol} 1d`)
88
+ .filter((bar) => bar.time.getTime() + DAY_MS <= eventMs)
89
+ .slice(-WAVE9_CONTEXT_BARS);
90
+ const fourHourBars = ohlcvRows(fourHourRaw, `${symbol} 4h`)
91
+ .filter((bar) => bar.time.getTime() >= fromMs && bar.time.getTime() <= eventMs)
92
+ .sort((left, right) => left.time.getTime() - right.time.getTime());
93
+ const fundingRowsInWindow = fundingRows(fundingRaw, symbol)
94
+ .filter((row) => row.time.getTime() > fromMs
95
+ && row.time.getTime() <= eventMs + FUNDING_TIME_TOLERANCE_MS)
96
+ .sort((left, right) => left.time.getTime() - right.time.getTime());
97
+ requireExactTimes(dailyBars, expectedDaily, `${symbol} completed 1d evidence`);
98
+ requireExactTimes(fourHourBars, expected4h, `${symbol} 4h evidence`);
99
+ const fundingSettlements = canonicalizeFundingTimes(fundingRowsInWindow, expectedFunding, `${symbol} funding evidence`);
100
+ return {
101
+ symbol,
102
+ venueSymbol: ccxtSymbol,
103
+ dailyBars,
104
+ fourHourBars,
105
+ fundingSettlements,
106
+ };
107
+ }));
108
+ if (symbols.some((row, index) => row.symbol !== WAVE9_SYMBOL_PRIORITY[index])) {
109
+ throw new Error('Wave 9 evidence universe/order mismatch');
110
+ }
111
+ return {
112
+ venue: 'binance_usdm',
113
+ marketType: 'future',
114
+ eventTime: new Date(eventMs),
115
+ evidenceFromExclusive: new Date(fromMs),
116
+ symbols,
117
+ };
118
+ }
119
+ }
120
+ /** Deliberately lazy: off mode imports this module but never loads/creates CCXT. */
121
+ export function createWave9UsdmEvidenceProvider() {
122
+ const require = createRequire(import.meta.url);
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
+ const ccxt = require('ccxt');
125
+ const BinanceUsdm = ccxt.binanceusdm ?? ccxt.default?.binanceusdm;
126
+ if (!BinanceUsdm)
127
+ throw new Error('CCXT binanceusdm class is unavailable');
128
+ const exchange = new BinanceUsdm({
129
+ enableRateLimit: true,
130
+ options: { defaultType: 'future' },
131
+ });
132
+ return new BinanceUsdmWave9EvidenceProvider(exchange);
133
+ }