crypto-agent-trading

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Skill: crypto-agent-trading

技能:crypto-agent-trading

Agent Capability Requirements

Agent 能力要求

This skill requires your agent platform to support the following capabilities. If your platform lacks any required capability, the skill will not function.
CapabilityRequiredDetails
Shell command executionYesMust be able to run
npx tsx ./scripts/...
and capture stdout
Environment variablesYesMust read
CDC_API_KEY
and
CDC_API_SECRET
from the shell environment
JSON parsingYesMust parse structured JSON from script stdout to extract fields
Multi-turn conversationYesTrading uses a quote → confirm flow that spans multiple user turns
Persistent memoryNoUsed for
confirmation_required
preference. If unsupported, default to always confirming trades
Elapsed-time awarenessNoUsed to check quote expiry (
countdown
field). If unsupported, always attempt confirmation and handle
invalid_quotation
errors gracefully
本技能要求你的Agent平台支持以下能力。如果你的平台缺少任意必填能力,技能将无法正常运行。
能力是否必填详情
Shell 命令执行必须能够运行
npx tsx ./scripts/...
并捕获标准输出
环境变量必须能够从Shell环境中读取
CDC_API_KEY
CDC_API_SECRET
JSON 解析必须能够解析脚本标准输出的结构化JSON,提取对应字段
多轮对话交易采用「报价→确认」的流程,需要跨多个用户轮次完成
持久化内存用于存储
confirmation_required
偏好设置。如果不支持,默认每次交易都需要确认
时长感知用于检查报价有效期(
countdown
字段)。如果不支持,始终尝试确认交易并优雅处理
invalid_quotation
错误

CRITICAL: How This Skill Works

重要提示:本技能的运行逻辑

You MUST use the TypeScript scripts for ALL API interactions. NEVER call the API directly with
curl
,
fetch
, or any other HTTP method.
The scripts handle request signing, error handling, and response formatting. If you bypass them:
  • The request will fail (missing HMAC signature)
  • The response won't be filtered or structured
For every user request, find the matching command below and run it via
npx tsx
. Read the JSON output. Act on it.
所有API交互必须使用TypeScript脚本完成。绝对不要直接用
curl
fetch
或其他HTTP方法调用API。
脚本会处理请求签名、错误处理和响应格式化。如果你绕过脚本:
  • 请求会失败(缺少HMAC签名)
  • 响应不会经过过滤或结构化处理
对于每一个用户请求,找到下方匹配的命令,通过
npx tsx
运行,读取JSON输出后执行对应操作。

Configurations

配置项

  • BASE_URL:
    https://wapi.crypto.com
  • CDC_API_KEY:
    {{env.CDC_API_KEY}}
  • CDC_API_SECRET:
    {{env.CDC_API_SECRET}}
  • CONFIRMATION_REQUIRED:
    {{memory.confirmation_required}}
    (Default: true)
  • SKILL_DIR: The directory containing this
    SKILL.md
    file. Resolve it from the path you loaded this file from (e.g. if you read
    /home/user/skills/crypto-agent-trading/SKILL.md
    , then
    SKILL_DIR
    is
    /home/user/skills/crypto-agent-trading
    ).
  • BASE_URL:
    https://wapi.crypto.com
  • CDC_API_KEY:
    {{env.CDC_API_KEY}}
  • CDC_API_SECRET:
    {{env.CDC_API_SECRET}}
  • CONFIRMATION_REQUIRED:
    {{memory.confirmation_required}}
    (默认值: true)
  • SKILL_DIR: 存储当前
    SKILL.md
    文件的目录。从你加载该文件的路径解析(比如你读取的是
    /home/user/skills/crypto-agent-trading/SKILL.md
    ,那么
    SKILL_DIR
    就是
    /home/user/skills/crypto-agent-trading
    )。

Environment Setup

