This is an unofficial Python wrapper for the Binance exchange REST API v1/3. I am in no way affiliated with Binance, use at your own risk.
If you came here looking for the Binance exchange to purchase cryptocurrencies, then go here. If you want to automate interactions with Binance stick around.
Register an account with Binance.
Generate an API Key and assign relevant permissions.
pip install python-binance
from binance.client import Client
client = Client(api_key, api_secret)
# get market depth
depth = client.get_order_book(symbol='BNBBTC')
# place market buy order
order = client.create_order(
symbol='BNBBTC',
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_MARKET,
quantity=100)
# get all symbol prices
prices = client.get_all_tickers()
# withdraw 100 ETH
# check docs for assumptions around withdrawals
from binance.exceptions import BinanceApiException, BinanceWithdrawException
try:
result = client.withdraw(
asset='ETH',
address='<eth_address>',
amount=100)
except BinanceApiException as e:
print(e)
except BinanceWithdrawException as e:
print(e)
else:
print("Success")
# fetch list of withdrawals
withdraws = client.get_withdraw_history()
# fetch list of ETH withdrawals
eth_withdraws = client.get_withdraw_history('ETH)
# get a deposit address
address = client.get_deposit_address('BTC)
# start trade websocket
def process_message(msg):
print("message type: {}".format(msg['e']))
print(msg)
# do something
from binance.websockets import BinanceSocketManager
bm = BinanceSocketManager(client)
bm.start_aggtrade_socket(symbol='BNBBTC')
bm.start()
For more check out the documentation.
If this library helped you out feel free to donate.
If you use Quoinex or Qryptos check out my python-quoine library.
If you use Kucoin check out my python-kucoin library.
If you use IDEX check out my python-idex library.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。