use indexmap::map::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use super::{
EndpointInfo, Input, KAssetPair, KrakenInput, MethodType, MutateInput, Output, UpdateInput,
};
pub struct KIRecentTrades {
params: IndexMap<String, String>,
}
impl KIRecentTrades {
pub fn build(pair: KAssetPair) -> Self {
let recent_trades = KIRecentTrades {
params: IndexMap::new(),
};
recent_trades.update_pair(pair)
}
pub fn update_pair(self, pair: KAssetPair) -> Self {
self.update_input("pair", pair.to_string())
}
pub fn since(self, id: String) -> Self {
self.update_input("since", id)
}
}
impl Input for KIRecentTrades {
fn finish(self) -> KrakenInput {
KrakenInput {
info: EndpointInfo {
methodtype: MethodType::Public,
endpoint: String::from("Trades"),
},
params: Some(self.params),
}
}
fn finish_clone(self) -> (KrakenInput, Self) {
(
KrakenInput {
info: EndpointInfo {
methodtype: MethodType::Public,
endpoint: String::from("Trades"),
},
params: Some(self.params.clone()),
},
self,
)
}
}
impl MutateInput for KIRecentTrades {
fn list_mut(&mut self) -> &mut IndexMap<String, String> {
&mut self.params
}
}
impl UpdateInput for KIRecentTrades {}
#[derive(Deserialize, Serialize, Debug)]
pub struct KOTradeInfo {
pub price: String,
pub volume: String,
pub time: f64,
pub tradetype: String,
pub ordertype: String,
pub misc: String,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct KORecentTrades {
#[serde(flatten)]
pub pair: HashMap<KAssetPair, Vec<KOTradeInfo>>,
pub last: String,
}
impl Output for KORecentTrades {}