nash_protocol/protocol/list_account_orders/
request.rs

1use super::types::ListAccountOrdersRequest;
2use crate::graphql;
3use crate::graphql::list_account_orders;
4use crate::types::{BuyOrSell, OrderStatus, OrderType};
5
6use graphql_client::GraphQLQuery;
7
8impl ListAccountOrdersRequest {
9    pub fn make_query(&self) -> graphql_client::QueryBody<list_account_orders::Variables> {
10        let get_order = list_account_orders::Variables {
11            payload: list_account_orders::ListAccountOrdersParams {
12                before: self.before.clone(),
13                limit: self.limit,
14                status: self
15                    .status
16                    .as_ref()
17                    .map(|x| x.iter().map(|x| Some(x.clone().into())).collect()),
18                buy_or_sell: self.buy_or_sell.map(|x| x.into()),
19                market_name: self.market.clone(),
20                type_: self
21                    .order_type
22                    .as_ref()
23                    .map(|x| x.iter().map(|x| Some(x.clone().into())).collect()),
24                range_start: self.range.as_ref().map(|x| format!("{:?}", x.start)),
25                range_stop: self.range.as_ref().map(|x| format!("{:?}", x.stop)),
26            },
27        };
28        graphql::ListAccountOrders::build_query(get_order)
29    }
30}
31
32impl From<BuyOrSell> for list_account_orders::OrderBuyOrSell {
33    fn from(buy_or_sell: BuyOrSell) -> Self {
34        match buy_or_sell {
35            BuyOrSell::Buy => list_account_orders::OrderBuyOrSell::BUY,
36            BuyOrSell::Sell => list_account_orders::OrderBuyOrSell::SELL,
37        }
38    }
39}
40
41impl From<OrderStatus> for list_account_orders::OrderStatus {
42    fn from(status: OrderStatus) -> Self {
43        match status {
44            OrderStatus::Canceled => list_account_orders::OrderStatus::CANCELLED,
45            OrderStatus::Filled => list_account_orders::OrderStatus::FILLED,
46            OrderStatus::Open => list_account_orders::OrderStatus::OPEN,
47            OrderStatus::Pending => list_account_orders::OrderStatus::PENDING,
48        }
49    }
50}
51
52impl From<OrderType> for list_account_orders::OrderType {
53    fn from(type_: OrderType) -> Self {
54        match type_ {
55            OrderType::Limit => list_account_orders::OrderType::LIMIT,
56            OrderType::Market => list_account_orders::OrderType::MARKET,
57            OrderType::StopLimit => list_account_orders::OrderType::STOP_LIMIT,
58            OrderType::StopMarket => list_account_orders::OrderType::STOP_MARKET,
59        }
60    }
61}