用途
该技能用于通过 uxc 与精选 OpenAPI schema 运行 MEXC 现货(Spot)REST 操作。它复用 uxc 技能提供的共享执行、认证和错误处理指引,将公开读取、签名读取与签名写入三类工作流分别管理,以降低误操作风险。
前置条件
- uxc 已安装并可在 PATH 中使用。
- 能够访问 https://api.mexc.com。
- 能够访问精选 OpenAPI schema:https://raw.githubusercontent.com/holon-run/uxc/main/skills/mexc-openapi-skill/references/mexc-spot.openapi.json
覆盖范围
该技能覆盖经过精选的 MEXC 现货 REST 接口,包括:
- 公开市场读取
- 签名账户读取
- 签名订单创建、取消与查询流程
不覆盖:
- 合约 API
- 更广泛的平台产品线
认证方式
公开市场端点不需要凭据。签名现货端点需要:
- api_key 字段,用于 X-MEXC-APIKEY
- secret_key 字段,用于 HMAC SHA256 查询签名
创建凭据:
uxc auth credential set mexc-spot \
--auth-type api_key \
--field api_key=env:MEXC_API_KEY \
--field secret_key=env:MEXC_SECRET_KEY
添加签名绑定:
uxc auth binding add \
--id mexc-spot \
--host api.mexc.com \
--path-prefix /api/v3 \
--scheme https \
--credential mexc-spot \
--signer-json '{"kind":"hmac_query_v1","algorithm":"hmac_sha256","signing_field":"secret_key","key_field":"api_key","key_placement":"header","key_name":"X-MEXC-APIKEY","signature_param":"signature","signature_encoding":"hex","timestamp_param":"timestamp","timestamp_unit":"milliseconds","canonicalization":{"mode":"preserve_order"}}' \
--priority 100
当认证出现异常时,可校验当前生效的映射:
uxc auth binding match https://api.mexc.com/api/v3/account
核心工作流
默认使用固定链接命令:
command -v mexc-openapi-cli
若缺失则创建:
uxc link mexc-openapi-cli https://api.mexc.com --schema-url https://raw.githubusercontent.com/holon-run/uxc/main/skills/mexc-openapi-skill/references/mexc-spot.openapi.json
查看帮助:
mexc-openapi-cli -h
执行前先查看具体操作帮助:
mexc-openapi-cli get:/api/v3/ticker/price -h
mexc-openapi-cli get:/api/v3/account -h
mexc-openapi-cli post:/api/v3/order -h
优先进行公开读取:
mexc-openapi-cli get:/api/v3/ticker/price symbol=BTCUSDT
mexc-openapi-cli get:/api/v3/depth symbol=BTCUSDT limit=20
在进行写入前先使用签名读取:
mexc-openapi-cli get:/api/v3/account recvWindow=5000
mexc-openapi-cli get:/api/v3/openOrders symbol=BTCUSDT recvWindow=5000
操作分组
公开市场:
- get:/api/v3/ping
- get:/api/v3/exchangeInfo
- get:/api/v3/ticker/price
- get:/api/v3/ticker/24hr
- get:/api/v3/depth
签名读取:
- get:/api/v3/account
- get:/api/v3/openOrders
- get:/api/v3/order
签名写入:
- post:/api/v3/order
- delete:/api/v3/order
防护规则
- 自动化应保持在 JSON 输出封装上,不要使用 --text。
- 优先解析稳定字段:ok、kind、protocol、data、error。
- 将签名写入操作视为高风险,执行前需要明确确认。
- timestamp 与 signature 由签名绑定注入;用户通常只需提供业务参数以及可选的 recvWindow。
- 下单前先查询 exchangeInfo,以了解交易对过滤规则与数量精度。
mexc-openapi-cli <operation> ...等价于uxc https://api.mexc.com --schema-url <mexc_spot_openapi_schema> <operation> ...。
参考资料
- 使用模式:references/usage-patterns.md
- 精选 OpenAPI schema:references/mexc-spot.openapi.json
- 官方 MEXC Spot v3 文档:https://mexcdevelop.github.io/apidocs/spot_v3_en/