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..6d417cd 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, }; @@ -43,6 +44,15 @@ impl DLOBClient { } /// Query L2 Orderbook for given `market` pub async fn get_l2(&self, market: MarketId) -> Result { + self.get_l2_with_depth(market, DEFAULT_ORDERBOOK_DEPTH) + .await + } + + pub async fn get_l2_with_depth( + &self, + market: MarketId, + depth: u8, + ) -> Result { let market_type = match market.kind { MarketType::Perp => "perp", MarketType::Spot => "spot", @@ -50,7 +60,7 @@ impl DLOBClient { let response = self .client .get(format!( - "{}/l2?marketType={}&marketIndex={}", + "{}/l2?marketType={}&marketIndex={}&depth={depth}", &self.url, market_type, market.index )) .send() @@ -89,7 +99,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).await; + if tx.try_send(book).is_err() { // capacity reached or receiver closed, end the subscription task break; }