General Info
General API Information¶
- Some endpoints will require an API Key. Please refer to this page
- The base endpoint is: https://fapi.asterdex.com
- All endpoints return either a JSON object or array.
- Data is returned in ascending order. Oldest first, newest last.
- All time and timestamp related fields are in milliseconds.
- All data types adopt definition in JAVA.
HTTP Return Codes¶
- HTTP
4XXreturn codes are used for for malformed requests; the issue is on the sender's side. - HTTP
403return code is used when the WAF Limit (Web Application Firewall) has been violated. - 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 Aster's side. - HTTP
503return code is used when the API successfully sent the message but not get a response within the timeout period.
It is important to NOT treat this as a failure operation; the execution status is UNKNOWN and could have been a success.
Error Codes and Messages¶
- Any endpoint can return an ERROR
The error payload is as follows:
{
"code": -1121,
"msg": "Invalid symbol."
}
- Specific error codes and messages defined in Error Codes Page.
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¶
- The
/fapi/v1/exchangeInforateLimitsarray contains objects related to the exchange'sRAW_REQUEST,REQUEST_WEIGHT, andORDERrate limits. These are further defined in theENUM definitionssection underRate limiters (rateLimitType). - A
429will be returned when either rate limit is violated.
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.
- The limits on the API are based on the IPs, not the API keys.
Order Rate Limits¶
- Every order response will contain a
X-MBX-ORDER-COUNT-(intervalNum)(intervalLetter)header which has the current order count for the account for all order rate limiters defined. - Rejected/unsuccessful orders are not guaranteed to have
X-MBX-ORDER-COUNT-**headers in the response. - The order rate limit is counted against each account.
Endpoint Security Type¶
- Each endpoint has a security type that determines the how you will interact with it.
- API-keys are passed into the Rest API via the
X-MBX-APIKEYheader. - API-keys and secret-keys are case sensitive.
- API-keys can be configured to only access certain types of secure endpoints. For example, one API-key could be used for TRADE only, while another API-key can access everything except for TRADE routes.
- By default, API-keys can access all secure routes.
| Security Type | Description |
|---|---|
| NONE | Endpoint can be accessed freely. |
| TRADE | Endpoint requires sending a valid API-Key and signature. |
| USER_DATA | Endpoint requires sending a valid API-Key and signature. |
| USER_STREAM | Endpoint requires sending a valid API-Key. |
| MARKET_DATA | Endpoint requires sending a valid API-Key. |
TRADEandUSER_DATAendpoints areSIGNEDendpoints.
SIGNED (TRADE and USER_DATA) Endpoint Security¶
SIGNEDendpoints require an additional parameter,signature, to be sent in thequery stringorrequest body.- Endpoints use
HMAC SHA256signatures. TheHMAC SHA256 signatureis a keyedHMAC SHA256operation. Use yoursecretKeyas the key andtotalParamsas the value for the HMAC operation. - The
signatureis not case sensitive. - Please make sure the
signatureis the end part of yourquery stringorrequest body. totalParamsis defined as thequery stringconcatenated with therequest body.
Timing Security¶
- A
SIGNEDendpoint 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 aftertimestampthe request is valid for. IfrecvWindowis not sent, it defaults to 5000.
The logic is as follows:
if (timestamp < (serverTime + 1000) && (serverTime - timestamp) <= recvWindow){
// process request
}
else {
// reject request
}
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 /fapi/v1/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.
| Key | Value |
|---|---|
| apiKey | dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83 |
| secretKey | 2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9 |
| Parameter | Value |
|---|---|
| symbol | BTCUSDT |
| side | BUY |
| type | LIMIT |
| timeInForce | GTC |
| quantity | 1 |
| price | 9000 |
| recvWindow | 5000 |
| timestamp | 1591702613943 |
Example 1: As a query string¶
Example 1
HMAC SHA256 signature:
$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943" | openssl dgst -sha256 -hmac "2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9"
(stdin)= 3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9
curl command:
(HMAC SHA256)
$ curl -H "X-MBX-APIKEY: dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83" -X POST 'https://fapi/asterdex.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943&signature= 3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9'
symbol=BTCUSDT
&side=BUY
&type=LIMIT
&timeInForce=GTC
&quantity=1
&price=9000
&recvWindow=5000
×tamp=1591702613943
Example 2: As a request body¶
Example 2
HMAC SHA256 signature:
$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943" | openssl dgst -sha256 -hmac "2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9"
(stdin)= 3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9
curl command:
(HMAC SHA256)
$ curl -H "X-MBX-APIKEY: dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83" -X POST 'https://fapi/asterdex.com/fapi/v1/order' -d 'symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943&signature= 3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9'
-
requestBody:
symbol=BTCUSDT
&side=BUY
&type=LIMIT
&timeInForce=GTC
&quantity=1
&price=9000
&recvWindow=5000
×tamp=1591702613943
Example 3: Mixed query string and request body¶
Example 3
HMAC SHA256 signature:
$ echo -n "symbol=BTCUSDT&side=BUY&type=LIMIT&quantity=1&price=9000&timeInForce=GTC&recvWindow=5000×tamp=1591702613943" | openssl dgst -sha256 -hmac "2b5eb11e18796d12d88f13dc27dbbd02c2cc51ff7059765ed9821957d82bb4d9"
(stdin)= 3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9
curl command:
(HMAC SHA256)
$ curl -H "X-MBX-APIKEY: dbefbc809e3e83c283a984c3a1459732ea7db1360ca80c5c2c8867408d28cc83" -X POST 'https://fapi/asterdex.com/fapi/v1/order?symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC' -d 'quantity=1&price=9000&recvWindow=5000×tamp=1591702613943&signature=3c661234138461fcc7a7d8746c6558c9842d4e10870d2ecbedf7777cad694af9'
- queryString: symbol=BTCUSDT&side=BUY&type=LIMIT&timeInForce=GTC
- requestBody: quantity=1&price=9000&recvWindow=5000×tamp= 1591702613943
Note that the signature is different in example 3.
There is no & between "GTC" and "quantity=1".
Public Endpoints Info¶
Terminology¶
base assetrefers to the asset that is thequantityof a symbol.quote assetrefers to the asset that is thepriceof a symbol.
ENUM definitions¶
Symbol type:
- FUTURE
Contract type (contractType):
- PERPETUAL
Contract status(contractStatus,status):
- PENDING_TRADING
- TRADING
- PRE_SETTLE
- SETTLING
- CLOSE
Order status (status):
- NEW
- PARTIALLY_FILLED
- FILLED
- CANCELED
- REJECTED
- EXPIRED
Order types (orderTypes, type):
- LIMIT
- MARKET
- STOP
- STOP_MARKET
- TAKE_PROFIT
- TAKE_PROFIT_MARKET
- TRAILING_STOP_MARKET
Order side (side):
- BUY
- SELL
Position side (positionSide):
- BOTH
- LONG
- SHORT
Time in force (timeInForce):
- GTC - Good Till Cancel
- IOC - Immediate or Cancel
- FOK - Fill or Kill
- GTX - Good Till Crossing (Post Only)
- HIDDEN - HIDDEN This type of order is not visible in the order book
Working Type (workingType)
- MARK_PRICE
- CONTRACT_PRICE
Response Type (newOrderRespType)
- ACK
- RESULT
Kline/Candlestick chart intervals:
m -> minutes; h -> hours; d -> days; w -> weeks; M -> months
- 1m
- 3m
- 5m
- 15m
- 30m
- 1h
- 2h
- 4h
- 6h
- 8h
- 12h
- 1d
- 3d
- 1w
- 1M
Rate limiters (rateLimitType)
REQUEST_WEIGHT
{
"rateLimitType": "REQUEST_WEIGHT",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 2400
}
ORDERS
{
"rateLimitType": "ORDERS",
"interval": "MINUTE",
"intervalNum": 1,
"limit": 1200
}
-
REQUEST_WEIGHT
-
ORDERS
Rate limit intervals (interval)
- MINUTE
Filters¶
Filters define trading rules on a symbol or an exchange.
Symbol filters¶
PRICE_FILTER¶
/exchangeInfo format:
{
"filterType": "PRICE_FILTER",
"minPrice": "0.00000100",
"maxPrice": "100000.00000000",
"tickSize": "0.00000100"
}
The PRICE_FILTER defines the price rules for a symbol. There are 3 parts:
minPricedefines the minimumprice/stopPriceallowed; disabled onminPrice== 0.maxPricedefines the maximumprice/stopPriceallowed; disabled onmaxPrice== 0.tickSizedefines the intervals that aprice/stopPricecan be increased/decreased by; disabled ontickSize== 0.
Any of the above variables can be set to 0, which disables that rule in the price filter. In order to pass the price filter, the following must be true for price/stopPrice of the enabled rules:
price>=minPriceprice<=maxPrice- (
price-minPrice) %tickSize== 0
LOT_SIZE¶
/exchangeInfo format:
{
"filterType": "LOT_SIZE",
"minQty": "0.00100000",
"maxQty": "100000.00000000",
"stepSize": "0.00100000"
}
The LOT_SIZE filter defines the quantity (aka "lots" in auction terms) rules for a symbol. There are 3 parts:
minQtydefines the minimumquantityallowed.maxQtydefines the maximumquantityallowed.stepSizedefines the intervals that aquantitycan be increased/decreased by.
In order to pass the lot size, the following must be true for quantity:
quantity>=minQtyquantity<=maxQty- (
quantity-minQty) %stepSize== 0
MARKET_LOT_SIZE¶
/exchangeInfo format:
{
"filterType": "MARKET_LOT_SIZE",
"minQty": "0.00100000",
"maxQty": "100000.00000000",
"stepSize": "0.00100000"
}
The MARKET_LOT_SIZE filter defines the quantity (aka "lots" in auction terms) rules for MARKET orders on a symbol. There are 3 parts:
minQtydefines the minimumquantityallowed.maxQtydefines the maximumquantityallowed.stepSizedefines the intervals that aquantitycan be increased/decreased by.
In order to pass the market lot size, the following must be true for quantity:
quantity>=minQtyquantity<=maxQty- (
quantity-minQty) %stepSize== 0
MAX_NUM_ORDERS¶
/exchangeInfo format:
{
"filterType": "MAX_NUM_ORDERS",
"limit": 200
}
The MAX_NUM_ORDERS filter defines the maximum number of orders an account is allowed to have open on a symbol.
Note that both "algo" orders and normal orders are counted for this filter.
MAX_NUM_ALGO_ORDERS¶
/exchangeInfo format:
{
"filterType": "MAX_NUM_ALGO_ORDERS",
"limit": 100
}
The MAX_NUM_ALGO_ORDERS filter defines the maximum number of all kinds of algo orders an account is allowed to have open on a symbol.
The algo orders include STOP, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET, and TRAILING_STOP_MARKET orders.
PERCENT_PRICE¶
/exchangeInfo format:
{
"filterType": "PERCENT_PRICE",
"multiplierUp": "1.1500",
"multiplierDown": "0.8500",
"multiplierDecimal": 4
}
The PERCENT_PRICE filter defines valid range for a price based on the mark price.
In order to pass the percent price, the following must be true for price:
- BUY:
price<=markPrice*multiplierUp - SELL:
price>=markPrice*multiplierDown
MIN_NOTIONAL¶
/exchangeInfo format:
{
"filterType": "MIN_NOTIONAL",
"notional": "1"
}
The MIN_NOTIONAL filter defines the minimum notional value allowed for an order on a symbol.
An order's notional value is the price * quantity.
Since MARKET orders have no price, the mark price is used.