环境配置

  • Both
    CDC_API_KEY
    and
    CDC_API_SECRET
    must be set as environment variables before use.
  • If either is missing, instruct the user to set them via the terminal:
    export CDC_API_KEY="your-api-key"
    export CDC_API_SECRET="your-api-secret"
  • Do NOT accept these values inline in chat or store them in files. Always direct users to set them via terminal for security.
  • 使用前必须先设置
    CDC_API_KEY
    CDC_API_SECRET
    两个环境变量。
  • 如果任意变量缺失,指导用户通过终端设置:
    export CDC_API_KEY="your-api-key"
    export CDC_API_SECRET="your-api-secret"
  • 不要接受聊天中输入的这些值,也不要将它们存储在文件中。出于安全考虑,始终指导用户通过终端设置。

Script Commands

脚本命令

ALL API interactions MUST go through these scripts. They handle signing, execution, filtering, and error formatting. Run the appropriate command below via shell, then parse the JSON output.
Prerequisite:
npx tsx
(Node.js 18+ required;
tsx
is fetched automatically by
npx
).
Important: All script paths below use
$SKILL_DIR
as a placeholder for this skill's root directory. Resolve it from the path you loaded this SKILL.md from, or
cd
into the skill directory and use
./scripts/...
as the path. Either approach works.
所有API交互必须通过这些脚本完成。 它们会处理签名、执行、过滤和错误格式化。通过Shell运行下方对应的命令,然后解析JSON输出。
前置依赖:
npx tsx
(需要Node.js 18+版本;
tsx
会被
npx
自动拉取)。
注意: 下方所有脚本路径使用
$SKILL_DIR
作为本技能根目录的占位符。你可以从加载该SKILL.md的路径解析,或者cd到技能目录后使用
./scripts/...
作为路径,两种方式都有效。

Account Commands

账户相关命令

bash
undefined
bash
undefined

Filtered non-zero balances (scope: fiat | crypto | all)

过滤后的非零余额(范围: fiat | crypto | all)

npx tsx $SKILL_DIR/scripts/account.ts balances [fiat|crypto|all]
npx tsx $SKILL_DIR/scripts/account.ts balances [fiat|crypto|all]

Single token balance lookup

单个代币余额查询

npx tsx $SKILL_DIR/scripts/account.ts balance <SYMBOL>
npx tsx $SKILL_DIR/scripts/account.ts balance <SYMBOL>

Weekly trading limit

周交易限额

npx tsx $SKILL_DIR/scripts/account.ts trading-limit
npx tsx $SKILL_DIR/scripts/account.ts trading-limit

Find funded source wallets for a trade type

查询对应交易类型的已充值来源钱包

npx tsx $SKILL_DIR/scripts/account.ts resolve-source <purchase|sale|exchange>
npx tsx $SKILL_DIR/scripts/account.ts resolve-source <purchase|sale|exchange>

Kill switch — revoke API key

Kill开关 — 吊销API密钥

npx tsx $SKILL_DIR/scripts/account.ts revoke-key
undefined
npx tsx $SKILL_DIR/scripts/account.ts revoke-key
undefined

Trade Commands

交易相关命令

Trading follows a two-step flow: get a quotation first, then confirm the order.
bash
undefined
交易遵循两步流程:先获取报价,再确认订单。
bash
undefined

Step 1 — Get quotation (type: purchase | sale | exchange)

步骤1 — 获取报价(类型: purchase | sale | exchange)

npx tsx $SKILL_DIR/scripts/trade.ts quote <type> '<json-params>'
npx tsx $SKILL_DIR/scripts/trade.ts quote <type> '<json-params>'

Returns: {"ok": true, "data": {"id": "<quotation-id>", "from_amount": {...}, "to_amount": {...}, "countdown": 15, ...}}

返回: {"ok": true, "data": {"id": "<quotation-id>", "from_amount": {...}, "to_amount": {...}, "countdown": 15, ...}}

Step 2 — Confirm order: pass the data.id from Step 1 as <quotation-id>

步骤2 — 确认订单:将步骤1返回的data.id作为<quotation-id>传入

npx tsx $SKILL_DIR/scripts/trade.ts confirm <type> <quotation-id>
npx tsx $SKILL_DIR/scripts/trade.ts confirm <type> <quotation-id>

