kraapi/api/private/
closed_orders.rs1use indexmap::map::IndexMap;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5use crate::auth::KrakenAuth;
6use super::{EndpointInfo, KrakenInput, MethodType, OrderCloseTime};
8
9use super::{Input, MutateInput, Output, UpdateInput};
11
12pub use super::KOOrderDescription;
13pub use super::KOOrderInfo;
14pub use super::KOOrderStatus;
15
16pub struct KIClosedOrders {
18 params: IndexMap<String, String>,
19}
20
21impl KIClosedOrders {
22 pub fn build() -> Self {
24 KIClosedOrders {
25 params: IndexMap::new(),
26 }
27 }
28
29 pub fn with_trade_info(self, include_trades: bool) -> Self {
31 if include_trades {
32 self.update_input("trades", include_trades.to_string())
33 } else {
34 self.update_input("trades", String::from(""))
35 }
36 }
37
38 pub fn with_userref(self, userref: u32) -> Self {
41 self.update_input("userref", userref.to_string())
42 }
43
44 pub fn starting_timestamp(self, timestamp: u64) -> Self {
46 self.update_input("start", timestamp.to_string())
47 }
48
49 pub fn ending_timestamp(self, timestamp: u64) -> Self {
51 self.update_input("end", timestamp.to_string())
52 }
53
54 pub fn starting_txid(self, txid: String) -> Self {
56 self.update_input("start", txid)
57 }
58
59 pub fn ending_txid(self, txid: String) -> Self {
61 self.update_input("end", txid)
62 }
63
64 pub fn with_offset(self, offset: u64) -> Self {
66 self.update_input("ofs", offset.to_string())
67 }
68
69 pub fn with_closetime(self, closetime: OrderCloseTime) -> Self {
71 self.update_input("closetime", closetime.to_string())
72 }
73
74 fn with_nonce(self) -> Self {
75 self.update_input("nonce", KrakenAuth::nonce())
76 }
77}
78
79impl Input for KIClosedOrders {
80 fn finish(self) -> KrakenInput {
81 KrakenInput {
82 info: EndpointInfo {
83 methodtype: MethodType::Private,
84 endpoint: String::from("ClosedOrders"),
85 },
86 params: Some(self.with_nonce().params),
87 }
88 }
89
90 fn finish_clone(self) -> (KrakenInput, Self) {
91 let newself = self.with_nonce();
92 (
93 KrakenInput {
94 info: EndpointInfo {
95 methodtype: MethodType::Private,
96 endpoint: String::from("ClosedOrders"),
97 },
98 params: Some(newself.params.clone()),
99 },
100 newself,
101 )
102 }
103}
104
105impl MutateInput for KIClosedOrders {
106 fn list_mut(&mut self) -> &mut IndexMap<String, String> {
107 &mut self.params
108 }
109}
110
111impl UpdateInput for KIClosedOrders {}
112
113#[derive(Deserialize, Serialize, Debug)]
115pub struct KOClosedOrders {
116 pub closed: HashMap<String, KOOrderInfo>,
117 pub count: u32,
118}
119
120impl Output for KOClosedOrders {}