Skip to content

bie202512-droid/bie-python-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BIE Python SDK

Official Python SDK for interacting with the BIE Network.

Installation

pip install bie-sdk

Or install from source:

git clone https://github.com/bie202512-droid/bie-python-sdk.git
cd bie-python-sdk
pip install -e .

Quick Start

from bie_sdk import BieClient

# Initialize client
client = BieClient("https://rpc.bie.ai")

# Get latest block
block = client.get_latest_block()
print(f"Latest block: {block}")

# Get account balance
balance = client.get_balance("0x...")
print(f"Balance: {balance}")

Features

Account Operations

# Create account
client.create_account(address, initial_balance="0")

# Get balance
client.get_balance(address)

# Get account info
client.get_account(address)

# Transfer
client.transfer(from_addr, to_addr, amount, signature, public_key)

Spot Trading (Order Book)

# Create order
client.create_order({
    "trader": "0x...",
    "base": "BTC",
    "quote": "USDT",
    "side": "buy",
    "price": "50000",
    "quantity": "0.1",
    "order_type": "limit"
})

# Cancel order
client.cancel_order(order_id, trader)

# Get order book depth
depth = client.get_orderbook("BTC", "USDT", depth=20)

# Get recent trades
trades = client.get_trades("BTC", "USDT", limit=50)

Derivatives (Perpetuals)

# Update margin
client.update_margin(trader, amount)

# Open position
client.open_position({
    "trader": "0x...",
    "symbol": "BTC-PERP",
    "side": "long",
    "size": "0.1",
    "leverage": 10,
    "price": "50000"
})

# Close position
client.close_position(trader, position_id, price)

# Get position
position = client.get_position(position_id)

# Get all positions
positions = client.get_positions(trader)

# Get margin account
margin = client.get_margin_account(trader)

Oracle

# Submit price (for oracles)
client.submit_price(symbol, price, oracle, signature)

# Get current price
price = client.get_price("BTC")

Blocks & Transactions

# Get block by height
block = client.get_block(12345)

# Get latest block
latest = client.get_latest_block()

WebSocket Subscriptions

def on_price_update(data):
    print(f"Price update: {data}")

# Subscribe to price feeds
client.subscribe_prices(on_price_update)

Configuration

Environment Variables

export BIE_API_URL="https://rpc.bie.ai"

Custom Endpoint

client = BieClient("https://custom-rpc.example.com")

API Reference

BieClient

Method Description
create_account(address, initial_balance) Create new account
get_balance(address) Get BIE balance
get_account(address) Get account details
transfer(from, to, amount, sig, pubkey) Transfer BIE
create_order(payload) Place order
cancel_order(order_id, trader) Cancel order
get_orderbook(base, quote, depth) Get order book
get_trades(base, quote, limit) Get recent trades
update_margin(trader, amount) Update margin
open_position(payload) Open perpetual position
close_position(trader, id, price) Close position
get_position(position_id) Get position
get_positions(trader) Get all positions
get_margin_account(trader) Get margin account
submit_price(symbol, price, oracle, sig) Submit oracle price
get_price(symbol) Get oracle price
get_block(height) Get block by height
get_latest_block() Get latest block
subscribe_prices(callback) Subscribe to prices

Requirements

  • Python 3.8+
  • requests
  • websocket-client (optional, for subscriptions)

Examples

See the examples directory for more usage examples.

Network Information

Network Chain ID RPC Endpoint
Mainnet 1342 https://rpc.bie.ai
Testnet 13420 https://testnet-rpc.bie.ai

Contributing

Contributions are welcome! Please read our contributing guidelines first.

License

MIT

Links

About

Official Python SDK for the BIE Network

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages