Unofficial Python wrapper for the Binance cryptocurrency exchange REST API v3 and WebSocket APIs with comprehensive trading, market data, and account management functionality
—
Comprehensive staking and mining functionality including DeFi staking, ETH/SOL staking, locked staking products, and mining operations. Provides access to staking rewards, mining statistics, and portfolio management across various blockchain networks.
Core staking functionality for various staking products and services.
def get_staking_product_list(self, **params): ...
def purchase_staking_product(self, **params): ...
def redeem_staking_product(self, **params): ...
def get_staking_position(self, **params): ...
def get_staking_purchase_history(self, **params): ...
def set_auto_staking(self, **params): ...# Get available staking products
staking_products = client.get_staking_product_list(
product='STAKING', # STAKING, F_DEFI, L_DEFI
current=1,
size=20
)
for product in staking_products:
print(f"Product ID: {product['productId']}")
print(f"Asset: {product['asset']}")
print(f"APY: {product['apy']}%")
print(f"Duration: {product['duration']} days")
print(f"Min purchase amount: {product['minPurchaseAmount']}")
print(f"Can purchase: {product['canPurchase']}")
# Purchase a staking product
purchase = client.purchase_staking_product(
product='STAKING',
productId='product_123',
amount=100,
renewable=True # Auto-renew when expired
)
print(f"Purchase ID: {purchase['purchaseId']}")
print(f"Status: {purchase['status']}")
# Get current staking positions
positions = client.get_staking_position(
product='STAKING', # STAKING, F_DEFI, L_DEFI
current=1,
size=50
)
for position in positions:
print(f"Position ID: {position['positionId']}")
print(f"Asset: {position['asset']}")
print(f"Amount: {position['amount']}")
print(f"APY: {position['apy']}%")
print(f"Status: {position['status']}")
print(f"Purchase time: {position['purchaseTime']}")
print(f"Accrual days: {position['accrualDays']}")
# Redeem a staking position
redemption = client.redeem_staking_product(
product='STAKING',
positionId=position['positionId'],
amount=50 # Partial redemption
)
# Get purchase history
history = client.get_staking_purchase_history(
product='STAKING',
current=1,
size=20
)
# Set auto-staking for renewals
auto_staking = client.set_auto_staking(
product='L_DEFI', # Locked DeFi
positionId='position_456',
renewable=True
)Specialized staking operations for US users with different product offerings.
def get_staking_asset_us(self, **params): ...
def get_staking_balance_us(self, **params): ...
def get_staking_history_us(self, **params): ...
def get_staking_rewards_history_us(self, **params): ...# Get US staking assets
us_assets = client.get_staking_asset_us()
for asset in us_assets:
print(f"Asset: {asset['asset']}")
print(f"APY range: {asset['minApy']}% - {asset['maxApy']}%")
print(f"Available for staking: {asset['canStake']}")
# Get US staking balances
us_balances = client.get_staking_balance_us()
total_value = 0
for balance in us_balances:
print(f"Asset: {balance['asset']}")
print(f"Staked amount: {balance['amount']}")
print(f"USD value: ${balance['usdValue']}")
total_value += float(balance['usdValue'])
print(f"Total staking value: ${total_value:.2f}")
# Get US staking history
us_history = client.get_staking_history_us(
product='STAKING',
txnType='SUBSCRIPTION', # SUBSCRIPTION, REDEMPTION
current=1,
size=20
)
# Get US staking rewards history
us_rewards = client.get_staking_rewards_history_us(
asset='USDT',
current=1,
size=100
)
for reward in us_rewards:
print(f"Asset: {reward['asset']}")
print(f"Amount: {reward['amount']}")
print(f"Time: {reward['time']}")
print(f"Type: {reward['type']}")Ethereum-specific staking functionality including ETH 2.0 staking and WBETH operations.
def margin_v2_get_eth_staking_account(self, **params): ...
def margin_v2_post_eth_staking_eth_stake(self, **params): ...
def margin_v1_post_eth_staking_eth_redeem(self, **params): ...
def margin_v1_post_eth_staking_wbeth_wrap(self, **params): ...
def margin_v1_post_eth_staking_wbeth_unwrap(self, **params): ...
def margin_v1_get_eth_staking_eth_history_staking_history(self, **params): ...
def margin_v1_get_eth_staking_eth_history_redemption_history(self, **params): ...
def margin_v1_get_eth_staking_eth_history_wbeth_rewards_history(self, **params): ...# Get ETH staking account information
eth_account = client.margin_v2_get_eth_staking_account()
print(f"Total ETH staked: {eth_account['totalAmount']}")
print(f"WBETH balance: {eth_account['wbethAmount']}")
print(f"Estimated APR: {eth_account['estimatedApr']}%")
print(f"Last reward distribution: {eth_account['lastRewardDistribution']}")
# Stake ETH
eth_stake = client.margin_v2_post_eth_staking_eth_stake(
amount=1.0 # Stake 1 ETH
)
print(f"Staking success: {eth_stake['success']}")
print(f"WBETH received: {eth_stake['wbethAmount']}")
# Redeem ETH from staking
eth_redeem = client.margin_v1_post_eth_staking_eth_redeem(
amount=0.5, # Redeem 0.5 ETH worth
type=1 # 1: fast redemption (with fee), 0: slow redemption
)
# Wrap ETH to WBETH
wbeth_wrap = client.margin_v1_post_eth_staking_wbeth_wrap(
amount=0.1
)
# Unwrap WBETH to ETH
wbeth_unwrap = client.margin_v1_post_eth_staking_wbeth_unwrap(
amount=0.1
)
# Get ETH staking history
eth_history = client.margin_v1_get_eth_staking_eth_history_staking_history(
current=1,
size=50
)
for record in eth_history['rows']:
print(f"Time: {record['time']}")
print(f"ETH amount: {record['amount']}")
print(f"WBETH received: {record['wbethAmount']}")
print(f"Status: {record['status']}")
# Get WBETH rewards history
wbeth_rewards = client.margin_v1_get_eth_staking_eth_history_wbeth_rewards_history(
current=1,
size=100
)
for reward in wbeth_rewards['rows']:
print(f"Date: {reward['time']}")
print(f"Holding amount: {reward['holdingAmount']}")
print(f"Annualized rate: {reward['annualizedRate']}%")
print(f"Rewards: {reward['rewards']}")Solana-specific staking functionality including BNSOL rewards and validator staking.
def margin_v1_get_sol_staking_account(self, **params): ...
def margin_v1_post_sol_staking_sol_stake(self, **params): ...
def margin_v1_post_sol_staking_sol_redeem(self, **params): ...
def margin_v1_post_sol_staking_sol_claim(self, **params): ...
def margin_v1_get_sol_staking_sol_quota(self, **params): ...
def margin_v1_get_sol_staking_sol_history_staking_history(self, **params): ...
def margin_v1_get_sol_staking_sol_history_redemption_history(self, **params): ...
def margin_v1_get_sol_staking_sol_history_bnsol_rewards_history(self, **params): ...
def margin_v1_get_sol_staking_sol_history_boost_rewards_history(self, **params): ...
def margin_v1_get_sol_staking_sol_history_unclaimed_rewards(self, **params): ...
def margin_v1_get_sol_staking_sol_history_rate_history(self, **params): ...# Get SOL staking account information
sol_account = client.margin_v1_get_sol_staking_account()
print(f"Total SOL staked: {sol_account['totalAmountInSOL']}")
print(f"BNSOL balance: {sol_account['bnsolAmount']}")
print(f"Unclaimed rewards: {sol_account['unclaimedRewards']}")
print(f"Estimated APR: {sol_account['estimatedApr']}%")
# Stake SOL
sol_stake = client.margin_v1_post_sol_staking_sol_stake(
amount=10.0 # Stake 10 SOL
)
print(f"Staking transaction ID: {sol_stake['transactionId']}")
print(f"BNSOL received: {sol_stake['bnsolAmount']}")
# Check SOL staking quota
sol_quota = client.margin_v1_get_sol_staking_sol_quota()
print(f"Available quota: {sol_quota['leftQuota']} SOL")
print(f"Minimum stake: {sol_quota['minAmount']} SOL")
# Redeem SOL from staking
sol_redeem = client.margin_v1_post_sol_staking_sol_redeem(
amount=5.0, # Redeem 5 SOL worth
type=1 # 1: fast redemption, 0: slow redemption
)
# Claim SOL staking rewards
claim_rewards = client.margin_v1_post_sol_staking_sol_claim()
print(f"Claimed amount: {claim_rewards['amount']}")
# Get SOL staking history
sol_history = client.margin_v1_get_sol_staking_sol_history_staking_history(
current=1,
size=50
)
# Get BNSOL rewards history
bnsol_rewards = client.margin_v1_get_sol_staking_sol_history_bnsol_rewards_history(
current=1,
size=100
)
for reward in bnsol_rewards['rows']:
print(f"Date: {reward['time']}")
print(f"Holding: {reward['bnsolHolding']} BNSOL")
print(f"Rewards: {reward['bnsolRewards']} BNSOL")
# Get boost rewards history
boost_rewards = client.margin_v1_get_sol_staking_sol_history_boost_rewards_history(
current=1,
size=100
)
# Get rate history
rate_history = client.margin_v1_get_sol_staking_sol_history_rate_history(
current=1,
size=30
)
for rate in rate_history['rows']:
print(f"Date: {rate['time']}")
print(f"Exchange rate: {rate['exchangeRate']}")
print(f"Annualized rate: {rate['annualizedRate']}%")Cross-platform staking record management.
def margin_v1_get_staking_staking_record(self, **params): ...# Get comprehensive staking records
staking_records = client.margin_v1_get_staking_staking_record(
product='ETH', # ETH, SOL, or other supported assets
current=1,
size=100
)
for record in staking_records['rows']:
print(f"Asset: {record['asset']}")
print(f"Amount: {record['amount']}")
print(f"Status: {record['status']}")
print(f"APR: {record['apr']}%")
print(f"Time: {record['time']}")
print(f"Type: {record['type']}") # STAKE, REDEEM, REWARDS# Staking product types
STAKING_PRODUCT_LOCKED = "STAKING" # Locked staking
STAKING_PRODUCT_DEFI_FLEXIBLE = "F_DEFI" # Flexible DeFi
STAKING_PRODUCT_DEFI_LOCKED = "L_DEFI" # Locked DeFi
# Staking transaction types
STAKING_TXN_SUBSCRIPTION = "SUBSCRIPTION"
STAKING_TXN_REDEMPTION = "REDEMPTION"
STAKING_TXN_INTEREST = "INTEREST"
# Staking status values
STAKING_STATUS_HOLDING = "HOLDING"
STAKING_STATUS_REDEEMED = "REDEEMED"
STAKING_STATUS_REWARDING = "REWARDING"from binance import BinanceAPIException
try:
# Attempt to stake
stake_result = client.purchase_staking_product(
product='STAKING',
productId='product_123',
amount=100
)
except BinanceAPIException as e:
if e.code == -3020:
print("Insufficient balance for staking")
elif e.code == -3021:
print("Staking product not available")
elif e.code == -3022:
print("Amount below minimum staking requirement")
else:
print(f"Staking error: {e.message}")Staking operations are subject to specific rate limits:
The Staking and Mining API provides comprehensive access to Binance's staking ecosystem with support for multiple blockchain networks, flexible and locked products, and detailed reward tracking across all supported assets.
Install with Tessl CLI
npx tessl i tessl/pypi-python-binance