Table of Contents * Fairdesk Public API * General Public API Information
- REST API Standards
- Fairdesk provides HTTP Rest API for client to operate Orders, all endpoints return a JSON object.
- Fairdesk provides WebSocket API for client to receive market data, order and position updates.
- The default Rest API base endpoint is: https://api.fairdesk.com.
- The WebSocket API url is: wss://www.fairdesk.com/.
- The Testnet endpoints are https://api-testnet.fairdesk.com and wss://testnet.fairdesk.com
- HTTP
401return code when unauthenticated - HTTP
403return code when lack of privilege. - HTTP
429return code when breaking a request rate limit. - HTTP
5XXreturn codes for Fairdesk internal errors. Note: This doesn't mean the operation failed, the execution status is UNKNOWN and could be Succeeded.
- All restful API except starting with
/mdshares same response format.
{
"status": <code>,
"error": <msg>,
"data": <data>
}
| Field | Description |
|---|---|
| code | 0 means success, non-zero means error |
| error | when code is non-zero, it provides short error description |
| data | operation dependent |
Every PRIVATE HTTP Request must have the following Headers:
- x-fairdesk-access-key: This is API-KEY (id field) from Fairdesk site.
- x-fairdesk-request-expiry : This describes the Unix EPoch milliseconds to expire the request, normally it should be (Now() + 1 minute)
- x-fairdesk-request-signature : This is HMAC SHA256 signature of the http request. Secret is API Secret, its formula is : HMacSha256( URL Path + QueryString + Expiry + body )
- private API requests are subject to 200 limit quota per minute
- Every private API call consumes 1 quota
- Each private API call must be signed and pass to server in HTTP header
x-fairdesk-request-signature. - Endpoints use
HMAC SHA256signatures. TheHMAC SHA256 signatureis a keyedHMAC SHA256operation. Use yourapiSecretas the key and the string(URL Path + QueryString + Expiry + body)as the value for the HMAC operation. apiSecret=Base64::urlDecode(API Secret)- The
signatureis case sensitive.
- API REST Request URL: https://api.fairdesk.com/api/v1/private/account/symbol-config
- Request Path: /api/v1/private/account/symbol-config
- Request Query:
- Request Body:
- Request Expiry: 1649999999999
- Signature: HMacSha256(/api/v1/private/account/symbol-config + 1649999999999)
- API REST Request URL: https://api.fairdesk.com/api/v1/private/account/config/adjust-leverage
- Request Path: /api/v1/private/account/config/adjust-leverage
- Request Query:
- Request Body: { "symbol": "btcusdt", "isolated": true, "leverage": "120"}
- Request Expire: 1649999999999
- Signature: HMacSha256(/api/v1/private/account/config/adjust-leverage + 1649999999999 + { "symbol": "btcusdt", " isolated": true, "leverage": "120"})
- Request
POST /api/v1/private/token/create
- Example Response
{
"status": 0,
"error": "OK",
"data": {
"apiKey": "YourAPIKeyName",
"wsToken": "yourAPIWsToken",
"expiry": 1649673693595
}
}this method is idempotent, call this method multiple times will generate the same websocket token
- Request
POST /api/v1/private/token/refresh
If no upstanding ws token is valid, an error of "error-code.api.ws-token.not-created" is thrown.
- Example Response
{
"status": 0,
"error": "OK",
"data": {
"apiKey": "YourAPIKeyName",
"wsToken": "yourAPIWsToken",
"expiry": 1649673693595
}
}- Request
DELETE /api/v1/private/token/delete
- Success Response
{
"status": 0,
"error": "OK",
"data": true
}- The following data can be sent through the websocket instance in order to subscribe/unsubscribe from streams. Examples can be seen below.
- The
idused in the JSON payloads is an unsigned INT used as an identifier to uniquely identify the messages going back and forth. - In the response, if the
resultreceived isnullthis means the request sent was a success for non-query requests ( e.g. Subscribing/Unsubscribing).
- Request
{ "method": "SUBSCRIBE", "params": [ "btcusdt@depth10" ], "id": 1 }
- Response
{ "result": null, "id": 1 }
- Request
{ "method": "UNSUBSCRIBE", "params": [ "btcusdt@depth10" ], "id": 15 }
- Response
{ "result": null, "id": 15 }
- Request
{ "method": "LIST_SUBSCRIPTIONS", "id": 4 }
- Response
{ "result": [ "btcusdt@depth10" ], "id": 4 }