Market data#
All market-data calls take the symbol as a string ("BTCUSDT") and work on a trader created for the market type you need. See Symbols and markets.
Current price#
let price: f64 = trader.get_current_price("BTCUSDT").await?;
Required on every adapter.
Ticker#
let t = trader.get_ticker("BTCUSDT").await?;
println!("last {} bid {:?} ask {:?}", t.last_price, t.bid_price, t.ask_price);
println!("funding {:?} next {:?}", t.funding_rate, t.next_funding_time);
println!("OI {:?} mark {:?} index {:?}", t.open_interest, t.mark_price, t.index_price);
TickerInfo fields:
| Field | Type | Notes |
|---|---|---|
symbol |
String |
|
last_price |
f64 |
|
bid_price, ask_price |
Option<f64> |
|
high_24h, low_24h |
Option<f64> |
|
volume_24h |
Option<f64> |
Base currency. |
turnover_24h |
Option<f64> |
Quote currency. |
change_24h |
Option<f64> |
Percent change. |
open_interest |
Option<f64> |
Contracts or coins. Perpetuals only. |
open_interest_value |
Option<f64> |
USD value. |
funding_rate |
Option<f64> |
Perpetuals only. |
next_funding_time |
Option<i64> |
Milliseconds. |
mark_price, index_price |
Option<f64> |
|
timestamp |
i64 |
Milliseconds. |
Fields the exchange does not provide are None. Not every adapter implements get_ticker; the default returns an error.
Order book#
let book = trader.get_orderbook("BTCUSDT", 20).await?;
let best_bid = book.bids.first().map(|l| l.price);
let best_ask = book.asks.first().map(|l| l.price);
Orderbook has symbol, bids, asks (Vec<OrderbookLevel> with price and quantity) and timestamp. This is a REST snapshot. The depth values an exchange accepts differ, so use a common one such as 5, 10, 20 or 50.
To check that a WebSocket stream works, see Dry-run checks.
Funding rate history#
let rows = trader.get_funding_rate_history("BTCUSDT", 100).await?;
for r in rows { println!("{} {} at {}", r.symbol, r.funding_rate, r.funding_time); }
Perpetual markets only. The limit is the number of entries requested.
Open interest history#
let rows = trader.get_open_interest_history("BTCUSDT", "5min", 100).await?;
for r in rows { println!("{} OI {} (value {})", r.timestamp, r.open_interest, r.open_interest_value); }
The interval string is passed to the exchange, so accepted values differ. For example Bybit's API takes values such as 5min, 1h and 1d. Bybit returns an error for spot traders.
Check support first#
When your code targets several exchanges, ask before calling:
let caps = trader.capabilities();
if caps.is_supported("get_funding_rate_history") { /* ... */ }
The exchange matrix shows which adapters declare funding and open-interest history today.