python-binance
Binance Exchange API python implementation for automated trading
An unofficial Python library that wraps the Binance crypto exchange API, letting you write trading bots, fetch live prices, manage orders, and stream real-time market data without building raw HTTP or WebSocket connections yourself.
python-binance is an unofficial Python library for connecting to the Binance cryptocurrency exchange. It wraps the Binance REST API so that you can interact with the exchange from Python code, rather than making raw HTTP requests yourself. The typical use case is automated trading: writing a script or bot that places orders, checks prices, and manages a portfolio without manual intervention.
The library covers all the main endpoint categories that Binance exposes. You can fetch market data such as prices and order books, place and cancel orders, pull account balances, and retrieve historical price charts called klines or candlesticks. More advanced areas are also supported: margin trading, futures trading, portfolio margin accounts, vanilla options, and withdrawals and deposits.
Beyond the REST API, the library handles WebSocket connections, which are persistent live data streams that push price changes, new trades, and order book updates to your application as they happen, rather than requiring you to poll repeatedly. WebSocket connections can be multiplexed, reconnect automatically on disconnection, and can even be used to place and modify orders at lower latency than the REST API.
Installation is done with pip, and the library supports both synchronous and asyncio-based usage. Authentication with API keys is handled for you, including support for RSA and EDDSA key formats. A verbose mode lets you inspect outgoing requests for debugging. Demo mode and testnet environments are available so you can test strategies without risking real funds, and proxy support is included for both REST and WebSocket connections.
Documentation lives at python-binance.readthedocs.io, and an active community Telegram channel is available for questions. The library uses ccxt for core exchange connectivity.
Where it fits
- Write a Python trading bot that automatically places buy and sell orders on Binance based on a price condition.
- Stream live price updates in real time using a WebSocket connection without polling the API repeatedly.
- Pull historical candlestick data for a trading pair and feed it into a strategy backtesting script.
- Check account balances and open positions across spot, margin, and futures from a single Python script.