kraapi/api/private/
open_orders.rs1use indexmap::map::IndexMap;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5use crate::auth::KrakenAuth;
6use super::{EndpointInfo, KrakenInput, MethodType};
8
9use super::{Input, MutateInput, Output, UpdateInput};
11
12pub use super::KOOrderDescription;
13pub use super::KOOrderInfo;
14pub use super::KOOrderStatus;
15
16pub struct KIOpenOrders {
18 params: IndexMap<String, String>,
19}
20
21impl KIOpenOrders {
22 pub fn build() -> Self {
24 KIOpenOrders {
25 params: IndexMap::new(),
26 }
27 }
28
29 pub fn with_trade_info(self, include_trades: bool) -> Self {
33 if include_trades {
34 self.update_input("trades", include_trades.to_string())
35 } else {
36 self.update_input("trades", String::from(""))
37 }
38 }
39
40 pub fn with_userref(self, userref: u32) -> Self {
43 self.update_input("userref", userref.to_string())
44 }
45
46 fn with_nonce(self) -> Self {
47 self.update_input("nonce", KrakenAuth::nonce())
48 }
49}
50
51impl Input for KIOpenOrders {
52 fn finish(self) -> KrakenInput {
53 KrakenInput {
54 info: EndpointInfo {
55 methodtype: MethodType::Private,
56 endpoint: String::from("OpenOrders"),
57 },
58 params: Some(self.with_nonce().params),
59 }
60 }
61
62 fn finish_clone(self) -> (KrakenInput, Self) {
63 let newself = self.with_nonce();
64 (
65 KrakenInput {
66 info: EndpointInfo {
67 methodtype: MethodType::Private,
68 endpoint: String::from("OpenOrders"),
69 },
70 params: Some(newself.params.clone()),
71 },
72 newself,
73 )
74 }
75}
76
77impl MutateInput for KIOpenOrders {
78 fn list_mut(&mut self) -> &mut IndexMap<String, String> {
79 &mut self.params
80 }
81}
82
83impl UpdateInput for KIOpenOrders {}
84
85#[derive(Deserialize, Serialize, Debug)]
87pub struct KOOpenOrders {
88 pub orders: HashMap<String, KOOrderInfo>,
89}
90
91impl Output for KOOpenOrders {}