5 releases

new 0.1.4 Jan 24, 2025
0.1.3 Jan 22, 2025
0.1.2 Jan 22, 2025
0.1.1 Jan 22, 2025
0.1.0 Jan 21, 2025

#56 in WebSocket

Download history 586/week @ 2025-01-21

586 downloads per month

MIT license

66KB
1.5K SLoC

Paradex

A simple, yet high performance client library for paradex

Both websocket and rest connectivity are supported. Currently a sub-set of the most important APIs are supported.

Examples

See here for full examples.

Simple example for receiving public market Data Over WebSocket

#[tokio::main]
async fn main() {
    let symbol: String = "BTC-USD-PERP".into();
    let manager = paradex::ws::WebsocketManager::new(paradex::url::URL::Testnet, None).await;
    let summary_id = manager
        .subscribe(
            paradex::ws::Channel::MarketSummary,
            Box::new(|message| info!("Received message {message:?}")),
        )
        .await
        .unwrap();
    let bbo_id = manager
        .subscribe(
            paradex::ws::Channel::BBO {
                market_symbol: symbol.clone(),
            },
            Box::new(|message| info!("Received message {message:?}")),
        )
        .await
        .unwrap();
    let trades_id = manager
        .subscribe(
            paradex::ws::Channel::Trades {
                market_symbol: symbol.clone(),
            },
            Box::new(|message| info!("Received message {message:?}")),
        )
        .await
        .unwrap();
    let orderbook_id = manager
        .subscribe(
            paradex::ws::Channel::OrderBook {
                market_symbol: symbol.clone(),
                refresh_rate: "50ms".into(),
                price_tick: None,
            },
            Box::new(|message| info!("Received message {message:?}")),
        )
        .await
        .unwrap();
    let orderbook_deltas_id = manager
        .subscribe(
            paradex::ws::Channel::OrderBookDeltas {
                market_symbol: symbol.clone(),
            },
            Box::new(|message| info!("Received message {message:?}")),
        )
        .await
        .unwrap();
    let funding_id = manager
        .subscribe(
            paradex::ws::Channel::FundingData {
                market_symbol: None,
            },
            Box::new(|message| info!("Received message {message:?}")),
        )
        .await
        .unwrap();

    tokio::time::sleep(Duration::from_secs(120)).await;

    for id in [
        summary_id,
        bbo_id,
        trades_id,
        orderbook_id,
        orderbook_deltas_id,
        funding_id,
    ] {
        manager.unsubscribe(id).await.unwrap();
    }

    tokio::time::sleep(Duration::from_secs(5)).await;
    manager.stop().await.unwrap();
}

Dependencies

~18–33MB
~524K SLoC