Skip to main content

General Info

Base endpoint

The base endpoint is:

  • https://api.mexc.com

HTTP Return Codes

  • HTTP 4XX return codes are used for malformed requests; the issue is on the sender's side.
  • HTTP 403 return code is used when the WAF Limit (Web Application Firewall) has been violated.
  • HTTP 429 return code is used when breaking a request rate limit.
  • HTTP 5XX return codes are used for internal errors; the issue is on MEXC's side. It is important to NOT treat this as a failure operation; the execution status is UNKNOWN and could have been a success.

General Information on Endpoints

The API accepts requests of type GET, POST or DELETE

  • For GET endpoints, parameters must be sent as a query string.
  • For POST, PUT, and DELETE endpoints, the parameters may be sent as a query string with content type application/x-www-form-urlencoded,or in the request body with content type application/json. You may mix parameters between both the query string and request body if you wish to do so.
  • Parameters may be sent in any order.
  • If a parameter sent in both the query string and request body, the query string parameter will be used.

Relevant parameters in the header

keyDescription
X-MEXC-APIKEYAccess key
Content-Typeapplication/json

SIGNED

  • SIGNED endpoints require an additional parameter, signature, to be sent in the query string or request body(in the API of batch operation, if there are special symbols such as comma in the parameter value, these symbols need to be URL encoded when signing,and encode only support uppercase).
  • Endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation.
  • The signature is support lowercase only.
  • totalParams is defined as the query string concatenated with the request body.

Timing security

The logic is as follows:

 if (timestamp < (serverTime + 1000) && (serverTime - timestamp) <= recvWindow)
{
// process request
}
else
{
// reject request
}
  • A SIGNED endpoint also requires a parameter, timestamp, to be sent which should be the millisecond timestamp of when the request was created and sent.
  • An additional parameter, recvWindow, may be sent to specify the number of milliseconds after timestamp the request is valid for. If recvWindow is not sent, it defaults to 5000.

Serious trading is about timing. Networks can be unstable and unreliable, which can lead to requests taking varying amounts of time to reach the servers. With recvWindow, you can specify that the request must be processed within a certain number of milliseconds or be rejected by the server.

SIGNED Endpoint Examples for POST /api/v3/order

Example 1

HMAC SHA256 signature:

$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087" | openssl dgst -sha256 -hmac "45d0b3c26f2644f19bfb98b07741b2f5"
(stdin)= 323c96ab85a745712e95e63cad28903dd8292e4a905e99c4ee3932023843a117
curl command:

(HMAC SHA256)
$ curl -H "X-MEXC-APIKEY: mx0aBYs33eIilxBWC5" -X POST 'https://api.mexc.com/api/v3/order' -d 'symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087&signature=323c96ab85a745712e95e63cad28903dd8292e4a905e99c4ee3932023843a117'

Example 2

HMAC SHA256 signature:

$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087" | openssl dgst -sha256 -hmac "45d0b3c26f2644f19bfb98b07741b2f5"
(stdin)= fd3e4e8543c5188531eb7279d68ae7d26a573d0fc5ab0d18eb692451654d837a
curl command:

(HMAC SHA256)
$ curl -H "X-MEXC-APIKEY: mx0aBYs33eIilxBWC5" -X POST 'https://api.mexc.com/api/v3/order' -d 'symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087&signature=fd3e4e8543c5188531eb7279d68ae7d26a573d0fc5ab0d18eb692451654d837a'

Example 3

HMAC SHA256 signature:

$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMITquantity=1&price=11&recvWindow=5000&timestamp=1644489390087" | openssl dgst -sha256 -hmac "45d0b3c26f2644f19bfb98b07741b2f5"
(stdin)= d1a676610ceb39174c8039b3f548357994b2a34139a8addd33baadba65684592
curl command:

(HMAC SHA256)
$ curl -H "X-MEXC-APIKEY: mx0aBYs33eIilxBWC5" -X POST 'https://api.mexc.com/api/v3/order?symbol=BTCUSDT&side=BUY&type=LIMIT' -d 'quantity=1&price=11&recvWindow=5000&timestamp=1644489390087&signature=d1a676610ceb39174c8039b3f548357994b2a34139a8addd33baadba65684592'

