use jiff::Timestamp;
use reqwest::Method;
use serde::Serialize;
use crate::{enums::SecurityType, rest_api::endpoint};
use super::OrderDetail;
endpoint!(
"/api/v3/allOrders",
Method::GET,
SecurityType::UserData,
AllOrdersEndpoint,
AllOrdersParams,
AllOrdersResponse
);
pub struct AllOrdersEndpoint<'r> {
client: &'r crate::rest_api::RestApiClient,
}
impl<'r> AllOrdersEndpoint<'r> {
pub fn new(client: &'r crate::rest_api::RestApiClient) -> Self {
Self { client }
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct AllOrdersParams {
symbol: String,
#[serde(skip_serializing_if = "Option::is_none")]
order_id: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
start_time: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
end_time: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
recv_window: Option<i64>,
timestamp: i64,
}
impl AllOrdersParams {
pub fn new(symbol: &str) -> Self {
Self {
symbol: symbol.to_owned(),
order_id: None,
start_time: None,
end_time: None,
limit: None,
recv_window: None,
timestamp: Timestamp::now().as_millisecond(),
}
}
pub fn order_id(mut self, order_id: i64) -> Self {
self.order_id = Some(order_id);
self
}
pub fn start_time(mut self, start_time: i64) -> Self {
self.start_time = Some(start_time);
self
}
pub fn end_time(mut self, end_time: i64) -> Self {
self.end_time = Some(end_time);
self
}
pub fn limit(mut self, limit: i64) -> Self {
self.limit = Some(limit);
self
}
pub fn recv_window(mut self, recv_window: i64) -> Self {
self.recv_window = Some(recv_window);
self
}
}
pub type AllOrdersResponse = Vec<OrderDetail>;