WEEX官方API開發者文檔v2版-現貨|API接口,配置指南與技術支援

API 域名

您可以自行使用 Rest API 存取方式進行操作。

域名API描述
現貨 rest 域名https://api-spot.weex.com主域名
合約 rest 域名https://api-contract.weex.com主域名

簽名

ACCESS-SIGN 的請求頭是對 timestamp + method.toUpperCase() + requestPath + “?” + queryString + body 字串 (+表示字串連接) 使用 HMAC SHA256 方法加密,透過 BASE64 編碼輸出而得到的。

簽名各欄位說明

  • timestamp:與 ACCESS-TIMESTAMP 請求頭相同。
  • method:請求方法 (POST/GET),字母全部大寫。
  • requestPath:請求接口路徑。
  • queryString:請求 URL中 (?後的請求參數) 的查詢字串。
  • body:請求主體對應的字串,如果請求沒有主體(通常為 GET 請求)則 body 可省略。

queryString 為空時,簽名格式

  • timestamp + method.toUpperCase() + requestPath + body

queryString 不為空時,簽名格式

  • timestamp + method.toUpperCase() + requestPath + “?” + queryString + body

舉例說明

取得深度訊息,以 btcusdt 為例:

  • Timestamp = 1591089508404
  • Method = “GET”
  • requestPath = “/api/v2/market/depth”
  • queryString= “?symbol=btcusdt_spbl&limit=20”

產生待簽章的字串:

  • ‘1591089508404GET/api/v2/market/depth?symbol=btcusdt_spbl&limit=20’

下單,以 btcusdt 為例:

  • Timestamp = 1561022985382
  • Method = “POST”
  • requestPath = “/api/v2/order/order”
  • body =
{"symbol":"btcusdt_spbl","quantity":"8","side":"buy","price":"1","orderType":"limit","clientOrderId":"ww#123456"}

產生待簽章的字串:

'1561022985382POST/api/spotPro/v3/order/order{"symbol":"btcusdt_spbl","size":"8","side":"buy","price":"1","orderType":"limit","clientOrderId":"ww#123456"}'

產生最終簽名的步驟**

  1. 將待簽章字串使用私鑰 secretkey 進行 hmac sha256 加密
    • Signature = hmac_sha256(secretkey, Message)
  2. 對於 Signature 進行 base64 編碼
    • Signature = base64.encode(Signature)

请求交互