View recent transactions

查看近期交易

npx tsx $SKILL_DIR/scripts/trade.ts history

**How to map user intent to trade type:**

| User says | Trade type | From | To |
|-----------|-----------|------|-----|
| "Buy CRO with 100 USD" | `purchase` | USD (fiat) | CRO (crypto) |
| "Sell 0.1 BTC" | `sale` | BTC (crypto) | USD (fiat) |
| "Swap 0.1 BTC to ETH" | `exchange` | BTC (crypto) | ETH (crypto) |

**Quotation JSON params by trade type:**

| Type | JSON fields |
|------|------------|
| purchase | `{"from_currency":"USD","to_currency":"CRO","from_amount":"100"}` or use `to_amount` instead |
| sale | `{"from_currency":"BTC","to_currency":"USD","from_amount":"0.1","fixed_side":"from"}` |
| exchange | `{"from_currency":"BTC","to_currency":"ETH","from_amount":"0.1","side":"buy"}` |

**Example — "Buy CRO with 100 USD":**

1. Run: `npx tsx $SKILL_DIR/scripts/trade.ts quote purchase '{"from_currency":"USD","to_currency":"CRO","from_amount":"100"}'`
2. Read `data.id`, `data.from_amount`, `data.to_amount`, `data.countdown` from the response.
3. **If confirmation required** (default): Ask user "Confirm: 100 USD for X CRO? Valid for {countdown}s. Reply 'YES' to proceed."
   - If user says YES (within countdown): `npx tsx $SKILL_DIR/scripts/trade.ts confirm purchase <data.id>`
4. **If confirmation opted out** (`memory.confirmation_required` is `false`): Skip asking and immediately run `npx tsx $SKILL_DIR/scripts/trade.ts confirm purchase <data.id>`

**Opt-in / Opt-out:** Users can say "stop asking for confirmation" to auto-execute trades, or "require confirmation" to re-enable the prompt. See Section 3 below.
npx tsx $SKILL_DIR/scripts/trade.ts history

**用户意图与交易类型的映射规则:**

| 用户表述 | 交易类型 | 转出 | 转入 |
|-----------|-----------|------|-----|
| "用100美元买CRO" | `purchase` | USD (法币) | CRO (加密货币) |
| "卖出0.1个BTC" | `sale` | BTC (加密货币) | USD (法币) |
| "把0.1个BTC换成ETH" | `exchange` | BTC (加密货币) | ETH (加密货币) |

**不同交易类型对应的报价JSON参数:**

| 类型 | JSON字段 |
|------|------------|
| purchase | `{"from_currency":"USD","to_currency":"CRO","from_amount":"100"}` 也可以使用`to_amount`代替 |
| sale | `{"from_currency":"BTC","to_currency":"USD","from_amount":"0.1","fixed_side":"from"}` |
| exchange | `{"from_currency":"BTC","to_currency":"ETH","from_amount":"0.1","side":"buy"}` |

**示例 — 「用100美元买CRO」:**

1. 运行:`npx tsx $SKILL_DIR/scripts/trade.ts quote purchase '{"from_currency":"USD","to_currency":"CRO","from_amount":"100"}'`
2. 从响应中读取 `data.id`、`data.from_amount`、`data.to_amount`、`data.countdown`。
3. **如果需要确认**(默认设置):询问用户「确认:用100美元兑换X CRO?报价有效期为{countdown}秒。回复「YES」继续。」
   - 如果用户在倒计时内回复YES:运行 `npx tsx $SKILL_DIR/scripts/trade.ts confirm purchase <data.id>`
4. **如果已关闭确认要求**(`memory.confirmation_required` 为 `false`):跳过询问,直接运行 `npx tsx $SKILL_DIR/scripts/trade.ts confirm purchase <data.id>`

**开启/关闭确认:** 用户可以说「停止询问确认」来自动执行交易,或者说「需要确认」来重新开启提示。详情见下文第3部分。

Coin Discovery Commands

币种发现命令

bash
undefined
bash
undefined

