Welcome to the new WEEX API documentation. Looking for the previous version?Switch to the legacy docs
WEEX
Quick Start

Request Processing

Java

JavaCode
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 Info private static final String API_KEY = ""; // Replace with your actual API Key private static final String SECRET_KEY = ""; // Replace with your actual Secret Key private static final String ACCESS_PASSPHRASE = ""; // Replace with your actual Access Passphrase private static final String BASE_URL = "https://api-spot.weex.com"; // Replace with your actual API address // Generate signature (POST request) 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); } // Generate signature (GET request) 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); } // Generate HMAC SHA256 signature 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); } // Send POST request 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"); 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); } } // Send GET request 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"); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { CloseableHttpResponse response = httpClient.execute(getRequest); return EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); } } // Example usage public static void main(String[] args) { try { // GET request example String requestPath = "/api/v3/openOrders"; String queryString = "?symbol=BTCUSDT"; String response = sendRequestGet(API_KEY, SECRET_KEY, ACCESS_PASSPHRASE, "GET", requestPath, queryString); System.out.println("GET Response: " + response); // POST request example String postPath = "/api/v3/order"; String body = "{\"symbol\":\"BTCUSDT\",\"side\":\"BUY\",\"type\":\"LIMIT\",\"timeInForce\":\"GTC\",\"quantity\":\"0.01\",\"price\":\"68900\"}"; response = sendRequestPost(API_KEY, SECRET_KEY, ACCESS_PASSPHRASE, "POST", postPath, "", body); System.out.println("POST Response: " + response); } catch (Exception e) { e.printStackTrace(); } } }

Python

Code
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" } url = "https://api-spot.weex.com" # Please replace with the actual API address 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" } url = "https://api-spot.weex.com" # Please replace with the actual API address if method == "GET": response = requests.get(url + request_path+query_string, headers=headers) return response def get(): # Example of calling a GET request request_path = "/api/v3/openOrders" query_string = '?symbol=BTCUSDT' response = send_request_get(api_key, secret_key, access_passphrase, "GET", request_path, query_string) print(response.status_code) print(response.text) def post(): # Example of calling a POST request request_path = "/api/v3/order" body = { "symbol": "BTCUSDT", "side": "BUY", "type": "LIMIT", "timeInForce": "GTC", "quantity": "0.01", "price": "68900" } 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) if __name__ == '__main__': get() post()

All requests are based on the HTTPS protocol. The Content-Type in the request headers must be set to 'application/json'.

Request Processing

  • Request parameters: Parameter encapsulation according to endpoint request parameter specification.
  • Submit request: Submit the encapsulated parameters to the server via GET/POST.
  • Server response: The server first performs security checks on the request data, and after passing the check, returns the response data to the user in the JSON format based on the operation logic.
  • Data processing: Process the server response data.

Success

HTTP 200 status codes indicates success and may contain content.Response content (if any) will be included in the returned data.

Common error codes

  • 400 Bad Request – Invalid request format
  • 401 Unauthorized – Invalid API Key
  • 403 Forbidden – You do not have access to the requested resource
  • 404 Not Found — No requests found
  • 429 Too Many Requests – Rate limit exceeded
  • 500 Internal Server Error – We had a problem with our server
  • Failed responses include error descriptions in the body.