explaingit

sammchardy/python-binance

7,154PythonAudience · developerComplexity · 3/5Setup · moderate

TLDR

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.

Mindmap

mindmap
  root((python-binance))
    What it does
      REST API wrapper
      WebSocket streams
      Order management
    Market Areas
      Spot trading
      Margin and futures
      Options withdrawals
    Features
      Async support
      Auto-reconnect
      Testnet demo mode
    Audience
      Algo traders
      Python developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Write a Python trading bot that automatically places buy and sell orders on Binance based on a price condition.

USE CASE 2

Stream live price updates in real time using a WebSocket connection without polling the API repeatedly.

USE CASE 3

Pull historical candlestick data for a trading pair and feed it into a strategy backtesting script.

USE CASE 4

Check account balances and open positions across spot, margin, and futures from a single Python script.

Tech stack

PythonasyncioWebSocketccxt

Getting it running

Difficulty · moderate Time to first run · 30min

Requires a Binance account and API keys, use the testnet environment to test strategies without risking real funds.

In plain English

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.

Copy-paste prompts

Prompt 1
Using python-binance, write a script that buys $50 of ETH on Binance when the price drops below a target I set, then sells when it rises 5%.
Prompt 2
I want to stream real-time BTC/USDT price ticks from Binance using python-binance WebSocket. Show me the minimal asyncio code to print each new price.
Prompt 3
Fetch the last 30 days of daily candlestick data for SOL/USDT using python-binance and load it into a pandas DataFrame.
Prompt 4
How do I safely store my Binance API key in a python-binance project so it is not hardcoded in the script?
Prompt 5
Set up python-binance to use the testnet environment so I can test my trading strategy without risking real funds.
Open on GitHub → Explain another repo

← sammchardy on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.