[
[
1725315120174, // open time
"0.098837", // o
"0.098837", // h
"0.098769", // l
"0.098769", // c
1725315151174, // close time
"20000", // v
"10000.000000", // quote v
34, // num of trades
], ...
]
GET /trades
Parameters
symbol (e.g. BTC-PERP).
startTime (optional).
endTime (optional: defaults to current).
limit (optional: defaults to 1000; maximum 1000 entries from endTime).
To authenticate, the client must have access to or create the following variables:
primaryAddr, the public key of your primary account which holds balances.
signingAddr, a signing key generated by the client that acts as a delegate to sign transactions on behalf of the primary account.
apiKey, an API key returned as the response to the POST /register endpoint.
To connect to private endpoints, the client then:
Sends apiKey in the header of the request as X-API-KEY.
Attaches a signature by a valid signing key (or primary key).
For each POST request, create a signature based on order parameters as specified below. It is generally recommended to use time as nonce, unless you want to create identical orders (orders whose fields are the same except for nonce).
The registration process will look like this:
Generate a random key/pair for signing; this will be your signingAddr.
{
"order": {
"time": 1683849600076, // in milliseconds
"nonce": 0,
"symbol": "SOL-PERP",
"isBuy": true,
"size": "3.1200",
"orderType": "MARKET",
"limitPrice": "30.03",
"reduceOnly": false,
"timeInForce": "GTC", // (optional str: only accepted when orderType == LIMIT, must be GTC or FOK),
"tpPrice": "31.03", // (optional str: can only be specified for LIMIT order),
"tpSignature": "0x0", // (optional str: should be produced by setting orderType = "TAKE_PROFIT", isBuy = opposite of parent LIMIT order, limitPrice = tpPrice and reduceOnly = True),
"slPrice": "29.03", // (optional str: can only be specified for LIMIT order),
"slSignature": "0x0", // (optional str: should be produced by setting orderType = "STOP_LOSS", isBuy = opposite of parent LIMIT order, limitPrice = slPrice and reduceOnly = True),
},
"recvWindow": 60000, // (optional int: defaults to 5000; server will discard if server ts > time + recvWindow)
"signature": "0x0", // NOTE: make sure this starts with 0x
}
Example Response
{
"id": "0x0"
}
Example Error Response
{
"code": 429,
"msg": "Rate limited"
}
POST /orders/cancel
Example Signature
from eth_abi import encode
from eth_account import Account
from eth_account.messages import encode_defunct
from web3 import Web3
args = Web3.keccak(
encode(
["uint256", "uint256", "string"],
[time, nonce, id]
)
)
signable_msg = encode_defunct(args)
signature = EthAccount.sign_message(
signable_msg, SIGNING_PRIVATE_KEY
).signature.hex()
Request Body Example
{
"order": {
"time": 1683849600076,
"nonce": 0,
"id": "0x",
},
"recvWindow": 60000, // (optional int: defaults to 5000; server will discard if server ts > time + recvWindow)
"signature": "0x0",
}
Example Response
{
"id": "0x0"
}
GET /orders
Parameters
id (optional: returns all orders by default).
nonce (optional: returns all orders by default).
symbol (optional: returns all symbols by default).
orderType (optional: returns all orders by default).
status (optional: returns all statuses by default).
startTime (optional).
endTime (optional: defaults to current).
limit (optional: defaults to 1000; maximum 1000 entires from endTime).
time (e.g. 1713593340000).
Example Response
[{
"id": "0x0",
"nonce": 0,
"symbol": "BTC-PERP",
"isBuy": true,
"orderType": "LIMIT",
"limitPrice": "30000",
"markPrice": "30000",
"size": "0.1000",
"status": "FILLED",
"reduceOnly": false,
"initMarginRatio": "0.1250",
"code": null, // error code, specified only if status is REJECTED
"lastFilledSize": "0.1000", // null if status != FILLED
"lastFilledPrice": "30000.00", // null if status != FILLED
"lastFilledTime": 1683849600076, // null if status != FILLED
"avgFilledPrice": "30000.00", // null if status != FILLED
"settledFunding": "0.100000", // null if status != FILLED, positive means trader received
"fees": "0.010000", // includes premium (and liquidation penalty if applicable)
"realizedPnl": "0.200000", // null if status != FILLED, includes funding and fees
"postTime": 1683849600076,
"tpPrice": null,
"slPrice": null,
}]
POST /lp
Example Signature
from eth_abi import encode
from eth_account import Account
from eth_account.messages import encode_defunct
from web3 import Web3
args = Web3.keccak(
encode(
["uint256", "uint256", "string", "string"],
[time, nonce, orderType, size]
)
)
signable_msg = encode_defunct(args)
signature = EthAccount.sign_message(
signable_msg, SIGNING_PRIVATE_KEY
).signature.hex()
{
"order": {
"time": 1683849600076,
"nonce": 0,
"recipient": "0x0",
"token": "USDC",
"size": 100000000, // uint256: should be multiplied by 1e6 for USDC
"chainId": 324,
},
"recvWindow": 60000, // (optional int: defaults to 5000; server will discard if server ts > time + recvWindow)
"signature": "0x0"
}
Example Response
{
"id": "0x0"
}
GET /transfer
Parameters
id (optional: returns all orders by default).
nonce (optional: returns all orders by default).
orderType (optional: returns all orders by default).
startTime (optional).
endTime (optional: defaults to current).
limit (optional: defaults to 1000; maximum 1000 entires from endTime).
time (e.g. 1713593340000).
Example Response
[{
"id": "0x0",
"nonce": 0,
"size": "100",
"orderType": "DEPOSIT",
"status": "FILLED",
"code": null, // error code, specified only if status is REJECTED
"chainId": 1,
"postTime": 1683849600076
}]
Public WS Endpoints
The base endpoints are available at:
When sending requests, this query parameter is required:
xwebsocketserver=restserver{account_group}
Ping/Pong
To check the connection, the client must send {"method": "PING", "params": [], "id": 0} where id can be any integer. The server will respond with {"data": "PONG"}.
Subscription
For each subscription, the client must attach an integer-valued id which will be unique per request. e.g. {"method": "SUBSCRIBE", "params": [channel1, channel2, ...], "id": subscription_id}.
The server will respond with {"result": null, "id": subscription_id}after successful subscription/un-subscription.
{
"channel": "DOGE-PERP@kline_1m",
"data": [
1725315120174, // open time
"0.098837", // o
"0.098837", // h
"0.098769", // l
"0.098769", // c
1725315151174, // close time
"20000", // v
"10000", // quote v
"34", // num of trades
]
}
To establish a connection to private endpoints, the client must obtain listenKey. For all methods, include the X-API-Key in the header obtained via /register.
POST /account/listenKey
Returns a listen key that is valid for 60 minutes. If a client has an active listenKey, it will return the existing listenKey and extend its validity by 60 minutes.
Extends the expiry of the current listen key by 60 minutes. If the existing key has already expired or there is no listen key, it will return an error response.
{
"code": 1125,
"msg": "Listen key expired. Make a POST request to create a new key."
}
DELETE /account/listenKey
Closes the current listen key.
Parameters
None
Example Response
{}
Subscription
Uses the same base url as the public endpoint but the client must pass in an additional query parameter, listenKey when sending a request for subscription.