@reefclaw/openclaw-plugin 0.1.10 → 0.1.11

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.
@@ -1,9 +1,23 @@
1
- import { GatewayHttpClient } from './gateway-http-client.js';
1
+ import { GatewayHttpClient, GatewayHttpError } from './gateway-http-client.js';
2
2
  /**
3
3
  * Logical tool names used by ReefClaw internally.
4
4
  * Each maps to one or more candidate actual tool names on the gateway.
5
5
  */
6
6
  export type LogicalTool = 'fetch_ticker' | 'fetch_balance' | 'fetch_ohlcv' | 'fetch_positions' | 'fetch_open_orders' | 'cancel_all_orders' | 'cancel_order' | 'close_position' | 'create_order' | 'get_market_structure' | 'get_crypto_metrics' | 'get_market_intel' | 'set_trading_mode' | 'set_exchange_credentials' | 'test_exchange_credentials' | 'clear_exchange_credentials' | 'get_bracket_config' | 'set_bracket_requirement';
7
+ /**
8
+ * Build the test args used when probing each logical tool.
9
+ *
10
+ * Read tools (ticker, ohlcv, market structure, …) use the CONFIGURED symbol so
11
+ * the probe is venue-correct — the old hardcoded 'BTC/USDT' made every probe
12
+ * throw on a Hyperliquid-venue box ("not USDC-quoted"), which dropped the
13
+ * tools whose probes throw (fetch_open_orders, cancel_all_orders) and left the
14
+ * bridge retrying discovery every 30s forever (observed live on the HL rig,
15
+ * 2026-07-24).
16
+ *
17
+ * Destructive-capable tools (cancel_all_orders, close_position) probe with the
18
+ * PROBE_SENTINEL_SYMBOL so they can never execute against real state.
19
+ */
20
+ export declare function buildProbeArgs(symbol?: string): Record<LogicalTool, Record<string, unknown>>;
7
21
  /** Map of logical tool names to their discovered actual tool names on the gateway */
8
22
  export type ToolMap = Partial<Record<LogicalTool, string>>;
