Skip to Content

API 参考

📋 目录


❌ 错误代码

错误代码汇总
错误代码说明解决方案
100011参数错误检查请求参数是否正确
410002签名验证失败检查签名算法和密钥是否正确
410001API Key 无效检查 API Key 是否正确
410006权限不足检查 API Key 的权限设置
常见错误处理
1. 签名验证失败 (410002)

可能原因:

  • API Secret 错误
  • 签名算法实现有误
  • 参数排序不正确
  • 时间戳或 nonce 格式错误

解决方案:

  1. 检查 API Secret 是否正确
  2. 验证签名算法的实现
  3. 确保参数按照字典序排序
  4. 检查时间戳和 nonce 的格式

📚 参考资料

官方资源
第三方资源
开发工具
编程语言资源
JavaScript/Node.js
Java
Python

🔧 技术规范

HTTP 状态码
状态码说明
200请求成功
400请求参数错误
401认证失败
403权限不足
404资源不存在
429请求频率超限
500服务器内部错误
502网关错误
503服务不可用
504网关超时
数据格式
请求格式
  • Content-Type: application/json
  • 字符编码: UTF-8
  • 时间格式: Unix 时间戳(毫秒)
响应格式
{ "code": "0", "data": {}, "msg": "请求成功", "success": true, "timestamp": 1640995200000 }
时间格式
  • 时间戳: Unix 时间戳,毫秒级精度
  • 时间字符串: ISO 8601 格式 (YYYY-MM-DDTHH:mm:ss.sssZ)
  • 时区: UTC 时间
数值精度
  • 价格: 根据交易对配置的精度
  • 数量: 根据交易对配置的精度
  • 金额: 根据币种配置的精度
  • 手续费: 根据币种配置的精度

🚀 最佳实践

1. 错误处理
try { const response = await apiRequest(endpoint, params); if (response.code === '0') { // 处理成功响应 handleSuccess(response.data); } else { // 处理业务错误 handleBusinessError(response.code, response.msg); } } catch (error) { // 处理网络错误 handleNetworkError(error); }
2. 重试机制
async function makeRequestWithRetry(endpoint, params, maxRetries = 3) { for (let i = 0; i < maxRetries; i++) { try { return await apiRequest(endpoint, params); } catch (error) { if (i === maxRetries - 1) throw error; // 指数退避 const delay = Math.pow(2, i) * 1000; await new Promise(resolve => setTimeout(resolve, delay)); } } }
3. 请求限流
class RateLimiter { constructor(maxRequests, timeWindow) { this.maxRequests = maxRequests; this.timeWindow = timeWindow; this.requests = []; } async throttle() { const now = Date.now(); this.requests = this.requests.filter(time => now - time < this.timeWindow); if (this.requests.length >= this.maxRequests) { const oldestRequest = this.requests[0]; const waitTime = this.timeWindow - (now - oldestRequest); await new Promise(resolve => setTimeout(resolve, waitTime)); } this.requests.push(now); } }
4. 日志记录
class ApiLogger { static log(level, message, data = {}) { const logEntry = { timestamp: new Date().toISOString(), level, message, data }; console.log(JSON.stringify(logEntry)); // 可以发送到日志服务 if (level === 'ERROR') { this.sendToLogService(logEntry); } } }

📞 技术支持

联系方式
支持时间
  • 工作日: 9:00 - 18:00 (UTC+8)
  • 周末: 10:00 - 16:00 (UTC+8)
  • 节假日: 10:00 - 16:00 (UTC+8)
问题反馈

如果您在使用过程中遇到问题,请提供以下信息:

  1. 错误描述: 详细描述遇到的问题
  2. 错误代码: 如果有错误代码,请提供
  3. 请求信息: 请求的接口、参数等
  4. 环境信息: 使用的编程语言、版本等
  5. 日志信息: 相关的错误日志

📄 许可证

本文档和相关代码示例采用 MIT 许可证。

MIT License

Copyright (c) 2024 BitTap

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

最后更新于: