1use std::clone::Clone;
2use std::collections::{BTreeMap, HashMap};
3
4use serde::{Deserialize, Serialize};
5
6use crate::base::*;
7use crate::front::{HqTrend, HqTrendSlice};
8
9#[derive(Serialize, Clone, Deserialize, Debug)]
19pub struct Mifi<T> {
20 pub topic: String,
21 pub frq: f64,
22 pub market: String,
23 pub history: BTreeMap<String, T>,
24 pub portfolio: HashMap<String, T>,
25 pub format: String,
26 pub real: T,
27 pub zip: bool,
28}
29
30impl<T> Mifi<T>
31 where
32 T: Handler + Serialize,
33{
34 pub fn to_json(&self) -> String {
35 serde_json::to_string(&self).unwrap()
36 }
37
38 pub fn hqchart_trend(&self) -> HqTrend {
39 let slice: Vec<HqTrendSlice> = self.history.values().into_iter().map(|x| {
40 x.to_hqchart_trend_slice()
41 }).collect();
42 let code = slice.last().unwrap().code.clone();
43 let time = slice.last().unwrap().get_datetime();
44 HqTrend {
45 name: "".to_string(),
46 symbol: code,
47 time: slice.last().unwrap().get_datetime(),
48 date: time,
49 price: 0.0,
50 yclose: slice[0].open,
51 open: slice.last().unwrap().open,
52 high: slice.last().unwrap().high,
53 low: slice.last().unwrap().low,
54 vol: slice.last().unwrap().vol,
55 amount: slice.last().unwrap().amount,
56 minutecount: slice.len().clone() as f64,
57 minute: slice,
58 }
59 }
60}