bpx_api_client/routes/
rfq.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use bpx_api_types::rfq::{Quote, QuotePayload, RequestForQuote, RequestForQuotePayload};

#[cfg(feature = "ws")]
use tokio::sync::mpsc::Sender;

use crate::error::Result;
use crate::BpxClient;

#[doc(hidden)]
pub const API_RFQ: &str = "/api/v1/rfq";
#[doc(hidden)]
pub const API_RFQ_QUOTE: &str = "/api/v1/rfq/quote";

const API_RFQ_STREAM: &str = "account.rfqUpdate";

impl BpxClient {
    pub async fn submit_rfq(&self, payload: RequestForQuotePayload) -> Result<RequestForQuote> {
        let endpoint = format!("{}{}", self.base_url, API_RFQ);
        let res = self.post(endpoint, payload).await?;
        res.json().await.map_err(Into::into)
    }

    pub async fn submit_quote(&self, payload: QuotePayload) -> Result<Quote> {
        let endpoint = format!("{}{}", self.base_url, API_RFQ_QUOTE);
        let res = self.post(endpoint, payload).await?;
        res.json().await.map_err(Into::into)
    }

    #[cfg(feature = "ws")]
    pub async fn subscribe_to_rfqs(&self, tx: Sender<RequestForQuote>) {
        self.subscribe(API_RFQ_STREAM, tx).await;
    }
}