Binance Spot API Skill
Use this skill to run Binance Spot REST operations through uxc + OpenAPI.
Reuse the uxc skill for shared execution, auth, and error-handling guidance.
Prerequisites
- -
uxc is installed and available in PATH. - Network access to:
-
https://api.binance.com
-
https://testnet.binance.vision
- - Access to the curated OpenAPI schema URL:
- INLINECODE6
Scope
This skill covers curated Binance Spot REST endpoints for:
- - public market reads
- signed account reads
- signed order queries
- test orders
- order placement and cancellation
This skill does not cover:
- - OCO, OTO, OTOCO, OPO, OPOCO, or other
orderList/* endpoints - INLINECODE8
- INLINECODE9
- INLINECODE10
- INLINECODE11
- INLINECODE12
- SOR endpoints
- Wallet, Margin, Earn, or
/sapi/* endpoints - RSA request signing
- INLINECODE14
Authentication
Public market endpoints do not require credentials.
Signed Spot endpoints require:
- -
api_key field for INLINECODE16 - INLINECODE17 field for Ed25519 PKCS#8 PEM signing, or
secret_key for deprecated HMAC SHA256 signing
Testnet API Key Setup
Binance Spot testnet uses a separate host and separate API key records from mainnet:
- - base URL: INLINECODE19
- testnet API keys do not work on mainnet
- mainnet API keys do not work on testnet
There are two practical testnet flows:
- 1.
Ed25519 (recommended by Binance)
- Generate an Ed25519 keypair locally.
- Register the public key in the Spot testnet API management UI.
- After registration, Binance shows a distinct
API key for that Ed25519 key record.
- Use that displayed
API key in
X-MBX-APIKEY, and use the matching private key PEM for signing.
- 2.
HMAC (legacy compatibility)
- Create an HMAC key in the Spot testnet API management UI.
- Binance shows both
API key and
Secret key.
- Use
API key in
X-MBX-APIKEY, and use
Secret key for HMAC SHA256 signing.
Important:
- - The Ed25519 public key you upload is not the
API key. - Each Binance key record has its own
API key. - Do not mix an HMAC
API key with an Ed25519 private key, or an Ed25519 API key with an HMAC secret. - If you do, Binance returns INLINECODE34
Recommended Credential Setup
Binance recommends Ed25519. Store the private key PEM text in an environment variable, or source it from 1Password.
CODEBLOCK0
Create one credential per environment so mainnet and testnet keys are never mixed:
CODEBLOCK1
Add one signer binding per environment:
CODEBLOCK2
HMAC Fallback
If you already have legacy HMAC keys, uxc still supports them:
CODEBLOCK3
Core Workflow
- 1. Use fixed link commands by default:
-
command -v binance-spot-mainnet-openapi-cli
- If missing, create it:
uxc link binance-spot-mainnet-openapi-cli https://api.binance.com --schema-url https://raw.githubusercontent.com/holon-run/uxc/main/skills/binance-spot-openapi-skill/references/binance-spot.openapi.json
-
command -v binance-spot-testnet-openapi-cli
- If missing, create it:
INLINECODE40
- 2. Discover operations with help-first flow:
-
binance-spot-mainnet-openapi-cli -h
-
binance-spot-testnet-openapi-cli -h
-
binance-spot-testnet-openapi-cli post:/api/v3/order/test -h
- INLINECODE44
- 3. Execute reads first:
- public read:
binance-spot-mainnet-openapi-cli get:/api/v3/ticker/price symbol=BTCUSDT
- signed read:
INLINECODE46
- 4. Use
order/test before real writes:
- INLINECODE48
Operation Groups
Public Market
- - INLINECODE49
- INLINECODE50
- INLINECODE51
- INLINECODE52
- INLINECODE53
- INLINECODE54
- INLINECODE55
- INLINECODE56
- INLINECODE57
Signed Reads
- - INLINECODE58
- INLINECODE59
- INLINECODE60
- INLINECODE61
- INLINECODE62
- INLINECODE63
Signed Writes
- - INLINECODE64
- INLINECODE65
- INLINECODE66
- INLINECODE67
Guardrails
- - Keep automation on the JSON output envelope; do not use
--text. - Parse stable fields first:
ok, kind, protocol, data, error. - Treat
order/test as the default validation path before any real order placement. - Treat all mainnet write operations as high-risk and require explicit user confirmation before execution.
- Prefer testnet for all signed examples unless the user explicitly asks for mainnet.
- Before placing orders, query
exchangeInfo for symbol filters and ticker/price or depth for current market context. - If Binance returns
-1021, call get:/api/v3/time, then retry with a fresh timestamp and, if needed, a larger recvWindow. - If Binance returns
-1022, first verify you are using the API key from the same Binance key record as the signing material:
- Ed25519: displayed
API key + matching private key PEM
- HMAC: displayed
API key + matching
Secret key
- - Use
--path-prefix /api/v3 on auth bindings. uxc now resolves OpenAPI auth against the final operation URL, so this narrower binding works for signed Spot requests and avoids over-broad host-level matching. - INLINECODE88 and
signature are injected by the signer binding; users normally provide business parameters plus optional recvWindow. - INLINECODE91 is equivalent to
uxc <host> --schema-url <binance_spot_openapi_schema> <operation> ....
References
- - Usage patterns: INLINECODE93
- Curated OpenAPI schema: INLINECODE94
- Binance Spot skill source material: https://github.com/binance/binance-skills-hub/tree/main/skills/binance/spot
- Official Binance Spot API docs: https://github.com/binance/binance-spot-api-docs
Binance 现货 API 技能
使用此技能通过 uxc + OpenAPI 运行 Binance 现货 REST 操作。
复用 uxc 技能以获取共享执行、认证和错误处理指导。
前提条件
- - uxc 已安装并存在于 PATH 中。
- 网络可访问:
- https://api.binance.com
- https://testnet.binance.vision
- https://raw.githubusercontent.com/holon-run/uxc/main/skills/binance-spot-openapi-skill/references/binance-spot.openapi.json
范围
此技能涵盖精选的 Binance 现货 REST 端点,用于:
- - 公开市场读取
- 签名账户读取
- 签名订单查询
- 测试订单
- 订单下达和取消
此技能不涵盖:
- - OCO、OTO、OTOCO、OPO、OPOCO 或其他 orderList/ 端点
- order/cancelReplace
- order/amend/
- historicalTrades
- uiKlines
- ticker/tradingDay
- SOR 端点
- 钱包、保证金、理财或 /sapi/* 端点
- RSA 请求签名
- https://demo-api.binance.com
认证
公开市场端点不需要凭据。
签名现货端点需要:
- - apikey 字段用于 X-MBX-APIKEY
- privatekey 字段用于 Ed25519 PKCS#8 PEM 签名,或 secret_key 用于已弃用的 HMAC SHA256 签名
测试网 API 密钥设置
Binance 现货测试网使用与主网不同的主机和独立的 API 密钥记录:
- - 基础 URL:https://testnet.binance.vision
- 测试网 API 密钥在主网无效
- 主网 API 密钥在测试网无效
有两种实用的测试网流程:
- 1. Ed25519(Binance 推荐)
- 在本地生成 Ed25519 密钥对。
- 在现货测试网 API 管理界面中注册公钥。
- 注册后,Binance 会为该 Ed25519 密钥记录显示一个独立的 API key。
- 在 X-MBX-APIKEY 中使用显示的 API key,并使用匹配的私钥 PEM 进行签名。
- 2. HMAC(旧版兼容)
- 在现货测试网 API 管理界面中创建 HMAC 密钥。
- Binance 会同时显示 API key 和 Secret key。
- 在 X-MBX-APIKEY 中使用 API key,并使用 Secret key 进行 HMAC SHA256 签名。
重要提示:
- - 您上传的 Ed25519 公钥不是 API key。
- 每个 Binance 密钥记录都有自己的 API key。
- 不要将 HMAC API key 与 Ed25519 私钥混用,或将 Ed25519 API key 与 HMAC 密钥混用。
- 如果混用,Binance 会返回 -1022 Signature for this request is not valid.
推荐凭据设置
Binance 推荐使用 Ed25519。将私钥 PEM 文本存储在环境变量中,或从 1Password 获取。
bash
export BINANCETESTNETED25519PRIVATEKEY=$(cat /absolute/path/to/binancetestneted25519_private.pem)
export BINANCEMAINNETED25519PRIVATEKEY=$(cat /absolute/path/to/binancemainneted25519_private.pem)
为每个环境创建一个凭据,以确保主网和测试网密钥永不混用:
bash
uxc auth credential set binance-spot-mainnet \
--auth-type api_key \
--field apikey=env:BINANCEMAINNETAPIKEY \
--field privatekey=env:BINANCEMAINNETED25519PRIVATE_KEY
uxc auth credential set binance-spot-testnet \
--auth-type api_key \
--field apikey=env:BINANCETESTNETAPIKEY \
--field privatekey=env:BINANCETESTNETED25519PRIVATE_KEY
为每个环境添加一个签名者绑定:
bash
uxc auth binding add \
--id binance-spot-mainnet \
--host api.binance.com \
--path-prefix /api/v3 \
--scheme https \
--credential binance-spot-mainnet \
--signer-json {kind:ed25519queryv1,algorithm:ed25519,signingfield:privatekey,keyfield:apikey,keyplacement:header,keyname:X-MBX-APIKEY,signatureparam:signature,signatureencoding:base64,timestampparam:timestamp,timestampunit:milliseconds,canonicalization:{mode:preserve_order}} \
--priority 100
uxc auth binding add \
--id binance-spot-testnet \
--host testnet.binance.vision \
--path-prefix /api/v3 \
--scheme https \
--credential binance-spot-testnet \
--signer-json {kind:ed25519queryv1,algorithm:ed25519,signingfield:privatekey,keyfield:apikey,keyplacement:header,keyname:X-MBX-APIKEY,signatureparam:signature,signatureencoding:base64,timestampparam:timestamp,timestampunit:milliseconds,canonicalization:{mode:preserve_order}} \
--priority 100
HMAC 回退
如果您已有旧版 HMAC 密钥,uxc 仍然支持它们:
bash
uxc auth credential set binance-spot-mainnet-hmac \
--auth-type api_key \
--field apikey=env:BINANCEMAINNETAPIKEY \
--field secretkey=env:BINANCEMAINNETSECRETKEY
uxc auth credential set binance-spot-testnet-hmac \
--auth-type api_key \
--field apikey=env:BINANCETESTNETAPIKEY \
--field secretkey=env:BINANCETESTNETSECRETKEY
uxc auth binding add \
--id binance-spot-mainnet-hmac \
--host api.binance.com \
--path-prefix /api/v3 \
--scheme https \
--credential binance-spot-mainnet-hmac \
--signer-json {kind:hmacqueryv1,algorithm:hmacsha256,signingfield:secretkey,keyfield:apikey,keyplacement:header,keyname:X-MBX-APIKEY,signatureparam:signature,signatureencoding:hex,timestampparam:timestamp,timestampunit:milliseconds,canonicalization:{mode:preserveorder}} \
--priority 100
uxc auth binding add \
--id binance-spot-testnet-hmac \
--host testnet.binance.vision \
--path-prefix /api/v3 \
--scheme https \
--credential binance-spot-testnet-hmac \
--signer-json {kind:hmacqueryv1,algorithm:hmacsha256,signingfield:secretkey,keyfield:apikey,keyplacement:header,keyname:X-MBX-APIKEY,signatureparam:signature,signatureencoding:hex,timestampparam:timestamp,timestampunit:milliseconds,canonicalization:{mode:preserveorder}} \
--priority 100
核心工作流程
- 1. 默认使用固定链接命令:
- command -v binance-spot-mainnet-openapi-cli
- 如果缺失,创建它:
uxc link binance-spot-mainnet-openapi-cli https://api.binance.com --schema-url https://raw.githubusercontent.com/holon-run/uxc/main/skills/binance-spot-openapi-skill/references/binance-spot.openapi.json
- command -v binance-spot-testnet-openapi-cli
- 如果缺失,创建它:
uxc link binance-spot-testnet-openapi-cli https://testnet.binance.vision --schema-url https://raw.githubusercontent.com/holon-run/uxc/main/skills/binance-spot-openapi-skill/references/binance-spot.openapi.json
- 2. 使用帮助优先流程发现操作:
- binance-spot-mainnet-openapi-cli -h
- binance-spot-testnet-openapi-cli -h
- binance-spot-testnet-openapi-cli post:/api/v3/order/test -h
- binance-spot-testnet-openapi-cli get:/api/v3/account