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 perps, Hyperliquid Spot, HIP-3 builder perps, HIP-4 outcome markets, and Lighter.xyz.

§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.7", features = ["websocket"] }

Re-exports§

pub use client::ClientBuilder;
pub use client::OxArchive;
pub use error::Error;
pub use error::Result;
pub use exchanges::Hip4;
pub use l4_reconstructor::L4OrderBookReconstructor;
pub use l4_reconstructor::L4Order;
pub use l4_reconstructor::L4Diff;
pub use l4_reconstructor::L2Level;
pub use orderbook_reconstructor::reconstruct_final;
pub use orderbook_reconstructor::reconstruct_orderbook;
pub use orderbook_reconstructor::OrderBookReconstructor;
pub use types::CursorResponse;
pub use types::Hip4AggregatedOi;
pub use types::Hip4OpenInterestRecord;
pub use types::Hip4Outcome;
pub use types::Hip4OutcomeAggregate;
pub use types::Hip4SideSpec;
pub use types::L4OrderBookSnapshot;
pub use types::L4OrderEntry;
pub use types::L4DiffEntry;
pub use types::L2OrderBookSnapshot;
pub use types::L2PriceLevel;
pub use types::L2DiffEntry;
pub use types::OrderHistoryEntry;

Modules§

client
error
Error types for the 0xArchive SDK.
exchanges
http
l4_reconstructor
L4 order book reconstructor with matching engine.
orderbook_reconstructor
resources
types
ws