| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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.
Make sure you update often and check the Changelog for new features and bug fixes.
This fork features numerous improvements on the parent project, though it is still a work in progress. Specifically, migration to coroutine-based websockets is not complete, though the parts that /are/ done are ready to use. Everything outside of websockets is complete though, which is to say at least as complete as the parent project. Among these improvements:
For all changes, just look at the git history.
Register an account with Binance.
Generate an API Key and assign relevant permissions.
% pacaur -S python-binance-gitfrom binance import Client
import binance.constants as bc
client = Client(api_key, api_secret)
# Get market depth.
depth = client.order_book(symbol='BNBBTC')
# Place a test market buy order. To place an actual order use the
# create_order function.
order = client.create_test_order(
symbol='BNBBTC',
side=bc.SIDE_BUY,
type=bc.ORDER_TYPE_MARKET,
quantity=100)
# Get all symbol prices.
prices = client.all_tickers()
# Withdraw 100 ETH. Check docs for assumptions around withdrawals.
from binance.exceptions import APIException, WithdrawException
try:
result = client.withdraw(
asset='ETH',
address='<eth_address>',
amount=100)
except APIException as e:
print(e)
except WithdrawException as e:
print(e)
else:
print("Success")
# Fetch list of withdrawals.
withdraws = client.withdraw_history()
# Fetch list of ETH withdrawals.
eth_withdraws = client.withdraw_history(asset='ETH')
# Get a deposit address for BTC.
address = client.deposit_address(asset='BTC')
# Start aggregated trade websocket for BNBBTC.
def process_message(msg):
print("message type: {}".format(msg['e']))
print(msg)
# do something
from binance.websockets import SocketManager
bm = SocketManager(client)
bm.start_aggtrade_socket('BNBBTC', process_message)
bm.start()
# Get historical kline data from any date range.
# Fetch 1 minute klines from one day ago until now.
from datetime import datetime, timedelta
from time import time
klines = client.historical_klines("BNBBTC", bc.KLINE_INTERVAL_1MINUTE,
datetime.utcnow() - timedelta(1))
# Fetch 30 minute klines for the last month of 2017.
klines = client.historical_klines("ETHBTC", bc.KLINE_INTERVAL_30MINUTE,
datetime(2017, 12, 1), datetime(2018, 1, 1))
# Fetch weekly klines since it listed.
klines = client.historical_klines("NEOBTC", bc.KLINE_INTERVAL_1WEEK,
datetime(2017, 1, 1))| Back | FazBrowse Home | New Git URL |