A look at sammchardy/python-binance: 7.2k stars on GitHub, written primarily in Python, tracked under the API category. Binance Exchange API python implementation for automated trading
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
This is an unofficial Python wrapper for the Binance exchange REST API v3 <https://binance-docs.github.io/apidocs/spot/en>_.
If you came here looking for the Binance exchange <https://accounts.binance.com/register?ref=PGDFCE46>_ to purchase cryptocurrencies, then go here <https://accounts.binance.com/register?ref=PGDFCE46>_.
If you want to automate interactions with Binance stick around.
Please make sure yourpython-binanceversion isv.1.0.20or higher.The previous versions are no longer recommended because some endpoints have been deprecated.
Examples including async
https://github.com/sammchardy/python-binance/tree/master/examples
Async basics for Binance <https://sammchardy.github.io/binance/2021/05/01/async-binance-basics.html>_
Understanding Binance Order Filters <https://sammchardy.github.io/binance/2021/05/03/binance-order-filters.html>_
Make sure you update often and check the Changelog <https://python-binance.readthedocs.io/en/latest/changelog.html>_ for new features and bug fixes.
Your contributions, suggestions, and fixes are always welcome! Don't hesitate to open a GitHub issue or reach out to us on our Telegram chat
Features
Implementation of all General, Market Data and Account endpoints.
Asyncio implementation
Demo trading support (by providing demo=True)
Testnet support for Spot, Futures and Vanilla Options (deprecated)
Simple handling of authentication include RSA and EDDSA keys
Verbose mode for inspecting requests (verbose=True)
No need to generate timestamps yourself, the wrapper does it for you
RecvWindow sent by default
Response exception handling
Customizable HTTP headers
Websocket handling with reconnection and multiplexed connections
CRUD over websockets, create/fetch/edit through websockets for minimum latency.
Symbol Depth Cache
Historical Kline/Candle fetching function
Withdraw functionality
Deposit addresses
Margin Trading
Futures Trading
Porfolio Margin Trading
Vanilla Options
Proxy support (REST and WS)
Orjson support for faster JSON parsing
Support other domains (.us, .jp, etc)
Support for the Gift Card API
Upgrading to v1.0.0+
The breaking changes include the migration from wapi to sapi endpoints which related to the
wallet endpoints detailed in the Binance Docs <https://binance-docs.github.io/apidocs/spot/en/#wallet-endpoints>_
The other breaking change is for websocket streams and the Depth Cache Manager which have been
converted to use Asynchronous Context Managers. See examples in the Async section below or view the
websockets <https://python-binance.readthedocs.io/en/latest/websockets.html>_ and
depth cache <https://python-binance.readthedocs.io/en/latest/depth_cache.html>_ docs.
Quick Start
Register an account with Binance <https://accounts.binance.com/register?ref=PGDFCE46>_.
Generate an API Key <https://www.binance.com/en/my/settings/api-management>_ and assign relevant permissions.
If you are using an exchange from the US, Japan or other TLD then make sure pass tld='us' when creating the
client.
To use the Spot <https://testnet.binance.vision/>, Vanilla Options <https://testnet.binanceops.com/> , or Futures <https://testnet.binancefuture.com>_ Testnet
pass testnet=True when creating the client.
.. code:: bash
pip install python-binance
.. code:: python
from binance import Client, ThreadedWebsocketManager, ThreadedDepthCacheManager
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_test_order(
symbol='BNBBTC',
side=Client.SIDE_BUY,
type=Client.ORDER_TYPE_MARKET,
quantity=100)
# get all symbol prices
prices = client.get_all_tickers()
# withdraw 100 ETH
# check docs for assumptions around withdrawals
from binance.exceptions import BinanceAPIException
try:
result = client.withdraw(
asset='ETH',
address='<eth_address>',
amount=100)
except BinanceAPIException 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(coin='ETH')
# get a deposit address for BTC
address = client.get_deposit_address(coin='BTC')
# get historical kline data from any date range
# 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")
# create conditional order using the dedicated method
algo_order = client.futures_create_algo_order(symbol="LTCUSDT", side="BUY", type="STOP_MARKET", quantity=0.1, triggerPrice = 120)
# create conditional order using the create_order method (will redirect to the algoOrder as well)
order2 = await client.futures_create_order(symbol="LTCUSDT", side="BUY", type="STOP_MARKET", quantity=0.1, triggerPrice = 120)
# cancel algo/conditional order
cancel2 = await client.futures_cancel_algo_order(orderId=order2["orderId"], symbol="LTCUSDT")
# fetch open algo/conditional orders
open_orders = await client.futures_get_open_algo_orders(symbol="LTCUSDT")
# create order through websockets
order_ws = client.ws_create_order( symbol="LTCUSDT", side="BUY", type="MARKET", quantity=0.1)
# get account using custom headers
account = client.get_account(headers={'MyCustomKey': 'MyCustomValue'})
# socket manager using threads
twm = ThreadedWebsocketManager()
twm.start()
# depth cache manager using threads
dcm = ThreadedDepthCacheManager()
dcm.start()
def handle_socket_message(msg):
print(f"message type: {msg['e']}")
print(msg)
def handle_dcm_message(depth_cache):
print(f"symbol {depth_cache.symbol}")
print("top 5 bids")
print(depth_cache.get_bids()[:5])
print("top 5 asks")
print(depth_cache.get_asks()[:5])
print("last update time {}".format(depth_cache.update_time))
twm.start_kline_socket(callback=handle_socket_message, symbol='BNBBTC')
dcm.start_depth_cache(callback=handle_dcm_message, symbol='ETHBTC')
# replace with a current options symbol
options_symbol = 'BTC-241227-41000-C'
dcm.start_options_depth_cache(callback=handle_dcm_message, symbol=options_symbol)
# join the threaded managers to the main thread
twm.join()
dcm.join()
For more check out the documentation <https://python-binance.readthedocs.io/en/latest/>_.
Async Example
Read Async basics for Binance <https://sammchardy.github.io/binance/2021/05/01/async-binance-basics.html>_
for more information.
.. code:: python
import asyncio
import json
from binance import AsyncClient, DepthCacheManager, BinanceSocketManager
async def main():
# initialise the client
client = await AsyncClient.create()
# run some simple requests
print(json.dumps(await client.get_exchange_info(), indent=2))
print(json.dumps(await client.get_symbol_ticker(symbol="BTCUSDT"), indent=2))
# initialise websocket factory manager
bsm = BinanceSocketManager(client)
# create listener using async with
# this will exit and close the connection after 5 messages
async with bsm.trade_socket('ETHBTC') as ts:
for _ in range(5):
res = await ts.recv()
print(f'recv {res}')
# get historical kline data from any date range
# fetch 1 minute klines for the last day up until now
klines = client.get_historical_klines("BNBBTC", AsyncClient.KLINE_INTERVAL_1MINUTE, "1 day ago UTC")
# use generator to fetch 1 minute klines for the last day up until now
async for kline in await client.get_historical_klines_generator("BNBBTC", AsyncClient.KLINE_INTERVAL_1MINUTE, "1 day ago UTC"):
print(kline)
# fetch 30 minute klines for the last month of 2017
klines = await client.get_historical_klines("ETHBTC", Client.KLINE_INTERVAL_30MINUTE, "1 Dec, 2017", "1 Jan, 2018")
# fetch weekly klines since it listed
klines = await client.get_historical_klines("NEOBTC", Client.KLINE_INTERVAL_1WEEK, "1 Jan, 2017")
# create order through websockets
order_ws = await client.ws_create_order( symbol="LTCUSDT", side="BUY", type="MARKET", quantity=0.1)
# setup an async context the Depth Cache and exit after 5 messages
async with DepthCacheManager(client, symbol='ETHBTC') as dcm_socket:
for _ in range(5):
depth_cache = await dcm_socket.recv()
print(f"symbol {depth_cache.symbol} updated:{depth_cache.update_time}")
print("Top 5 asks:")
print(depth_cache.get_asks()[:5])
print("Top 5 bids:")
print(depth_cache.get_bids()[:5])
# Vanilla options Depth Cache works the same, update the symbol to a current one
options_symbol = 'BTC-241227-41000-C'
async with OptionsDepthCacheManager(client, symbol=options_symbol) as dcm_socket:
for _ in range(5):
depth_cache = await dcm_socket.recv()
count += 1
print(f"symbol {depth_cache.symbol} updated:{depth_cache.update_time}")
print("Top 5 asks:")
print(depth_cache.get_asks()[:5])
print("Top 5 bids:")
print(depth_cache.get_bids()[:5])
await client.close_connection()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
The library is under MIT license, that means it's absolutely free for any developer to build commercial and opensource software on top of it, but use it at your own risk with no warranties, as is.
Orjson support
Python-binance also supports orjson for parsing JSON since it is much faster than the builtin library. This is especially important when using websockets because some exchanges return big messages that need to be parsed and dispatched as quickly as possible.
However, orjson is not enabled by default because it is not supported by every python interpreter. If you want to opt-in, you just need to install it (pip install orjson) on your local environment. Python-binance will detect the installion and pick it up automatically.
LLM & AI Agent Support
This library includes resources to help AI coding assistants (Claude Code, Cursor, Copilot, etc.):
llms.txt — Concise library overview for LLMs (llmstxt.org <https://llmstxt.org>_ standard)
llms-full.txt — Complete API reference for LLMs (all 797+ methods with signatures and parameters)
.agents/skills/python-binance/ — Agent Skill (works with any Agent Skills <https://agentskills.io>_ compatible tool)
generate_llms_txt.py — Script to regenerate the LLM files after library updates
Install the agent skill into any project or globally with npx skills <https://www.npmjs.com/package/skills>_
(works with Claude Code, Cursor, Copilot, Gemini CLI, Goose, Roo Code, and 30+ other agents):
.. code:: bash
# Install into the current project
npx -y skills add sammchardy/python-binance
# Install globally (available in all projects)
npx -y skills add sammchardy/python-binance --global
Check out CCXT <https://github.com/ccxt/ccxt>_ for more than 100 crypto exchanges with a unified trading API.
If you use Kucoin <https://www.kucoin.com/ucenter/signup?rcode=E5wkqe>_ check out my python-kucoin <https://github.com/sammchardy/python-kucoin>_ library.
How active is development on sammchardy/python-binance?
The most recent commit recorded on sammchardy/python-binance was 5 months ago, based on the GitHub push timestamp. The repository has 2.3k forks — one of the better signals of community interest.
How many stars does sammchardy/python-binance have?
sammchardy/python-binance has 7.2k GitHub stars — refresh the page for the live number, or check github.com/sammchardy/python-binance. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is sammchardy/python-binance open source?
Yes — sammchardy/python-binance ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/sammchardy/python-binance.
What else is in the API space?
sammchardy/python-binance is tracked by TopGit under the API category, alongside 7 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What topics is sammchardy/python-binance associated with?
GitHub's repository topics for sammchardy/python-binance: "api", "binance", "cryptocurrency", "python", "python2", "python3", "websockets". TopGit's editorial category is API.
Where can I see sammchardy/python-binance in action?
The project maintains a homepage at https://python-binance.readthedocs.io/en/latest/. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about sammchardy/python-binance?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/sammchardy/python-binance is the definitive source.
Read full README in the tab above.
Still deciding about python-binance?
One click hands the question to an AI along with this page — see what it says about python-binance.