diff --git a/lib/client/src/client.rs b/lib/client/src/client.rs index 0e7c45a8f..ee95831e5 100644 --- a/lib/client/src/client.rs +++ b/lib/client/src/client.rs @@ -566,8 +566,8 @@ impl OpenBookClient { open_orders_account: self.open_orders_account, signer: self.owner(), open_orders_admin: market.open_orders_admin.into(), - user_quote_account: user_quote_account, - user_base_account: user_base_account, + user_quote_account, + user_base_account, market: market_address, bids: market.bids, asks: market.asks, diff --git a/programs/openbook-v2/src/state/market.rs b/programs/openbook-v2/src/state/market.rs index 03b6bc3bf..741977a97 100644 --- a/programs/openbook-v2/src/state/market.rs +++ b/programs/openbook-v2/src/state/market.rs @@ -218,6 +218,22 @@ impl Market { / I80F48::from_num(self.base_lot_size) } + /// Convert the quantity from quote lots to native quantity (e.g. 5 SOL, 3 USDC, etc) + pub fn quote_lot_to_native_quantity(&self, quote_lots: i64) -> i64 { + let quote_lot_size = self.quote_lot_size; + let quote_decimals = self.quote_decimals; + let quote_units = quote_lots * quote_lot_size; + quote_units / 10_i64.pow(quote_decimals.into()) + } + + /// Convert the quantity from base lots to native quantity (e.g. 5 SOL, 3 USDC, etc) + pub fn base_lot_to_native_quantity(&self, base_lots: i64) -> i64 { + let base_lot_size = self.base_lot_size; + let base_decimals = self.base_decimals; + let base_units = base_lots * base_lot_size; + base_units / 10_i64.pow(base_decimals.into()) + } + pub fn native_price_to_lot(&self, price: I80F48) -> Result { price .checked_mul(I80F48::from_num(self.base_lot_size)) diff --git a/programs/openbook-v2/src/state/orderbook/bookside.rs b/programs/openbook-v2/src/state/orderbook/bookside.rs index 41fca4f01..1f0633309 100644 --- a/programs/openbook-v2/src/state/orderbook/bookside.rs +++ b/programs/openbook-v2/src/state/orderbook/bookside.rs @@ -182,6 +182,16 @@ impl BookSide { ) } + /// Return the quantity of the order closest to the spread + pub fn best_quantity(&self, now_ts: u64, oracle_price_lots: Option) -> Option { + Some( + self.iter_valid(now_ts, oracle_price_lots) + .next()? + .node + .quantity, + ) + } + /// Walk up the book `quantity` units and return the price at that level. If `quantity` units /// not on book, return None pub fn impact_price(&self, quantity: i64, now_ts: u64, oracle_price_lots: i64) -> Option {