Search coins

搜索币种

npx tsx $SKILL_DIR/scripts/coins.ts search '{"keyword":"BTC","sort_by":"rank","sort_direction":"asc","native_currency":"USD","page_size":10}'

**Required JSON parameters:**

| Parameter | Type | Allowed values |
|-----------|------|----------------|
| `sort_by` | string | `rank`, `market_cap`, `alphabetical`, `volume`, `performance` |
| `sort_direction` | string | `asc`, `desc` |
| `native_currency` | string | Uppercase currency code (e.g. `USD`) |
| `keyword` | string | Search string, 1–100 chars; matches coin name and symbol only |
| `page_size` | integer | Number of results per page |

**Optional:** `page_token` — opaque token for fetching the next page (see pagination below).

**Pagination:** The response includes a `pagination` object with `has_more` (boolean) and `next_page_token` (string). When `has_more` is `true`, pass `next_page_token` as `page_token` in the next request to fetch the next page.

**Key response fields per coin:** `rails_id` (identical to `currency_id` / `currency` in trade and account APIs — use this to cross-reference), `price_native`, `price_usd`, `percent_change_*_native` (price performance over past timeframes, e.g. `percent_change_24h_native`).
npx tsx $SKILL_DIR/scripts/coins.ts search '{"keyword":"BTC","sort_by":"rank","sort_direction":"asc","native_currency":"USD","page_size":10}'

**必填JSON参数:**

| 参数 | 类型 | 允许值 |
|-----------|------|----------------|
| `sort_by` | string | `rank`、`market_cap`、`alphabetical`、`volume`、`performance` |
| `sort_direction` | string | `asc`、`desc` |
| `native_currency` | string | 大写货币代码(比如 `USD`) |
| `keyword` | string | 搜索字符串,长度1-100字符;仅匹配币种名称和代码 |
| `page_size` | 整数 | 每页返回的结果数量 |

**可选参数:** `page_token` — 用于获取下一页内容的不透明令牌(见下方分页说明)。

**分页:** 响应包含`pagination`对象,有`has_more`(布尔值)和`next_page_token`(字符串)两个字段。当`has_more`为`true`时,将`next_page_token`作为`page_token`传入下一次请求来获取下一页内容。

**每个币种的核心响应字段:** `rails_id`(和交易、账户API中的`currency_id`/`currency`一致,可用于跨接口关联)、`price_native`、`price_usd`、`percent_change_*_native`(过去时间段的价格表现,比如`percent_change_24h_native`)。

Output Format

输出格式

Every script prints structured JSON to stdout:
Success:
json
{"ok": true, "data": { ... }}
Error:
json
{"ok": false, "error": "ERROR_CODE", "error_message": "Human-readable message"}
每个脚本都会向标准输出打印结构化JSON:
成功:
json
{"ok": true, "data": { ... }}
错误:
json
{"ok": false, "error": "ERROR_CODE", "error_message": "可读性错误提示"}

Constraints

约束

  • Validation: Success requires
    ok: true
    in the script output.
  • Confirmation Window: Quote validity is defined by the
    countdown
    field in the quotation data.
  • Execution Warning: If order confirmation takes > 5s, notify: "Order submitted but taking longer than expected. Check order status with 'Show recent trades'".
  • Rate Limits:
    • Max 10 trades per minute.
    • Max 100 API calls per minute.
    • On HTTP 429 (
      RATE_LIMITED
      error): wait 60 seconds before retrying the same request. Inform the user: "Rate limit reached — please wait 60 seconds before trying again."
  • 校验规则: 脚本输出中包含
    ok: true
    才算执行成功。
  • 确认窗口: 报价有效期由报价数据中的
    countdown
    字段定义。
  • 执行提示: 如果订单确认耗时超过5秒,通知用户:「订单已提交,但耗时超出预期。你可以使用「显示近期交易」查询订单状态。」
  • 频率限制:
    • 每分钟最多10笔交易
    • 每分钟最多100次API调用
    • 收到HTTP 429(
      RATE_LIMITED
      错误):等待60秒再重试相同请求。告知用户:「已达到频率限制,请等待60秒后再尝试。」

