Skip to main content

Crate oxarchive

Crate oxarchive 

Source
Expand description

§oxarchive

Rust client library for the 0xArchive API.

Query historical and real-time crypto market data — orderbooks, trades, candles, funding rates, open interest, and liquidations across Hyperliquid, Lighter.xyz, and HIP-3.

§Quick start

use oxarchive::OxArchive;

#[tokio::main]
async fn main() -> oxarchive::Result<()> {
    let client = OxArchive::new("your-api-key")?;

    // Get BTC orderbook from Hyperliquid
    let ob = client.hyperliquid.orderbook.get("BTC", None).await?;
    println!("BTC mid price: {:?}", ob.mid_price);

    // List Lighter.xyz instruments
    let instruments = client.lighter.instruments.list().await?;
    println!("Lighter has {} instruments", instruments.len());

    // Get current funding rate
    let funding = client.hyperliquid.funding.current("ETH").await?;
    println!("ETH funding: {}", funding.funding_rate);

    Ok(())
}

§Pagination

Historical endpoints return CursorResponse with an optional next_cursor. Pass it back as the cursor parameter to fetch the next page:

let mut all_trades = vec![];
let mut cursor = None;

loop {
    let result = client.hyperliquid.trades.list("BTC", GetTradesParams {
        start: 1704067200000_i64.into(),
        end: 1704153600000_i64.into(),
        cursor,
        limit: Some(1000),
        side: None,
    }).await?;

    all_trades.extend(result.data);
    cursor = result.next_cursor;
    if cursor.is_none() {
        break;
    }
}

§WebSocket (optional)

Enable the websocket feature for real-time streaming, historical replay, and bulk data download:

oxarchive = { version = "1.2", features = ["websocket"] }

Re-exports§

pub use client::ClientBuilder;
pub use client::OxArchive;
pub use error::Error;
pub use error::Result;
pub use orderbook_reconstructor::reconstruct_final;
pub use orderbook_reconstructor::reconstruct_orderbook;
pub use orderbook_reconstructor::OrderBookReconstructor;
pub use types::CursorResponse;

Modules§

client
error
exchanges
http
orderbook_reconstructor
resources
types
ws