Skip to main content

longbridge/trade/requests/
cancel_order.rs

1use serde::Serialize;
2
3/// Options for cancel order request
4#[derive(Debug, Serialize, Clone)]
5pub struct CancelOrderOptions {
6    order_id: String,
7    #[serde(skip_serializing_if = "Option::is_none")]
8    is_attached: Option<bool>,
9}
10
11impl CancelOrderOptions {
12    /// Create new options with order ID
13    pub fn new(order_id: impl Into<String>) -> Self {
14        Self {
15            order_id: order_id.into(),
16            is_attached: None,
17        }
18    }
19    /// Indicate that the provided `order_id` is an attached sub-order ID.
20    ///
21    /// When set, the server looks up the order using the attached order ID
22    /// instead of treating `order_id` as a regular order ID.
23    pub fn is_attached(self) -> Self {
24        Self {
25            is_attached: Some(true),
26            ..self
27        }
28    }
29}
30
31impl From<String> for CancelOrderOptions {
32    fn from(order_id: String) -> Self {
33        Self::new(order_id)
34    }
35}
36
37impl<'a> From<&'a str> for CancelOrderOptions {
38    fn from(order_id: &'a str) -> Self {
39        Self::new(order_id)
40    }
41}