Here is a step-by-step example of how to send a vaild signed payload from the Linux command line using echo, openssl, and curl.

KeyValue
apiKeymx0aBYs33eIilxBWC5
secretKey45d0b3c26f2644f19bfb98b07741b2f5
ParameterValue
symbolBTCUSDT
sideBUY
typeLIMIT
quantity1
price11
recvWindow5000
timestamp1644489390087

Example 1: As a request body

  • requestBody: symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087

Example 2: As a query string

  • queryString: symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087

Example 3: Mixed query string and request body

  • queryString: symbol=BTCUSDT&side=BUY&type=LIMIT

  • requestBody: quantity=1&price=11&recvWindow=5000&timestamp=1644489390087

Note that the signature is different in example 3. There is no & between "LIMIT" and "quantity=1".

Timing security

-A SIGNED endpoint also requires a parameter, timestamp, to be sent which should be the millisecond timestamp of when the request was created and sent. -An additional parameter, recvWindow, may be sent to specify the number of milliseconds after timestamp the request is valid for. If recvWindow is not sent, it defaults to 5000.

Serious trading is about timing. Networks can be unstable and unreliable, which can lead to requests taking varying amounts of time to reach the servers. With recvWindow, you can specify that the request must be processed within a certain number of milliseconds or be rejected by the server.

info

It is recommended to use a small recvWindow of 5000 or less! The max cannot go beyond 60,000!

The logic is as follows:
if (timestamp < serverTime + 1000 && serverTime - timestamp <= recvWindow) {
// process request
} else {
// reject request
}

SIGNED Endpoint Examples for POST /api/v3/order

Here is a step-by-step example of how to send a vaild signed payload from the Linux command line using echo, openssl, and curl.

keyvalue
apiKeymx0aBYs33eIilxBWC5
secretKey45d0b3c26f2644f19bfb98b07741b2f5
Parametervalue
symbolBTCUSDT
sideBUY
typeLIMIT
quantity1
price11
recvWindow5000
timestamp1644489390087

Example 1: As a request body

  • requestBody: symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087
HMAC SHA256 signature:

$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087" | openssl dgst -sha256 -hmac "45d0b3c26f2644f19bfb98b07741b2f5"
(stdin)= 323c96ab85a745712e95e63cad28903dd8292e4a905e99c4ee3932023843a117

curl command:

(HMAC SHA256)
$ curl -H "X-MEXC-APIKEY: mx0aBYs33eIilxBWC5" -X POST 'https://api.mexc.com/api/v3/order' -d 'symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087&signature=323c96ab85a745712e95e63cad28903dd8292e4a905e99c4ee3932023843a117'

Example 2: As a query string

  • queryString: symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087
HMAC SHA256 signature:

$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087" | openssl dgst -sha256 -hmac "45d0b3c26f2644f19bfb98b07741b2f5"
(stdin)= fd3e4e8543c5188531eb7279d68ae7d26a573d0fc5ab0d18eb692451654d837a

curl command:

(HMAC SHA256)
$ curl -H "X-MEXC-APIKEY: mx0aBYs33eIilxBWC5" -X POST 'https://api.mexc.com/api/v3/order' -d 'symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=11&recvWindow=5000&timestamp=1644489390087&signature=fd3e4e8543c5188531eb7279d68ae7d26a573d0fc5ab0d18eb692451654d837a'

Example 3: Mixed query string and request body

  • queryString: symbol=BTCUSDT&side=BUY&type=LIMIT

  • requestBody: quantity=1&price=11&recvWindow=5000&timestamp=1644489390087

HMAC SHA256 signature:

$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMITquantity=1&price=11&recvWindow=5000&timestamp=1644489390087" | openssl dgst -sha256 -hmac "45d0b3c26f2644f19bfb98b07741b2f5"
(stdin)= d1a676610ceb39174c8039b3f548357994b2a34139a8addd33baadba65684592

curl command:

(HMAC SHA256)
$ curl -H "X-MEXC-APIKEY: mx0aBYs33eIilxBWC5" -X POST 'https://api.mexc.com/api/v3/order?symbol=BTCUSDT&side=BUY&type=LIMIT' -d 'quantity=1&price=11&recvWindow=5000&timestamp=1644489390087&signature=d1a676610ceb39174c8039b3f548357994b2a34139a8addd33baadba65684592'

