kraapi/api/private/
cancel_on_timeout.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 Orders After endpoint
12pub struct KICancelOnTimeout {
13    params: IndexMap<String, String>,
14}
15
16impl KICancelOnTimeout {
17    /// Constructor returning a [KrakenInput] builder for the cancel all orders after... endpoint.
18    /// Cancel all orders in `timeout` seconds
19    pub fn build(timeout: u32) -> KICancelOnTimeout {
20        let cancelorder = KICancelOnTimeout {
21            params: IndexMap::new(),
22        };
23        cancelorder.on_timeout(timeout)
24    }
25
26    /// Update the timeout value. Useful for templating
27    pub fn on_timeout(self, timeout: u32) -> Self {
28        self.update_input("timeout", timeout.to_string())
29    }
30
31    fn with_nonce(self) -> Self {
32        self.update_input("nonce", KrakenAuth::nonce())
33    }
34}
35
36impl MutateInput for KICancelOnTimeout {
37    fn list_mut(&mut self) -> &mut IndexMap<String, String> {
38        &mut self.params
39    }
40}
41
42impl UpdateInput for KICancelOnTimeout {}
43
44impl Input for KICancelOnTimeout {
45    fn finish(self) -> KrakenInput {
46        KrakenInput {
47            info: EndpointInfo {
48                methodtype: MethodType::Private,
49                endpoint: String::from("CancelAllOrdersAfter"),
50            },
51            params: Some(self.with_nonce().params),
52        }
53    }
54
55    fn finish_clone(self) -> (KrakenInput, Self) {
56        let newself = self.with_nonce();
57        (
58            KrakenInput {
59                info: EndpointInfo {
60                    methodtype: MethodType::Private,
61                    endpoint: String::from("CancelAllOrdersAfter"),
62                },
63                params: Some(newself.params.clone()),
64            },
65            newself,
66        )
67    }
68}
69
70/// Response from the Cancel All Orders After endpoint
71#[derive(Deserialize, Serialize, Debug)]
72pub struct KOCancelOnTimeout {
73    /// Timestamp (RFC3339) reflecting when the request has been handled (second precision, rounded up)
74    #[serde(rename = "currentTime")]
75    pub current_time: String,
76    /// Timestamp (RFC3339) reflecting the time at which all open orders will be cancelled,
77    /// unless the timer is extended or disabled (second precision, rounded up)
78    #[serde(rename = "triggerTime")]
79    pub trigger_time: String,
80}
81
82impl Output for KOCancelOnTimeout {}