API documentation¶
binance_asyncio.endpoints¶
GeneralEndpoints¶
- class binance_asyncio.endpoints.GeneralEndpoints(api_key=None, uri=None)¶
Class wrapping the general endpoints of the BINANCE RESTfull API
- Parameters:
api_key (string) – your Binance provided API key
- async get_exchange_info()¶
Get the current exchange trading rules and symbol information
- Return type:
(int, dict)
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element is a dict representing the JSON response from the server
- async get_server_time()¶
This checks the connectivity to the binance REST APIs, and returns the current server time.
- Return type:
(int, dict)
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element is a dict representing the JSON response from the server of the form
{ "serverTime": 1499828319859 }
- async ping()¶
Ping the exchange to test the connectivity to the binance REST APIs
MarketDataEndpoints¶
- class binance_asyncio.endpoints.MarketDataEndpoints(api_key=None, uri=None)¶
Class wrapping the Market data endpoints of the BINANCE RESTfull API
- Parameters:
api_key (string) – your Binance provided API key
- async get_aggregated_trades(symbol: str, from_id=None, start_time=None, end_time=None, limit=500)¶
Get aggregate trades.
- Parameters:
symbol (string) – The symbol of the pair
limit (int) – The maximum number results wanted. It default to 500 , the maximum is 1000.
from_id – This is the tradeid to get aggregate trades from (inclusive), if none is provided, it just gets most recent trades
start_time (string) – The time to begin the aggregation from. For example, ‘10 minutes ago’ or ‘1 second ago’
end_time (string) – The time to end the aggregation, in similar format as above
- Return type:
(int, list)
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element is a list containing the aggregated trades
[ { "a": 16239, // agg tradeId "p": "0.01633102", // price "q": "6.73443515", // quantity "f": 13781, // the first tradeId "l": 13781, // the last tradeId "T": 1498794537053, // timestamp "m": true, // is the buyer the maker? "M": true // was the trade the best price match? } ]
- async get_current_average(symbol: str)¶
Get the current average price for a symbol.
- Parameters:
symbol (string) – The symbol of the pair
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element dictionary representing the response
{ "mins": 5, "price": "9.35751834" }
- async get_historical_trades(symbol: str, limit=500, from_id=None)¶
Get historical trades for a symbol.
- Parameters:
symbol (string) – The symbol of the pair
limit (int) – The maximum number results wanted. It default to 500 , the maximum is 1000.
from_id – This is the tradeid to fetch from, if none is provided, it just gets most recent trades
- Return type:
(int, list)
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element is a list containing all recent trades
[ { "id": 82457, "price": "23.00000", "qty": "12.00000000", "quoteQty": "48.000012", "time": 1499865542190, "isBuyerMaker": true, "isBestMatch": true } ]
- async get_klines(symbol: str, interval='1m', start_time=None, end_time=None, limit=500)¶
Get kline/candlestick bars for a symbol
- Parameters:
symbol (string) – The symbol of the pair
interval (string) –
The interval of the kline, valid intervals are
”1m”
”3m”
”5m”
”15m”
”30m”
”1h”
”2h”
”4h”
”6h”
”8h”
”12h”
”1d”
”3d”
”1w”
”1M”
limit (int) – The maximum number of klines wanted. It default to 500 , the maximum is 1000.
start_time (string) – The time to get klines from from. For example, ‘10 minutes ago’ or ‘1 second ago’
end_time (string) – The time to get klines until, in similar format as above
- Return type:
(int, list)
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element is a list containing the klines
[ [ 1499040000000, // Open time "0.01634790", // Open "0.80000000", // High "0.01575800", // Low "0.01577100", // Close "148976.11427815", // Volume 1499644799999, // Close time "2434.19055334", // Quote asset volume 308, // Number of trades "1756.87402397", // Taker buy base asset volume "28.46694368", // Taker buy quote asset volume "17928899.62484339" // Ignore. ] ]
- async get_orderbook(symbol: str, limit=100)¶
Gets the order book.
- Parameters:
symbol (string) – The symbol of the pair
limit (int) – The maximum number results wanted. It default to 100 , the maximum is 5000. And valid limits are 5, 10, 20, 50, 100, 500, 1000, 5000
- Return type:
(int, dict)
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element is a dict representing the JSON response from the server
{ "lastUpdateId": 23321024, "bids": [ [ "1.00000000", // the price "42.00000000" // the quantity ] ], "asks": [ [ "4.00001300", "14.00000000" ] ] }
- async get_price_change_stats_ticker(symbol: str)¶
Get the 24 hour rolling window price change statistics.
- Parameters:
symbol (string) – The symbol of the pair
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element dictionary representing the response
{ "symbol": "BNBBTC", "priceChange": "-94.99999800", "priceChangePercent": "-95.960", "weightedAvgPrice": "0.29628482", "prevClosePrice": "0.10002000", "lastPrice": "4.00000200", "lastQty": "200.00000000", "bidPrice": "4.00000000", "askPrice": "4.00000200", "openPrice": "99.00000000", "highPrice": "100.00000000", "lowPrice": "0.10000000", "volume": "8913.30000000", "quoteVolume": "15.30000000", "openTime": 1499783499040, "closeTime": 1499869899040, "firstId": 28385, // First tradeId "lastId": 28460, // Last tradeId "count": 76 // Trade count }
- async get_recent_trades(symbol: str, limit=500)¶
Get the most recent trades for a symbol.
- Parameters:
symbol (string) – The symbol of the pair
limit (int) – The maximum number results wanted. It default to 500 , the maximum is 1000.
- Return type:
(int, list)
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element is a list containing all recent trades
[ { "id": 82457, "price": "23.00000", "qty": "12.00000000", "quoteQty": "48.000012", "time": 1499865542190, "isBuyerMaker": true, "isBestMatch": true } ]
- async get_symbol_order_book_ticker(symbol: str)¶
Get the best price/qty on the order book for a symbol or symbols
- Parameters:
symbol (string) – The symbol of the pair
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element dictionary representing the response
{ "symbol": "LTCBTC", "bidPrice": "4.00000000", "bidQty": "431.00000000", "askPrice": "4.00000200", "askQty": "9.00000000" }
- async get_symbol_price_ticker(symbol: str)¶
Get the latest price for a symbol or symbols
- Parameters:
symbol (string) – The symbol of the pair
- Returns:
returns a tuple, where the first element is the HTTP response status code and the second element dictionary representing the response
{ "symbol": "LTCBTC", "price": "4.00000200" }