General REST API Information
- The following base endpoints are available. Please use whichever works best for your setup:
- The last 4 endpoints in the point above (
api1-api4) should give better performance but have less stability. - Responses are in JSON by default. To receive responses in SBE, refer to the SBE FAQ page.
- Data is returned in chronological order, unless noted otherwise.
- Without
startTimeorendTime, returns the most recent items up to the limit. - With
startTime, returns oldest items fromstartTimeup to the limit. - With
endTime, returns most recent items up toendTimeand the limit. - With both, behaves like
startTimebut does not exceedendTime.
- Without
- All time and timestamp related fields in the JSON responses are in milliseconds by default. To
receive the information in microseconds, please add the header
X-MBX-TIME-UNIT:MICROSECONDorX-MBX-TIME-UNIT:microsecond. - We support HMAC, RSA, and Ed25519 keys. For more information, please see API Key types.
- Timestamp parameters (e.g.
startTime,endTime,timestamp) can be passed in milliseconds or microseconds. - For APIs that only send public market data, please use the base endpoint https://data-api.binance.vision. Please refer to Market Data Only page.
- If there are enums or terms you want clarification on, please see the SPOT Glossary for more information.
- APIs have a timeout of 10 seconds when processing a request. If a response from the Matching
Engine takes longer than this, the API responds with "Timeout waiting for response from backend
server. Send status unknown; execution status unknown."
(-1007 TIMEOUT)
- This does not always mean that the request failed in the Matching Engine.
- If the status of the request has not appeared in User Data Stream, please perform an API query for its status.
- Please avoid SQL keywords in requests as they may trigger a security block by a WAF (Web Application Firewall) rule. See https://www.binance.com/en/support/faq/detail/360004492232 for more details.
- If your request contains a symbol name containing non-ASCII characters, then the response may contain non-ASCII characters encoded in UTF-8.
- Some endpoints may return asset and/or symbol names containing non-ASCII characters encoded in UTF-8 even if the request did not contain non-ASCII characters.
HTTP Return Codes
- HTTP
4XXreturn codes are used for malformed requests; the issue is on the sender's side. - HTTP
403return code is used when a WAF (Web Application Firewall) rule has been violated. This can indicate a rate limit violation or a security block. See https://www.binance.com/en/support/faq/detail/360004492232 for more details. - HTTP
409return code is used when a cancelReplace order partially succeeds. (i.e. if the cancellation of the order fails but the new order placement succeeds.) - HTTP
429return code is used when breaking a request rate limit. - HTTP
418return code is used when an IP has been auto-banned for continuing to send requests after receiving429codes. - HTTP
5XXreturn codes are used for internal errors; the issue is on Binance's side. It is important to NOT treat this as a failure operation; the execution status is UNKNOWN and could have been a success.
Error Codes
- Any endpoint can return an ERROR
Sample Payload below:
Code
- Specific error codes and messages are defined in Errors Codes.
General Information on Endpoints
- For
GETendpoints, parameters must be sent as aquery string. - For
POST,PUT, andDELETEendpoints, the parameters may be sent as aquery stringor in therequest bodywith content typeapplication/x-www-form-urlencoded. You may mix parameters between both thequery stringandrequest bodyif you wish to do so. - Parameters may be sent in any order.
- If a parameter sent in both the
query stringandrequest body, thequery stringparameter will be used.
LIMITS
General Info on Limits
- The following
intervalLettervalues for headers:- SECOND => S
- MINUTE => M
- HOUR => H
- DAY => D
intervalNumdescribes the amount of the interval. For example,intervalNum5 withintervalLetterM means "Every 5 minutes".- The
/api/v3/exchangeInforateLimitsarray contains objects related to the exchange'sRAW_REQUESTS,REQUEST_WEIGHT, andORDERSrate limits. These are further defined in theENUM definitionssection underRate limiters (rateLimitType). - Requests fail with HTTP status code 429 when you exceed the request rate limit.
IP Limits
- Every request will contain
X-MBX-USED-WEIGHT-(intervalNum)(intervalLetter)in the response headers which has the current used weight for the IP for all request rate limiters defined. - Each route has a
weightwhich determines for the number of requests each endpoint counts for. Heavier endpoints and endpoints that do operations on multiple symbols will have a heavierweight. - 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 (HTTP status 418).
- IP bans are tracked and scale in duration for repeat offenders, from 2 minutes to 3 days.
- A
Retry-Afterheader 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. - The limits on the API are based on the IPs, not the API keys.
Unfilled Order Count
- Every successful order response will contain a
X-MBX-ORDER-COUNT-(intervalNum)(intervalLetter)header indicating how many orders you have placed for that interval. To monitor this, refer toGET api/v3/rateLimit/order. - Rejected/unsuccessful orders are not guaranteed to have
X-MBX-ORDER-COUNT-**headers in the response. - If you have exceeded this, you will receive a 429 error with the
Retry-Afterheader. - Please note that if your orders are consistently filled by trades, you can continuously place orders on the API. For more information, please see Spot Unfilled Order Count Rules.
- The number of unfilled orders is tracked for each account.
Data Sources
- The API system is asynchronous, so some delay in the response is normal and expected.
- Each endpoint has a data source indicating where the data is being retrieved, and thus which endpoints have the most up-to-date response.
These are the three sources, ordered by least to most potential for delays in data updates.
- Matching Engine - the data is from the Matching Engine
- Memory - the data is from a server's local or external memory
- Database - the data is taken directly from a database
Some endpoints can have more than 1 data source. (e.g. Memory => Database) This means that the endpoint will check the first Data Source, and if it cannot find the value it's looking for it will check the next one.
Request Security
- Each endpoint has a security type indicating required API key permissions, shown next to the endpoint name (e.g., New order (TRADE)).
- If unspecified, the security type is
NONE. - Except for
NONE, all endpoints with a security type are consideredSIGNEDrequests (i.e. including asignature). - Secure endpoints require a valid API key to be specified and authenticated.
- API keys can be created on the API Management page of your Binance account.
- Both API key and secret key are sensitive. Never share them with anyone. If you notice unusual activity in your account, immediately revoke all the keys and contact Binance support.
- API keys can be configured to allow access only to certain types of secure endpoints.
- For example, you can have an API key with
TRADEpermission for trading, while using a separate API key withUSER_DATApermission to monitor your order status. - By default, an API key cannot
TRADE. You need to enable trading in API Management first.
- For example, you can have an API key with
| Security type | Description |
|---|---|
NONE | Public market data |
TRADE | Trading on the exchange, placing and canceling orders |
USER_DATA | Private account information, such as order status and your trading history |
USER_STREAM | Managing User Data Stream subscriptions |
SIGNED Endpoint security
SIGNEDendpoints require an additional parameter,signature, to be sent in thequery stringorrequest body.
Signature Case Sensitivity
- HMAC: Signatures generated using HMAC are not case-sensitive. This means the signature string can be verified regardless of letter casing.
- RSA: Signatures generated using RSA are case-sensitive.
- Ed25519: Signatures generated using Ed25519 are also case-sensitive
Please consult SIGNED request example (HMAC), SIGNED request example (RSA), and SIGNED request example (Ed25519) on how to compute signature, depending on which API key type you are using.
Timing security
SIGNEDrequests also require atimestampparameter which should be the current timestamp either in milliseconds or microseconds. (See General API Information)- An additional optional parameter,
recvWindow, specifies for how long the request stays valid and may only be specified in milliseconds.recvWindowsupports up to three decimal places of precision (e.g., 6000.346) so that microseconds may be specified.- If
recvWindowis not sent, it defaults to 5000 milliseconds. - Maximum
recvWindowis 60000 milliseconds.
- Request processing logic is as follows:
Code
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.
It is recommended to use a small recvWindow of 5000 or less! The max cannot go beyond 60,000!
SIGNED Endpoint Examples for POST /api/v3/order
HMAC Keys
The signature payload of your request is the query string concatenated without separator to the HTTP body. Any non-ASCII character must be percent-encoded before signing.
Here is a step-by-step example of how to send a valid signed payload from the Linux command line
using echo, openssl, and curl. There is one example with a symbol name comprised entirely of
ASCII characters and one example with a symbol name containing non-ASCII characters.
Example API key and secret key:
| Key | Value |
|---|---|
apiKey | vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A |
secretKey | NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j |
WARNING: DO NOT SHARE YOUR API KEY AND SECRET KEY WITH ANYONE.
The example keys are provided here only for illustrative purposes.
Example of request with a symbol name comprised entirely of ASCII characters:
| Parameter | Value |
|---|---|
symbol | LTCBTC |
side | BUY |
type | LIMIT |
timeInForce | GTC |
quantity | 1 |
price | 0.1 |
recvWindow | 5000 |
timestamp | 1499827319559 |
Example of a request with a symbol name containing non-ASCII characters:
| Parameter | Value |
|---|---|
symbol | 123456 |
side | BUY |
type | LIMIT |
timeInForce | GTC |
quantity | 1 |
price | 0.1 |
recvWindow | 5000 |
timestamp | 1499827319559 |
Step 1: Construct the signature payload
- Format parameters as
parameter=valuepairs separated by&. - Percent-encode the string.
For the first set of example parameters (ASCII only), the parameter=value string should look like
this:
Code
After percent-encoding, the signature payload should look like this:
Code
For the second set of example parameters (some non-ASCII characters), the parameter=value string
should look like this:
Code
After percent-encoding, the signature payload should look like this:
Code
Step 2: Compute the signature
- Use the
secretKeyof your API key as the signing key for the HMAC-SHA-256 algorithm. - Sign the signature payload constructed in Step 1.
- Encode the HMAC-SHA-256 output as a hex string.
Note that secretKey and the payload are case-sensitive, while the resulting signature value is
case-insensitive.
Example commands
For the first set of example parameters (ASCII only):
Code
For the second set of example parameters (some non-ASCII characters):
Code
Step 3: Add signature to the request
Complete the request by adding the signature parameter to the query string.
For the first set of example parameters (ASCII only):
Code
For the second set of example parameters (some non-ASCII characters)
Code
Here is a sample Bash script performing all the steps above:
Code
RSA Keys
The signature payload of your request is the query string concatenated without separator to the HTTP body. Any non-ASCII character must be percent-encoded before signing.
To get your API key, you need to upload your RSA Public Key to your account and a corresponding API key will be provided for you.
Only PKCS#8 keys are supported.
There is one example with a symbol name comprised entirely of ASCII characters and one example with a symbol name containing non-ASCII characters.
These examples assume the private key is stored in the file ./test-prv-key.pem.
| Key | Value |
|---|---|
apiKey | CAvIjXy3F44yW6Pou5k8Dy1swsYDWJZLeoK2r8G4cFDnE9nosRppc2eKc1T8TRTQ |
Example of request with a symbol name comprised entirely of ASCII characters:
| Parameter | Value |
|---|---|
symbol | BTCUSDT |
side | SELL |
type | LIMIT |
timeInForce | GTC |
quantity | 1 |
price | 0.2 |
timestamp | 1668481559918 |
recvWindow | 5000 |
Example of a request with a symbol name containing non-ASCII characters:
| Parameter | Value |
|---|---|
symbol | 123456 |
side | SELL |
type | LIMIT |
timeInForce | GTC |
quantity | 1 |
price | 0.2 |
timestamp | 1668481559918 |
recvWindow | 5000 |
Step 1: Construct the signature payload
- Format parameters as
parameter=valuepairs separated by&. - Percent-encode the string.
For the first set of example parameters (ASCII only), the parameter=value string should look like
this:
Code
After percent-encoding, the signature payload should look like this:
Code
For the second set of example parameters (some non-ASCII characters), the parameter=value string
should look like this:
Code
After percent-encoding, the signature payload should look like this:
Code
Step 2: Compute the signature
- Sign the signature payload constructed in Step 1 using the RSASSA-PKCS1-v1_5 algorithm with SHA-256 hash function.
- Encode the output in base64.
Note that the payload and the resulting signature are case-sensitive.
For the first set of example parameters (ASCII only):
Code
For the second set of example parameters (some non-ASCII characters):
Code
- Percent-encode the base64 string.
For the first set of example parameters (ASCII only):
Code
For the second set of example parameters (some non-ASCII characters):
Code
Step 3: Add signature to the request
Complete the request by adding the signature parameter to the query string.
For the first set of example parameters (ASCII only):
Code
For the second set of example parameters (some non-ASCII characters):
Code
Here is a sample Bash script performing all the steps above:
Code
Ed25519 Keys
Note: It is highly recommended to use Ed25519 API keys as it should provide the best performance and security out of all supported key types.
The signature payload of your request is the query string concatenated without separator to the HTTP body. Any non-ASCII character must be percent-encoded before signing.
There is one example with a symbol name comprised entirely of ASCII characters and one example with a symbol name containing non-ASCII characters.
These examples assume the private key is stored in the file ./test-prv-key.pem.
| Key | Value |
|---|---|
apiKey | 4yNzx3yWC5bS6YTwEkSRaC0nRmSQIIStAUOh1b6kqaBrTLIhjCpI5lJH8q8R8WNO |
Example of request with a symbol name comprised entirely of ASCII characters.
| Parameter | Value |
|---|---|
symbol | BTCUSDT |
side | SELL |
type | LIMIT |
timeInForce | GTC |
quantity | 1 |
price | 0.2 |
timestamp | 1668481559918 |
recvWindow | 5000 |
Example of a request with a symbol name containing non-ASCII characters.
| Parameter | Value |
|---|---|
symbol | 123456 |
side | SELL |
type | LIMIT |
timeInForce | GTC |
quantity | 1 |
price | 0.2 |
timestamp | 1668481559918 |
recvWindow | 5000 |
Step 1: Construct the signature payload
- Format parameters as
parameter=valuepairs separated by&. - Percent-encode the string.
For the first set of example parameters (ASCII only), the parameter=value string should look like
this:
Code
After percent-encoding, the signature payload should look like this:
Code
For the second set of example parameters (some non-ASCII characters), the parameter=value string
should look like this:
Code
After percent-encoding, the signature payload should look like this:
Code
Step 2: Compute the signature
- Sign the payload.
- Encode the output as a base64 string.
Note that the payload and the resulting signature are case-sensitive.
For the first set of example parameters (ASCII only):
Code
For the second set of example parameters (some non-ASCII characters):
Code
- Percent-encode the base64 string.
For the first set of example parameters (ASCII only):
Code
For the second set of example parameters (some non-ASCII characters):
Code
Step 3: Add signature to the request
Complete the request by adding the signature parameter to the query string.
For the first set of example parameters (ASCII only):
Code
For the second set of example parameters (some non-ASCII characters):
Code
Here is a sample Python script performing all the steps above:
Code