CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-python-binance

Unofficial Python wrapper for the Binance cryptocurrency exchange REST API v3 and WebSocket APIs with comprehensive trading, market data, and account management functionality

Pending
Overview
Eval results
Files

account.mddocs/

Account Management

Account information, balance management, trade history, and API permissions. Includes wallet operations, asset transfers, and comprehensive account status monitoring.

Capabilities

Account Information

Get comprehensive account details including balances, trading status, and permissions.

def get_account(self, **params): ...
def get_asset_balance(self, asset=None, **params): ...
def get_account_status(self, version=1, **params): ...
def get_account_api_trading_status(self, **params): ...
def get_account_api_permissions(self, **params): ...

Usage Examples

# Get complete account information
account = client.get_account()

# Extract balances with non-zero amounts
balances = {b['asset']: {'free': b['free'], 'locked': b['locked']} 
           for b in account['balances'] if float(b['free']) > 0 or float(b['locked']) > 0}

print(f"Account type: {account['accountType']}")
print(f"Can trade: {account['canTrade']}")
print(f"Can withdraw: {account['canWithdraw']}")
print(f"Can deposit: {account['canDeposit']}")
print(f"Balances: {balances}")

# Get specific asset balance
btc_balance = client.get_asset_balance(asset='BTC')
if btc_balance:
    print(f"BTC Balance - Free: {btc_balance['free']}, Locked: {btc_balance['locked']}")

# Check account status
status = client.get_account_status()
print(f"Account status: {status['data']}")  # "Normal" or other status

# Get API trading status
api_status = client.get_account_api_trading_status()
print(f"API trading enabled: {api_status['data']['isLocked'] == False}")

# Get API permissions
permissions = client.get_account_api_permissions()
print(f"Permissions: {permissions['data']}")
# Shows: ipRestrict, createTime, enableWithdrawals, enableInternalTransfer, 
#        permitsUniversalTransfer, enableVanillaOptions, enableReading, 
#        enableFutures, enableMargin, enableSpotAndMarginTrading

Trading History

Access trade history and order information.

def get_my_trades(self, **params): ...
def get_all_orders(self, **params): ...
def get_open_orders(self, **params): ...

Usage Examples

# Get recent trades for specific symbol
trades = client.get_my_trades(symbol='BTCUSDT', limit=100)

for trade in trades:
    print(f"Trade ID: {trade['id']}")
    print(f"Price: {trade['price']}, Qty: {trade['qty']}")
    print(f"Commission: {trade['commission']} {trade['commissionAsset']}")
    print(f"Time: {trade['time']}")
    print(f"Is buyer: {trade['isBuyer']}, Is maker: {trade['isMaker']}")

# Get trades within date range
import time
end_time = int(time.time() * 1000)
start_time = end_time - (7 * 24 * 60 * 60 * 1000)  # 7 days ago

recent_trades = client.get_my_trades(
    symbol='BTCUSDT',
    startTime=start_time,
    endTime=end_time
)

# Get all historical orders
all_orders = client.get_all_orders(symbol='BTCUSDT', limit=500)

# Filter by order status
filled_orders = [o for o in all_orders if o['status'] == 'FILLED']
print(f"Total filled orders: {len(filled_orders)}")

Dust Operations

Manage small balance amounts (dust) that are too small to trade.

def get_dust_assets(self, **params): ...
def get_dust_log(self, **params): ...
def transfer_dust(self, **params): ...

Usage Examples

# Get dust assets (small balances)
dust_assets = client.get_dust_assets()
print(f"Dust assets: {dust_assets['details']}")

# Get dust conversion history
dust_log = client.get_dust_log()
for entry in dust_log['userAssetDribblets']:
    print(f"Converted on {entry['operateTime']}: {entry['totalTransferedAmount']} BNB")

# Convert dust to BNB
dust_result = client.transfer_dust(asset=['ADA', 'XRP', 'DOT'])
print(f"Dust transfer result: {dust_result}")

Asset Dividends and Distribution

Track dividend payments and asset distributions.

def get_asset_dividend_history(self, **params): ...

Usage Examples

# Get dividend payment history
dividends = client.get_asset_dividend_history(limit=100)

for dividend in dividends['rows']:
    print(f"Asset: {dividend['asset']}")
    print(f"Amount: {dividend['amount']}")
    print(f"Dividend time: {dividend['divTime']}")
    print(f"Transaction ID: {dividend['tranId']}")

Wallet Operations

Deposit and withdrawal operations and history.

def get_deposit_history(self, **params): ...
def get_withdraw_history(self, **params): ...
def get_deposit_address(self, **params): ...
def withdraw(self, **params): ...

Usage Examples

# Get deposit history
deposits = client.get_deposit_history(coin='BTC', limit=100)

