diff --git a/src/constants.rs b/src/constants.rs index c17ed36..9f8d540 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -14,6 +14,8 @@ use crate::types::Context; static STATE_ACCOUNT: OnceLock = OnceLock::new(); +pub const DEFAULT_ORDERBOOK_DEPTH: u8 = 10; + pub const TOKEN_PROGRAM_ID: Pubkey = solana_sdk::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"); diff --git a/src/dlob.rs b/src/dlob.rs index 9dc5fa6..0ec726e 100644 --- a/src/dlob.rs +++ b/src/dlob.rs @@ -18,6 +18,7 @@ use tokio::{ use tokio_tungstenite::{connect_async, tungstenite::protocol::Message}; use crate::{ + constants::DEFAULT_ORDERBOOK_DEPTH, types::{MarketId, SdkError, SdkResult}, utils::dlob_subscribe_ws_json, }; @@ -42,15 +43,20 @@ impl DLOBClient { } } /// Query L2 Orderbook for given `market` - pub async fn get_l2(&self, market: MarketId) -> Result { + pub async fn get_l2( + &self, + market: MarketId, + depth: Option, + ) -> Result { let market_type = match market.kind { MarketType::Perp => "perp", MarketType::Spot => "spot", }; + let depth = depth.map(|d| format!("&depth={d}")).unwrap_or_default(); let response = self .client .get(format!( - "{}/l2?marketType={}&marketIndex={}", + "{}/l2?marketType={}&marketIndex={}{depth}", &self.url, market_type, market.index )) .send() @@ -89,7 +95,8 @@ impl DLOBClient { async move { loop { let _ = interval.tick().await; - if tx.try_send(client.get_l2(market).await).is_err() { + let book = client.get_l2(market, None).await; + if tx.try_send(book).is_err() { // capacity reached or receiver closed, end the subscription task break; }