kraapi/api/private/
trade_volume.rs1use indexmap::map::IndexMap;
2use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5use crate::auth::KrakenAuth;
6use super::{EndpointInfo, KAssetPair, KrakenInput, MethodType};
8
9use super::{Input, InputList, InputListItem, IntoInputList, MutateInput, Output, UpdateInput};
11
12pub struct KITradeVolume {
14 params: IndexMap<String, String>,
15}
16
17impl KITradeVolume {
18 pub fn build() -> Self {
20 KITradeVolume {
21 params: IndexMap::new(),
22 }
23 }
24
25 pub fn clear_pair_list(self) -> Self {
29 self.update_input("pair", String::from(""))
30 }
31
32 pub fn with_pair(self, pair: KAssetPair) -> Self {
34 self.with_item(pair)
35 }
36
37 pub fn with_pair_list<T>(self, pairs: T) -> Self
39 where
40 T: IntoIterator<Item = KAssetPair>,
41 {
42 self.with_item_list(pairs)
43 }
44
45 pub fn with_fee_info(self, feeinfo: bool) -> Self {
47 self.update_input("fee-info", feeinfo.to_string())
48 }
49
50 fn with_nonce(self) -> Self {
51 self.update_input("nonce", KrakenAuth::nonce())
52 }
53}
54
55impl MutateInput for KITradeVolume {
56 fn list_mut(&mut self) -> &mut IndexMap<String, String> {
57 &mut self.params
58 }
59}
60
61impl UpdateInput for KITradeVolume {}
62
63impl IntoInputList for KITradeVolume {
64 fn list_name(&self) -> String {
65 String::from("pair")
66 }
67}
68
69impl InputListItem for KITradeVolume {
70 type ListItem = KAssetPair;
71}
72
73impl InputList for KITradeVolume {}
74
75impl Input for KITradeVolume {
76 fn finish(self) -> KrakenInput {
77 KrakenInput {
78 info: EndpointInfo {
79 methodtype: MethodType::Private,
80 endpoint: String::from("TradeVolume"),
81 },
82 params: Some(self.with_nonce().params),
83 }
84 }
85
86 fn finish_clone(self) -> (KrakenInput, Self) {
87 let newself = self.with_nonce();
88 (
89 KrakenInput {
90 info: EndpointInfo {
91 methodtype: MethodType::Private,
92 endpoint: String::from("TradeVolume"),
93 },
94 params: Some(newself.params.clone()),
95 },
96 newself,
97 )
98 }
99}
100
101#[derive(Deserialize, Serialize, Debug)]
103pub struct KOFeeInfo {
104 pub fee: String,
105 pub minfee: Option<String>,
106 pub maxfee: Option<String>,
107 pub nextfee: Option<String>,
108 pub nextvolume: Option<String>,
109}
110
111#[derive(Deserialize, Serialize, Debug)]
113pub struct KOMakerFeeInfo {
114 pub fee: String,
115 pub minfee: Option<String>,
116 pub maxfee: Option<String>,
117 pub nextfee: Option<String>,
118 pub nextvolume: Option<String>,
119 pub tiervolume: Option<String>,
120}
121
122#[derive(Deserialize, Serialize, Debug)]
124pub struct KOTradeVolume {
125 pub currency: String,
126 pub volume: String,
127 pub fees: Option<HashMap<String, KOFeeInfo>>,
128 pub fees_maker: Option<HashMap<String, KOMakerFeeInfo>>,
129}
130
131impl Output for KOTradeVolume {}