SuperAPI AI Directory

trade-executor

Data & analytics

View repository

Updated 10-16 08:49

About this skill

Skill: trade-executor (interface definition)

Interface layer: defines preconditions, risk control flow, user confirmation format, and audit record structure, independent of any specific exchange. For each exchange's order placement API and signature method, see the impl/ directory:

  • impl/binance.md — Binance implementation
  • impl/okx.md — OKX implementation

When adding a new exchange, simply add the corresponding impl/{exchange}.md, and this file does not need to be modified.

Overview

Execute cryptocurrency trades, including complete risk control checks and user confirmation flow.

Trigger conditions

  • The user explicitly requests an order
  • market-monitor generates a signal and the user has pre-authorized (confidence ≥ 0.85)

Preconditions (all must be satisfied to execute)

  1. The user has explicitly confirmed the trade intent
  2. All risk control checks pass (see checklist below)
  3. The trading pair is in the whitelist (see openclaw.json allowedPairs)
  4. The target exchange's API Key has been configured and is valid

Risk control checklist

[RISK CHECK] 执行前逐项验证:
├── [ ] 交易对在白名单? (BTC/USDT, ETH/USDT, SOL/USDT)
├── [ ] 单笔金额 ≤ 1,000 USDT?
├── [ ] 今日交易笔数 < 20?  ← 由网关跨 session 追踪
├── [ ] 今日累计亏损 < 500 USDT? ← 由网关跨 session 追踪
├── [ ] 操作类型安全? (非提币/转账/改权限)
├── [ ] 用户已确认?
└── [ ] 止损已设置?

If any item fails → refuse to execute, and explain the specific reason to the user.

Execution flow

1. Parameter validation

必需: exchange, pair, side (buy/sell), type (limit/market), quantity
可选: price(limit 单必须), stopLoss, takeProfit

2. User confirmation display

交易确认:
  交易所: {exchange}
  交易对: {pair}
  方向:   买入 / 卖出
  类型:   限价单 / 市价单
  价格:   ${price}
  数量:   {quantity} {base}
  金额:   ${amount}
  止损:   ${stopLoss} (-{pct}%)
  止盈:   ${takeProfit} (+{pct}%)

请回复 "确认" 执行,或 "取消" 放弃

3. Order placement

Based on the exchange parameter, load the corresponding impl/{exchange}.md, and call its order placement API.

4. Result handling

  • Success: return the order ID and execution details
  • Partial fill: notify the user and continue monitoring the remaining quantity
  • Failure: return an error explanation and suggest a handling method

Audit record format

Each trade is automatically recorded by the gateway (Vega does not need to write):

{
  "tradeId": "uuid",
  "timestamp": "ISO8601",
  "exchange": "binance | okx",
  "pair": "BTC/USDT",
  "side": "buy | sell",
  "type": "limit | market",
  "price": 0.0,
  "quantity": 0.0,
  "amountUSD": 0.0,
  "stopLoss": 0.0,
  "takeProfit": 0.0,
  "orderId": "exchange_order_id",
  "status": "filled | partial | rejected | cancelled",
  "riskChecks": { "allPassed": true, "details": [] },
  "userConfirmed": true
}

Security constraints

  • User confirmation is a mandatory process; it cannot be skipped and cannot be automatically confirmed by code
  • exec = deny, write = deny (Vega itself does not write any files)
  • All trade records are written to the audit log by the gateway
  • Risk control violations are automatically rejected and alerted