Introduction
欢迎使用 ZTDX API 文档。ZTDX 提供高性能的加密货币交易 API,支持现货、永续合约交易。
基本信息
| 项目 | 内容 |
|---|---|
| REST Base URL | https://api.ztdx.io |
| WebSocket Base URL | wss://ws.ztdx.io |
| 响应格式 | JSON |
身份验证
API 使用基于 Ethereum 的签名验证机制。大多数私有接口需要提供 signature 和 timestamp 参数。
签名过程
- 准备待签名消息:
timestamp+method+path+body - 使用私钥进行消息哈希和签名
- 将签名和时间戳放入请求参数或 Header 中
# 示例 Python 签名代码
import time
from eth_account.messages import encode_defunct
timestamp = int(time.time() * 1000)
message = f"{timestamp}GET/api/v1/account/balances"
signature = w3.eth.account.sign_message(encode_defunct(text=message), private_key=pk)
错误码
| 状态码 | 描述 | 含义 |
|---|---|---|
| 200 | OK | 请求成功 |
| 400 | Bad Request | 参数错误或业务逻辑违规 |
| 401 | Unauthorized | 签名验证失败 |
| 429 | Too Many Requests | 触 发频率限制 |
| 500 | Internal Server Error | 服务器内部错误 |
快速集成 (Quick Start)
这是一个使用 Python 快速登录并查询余额的示例:
import asyncio
from lib.api_client import APIClient
from lib.auth_signer import AuthSigner
from eth_account import Account
async def main():
address = "0x..."
private_key = "0x..."
account = Account.from_key(private_key)
async with APIClient() as client:
# 1. 获取 Nonce 并登录
nonce_resp = await client.get_nonce(address)
signer = AuthSigner(account)
sig, ts = signer.sign_login_message(nonce_resp["nonce"])
await client.login(address, sig, ts)
# 2. 查询余额
balances = await client.get_balances()
print(f"账户余额: {balances}")
if __name__ == "__main__":
asyncio.run(main())