API Validation
Request Header
The Content-Type must be set to application/json in all request headers.
Generate Api Key
To begin, generate and Open API token management section in your personal center.
Next, you will receive an API key and a secret key, both of which you must remember.
The API key and secret key will be generated randomly.
Generate Sign
Required Headers
| header | description |
|---|---|
| X-CH-APIKEY | the key is in the user api management |
| X-CH-TS | it is the current timestamp |
| X-CH-SIGN | the string is generated according to signature rule |
Http Method: GET
Concatenate the current timestamp, HTTP method, API path, and query parameters.
1736303665297GET/path?key1=value1&key2=value2Sign the content with HMAC-SHA256.
CryptoJS.HmacSHA256('1736303665297GET/path?key1=value1&key2=value2', secretKey)After signature generated, attach it in the request header.
Example
api key = APIKEY
secret key = SECRETKEY
timestamp = 1736839890257
http method = GET
request path = /fapi/v1/position/positions?futuresName=E-BTC-USDTGenerate the content to be signed.
1736839957714GET/fapi/v1/position/positions?futuresName=E-BTC-USDTSign the content with HMAC-SHA256.
65f0f94af4997e240baa569c312b36dcffc72f59f22fb546cbd5296cc12223bbAfter signature generated, attach it in the request header.
Http Method: POST
Concatenate the current timestamp, HTTP method, API path, and request body.
1736840154334POST/fapi/v1/cancel{"key1":"value1","key2":"value2"}Sign the content with HMAC-SHA256.
CryptoJS.HmacSHA256('1736840154334POST/fapi/v1/cancel{"key1":"value1","key2":"value2"}', secretKey)After signature generated, attach it in the request header.
Example
api key = APIKEY
secret key = SECRETKEY
timestamp = 1736840154334
http method = POST
request path = /fapi/v1/cancel
request body = {"futuresName":"E-ETH-USDT","orderId":4564516456}Generate the content to be signed.
1736840154334POST/fapi/v1/cancel{"futuresName":"E-ETH-USDT","orderId":4564516456}Sign the content with HMAC-SHA256.
4c89486597292040d2aa16176fa85414b55d61a01e2e00355b2aae2c86e32405After signature generated, attach it in the request header.
javascript example
const timestamp = new Date().getTime();
const method = 'POST';
const timeKey = "time";
const apiKeyKey = "api_key";
const apiKey = "APIKEY";
const secretKey = "SECRETKEY";
const path = "/path";
let hash = `${timestamp}${method}${path}`;
const queryString = "key1=value1&key2=value2";
if(queryString!=null && queryString.length>0) {
hash+=`?${queryString}`;
}
const body = '{"key1":"value1","key2":"value2"}';
if(body!=null) {
hash+=(typeof body === 'object')?JSON.stringify(body):body;
}
//need to includ the library of CryptoJS
let hashBytesArr=CryptoJS.HmacSHA256(hash, secretKey);
let sign=CryptoJS.enc.Hex.stringify(hashBytesArr);
//TODO add sign, timestamp, apiKey to header