mifi_rs/
market.rs

1use std::clone::Clone;
2use serde::{Deserialize, Serialize};
3use chrono::prelude::*;
4use crate::base::Handler;
5
6#[derive(Serialize, Deserialize, Debug)]
7pub struct FullData {
8    pub amount: f64,
9    pub close: f64,
10    pub code: String,
11    pub high: f64,
12    pub low: f64,
13    pub market: String,
14    pub open: f64,
15    pub productid: f64,
16    pub tickcount: f64,
17    pub time: String,
18    pub vol: f64,
19    pub BuyPrices: Vec<f64>,
20    pub BuyVols: Vec<f64>,
21    pub SellPrices: Vec<f64>,
22    pub SellVols: Vec<f64>,
23}
24
25impl Handler for FullData {
26    fn get_datetime(&self) -> String {
27        return self.time.clone();
28    }
29
30    fn get_code(&self) -> String {
31        self.code.clone()
32    }
33
34    fn get_date(&self) -> String {
35        unimplemented!()
36    }
37
38    fn get_open(&self) -> f64 {
39        self.open.clone()
40    }
41
42    fn get_close(&self) -> f64 {
43        self.close.clone()
44    }
45
46    fn get_high(&self) -> f64 {
47        self.high.clone()
48    }
49
50    fn get_low(&self) -> f64 {
51        self.low.clone()
52    }
53
54    fn get_vol(&self) -> f64 {
55        self.vol.clone()
56    }
57
58    fn get_amount(&self) -> f64 {
59        self.amount.clone()
60    }
61
62    fn set_datetime(&mut self, datetime: String) {
63        self.time = datetime;
64    }
65    fn set_open(&mut self, open: f64) {
66        self.open = open;
67    }
68
69    fn set_high(&mut self, high: f64) {
70        self.high = high;
71    }
72
73    fn set_low(&mut self, low: f64) {
74        self.low = low;
75    }
76    fn set_close(&mut self, close: f64) {
77        self.close = close
78    }
79    fn set_vol(&mut self, vol: f64) {
80        self.vol = vol;
81    }
82
83    fn set_amount(&mut self, amount: f64) {
84        self.amount = amount
85    }
86}
87
88impl Clone for FullData {
89    fn clone(&self) -> Self {
90        FullData {
91            amount: self.amount.clone(),
92            close: self.close.clone(),
93            code: self.code.clone(),
94            high: self.high.clone(),
95            low: self.low.clone(),
96            market: self.market.clone(),
97            open: self.open.clone(),
98            productid: self.productid.clone(),
99            tickcount: self.tickcount.clone(),
100            time: self.time.clone(),
101            vol: self.vol.clone(),
102            BuyPrices: self.BuyPrices.clone(),
103            BuyVols: self.BuyVols.clone(),
104            SellPrices: self.SellPrices.clone(),
105            SellVols: self.SellVols.clone(),
106        }
107    }
108}
109
110impl Default for FullData {
111    fn default() -> Self {
112        FullData {
113            amount: 0.0,
114            close: 0.0,
115            code: "".to_string(),
116            high: 0.0,
117            low: 0.0,
118            market: "".to_string(),
119            open: 0.0,
120            productid: 0.0,
121            tickcount: 0.0,
122            time: "1900-01-01 00:00:00".to_string(),
123            vol: 0.0,
124            BuyPrices: vec![],
125            BuyVols: vec![],
126            SellPrices: vec![],
127            SellVols: vec![],
128        }
129    }
130}
131
132#[derive(Serialize, Clone, Deserialize, Debug)]
133pub struct Full {
134    pub MarketFullName: String,
135    pub products: Vec<FullData>,
136}
137
138/// ctpx提供的数据源
139#[derive(Serialize, Clone, Deserialize, Debug)]
140pub struct CtpPro {
141    pub ask_price_1: f64,
142    pub ask_price_2: f64,
143    pub ask_price_3: f64,
144    pub ask_price_4: f64,
145    pub ask_price_5: f64,
146    pub ask_volume_1: f64,
147    pub ask_volume_2: f64,
148    pub ask_volume_3: f64,
149    pub ask_volume_4: f64,
150    pub ask_volume_5: f64,
151    pub average_price: f64,
152    pub bid_price_1: f64,
153    pub bid_price_2: f64,
154    pub bid_price_3: f64,
155    pub bid_price_4: f64,
156    pub bid_price_5: f64,
157    pub bid_volume_1: f64,
158    pub bid_volume_2: f64,
159    pub bid_volume_3: f64,
160    pub bid_volume_4: f64,
161    pub bid_volume_5: f64,
162    pub datetime: String,
163    pub exchange: String,
164    pub gateway_name: String,
165    pub high_price: f64,
166    pub last_price: f64,
167    pub last_volume: f64,
168    pub limit_down: f64,
169    pub limit_up: f64,
170    pub local_symbol: String,
171    pub low_price: f64,
172    pub name: String,
173    pub open_interest: f64,
174    pub open_price: f64,
175    pub preSettlementPrice: f64,
176    pub pre_close: f64,
177    pub symbol: String,
178    pub volume: f64,
179}
180
181impl Handler for CtpPro {
182    fn get_datetime(&self) -> String {
183        return self.datetime.clone();
184    }
185
186    fn get_code(&self) -> String {
187        self.symbol.clone().to_string()
188    }
189
190    fn get_date(&self) -> String {
191        self.datetime[0..9].parse().unwrap()
192    }
193
194    fn get_open(&self) -> f64 {
195        unimplemented!()
196    }
197
198    fn get_close(&self) -> f64 {
199        self.last_price.clone()
200    }
201
202    fn get_high(&self) -> f64 {
203        unimplemented!()
204    }
205
206    fn get_low(&self) -> f64 {
207        unimplemented!()
208    }
209
210    fn get_vol(&self) -> f64 {
211        self.volume.clone()
212    }
213
214    fn get_amount(&self) -> f64 {
215        0 as f64
216    }
217}
218
219impl Default for CtpPro {
220    fn default() -> Self {
221        CtpPro {
222            ask_price_1: 0.0,
223            ask_price_2: 0.0,
224            ask_price_3: 0.0,
225            ask_price_4: 0.0,
226            ask_price_5: 0.0,
227            ask_volume_1: 0.0,
228            ask_volume_2: 0.0,
229            ask_volume_3: 0.0,
230            ask_volume_4: 0.0,
231            ask_volume_5: 0.0,
232            average_price: 0.0,
233            bid_price_1: 0.0,
234            bid_price_2: 0.0,
235            bid_price_3: 0.0,
236            bid_price_4: 0.0,
237            bid_price_5: 0.0,
238            bid_volume_1: 0.0,
239            bid_volume_2: 0.0,
240            bid_volume_3: 0.0,
241            bid_volume_4: 0.0,
242            bid_volume_5: 0.0,
243            datetime: "1900-01-01 00:00:00.10000".to_string(),
244            exchange: "".to_string(),
245            gateway_name: "".to_string(),
246            high_price: 0.0,
247            last_price: 0.0,
248            last_volume: 0.0,
249            limit_down: 0.0,
250            limit_up: 0.0,
251            local_symbol: "".to_string(),
252            low_price: 0.0,
253            name: "".to_string(),
254            open_interest: 0.0,
255            open_price: 0.0,
256            preSettlementPrice: 0.0,
257            pre_close: 0.0,
258            symbol: "".to_string(),
259            volume: 0.0,
260        }
261    }
262}
263
264impl CtpPro {
265    pub fn to_diff(&self) -> Diff {
266        Diff {
267            instrument_id: self.local_symbol.clone(),
268            volume_multiple: 0,
269            price_tick: 0.0,
270            price_decs: 0,
271            max_market_order_volume: 0,
272            min_market_order_volume: 0,
273            max_limit_order_volume: 0,
274            min_limit_order_volume: 0,
275            margin: 0.0,
276            commission: 0.0,
277            datetime: "1900-01-01 00:00:00".to_string(),
278            ask_price1: 0.0,
279            ask_volume1: 0,
280            bid_price1: 0.0,
281            bid_volume1: 0,
282            last_price: 0.0,
283            highest: 0.0,
284            lowest: 0.0,
285            amount: 0.0,
286            volume: 0,
287            open_interest: 0,
288            pre_open_interest: 0,
289            pre_close: self.pre_close,
290            open: self.open_price.clone(),
291            close: 0.0,
292            lower_limit: 0.0,
293            upper_limit: 0.0,
294            average: 0.0,
295            pre_settlement: 0.0,
296            settlement: 0.0,
297        }
298    }
299}
300
301/// ---------------------------------------------------------------- StockDay------------------------------------------------------------------------
302#[derive(Serialize, Clone, Deserialize, Debug)]
303pub struct StockDay {
304    pub open: f64,
305    pub close: f64,
306    pub high: f64,
307    pub low: f64,
308    #[serde(rename = "vol")]
309    pub volume: f64,
310    pub amount: f64,
311    pub date: String,
312    pub code: String,
313//    date_stamp : f64
314}
315
316impl Default for StockDay {
317    fn default() -> Self {
318        StockDay {
319            open: 0.0,
320            close: 0.0,
321            high: 0.0,
322            low: 0.0,
323            volume: 0.0,
324            amount: 0.0,
325            date: "1900-01-01".to_string(),
326            code: "".to_string(),
327        }
328    }
329}
330
331impl Handler for StockDay {
332    fn get_datetime(&self) -> String {
333        unimplemented!()
334    }
335
336    fn get_code(&self) -> String {
337        self.code.clone()
338    }
339
340    fn get_date(&self) -> String {
341        self.date.clone()
342    }
343
344    fn get_open(&self) -> f64 {
345        self.open.clone()
346    }
347
348    fn get_close(&self) -> f64 {
349        self.close.clone()
350    }
351
352    fn get_high(&self) -> f64 {
353        self.high.clone()
354    }
355
356    fn get_low(&self) -> f64 {
357        self.low.clone()
358    }
359
360    fn get_vol(&self) -> f64 {
361        self.volume.clone()
362    }
363
364    fn get_amount(&self) -> f64 {
365        self.amount.clone()
366    }
367
368    fn set_code(&mut self, code: String) {
369        self.code = code;
370    }
371
372    fn set_date(&mut self, date: String) {
373        self.date = date;
374    }
375
376    fn set_open(&mut self, open: f64) {
377        self.open = open
378    }
379
380    fn set_close(&mut self, close: f64) {
381        self.close = close;
382    }
383
384    fn set_high(&mut self, high: f64) {
385        self.high = high;
386    }
387
388    fn set_low(&mut self, low: f64) {
389        self.low = low;
390    }
391
392    fn set_vol(&mut self, vol: f64) {
393        self.volume = vol;
394    }
395
396    fn set_amount(&mut self, amount: f64) {
397        self.amount = amount
398    }
399}
400
401/// ---------------------------------------------------------------- FutureDay------------------------------------------------------------------------
402#[derive(Serialize, Clone, Deserialize, Debug)]
403pub struct FutureDay {
404    pub open: f64,
405    pub close: f64,
406    pub high: f64,
407    pub low: f64,
408    #[serde(rename = "trade")]
409    pub volume: f64,
410    pub date: String,
411    pub code: String,
412}
413
414impl Default for FutureDay {
415    fn default() -> Self {
416        FutureDay {
417            open: 0.0,
418            close: 0.0,
419            high: 0.0,
420            low: 0.0,
421            volume: 0.0,
422            date: "1900-01-01".to_string(),
423            code: "".to_string(),
424        }
425    }
426}
427
428impl Handler for FutureDay {
429    fn get_datetime(&self) -> String {
430        unimplemented!()
431    }
432
433    fn get_code(&self) -> String {
434        self.code.clone()
435    }
436
437    fn get_date(&self) -> String {
438        self.date.clone()
439    }
440
441    fn get_open(&self) -> f64 {
442        self.open.clone()
443    }
444
445    fn get_close(&self) -> f64 {
446        self.close.clone()
447    }
448
449    fn get_high(&self) -> f64 {
450        self.high.clone()
451    }
452
453    fn get_low(&self) -> f64 {
454        self.low.clone()
455    }
456
457    fn get_vol(&self) -> f64 {
458        self.volume.clone()
459    }
460
461    fn get_amount(&self) -> f64 {
462        unimplemented!()
463    }
464
465    fn set_code(&mut self, code: String) {
466        self.code = code;
467    }
468
469    fn set_date(&mut self, date: String) {
470        self.date = date;
471    }
472
473    fn set_open(&mut self, open: f64) {
474        self.open = open
475    }
476
477    fn set_close(&mut self, close: f64) {
478        self.close = close;
479    }
480
481    fn set_high(&mut self, high: f64) {
482        self.high = high;
483    }
484
485    fn set_low(&mut self, low: f64) {
486        self.low = low;
487    }
488
489    fn set_vol(&mut self, vol: f64) {
490        self.volume = vol;
491    }
492
493    fn set_amount(&mut self, amount: f64) {
494        unimplemented!()
495    }
496}
497
498/// -------------------------------------------------------------------FutureMin ----------------------------------------------------------------------
499#[derive(Serialize, Clone, Deserialize, Debug)]
500pub struct FutureMin {
501    pub open: f64,
502    pub close: f64,
503    pub high: f64,
504    pub low: f64,
505    #[serde(rename = "trade")]
506    pub volume: f64,
507    pub date: String,
508    pub datetime: String,
509    pub code: String,
510    #[serde(rename = "type")]
511    pub frequence: String,
512    pub position: f64,
513    pub amount: f64,
514    pub tradetime: String,
515}
516
517
518impl Default for FutureMin {
519    fn default() -> Self {
520        FutureMin {
521            open: 0.0,
522            close: 0.0,
523            high: 0.0,
524            low: 0.0,
525            volume: 0.0,
526            date: "".to_string(),
527            datetime: "1900-01-01 00:00:00".to_string(),
528            code: "".to_string(),
529            frequence: "".to_string(),
530            position: 0.0,
531            amount: 0.0,
532            tradetime: "".to_string(),
533        }
534    }
535}
536
537impl Handler for FutureMin {
538    fn get_datetime(&self) -> String {
539        self.datetime.clone()
540    }
541
542    fn get_code(&self) -> String {
543        self.code.clone()
544    }
545
546    fn get_date(&self) -> String {
547        self.date.clone()
548    }
549
550    fn get_open(&self) -> f64 {
551        self.open.clone()
552    }
553
554    fn get_close(&self) -> f64 {
555        self.close.clone()
556    }
557
558    fn get_high(&self) -> f64 {
559        self.high.clone()
560    }
561
562    fn get_low(&self) -> f64 {
563        self.low.clone()
564    }
565
566    fn get_vol(&self) -> f64 {
567        self.volume.clone()
568    }
569
570    fn get_amount(&self) -> f64 {
571        self.amount.clone()
572    }
573}
574
575
576#[derive(Serialize, Clone, Deserialize, Debug)]
577pub struct StockMin {
578    pub open: f64,
579    pub close: f64,
580    pub high: f64,
581    pub low: f64,
582    #[serde(rename = "vol")]
583    pub volume: f64,
584    pub amount: f64,
585    pub date: String,
586    pub datetime: String,
587    pub code: String,
588    //    date_stamp : f64,
589//    time_stamp : f64,
590    #[serde(rename = "type")]
591    pub frequence: String,
592}
593
594impl Default for StockMin {
595    fn default() -> Self {
596        StockMin {
597            open: 0.0,
598            close: 0.0,
599            high: 0.0,
600            low: 0.0,
601            volume: 0.0,
602            amount: 0.0,
603            date: "".to_string(),
604            datetime: "".to_string(),
605            code: "".to_string(),
606            frequence: "".to_string(),
607        }
608    }
609}
610
611impl Handler for StockMin {
612    fn get_datetime(&self) -> String {
613        self.datetime.clone()
614    }
615
616    fn get_code(&self) -> String {
617        self.code.clone()
618    }
619
620    fn get_date(&self) -> String {
621        unimplemented!()
622    }
623
624    fn get_open(&self) -> f64 {
625        self.open.clone()
626    }
627
628    fn get_close(&self) -> f64 {
629        self.close.clone()
630    }
631
632    fn get_high(&self) -> f64 {
633        self.high.clone()
634    }
635
636    fn get_low(&self) -> f64 {
637        self.low.clone()
638    }
639
640    fn get_vol(&self) -> f64 {
641        self.volume.clone()
642    }
643
644    fn get_amount(&self) -> f64 {
645        self.amount.clone()
646    }
647}
648
649/// ------------------------------------------------------------ Diff --------------------------------------------------------------------
650#[derive(Serialize, Clone, Deserialize, Debug)]
651pub struct Diff {
652    instrument_id: String,
653    //合约代码
654    volume_multiple: i64,
655    //合约乘数
656    price_tick: f64,
657    //合约价格单位
658    price_decs: i64,
659    //合约价格小数位数
660    max_market_order_volume: i64,
661    //市价单最大下单手数
662    min_market_order_volume: i64,
663    //市价单最小下单手数
664    max_limit_order_volume: i64,
665    //限价单最大下单手数
666    min_limit_order_volume: i64,
667    //限价单最小下单手数
668    margin: f64,
669    //每手保证金
670    commission: f64,
671    //每手手续费
672    datetime: String,
673    //时间
674    ask_price1: f64,
675    //卖价
676    ask_volume1: i64,
677    //卖量
678    bid_price1: f64,
679    //买价
680    bid_volume1: i64,
681    //买量
682    last_price: f64,
683    //最新价
684    highest: f64,
685    //最高价
686    lowest: f64,
687    //最低价
688    amount: f64,
689    //成交额
690    volume: i64,
691    //成交量
692    open_interest: i64,
693    //持仓量
694    pre_open_interest: i64,
695    //昨持
696    pre_close: f64,
697    //昨收
698    open: f64,
699    //今开
700    close: f64,
701    //收盘
702    lower_limit: f64,
703    //跌停
704    upper_limit: f64,
705    //涨停
706    average: f64,
707    //均价
708    pre_settlement: f64,
709    //昨结
710    settlement: f64,                            //结算价
711}
712
713impl Default for Diff {
714    fn default() -> Self {
715        Diff {
716            instrument_id: "".to_string(),
717            volume_multiple: 0,
718            price_tick: 0.0,
719            price_decs: 0,
720            max_market_order_volume: 0,
721            min_market_order_volume: 0,
722            max_limit_order_volume: 0,
723            min_limit_order_volume: 0,
724            margin: 0.0,
725            commission: 0.0,
726            datetime: "1900-01-01 00:00:00.10000".to_string(),
727            ask_price1: 0.0,
728            ask_volume1: 0,
729            bid_price1: 0.0,
730            bid_volume1: 0,
731            last_price: 0.0,
732            highest: 0.0,
733            lowest: 0.0,
734            amount: 0.0,
735            volume: 0,
736            open_interest: 0,
737            pre_open_interest: 0,
738            pre_close: 0.0,
739            open: 0.0,
740            close: 0.0,
741            lower_limit: 0.0,
742            upper_limit: 0.0,
743            average: 0.0,
744            pre_settlement: 0.0,
745            settlement: 0.0,
746        }
747    }
748}
749
750#[derive(Serialize, Deserialize, Debug)]
751pub struct L2xHis
752{
753    pub time: String,
754    pub price: f64,
755    pub vol: f64,
756    pub buyorsell: f64,
757    pub date: String,
758    pub datetime: String,
759    pub code: String,
760    pub date_stamp: f64,
761    pub time_stamp: f64,
762    #[serde(rename(serialize = "type", deserialize = "type"))]   //type字段 实现与数据库中读取不进行冲突
763    pub type_: String,
764    pub order: f64,
765}
766
767impl Default for L2xHis {
768    fn default() -> Self {
769        L2xHis {
770            time: "25:00".to_string(),
771            price: 0.0,
772            vol: 0.0,
773            buyorsell: 0.0,
774            date: "1900-01-01".to_string(),
775            datetime: "1900-01-01 00:00:00".to_string(),
776            code: "".to_string(),
777            date_stamp: 0.0,
778            time_stamp: 0.0,
779            type_: "tick".to_string(),
780            order: 0.0,
781        }
782    }
783}
784
785impl Clone for L2xHis {
786    fn clone(&self) -> Self {
787        L2xHis {
788            time: self.time.clone(),
789            price: self.price.clone(),
790            vol: self.vol.clone(),
791            buyorsell: self.buyorsell.clone(),
792            date: self.date.clone(),
793            datetime: self.datetime.clone(),
794            code: self.code.clone(),
795            date_stamp: self.date_stamp.clone(),
796            time_stamp: self.time_stamp.clone(),
797            type_: self.type_.clone(),
798            order: self.order.clone(),
799        }
800    }
801}
802
803impl Handler for L2xHis {
804    fn get_datetime(&self) -> String {
805        self.datetime.clone()
806    }
807
808    fn get_code(&self) -> String {
809        self.code.clone()
810    }
811
812    fn get_date(&self) -> String {
813        self.date.clone()
814    }
815
816    fn get_open(&self) -> f64 {
817        unimplemented!()
818    }
819
820    fn get_close(&self) -> f64 {
821        self.price.clone()
822    }
823
824    fn get_high(&self) -> f64 {
825        unimplemented!()
826    }
827
828    fn get_low(&self) -> f64 {
829        unimplemented!()
830    }
831
832    fn get_vol(&self) -> f64 {
833        self.vol.clone()
834    }
835
836    fn get_amount(&self) -> f64 {
837        unimplemented!()
838    }
839}
840
841
842