概述

欢迎使用 Legend Gateway API。本文档为您提供接入我们 API 服务的完整指南,包括认证方式、请求规范、错误处理及示例代码。


认证方式


Token 申请流程

所有 API 接口均为私有接口,调用需提供有效访问令牌。请按以下流程申请:


  1. 发送申请邮件

收件人: [email protected]

邮件标题: 【交易所名称 Token申请】

邮件内容:

麻烦回答以下问题,用于配置测试环境和账号: 

homepage_url: 官网地址

api_url: 回调地址 

api_key: 用于鉴权.Optional.

associated_email: 用于在legend注册账户用 

联系人email: 用于接收creds 

Telegram 联系人: 用于接收creds的解密密码 

IPs: 添加白名单 

logo下载地址: 600x200 

Legend landing/用户入口页面URL:  

添加Legend服务器白名单IP

Token 有效期

Token 有效期为 1 年

失效前Legend 会主动通知

请求头参数说明

参数名类型必填默认值说明
Authorizationstring(无)认证令牌,格式:Bearer {你的Token}
Content-Typestringapplication/json请求体内容类型,固定为 application/json
Acceptstringapplication/json期望的响应内容类型,固定为 application/json
User-Ipstring(无)终端用户的真实IP地址,用于风控和审计

使用示例:

Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
Content-Type: application/json
Accept: application/json
User-Ip: 123.45.67.89

注意事项:

  • Authorization 头必须包含有效的访问令牌
  • User-Ip 必须提供真实的终端用户公网IP地址,不可使用服务器IP或内网IP
  • 所有API请求必须包含这四个请求头参数

错误响应示例

Token 失效

v1接口返回:

{ "message": "Unauthenticated."}

v2接口返回:

{
  "request_id": "21c1bec06e1086924127c6e22e42c49e",
  "status": "error",
  "code": "101003",
  "message": "Unauthenticated",
  "errors": [
    {
      "message": "Unauthenticated."
    }
  ],
  "metadata": {}
}

IP 地域限制

{
  "request_id": "3cca1262df14f53f7798f3901d5539c4",
  "status": "error",
  "code": "101100",
  "message": "Due to compliance reasons, we are unable to offer services to users from this region.",
  "errors": [],
  "metadata": {
    "ip": "117.104.227.243",
    "country": "Afghanistan"
  }
}`

提示: 可通过接口 https://ex.legendtrading.com/v2.0/reference/ip 获取不支持交易的国家名单


服务器IP未授权

当请求服务器IP不在白名单内时返回:

`

{
  'error': 401, 
  'message': 'Access restricted.'
}

Sandbox 测试环境

https://sandboxapi.legendtrading.com

生产环境

https://api.legendtrading.com


代码示例

示例 1: GET 请求

curl -s \
  -H "Authorization: Bearer 您的Token" \
  -H "Accept: application/json" \
  -H "User-Ip: 12.34.56.78" \
  "https://sandboxapi.legendtrading.com/v2/app/countries"

成功返回

{
  "request_id": "0578ac927c446fedd16a32e2846028a9",
  "status": "success",
  "code": "100000",
  "message": "success",
  "data": [
    {
      "country_iso2_code": "AF"
    }
  ],
  "metadata": {}
}

示例 2: POST 请求(KYC个人认证)

curl -X POST \
  -H "Authorization: Bearer 您的Token" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "User-Ip: 12.34.56.78" \
  -d '{
    "uid": "sandbox_test_uid1",
    "email": "[email protected]",
    "first_name": "Testname",
    "last_name": "Testlastname",
    "birthdate": "1990-01-01",
    "country_iso2_code": "US",
    "state": "California",
    "city": "San Francisco",
    "address": "123 Main St,California",
    "zipcode": "94102",
    "citizenship_iso2_codes": ["US"],
    "place_of_birth": "US",
    "ssn": "123456789"
  }' \
  "https://sandboxapi.legendtrading.com/v2/app/kyc/individual/pi"


成功响应示例

{
  "request_id": "7eacd1af7897465be4ac87570a8bde2a",
  "status": "success",
  "code": "100000",
  "message": "success",
  "data": [],
  "metadata": {}
}

安全提醒

Token 保密: 请妥善保管您的 API Token,切勿在公共代码库或非安全环境中暴露

IP 白名单: 确保所有生产环境请求均来自已授权的服务器IP

超时设置: 建议设置合理的请求超时时间(如8-15秒)

错误处理: 实现完整的异常处理机制,确保系统稳定性