use jiff::Timestamp;
use reqwest::Method;
use serde::Serialize;
use crate::{enums::SecurityType, rest_api::endpoint, web_socket_api::web_socket};
use super::CancelOrderResult;
endpoint!(
"/api/v3/openOrders",
Method::DELETE,
SecurityType::Trade,
CancelAllOpenOrdersEndpoint,
CancelAllOpenOrdersParams,
CancelAllOpenOrdersResponse
);
pub struct CancelAllOpenOrdersEndpoint<'r> {
client: &'r crate::rest_api::RestApiClient,
}
impl<'r> CancelAllOpenOrdersEndpoint<'r> {
pub fn new(client: &'r crate::rest_api::RestApiClient) -> Self {
Self { client }
}
}
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CancelAllOpenOrdersParams {
symbol: String,
#[serde(skip_serializing_if = "Option::is_none")]
recv_window: Option<i64>,
timestamp: i64,
}
impl CancelAllOpenOrdersParams {
pub fn new(symbol: &str) -> Self {
Self {
symbol: symbol.to_owned(),
recv_window: None,
timestamp: Timestamp::now().as_millisecond(),
}
}
pub fn recv_window(mut self, recv_window: i64) -> Self {
self.recv_window = Some(recv_window);
self
}
}
pub type CancelAllOpenOrdersResponse = Vec<CancelOrderResult>;
web_socket!(
"openOrders.cancelAll",
CancelAllOpenOrdersWebSocket,
CancelAllOpenOrdersParams,
CancelAllOpenOrdersResponse
);
pub struct CancelAllOpenOrdersWebSocket<'w> {
client: &'w crate::web_socket_api::WebSocketApiClient,
}
impl<'w> CancelAllOpenOrdersWebSocket<'w> {
pub fn new(client: &'w crate::web_socket_api::WebSocketApiClient) -> Self {
Self { client }
}
}