nash_protocol/protocol/get_account_order/
types.rs

1use super::super::{
2    serializable_to_json, try_response_with_state_from_json, NashProtocol, ResponseOrError, State,
3};
4use crate::errors::Result;
5use crate::graphql::get_account_order;
6use crate::types::Order;
7use super::super::list_markets::ListMarketsRequest;
8use super::super::hooks::{ProtocolHook, NashProtocolRequest};
9use async_trait::async_trait;
10use tokio::sync::RwLock;
11use std::sync::Arc;
12
13/// Lookup order information via id
14#[derive(Clone, Debug)]
15pub struct GetAccountOrderRequest {
16    pub order_id: String,
17}
18
19/// Response contains an `Order` with associated information
20#[derive(Clone, Debug)]
21pub struct GetAccountOrderResponse {
22    pub order: Order,
23}
24
25/// Implement protocol bindings for GetAccountOrderRequest
26#[async_trait]
27impl NashProtocol for GetAccountOrderRequest {
28    type Response = GetAccountOrderResponse;
29
30    async fn graphql(&self, _state: Arc<RwLock<State>>) -> Result<serde_json::Value> {
31        let query = self.make_query();
32        serializable_to_json(&query)
33    }
34
35    async fn response_from_json(
36        &self,
37        response: serde_json::Value,
38        state: Arc<RwLock<State>>
39    ) -> Result<ResponseOrError<Self::Response>> {
40        try_response_with_state_from_json::<GetAccountOrderResponse, get_account_order::ResponseData>(response, state).await
41    }
42
43    async fn run_before(&self, state: Arc<RwLock<State>>) -> Result<Option<Vec<ProtocolHook>>> {
44        let state = state.read().await;
45        let mut hooks = Vec::new();
46        if let None = state.markets {
47            hooks.push(ProtocolHook::Protocol(NashProtocolRequest::ListMarkets(
48                ListMarketsRequest,
49            )))
50        }
51        Ok(Some(hooks))
52    }
53}