Error Handling

错误处理

All scripts return structured errors. Parse the
error
field to determine the appropriate response.
所有脚本都会返回结构化错误。解析
error
字段来生成对应的回复。

Script Error Codes

脚本错误码

These are the
error
values in the script's JSON output. They tell you what category of failure occurred.
Error CodeMeaningAgent Response
MISSING_ENV
CDC_API_KEY
or
CDC_API_SECRET
not set
Tell user to set env vars via terminal
API_ERROR
API returned non-200 or
ok !== true
Report: "Transaction failed: {error_message}"
INVALID_ARGS
Bad command-line argumentsShow correct usage from the
error_message
QUOTATION_FAILED
Quotation request rejected by APIReport the
error_message
to user (see API errors below)
EXECUTION_FAILED
Order confirmation failedReport and suggest: "Check order status with 'Show recent trades'"
API_KEY_NOT_FOUND
Key already revoked or does not exist"API key not found — it may have already been revoked."
RATE_LIMITED
Too many requests (HTTP 429)"Rate limit reached — please wait 60 seconds before trying again."
UNKNOWN
Unexpected errorReport the raw
error_message
Rule: When
ok
is
false
in the output, stop the current operation and report the error to the user using the guidance above. Never proceed to the next step after a failure.
这些是脚本JSON输出中的
error
值,用于标识失败的类别。
错误码含义Agent回复
MISSING_ENV
未设置
CDC_API_KEY
CDC_API_SECRET
告知用户需要通过终端设置环境变量
API_ERROR
API返回非200状态码或
ok !== true
报告:「交易失败:{error_message}」
INVALID_ARGS
命令行参数错误展示
error_message
中的正确用法
QUOTATION_FAILED
API拒绝了报价请求向用户报告
error_message
(见下方API错误)
EXECUTION_FAILED
订单确认失败报告并建议:「你可以使用「显示近期交易」查询订单状态」
API_KEY_NOT_FOUND
密钥已被吊销或不存在「API密钥未找到,可能已经被吊销。」
RATE_LIMITED
请求过多(HTTP 429)「已达到频率限制,请等待60秒后再尝试。」
UNKNOWN
未知错误报告原始的
error_message
规则: 当输出中
ok
false
时,停止当前操作,按照上方指引向用户报告错误。失败后绝对不要继续执行下一步。

Common API Errors (Quick Reference)

常见API错误(快速参考)

These are the specific API error codes that appear inside the
error_message
of
QUOTATION_FAILED
,
EXECUTION_FAILED
, or
API_ERROR
responses. They tell you why the API rejected the request.
error
MeaningRecovery
not_enough_balance
Insufficient fundsCheck balances, reduce trade amount
invalid_currency
Currency code not recognizedVerify via coin search
invalid_quotation
Quote expired or already usedRequest a new quotation
failed_to_create_quotation
Quotation engine errorRetry shortly
not_eligible_for_prime
Not eligible for Prime benefitsProceed without Prime
unauthorized
Account not approved for tradingContact support
restricted_feature
Feature restricted on accountReport
error_message
to user
existing_currency_order_error
An existing order is in progressWait or cancel existing order
viban_purchase_not_enabled
Fiat-to-crypto not enabledAccount feature not available
crypto_viban_not_enabled
Crypto-to-fiat not enabledAccount feature not available
bank_transfer_not_enabled
Bank transfer not enabledAccount feature not available
missing_parameter
Required parameter missingScript bug — report it
failed_to_create_transaction
Transaction creation failedRetry or contact support
key_not_active
API key revoked or expiredGenerate a new API key, update env vars
api_key_not_found
Key doesn't exist or belongs to another userVerify correct key is set in
CDC_API_KEY
For dynamic errors (limit exceeded, currency disabled, cooling-off, etc.), report the
error
and
error_message
directly to the user. For full details, see references/errors.md.

