Skip to content

Commit

Permalink
Merge pull request #188 from InjectiveLabs/f/add-derivative-orderbook…
Browse files Browse the repository at this point in the history
…-query
  • Loading branch information
gorgos authored Nov 7, 2023
2 parents 6293909 + 718dceb commit f760494
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/injective-cosmwasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "Apache-2.0"
name = "injective-cosmwasm"
readme = "README.md"
repository = "https://github.com/InjectiveLabs/cw-injective/tree/master/packages/bindings"
version = "0.2.15"
version = "0.2.16"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
21 changes: 21 additions & 0 deletions packages/injective-cosmwasm/src/exchange_mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ fn default_spot_market_orderbook_response_handler() -> QuerierResult {
SystemResult::Ok(ContractResult::from(to_binary(&response)))
}

fn default_derivative_market_orderbook_response_handler() -> QuerierResult {
let response = QueryOrderbookResponse {
buys_price_level: vec![PriceLevel::new(9u128.into(), 10u128.into()), PriceLevel::new(8u128.into(), 10u128.into())],
sells_price_level: vec![
PriceLevel::new(11u128.into(), 10u128.into()),
PriceLevel::new(12u128.into(), 10u128.into()),
],
};
SystemResult::Ok(ContractResult::from(to_binary(&response)))
}

fn default_market_atomic_execution_fee_multiplier_response_handler() -> QuerierResult {
let response = QueryMarketAtomicExecutionFeeMultiplierResponse {
multiplier: FPDecimal::from_str("2.0").unwrap(),
Expand Down Expand Up @@ -444,6 +455,10 @@ pub trait HandlesPriceLevelsQuery {
fn handle(&self, market_id: MarketId, order_side: OrderSide) -> QuerierResult;
}

pub trait HandlesDerivativePriceLevelsQuery {
fn handle(&self, market_id: MarketId) -> QuerierResult;
}

pub trait HandlesExchangeParamsQuery {
fn handle(&self) -> QuerierResult;
}
Expand Down Expand Up @@ -482,6 +497,7 @@ pub struct WasmMockQuerier {
pub all_balances_query_handler: Option<Box<dyn HandlesBankAllBalancesQuery>>,
pub registered_contract_info_query_handler: Option<Box<dyn HandlesByAddressQuery>>,
pub spot_market_orderbook_response_handler: Option<Box<dyn HandlesPriceLevelsQuery>>,
pub derivative_market_orderbook_response_handler: Option<Box<dyn HandlesDerivativePriceLevelsQuery>>,
pub market_atomic_execution_fee_multiplier_response_handler: Option<Box<dyn HandlesMarketIdQuery>>,
}

Expand Down Expand Up @@ -677,6 +693,10 @@ impl WasmMockQuerier {
Some(handler) => handler.handle(market_id, order_side),
None => default_spot_market_orderbook_response_handler(),
},
InjectiveQuery::DerivativeOrderbook { market_id, .. } => match &self.derivative_market_orderbook_response_handler {
Some(handler) => handler.handle(market_id),
None => default_derivative_market_orderbook_response_handler(),
},
InjectiveQuery::MarketAtomicExecutionFeeMultiplier { market_id } => {
match &self.market_atomic_execution_fee_multiplier_response_handler {
Some(handler) => handler.handle(market_id),
Expand Down Expand Up @@ -731,6 +751,7 @@ impl WasmMockQuerier {
registered_contract_info_query_handler: None,
denom_decimals_handler: None,
spot_market_orderbook_response_handler: None,
derivative_market_orderbook_response_handler: None,
market_atomic_execution_fee_multiplier_response_handler: None,
}
}
Expand Down
17 changes: 17 additions & 0 deletions packages/injective-cosmwasm/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,23 @@ impl<'a> InjectiveQuerier<'a> {
Ok(res)
}

pub fn query_derivative_market_orderbook<T: Into<MarketId> + Clone>(
&self,
market_id: &'a T,
limit_cumulative_notional: FPDecimal,
) -> StdResult<QueryOrderbookResponse> {
let request = InjectiveQueryWrapper {
route: InjectiveRoute::Exchange,
query_data: InjectiveQuery::DerivativeOrderbook {
market_id: market_id.clone().into(),
limit: 0,
limit_cumulative_notional: Some(limit_cumulative_notional),
},
};
let res: QueryOrderbookResponse = self.querier.query(&request.into())?;
Ok(res)
}

pub fn query_market_atomic_execution_fee_multiplier<T: Into<MarketId> + Clone>(
&self,
market_id: &'a T,
Expand Down
5 changes: 5 additions & 0 deletions packages/injective-cosmwasm/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ pub enum InjectiveQuery {
limit_cumulative_quantity: Option<FPDecimal>,
limit_cumulative_notional: Option<FPDecimal>,
},
DerivativeOrderbook {
market_id: MarketId,
limit: u64,
limit_cumulative_notional: Option<FPDecimal>,
},
DerivativeMarketMidPriceAndTob {
market_id: MarketId,
},
Expand Down

0 comments on commit f760494

Please sign in to comment.