Error Responses

The QuBit API uses a unified response structure to return the results of all requests, for both success and failure cases.

Unified Response Structure

All REST API responses adhere to the following JSON format:

{
  "code": "0",        // Business status code
  "msg": "success",   // Response message
  "data": [ ... ]     // Business data
}
  • code (String): The business status code.

    • "0" indicates that the request was processed successfully.

    • Any non-zero value indicates an error.

  • msg (String): The response message.

    • On success, this is typically an empty string "" or "success".

    • On failure, it provides a human-readable description of the error.

  • data (Array or Object): The business data.

    • On success, it contains the requested data.

    • On failure, it is usually an empty array [] or object {}.

You should always check the code field first to determine if your request was successful.


HTTP Status Codes

Our API uses standard HTTP status codes to indicate the overall status of a request:

Code
Meaning
Explanation

200

OK

The request was received and processed successfully, regardless of business success or failure. Check the code field in the response body.

400

Bad Request

The request parameters are malformed, failed validation, or are missing.

401

Unauthorized

Authentication failed, e.g., invalid API Key, incorrect timestamp, or invalid signature.

403

Forbidden

Authentication was successful, but your API Key does not have permission for this action.

429

Too Many Requests

You have exceeded the rate limits. Check the X-RateLimit headers for more info.

500

Internal Server Error

An unexpected error occurred on the server.


Common Business Error Codes

Below is a list of common business error codes (the value of the code field) that can help you handle errors programmatically.

General Errors (50000 - 50999)

Code
Message
Explanation

50001

Permission denied

The API Key lacks the required permission.

50002

Invalid parameters

The request parameters are invalid.

50003

Service unavailable

The system is under maintenance or temporarily unavailable.

Order-Related Errors (51000 - 51999)

Code
Message
Explanation

51001

Invalid instrument ID

The provided instId is invalid.

51004

Order does not exist

The specified order was not found.

51005

Order has already been filled

The order is already fully filled and cannot be modified.

51008

Insufficient balance

Not enough funds in the account.

51011

Price must be a multiple of tick size

The price does not meet the tickSize precision requirement.

51021

Leverage exceeds the maximum limit

The specified leverage is higher than the maximum allowed for the instrument.

51109

clOrdId format is invalid

The format of the clOrdId is incorrect.

51111

sz is required when closeType is 1

The sz field is mandatory for partial close orders.

This is not an exhaustive list. A complete list of error codes will be provided in the future.


Responses for Batch Operations

For batch operation endpoints, such as POST /api/v1/trade/cancel-batch-orders, the data field will be an array where each object contains its own sCode (status code for the individual operation) and sMsg (message) to indicate the result of that specific item.

{
  "code": "0", // Top-level code is 0, indicating the batch request was processed
  "msg": "",
  "data": [
    {
      "ordId": "123...",
      "sCode": "0", // This order was canceled successfully
      "sMsg": ""
    },
    {
      "clOrdId": "456...",
      "sCode": "51005", // This order failed to be canceled
      "sMsg": "Order has already been filled."
    }
  ]
}

Last updated