package com.weex.lcp.utils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class ApiClient {
// API信息
private static final String API_KEY = ""; // 替换为实际的 API Key
private static final String SECRET_KEY = ""; // 替换为实际的 Secret Key
private static final String ACCESS_PASSPHRASE = ""; // 替换为实际的 Access Passphrase
private static final String BASE_URL = ""; // 替换为实际的 API 地址
// 生成签名(POST请求)
public static String generateSignature(String secretKey, String timestamp, String method, String requestPath, String queryString, String body) throws Exception {
String message = timestamp + method.toUpperCase() + requestPath + queryString + body;
return generateHmacSha256Signature(secretKey, message);
}
// 生成签名(GET请求)
public static String generateSignatureGet(String secretKey, String timestamp, String method, String requestPath, String queryString) throws Exception {
String message = timestamp + method.toUpperCase() + requestPath + queryString;
return generateHmacSha256Signature(secretKey, message);
}
// 生成 HMAC SHA256 签名
private static String generateHmacSha256Signature(String secretKey, String message) throws Exception {
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(secretKeySpec);
byte[] signatureBytes = mac.doFinal(message.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(signatureBytes);
}
// 发送 POST 请求
public static String sendRequestPost(String apiKey, String secretKey, String accessPassphrase, String method, String requestPath, String queryString, String body) throws Exception {
String timestamp = String.valueOf(System.currentTimeMillis());
String signature = generateSignature(secretKey, timestamp, method, requestPath, queryString, body);
HttpPost postRequest = new HttpPost(BASE_URL + requestPath);
postRequest.setHeader("ACCESS-KEY", apiKey);
postRequest.setHeader("ACCESS-SIGN", signature);
postRequest.setHeader("ACCESS-TIMESTAMP", timestamp);
postRequest.setHeader("ACCESS-PASSPHRASE", accessPassphrase);
postRequest.setHeader("Content-Type", "application/json");
postRequest.setHeader("locale", "zh-CN");
StringEntity entity = new StringEntity(body, StandardCharsets.UTF_8);
postRequest.setEntity(entity);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
CloseableHttpResponse response = httpClient.execute(postRequest);
return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
}
}
// 发送 GET 请求
public static String sendRequestGet(String apiKey, String secretKey, String accessPassphrase, String method, String requestPath, String queryString) throws Exception {
String timestamp = String.valueOf(System.currentTimeMillis());
String signature = generateSignatureGet(secretKey, timestamp, method, requestPath, queryString);
HttpGet getRequest = new HttpGet(BASE_URL + requestPath+queryString);
getRequest.setHeader("ACCESS-KEY", apiKey);
getRequest.setHeader("ACCESS-SIGN", signature);
getRequest.setHeader("ACCESS-TIMESTAMP", timestamp);
getRequest.setHeader("ACCESS-PASSPHRASE", accessPassphrase);
getRequest.setHeader("Content-Type", "application/json");
getRequest.setHeader("locale", "zh-CN");
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
CloseableHttpResponse response = httpClient.execute(getRequest);
return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
}
}
// 示例调用
public static void main(String[] args) {
try {
// GET 请求示例
String requestPath = "/api/uni/v3/order/currentPlan";
String queryString = "?symbol=cmt_bchusdt&delegateType=0&startTime=1742213127794&endTime=1742213506548";
String response = sendRequestGet(API_KEY, SECRET_KEY, ACCESS_PASSPHRASE, "GET", requestPath, queryString);
System.out.println("GET Response: " + response);
// POST 请求示例
String body = "{\"symbol\": \"ETHUSDT_SPBL\", \"limit\": \"2\"}";
response = sendRequestPost(API_KEY, SECRET_KEY, ACCESS_PASSPHRASE, "POST", requestPath, "", body);
System.out.println("POST Response: " + response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
import time
import hmac
import hashlib
import base64
import requests
import json

api_key = ""
secret_key = ""
access_passphrase = ""

def generate_signature(secret_key, timestamp, method, request_path, query_string, body): message = timestamp + method.upper() + request_path + query_string + str(body)
signature = hmac.new(secret_key.encode(), message.encode(), hashlib.sha256).digest()
print(base64.b64encode(signature).decode())
return base64.b64encode(signature).decode()

def generate_signature_get(secret_key, timestamp, method, request_path, query_string):
message = timestamp + method.upper() + request_path + query_string
signature = hmac.new(secret_key.encode(), message.encode(), hashlib.sha256).digest()
# print(base64.b64encode(signature).decode())
return base64.b64encode(signature).decode()

def send_request_post(api_key, secret_key, access_passphrase, method, request_path, query_string, body):
timestamp = str(int(time.time() * 1000))
# print(timestamp)

body = json.dumps(body)
signature = generate_signature(secret_key, timestamp, method, request_path, query_string, body)

headers = {
    "ACCESS-KEY": api_key,
    "ACCESS-SIGN": signature,
    "ACCESS-TIMESTAMP": timestamp,
    "ACCESS-PASSPHRASE": access_passphrase,
    "Content-Type": "application/json",
    "locale": "zh-CN"
}

url = "https://contract-openapi.weex.com"  # 请替换为实际的API地址
if method == "GET":
    response = requests.get(url + request_path, headers=headers)
elif method == "POST":
    response = requests.post(url + request_path, headers=headers, data=body)
return response

def send_request_get(api_key, secret_key, access_passphrase, method, request_path, query_string):
timestamp = str(int(time.time() * 1000))
# print(timestamp)

signature = generate_signature_get(secret_key, timestamp, method, request_path, query_string)

headers = {
    "ACCESS-KEY": api_key,
    "ACCESS-SIGN": signature,
    "ACCESS-TIMESTAMP": timestamp,
    "ACCESS-PASSPHRASE": access_passphrase,
    "Content-Type": "application/json",
    "locale": "zh-CN"
}

url = "https://contract-openapi.weex.com"  # 请替换为实际的API地址
if method == "GET":
    response = requests.get(url + request_path, headers=headers)
return response

# 示例调用 GET 请求

request_path = "/api/spot/v1/account/assets"

# request_path = "/api/spot/v1/public/currencies" # 查看币对列表

query_string = ''
body = ''
response = send_request_get(api_key, secret_key, access_passphrase, "GET", request_path, query_string)

# 示例调用 POST 请求
# request_path = "/api/spot/v1/trade/fills"
# body = {"symbol": "ETHUSDT_SPBL", "limit": "2"}
# query_string = ""
# response = send_request_post(api_key, secret_key, access_passphrase, "POST", request_path, query_string, body)

print(response.status_code)
print(response.text)

所有請求基於Https協議,請求頭資訊中 Content-Type 需要統一設定為: ‘application/json’。

請求互動說明

  • 請求參數:根據接口請求參數規定進行參數封裝。
  • 提交請求參數:將封裝好的請求參數透過GET/POST方式提交至伺服器。
  • 伺服器回應:伺服器首先對使用者請求資料進行參數安全校驗,透過校驗後根據業務邏輯將回應資料以JSON格式傳回給使用者。
  • 資料處理:對伺服器回應資料進行處理。

成功

HTTP 狀態碼 200 表示成功回應,並可能包含內容。如果回應含有內容,則會顯示在對應的回傳內容裡面。

常見錯誤碼

  • 400 Bad Request – Invalid request format 請求格式無效
  • 401 Unauthorized – Invalid API Key 無效的API Key
  • 403 Forbidden – You do not have access to the requested resource 請求無權
  • 404 Not Found 沒有找到請求
  • 429 Too Many Requests 請求太頻繁被系統限流
  • 500 Internal Server Error – We had a problem with our server 伺服器內部錯誤
  • 如果失敗body帶有錯誤描述訊息

標準規範

時間戳

請求簽名中的 ACCESS-TIMESTAMP 的單位是毫秒。請求的時間戳記必須在 API 服務時間的 30 秒內,否則請求將被視為過期並被拒絕。 如果本地伺服器時間和API伺服器時間之間存在較大的偏差,那麼我們建議您使用透過查詢API伺服器時間來更新 http header。

限頻規則

如果請求過於頻繁系統將自動限制請求,並在 http header 中傳回 429 too many requests 狀態碼。

  • 公共接口:如行情接口,統一限頻為 2 秒最多 20 個請求。
  • 授權接口:透過 apikey 限制授權接口的調用,參考每個接口的限頻規則限頻。

請求格式

目前只有兩種格式的請求方法:GET 和 POST

  • GET: 參數透過 queryString 在路徑中傳輸到伺服器。
  • POST: 參數依照 json 格式傳送 body 傳送到伺服器。

WEEX唯客官網:www.weex.com

你也可以在 CMCCoingecko非小號X(Twitter)YoutubeFacebookLinkedin微博 上關注我们,第一时间获取更多投資導航和福利活動!了解平台幣 WXT 最新資訊請訪問 WXT專區

在線諮詢:

WEEX唯客中文交流群:https://t.me/weex_group

WEEX唯客英文交流群:https://t.me/Weex_Global

讚! (2)
Previous 2025年 5月 7日 下午2:37
Next 2025年 5月 13日 下午1:42

相關推薦

  • Umbra (U1SOL) 現已上線WEEX!

    尊敬的WEEX用戶: 充值:即將開放 交易:2025年12月15日12:10(UTC 8)正式開放 提現:即將開放 立即交易:U1SOL/USDT Umbra (U1SOL) 更多信息: U1代幣源於@Umbrae_Ignis關於神秘陰影力量的推文報導,背景為探索黑暗中隱藏的數字火焰與加密啟示。 官網 X賬號 交易手續費

    1小時前
    7
  • jeff (JEFF) 現已上線WEEX!

    尊敬的WEEX用戶: 充值:即將開放 交易:2025年12月15日12:10(UTC 8)正式開放 提現:即將開放 立即交易:JEFF/USDT jeff (JEFF) 更多信息: jeff代幣源於dweopifgdh的推文,關於一隻搞笑貓咪的meme。 X賬號 交易手續費

    2小時前
    11
  • WEEX合約將上線RAVE U本位合約- 12/15 12:00(UTC 8)

    我們很高興的宣布,WEEX合約將於2025年12月15日12:00(UTC 8)上線RAVE U本位合約。 合約以美元穩定幣為計價單位,支持多種槓桿,以滿足不同投資者的需求。您可以通過網頁、APP進行交易,歡迎您體驗! 新增加的幣對包括: RAVE/USDT 其他信息: WEEX 手續費 風險提示: 數字資產合約交易是高風險的創新產品,需要專業知識。請您理性判斷,審慎做出交易決策。 WEEX唯客團隊 註冊WEEX唯客 >>> 在Twitter上關注WEEX >>> 加入WEEX唯客社群 >>> 更多交易機會 >>> 【收錄平台】: CoinMarketCap | CryptoWisser.com | Coingecko | Coincarp – 感謝您對WEEX 的支持! – 下載WEEX App: Test Flight | Android APK | App Store / Google Play 聯絡我們: X | YouTube | Telegram | Medium | Facebook | LinkedIn | Blog 立即註冊WEEX賬戶: https://www.weex.com/register CoinMarketCap | Cryptowisser.com | Coingecko | Coincarp

    4小時前
    10
  • WEEX即將上線Mansa AI (MUSA)!

    尊敬的WEEX用戶: Mansa AI (MUSA) 更多信息: Mansa AI 是一個面向Web3 領域企業和個人用戶的綜合性AI 平台,可無縫集成先進的AI 技術,助力用戶打造創新解決方案。該平台注重可擴展性和高效性,使用戶能夠開發、部署和管理AI 驅動的應用程序。其AgentCraft 框架提供了一個低代碼環境,用於構建自主代理和認知架構,從而實現快速開發、測試和迭代。 官網 X賬號 交易手續費

    17小時前
    18
  • WEEX WE-Launch – Mansa AI(MUSA)上線及10,000 USDT空投!

    宣布啟動WE-Launch新一輪項目:Mansa AI(MUSA)。 📅 活動時間:2025-12-14 17:00 (UTC 8) — 2025-12-17 17:00 (UTC 8) 🚀 上線時間: 充值時間:2025-12-16 18:00 (UTC 8) 交易時間:2025-12-17 18:00 (UTC 8) 提現時間:2025-12-18 18:00 (UTC 8) 活動期間,通過投入WXT,您將有機會免費分享 10,000枚USDT代幣 ! 持有WXT並參與WE-Launch即可賺取USDT。 WXT 投入池 總獎勵:10,000 USDT 最低投入:300 WXT 最高投入:500,000 WXT WXT 投入期結束後,系統將計算每個參與用戶的空投獎勵。 實際投入必須滿足每個級別的最低要求,有效投入是根據相應級別的投入倍數計算的。 您的有效投入百分比越大,您在獎勵池中的份額就越大。 預計獎勵= 當前用戶的有效投入/ 所有用戶的總有效投入* 總獎勵池; 用戶的有效投入= 用戶的實際投入* 相應級別的投入倍數; *投入的WXT 可同時參與多個項目,無需鎖倉,也沒有任何質押要求。 【Mansa AI(MUSA)簡介】 Mansa AI 是一個面向Web3 企業和個人用戶的綜合型AI 平台,致力於通過無縫整合先進的人工智能技術,賦能各類創新解決方案。平台以可擴展性和高效率為核心,支持用戶開發、部署並管理AI 驅動的應用。 其核心框架AgentCraft 提供了低代碼的開發環境,用於構建自主智能體和認知架構,支持快速開發、測試與迭代,大幅降低AI 應用的落地門檻。 其它信息 官網條款與條件: 參加WE-Launch活動無需支付任何費用。 活動期間,您賬戶中的WXT無任何限制,可隨時進行交易或提現。 空投快照​​不包含任何被鎖定的WXT。 做市商和項目團隊賬戶不具備參與本次活動的資格。 嚴禁使用惡意手段,包括洗售交易、操縱交易量、創建多個賬戶以謀取利益或偽造KYC信息,以滿足活動資格要求。 WEEX保留對參與者進行資格審查的權利,有權取消參與者的活動資格、暫停發放獎勵,並追回已發放至賬戶的任何活動獎勵。 WEEX 保留本活動最終解釋權。平台有權根據市場情況調整或終止活動,且無需提前通知用戶。如有任何疑問,請聯繫我們的在線客服。

    18小時前
    18
  • WE-Launch 活動結果- Cysic (CYS)

    宣布新一輪WE-Launch 項目活動結果: Cysic (CYS)。 總獎池: 10,000 USDT 總投入: 949,231,736 WXT 有效投入量: 1,207,727,754 WXT 參與人數: 43,229 有效人數: 39,781 *為保證一貫真實透明的原則,WEEX保留所有原始認購記錄,以備後續可能的第三方審計需要。 📅 活動時間:2025年12月11日18:00 (UTC 8) – 2025年12月14日18:00 (UTC 8) 【Cysic (CYS)簡介】 Cysic XYZ 是第一個全棧計算網絡,旨在將GPU、ASIC 和原始計算資源轉化為流動的、產生收益的資產。它專注於實時ZK 證明生成和驗證,使區塊鏈生態系統的ZK 應用更快、更便宜且更具可擴展性。該項目橋接了傳統雲計算與鏈上驗證,支持ComputeFi(計算DeFi)和可驗證AI 等敘事。 其它信息 官網 X賬號

    19小時前
    16
內容目錄