kraapi/api/private/
cancel_all_orders.rs

1use indexmap::map::IndexMap;
2use serde::{Deserialize, Serialize};
3
4use crate::auth::KrakenAuth;
5// Structs/Enums
6use super::{EndpointInfo, KrakenInput, MethodType};
7
8// Traits
9use super::{Input, MutateInput, Output, UpdateInput};
10
11/// Request builder for the Cancel All Open Orders endpoint
12pub struct KICancelAllOrders {
13    params: IndexMap<String, String>,
14}
15
16impl KICancelAllOrders {
17    /// Construct and build a [KrakenInput] for the cancel all orders endpoint. No parameters are
18    /// needed
19    pub fn build() -> KrakenInput {
20        let cancelorders = KICancelAllOrders {
21            params: IndexMap::new(),
22        };
23        cancelorders.finish()
24    }
25
26    fn with_nonce(self) -> Self {
27        self.update_input("nonce", KrakenAuth::nonce())
28    }
29}
30
31impl Input for KICancelAllOrders {
32    fn finish(self) -> KrakenInput {
33        KrakenInput {
34            info: EndpointInfo {
35                methodtype: MethodType::Private,
36                endpoint: String::from("CancelAll"),
37            },
38            params: Some(self.with_nonce().params),
39        }
40    }
41
42    fn finish_clone(self) -> (KrakenInput, Self) {
43        let newself = self.with_nonce();
44        (
45            KrakenInput {
46                info: EndpointInfo {
47                    methodtype: MethodType::Private,
48                    endpoint: String::from("CancelAll"),
49                },
50                params: Some(newself.params.clone()),
51            },
52            newself,
53        )
54    }
55}
56
57impl MutateInput for KICancelAllOrders {
58    fn list_mut(&mut self) -> &mut IndexMap<String, String> {
59        &mut self.params
60    }
61}
62
63impl UpdateInput for KICancelAllOrders {}
64
65/// Response from the Cancel All Open Orders endpoint
66#[derive(Deserialize, Serialize, Debug)]
67pub struct KOCancelAllOrders {
68    /// number of orders canceled
69    pub count: u32,
70}
71
72impl Output for KOCancelAllOrders {}