quantaxis_rs/
market_preset.rs

1use std::collections::HashMap;
2
3use regex::Regex;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Deserialize, Serialize, Clone)]
7pub struct CodePreset {
8    pub name: String,
9    pub unit_table: i32,
10    pub price_tick: f64,
11    pub buy_frozen_coeff: f64,
12    pub sell_frozen_coeff: f64,
13    pub exchange: String,
14    pub commission_coeff_peramount: f64,
15    pub commission_coeff_pervol: f64,
16    pub commission_coeff_today_peramount: f64,
17    pub commission_coeff_today_pervol: f64,
18}
19
20impl CodePreset {
21    pub fn calc_marketvalue(&mut self, price: f64, volume: f64) -> f64 {
22        volume * price * self.unit_table.clone() as f64
23    }
24
25    pub fn calc_frozenmoney(&mut self, price: f64, volume: f64) -> f64 {
26        self.calc_marketvalue(price.clone(), volume) * self.buy_frozen_coeff.clone()
27    }
28
29    pub fn calc_commission(&mut self, price: f64, volume: f64) -> f64 {
30        self.commission_coeff_pervol.clone() * volume.clone()
31            + self.commission_coeff_peramount.clone()
32            * self.calc_marketvalue(price.clone(), volume.clone())
33    }
34
35    pub fn calc_tax(&mut self, price: f64, volume: f64, towards: i32) -> f64 {
36        if &self.exchange == "STOCK" && towards < 0 {
37            0.001 * self.calc_marketvalue(price.clone(), volume.clone())
38        } else {
39            0.0
40        }
41    }
42
43    pub fn calc_commission_today(&mut self, price: f64, volume: f64) -> f64 {
44        self.commission_coeff_today_pervol.clone() * volume.clone()
45            + self.commission_coeff_today_peramount.clone()
46            * self.calc_marketvalue(price.clone(), volume.clone())
47    }
48    pub fn calc_coeff(&mut self) -> f64 {
49        self.buy_frozen_coeff.clone() * self.unit_table.clone() as f64
50    }
51
52    pub fn print(&mut self) {
53        println!(
54            "name {} / buy_frozen {} / sell_frozen {}",
55            self.name, self.buy_frozen_coeff, self.sell_frozen_coeff
56        )
57    }
58}
59
60#[derive(Debug, Deserialize, Serialize, Clone)]
61pub struct MarketPreset {
62    preset: HashMap<String, CodePreset>,
63}
64
65impl MarketPreset {
66    pub fn new() -> Self {
67        let mut market_preset: HashMap<String, CodePreset> = HashMap::new();
68        market_preset.insert(
69            "AG".to_string(),
70            CodePreset {
71                name: "白银".to_string(),
72                unit_table: 15,
73                price_tick: 1.0,
74                buy_frozen_coeff: 0.1,
75                sell_frozen_coeff:0.1,
76                exchange: "SHFE".to_string(),
77                commission_coeff_peramount: 5e-05,
78                commission_coeff_pervol:0.0,
79                commission_coeff_today_peramount: 5e-05,
80                commission_coeff_today_pervol: 0.0,
81            },
82        );
83        market_preset.insert(
84            "AL".to_string(),
85            CodePreset {
86                name: "铝".to_string(),
87                unit_table: 5,
88                price_tick: 5.0,
89                buy_frozen_coeff: 0.1,
90                sell_frozen_coeff:0.1,
91                exchange: "SHFE".to_string(),
92                commission_coeff_peramount: 0.0,
93                commission_coeff_pervol:3.0,
94                commission_coeff_today_peramount: 0.0,
95                commission_coeff_today_pervol: 0.0,
96            },
97        );
98        market_preset.insert(
99            "AU".to_string(),
100            CodePreset {
101                name: "黄金".to_string(),
102                unit_table: 1000,
103                price_tick: 0.02,
104                buy_frozen_coeff: 0.08,
105                sell_frozen_coeff:0.08,
106                exchange: "SHFE".to_string(),
107                commission_coeff_peramount: 0.0,
108                commission_coeff_pervol:10.0,
109                commission_coeff_today_peramount: 0.0,
110                commission_coeff_today_pervol: 0.0,
111            },
112        );
113        market_preset.insert(
114            "BU".to_string(),
115            CodePreset {
116                name: "石油沥青".to_string(),
117                unit_table: 10,
118                price_tick: 2.0,
119                buy_frozen_coeff: 0.15,
120                sell_frozen_coeff:0.15,
121                exchange: "SHFE".to_string(),
122                commission_coeff_peramount: 0.0001,
123                commission_coeff_pervol:0.0,
124                commission_coeff_today_peramount: 0.0001,
125                commission_coeff_today_pervol: 0.0,
126            },
127        );
128        market_preset.insert(
129            "CU".to_string(),
130            CodePreset {
131                name: "铜".to_string(),
132                unit_table: 5,
133                price_tick: 10.0,
134                buy_frozen_coeff: 0.1,
135                sell_frozen_coeff:0.1,
136                exchange: "SHFE".to_string(),
137                commission_coeff_peramount: 5e-05,
138                commission_coeff_pervol:0.0,
139                commission_coeff_today_peramount: 0.0,
140                commission_coeff_today_pervol: 0.0,
141            },
142        );
143        market_preset.insert(
144            "FU".to_string(),
145            CodePreset {
146                name: "燃料油".to_string(),
147                unit_table: 10,
148                price_tick: 1.0,
149                buy_frozen_coeff: 0.15,
150                sell_frozen_coeff:0.15,
151                exchange: "SHFE".to_string(),
152                commission_coeff_peramount: 5e-05,
153                commission_coeff_pervol:0.0,
154                commission_coeff_today_peramount: 0.0,
155                commission_coeff_today_pervol: 0.0,
156            },
157        );
158        market_preset.insert(
159            "HC".to_string(),
160            CodePreset {
161                name: "热轧卷板".to_string(),
162                unit_table: 10,
163                price_tick: 1.0,
164                buy_frozen_coeff: 0.09,
165                sell_frozen_coeff:0.09,
166                exchange: "SHFE".to_string(),
167                commission_coeff_peramount: 0.0001,
168                commission_coeff_pervol:0.0,
169                commission_coeff_today_peramount: 0.0001,
170                commission_coeff_today_pervol: 0.0,
171            },
172        );
173        market_preset.insert(
174            "NI".to_string(),
175            CodePreset {
176                name: "镍".to_string(),
177                unit_table: 1,
178                price_tick: 10.0,
179                buy_frozen_coeff: 0.1,
180                sell_frozen_coeff:0.1,
181                exchange: "SHFE".to_string(),
182                commission_coeff_peramount: 0.0,
183                commission_coeff_pervol:6.0,
184                commission_coeff_today_peramount: 0.0,
185                commission_coeff_today_pervol: 6.0,
186            },
187        );
188        market_preset.insert(
189            "PB".to_string(),
190            CodePreset {
191                name: "铅".to_string(),
192                unit_table: 5,
193                price_tick: 5.0,
194                buy_frozen_coeff: 0.1,
195                sell_frozen_coeff:0.1,
196                exchange: "SHFE".to_string(),
197                commission_coeff_peramount: 4e-05,
198                commission_coeff_pervol:0.0,
199                commission_coeff_today_peramount: 0.0,
200                commission_coeff_today_pervol: 0.0,
201            },
202        );
203        market_preset.insert(
204            "RB".to_string(),
205            CodePreset {
206                name: "螺纹钢".to_string(),
207                unit_table: 10,
208                price_tick: 1.0,
209                buy_frozen_coeff: 0.09,
210                sell_frozen_coeff:0.09,
211                exchange: "SHFE".to_string(),
212                commission_coeff_peramount: 0.0001,
213                commission_coeff_pervol:0.0,
214                commission_coeff_today_peramount: 0.0001,
215                commission_coeff_today_pervol: 0.0,
216            },
217        );
218        market_preset.insert(
219            "RU".to_string(),
220            CodePreset {
221                name: "天然橡胶".to_string(),
222                unit_table: 10,
223                price_tick: 5.0,
224                buy_frozen_coeff: 0.09,
225                sell_frozen_coeff:0.09,
226                exchange: "SHFE".to_string(),
227                commission_coeff_peramount: 4.5e-05,
228                commission_coeff_pervol:0.0,
229                commission_coeff_today_peramount: 4.5e-05,
230                commission_coeff_today_pervol: 0.0,
231            },
232        );
233        market_preset.insert(
234            "SN".to_string(),
235            CodePreset {
236                name: "锡".to_string(),
237                unit_table: 1,
238                price_tick: 10.0,
239                buy_frozen_coeff: 0.1,
240                sell_frozen_coeff:0.1,
241                exchange: "SHFE".to_string(),
242                commission_coeff_peramount: 0.0,
243                commission_coeff_pervol:1.0,
244                commission_coeff_today_peramount: 0.0,
245                commission_coeff_today_pervol: 0.0,
246            },
247        );
248        market_preset.insert(
249            "SP".to_string(),
250            CodePreset {
251                name: "漂针浆".to_string(),
252                unit_table: 10,
253                price_tick: 2.0,
254                buy_frozen_coeff: 0.08,
255                sell_frozen_coeff:0.08,
256                exchange: "SHFE".to_string(),
257                commission_coeff_peramount: 5e-05,
258                commission_coeff_pervol:0.0,
259                commission_coeff_today_peramount: 0.0,
260                commission_coeff_today_pervol: 0.0,
261            },
262        );
263        market_preset.insert(
264            "WR".to_string(),
265            CodePreset {
266                name: "线材".to_string(),
267                unit_table: 10,
268                price_tick: 1.0,
269                buy_frozen_coeff: 0.09,
270                sell_frozen_coeff:0.09,
271                exchange: "SHFE".to_string(),
272                commission_coeff_peramount: 4e-05,
273                commission_coeff_pervol:0.0,
274                commission_coeff_today_peramount: 0.0,
275                commission_coeff_today_pervol: 0.0,
276            },
277        );
278        market_preset.insert(
279            "ZN".to_string(),
280            CodePreset {
281                name: "锌".to_string(),
282                unit_table: 5,
283                price_tick: 5.0,
284                buy_frozen_coeff: 0.1,
285                sell_frozen_coeff:0.1,
286                exchange: "SHFE".to_string(),
287                commission_coeff_peramount: 0.0,
288                commission_coeff_pervol:3.0,
289                commission_coeff_today_peramount: 0.0,
290                commission_coeff_today_pervol: 0.0,
291            },
292        );
293        market_preset.insert(
294            "A".to_string(),
295            CodePreset {
296                name: "豆一".to_string(),
297                unit_table: 10,
298                price_tick: 1.0,
299                buy_frozen_coeff: 0.05,
300                sell_frozen_coeff:0.05,
301                exchange: "DCE".to_string(),
302                commission_coeff_peramount: 0.0,
303                commission_coeff_pervol:2.0,
304                commission_coeff_today_peramount: 0.0,
305                commission_coeff_today_pervol: 2.0,
306            },
307        );
308        market_preset.insert(
309            "B".to_string(),
310            CodePreset {
311                name: "豆二".to_string(),
312                unit_table: 10,
313                price_tick: 1.0,
314                buy_frozen_coeff: 0.05,
315                sell_frozen_coeff:0.05,
316                exchange: "DCE".to_string(),
317                commission_coeff_peramount: 0.0,
318                commission_coeff_pervol:1.0,
319                commission_coeff_today_peramount: 0.0,
320                commission_coeff_today_pervol: 1.0,
321            },
322        );
323        market_preset.insert(
324            "BB".to_string(),
325            CodePreset {
326                name: "细木工板".to_string(),
327                unit_table: 500,
328                price_tick: 0.05,
329                buy_frozen_coeff: 0.2,
330                sell_frozen_coeff:0.2,
331                exchange: "DCE".to_string(),
332                commission_coeff_peramount: 0.0001,
333                commission_coeff_pervol:0.0,
334                commission_coeff_today_peramount: 5e-05,
335                commission_coeff_today_pervol: 0.0,
336            },
337        );
338        market_preset.insert(
339            "C".to_string(),
340            CodePreset {
341                name: "黄玉米".to_string(),
342                unit_table: 10,
343                price_tick: 1.0,
344                buy_frozen_coeff: 0.05,
345                sell_frozen_coeff:0.05,
346                exchange: "DCE".to_string(),
347                commission_coeff_peramount: 0.0,
348                commission_coeff_pervol:1.2,
349                commission_coeff_today_peramount: 0.0,
350                commission_coeff_today_pervol: 0.0,
351            },
352        );
353        market_preset.insert(
354            "CS".to_string(),
355            CodePreset {
356                name: "玉米淀粉".to_string(),
357                unit_table: 10,
358                price_tick: 1.0,
359                buy_frozen_coeff: 0.05,
360                sell_frozen_coeff:0.05,
361                exchange: "DCE".to_string(),
362                commission_coeff_peramount: 0.0,
363                commission_coeff_pervol:1.5,
364                commission_coeff_today_peramount: 0.0,
365                commission_coeff_today_pervol: 0.0,
366            },
367        );
368        market_preset.insert(
369            "EG".to_string(),
370            CodePreset {
371                name: "乙二醇".to_string(),
372                unit_table: 10,
373                price_tick: 1.0,
374                buy_frozen_coeff: 0.06,
375                sell_frozen_coeff:0.06,
376                exchange: "DCE".to_string(),
377                commission_coeff_peramount: 0.0,
378                commission_coeff_pervol:4.0,
379                commission_coeff_today_peramount: 0.0,
380                commission_coeff_today_pervol: 0.0,
381            },
382        );
383        market_preset.insert(
384            "FB".to_string(),
385            CodePreset {
386                name: "中密度纤维板".to_string(),
387                unit_table: 500,
388                price_tick: 0.05,
389                buy_frozen_coeff: 0.2,
390                sell_frozen_coeff:0.2,
391                exchange: "DCE".to_string(),
392                commission_coeff_peramount: 0.0001,
393                commission_coeff_pervol:0.0,
394                commission_coeff_today_peramount: 5e-05,
395                commission_coeff_today_pervol: 0.0,
396            },
397        );
398        market_preset.insert(
399            "I".to_string(),
400            CodePreset {
401                name: "铁矿石".to_string(),
402                unit_table: 100,
403                price_tick: 0.5,
404                buy_frozen_coeff: 0.08,
405                sell_frozen_coeff:0.08,
406                exchange: "DCE".to_string(),
407                commission_coeff_peramount: 6e-05,
408                commission_coeff_pervol:0.0,
409                commission_coeff_today_peramount: 6e-05,
410                commission_coeff_today_pervol: 0.0,
411            },
412        );
413        market_preset.insert(
414            "J".to_string(),
415            CodePreset {
416                name: "冶金焦炭".to_string(),
417                unit_table: 100,
418                price_tick: 0.5,
419                buy_frozen_coeff: 0.08,
420                sell_frozen_coeff:0.08,
421                exchange: "DCE".to_string(),
422                commission_coeff_peramount: 0.00018,
423                commission_coeff_pervol:0.0,
424                commission_coeff_today_peramount: 0.00018,
425                commission_coeff_today_pervol: 0.0,
426            },
427        );
428        market_preset.insert(
429            "JD".to_string(),
430            CodePreset {
431                name: "鲜鸡蛋".to_string(),
432                unit_table: 10,
433                price_tick: 1.0,
434                buy_frozen_coeff: 0.07,
435                sell_frozen_coeff:0.07,
436                exchange: "DCE".to_string(),
437                commission_coeff_peramount: 0.00015,
438                commission_coeff_pervol:0.0,
439                commission_coeff_today_peramount: 0.00015,
440                commission_coeff_today_pervol: 0.0,
441            },
442        );
443        market_preset.insert(
444            "JM".to_string(),
445            CodePreset {
446                name: "焦煤".to_string(),
447                unit_table: 60,
448                price_tick: 0.5,
449                buy_frozen_coeff: 0.08,
450                sell_frozen_coeff:0.08,
451                exchange: "DCE".to_string(),
452                commission_coeff_peramount: 0.00018,
453                commission_coeff_pervol:0.0,
454                commission_coeff_today_peramount: 0.00018,
455                commission_coeff_today_pervol: 0.0,
456            },
457        );
458        market_preset.insert(
459            "L".to_string(),
460            CodePreset {
461                name: "线型低密度聚乙烯".to_string(),
462                unit_table: 5,
463                price_tick: 5.0,
464                buy_frozen_coeff: 0.05,
465                sell_frozen_coeff:0.05,
466                exchange: "DCE".to_string(),
467                commission_coeff_peramount: 0.0,
468                commission_coeff_pervol:2.0,
469                commission_coeff_today_peramount: 0.0,
470                commission_coeff_today_pervol: 0.0,
471            },
472        );
473        market_preset.insert(
474            "M".to_string(),
475            CodePreset {
476                name: "豆粕".to_string(),
477                unit_table: 10,
478                price_tick: 1.0,
479                buy_frozen_coeff: 0.05,
480                sell_frozen_coeff:0.05,
481                exchange: "DCE".to_string(),
482                commission_coeff_peramount: 0.0,
483                commission_coeff_pervol:1.5,
484                commission_coeff_today_peramount: 0.0,
485                commission_coeff_today_pervol: 0.0,
486            },
487        );
488        market_preset.insert(
489            "P".to_string(),
490            CodePreset {
491                name: "棕榈油".to_string(),
492                unit_table: 10,
493                price_tick: 2.0,
494                buy_frozen_coeff: 0.08,
495                sell_frozen_coeff:0.08,
496                exchange: "DCE".to_string(),
497                commission_coeff_peramount: 0.0,
498                commission_coeff_pervol:2.5,
499                commission_coeff_today_peramount: 0.0,
500                commission_coeff_today_pervol: 0.0,
501            },
502        );
503        market_preset.insert(
504            "PP".to_string(),
505            CodePreset {
506                name: "聚丙烯".to_string(),
507                unit_table: 5,
508                price_tick: 1.0,
509                buy_frozen_coeff: 0.05,
510                sell_frozen_coeff:0.05,
511                exchange: "DCE".to_string(),
512                commission_coeff_peramount: 6e-05,
513                commission_coeff_pervol:0.0,
514                commission_coeff_today_peramount: 3e-05,
515                commission_coeff_today_pervol: 0.0,
516            },
517        );
518        market_preset.insert(
519            "V".to_string(),
520            CodePreset {
521                name: "聚氯乙烯".to_string(),
522                unit_table: 5,
523                price_tick: 5.0,
524                buy_frozen_coeff: 0.05,
525                sell_frozen_coeff:0.05,
526                exchange: "DCE".to_string(),
527                commission_coeff_peramount: 0.0,
528                commission_coeff_pervol:2.0,
529                commission_coeff_today_peramount: 0.0,
530                commission_coeff_today_pervol: 0.0,
531            },
532        );
533        market_preset.insert(
534            "Y".to_string(),
535            CodePreset {
536                name: "豆油".to_string(),
537                unit_table: 10,
538                price_tick: 2.0,
539                buy_frozen_coeff: 0.05,
540                sell_frozen_coeff:0.05,
541                exchange: "DCE".to_string(),
542                commission_coeff_peramount: 0.0,
543                commission_coeff_pervol:2.5,
544                commission_coeff_today_peramount: 0.0,
545                commission_coeff_today_pervol: 0.0,
546            },
547        );
548        market_preset.insert(
549            "AP".to_string(),
550            CodePreset {
551                name: "鲜苹果".to_string(),
552                unit_table: 10,
553                price_tick: 1.0,
554                buy_frozen_coeff: 0.08,
555                sell_frozen_coeff:0.08,
556                exchange: "CZCE".to_string(),
557                commission_coeff_peramount: 0.0,
558                commission_coeff_pervol:5.0,
559                commission_coeff_today_peramount: 0.0,
560                commission_coeff_today_pervol: 5.0,
561            },
562        );
563        market_preset.insert(
564            "CF".to_string(),
565            CodePreset {
566                name: "一号棉花".to_string(),
567                unit_table: 5,
568                price_tick: 5.0,
569                buy_frozen_coeff: 0.05,
570                sell_frozen_coeff:0.05,
571                exchange: "CZCE".to_string(),
572                commission_coeff_peramount: 0.0,
573                commission_coeff_pervol:4.3,
574                commission_coeff_today_peramount: 0.0,
575                commission_coeff_today_pervol: 0.0,
576            },
577        );
578        market_preset.insert(
579            "CY".to_string(),
580            CodePreset {
581                name: "棉纱".to_string(),
582                unit_table: 5,
583                price_tick: 5.0,
584                buy_frozen_coeff: 0.05,
585                sell_frozen_coeff:0.05,
586                exchange: "CZCE".to_string(),
587                commission_coeff_peramount: 0.0,
588                commission_coeff_pervol:4.0,
589                commission_coeff_today_peramount: 0.0,
590                commission_coeff_today_pervol: 0.0,
591            },
592        );
593        market_preset.insert(
594            "FG".to_string(),
595            CodePreset {
596                name: "玻璃".to_string(),
597                unit_table: 20,
598                price_tick: 1.0,
599                buy_frozen_coeff: 0.05,
600                sell_frozen_coeff:0.05,
601                exchange: "CZCE".to_string(),
602                commission_coeff_peramount: 0.0,
603                commission_coeff_pervol:3.0,
604                commission_coeff_today_peramount: 0.0,
605                commission_coeff_today_pervol: 6.0,
606            },
607        );
608        market_preset.insert(
609            "JR".to_string(),
610            CodePreset {
611                name: "粳稻".to_string(),
612                unit_table: 20,
613                price_tick: 1.0,
614                buy_frozen_coeff: 0.05,
615                sell_frozen_coeff:0.05,
616                exchange: "CZCE".to_string(),
617                commission_coeff_peramount: 0.0,
618                commission_coeff_pervol:3.0,
619                commission_coeff_today_peramount: 0.0,
620                commission_coeff_today_pervol: 3.0,
621            },
622        );
623        market_preset.insert(
624            "LR".to_string(),
625            CodePreset {
626                name: "晚籼稻".to_string(),
627                unit_table: 20,
628                price_tick: 1.0,
629                buy_frozen_coeff: 0.05,
630                sell_frozen_coeff:0.05,
631                exchange: "CZCE".to_string(),
632                commission_coeff_peramount: 0.0,
633                commission_coeff_pervol:3.0,
634                commission_coeff_today_peramount: 0.0,
635                commission_coeff_today_pervol: 3.0,
636            },
637        );
638        market_preset.insert(
639            "MA".to_string(),
640            CodePreset {
641                name: "甲醇MA".to_string(),
642                unit_table: 10,
643                price_tick: 1.0,
644                buy_frozen_coeff: 0.07,
645                sell_frozen_coeff:0.07,
646                exchange: "CZCE".to_string(),
647                commission_coeff_peramount: 0.0,
648                commission_coeff_pervol:2.0,
649                commission_coeff_today_peramount: 0.0,
650                commission_coeff_today_pervol: 6.0,
651            },
652        );
653        market_preset.insert(
654            "OI".to_string(),
655            CodePreset {
656                name: "菜籽油".to_string(),
657                unit_table: 10,
658                price_tick: 1.0,
659                buy_frozen_coeff: 0.05,
660                sell_frozen_coeff:0.05,
661                exchange: "CZCE".to_string(),
662                commission_coeff_peramount: 0.0,
663                commission_coeff_pervol:2.0,
664                commission_coeff_today_peramount: 0.0,
665                commission_coeff_today_pervol: 0.0,
666            },
667        );
668        market_preset.insert(
669            "PM".to_string(),
670            CodePreset {
671                name: "普通小麦".to_string(),
672                unit_table: 50,
673                price_tick: 1.0,
674                buy_frozen_coeff: 0.05,
675                sell_frozen_coeff:0.05,
676                exchange: "CZCE".to_string(),
677                commission_coeff_peramount: 0.0,
678                commission_coeff_pervol:5.0,
679                commission_coeff_today_peramount: 0.0,
680                commission_coeff_today_pervol: 5.0,
681            },
682        );
683        market_preset.insert(
684            "RI".to_string(),
685            CodePreset {
686                name: "早籼".to_string(),
687                unit_table: 20,
688                price_tick: 1.0,
689                buy_frozen_coeff: 0.05,
690                sell_frozen_coeff:0.05,
691                exchange: "CZCE".to_string(),
692                commission_coeff_peramount: 0.0,
693                commission_coeff_pervol:2.5,
694                commission_coeff_today_peramount: 0.0,
695                commission_coeff_today_pervol: 2.5,
696            },
697        );
698        market_preset.insert(
699            "RM".to_string(),
700            CodePreset {
701                name: "菜籽粕".to_string(),
702                unit_table: 10,
703                price_tick: 1.0,
704                buy_frozen_coeff: 0.06,
705                sell_frozen_coeff:0.06,
706                exchange: "CZCE".to_string(),
707                commission_coeff_peramount: 0.0,
708                commission_coeff_pervol:1.5,
709                commission_coeff_today_peramount: 0.0,
710                commission_coeff_today_pervol: 0.0,
711            },
712        );
713        market_preset.insert(
714            "RS".to_string(),
715            CodePreset {
716                name: "油菜籽".to_string(),
717                unit_table: 10,
718                price_tick: 1.0,
719                buy_frozen_coeff: 0.2,
720                sell_frozen_coeff:0.2,
721                exchange: "CZCE".to_string(),
722                commission_coeff_peramount: 0.0,
723                commission_coeff_pervol:2.0,
724                commission_coeff_today_peramount: 0.0,
725                commission_coeff_today_pervol: 2.0,
726            },
727        );
728        market_preset.insert(
729            "SF".to_string(),
730            CodePreset {
731                name: "硅铁".to_string(),
732                unit_table: 5,
733                price_tick: 2.0,
734                buy_frozen_coeff: 0.07,
735                sell_frozen_coeff:0.07,
736                exchange: "CZCE".to_string(),
737                commission_coeff_peramount: 0.0,
738                commission_coeff_pervol:3.0,
739                commission_coeff_today_peramount: 0.0,
740                commission_coeff_today_pervol: 9.0,
741            },
742        );
743        market_preset.insert(
744            "SM".to_string(),
745            CodePreset {
746                name: "锰硅".to_string(),
747                unit_table: 5,
748                price_tick: 2.0,
749                buy_frozen_coeff: 0.07,
750                sell_frozen_coeff:0.07,
751                exchange: "CZCE".to_string(),
752                commission_coeff_peramount: 0.0,
753                commission_coeff_pervol:3.0,
754                commission_coeff_today_peramount: 0.0,
755                commission_coeff_today_pervol: 6.0,
756            },
757        );
758        market_preset.insert(
759            "SR".to_string(),
760            CodePreset {
761                name: "白砂糖".to_string(),
762                unit_table: 10,
763                price_tick: 1.0,
764                buy_frozen_coeff: 0.05,
765                sell_frozen_coeff:0.05,
766                exchange: "CZCE".to_string(),
767                commission_coeff_peramount: 0.0,
768                commission_coeff_pervol:3.0,
769                commission_coeff_today_peramount: 0.0,
770                commission_coeff_today_pervol: 0.0,
771            },
772        );
773        market_preset.insert(
774            "TA".to_string(),
775            CodePreset {
776                name: "精对苯二甲酸".to_string(),
777                unit_table: 5,
778                price_tick: 2.0,
779                buy_frozen_coeff: 0.06,
780                sell_frozen_coeff:0.06,
781                exchange: "CZCE".to_string(),
782                commission_coeff_peramount: 0.0,
783                commission_coeff_pervol:3.0,
784                commission_coeff_today_peramount: 0.0,
785                commission_coeff_today_pervol: 0.0,
786            },
787        );
788        market_preset.insert(
789            "WH".to_string(),
790            CodePreset {
791                name: "优质强筋小麦".to_string(),
792                unit_table: 20,
793                price_tick: 1.0,
794                buy_frozen_coeff: 0.2,
795                sell_frozen_coeff:0.2,
796                exchange: "CZCE".to_string(),
797                commission_coeff_peramount: 0.0,
798                commission_coeff_pervol:2.5,
799                commission_coeff_today_peramount: 0.0,
800                commission_coeff_today_pervol: 0.0,
801            },
802        );
803        market_preset.insert(
804            "ZC".to_string(),
805            CodePreset {
806                name: "动力煤ZC".to_string(),
807                unit_table: 100,
808                price_tick: 0.2,
809                buy_frozen_coeff: 0.06,
810                sell_frozen_coeff:0.06,
811                exchange: "CZCE".to_string(),
812                commission_coeff_peramount: 0.0,
813                commission_coeff_pervol:4.0,
814                commission_coeff_today_peramount: 0.0,
815                commission_coeff_today_pervol: 4.0,
816            },
817        );
818        market_preset.insert(
819            "SC".to_string(),
820            CodePreset {
821                name: "原油".to_string(),
822                unit_table: 1000,
823                price_tick: 0.1,
824                buy_frozen_coeff: 0.1,
825                sell_frozen_coeff:0.1,
826                exchange: "INE".to_string(),
827                commission_coeff_peramount: 0.0,
828                commission_coeff_pervol:20.0,
829                commission_coeff_today_peramount: 0.0,
830                commission_coeff_today_pervol: 0.0,
831            },
832        );
833        market_preset.insert(
834            "EB".to_string(),
835            CodePreset {
836                name: "苯乙烯".to_string(),
837                unit_table: 5,
838                price_tick: 1.0,
839                buy_frozen_coeff: 0.05,
840                sell_frozen_coeff:0.05,
841                exchange: "DCE".to_string(),
842                commission_coeff_peramount: 0.0001,
843                commission_coeff_pervol:0.0,
844                commission_coeff_today_peramount: 0.0001,
845                commission_coeff_today_pervol: 0.0,
846            },
847        );
848        market_preset.insert(
849            "RR".to_string(),
850            CodePreset {
851                name: "粳米".to_string(),
852                unit_table: 10,
853                price_tick: 1.0,
854                buy_frozen_coeff: 0.05,
855                sell_frozen_coeff:0.05,
856                exchange: "DCE".to_string(),
857                commission_coeff_peramount: 0.0001,
858                commission_coeff_pervol:0.0,
859                commission_coeff_today_peramount: 0.0001,
860                commission_coeff_today_pervol: 0.0,
861            },
862        );
863        market_preset.insert(
864            "NR".to_string(),
865            CodePreset {
866                name: "20号胶".to_string(),
867                unit_table: 10,
868                price_tick: 5.0,
869                buy_frozen_coeff: 0.09,
870                sell_frozen_coeff:0.09,
871                exchange: "INE".to_string(),
872                commission_coeff_peramount: 0.0001,
873                commission_coeff_pervol:0.0,
874                commission_coeff_today_peramount: 0.0001,
875                commission_coeff_today_pervol: 0.0,
876            },
877        );
878        market_preset.insert(
879            "SS".to_string(),
880            CodePreset {
881                name: "不锈钢".to_string(),
882                unit_table: 5,
883                price_tick: 5.0,
884                buy_frozen_coeff: 0.08,
885                sell_frozen_coeff:0.08,
886                exchange: "SHFE".to_string(),
887                commission_coeff_peramount: 0.0001,
888                commission_coeff_pervol:0.0,
889                commission_coeff_today_peramount: 0.0001,
890                commission_coeff_today_pervol: 0.0,
891            },
892        );
893        market_preset.insert(
894            "SA".to_string(),
895            CodePreset {
896                name: "纯碱".to_string(),
897                unit_table: 20,
898                price_tick: 1.0,
899                buy_frozen_coeff: 0.05,
900                sell_frozen_coeff:0.05,
901                exchange: "CZCE".to_string(),
902                commission_coeff_peramount: 0.0001,
903                commission_coeff_pervol:0.0,
904                commission_coeff_today_peramount: 0.0001,
905                commission_coeff_today_pervol: 0.0,
906            },
907        );
908        market_preset.insert(
909            "PG".to_string(),
910            CodePreset {
911                name: "液化石油气".to_string(),
912                unit_table: 20,
913                price_tick: 1.0,
914                buy_frozen_coeff: 0.05,
915                sell_frozen_coeff:0.05,
916                exchange: "DCE".to_string(),
917                commission_coeff_peramount: 0.0001,
918                commission_coeff_pervol:0.0,
919                commission_coeff_today_peramount: 0.0001,
920                commission_coeff_today_pervol: 0.0,
921            },
922        );
923        market_preset.insert(
924            "LU".to_string(),
925            CodePreset {
926                name: "低硫燃油".to_string(),
927                unit_table: 10,
928                price_tick: 1.0,
929                buy_frozen_coeff: 0.08,
930                sell_frozen_coeff:0.08,
931                exchange: "INE".to_string(),
932                commission_coeff_peramount: 0.0001,
933                commission_coeff_pervol:0.0,
934                commission_coeff_today_peramount: 0.0001,
935                commission_coeff_today_pervol: 0.0,
936            },
937        );
938        market_preset.insert(
939            "CJ".to_string(),
940            CodePreset {
941                name: "红枣".to_string(),
942                unit_table: 5,
943                price_tick: 5.0,
944                buy_frozen_coeff: 0.07,
945                sell_frozen_coeff:0.07,
946                exchange: "CZCE".to_string(),
947                commission_coeff_peramount: 0.0,
948                commission_coeff_pervol:3.0,
949                commission_coeff_today_peramount: 0.0,
950                commission_coeff_today_pervol: 3.0,
951            },
952        );
953        market_preset.insert(
954            "UR".to_string(),
955            CodePreset {
956                name: "尿素".to_string(),
957                unit_table: 20,
958                price_tick: 1.0,
959                buy_frozen_coeff: 0.05,
960                sell_frozen_coeff:0.05,
961                exchange: "CZCE".to_string(),
962                commission_coeff_peramount: 0.0001,
963                commission_coeff_pervol:0.0,
964                commission_coeff_today_peramount: 0.0001,
965                commission_coeff_today_pervol: 0.0,
966            },
967        );
968        market_preset.insert(
969            "IC".to_string(),
970            CodePreset {
971                name: "中证500指数".to_string(),
972                unit_table: 200,
973                price_tick: 0.2,
974                buy_frozen_coeff: 0.12,
975                sell_frozen_coeff:0.12,
976                exchange: "CFFEX".to_string(),
977                commission_coeff_peramount: 2.301e-05,
978                commission_coeff_pervol:0.0,
979                commission_coeff_today_peramount: 0.00034501,
980                commission_coeff_today_pervol: 0.0,
981            },
982        );
983        market_preset.insert(
984            "IF".to_string(),
985            CodePreset {
986                name: "沪深300指数".to_string(),
987                unit_table: 300,
988                price_tick: 0.2,
989                buy_frozen_coeff: 0.1,
990                sell_frozen_coeff:0.1,
991                exchange: "CFFEX".to_string(),
992                commission_coeff_peramount: 2.301e-05,
993                commission_coeff_pervol:0.0,
994                commission_coeff_today_peramount: 0.0001,
995                commission_coeff_today_pervol: 0.0,
996            },
997        );
998        market_preset.insert(
999            "IH".to_string(),
1000            CodePreset {
1001                name: "上证50指数".to_string(),
1002                unit_table: 300,
1003                price_tick: 0.2,
1004                buy_frozen_coeff: 0.05,
1005                sell_frozen_coeff:0.05,
1006                exchange: "CFFEX".to_string(),
1007                commission_coeff_peramount: 2.301e-05,
1008                commission_coeff_pervol:0.0,
1009                commission_coeff_today_peramount: 0.00034501,
1010                commission_coeff_today_pervol: 0.0,
1011            },
1012        );
1013        market_preset.insert(
1014            "T".to_string(),
1015            CodePreset {
1016                name: "10年期国债".to_string(),
1017                unit_table: 10000,
1018                price_tick: 0.005,
1019                buy_frozen_coeff: 0.02,
1020                sell_frozen_coeff:0.02,
1021                exchange: "CFFEX".to_string(),
1022                commission_coeff_peramount: 0.0001,
1023                commission_coeff_pervol:0.0,
1024                commission_coeff_today_peramount: 0.0001,
1025                commission_coeff_today_pervol: 0.0,
1026            },
1027        );
1028        market_preset.insert(
1029            "TF".to_string(),
1030            CodePreset {
1031                name: "5年期国债".to_string(),
1032                unit_table: 10000,
1033                price_tick: 0.005,
1034                buy_frozen_coeff: 0.012,
1035                sell_frozen_coeff:0.012,
1036                exchange: "CFFEX".to_string(),
1037                commission_coeff_peramount: 0.0001,
1038                commission_coeff_pervol:0.0,
1039                commission_coeff_today_peramount: 0.0001,
1040                commission_coeff_today_pervol: 0.0,
1041            },
1042        );
1043        market_preset.insert(
1044            "TS".to_string(),
1045            CodePreset {
1046                name: "2年期国债".to_string(),
1047                unit_table: 20000,
1048                price_tick: 0.005,
1049                buy_frozen_coeff: 0.005,
1050                sell_frozen_coeff:0.005,
1051                exchange: "CFFEX".to_string(),
1052                commission_coeff_peramount: 0.0001,
1053                commission_coeff_pervol:0.0,
1054                commission_coeff_today_peramount: 0.0001,
1055                commission_coeff_today_pervol: 0.0,
1056            },
1057        );
1058        market_preset.insert(
1059            "HU".to_string(),
1060            CodePreset {
1061                name: "火币Pro".to_string(),
1062                unit_table: 1,
1063                price_tick: 1.0,
1064                buy_frozen_coeff: 0.06,
1065                sell_frozen_coeff:0.06,
1066                exchange: "huobi".to_string(),
1067                commission_coeff_peramount: 0.002,
1068                commission_coeff_pervol:0.0,
1069                commission_coeff_today_peramount: 0.002,
1070                commission_coeff_today_pervol: 0.0,
1071            },
1072        );
1073        market_preset.insert(
1074            "OK".to_string(),
1075            CodePreset {
1076                name: "OKEx".to_string(),
1077                unit_table: 1,
1078                price_tick: 1.0,
1079                buy_frozen_coeff: 0.06,
1080                sell_frozen_coeff:0.06,
1081                exchange: "OKEx".to_string(),
1082                commission_coeff_peramount: 0.002,
1083                commission_coeff_pervol:0.0,
1084                commission_coeff_today_peramount: 0.002,
1085                commission_coeff_today_pervol: 0.0,
1086            },
1087        );
1088        market_preset.insert(
1089            "BI".to_string(),
1090            CodePreset {
1091                name: "Bianace".to_string(),
1092                unit_table: 1,
1093                price_tick: 1.0,
1094                buy_frozen_coeff: 0.06,
1095                sell_frozen_coeff:0.06,
1096                exchange: "binance".to_string(),
1097                commission_coeff_peramount: 0.002,
1098                commission_coeff_pervol:0.0,
1099                commission_coeff_today_peramount: 0.002,
1100                commission_coeff_today_pervol: 0.0,
1101            },
1102        );
1103        market_preset.insert(
1104            "BC".to_string(),
1105            CodePreset {
1106                name: "国际铜".to_string(),
1107                unit_table: 5,
1108                price_tick: 10.0,
1109                buy_frozen_coeff: 0.05,
1110                sell_frozen_coeff:0.05,
1111                exchange: "INE".to_string(),
1112                commission_coeff_peramount: 0.0001, 
1113                commission_coeff_pervol:0.0,
1114                commission_coeff_today_peramount: 0.0001,
1115                commission_coeff_today_pervol: 0.0,
1116            },
1117        );
1118        market_preset.insert(
1119            "PF".to_string(),
1120            CodePreset {
1121                name: "涤纶短纤".to_string(),
1122                unit_table: 5,
1123                price_tick: 2.0,
1124                buy_frozen_coeff: 0.05,
1125                sell_frozen_coeff:0.05,
1126                exchange: "CZCE".to_string(),
1127                commission_coeff_peramount: 0.0, 
1128                commission_coeff_pervol: 3.0,
1129                commission_coeff_today_peramount: 0.0,
1130                commission_coeff_today_pervol: 3.0,
1131            },
1132        );
1133        market_preset.insert(
1134            "LH".to_string(),
1135            CodePreset {
1136                name: "生猪".to_string(),
1137                unit_table: 16,
1138                price_tick: 5.0,
1139                buy_frozen_coeff: 0.05,
1140                sell_frozen_coeff:0.05,
1141                exchange: "DCE".to_string(),
1142                commission_coeff_peramount: 0.0, 
1143                commission_coeff_pervol: 3.0,
1144                commission_coeff_today_peramount: 0.0,
1145                commission_coeff_today_pervol: 3.0,
1146            },
1147        );
1148        MarketPreset {
1149            preset: market_preset,
1150        }
1151    }
1152
1153    pub fn get(&mut self, code: &str) -> CodePreset {
1154        let mut preset = CodePreset {
1155            name: code.to_string(),
1156            unit_table: 1,
1157            price_tick: 0.01,
1158            buy_frozen_coeff: 1.0,
1159            sell_frozen_coeff: 0.0,
1160            exchange: "STOCK".to_string(),
1161            commission_coeff_peramount: 0.00025,
1162            commission_coeff_pervol: 0.0,
1163            commission_coeff_today_peramount: 0.00025,
1164            commission_coeff_today_pervol: 0.0,
1165        };
1166
1167        let re = Regex::new(r"[a-zA-z]+").unwrap();
1168        if code.ends_with("L8") || code.ends_with("L9") {
1169            let lens = code.len();
1170            let codename = code.to_string().to_uppercase();
1171
1172            if self.preset.contains_key(&codename[0..lens - 2]) {
1173                preset = self
1174                    .preset
1175                    .get(&codename[0..lens - 2])
1176                    .unwrap()
1177                    .to_owned();
1178            }
1179        } else {
1180            let rcode = re.find(code);
1181            if rcode.is_some() {
1182                let codename = rcode.unwrap().as_str().to_uppercase();
1183
1184                if self.preset.contains_key(&codename) {
1185                    preset = self.preset.get(&codename).unwrap().to_owned();
1186                }
1187            }
1188        }
1189
1190        preset
1191    }
1192}