这些是出现在
QUOTATION_FAILED
EXECUTION_FAILED
API_ERROR
响应的
error_message
中的特定API错误码,用于说明API拒绝请求的具体原因。
error
含义恢复方案
not_enough_balance
余额不足检查余额,减少交易金额
invalid_currency
货币代码未被识别通过币种搜索验证代码
invalid_quotation
报价已过期或已被使用请求新的报价
failed_to_create_quotation
报价引擎错误稍后重试
not_eligible_for_prime
不符合Prime权益资格不使用Prime权益继续操作
unauthorized
账户未通过交易审核联系客服
restricted_feature
账户的该功能被限制向用户报告
error_message
existing_currency_order_error
已有同币种订单正在处理中等待或取消已有订单
viban_purchase_not_enabled
法币兑加密货币功能未开启账户功能不可用
crypto_viban_not_enabled
加密货币兑法币功能未开启账户功能不可用
bank_transfer_not_enabled
银行转账功能未开启账户功能不可用
missing_parameter
缺少必填参数脚本bug,请上报
failed_to_create_transaction
交易创建失败重试或联系客服
key_not_active
API密钥已被吊销或过期生成新的API密钥,更新环境变量
api_key_not_found
密钥不存在或属于其他用户验证
CDC_API_KEY
中设置的密钥是否正确
对于动态错误(超出限额、货币禁用、冷却期等),直接向用户报告
error
error_message
。完整详情请参考 references/errors.md

Logic & Rules

逻辑与规则

1. Asset & Source Disambiguation

1. 资产与来源歧义处理

Determine the trade type first:
  • Purchase — fiat → crypto
  • Sale — crypto → fiat
  • Exchange — crypto → crypto
Then resolve the source wallet:
  • For purchase: run
    npx tsx $SKILL_DIR/scripts/account.ts resolve-source purchase
    . The script returns only funded fiat entries.
  • For sale or exchange: run
    npx tsx $SKILL_DIR/scripts/account.ts resolve-source sale
    (or
    exchange
    ). The script returns only funded crypto entries.
Result (from
data.status
):
  • SELECTED
    → auto-select
    data.currency
    .
  • AMBIGUOUS
    → prompt user to choose from
    data.options
    .
  • EMPTY
    → inform user "No funded wallets found" and stop.
"Sell All" Scenario: If user says "Sell all [TOKEN]", run
npx tsx $SKILL_DIR/scripts/account.ts balance [TOKEN]
. Use the
data.available
amount (or
data.balance
) as
from_amount
for the quotation.
首先确定交易类型:
  • 买入(Purchase) — 法币 → 加密货币
  • 卖出(Sale) — 加密货币 → 法币
  • 兑换(Exchange) — 加密货币 → 加密货币
然后解析来源钱包:
  • 对于买入:运行
    npx tsx $SKILL_DIR/scripts/account.ts resolve-source purchase
    。脚本仅返回有余额的法币条目。
  • 对于卖出兑换:运行
    npx tsx $SKILL_DIR/scripts/account.ts resolve-source sale
    (或
    exchange
    )。脚本仅返回有余额的加密货币条目。
结果(从
data.status
获取):
  • SELECTED
    → 自动选择
    data.currency
  • AMBIGUOUS
    → 提示用户从
    data.options
    中选择。
  • EMPTY
    → 告知用户「未找到有余额的钱包」并停止操作。
「全部卖出」场景: 如果用户说「卖出全部[TOKEN]」,运行
npx tsx $SKILL_DIR/scripts/account.ts balance [TOKEN]
。使用
data.available
金额(或
data.balance
)作为报价的
from_amount

2. Trading Process (Quotation → Confirmation → Execution)

2. 交易流程(报价→确认→执行)

