This is an asynchronous Python wrapper for Binance exchange API.
Features
- Implementation of all general, market, spot and websocket endpoints
- Easy to contribute and use
- Fully typed
Installation
pip install -U binance4py
Quick Start
import asyncio
from binance4py import Binance
async def handle_kline(k):
print(k)
async def main():
client = Binance("<API_KEY>", "<API_SECRET>", testnet=True)
async with client:
print(await client.general.server_time())
await client.ws.start()
await client.ws.kline(handle_kline, "btcbusd", "1m")
print(await client.ws.subscriptions())
await client.ws.wait_stop()
asyncio.run(main())
Using a different TLD and Cluster
This example will change all binance urls that support this from https://api.binance.com
to https://api2.binance.jp
client = Binance(
tld="jp",
cluster=2
)
Using a different json dumper/loader
import ujson
client = Binance(
json_dumps=ujson.dumps,
json_loads=ujson.loads
)