This is an unofficial Python wrapper for the Bitrue exchange REST API v1/. I am in no way affiliated with Bitrue, use at your own risk.
If you came here looking for the Bitrue exchange to purchase cryptocurrencies, then go here. If you want to automate interactions with Binance stick around.
- Source code
- https://github.com/sammchardy/python-bitrue-lab
- Documentation
- https://python-bitrue.readthedocs.io/en/latest/ (pending release)
- Binance Telegram
- https://t.me/BitrueOfficial
- Implementation of all General, Market Data and Account endpoints.
- Simple handling of authentication
- No need to generate timestamps yourself, the wrapper does it for you
- Response exception handling
- Websocket handling with reconnection and multiplexed connections
- Symbol Depth Cache
- Historical Kline/Candle fetching function
- Withdraw functionality
- Deposit addresses
Register an account with Binance.
Generate an API Key and assign relevant permissions.
pip install python-bitrue (pending release)
from bitrue.client import Client
api_key=''
api_secret=''
client = Client(api_key, api_secret)
# get market depth
depth = client.get_order_book(symbol='BNBBTC')
# place a test market buy order, to place an actual order use the create_order function
order = client.create_order(
symbol='XRPUSDT',
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_MARKET,
quantity=100)
# get all symbol prices
prices = client.get_all_tickers()
# withdraw 1000 XRP
# 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(asset='ETH')
# get a deposit address for BTC
address = client.get_deposit_address(asset='BTC')
# Fetch balance of asset, create a sell order - subsequently cancel sell order using orderId
asset = test.get_asset_balance(asset='XRP')
asset_free = asset['free']
order = test.create_order(symbol='XRPUSDT',
side=Client.SIDE_SELL,
type=Client.ORDER_TYPE_LIMIT,
quantity=int(float(asset_free)),
price=4.01)
print(order)
orderId = order['orderId']
print('Order ID: ',orderId, 'sleeping for 10')
time.sleep(10)
pprint(test.cancel_order(symbol='XRPUSDT', orderId=orderId))
#check for open orders and format data for easy reading.
try:
open = test.get_open_orders(symbol='CSCXRP',orderId=orderId) #,orderId=orderId
filled = open[0]['executedQty']
total = open[0]['origQty']
print('Order status: ', float(filled), 'of',float(total))
except:
print('no orders open')
# get historical kline data from any date range - BITRUE CURRENTLY DOES NOT OFFER KLINE QUERIES VIA API
# fetch 1 minute klines for the last day up until now
klines = client.get_historical_klines("BNBBTC", Client.KLINE_INTERVAL_1MINUTE, "1 day ago UTC")
# fetch 30 minute klines for the last month of 2017
klines = client.get_historical_klines("ETHBTC", Client.KLINE_INTERVAL_30MINUTE, "1 Dec, 2017", "1 Jan, 2018")
# fetch weekly klines since it listed
klines = client.get_historical_klines("NEOBTC", Client.KLINE_INTERVAL_1WEEK, "1 Jan, 2017")
For more check out the documentation.
If this library helped you out feel free to donate.
- ETH: 0xD7a7fDdCfA687073d7cC93E9E51829a727f9fE70
- LTC: LPC5vw9ajR1YndE1hYVeo3kJ9LdHjcRCUZ
- NEO: AVJB4ZgN7VgSUtArCt94y7ZYT6d5NDfpBo
- BTC: 1Dknp6L6oRZrHDECRedihPzx2sSfmvEBys
If you use Binance Chain check out my python-binance-chain library.
If you use Kucoin check out my python-kucoin library.
If you use Allcoin check out my python-allucoin library.
If you use IDEX check out my python-idex library.
If you use Quoinex or Qryptos check out my python-quoine library.
If you use BigONE check out my python-bigone library.