When the user asks to buy, sell, or swap crypto, always follow this three-step flow:
  • Step A — Get Quotation: Build the JSON params from the user's request (see the "Quotation JSON params" table in Trade Commands) and run:
    npx tsx $SKILL_DIR/scripts/trade.ts quote <type> '<json-params>'
    Read
    data.id
    ,
    data.from_amount
    ,
    data.to_amount
    , and
    data.countdown
    from the response.
  • Step B — Ask User to Confirm:
    • IF
      memory.confirmation_required
      is
      true
      (or unset):
      • Prompt: "Confirm: {from_amount} for {to_amount}? Valid for {countdown}s. Reply 'YES' to proceed."
      • Expiration Logic: If the user replies "YES" after
        countdown
        seconds have elapsed, reject: "Transaction rejected: The quotation rate has expired. Please request a new quote."
      • Execute Step C ONLY if user replies "YES" within the valid window.
    • ELSE (Opted Out):
      • Notify: "Quotation received. Proceeding to execution automatically..."
      • Immediately proceed to Step C.
  • Step C — Execute Order: Run:
    npx tsx $SKILL_DIR/scripts/trade.ts confirm <type> <data.id>
    using the
    id
    from Step A.
当用户要求买入、卖出或swap加密货币时,必须遵循以下三步流程:
  • 步骤A — 获取报价: 根据用户请求构建JSON参数(参考交易命令中的「报价JSON参数」表格),运行:
    npx tsx $SKILL_DIR/scripts/trade.ts quote <type> '<json-params>'
    从响应中读取
    data.id
    data.from_amount
    data.to_amount
    data.countdown
  • 步骤B — 询问用户确认:
    • 如果
      memory.confirmation_required
      true
      (或未设置):
      • 提示:「确认:用{from_amount}兑换{to_amount}?报价有效期为{countdown}秒。回复「YES」继续。」
      • 过期逻辑: 如果用户在
        countdown
        秒后才回复「YES」,拒绝请求:「交易已拒绝:报价已过期,请请求新的报价。」
      • 仅当用户在有效期内回复「YES」时才执行步骤C。
    • 否则(已关闭确认):
      • 通知:「已收到报价,自动执行交易中...」
      • 直接进入步骤C。
  • 步骤C — 执行订单: 使用步骤A返回的
    id
    运行:
    npx tsx $SKILL_DIR/scripts/trade.ts confirm <type> <data.id>

3. Memory Management (Opt-in/Out)

3. 内存管理(确认开关)

  • To Opt-out: If user says "stop asking for confirmation" or "enable auto-trade", update
    memory.confirmation_required
    to
    false
    .
  • To Opt-in: If user says "require confirmation" or "enable manual trade", update
    memory.confirmation_required
    to
    true
    .
  • Platforms without persistent memory: If your platform does not support
    {{memory.*}}
    , treat
    confirmation_required
    as always
    true
    (safest default).
  • 关闭确认: 如果用户说「停止询问确认」或「开启自动交易」,将
    memory.confirmation_required
    更新为
    false
  • 开启确认: 如果用户说「需要确认」或「开启手动交易」,将
    memory.confirmation_required
    更新为
    true
  • 无持久化内存的平台: 如果你的平台不支持
    {{memory.*}}
    ,将
    confirmation_required
    始终视为
    true
    (最安全的默认值)。

4. Error Handling

4. 错误处理

  • All script outputs include an
    ok
    field. Success is defined ONLY as
    ok: true
    .
  • If
    ok
    is
    false
    , read
    error
    and respond per the Error Handling table above.
  • Never proceed to the next step after a failed command.
  • 所有脚本输出都包含
    ok
    字段。仅当
    ok: true
    时才算执行成功。
  • 如果
    ok
    false
    ,读取
    error
    并按照上方错误处理表格的要求回复。
  • 命令失败后绝对不要继续执行下一步。

5. Account & History

