Aster Spot Skill
Spot request on Aster using authenticated API endpoints. Requires API key and secret key for certain endpoints. Return the result in JSON format.
Data Fetching Guidelines (CRITICAL)
NEVER truncate JSON responses with head -c, head -n, or similar — truncated JSON is corrupted and will produce wrong results.
Mandatory Rules
- 1. Always specify
symbol parameter when querying a specific trading pair. Many endpoints return ALL symbols when symbol is omitted, producing responses of 100KB+. - Always use
limit parameter to constrain result size. Use the smallest limit that satisfies the request (e.g., limit=5 instead of default 500). - Use
jq to extract fields — never parse raw mega-JSON visually. Pipe through jq to select only needed data.
Progressive Data Exploration Strategy
When the user asks a broad question (e.g., "what spot pairs are available?"), use a layered approach:
- 1. Step 1 — Get lightweight summary first:
CODEBLOCK0
- 2. Step 2 — Confirm scope with user before fetching detailed data for many symbols.
- 3. Step 3 — Fetch details for specific symbols only:
CODEBLOCK1
Endpoints That Return Dangerously Large Data (without symbol filter)
| Endpoint | Without INLINECODE8 | With INLINECODE9 |
|---|
| INLINECODE10 | ALL symbols + filters (100KB+) | N/A — use jq to filter |
| INLINECODE12 |
ALL symbols (50KB+) | Single object (~500B) |
|
/api/v1/ticker/price | ALL symbols (10KB+) | Single object (~80B) |
|
/api/v1/ticker/bookTicker | ALL symbols (20KB+) | Single object (~150B) |
|
/api/v1/depth | N/A (symbol required) | Varies by
limit: use
limit=5 for overview |
|
/api/v1/klines | N/A (symbol required) | Default 500 candles — always set
limit |
|
/api/v1/trades | N/A (symbol required) | Default 500 trades — always set
limit |
Example: Safe vs Unsafe
CODEBLOCK2
Quick Reference
| Endpoint | Description | Required | Optional | Authentication |
|---|
| INLINECODE22 (GET) | Test server connectivity | None | None | No |
| INLINECODE23 (GET) |
Get server time | None | None | No |
|
/api/v1/exchangeInfo (GET) | Trading specification information | None | None | No |
|
/api/v1/depth (GET) | Order book depth | symbol | limit | No |
|
/api/v1/trades (GET) | Recent trades list | symbol | limit | No |
|
/api/v1/historicalTrades (GET) | Query historical trades | symbol | limit, fromId | Yes |
|
/api/v1/aggTrades (GET) | Compressed/Aggregate trades list | symbol | fromId, startTime, endTime, limit | No |
|
/api/v1/klines (GET) | K-line/Candlestick data | symbol, interval | startTime, endTime, limit | No |
|
/api/v1/ticker/24hr (GET) | 24-hour price change statistics | None | symbol | No |
|
/api/v1/ticker/price (GET) | Latest price ticker | None | symbol | No |
|
/api/v1/ticker/bookTicker (GET) | Best bid/ask price ticker | None | symbol | No |
|
/api/v1/commissionRate (GET) | Get symbol commission rate | symbol, timestamp | recvWindow | Yes |
|
/api/v1/order (POST) | Place new order | symbol, side, type, timestamp | timeInForce, quantity, quoteOrderQty, price, newClientOrderId, stopPrice, recvWindow | Yes |
|
/api/v1/order (DELETE) | Cancel order | symbol, timestamp | orderId, origClientOrderId, recvWindow | Yes |
|
/api/v1/order (GET) | Query order | symbol, timestamp | orderId, origClientOrderId, recvWindow | Yes |
|
/api/v1/allOpenOrders (DELETE) | Cancel all open orders on a symbol | symbol, timestamp | orderIdList, origClientOrderIdList, recvWindow | Yes |
|
/api/v1/openOrders (GET) | Current open orders | timestamp | symbol, recvWindow | Yes |
|
/api/v1/allOrders (GET) | Query all orders | symbol, timestamp | orderId, startTime, endTime, limit, recvWindow | Yes |
|
/api/v1/account (GET) | Account information | timestamp | recvWindow | Yes |
|
/api/v1/userTrades (GET) | Account trade history | timestamp | symbol, orderId, startTime, endTime, fromId, limit, recvWindow | Yes |
|
/api/v1/asset/wallet/transfer (POST) | Perp-Spot transfer | amount, asset, clientTranId, kindType, timestamp | None | Yes |
|
/api/v1/asset/sendToAddress (POST) | Transfer asset to other address | amount, asset, toAddress, timestamp | clientTranId, recvWindow | Yes |
|
/api/v1/aster/withdraw/estimateFee (GET) | Get withdrawal fee estimate | chainId, asset | None | No |
|
/api/v1/aster/user-withdraw (POST) | Withdraw funds | chainId, asset, amount, fee, receiver, nonce, userSignature, timestamp | recvWindow | Yes |
|
/api/v1/getNonce (POST) | Get nonce for API key creation | address, userOperationType | network | No |
|
/api/v1/createApiKey (POST) | Create API key | address, userOperationType, userSignature, desc, timestamp | network, apikeyIP, recvWindow | No |
|
/api/v1/listenKey (POST) | Generate user data stream listen key | None | None | Yes (API key only) |
|
/api/v1/listenKey (PUT) | Extend listen key validity | listenKey | None | Yes (API key only) |
|
/api/v1/listenKey (DELETE) | Close user data stream | listenKey | None | Yes (API key only) |
Parameters
Common Parameters
- * symbol: Trading pair (e.g., BTCUSDT)
- limit: Default 500; maximum 1000 (depth endpoint supports: 5, 10, 20, 50, 100, 500, 1000; klines max 1500)
- fromId: Return starting from trade ID (e.g., 1)
- startTime: Timestamp in ms to get data from INCLUSIVE (e.g., 1735693200000)
- endTime: Timestamp in ms to get data until INCLUSIVE (e.g., 1735693200000)
- recvWindow: The value cannot be greater than
60000. Default 5000. (e.g., 5000) - timestamp: Unix timestamp in milliseconds (e.g., 1735693200000)
- quantity: Order quantity (e.g., 1)
- quoteOrderQty: Quote order quantity (e.g., 100)
- price: Order price (e.g., 50000)
- stopPrice: Required for STOP, STOPMARKET, TAKEPROFIT, TAKEPROFITMARKET orders (e.g., 49000)
- newClientOrderId: Client-customized unique order ID. Automatically generated if not sent.
- orderId: Order ID (e.g., 1)
- origClientOrderId: Original client order ID
- orderIdList: Order ID array string (for batch cancel)
- origClientOrderIdList: Client order ID array string (for batch cancel)
- amount: Transfer/withdrawal quantity (e.g., 1.5)
- asset: Asset type (e.g., USDT, BTC)
- clientTranId: Client transaction ID (minimum 20 characters if provided)
- kindType: Transfer direction: FUTURESPOT or SPOTFUTURE
- toAddress: Target EVM address for transfers
- chainId: Chain ID for withdrawals: 1 (ETH), 56 (BSC), 42161 (Arbi)
- fee: Withdrawal fee
- receiver: Current account address (for withdrawals)
- nonce: Current time in microseconds (for withdrawals)
- userSignature: EVM wallet signature
- address: Wallet address (for API key creation)
- userOperationType: Operation type: CREATEAPIKEY
- network: Network type (SOL for Solana network only)
- apikeyIP: Comma-separated IP addresses for whitelist
- desc: API key description (max 20 characters; no duplicates per account)
- listenKey: Listen key for user data streams
Enums
- * side: BUY | SELL
- type (order type): LIMIT | MARKET | STOP | TAKEPROFIT | STOPMARKET | TAKEPROFITMARKET
- timeInForce: GTC | IOC | FOK | GTX
- interval: 1m | 3m | 5m | 15m | 30m | 1h | 2h | 4h | 6h | 8h | 12h | 1d | 3d | 1w | 1M
- kindType: FUTURESPOT | SPOTFUTURE
- orderStatus: NEW | PARTIALLY_FILLED | FILLED | CANCELED | REJECTED | EXPIRED
Authentication
For endpoints that require authentication, you will need to provide Aster API credentials.
Required credentials:
- * apiKey: Your Aster API key (for header)
- secretKey: Your Aster API secret (for signing)
Base URL:
- * Mainnet: https://sapi.asterdex.com
WebSocket:
- * Market Streams: wss://sstream.asterdex.com
See references/authentication.md for implementation details.
Security
Share Credentials
Users can provide Aster API credentials by sending a file where the content is in the following format:
CODEBLOCK3
Never Display Full Secrets
When showing credentials to users:
- - API Key: Show first 5 + last 4 characters: INLINECODE53
- Secret Key: Always mask, show only last 5: INLINECODE54
Example response when asked for credentials:
Account: main
API Key: bb3b2...02ae
Secret: *...ae1c
Environment: Mainnet
Listing Accounts
When listing accounts, show names and environment only — never keys:
Aster Accounts:
- * main (Mainnet)
- trading (Mainnet)
Transactions in Mainnet
When performing transactions in mainnet, always confirm with the user before proceeding by asking them to write "CONFIRM" to proceed.
Aster Accounts
main
- - API Key: yourmainnetapikey
- Secret: yourmainnet_secret
- Testnet: false
TOOLS.md Structure
CODEBLOCK4
Agent Behavior
- 1. Credentials requested: Mask secrets (show last 5 chars only)
- Listing accounts: Show names and environment, never keys
- Account selection: Ask if ambiguous, default to main
- When doing a transaction in mainnet, confirm with user before by asking to write "CONFIRM" to proceed
- New credentials: Prompt for name, environment, signing mode
Adding New Accounts
When user provides new credentials:
- * Ask for account name
- Ask: Mainnet?
- Store in
TOOLS.md with masked display confirmation
Signing Requests
All trading endpoints require HMAC SHA256 signature:
- 1. Build query string with all params + timestamp (Unix ms)
- Sign query string with secretKey using HMAC SHA256
- Append signature to query string
- Include
X-MBX-APIKEY header
See references/authentication.md for implementation details.
Aster Spot 技能
使用经过身份验证的API端点对Aster进行现货请求。某些端点需要API密钥和密钥。以JSON格式返回结果。
数据获取指南(关键)
切勿使用 head -c、head -n 或类似命令截断JSON响应——截断的JSON已损坏,会产生错误结果。
强制性规则
- 1. 查询特定交易对时,始终指定 symbol 参数。省略 symbol 时,许多端点会返回所有交易对,产生100KB+的响应。
- 始终使用 limit 参数限制结果大小。使用满足请求的最小限制(例如,使用 limit=5 而非默认的500)。
- 使用 jq 提取字段——切勿目视解析原始巨型JSON。通过 jq 管道仅选择所需数据。
渐进式数据探索策略
当用户提出宽泛问题(例如有哪些现货交易对可用?)时,使用分层方法:
- 1. 步骤1 — 先获取轻量级摘要:
bash
# 仅获取交易对列表,而非完整的exchangeInfo
curl -s https://sapi.asterdex.com/api/v1/exchangeInfo | jq [.symbols[].symbol]
- 2. 步骤2 — 在获取多个交易对的详细数据前,先与用户确认范围。
- 3. 步骤3 — 仅获取特定交易对的详细信息:
bash
# 获取一个交易对的价格,而非全部
curl -s https://sapi.asterdex.com/api/v1/ticker/price?symbol=BTCUSDT
返回危险大数据量的端点(无symbol过滤)
| 端点 | 无 symbol | 有 symbol |
|---|
| /api/v1/exchangeInfo | 所有交易对+过滤器(100KB+) | 不适用——使用 jq 过滤 |
| /api/v1/ticker/24hr |
所有交易对(50KB+) | 单个对象(~500B) |
| /api/v1/ticker/price | 所有交易对(10KB+) | 单个对象(~80B) |
| /api/v1/ticker/bookTicker | 所有交易对(20KB+) | 单个对象(~150B) |
| /api/v1/depth | 不适用(需要symbol) | 因 limit 而异:使用 limit=5 进行概览 |
| /api/v1/klines | 不适用(需要symbol) | 默认500根K线——始终设置 limit |
| /api/v1/trades | 不适用(需要symbol) | 默认500笔交易——始终设置 limit |
示例:安全与不安全
bash
错误——返回所有交易对,然后截断=损坏的JSON
curl -s .../api/v1/ticker/price | head -c 5000
正确——返回单个交易对,完整JSON
curl -s .../api/v1/ticker/price?symbol=BTCUSDT
错误——默认500根K线
curl -s .../api/v1/klines?symbol=BTCUSDT&interval=1h
正确——仅5根K线
curl -s .../api/v1/klines?symbol=BTCUSDT&interval=1h&limit=5
正确——从exchangeInfo中仅提取交易对名称
curl -s .../api/v1/exchangeInfo | jq [.symbols[] | {symbol, status}]
快速参考
| 端点 | 描述 | 必需参数 | 可选参数 | 身份验证 |
|---|
| /api/v1/ping (GET) | 测试服务器连接 | 无 | 无 | 否 |
| /api/v1/time (GET) |
获取服务器时间 | 无 | 无 | 否 |
| /api/v1/exchangeInfo (GET) | 交易规范信息 | 无 | 无 | 否 |
| /api/v1/depth (GET) | 订单簿深度 | symbol | limit | 否 |
| /api/v1/trades (GET) | 近期交易列表 | symbol | limit | 否 |
| /api/v1/historicalTrades (GET) | 查询历史交易 | symbol | limit, fromId | 是 |
| /api/v1/aggTrades (GET) | 压缩/聚合交易列表 | symbol | fromId, startTime, endTime, limit | 否 |
| /api/v1/klines (GET) | K线/蜡烛图数据 | symbol, interval | startTime, endTime, limit | 否 |
| /api/v1/ticker/24hr (GET) | 24小时价格变动统计 | 无 | symbol | 否 |
| /api/v1/ticker/price (GET) | 最新价格行情 | 无 | symbol | 否 |
| /api/v1/ticker/bookTicker (GET) | 最优买卖盘口行情 | 无 | symbol | 否 |
| /api/v1/commissionRate (GET) | 获取交易对手续费率 | symbol, timestamp | recvWindow | 是 |
| /api/v1/order (POST) | 下新订单 | symbol, side, type, timestamp | timeInForce, quantity, quoteOrderQty, price, newClientOrderId, stopPrice, recvWindow | 是 |
| /api/v1/order (DELETE) | 取消订单 | symbol, timestamp | orderId, origClientOrderId, recvWindow | 是 |
| /api/v1/order (GET) | 查询订单 | symbol, timestamp | orderId, origClientOrderId, recvWindow | 是 |
| /api/v1/allOpenOrders (DELETE) | 取消交易对所有未成交订单 | symbol, timestamp | orderIdList, origClientOrderIdList, recvWindow | 是 |
| /api/v1/openOrders (GET) | 当前未成交订单 | timestamp | symbol, recvWindow | 是 |
| /api/v1/allOrders (GET) | 查询所有订单 | symbol, timestamp | orderId, startTime, endTime, limit, recvWindow | 是 |
| /api/v1/account (GET) | 账户信息 | timestamp | recvWindow | 是 |
| /api/v1/userTrades (GET) | 账户交易历史 | timestamp | symbol, orderId, startTime, endTime, fromId, limit, recvWindow | 是 |
| /api/v1/asset/wallet/transfer (POST) | 永续-现货转账 | amount, asset, clientTranId, kindType, timestamp | 无 | 是 |
| /api/v1/asset/sendToAddress (POST) | 将资产转账至其他地址 | amount, asset, toAddress, timestamp | clientTranId, recvWindow | 是 |
| /api/v1/aster/withdraw/estimateFee (GET) | 获取提现费用估算 | chainId, asset | 无 | 否 |
| /api/v1/aster/user-withdraw (POST) | 提现资金 | chainId, asset, amount, fee, receiver, nonce, userSignature, timestamp | recvWindow | 是 |
| /api/v1/getNonce (POST) | 获取创建API密钥的nonce | address, userOperationType | network | 否 |
| /api/v1/createApiKey (POST) | 创建API密钥 | address, userOperationType, userSignature, desc, timestamp | network, apikeyIP, recvWindow | 否 |
| /api/v1/listenKey (POST) | 生成用户数据流监听密钥 | 无 | 无 | 是(仅API密钥) |
| /api/v1/listenKey (PUT) | 延长监听密钥有效期 | listenKey | 无 | 是(仅API密钥) |
| /api/v1/listenKey (DELETE) | 关闭用户数据流 | listenKey | 无 | 是(仅API密钥) |
参数
通用参数
- * symbol: 交易对(例如 BTCUSDT)
- limit: 默认500;最大1000(深度端点支持:5, 10, 20, 50, 100, 500, 1000;K线最大1500)
- fromId: 从指定交易ID开始返回(例如 1)
- startTime: 获取数据的起始时间戳(毫秒,包含该时间点)(例如 1735693200000)
- endTime: 获取数据的结束时间戳(毫秒,包含该时间点)(例如 1735693200000)
- recvWindow: