crypto-com-app

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Skill: crypto-com-app

Skill: crypto-com-app

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
本Skill要求你的Agent平台支持以下能力。若你的平台缺少任何必需能力,本Skill将无法正常运行。
能力是否必需详情
Shell命令执行必须能够运行
npx tsx ./scripts/...
并捕获标准输出
环境变量必须从Shell环境中读取
CDC_API_KEY
CDC_API_SECRET
JSON解析必须解析脚本标准输出中的结构化JSON以提取字段
多轮对话交易采用报价→确认的流程,需跨越多轮用户对话
持久化内存用于
confirmation_required
偏好设置。若不支持,默认始终确认交易
时间感知用于检查报价过期时间(
countdown
字段)。若不支持,始终尝试确认并优雅处理
invalid_quotation
错误

CRITICAL: How This Skill Works

重要提示:本Skill的工作方式

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-com-app/SKILL.md
    , then
    SKILL_DIR
    is
    /home/user/skills/crypto-com-app
    ).
  • 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-com-app/SKILL.md
    ,那么
    SKILL_DIR
    /home/user/skills/crypto-com-app
    )。

Environment Setup

环境设置

  • Both
    CDC_API_KEY
    and
    CDC_API_SECRET
    must be set as environment variables before use.
  • Before running any script, check whether both variables are set by running:
    bash
    echo "CDC_API_KEY=${CDC_API_KEY:+set}" "CDC_API_SECRET=${CDC_API_SECRET:+set}"
    If either prints empty instead of
    set
    , prompt the user:
    "Your API credentials are not configured. Please set them in your terminal before I can proceed:
    export CDC_API_KEY="your-api-key"
    export CDC_API_SECRET="your-api-secret"
    You can generate an API key at https://help.crypto.com/en/articles/13843786-api-key-management. Let me know once you've set them."
    Then stop and wait for the user to confirm before retrying.
  • If a script returns a
    MISSING_ENV
    error, treat it the same way: prompt the user to set the variables and wait.
  • 使用前必须将
    CDC_API_KEY
    CDC_API_SECRET
    设置为环境变量。
  • 运行任何脚本前,通过运行以下命令检查两个变量是否已设置:
    bash
    echo "CDC_API_KEY=${CDC_API_KEY:+set}" "CDC_API_SECRET=${CDC_API_SECRET:+set}"
    如果其中任何一个显示为空而非
    set
    ,请提示用户:
    "你的API凭证未配置。请在终端中设置以下变量后再继续:
    export CDC_API_KEY="your-api-key"
    export CDC_API_SECRET="your-api-secret"
    然后停止操作并等待用户确认后再重试。
  • 如果脚本返回
    MISSING_ENV
    错误,处理方式相同:提示用户设置变量并等待。

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根目录的占位符。你可以从加载SKILL.md的路径中解析它,或者进入Skill目录后使用
./scripts/...
作为路径。两种方式均可。

Account Commands

账户命令

bash
undefined
bash
undefined

Filtered non-zero balances (scope: 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

紧急关停开关 — 撤销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` | 美元(法币) | CRO(加密货币) |
| "卖出0.1个BTC" | `sale` | BTC(加密货币) | 美元(法币) |
| "将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` | 字符串 | `rank`, `market_cap`, `alphabetical`, `volume`, `performance` |
| `sort_direction` | 字符串 | `asc`, `desc` |
| `native_currency` | 字符串 | 大写货币代码(如`USD`) |
| `keyword` | 字符串 | 搜索字符串,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
缺少必需参数脚本错误 — 请报告
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.
当用户要求买入、卖出或兑换加密货币时,必须遵循以下三步流程:
  • **步骤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 — 执行订单:**运行:
    npx tsx $SKILL_DIR/scripts/trade.ts confirm <type> <data.id>
    ,使用步骤A中的
    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
      。**重要:**先显示法币类别,再显示加密货币余额。
    • 脚本会自动过滤掉零余额条目。如果某类别在输出中没有条目,在该标题下显示“无持仓”。

6. Kill Switch

6. 紧急关停开关

  • 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.
  • **触发条件:**用户说“停止所有交易”、“紧急关停”或类似的紧急停止命令。
  • 无论
    memory.confirmation_required
    设置如何,必须要求明确确认:
    • 提示:“⚠️ 警告:这将立即撤销你的API密钥并禁用所有交易。恢复交易必须生成新的API密钥。输入'CONFIRM KILL SWITCH'继续。”
    • 仅当用户回复确切短语时才执行。
  • **执行:**运行
    npx tsx $SKILL_DIR/scripts/account.ts revoke-key
  • **成功时(
    ok: true
    ):**通知:“🛑 紧急关停开关已激活。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的资产。如果某类别下所有资产均为零,在该标题下显示“无持仓”。