LIMITS

There is rate limit for API access frequency, upon exceed client will get code 429: Too many requests. The account is used as the basic unit of speed limit for the endpoints that need to carry access keys. For endpoints that do not need to carry access keys, IP addresses are used as the basic unit of rate limiting.

Limits Description

  • According to the two modes of IP and UID (account) limit, each are independent.
  • Endpoints are marked according to IP or UID limit and their corresponding weight value.
  • Each endpoint with IP limits has an independent 500 every 10 second limit.
  • Each endpoint with UID limits has an independent 500 every 10 second limit.

Limits Error

  • When a 429 is received, it's your obligation as an API to back off and not spam the API.
  • Repeatedly violating rate limits and/or failing to back off after receiving 429s will result in an automated IP ban .
  • IP bans are tracked and scale in duration for repeat offenders, from 2 minutes to 3 days.
  • A Retry-After header is sent with a 418 or 429 responses and will give the number of seconds required to wait, in the case of a 429, to prevent a ban, or, in the case of a 418, until the ban is over.

Websocket Limits

  • The Websocket limits is: 100times/s.
  • A connection that goes beyond the limit will be disconnected; IPs that are repeatedly disconnected may be banned.
  • A single connection can listen to a maximum of 30 streams.

Error Code

The following error information can be returend

CodeDescription
-2011Unknown order sent
26operation not allowed
400api key required
401No authority
403Access Denied
429Too Many Requests
500Internal error
503service not available, please try again
504Gateway Time-out
602Signature verification failed
10001user does not exist
10007bad symbol
10015user id cannot be null
10072invalid access key
10073invalid Request-Time
10095amount cannot be null
10096amount decimal places is too long
10097amount is error
10098risk control system detected abnormal
10099user sub account does not open
10100this currency transfer is not supported
10101Insufficient balance
10102amount cannot be zero or negative
10103this account transfer is not supported
10200transfer operation processing
10201transfer in failed
10202transfer out failed
10206transfer is disabled
10211transfer is forbidden
10212This withdrawal address is not on the commonly used address list or has been invalidated
10216no address available. Please try again later
10219asset flow writing failed please try again
10222currency cannot be null
10232currency does not exist
10259Intermediate account does not configured in redisredis
10265Due to risk control, withdrawal is unavailable, please try again later
10268remark length is too long
20001subsystem is not supported
20002Internal system error please contact support
22222record does not exist
30000suspended transaction for the symbol
30001The current transaction direction is not allowed to place an order
30002The minimum transaction volume cannot be less than :
30003The maximum transaction volume cannot be greater than :
30004Insufficient position
30005Oversold
30010no valid trade price
30014invalid symbol
30016trading disabled
30018market order is disabled
30019api market order is disabled
30020no permission for the symbol
30021invalid symbol
30025no exist opponent order
30026invalid order ids
30027The currency has reached the maximum position limit, the buying is suspended
30028The currency triggered the platform risk control, the selling is suspended
30029Cannot exceed the maximum order limit
30032Cannot exceed the maximum position
30041current order type can not place order
33333param is error
44444param cannot be null
60005your account is abnormal
70011Pair user ban trade apikey
700001API-key format invalid
700002Signature for this request is not valid
700003Timestamp for this request is outside of the recvWindow
700004Param 'origClientOrderId' or 'orderId' must be sent, but both were empty/null
700005recvWindow must less than 60000
700006IP non white list
700007No permission to access the endpoint
700008Illegal characters found in parameter
730001Pair not found
730002Your input param is invalid
730000Request failed, please contact the customer service
730001User information error
730002Parameter error
730003Unsupported operation, please contact the customer service
730100Unusual user status
730600Sub-account Name cannot be null
730601Sub-account Name must be a combination of 8-32 letters and numbers
730602Sub-account remarks cannot be null
730700API KEY remarks cannot be null
730701API KEY permission cannot be null
730702API KEY permission does not exist
730703The IP information is incorrect, and a maximum of 10 IPs are allowed to be bound only
730704The bound IP format is incorrect, please refill
730705At most 30 groups of Api Keys are allowed to be created only
730706API KEY information does not exist
730707accessKey cannot be null
730101The user Name already exists
140001sub account does not exist
140002sub account is forbidden