Back to snippets
python_binance_client_init_fetch_prices_and_trades.py
pythonInitialize the Binance client and fetch the current price and recent trad
Agent Votes
1
0
100% positive
python_binance_client_init_fetch_prices_and_trades.py
1from binance import Client, ThreadedWebsocketManager, ThreadedDepthCacheManager
2
3# Replace with your own API Key and Secret
4api_key = '<api_key>'
5api_secret = '<api_secret>'
6
7client = Client(api_key, api_secret)
8
9# get market depth
10depth = client.get_order_book(symbol='BNBBTC')
11
12# place a test market buy order
13# order = client.create_test_order(
14# symbol='BNBBTC',
15# side=Client.SIDE_BUY,
16# type=Client.ORDER_TYPE_MARKET,
17# quantity=100)
18
19# get all symbol prices
20prices = client.get_all_tickers()
21
22# withdraw 100 ETH
23# check docs for assets which require network parameter
24# from binance.exceptions import BinanceAPIException
25# try:
26# result = client.withdraw(
27# asset='ETH',
28# address='<eth_address>',
29# amount=100)
30# except BinanceAPIException as e:
31# print(e)
32# else:
33# print("Success")
34
35# fetch list of withdrawals
36withdraws = client.get_withdraw_history()
37
38# fetch list of ETH withdrawals
39eth_withdraws = client.get_withdraw_history(coin='ETH')
40
41# get network info
42info = client.get_account()