跳到主要内容

Introduction

欢迎使用 ZTDX API 文档。ZTDX 提供高性能的加密货币交易 API,支持现货、永续合约交易。

基本信息

项目内容
REST Base URLhttps://api.ztdx.io
WebSocket Base URLwss://ws.ztdx.io
响应格式JSON

身份验证

API 使用基于 Ethereum 的签名验证机制。大多数私有接口需要提供 signaturetimestamp 参数。

签名过程

  1. 准备待签名消息:timestamp + method + path + body
  2. 使用私钥进行消息哈希和签名
  3. 将签名和时间戳放入请求参数或 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)

错误码

状态码描述含义
200OK请求成功
400Bad Request参数错误或业务逻辑违规
401Unauthorized签名验证失败
429Too Many Requests触发频率限制
500Internal 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())