use cow_errors::CowError;
use crate::{
OrderBookApi,
types::{
Order, OrderCancellations, OrderCreation, OrderQuoteRequest, OrderQuoteResponse, Trade,
},
};
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
pub trait OrderbookClient: Send + Sync {
async fn get_quote(&self, request: &OrderQuoteRequest) -> Result<OrderQuoteResponse, CowError>;
async fn send_order(&self, creation: &OrderCreation) -> Result<String, CowError>;
async fn get_order(&self, order_uid: &str) -> Result<Order, CowError>;
async fn get_trades(&self, order_uid: &str) -> Result<Vec<Trade>, CowError>;
async fn cancel_orders(&self, cancellation: &OrderCancellations) -> Result<(), CowError>;
}
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
#[allow(clippy::use_self, reason = "fully qualified calls needed to avoid infinite recursion")]
impl OrderbookClient for OrderBookApi {
async fn get_quote(&self, request: &OrderQuoteRequest) -> Result<OrderQuoteResponse, CowError> {
OrderBookApi::get_quote(self, request).await
}
async fn send_order(&self, creation: &OrderCreation) -> Result<String, CowError> {
OrderBookApi::send_order(self, creation).await
}
async fn get_order(&self, order_uid: &str) -> Result<Order, CowError> {
OrderBookApi::get_order(self, order_uid).await
}
async fn get_trades(&self, order_uid: &str) -> Result<Vec<Trade>, CowError> {
OrderBookApi::get_trades(self, Some(order_uid), None).await
}
async fn cancel_orders(&self, cancellation: &OrderCancellations) -> Result<(), CowError> {
OrderBookApi::cancel_orders(self, cancellation).await
}
}