### List all orders - HTTP request example Source: https://www.gatedex.com/docs/api/rest/en Example HTTP request for listing all orders. The request method is GET, the URL is /api/v1/dex_futures/orders, and the query string is contract=BTC_USD&status=finished&limit=50. This is used to demonstrate the signature string generation. ```HTTP GET /api/v1/dex_futures/orders?contract=BTC_USD&status=finished&limit=50 HTTP/1.1 ``` -------------------------------- ### Query Liquidation History with Python Source: https://www.gatedex.com/docs/api/rest/en Example using the requests library to perform an authenticated GET request to the liquidation history endpoint. ```python # coding: utf-8 import requests import time import hashlib import hmac host = "https://api.gatedex.com" prefix = "/api/v1" headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} url = '/dex_futures/usdt/liquidates' query_param = '' # for `gen_sign` implementation, refer to section `Authentication` above sign_headers = gen_sign('GET', prefix + url, query_param) headers.update(sign_headers) r = requests.request('GET', host + prefix + url, headers=headers) print(r.json()) ``` -------------------------------- ### Get Perp account request in Python Source: https://www.gatedex.com/docs/api/rest/en Example of how to construct and send a GET request to the Perp account endpoint using the requests library. Note that the gen_sign function must be implemented as per the authentication documentation. ```python # coding: utf-8 import requests import time import hashlib import hmac host = "https://api.gatedex.com" prefix = "/api/v1" headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} url = '/dex_futures/usdt/accounts' query_param = '' # for `gen_sign` implementation, refer to section `Authentication` above sign_headers = gen_sign('GET', prefix + url, query_param) headers.update(sign_headers) r = requests.request('GET', host + prefix + url, headers=headers) print(r.json()) ``` -------------------------------- ### Query account history using cURL Source: https://www.gatedex.com/docs/api/rest/en Example of how to perform the GET request using cURL, including the generation of the required signature headers. ```bash key="YOUR_API_KEY" secret="YOUR_API_SECRET" host="https://api.gatedex.com" prefix="/api/v1" method="GET" url="/dex_futures/usdt/account_book" query_param="" body_param='' timestamp=$(date +%s) body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}') sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp" sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}') full_url="$host$prefix$url" curl -X $method $full_url \ -H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign" ``` -------------------------------- ### Query account history using Python Source: https://www.gatedex.com/docs/api/rest/en Example of how to perform the GET request using the requests library in Python, requiring a custom gen_sign function for authentication. ```python # coding: utf-8 import requests import time import hashlib import hmac host = "https://api.gatedex.com" prefix = "/api/v1" headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} url = '/dex_futures/usdt/account_book' query_param = '' # for `gen_sign` implementation, refer to section `Authentication` above sign_headers = gen_sign('GET', prefix + url, query_param) headers.update(sign_headers) r = requests.request('GET', host + prefix + url, headers=headers) print(r.json()) ``` -------------------------------- ### 201 Created Response Example Source: https://www.gatedex.com/docs/api/rest/en Example of the JSON response returned upon successful order creation. ```json { "id": 15675394, "user": 100000, "contract": "BTC_USDT", "create_time": 1546569968, "size": "6024", "iceberg": "0", "left": "6024", "price": "3765", "fill_price": "0", "mkfr": "-0.00025", "tkfr": "0.00075", "tif": "gtc", "refu": 0, "is_reduce_only": false, "is_close": false, "is_liq": false, "text": "t-my-custom-id", "status": "finished", "finish_time": 1514764900, "finish_as": "cancelled", "stp_id": 0, "stp_act": "-", "amend_text": "-", "order_value": "64112.2099000000005", "trade_value": "64112.2099000000005", "market_order_slip_ratio": "0.03" } ``` -------------------------------- ### 200 OK response example Source: https://www.gatedex.com/docs/api/rest/en Example JSON response body returned when the query is successful. ```json [ { "t": 1539852480, "v": "97151", "c": "1.032", "h": "1.032", "l": "1.032", "o": "1.032", "sum": "3580" } ] ``` -------------------------------- ### Query Liquidation History with cURL Source: https://www.gatedex.com/docs/api/rest/en Example using cURL to perform an authenticated GET request, including manual signature generation using OpenSSL. ```bash key="YOUR_API_KEY" secret="YOUR_API_SECRET" host="https://api.gatedex.com" prefix="/api/v1" method="GET" url="/dex_futures/usdt/liquidates" query_param="" body_param='' timestamp=$(date +%s) body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}') sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp" sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}') full_url="$host$prefix$url" curl -X $method $full_url \ -H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign" ``` -------------------------------- ### 200 Response example Source: https://www.gatedex.com/docs/api/rest/en Example JSON response returned when the liquidation order list is retrieved successfully. ```json [ { "time": 1548654951, "contract": "BTC_USDT", "size": "600", "order_size": "-600", "order_price": "3405", "fill_price": "3424", "left": "0" } ] ``` -------------------------------- ### 200 OK Response Example Source: https://www.gatedex.com/docs/api/rest/en Example JSON response body returned upon a successful request. ```json [ { "id": 121234231, "create_time": 1514764800.123, "contract": "BTC_USDT", "order_id": "21893289839", "size": "100", "price": "100.123", "text": "t-123456", "fee": "0.01", "point_fee": "0", "role": "taker", "close_size": "0", "trade_value": "28601.83" } ] ``` -------------------------------- ### 200 Response example Source: https://www.gatedex.com/docs/api/rest/en Example successful response showing cancellation results for each order ID. ```json [ { "user_id": 111, "id": "123456", "succeeded": true, "message": "" } ] ``` -------------------------------- ### 200 Response example Source: https://www.gatedex.com/docs/api/rest/en Example JSON response returned when the history query is successful. ```json [ { "t": 1543968000, "r": "0.000157" } ] ``` -------------------------------- ### 200 Response Example Source: https://www.gatedex.com/docs/api/rest/en Example JSON response for a successful request. ```json [ { "time": 1546487347, "pnl": "0.00013", "pnl_pnl": "0.00011", "pnl_fund": "0.00001", "pnl_fee": "0.00001", "side": "long", "contract": "BTC_USDT", "text": "web", "max_size": "100", "accum_size": "100", "first_open_time": 1546487347, "long_price": "2026.87", "short_price": "2544.4" } ] ``` -------------------------------- ### 200 Response example Source: https://www.gatedex.com/docs/api/rest/en Example JSON response returned when the request is successful. ```json [ { "time": 1675841679, "contract": "ACH_USDT", "order_id": 73873128, "user": 1666, "cross_leverage_limit": "0", "leverage": "0", "entry_price": "2649.648633636364", "fill_price": "2790.8082", "position_size": "1", "trade_size": "-10" } ] ``` -------------------------------- ### 200 Response Example Source: https://www.gatedex.com/docs/api/rest/en Example of a successful JSON response containing a list of K-line data points. ```json [ { "t": 1539852480, "c": "0", "h": "0.00023", "l": "0", "o": "0" } ] ``` -------------------------------- ### 200 OK Response Example Source: https://www.gatedex.com/docs/api/rest/en Example JSON response returned by the API upon a successful request. ```json [ { "time": 1682294400.123456, "change": "0.000010152188", "balance": "4.59316525194", "text": "ETH_USD:6086261", "type": "fee", "contract": "ETH_USD", "trade_id": "1", "id": "1" } ] ``` -------------------------------- ### Example 200 response for batch_orders Source: https://www.gatedex.com/docs/api/rest/en Example successful response from the batch_orders endpoint. Shows a single order object with fields like succeeded, id, contract, status, and finish_as. ```JSON [ { "succeeded": true, "id": 15675394, "user": 100000, "contract": "BTC_USDT", "create_time": 1546569968, "size": "6024", "iceberg": "0", "left": "6024", "price": "3765", "fill_price": "0", "mkfr": "-0.00025", "tkfr": "0.00075", "tif": "gtc", "refu": 0, "is_reduce_only": false, "is_close": false, "is_liq": false, "text": "t-my-custom-id", "status": "finished", "finish_time": 1514764900, "finish_as": "cancelled", "stp_id": 0, "stp_act": "-", "amend_text": "-", "market_order_slip_ratio": "0.03" } ] ``` -------------------------------- ### 200 Response Example Source: https://www.gatedex.com/docs/api/rest/en Example JSON response structure for a successful depth query, including order book ID, timestamps, and lists of asks and bids. ```json { "id": 123456, "current": 1623898993.123, "update": 1623898993.121, "asks": [ { "p": "1.52", "s": "100" }, { "p": "1.53", "s": "40" } ], "bids": [ { "p": "1.17", "s": "150" }, { "p": "1.16", "s": "203" } ] } ``` -------------------------------- ### Get 200 Response for contract statistics Source: https://www.gatedex.com/docs/api/rest/en Example JSON response for a successful perpetual contract statistics query. ```json [ { "time": 1603865400, "lsr_taker": 100, "lsr_account": 0.5, "long_liq_size": "0", "short_liq_size": "0", "open_interest": "124724", "short_liq_usd": 0, "mark_price": "8865", "top_lsr_size": "1.02", "short_liq_amount": 0, "long_liq_amount": 0, "open_interest_usd": 1511, "top_lsr_account": 1.5, "long_liq_usd": 0 } ] ``` -------------------------------- ### Get single position information using cURL Source: https://www.gatedex.com/docs/api/rest/en Example request using cURL with OpenSSL for generating the required signature. ```bash key="YOUR_API_KEY" secret="YOUR_API_SECRET" host="https://api.gatedex.com" prefix="/api/v1" method="GET" url="/dex_futures/usdt/positions/BTC_USDT" query_param="" body_param='' timestamp=$(date +%s) body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}') sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp" sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}') full_url="$host$prefix$url" curl -X $method $full_url \ -H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign" ``` -------------------------------- ### Get 200 Response for insurance fund history Source: https://www.gatedex.com/docs/api/rest/en Example JSON response for a successful insurance fund history query. ```json [ { "t": 1543968000, "b": "83.0031" } ] ``` -------------------------------- ### Example 200 response for my_trades_timerange Source: https://www.gatedex.com/docs/api/rest/en Example JSON response showing a single trade record with fields like trade_id, create_time, contract, order_id, size, price, text, fee, point_fee, role, and close_size. ```json [ { "trade_id": "121234231", "create_time": 1514764800.123, "contract": "BTC_USDT", "order_id": "21893289839", "size": "100", "price": "100.123", "text": "t-123456", "fee": "0.01", "point_fee": "0", "role": "taker", "close_size": "0" } ] ``` -------------------------------- ### Get single position information using Python Source: https://www.gatedex.com/docs/api/rest/en Example request using the requests library. Requires a gen_sign implementation for authentication. ```python # coding: utf-8 import requests import time import hashlib import hmac host = "https://api.gatedex.com" prefix = "/api/v1" headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} url = '/dex_futures/usdt/positions/BTC_USDT' query_param = '' # for `gen_sign` implementation, refer to section `Authentication` above sign_headers = gen_sign('GET', prefix + url, query_param) headers.update(sign_headers) r = requests.request('GET', host + prefix + url, headers=headers) print(r.json()) ``` -------------------------------- ### Create an order - HTTP request example Source: https://www.gatedex.com/docs/api/rest/en Example HTTP request for creating an order. The request method is POST, the URL is /api/v1/dex_futures/orders, and the request body is a JSON string with contract, type, size, price, and time_in_force fields. This is used to demonstrate the signature string generation. ```HTTP POST /api/v1/dex_futures/orders HTTP/1.1 {"contract":"BTC_USD","type":"limit","size":100,"price":6800,"time_in_force":"gtc"} ``` -------------------------------- ### 200 OK response example Source: https://www.gatedex.com/docs/api/rest/en A sample JSON response body returned when the request is successful. ```json [ { "id": 121234231, "create_time": 1514764800, "contract": "BTC_USDT", "size": "-100", "price": "100.123" } ] ``` -------------------------------- ### Query risk limit table using cURL Source: https://www.gatedex.com/docs/api/rest/en Example of how to perform a GET request to the risk limit table endpoint using the cURL command-line tool. ```bash curl -X GET https://api.gatedex.com/api/v1/dex_futures/usdt/risk_limit_table?table_id=CYBER_USDT_20241122 \ -H 'Accept: application/json' ``` -------------------------------- ### Python request to GET /dex_futures/usdt/my_trades_timerange Source: https://www.gatedex.com/docs/api/rest/en Python example using requests to call the endpoint. Requires gen_sign implementation from the Authentication section. The URL is hardcoded to settle=usdt. ```python # coding: utf-8 import requests import time import hashlib import hmac host = "https://api.gatedex.com" prefix = "/api/v1" headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} url = '/dex_futures/usdt/my_trades_timerange' query_param = '' # for `gen_sign` implementation, refer to section `Authentication` above sign_headers = gen_sign('GET', prefix + url, query_param) headers.update(sign_headers) r = requests.request('GET', host + prefix + url, headers=headers) print(r.json()) ``` -------------------------------- ### Query Perp order list using Python Source: https://www.gatedex.com/docs/api/rest/en Example using the requests library to query the order list. Requires a gen_sign function for authentication. ```python # coding: utf-8 import requests import time import hashlib import hmac host = "https://api.gatedex.com" prefix = "/api/v1" headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} url = '/dex_futures/usdt/orders_timerange' query_param = '' # for `gen_sign` implementation, refer to section `Authentication` above sign_headers = gen_sign('GET', prefix + url, query_param) headers.update(sign_headers) r = requests.request('GET', host + prefix + url, headers=headers) print(r.json()) ``` -------------------------------- ### Query risk limit table using Python requests Source: https://www.gatedex.com/docs/api/rest/en Example of how to perform a GET request to the risk limit table endpoint using the Python requests library. ```python # coding: utf-8 import requests host = "https://api.gatedex.com" prefix = "/api/v1" headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} url = '/dex_futures/usdt/risk_limit_table' query_param = 'table_id=CYBER_USDT_20241122' r = requests.request('GET', host + prefix + url + "?" + query_param, headers=headers) print(r.json()) ``` -------------------------------- ### Get Perp market insurance fund history Source: https://www.gatedex.com/docs/api/rest/en Retrieves the insurance fund history for a specified settle currency. The example demonstrates the request using Python requests and cURL. ```python # coding: utf-8 import requests host = "https://api.gatedex.com" prefix = "/api/v1" headers = {'Accept': 'application/json', 'Content-Type': 'application/json'} url = '/dex_futures/usdt/insurance' query_param = '' r = requests.request('GET', host + prefix + url, headers=headers) print(r.json()) ``` ```bash curl -X GET https://api.gatedex.com/api/v1/dex_futures/usdt/insurance \ -H 'Accept: application/json' ``` -------------------------------- ### Query Perp Order List with cURL Source: https://www.gatedex.com/docs/api/rest/en Demonstrates how to generate the required signature and perform the request using cURL. ```bash key="YOUR_API_KEY" secret="YOUR_API_SECRET" host="https://api.gatedex.com" prefix="/api/v1" method="GET" url="/dex_futures/usdt/orders" query_param="status=open" body_param='' timestamp=$(date +%s) body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}') sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp" sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}') full_url="$host$prefix$url?$query_param" curl -X $method $full_url \ -H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign" ``` -------------------------------- ### Shell script with curl to GET /dex_futures/usdt/my_trades_timerange Source: https://www.gatedex.com/docs/api/rest/en Shell example using curl with HMAC-SHA512 signing. Requires YOUR_API_KEY and YOUR_API_SECRET. The script computes body hash and signature, then sends the request. ```shell key="YOUR_API_KEY" secret="YOUR_API_SECRET" host="https://api.gatedex.com" prefix="/api/v1" method="GET" url="/dex_futures/usdt/my_trades_timerange" query_param="" body_param='' timestamp=$(date +%s) body_hash=$(printf "$body_param" | openssl sha512 | awk '{print $NF}') sign_string="$method\n$prefix$url\n$query_param\n$body_hash\n$timestamp" sign=$(printf "$sign_string" | openssl sha512 -hmac "$secret" | awk '{print $NF}') full_url="$host$prefix$url" curl -X $method $full_url \ -H "Timestamp: $timestamp" -H "KEY: $key" -H "SIGN: $sign" ```