Request signing
Authentication headers
| Name | Type | Description |
|---|---|---|
ACCESS-KEY |
string | Your API key |
ACCESS-SIGN |
string | Hexadecimal signature string. See the signing rules and code examples below. |
ACCESS-TIMESTAMP |
decimal | Request timestamp in UTC, expressed as Unix seconds with a fractional part or in ISO8601 format, with millisecond precision. Examples: 1795161600.000 or 2026-11-20T08:00:00.000Z. |
Parameter encoding
- GET: send parameters in the URL query string and leave the request body empty.
- POST: send the JSON object or array defined by the endpoint in the request body, with
Content-Type: application/json. - Query values are URL-encoded text. JSON values follow the types in each endpoint's request table.
Build the signing input
Value generation rules for ACCESS-SIGN
-
Concatenate timestamp + method + requestPath + querySuffix + body (+ denotes string concatenation). querySuffix is "?" followed by the exact URL-encoded query string when present; otherwise it is empty. Use the secret to compute HMAC SHA256, then convert the resulting byte array to a hexadecimal string. The timestamp must match the ACCESS-TIMESTAMP header and use UTC Unix seconds with a fractional part or ISO8601 format, with millisecond precision.
-
Method is the HTTP method in uppercase: GET/POST.
-
RequestPath is the endpoint path without the query string, for example: /api/v1/usdt/account;
-
Body is the request body as a string. GET requests have no body, so it can be omitted. POST requests use a JSON string, such as {"instrument_id":"ETH","direction":"openLong","leverage":"5","order_type":"limit","order_price":"2420","quantity":"12","margin_mode":"fixed","take_profit_price":"2580","stop_lose_price":"2320"}
-
The secret is generated when you apply for API access.
Signing implementations
Example code for signature
/**
* Generate signature
* @param timeStamp timestamp
* @param method Request method: POST or GET
* @param requestUrl url
* @param requestBody request content, no null
* @param secret key
*/
public static String sign(String timestamp, String method, String requestPath, String queryString, String body, String secretKey) throws Exception {
if (StringUtils.isEmpty(secretKey) || StringUtils.isEmpty(method)) {
return APIConstants.EMPTY;
}
String preHash = preHash(timestamp, method, requestPath, queryString, body);
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
byte[] secretKeyBytes = secretKey.getBytes(CharsetEnum.UTF_8.charset());
SecretKeySpec secret_key = new SecretKeySpec(secretKeyBytes, "HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] bytes = sha256_HMAC.doFinal(preHash.getBytes(CharsetEnum.UTF_8.charset()));
return byteArrayToHexString(bytes);
}
/**
* the prehash string = timestamp + method + requestPath + querySuffix + body <br/>
*
* @param timestamp the number of seconds since Unix Epoch in UTC. Decimal values are allowed.
* eg: 1795161600.000 or 2026-11-20T08:00:00.000Z
* @param method eg: POST
* @param requestPath eg: /api/v1/spot/account/one
* @param queryString eg: asset=USDT
* @param body json string, eg: {"instrument_id":"ETH/USDT","price":"2420.00","quantity":"0.50","direction":"1"}
*/
public static String preHash(String timestamp, String method, String requestPath, String queryString, String body) {
StringBuilder preHash = new StringBuilder();
preHash.append(timestamp);
preHash.append(method.toUpperCase());
preHash.append(requestPath);
if (StringUtils.isNotEmpty(queryString)) {
preHash.append("?").append(queryString);
}
if (StringUtils.isNotEmpty(body)) {
preHash.append(body);
}
return preHash.toString();
}
private static String byteArrayToHexString(byte[] b) {
StringBuilder hex = new StringBuilder();
if (b == null) return hex.toString();
for (byte value : b) {
int unsigned = value & 0xff;
hex.append(Character.forDigit(unsigned >>> 4, 16));
hex.append(Character.forDigit(unsigned & 0x0f, 16));
}
return hex.toString();
}
import hmac
def sign(message, secret_key):
return hmac.new(
secret_key.encode("utf-8"),
message.encode("utf-8"),
digestmod="sha256",
).hexdigest()
def pre_hash(timestamp, method, request_path, body="", query_string=""):
query_suffix = "?" + query_string if query_string else ""
return "".join((str(timestamp), method.upper(), request_path, query_suffix, body))