5. 账户与历史查询

  • History: Run
    npx tsx $SKILL_DIR/scripts/trade.ts history
    — display the entries from
    data
    .
  • Weekly Trading Limit: Run
    npx tsx $SKILL_DIR/scripts/account.ts trading-limit
    — display as: "📊 Weekly Trading Limit: {data.used} / {data.limit} USD (Remaining: {data.remaining} USD)".
  • Balances (Categorized):
    • If "List Fiat": run
      npx tsx $SKILL_DIR/scripts/account.ts balances fiat
      .
    • If "List Crypto": run
      npx tsx $SKILL_DIR/scripts/account.ts balances crypto
      .
    • If "List All": run
      npx tsx $SKILL_DIR/scripts/account.ts balances all
      . Crucial: Display Fiat category first, followed by Crypto balances below.
    • The scripts automatically filter out zero-balance entries. If a category has no entries in the output, display "No holdings" under that header.
  • 交易历史: 运行
    npx tsx $SKILL_DIR/scripts/trade.ts history
    — 展示
    data
    中的条目。
  • 周交易限额: 运行
    npx tsx $SKILL_DIR/scripts/account.ts trading-limit
    — 展示为:「📊 周交易限额:{data.used} / {data.limit} 美元(剩余:{data.remaining} 美元)」。
  • 余额(分类展示):
    • 如果是「列出法币余额」:运行
      npx tsx $SKILL_DIR/scripts/account.ts balances fiat
    • 如果是「列出加密货币余额」:运行
      npx tsx $SKILL_DIR/scripts/account.ts balances crypto
    • 如果是「列出全部余额」:运行
      npx tsx $SKILL_DIR/scripts/account.ts balances all
      重要: 先展示法币分类,再展示加密货币余额。
    • 脚本会自动过滤余额为0的条目。如果输出中某个分类没有条目,在该标题下展示「暂无持仓」。

6. Kill Switch

6. Kill开关

  • Trigger: User says "STOP ALL TRADING", "kill switch", or similar emergency stop command.
  • ALWAYS require explicit confirmation regardless of
    memory.confirmation_required
    :
    • Prompt: "⚠️ WARNING: This will immediately revoke your API key and disable all trading. A new API key must be generated to resume. Type 'CONFIRM KILL SWITCH' to proceed."
    • Execute ONLY if user replies with the exact phrase.
  • Execution: Run
    npx tsx $SKILL_DIR/scripts/account.ts revoke-key
    .
  • On success (
    ok: true
    ):
    Notify: "🛑 Kill switch activated. API key has been revoked. All trading is disabled. Generate a new API key and update your environment variables to resume."
  • On
    API_KEY_NOT_FOUND
    error:
    Notify: "API key not found — it may have already been revoked or does not exist."
  • Idempotency: Revoking an already-revoked key is not an error; treat it the same as a successful revocation.
  • 触发条件: 用户说「停止所有交易」、「kill开关」或类似的紧急停止命令。
  • 无论
    memory.confirmation_required
    设置如何,必须要求显式确认:
    • 提示:「⚠️ 警告:该操作会立即吊销你的API密钥,禁用所有交易功能。你需要生成新的API密钥才能恢复交易。输入「CONFIRM KILL SWITCH」继续。」
    • 仅当用户回复完全匹配的短语时才执行操作。
  • 执行: 运行
    npx tsx $SKILL_DIR/scripts/account.ts revoke-key
  • 执行成功(
    ok: true
    ):
    通知:「🛑 Kill开关已激活。API密钥已被吊销,所有交易功能已禁用。你需要生成新的API密钥并更新环境变量才能恢复交易。」
  • 返回
    API_KEY_NOT_FOUND
    错误:
    通知:「API密钥未找到,可能已经被吊销或不存在。」
  • 幂等性: 吊销已被吊销的密钥不算错误,按照成功吊销处理即可。

7. Balance Display Format

7. 余额展示格式

  • Fiat Header: "🏦 Fiat Balances"
  • Crypto Header: "🪙 Crypto Balances"
  • Always list Fiat section before Crypto section when both are requested.
  • Never display zero-balance assets. Only show assets with a balance greater than 0. If all assets in a category are zero, show "No holdings" under that header.
  • 法币标题: 「🏦 法币余额」
  • 加密货币标题: 「🪙 加密货币余额」
  • 同时请求两类余额时,始终先展示法币部分,再展示加密货币部分。
  • 绝对不要展示余额为0的资产。 仅展示余额大于0的资产。如果某个分类下所有资产余额都是0,在该标题下展示「暂无持仓」。