Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
feat: query margin order(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
politeWall committed Nov 15, 2023
1 parent c39e5df commit 17457bc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
9 changes: 1 addition & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,10 @@ thiserror = "1"
schemars = "0.8.1"
cosmwasm-schema = "1.1.4"
cw-utils = "0.13"
elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "margin_query" }
elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "main" }

[dev-dependencies]

<<<<<<< HEAD
elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", features = [
"testing",
], branch = "main" }
=======

>>>>>>> a8dcd69 (feat: bindings repository integration)
cw-multi-test = "0.13.4"
serde_json = "1.0.107"
elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "main", features = [
Expand Down
13 changes: 10 additions & 3 deletions src/action/query/get_margin_order.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use cosmwasm_std::StdError;

use super::*;

pub fn get_margin_order(
deps: Deps<ElysQuery>,
address: String,
id: u64,
) -> Result<MTPResponse, ContractError> {
) -> Result<Mtp, ContractError> {
let querier = ElysQuerier::new(&deps.querier);

let resp: MTPResponse = querier.mtp(address, id)?;
Ok(resp)
let resp: MarginMtpResponse = querier.mtp(address, id)?;

if let Some(mtp) = resp.mtp {
Ok(mtp)
} else {
Err(StdError::not_found("margin trading prosition").into())
}
}
5 changes: 3 additions & 2 deletions src/action/query/get_margin_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use super::*;
pub fn get_margin_orders(
deps: Deps<ElysQuery>,
pagination: PageRequest,
) -> Result<PositionsResponse, ContractError> {
) -> Result<MarginQueryPositionsResponse, ContractError> {
let querier = ElysQuerier::new(&deps.querier);

let resp: PositionsResponse = querier.positions(pagination)?;
let resp: MarginQueryPositionsResponse = querier.positions(pagination)?;

Ok(resp)
}
18 changes: 9 additions & 9 deletions src/entry_point/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ pub fn query(deps: Deps<ElysQuery>, _env: Env, msg: QueryMsg) -> Result<Binary,
use QueryMsg::*;

match msg {
GetSpotOrder { order_id } => Ok(to_binary(&query::get_spot_order(deps, order_id)?)?),
GetAllPrices {} => Ok(to_binary(&query::get_all_prices(deps)?)?),
AssetInfo { denom } => Ok(to_binary(&query::asset_info(deps, denom)?)?),
GetMarginOrder { address, id } => {
Ok(to_binary(&query::get_margin_order(deps, address, id)?)?)
}
GetMarginOrders { pagination } => {
Ok(to_binary(&query::get_margin_orders(deps, pagination)?)?)
}
GetSpotOrder { order_id } => Ok(to_json_binary(&query::get_spot_order(deps, order_id)?)?),
GetAllPrices {} => Ok(to_json_binary(&query::get_all_prices(deps)?)?),
AssetInfo { denom } => Ok(to_json_binary(&query::asset_info(deps, denom)?)?),
GetMarginOrder { address, id } => Ok(to_json_binary(&query::get_margin_order(
deps, address, id,
)?)?),
GetMarginOrders { pagination } => Ok(to_json_binary(&query::get_margin_orders(
deps, pagination,
)?)?),
}
}
4 changes: 2 additions & 2 deletions src/msg/query_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub enum QueryMsg {
GetAllPrices {},
#[returns(OracleAssetInfoResponse)]
AssetInfo { denom: String },
#[returns(MTPResponse)]
#[returns(MarginMtpResponse)]
GetMarginOrder { address: String, id: u64 },
#[returns(PositionsResponse)]
#[returns(MarginQueryPositionsResponse)]
GetMarginOrders { pagination: PageRequest },
}

0 comments on commit 17457bc

Please sign in to comment.