Binance SDK (Python)
🔗 Fork Notice: This repository is a significantly modified fork of the official binance-connector-python. It has been refactored to use modern Python packaging (pyproject.toml), updated tooling (uv, ruff), and enhanced development workflows.
sidan-binance-py is a lightweight, modern Python library for connecting to the Binance public API. It’s designed to be simple, clean, and easy to use with minimal dependencies.
Fork Source Code: https://github.com/sidan-lab/sidan-binance-py
Original Connector: https://github.com/binance/binance-connector-python
Official API document:
Support channels:
Binance developer forum: https://dev.binance.vision/
Telegram Channel: https://t.me/binance_api_english
API key setup: https://www.binance.com/en-NG/support/faq/360002502072
Testnet API key setup: https://dev.binance.vision/t/99
Features
Supported APIs:
/api/*/sapi/*Spot Websocket Market Stream
Spot User Data Stream
Inclusion of test cases and examples
Customizable base URL, request timeout and HTTP proxy
Response metadata can be displayed
Quick Start
Installation
Install via package name
pip install sidan-binance-py
Using uv (fastest)
uv add sidan-binance-py
From source
git clone https://github.com/sidan-lab/sidan-binance-py.git cd sidan-binance-py uv sync
Usage
RESTful APIs
import logging
from binance.spot import Spot
from binance.lib.utils import config_logging
config_logging(logging, logging.DEBUG)
client = Spot()
logging.info(client.time())
client = Spot(api_key='<api_key>', api_secret='<api_secret>')
# Get account information
logging.info(client.account())
# Post a new order
params = {
'symbol': 'BTCUSDT',
'side': 'SELL',
'type': 'LIMIT',
'timeInForce': 'GTC',
'quantity': 0.002,
'price': 9500
}
response = client.new_order(**params)
logging.info(response)
Please find examples folder to check for more endpoints.
Websocket
import logging
from binance.websocket.spot.websocket_api import SpotWebsocketAPIClient
def on_close(_):
logging.info("Do custom stuff when connection is closed")
def message_handler(message):
print(message)
ws_client = SpotWebsocketAPIClient(on_message=message_handler, on_close=on_close)
ws_client.ticker(
symbol='bnbusdt',
type="FULL",
)
# Combine selected streams
ws_client.ticker(
symbols=["BNBBUSD", "BTCUSDT"],
type="MINI",
windowSize="2h",
)
ws_client.stop()
More websocket examples are available in the examples folder
Contents
- Changelog
- 3.12.0 - 2025-01-09
- 3.11.0 - 2024-12-19
- 3.10.0 - 2024-11-29
- 3.9.0 - 2024-10-02
- 3.8.1 - 2024-07-25
- 3.8.0 - 2024-07-04
- 3.7.0 - 2024-05-03
- 3.6.0 - 2024-03-07
- 3.5.1 - 2023-11-17
- 3.5.0 - 2023-10-26
- 3.4.0 - 2023-10-07
- 3.3.1 - 2023-08-23
- 3.3.0 - 2023-08-07
- 3.2.0 - 2023-08-01
- 3.1.1 - 2023-07-03
- 3.0.0rc2 - 2023-04-21
- 3.0.0rc1 - 2023-02-10
- 2.0.0 - 2023-01-18
- 2.0.0rc2 - 2022-11-29
- 2.0.0-rc1 - 2022-11-29
- 1.18.0 - 2022-09-29
- 1.17.0 - 2022-09-05
- 1.16.0 - 2022-08-11
- 1.15.0 - 2022-07-19
- 1.14.0 - 2022-07-04
- 1.13.0 - 2022-05-23
- 1.12.0 - 2022-05-03
- 1.11.0 - 2022-02-23
- 1.10.0 - 2022-01-11
- 1.9.0 - 2021-12-22
- 1.8.0 - 2021-11-25
- 1.7.0 - 2021-11-04
- 1.6.0 - 2021-09-24
- 1.5.0 - 2021-08-17
- 1.4.0 - 2021-07-30
- 1.3.0 - 2021-07-22
- 1.2.0 - 2021-07-12
- 1.1.1 - 2021-06-24
- 1.1.0 - 2021-06-23
- 1.0.0 - 2021-06-15
- Getting Started
- Spot APIs
- Auto Invest Endpoints
- Get target asset list (USER_DATA)
- Get target asset ROI data (USER_DATA)
- Query all source asset and target asset (USER_DATA)
- Query source asset list (USER_DATA)
- Change Plan Status (TRADE)
- Get list of plans (USER_DATA)
- Query holding details of the plan (USER_DATA)
- Query subscription transaction history (USER_DATA)
- Query Index Details (USER_DATA)
- Query Index Linked Plan Position Details (USER_DATA)
- One Time Transaction (TRADE)
- Query One-Time Transaction Status (USER_DATA)
- Index Linked Plan Redemption (TRADE)
- Index Linked Plan Redemption (USER_DATA)
- Index Linked Plan Rebalance Details (USER_DATA)
- C2C Endpoints
- Convert Endpoints
- Data Stream Endpoints
- Create a ListenKey (USER_STREAM)
- Ping/Keep-alive a ListenKey (USER_STREAM)
- Close a ListenKey (USER_STREAM)
- Create a margin ListenKey (USER_STREAM)
- Renew a margin ListenKey (USER_STREAM)
- Close a margin ListenKey (USER_STREAM)
- Create an isolated margin ListenKey (USER_STREAM)
- Renew an isolated ListenKey (USER_STREAM)
- Close an isolated margin ListenKey (USER_STREAM)
- Fiat Endpoints
- Card Gift Endpoints
- Crypto Loans Endpoints
- Get Crypto Loans Income History (USER_DATA)
- Get Loan Borrow History (USER_DATA)
- Get Loan Repayment History (USER_DATA)
- Get Loan LTV Adjustment History (USER_DATA)
- Get VIP Loan Ongoing Orders (USER_DATA)
- VIP Loan Repay (TRADE)
- Get VIP Loan Repayment History (USER_DATA)
- Check Locked Value of VIP Collateral Account (USER_DATA)
- Get Loanable Assets Data (USER_DATA)
- Margin Endpoints
- Margin Account Borrow/Repay (MARGIN)
- Get All Margin Assets (MARKET_DATA)
- Get All Margin Pairs (MARKET_DATA)
- Query Margin PriceIndex (MARKET_DATA)
- Margin Account New Order (TRADE)
- Margin Account Cancel Order (TRADE)
- Get Transfer History (USER_DATA)
- Query borrow/repay records in Margin account (USER_DATA)
- Get Interest History (USER_DATA)
- Get Force Liquidation Record (USER_DATA)
- Query Cross Margin Account Details (USER_DATA)
- Query Margin Account’s Order (USER_DATA)
- Query Margin Account’s Open Order (USER_DATA)
- Margin Account Cancel all Open Orders on a Symbol (USER_DATA)
- Query Margin Account’s All Orders (USER_DATA)
- Query Margin Account’s Trade List (USER_DATA)
- Query Max Borrow (USER_DATA)
- Query Max Transfer-Out Amount (USER_DATA)
- Query Isolated Margin Account Info (USER_DATA)
- Get All Isolated Margin Symbol(USER_DATA)
- Toggle BNB Burn On Spot Trade And Margin Interest (USER_DATA)
- Get BNB Burn Status (USER_DATA)
- Get Margin Interest Rate History (USER_DATA)
- Margin Account New OCO (TRADE)
- Margin Account Cancel OCO (TRADE)
- Query Margin Account’s OCO (USER_DATA)
- Query Margin Account’s all OCO (USER_DATA)
- Query Margin Account’s Open OCO (USER_DATA)
- Disable Isolated Margin Account (TRADE)
- Enable Isolated Margin Account (TRADE)
- Query Enabled Isolated Margin Account Limit (USER_DATA)
- Query Cross Margin Fee Data (USER_DATA)
- Query Isolated Margin Fee Data (USER_DATA)
- Query Isolated Margin Tier Data (USER_DATA)
- Query Current Margin Order Count Usage (TRADE)
- Get Summary of Margin account (USER_DATA)
- Cross margin collateral ratio (MARKET_DATA)
- Get Small Liability Exchange Coin List (USER_DATA)
- Get Small Liability Exchange History (USER_DATA)
- Get a future hourly interest rate (USER_DATA)
- Adjust cross margin max leverage (USER_DATA)
- Query Margin Available Inventory (USER_DATA)
- Margin manual liquidation (MARGIN)
- Margin Account New OTO (TRADE)
- Margin Account New OTOCO (TRADE)
- Query Liability Coin Leverage Bracket in Cross Margin Pro Mode(MARKET_DATA)
- Market Endpoints
- Test Connectivity
- Check Server Time
- Exchange Information
- Get orderbook
- Recent Trades List
- Old Trade Lookup
- Compressed/Aggregate Trades List
- Kline/Candlestick Data
- UIKlines
- Current Average Price
- 24hr Ticker Price Change Statistics
- Trading Day Ticker
- Symbol Price Ticker
- Symbol Order Book Ticker
- Rolling window price change statistics
- Mining Endpoints
- Acquiring Algorithm (MARKET_DATA)
- Acquiring CoinName (MARKET_DATA)
- Request for Detail Miner List (USER_DATA)
- Request for Miner List (USER_DATA)
- Revenue List (USER_DATA)
- Extra Bonus List (USER_DATA)
- Statistic List (USER_DATA)
- Account List (USER_DATA)
- Hashrate Resale Request (USER_DATA)
- Cancel hashrate resale configuration(USER_DATA)
- Hashrate Resale List (USER_DATA)
- Hashrate Resale Detail (USER_DATA)
- Mining Account Earning (USER_DATA)
- NFT Endpoints
- Pay Endpoints
- Portfolio Margin Endpoints
- Portfolio Margin Account (USER_DATA)
- Portfolio Margin Collateral Rate (MARKET_DATA)
- Portfolio Margin Pro Tiered Collateral Rate (USER_DATA)
- Portfolio Margin Bankruptcy Loan Amount (USER_DATA)
- Portfolio Margin Bankruptcy Loan Repay (USER_DATA)
- Query Classic Portfolio Margin Negative Balance Interest History (USER_DATA)
- Get Portfolio Margin Pro SPAN Account Info (USER_DATA)
- Get Portfolio Margin Pro Account Balance (USER_DATA)
- Query Portfolio Margin Asset Index Price (MARKET_DATA)
- Fund Auto-collection (USER_DATA)
- BNB Transfer (USER_DATA)
- Change Auto-repay-futures Status (USER_DATA)
- Get Auto-repay-futures Status (USER_DATA)
- Repay futures Negative Balance (USER_DATA)
- Fund Collection by Asset (USER_DATA)
- Rebate Endpoints
- Staking Endpoints
- ETH Staking account (USER_DATA)
- Get current ETH staking quota (USER_DATA)
- Subscribe ETH Staking (TRADE)
- Redeem ETH (TRADE)
- Wrap BETH (TRADE)
- Get ETH staking history (USER_DATA)
- Get ETH redemption history (USER_DATA)
- Get BETH rewards distribution history (USER_DATA) (USER_DATA)
- Get WBETH rewards history (USER_DATA)
- Get WBETH Rate History (USER_DATA)
- Get WBETH wrap history (USER_DATA)
- Get WBETH unwrap history (USER_DATA)
- Sub Account Endpoints
- Create a Virtual Sub-account (For Master Account)
- Query Sub-account List (For Master Account)
- Query Sub-account Assets (For Master Account)
- Get Sub-account Deposit Address (For Master Account)
- Get Sub-account Deposit History (For Master Account)
- Get Sub-account’s Status on Margin/Futures(For Master Account)
- Enable Margin for Sub-account (For Master Account)
- Get Detail on Sub-account’s Margin Account (For Master Account)
- Get Summary of Sub-account’s Margin Account (For Master Account)
- Enable Futures for Sub-account (For Master Account)
- Futures Transfer for Sub-account (For Master Account)
- Margin Transfer for Sub-account (For Master Account)
- Transfer to Sub-account of Same Master (For Sub-account)
- Transfer to Master (For Sub-account)
- Sub-account Transfer History (For Sub-account)
- Query Sub-account Futures Asset Transfer History (For Master Account)
- Query Sub-account Futures Asset Transfer History (For Master Account)
- Query Sub-account Spot Assets Summary (For Master Account)
- Universal Transfer (For Master Account)
- Query Universal Transfer History (For Master Account)
- Get Detail on Sub-account’s Futures Account V2 (For Master Account)
- Get Summary of Sub-account’s Futures Account V2 (For Master Account)
- Get Futures Position-Risk of Sub-account V2 (For Master Account)
- Query Sub-account Spot Asset Transfer History (SAPI For Master Account)
- Enable Leverage Token for Sub-account (For Master Account)
- Deposit assets into the managed sub-account (For Investor Master Account)
- Query managed sub-account asset details (For Investor Master Account)
- Withdrawl assets from the managed sub-account (For Investor Master Account)
- Update IP Restriction for Sub-Account API key (For Master Account)
- Get IP Restriction for a Sub-account API Key (For Master Account)
- Delete IP List for a Sub-account API Key (For Master Account)
- Query Managed Sub-account Snapshot (For Investor Master Account)
- Query Managed Sub Account Transfer Log (Investor) (USER_DATA)
- Query Managed Sub Account Transfer Log (Trading Team) (USER_DATA)
- Get Managed Sub-account Deposit Address (For Investor Master Account) (USER_DATA)
- Query Sub-account Assets (For Master Account)
- Enable Options for Sub-account (For Master Account)
- Query Sub-account Transaction Statistics (For Master Account)
- Query Managed Sub-account Margin Asset Details (For Investor Master Account)
- Query Managed Sub-account List (For Investor)
- Query Managed Sub-account Futures Asset Details (For Investor Master Account)
- Futures Position-Risk of Sub-account (For Master Account)
- Summary of Sub-account’s Futures Account V2 (For Master Account)
- Detail on Sub-account’s Futures Account (For Master Account)
- Query Managed Sub Account Transfer Log (For Trading Team Sub Account)(USER_DATA)
- Account / Trade Endpoints
- Test New Order (TRADE)
- New Order (TRADE)
- Cancel Order (TRADE)
- Cancel all Open Orders on a Symbol (TRADE)
- Query Order (USER_DATA)
- Cancel an Existing Order and Send a New Order (USER_DATA)
- Current Open Orders (USER_DATA)
- All Orders (USER_DATA)
- New OCO (TRADE)
- Cancel OCO (TRADE)
- Query OCO (USER_DATA)
- Query all OCO (USER_DATA)
- Query Open OCO (USER_DATA)
- Account Information (USER_DATA)
- Account Trade List (USER_DATA)
- Query Current Order Count Usage (TRADE)
- Query Prevented Matches (USER_DATA)
- Query Cross-Collateral Information (USER_DATA)
- Query Commission Rates (USER_DATA)
- Wallet Endpoints
- System Status (System)
- All Coins’ Information (USER_DATA)
- Daily Account Snapshot (USER_DATA)
- Disable Fast Withdraw Switch (USER_DATA)
- Enable Fast Withdraw Switch (USER_DATA)
- Withdraw (USER_DATA)
- Deposit History (supporting network) (USER_DATA)
- Withdraw History (supporting network) (USER_DATA)
- Deposit Address (supporting network) (USER_DATA)
- Account Status (USER_DATA)
- Account API Trading Status (USER_DATA)
- DustLog (USER_DATA)
- User Universal Transfer
- Query User Universal Transfer History
- Dust Transfer (USER_DATA)
- Asset Dividend Record (USER_DATA)
- Asset Detail (USER_DATA)
- Trade Fee (USER_DATA)
- Funding Wallet (USER_DATA)
- User Asset (USER_DATA)
- API Key Permission (USER_DATA)
- Withdraw (for local entities that require travel rule) (USER_DATA)
- Withdraw History (for local entities that require travel rule) (supporting network) (USER_DATA)
- Submit Deposit Questionnaire (For local entities that require travel rule) (supporting network) (USER_DATA)
- Deposit History (for local entities that required travel rule) (supporting network) (USER_DATA)
- Get Assets That Can Be Converted Into BNB (USER_DATA)
- Get Cloud-Mining payment and refund history (USER_DATA)
- One click arrival deposit apply (USER_DATA)
- Query User Wallet Balance (USER_DATA)
- Get symbols delist schedule for spot (MARKET_DATA)
- Simple Earn Endpoints
- Get Simple Earn Flexible Product List (USER_DATA)
- Get Simple Earn Locked Product List (USER_DATA)
- Subscribe Flexible Product (TRADE)
- Subscribe Locked Product (TRADE)
- Redeem Flexible Product (TRADE)
- Redeem Locked Product (TRADE)
- Get Flexible Product Position (USER_DATA)
- Get Locked Product Position (USER_DATA)
- Simple Account (USER_DATA)
- Get Flexible Subscription Record (USER_DATA)
- Get Locked Subscription Record (USER_DATA)
- Get Flexible Redemption Record (USER_DATA)
- Get Locked Redemption Record (USER_DATA)
- Get Flexible Rewards History (USER_DATA)
- Get Locked Rewards History (USER_DATA)
- Set Flexible Auto Subscribe (USER_DATA)
- Set Locked Auto Subscribe (USER_DATA)
- Get Flexible Personal Left Quota (USER_DATA)
- Get Locked Personal Left Quota (USER_DATA)
- Get Flexible Subscription Preview (USER_DATA)
- Get Locked Subscription Preview (USER_DATA)
- Set Locked Product Redeem Option (USER_DATA)
- Get Rate History (USER_DATA)
- Get Collateral Record (USER_DATA)
- Auto Invest Endpoints
- Spot Websocket Streams
- Aggregate Trade Streams
- Trade Streams
- Kline/Candlestick Streams
- Kline/Candlestick Streams with timezone offset
- Individual symbol or all symbols mini ticker
- Individual symbol or all symbols ticker
- Individual symbol or all book ticker
- Individual Symbol Rolling Window Statistics Streams
- All Market Rolling Window Statistics Streams
- Partial Book Depth Streams
- Diff. Depth Stream
- Listen to user data by provided listenkey
- Spot Websocket API
- Test connectivity to the WebSocket API
- Check server time
- Get exchange information
- Get order book
- Get historical trades
- Get compressed, aggregate trades
- klines
- Klines/candlesticks for UI
- Current average price for a symbol
- 24hr ticker price change statistics
- Rolling window price change statistics
- Symbol price ticker
- Symbol order book ticker
- Account information
- Account order rate limits
- Account order history
- Account OCO history
- Account trade history
- Account prevented matches
- Create a new order
- Test new order
- Get order
- Cancel order
- Cancel and replace order
- Current open orders
- Cancel all open orders on a symbol
- Place a new OCO Order
- Get OCO order
- Cancel OCO order
- Get all OCO orders
- Start user data stream
- Ping user data stream
- Stop user data stream