MarketDataClient
The MarketDataClient provides access to prices, order books, and real-time streaming.
Getting Prices
prices = await client.market_data.get_prices(["BTC", "ETH"])
price = await client.market_data.get_price("BTC")
print(f"BTC: {price.mid} (spread: {price.spread_bps:.1f} bps)")
Order Books
orderbook = await client.market_data.get_orderbook("BTC", depth=10)
print(f"Best bid: {orderbook.best_bid.price}")
print(f"Best ask: {orderbook.best_ask.price}")
print(f"Spread: {orderbook.spread}")
Real-Time Prices
async def on_price(price):
print(f"{price.asset}: {price.mid}")
await client.market_data.subscribe_prices(["BTC", "ETH"], on_price)
Real-Time Order Book
async def on_orderbook(ob):
print(f"Best bid: {ob.best_bid.price}")
await client.market_data.subscribe_orderbook("BTC", on_orderbook)