9
23
  export interface DiscoveryResult {
@@ -16,10 +30,15 @@ export interface DiscoveryResult {
16
30
  /** Logical names of optional tools that are missing */
17
31
  missingOptional: LogicalTool[];
18
32
  }
33
+ /** True when an envelope-level (HTTP 200, ok:false) error denotes an unknown
34
+ * tool name rather than a tool that executed and failed. Exported for tests. */
35
+ export declare function isUnknownToolEnvelopeError(err: GatewayHttpError): boolean;
19
36
  /**
20
37
  * Discover all available trading tools on the gateway.
21
38
  *
22
39
  * Probes required tools first, then optional tools in parallel.
23
40
  * Fails fast if no required tools are found.
24
41
  */
25
- export declare function discoverTools(http: GatewayHttpClient): Promise<DiscoveryResult>;
42
+ export declare function discoverTools(http: GatewayHttpClient, opts?: {
43
+ symbol?: string;
44
+ }): Promise<DiscoveryResult>;
@@ -47,53 +47,109 @@ const CANDIDATES = {
47
47
  get_bracket_config: ['get_bracket_config'],
48
48
  set_bracket_requirement: ['set_bracket_requirement'],
49
49
  };
50
+ /** Default probe symbol when the caller does not supply the configured one.
51
+ * Kept for back-compat with pre-symbol callers; real deployments should pass
52
+ * the configured symbol so probes are venue-correct (see buildProbeArgs). */
53
+ const DEFAULT_PROBE_SYMBOL = 'BTC/USDT';
54
+ /** Sentinel symbol for probes of DESTRUCTIVE-CAPABLE tools. It never resolves
55
+ * to a market on any venue, so the probe can never touch a real order or
56
+ * position: the tool executes, fails fast client-side, and the envelope-level
57
+ * error still proves the tool exists (see probeCandidate).
58
+ *
59
+ * ★ Why this exists (2026-07-24): cancel_all_orders was probed with a REAL
60
+ * symbol — a valid, executable cancel-all sweep. On a live box with a resting
61
+ * working order, every bridge restart (and every 30s discovery retry) would
62
+ * silently cancel it. A probe must never be an order-book mutation. */
63
+ const PROBE_SENTINEL_SYMBOL = '__probe__';
50
64
  /**
51
- * Test args used when probing each logical tool.
52
- * Read tools (ticker, balance, etc.) use real args that return data.
53
- * Write tools (create_order, cancel, close) use args that will be
54
- * rejected by exchange validation (amount:0, etc.) we only need
55
- * to distinguish 400 (tool exists, bad args) from 404 (tool not found).
65
+ * Build the test args used when probing each logical tool.
66
+ *
67
+ * Read tools (ticker, ohlcv, market structure, …) use the CONFIGURED symbol so
68
+ * the probe is venue-correct the old hardcoded 'BTC/USDT' made every probe
69
+ * throw on a Hyperliquid-venue box ("not USDC-quoted"), which dropped the
70
+ * tools whose probes throw (fetch_open_orders, cancel_all_orders) and left the
71
+ * bridge retrying discovery every 30s forever (observed live on the HL rig,
72
+ * 2026-07-24).
73
+ *
74
+ * Destructive-capable tools (cancel_all_orders, close_position) probe with the
75
+ * PROBE_SENTINEL_SYMBOL so they can never execute against real state.
56
76
  */
57
- const PROBE_ARGS = {
58
- fetch_ticker: { symbol: 'BTC/USDT' },
59
- fetch_balance: {},
60
- fetch_ohlcv: { symbol: 'BTC/USDT', timeframe: '1h', limit: 1 },
61
- fetch_positions: { symbol: 'BTC/USDT' },
62
- fetch_open_orders: { symbol: 'BTC/USDT' },
63
- // For write tools: probe with minimal args. We expect 400 (bad args) = tool exists.
64
- cancel_all_orders: { symbol: 'BTC/USDT' },
65
- cancel_order: { id: 'probe-0', symbol: 'BTC/USDT' },
66
- close_position: { symbol: 'BTC/USDT' },
67
- create_order: { symbol: 'BTC/USDT', type: 'limit', side: 'buy', amount: 0, price: 0 },
68
- get_market_structure: { symbol: 'BTC/USDT' },
69
- get_crypto_metrics: { symbol: 'BTC/USDT' },
70
- get_market_intel: { category: 'sentiment' },
71
- // Safe probe args plugin tools early-return on invalid input without
72
- // touching disk. `mode: '__probe__'` fails the VALID_MODES check; empty
73
- // strings fail the length-8 validator in set_exchange_credentials. Both
74
- // return HTTP 200 with ok:false, which the probe treats as "tool exists".
75
- set_trading_mode: { mode: '__probe__' },
76
- set_exchange_credentials: { apiKey: '', secret: '' },
77
- // test_exchange_credentials: empty strings fail the length check and
78
- // early-return without hitting Binance.
79
- test_exchange_credentials: { apiKey: '', secret: '' },
80
- // clear_exchange_credentials: tool requires confirm:true. Probing without
81
- // it triggers the safety gate early-return tool exists, nothing wiped.
82
- clear_exchange_credentials: {},
83
- // Bracket-config probes: no-arg read; set with an invalid flag triggers early-return.
84
- get_bracket_config: {},
85
- set_bracket_requirement: { flag: '__probe__', value: false },
86
- };
77
+ export function buildProbeArgs(symbol = DEFAULT_PROBE_SYMBOL) {
78
+ return {
79
+ fetch_ticker: { symbol },
80
+ fetch_balance: {},
81
+ fetch_ohlcv: { symbol, timeframe: '1h', limit: 1 },
82
+ fetch_positions: { symbol },
83
+ fetch_open_orders: { symbol },
84
+ // NEVER a real symbol: a cancel-all probe with a real symbol is a real
85
+ // cancel-all. The sentinel fails symbol resolution before any order is
86
+ // touched; the resulting envelope error still counts as "tool exists".
87
+ cancel_all_orders: { symbol: PROBE_SENTINEL_SYMBOL },
88
+ // cancel_order: nonexistent id order-not-found error, nothing cancelled.
89
+ cancel_order: { id: 'probe-0', symbol },
90
+ // Sentinel for the same reason: close_position with a real symbol and an
91
+ // open position could market-close it (the close-discipline validator is a
92
+ // live-mode reason gate, not a guarantee on every mode/venue/version).
93
+ close_position: { symbol: PROBE_SENTINEL_SYMBOL },
94
+ // amount 0 is rejected by order validation before reaching any exchange.
95
+ create_order: { symbol, type: 'limit', side: 'buy', amount: 0, price: 0 },
96
+ get_market_structure: { symbol },
97
+ get_crypto_metrics: { symbol },
98
+ get_market_intel: { category: 'sentiment' },
99
+ // Safe probe args plugin tools early-return on invalid input without
100
+ // touching disk. `mode: '__probe__'` fails the VALID_MODES check; empty
101
+ // strings fail the length-8 validator in set_exchange_credentials. Both
102
+ // return HTTP 200 with ok:false, which the probe treats as "tool exists".
103
+ set_trading_mode: { mode: '__probe__' },
104
+ set_exchange_credentials: { apiKey: '', secret: '' },
105
+ // test_exchange_credentials: empty strings fail the length check and
106
+ // early-return without hitting Binance.
107
+ test_exchange_credentials: { apiKey: '', secret: '' },
108
+ // clear_exchange_credentials: tool requires confirm:true. Probing without
109
+ // it triggers the safety gate early-return — tool exists, nothing wiped.
110
+ clear_exchange_credentials: {},
111
+ // Bracket-config probes: no-arg read; set with an invalid flag triggers early-return.
112
+ get_bracket_config: {},
113
+ set_bracket_requirement: { flag: '__probe__', value: false },
114
+ };
115
+ }
87
116
  // ---- Discovery logic ----
117
+ /** Envelope-level error messages that mean "the gateway does not have this
118
+ * tool" (as opposed to "the tool executed and failed"). Matched against the
119
+ * error message + body of a 200-status GatewayHttpError.
120
+ *
121
+ * The name-not-found pattern requires a QUOTED tool name ("tool 'x' not
122
+ * found") — a bare `tool .* not found` would false-positive on legitimate
123
+ * execution errors like cancel_order's "Tool invoke failed: Order probe-0
124
+ * not found" (the probe's EXPECTED failure) and drop the tool. */
125
+ const UNKNOWN_TOOL_RE = /unknown tool|tool ['"][^'"]*['"] (?:not found|does not exist)|no such tool|is not registered|tool_not_found|unavailable tool|not in allowlist/i;
126
+ /** True when an envelope-level (HTTP 200, ok:false) error denotes an unknown
127
+ * tool name rather than a tool that executed and failed. Exported for tests. */
128
+ export function isUnknownToolEnvelopeError(err) {
129
+ const haystack = `${err.message} ${JSON.stringify(err.body ?? '')}`;
130
+ return UNKNOWN_TOOL_RE.test(haystack);
131
+ }
88
132
  /**
89
133
  * Probe a single candidate tool name. Returns true if the tool exists.
90
134
  *
135
+ * ★ "Exists" means the invocation REACHED the tool — not that it succeeded.
136
+ * A tool that executed and threw (venue mismatch, transient rate limit, a
137
+ * refused destructive call) absolutely exists; dropping it from the toolMap
138
+ * was the 2026-07-24 HL-rig bug (fetch_open_orders/cancel_all_orders throw on
139
+ * a probe error → "missing" forever → 30s discovery-retry loop + emergency
140
+ * controls degraded).
141
+ *
91
142
  * Strategy:
92
- * - 200: tool exists and invocation succeeded
93
- * - 400: tool exists but args were bad (still counts as found)
143
+ * - 200 parsed OK: exists and works
144
+ * - 400: exists, bad args
145
+ * - 200 + envelope ok:false: the tool EXECUTED and failed → exists — unless
146
+ * the envelope error says the tool name itself is unknown (gateways that
147
+ * report unknown tools in-envelope instead of via 404)
148
+ * - >=500: the tool executed and threw server-side → exists
94
149
  * - 404: tool does not exist
95
150
  * - 401: auth error — rethrow (don't mask)
96
- * - Other: treat as not found
151
+ * - network error / timeout (status 0): unknown — treat as not found, the
152
+ * discovery retry loop will re-probe
97
153
  */
98
154
  async function probeCandidate(http, candidateName, args) {
99
155
  try {
@@ -108,6 +164,15 @@ async function probeCandidate(http, candidateName, args) {
108
164
  return false; // Tool not found
109
165
  if (err.status === 401)
110
166
  throw err; // Auth error — fatal
167
+ if (err.status === 200) {
168
+ // Envelope-level failure: the HTTP layer accepted the call. Either the
169
+ // tool executed and failed (exists) or the gateway rejected an unknown
170
+ // tool name in-envelope (not found). Candidate order protects the
171
+ // ambiguous case: the real plugin name is probed before any alias.
172
+ return !isUnknownToolEnvelopeError(err);
173
+ }
174
+ if (err.status >= 500)
175
+ return true; // Tool executed and threw
111
176
  }
112
177
  return false;
113
178
  }
@@ -116,9 +181,9 @@ async function probeCandidate(http, candidateName, args) {
116
181
  * Discover the actual tool name for a logical tool by probing candidates in order.
117
182
  * Returns the first candidate that exists, or null if none found.
118
183
  */
119
- async function discoverTool(http, logical) {
184
+ async function discoverTool(http, logical, probeArgs) {
120
185
  const candidates = CANDIDATES[logical];
121
- const args = PROBE_ARGS[logical];
186
+ const args = probeArgs[logical];
122
187
  for (const candidate of candidates) {
123
188
  logger.debug(TAG, `Probing ${candidate} for ${logical}...`);
124
189
  const exists = await probeCandidate(http, candidate, args);
@@ -135,15 +200,16 @@ async function discoverTool(http, logical) {
135
200
  * Probes required tools first, then optional tools in parallel.
136
201
  * Fails fast if no required tools are found.
137
202
  */
138
- export async function discoverTools(http) {
203
+ export async function discoverTools(http, opts) {
139
204
  logger.info(TAG, 'Starting tool auto-discovery...');
205
+ const probeArgs = buildProbeArgs(opts?.symbol);
140
206
  const toolMap = {};
141
207
  const found = [];
142
208
  const missingRequired = [];
143
209
  const missingOptional = [];
144
210
  // Discover required tools first (sequentially to fail fast on auth errors)
145
211
  for (const logical of REQUIRED_TOOLS) {
146
- const actual = await discoverTool(http, logical);
212
+ const actual = await discoverTool(http, logical, probeArgs);
147
213
  if (actual) {
148
214
  toolMap[logical] = actual;
149
215
  found.push(logical);
@@ -167,7 +233,7 @@ export async function discoverTools(http) {
167
233
  }
168
234
  // Discover optional tools in parallel
169
235
  const optionalResults = await Promise.allSettled(OPTIONAL_TOOLS.map(async (logical) => {
170
- const actual = await discoverTool(http, logical);
236
+ const actual = await discoverTool(http, logical, probeArgs);
171
237
  return { logical, actual };
172
238
  }));
173
239
  for (const result of optionalResults) {
@@ -14,6 +14,17 @@ export declare function shouldAnchorSessionNav(args: {
14
14
  today: string;
15
15
  mode: TradingMode;
16
16
  }): boolean;
17
+ /** Decide whether to adopt the plugin-provided sessionStartNav from a balance
18
+ * response. Pure so it can be unit-tested without the full provider.
19
+ *
20
+ * ★ Deliberately MODE-INDEPENDENT: the plugin's anchor is authoritative in
21
+ * every mode — live/shadow anchor to the exchange income/day-anchor, and
22
+ * PAPER's simulator seeds + midnight-rolls its own anchor in state.json (the
23
+ * same value its pre-trade risk gate reads). The pre-2026-07-24 non-PAPER
24
+ * gate left paper with a SECOND, skill-computed anchor; on a customer box the
25
+ * two diverged (13942 vs 10024) and the skill auto-flattened a FLAT account
26
+ * at a phantom −27.81% drawdown while the plugin's own view was GREEN. */
27
+ export declare function shouldSyncPluginSessionNav(pluginNav: unknown, currentNav: number): pluginNav is number;
17
28
  export declare class GatewayProvider implements OpenClawProvider {
18
29
  private readonly config;
19
30
  private http;
@@ -49,6 +49,21 @@ export function shouldAnchorSessionNav(args) {
49
49
  return true; // never anchored
50
50
  return args.mode === 'PAPER' && args.sessionDate !== args.today; // paper midnight rollover
51
51
  }
52
+ /** Decide whether to adopt the plugin-provided sessionStartNav from a balance
53
+ * response. Pure so it can be unit-tested without the full provider.
54
+ *
55
+ * ★ Deliberately MODE-INDEPENDENT: the plugin's anchor is authoritative in
56
+ * every mode — live/shadow anchor to the exchange income/day-anchor, and
57
+ * PAPER's simulator seeds + midnight-rolls its own anchor in state.json (the
58
+ * same value its pre-trade risk gate reads). The pre-2026-07-24 non-PAPER
59
+ * gate left paper with a SECOND, skill-computed anchor; on a customer box the
60
+ * two diverged (13942 vs 10024) and the skill auto-flattened a FLAT account
61
+ * at a phantom −27.81% drawdown while the plugin's own view was GREEN. */
62
+ export function shouldSyncPluginSessionNav(pluginNav, currentNav) {
63
+ return typeof pluginNav === 'number'
64
+ && pluginNav > 0
65
+ && Math.abs(currentNav - pluginNav) > 0.001;
66
+ }
52
67
  function loadSessionStartNav() {
53
68
  for (const path of [getDayNavPath(), getLegacyDayNavPath()]) {
54
69
  try {
@@ -831,8 +846,11 @@ export class GatewayProvider {
831
846
  else {
832
847
  logger.warn(TAG, 'No device token from WS handshake — REST calls may fail (using raw gateway token)');
833
848
  }
834
- // Step 4: Discover available tools (async — check for stop() after)
835
- const discovery = await discoverTools(this.http);
849
+ // Step 4: Discover available tools (async — check for stop() after).
850
+ // Pass the configured symbol so probes are venue-correct — a hardcoded
851
+ // BTC/USDT probe throws on a Hyperliquid-venue plugin and silently drops
852
+ // the tools whose probes throw (2026-07-24 HL-rig bug).
853
+ const discovery = await discoverTools(this.http, { symbol: this.config.symbol });
836
854
  if (!this.started) {
837
855
  logger.info(TAG, 'Stopped during tool discovery — aborting initialization');
838
856
  this.http = null;
@@ -975,7 +993,7 @@ export class GatewayProvider {
975
993
  try {
976
994
  // Capture http ref before await — stop() can nullify it
977
995
  const http = this.http;
978
- const discovery = await discoverTools(http);
996
+ const discovery = await discoverTools(http, { symbol: this.config.symbol });
979
997
  // Guard: stop() may have been called during async discovery
980
998
  if (!this.started || !this.http)
981
999
  return;
@@ -1653,23 +1671,32 @@ export class GatewayProvider {
1653
1671
  if (typeof result.data.equity === 'number') {
1654
1672
  this.equity = result.data.equity;
1655
1673
  }
1656
- // In non-PAPER modes, the plugin anchors sessionStartNav to Binance's
1657
- // /fapi/v1/income at UTC midnight on every balance fetch — that's the
1658
- // authoritative truth. Sync continuously, not just on first set: the
1659
- // pre-2026-05-14 guard `this.sessionStartNav < 0` meant once the skill
1660
- // had ANY value (from file load or computeEquity), the plugin's correct
1661
- // value was ignored forever. The skill's self-computed value drifts
1662
- // whenever trading has already happened before the skill first polls
1663
- // (operator screenshot 2026-05-14 found a $3.92 dashboard-vs-Binance
1664
- // gap from a $1095.95 self-computed seed vs the plugin's $1099.86
1665
- // midnight-anchored truth). Crossing UTC midnight is also handled
1666
- // automatically plugin's anchor refreshes, skill syncs next poll.
1667
- if (this.tradingMode !== 'PAPER') {
1674
+ // The plugin's sessionStartNav is the authoritative day anchor in EVERY
1675
+ // mode, so sync continuously whenever it provides one:
1676
+ // - live/shadow: anchored to Binance's /fapi/v1/income at UTC midnight
1677
+ // (or the HL day-anchor reconstruction) — the 2026-05-14 lesson: the
1678
+ // skill's self-computed value drifts whenever trading happened before
1679
+ // the skill first polled ($1095.95 self-seed vs the plugin's $1099.86
1680
+ // income-anchored truth = a $3.92 dashboard-vs-Binance gap).
1681
+ // - PAPER: the simulator seeds + midnight-rolls its own anchor in
1682
+ // state.json and its pre-trade risk gate reads THAT value. The skill
1683
+ // previously kept a SECOND, self-computed paper anchor here — two
1684
+ // anchors for one number. On a customer box (2026-07-24) the skill's
1685
+ // boot-seeded 13942 diverged from the plugin's 10024 and the skill's
1686
+ // RED-zone math auto-flattened a FLAT account at a phantom −27.81%
1687
+ // while the plugin's own view was GREEN. One anchor, one truth.
1688
+ // Crossing UTC midnight is handled automatically — the plugin's anchor
1689
+ // refreshes, the skill syncs next poll. The skill's self-seed
1690
+ // (trySetSessionStartNav) remains only as a fallback for plugins too old
1691
+ // to emit sessionStartNav.
1692
+ {
1668
1693
  const pluginNav = result.data.sessionStartNav;
1669
- if (typeof pluginNav === 'number' && pluginNav > 0
1670
- && Math.abs(this.sessionStartNav - pluginNav) > 0.001) {
1694
+ if (shouldSyncPluginSessionNav(pluginNav, this.sessionStartNav)) {
1671
1695
  const prev = this.sessionStartNav;
1672
1696
  this.sessionStartNav = pluginNav;
1697
+ // Stamp the day so the PAPER self-seed path (shouldAnchorSessionNav
1698
+ // re-anchors on a stale sessionDate) doesn't flap against the sync.
1699
+ this.sessionDate = todayDateStr();
1673
1700
  saveSessionStartNav(pluginNav);
1674
1701
  logger.info(TAG, `Session start NAV synced from plugin: ${prev.toFixed(4)} -> ${pluginNav} (${this.tradingMode} mode)`);
1675
1702
  }
package/index.js CHANGED
@@ -22,6 +22,7 @@ import { DEFAULT_CONFIG } from './types.js';
22
22
  import { PaperAdapter } from './paper-adapter.js';
23
23
  import { LiveAdapter, } from './live/live-adapter.js';
24
24
  import { createLiveAdapter, fillExchangeId, isLiveVenueSupported, parseVenue, venueQuoteCurrency, } from './venues/registry.js';
25
+ import { resolvePluginSymbol } from './venues/symbols.js';
25
26
  import { HyperliquidPublicApi } from './venues/hyperliquid/hl-public.js';
26
27
  import { bracketsEnabled, loadBracketMode } from './config/brackets-config.js';
27
28
  import { loadUserDataStreamMode, loadUserDataStreamTunables, loadUserDataStreamDbWrite, getUserDataStreamIngestBaseUrl, resolveIngestToken, resolveReefclawUserId, } from './config/user-data-stream-config.js';
@@ -909,15 +910,22 @@ const paperTradingPlugin = {
909
910
  // rules, and an unreadable config falls back to the binance default
910
911
  // exactly like the main read does.
911
912
  let paperQuoteCurrency = DEFAULT_CONFIG.quoteCurrency;
913
+ let peekedVenue = 'binance';
912
914
  try {
913
- paperQuoteCurrency = venueQuoteCurrency(parseVenue(readPluginConfig().exchange?.venue).venue);
915
+ peekedVenue = parseVenue(readPluginConfig().exchange?.venue).venue;
916
+ paperQuoteCurrency = venueQuoteCurrency(peekedVenue);
914
917
  }
915
918
  catch {
916
919
  /* unreadable plugin-config → binance default, matching the main read */
917
920
  }
918
921
  const pluginConfig = {
919
922
  startingBalance: DEFAULT_CONFIG.startingBalance,
920
- symbol: DEFAULT_CONFIG.symbol,
923
+ // Symbol resolution (2026-07-24): honor the openclaw.json entry config
924
+ // (api.config.symbol — declared in configSchema but previously IGNORED),
925
+ // falling back to the VENUE's default (BTC/USDC on hyperliquid). The old
926
+ // venue-blind DEFAULT_CONFIG.symbol hardcode gave every in-plugin
927
+ // consumer on a hyperliquid box a symbol its own venue rejects.
928
+ symbol: resolvePluginSymbol(api.config?.symbol, peekedVenue),
921
929
  quoteCurrency: paperQuoteCurrency,
922
930
  };
923
931
  logger.info(TAG, `Config: ${pluginConfig.startingBalance} ${pluginConfig.quoteCurrency}, symbol: ${pluginConfig.symbol}`);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "reefclaw-paper-trading",
3
3
  "name": "ReefClaw Trading",
4
- "version": "0.1.10",
4
+ "version": "0.1.11",
5
5
  "description": "Supervised trading plugin for the ReefClaw dashboard: paper trading with real market data (no API keys required), and optional live trading on Binance or Hyperliquid behind explicit operator opt-in, exchange API credentials, and always-on protective stop brackets. Includes the dashboard connector bridge, heartbeat automation, and remote SKILL.md instruction updates from the ReefClaw webapp.",
6
6
  "author": "ReefClaw",
7
7
  "activation": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reefclaw/openclaw-plugin",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "ReefClaw supervised trading plugin for OpenClaw \u2014 paper trading with real market data, optional live trading on Binance or Hyperliquid (operator opt-in, API keys, always-on protective brackets), plus the ReefClaw dashboard connector with heartbeat automation and remote SKILL.md updates from the ReefClaw webapp. Install: /plugins install clawhub:@reefclaw/openclaw-plugin",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -20,6 +20,18 @@ export declare function fillExchangeId(venue: VenueId): string;
20
20
  export declare const VENUE_QUOTE_ASSET: Record<VenueId, string>;
21
21
  /** Prefix that namespaces Hyperliquid rows inside the intel symbol column. */
22
22
  export declare const HL_INTEL_PREFIX = "HL_";
23
+ /** Default canonical trading symbol per venue — BTC quoted in the venue's
24
+ * settle asset. A venue-blind 'BTC/USDT' default on a hyperliquid box is a
25
+ * guaranteed venue-rejection everywhere it's consumed (same class as the
26
+ * issue-#174 hardcoded-USDT wallet that read as $0 equity on the USDC venue). */
27
+ export declare const VENUE_DEFAULT_SYMBOL: Record<VenueId, string>;
28
+ /** Resolve the plugin's configured trading symbol: an explicit entry-config
29
+ * value wins (openclaw.json plugins.entries.<id>.config.symbol, passed to
30
+ * register() via api.config); otherwise the VENUE's default. Never a
31
+ * venue-blind hardcode — before 2026-07-24 register() ignored the entry
32
+ * config entirely and always used 'BTC/USDT', so every in-plugin consumer on
33
+ * a hyperliquid-venue box carried a symbol its own venue rejects. */
34
+ export declare function resolvePluginSymbol(entrySymbol: unknown, venue: VenueId): string;
23
35
  /** Canonical symbol → the venue's CCXT unified symbol.
24
36
  * 'BTC/USDT' (binance) → 'BTC/USDT:USDT'; 'BTC/USDC' (hyperliquid) →
25
37
  * 'BTC/USDC:USDC'. Accepts an already-suffixed input (idempotent). */
package/venues/symbols.js CHANGED
@@ -39,6 +39,26 @@ export const VENUE_QUOTE_ASSET = {
39
39
  };
40
40
  /** Prefix that namespaces Hyperliquid rows inside the intel symbol column. */
41
41
  export const HL_INTEL_PREFIX = 'HL_';
42
+ /** Default canonical trading symbol per venue — BTC quoted in the venue's
43
+ * settle asset. A venue-blind 'BTC/USDT' default on a hyperliquid box is a
44
+ * guaranteed venue-rejection everywhere it's consumed (same class as the
45
+ * issue-#174 hardcoded-USDT wallet that read as $0 equity on the USDC venue). */
46
+ export const VENUE_DEFAULT_SYMBOL = {
47
+ binance: 'BTC/USDT',
48
+ hyperliquid: 'BTC/USDC',
49
+ };
50
+ /** Resolve the plugin's configured trading symbol: an explicit entry-config
51
+ * value wins (openclaw.json plugins.entries.<id>.config.symbol, passed to
52
+ * register() via api.config); otherwise the VENUE's default. Never a
53
+ * venue-blind hardcode — before 2026-07-24 register() ignored the entry
54
+ * config entirely and always used 'BTC/USDT', so every in-plugin consumer on
55
+ * a hyperliquid-venue box carried a symbol its own venue rejects. */
56
+ export function resolvePluginSymbol(entrySymbol, venue) {
57
+ if (typeof entrySymbol === 'string' && entrySymbol.trim().length > 0) {
58
+ return stripSettleSuffix(entrySymbol.trim());
59
+ }
60
+ return VENUE_DEFAULT_SYMBOL[venue];
61
+ }
42
62
  /** Strip a CCXT settle suffix ('BTC/USDT:USDT' → 'BTC/USDT'). Same regex as
43
63
  * webapp/src/lib/symbols.ts normalizeSymbol — kept inline so this module has
44
64
  * zero imports and survives the sync-copy deploy boundary. */