for deposit in deposits:
    print(f"Amount: {deposit['amount']} {deposit['coin']}")
    print(f"Status: {deposit['status']}")  # 0: pending, 6: credited, 1: success
    print(f"Network: {deposit['network']}")
    print(f"TxId: {deposit['txId']}")

# Get withdrawal history
withdrawals = client.get_withdraw_history(coin='BTC', limit=100)

for withdrawal in withdrawals:
    print(f"Amount: {withdrawal['amount']} {withdrawal['coin']}")
    print(f"Status: {withdrawal['status']}")
    print(f"Network: {withdrawal['network']}")
    print(f"TxId: {withdrawal['txId']}")

# Get deposit address
deposit_addr = client.get_deposit_address(coin='BTC', network='BTC')
print(f"BTC deposit address: {deposit_addr['address']}")
print(f"Tag: {deposit_addr.get('tag', 'None')}")

# Withdraw (requires withdrawal permissions)
withdraw_result = client.withdraw(
    coin='BTC',
    address='bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
    amount=0.001,
    network='BTC'
)
print(f"Withdrawal ID: {withdraw_result['id']}")

Universal Transfer

Transfer assets between different Binance account types.

def universal_transfer(self, **params): ...
def get_universal_transfer_history(self, **params): ...

Usage Examples

# Transfer from spot to futures account
transfer_result = client.universal_transfer(
    type='MAIN_UMFUTURE',  # Main account to USD-M Futures
    asset='USDT',
    amount=100.0
)
print(f"Transfer ID: {transfer_result['tranId']}")

# Get transfer history
transfer_history = client.get_universal_transfer_history(
    type='MAIN_UMFUTURE',
    limit=100
)

for transfer in transfer_history['rows']:
    print(f"Amount: {transfer['amount']} {transfer['asset']}")
    print(f"Status: {transfer['status']}")
    print(f"Time: {transfer['timestamp']}")

Funding Wallet

Operations for the funding wallet.

def funding_wallet(self, **params): ...
def get_user_asset(self, **params): ...

Usage Examples

# Get funding wallet balance
funding_balance = client.funding_wallet()
for balance in funding_balance:
    if float(balance['free']) > 0:
        print(f"{balance['asset']}: {balance['free']}")

# Get user asset information
user_assets = client.get_user_asset()
for asset in user_assets:
    if float(asset['free']) > 0:
        print(f"{asset['asset']}: Free={asset['free']}, Locked={asset['locked']}, Freeze={asset['freeze']}, Withdrawing={asset['withdrawing']}")

API Key Management

Monitor API key usage and restrictions.

def get_account_api_trading_status(self, **params): ...
def get_account_api_permissions(self, **params): ...

Usage Examples

# Check if API key is restricted
api_status = client.get_account_api_trading_status()
data = api_status['data']

print(f"API locked: {data['isLocked']}")
print(f"Planned recover time: {data['plannedRecoverTime']}")

if data['triggerCondition']:
    print(f"Trigger conditions: {data['triggerCondition']}")

# Get detailed API permissions
permissions = client.get_account_api_permissions()
perms = permissions['data']

print(f"IP restrict: {perms['ipRestrict']}")
print(f"Created: {perms['createTime']}")
print(f"Enable withdrawals: {perms['enableWithdrawals']}")
print(f"Enable reading: {perms['enableReading']}")
print(f"Enable spot trading: {perms['enableSpotAndMarginTrading']}")
print(f"Enable futures: {perms['enableFutures']}")
print(f"Enable margin: {perms['enableMargin']}")
print(f"Enable options: {perms['enableVanillaOptions']}")

Rate Limiting Information

Monitor current rate limit usage.

def get_current_order_count(self, **params): ...

Usage Examples

# Check current order count and rate limits
order_count = client.get_current_order_count()

for limit in order_count:
    print(f"Rate limit type: {limit['rateLimitType']}")
    print(f"Interval: {limit['intervalNum']} {limit['interval']}")
    print(f"Usage: {limit['count']}/{limit['limit']}")

Account Allocations

Get allocation information for trades.

def get_allocations(self, **params): ...

Usage Examples

# Get recent allocations
allocations = client.get_allocations(symbol='BTCUSDT', limit=100)

for allocation in allocations['allocations']:
    print(f"Symbol: {allocation['symbol']}")
    print(f"Allocation ID: {allocation['allocationId']}")
    print(f"Type: {allocation['allocationType']}")
    print(f"Quantity: {allocation['qty']}")
    print(f"Quote quantity: {allocation['quoteQty']}")

This comprehensive account management functionality provides complete control over account information, balances, trading history, and wallet operations across all Binance account types.

Install with Tessl CLI

npx tessl i tessl/pypi-python-binance

docs

account.md

convert-api.md

depth-cache.md

futures.md

index.md

margin.md

market-data.md

rest-clients.md

staking-mining.md

trading.md

websockets.md

tile.json