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

Commit

Permalink
Query margin order (#33)
Browse files Browse the repository at this point in the history
* merge fix

* save change

* feat: bindings repository integration

* feat: add quering endpoint

* feat: query margin order(s)

* Update query_msg.rs

---------

Co-authored-by: Cosmic Vagabond <[email protected]>
  • Loading branch information
politeWall and cosmic-vagabond authored Nov 16, 2023
1 parent 472f88a commit ec28760
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ cw-utils = "0.13"
elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "main" }

[dev-dependencies]

cw-multi-test = "0.13.4"
serde_json = "1.0.107"
elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", features = [
elys-bindings = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "main", features = [
"testing",
], branch = "main" }
] }
elys-bindings-test = { version = "0.1.0", git = "https://github.com/elys-network/bindings", branch = "main" }
4 changes: 4 additions & 0 deletions src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use elys_bindings::*;
pub mod query {
mod asset_info;
mod get_all_price;
mod get_margin_order;
mod get_margin_orders;
mod get_spot_order;
mod get_spot_orders;

Expand All @@ -16,6 +18,8 @@ pub mod query {

pub use asset_info::asset_info;
pub use get_all_price::get_all_prices;
pub use get_margin_order::get_margin_order;
pub use get_margin_orders::get_margin_orders;
pub use get_spot_order::get_spot_order;
pub use get_spot_orders::get_spot_orders;
}
Expand Down
19 changes: 19 additions & 0 deletions src/action/query/get_margin_order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use cosmwasm_std::StdError;

use super::*;

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

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

if let Some(mtp) = resp.mtp {
Ok(mtp)
} else {
Err(StdError::not_found("margin trading prosition").into())
}
}
12 changes: 12 additions & 0 deletions src/action/query/get_margin_orders.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use super::*;

pub fn get_margin_orders(
deps: Deps<ElysQuery>,
pagination: PageRequest,
) -> Result<MarginQueryPositionsResponse, ContractError> {
let querier = ElysQuerier::new(&deps.querier);

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

Ok(resp)
}
6 changes: 6 additions & 0 deletions src/entry_point/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub fn query(deps: Deps<ElysQuery>, _env: Env, msg: QueryMsg) -> Result<Binary,
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,
)?)?),
GetSpotOrders {
pagination,
order_owner,
Expand Down
7 changes: 6 additions & 1 deletion src/msg/query_msg.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#[allow(unused_imports)]
use super::query_resp::*;
use crate::types::{PageRequest, SpotOrderType};
use crate::types::{SpotOrderType};
use cosmwasm_schema::{cw_serde, QueryResponses};
#[allow(unused_imports)]
use elys_bindings::query_resp::*;
use elys_bindings::types::PageRequest;

#[cw_serde]
#[derive(QueryResponses)]
Expand All @@ -14,6 +15,10 @@ pub enum QueryMsg {
GetAllPrices {},
#[returns(OracleAssetInfoResponse)]
AssetInfo { denom: String },
#[returns(MarginMtpResponse)]
GetMarginOrder { address: String, id: u64 },
#[returns(MarginQueryPositionsResponse)]
GetMarginOrders { pagination: PageRequest },
#[returns(GetSpotOrdersResp)]
GetSpotOrders {
pagination: PageRequest,
Expand Down

0 comments on commit ec28760

Please sign in to comment.