nash_protocol/protocol/subscriptions/updated_account_orders/
request.rs1use crate::graphql;
2use graphql::updated_account_orders;
3use graphql_client::GraphQLQuery;
4use crate::types::{BuyOrSell, OrderStatus, OrderType, DateTimeRange};
5
6#[derive(Clone, Debug)]
8pub struct SubscribeAccountOrders {
9 pub market: Option<String>,
10 pub buy_or_sell: Option<BuyOrSell>,
11 pub status: Option<Vec<OrderStatus>>,
12 pub order_type: Option<Vec<OrderType>>,
13 pub range: Option<DateTimeRange>
14}
15
16impl From<BuyOrSell> for updated_account_orders::OrderBuyOrSell {
17 fn from(buy_or_sell: BuyOrSell) -> Self {
18 match buy_or_sell {
19 BuyOrSell::Buy => updated_account_orders::OrderBuyOrSell::BUY,
20 BuyOrSell::Sell => updated_account_orders::OrderBuyOrSell::SELL,
21 }
22 }
23}
24
25impl From<OrderStatus> for updated_account_orders::OrderStatus {
26 fn from(status: OrderStatus) -> Self {
27 match status {
28 OrderStatus::Canceled => updated_account_orders::OrderStatus::CANCELLED,
29 OrderStatus::Filled => updated_account_orders::OrderStatus::FILLED,
30 OrderStatus::Open => updated_account_orders::OrderStatus::OPEN,
31 OrderStatus::Pending => updated_account_orders::OrderStatus::PENDING,
32 }
33 }
34}
35
36impl From<OrderType> for updated_account_orders::OrderType {
37 fn from(type_: OrderType) -> Self {
38 match type_ {
39 OrderType::Limit => updated_account_orders::OrderType::LIMIT,
40 OrderType::Market => updated_account_orders::OrderType::MARKET,
41 OrderType::StopLimit => updated_account_orders::OrderType::STOP_LIMIT,
42 OrderType::StopMarket => updated_account_orders::OrderType::STOP_MARKET,
43 }
44 }
45}
46
47impl SubscribeAccountOrders {
48 pub fn make_query(&self) -> graphql_client::QueryBody<updated_account_orders::Variables> {
49 graphql::UpdatedAccountOrders::build_query(updated_account_orders::Variables {
50 payload: updated_account_orders::UpdatedAccountOrdersParams {
51 market_name: self.market.clone(),
52 buy_or_sell: self.buy_or_sell.map(|x| x.into()),
53 status: self
54 .status
55 .as_ref()
56 .map(|x| x.iter().map(|x| Some(x.clone().into())).collect()),
57 type_: self
58 .order_type
59 .as_ref()
60 .map(|x| x.iter().map(|x| Some(x.clone().into())).collect()),
61 range_start: self.range.as_ref().map(|x| format!("{:?}", x.start)),
62 range_stop: self.range.as_ref().map(|x| format!("{:?}", x.stop)),
63 }
64 })
65 }
66}