use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{rest_api::endpoint, web_socket_api::web_socket};
endpoint!(
"/api/v3/depth",
Method::GET,
OrderBookEndpoint,
OrderBookParams,
OrderBookResponse
);
pub struct OrderBookEndpoint<'r> {
client: &'r crate::rest_api::RestApiClient,
}
impl<'r> OrderBookEndpoint<'r> {
pub fn new(client: &'r crate::rest_api::RestApiClient) -> Self {
Self { client }
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderBookParams {
symbol: String,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<i64>,
}
impl OrderBookParams {
pub fn new(symbol: &str) -> Self {
Self {
symbol: symbol.to_string(),
limit: None,
}
}
pub fn limit(mut self, limit: i64) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OrderBookResponse {
pub last_update_id: i64,
pub bids: Vec<(String, String)>,
pub asks: Vec<(String, String)>,
}
web_socket!(
"depth",
OrderBookWebSocket,
OrderBookParams,
OrderBookResponse
);
pub struct OrderBookWebSocket<'w> {
client: &'w crate::web_socket_api::WebSocketApiClient,
}
impl<'w> OrderBookWebSocket<'w> {
pub fn new(client: &'w crate::web_socket_api::WebSocketApiClient) -> Self {
Self { client }
}
}