新版仿ok交易所-后端
zj
2025-02-08 75018b2f492444248d8b476d9703bb312d2befc3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
package com.yami.trading.huobi.hobi.internal;
 
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.yami.trading.bean.data.domain.*;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.common.util.Arith;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.common.util.ThreadUtils;
import com.yami.trading.common.util.UTCDateUtils;
import com.yami.trading.huobi.data.internal.KlineConstant;
import com.yami.trading.huobi.data.internal.KlineService;
import com.yami.trading.huobi.data.model.TimeseriesResult;
import com.yami.trading.huobi.data.websocket.model.market.MarketDepthEvent;
import com.yami.trading.huobi.data.websocket.model.market.MarketTrade;
import com.yami.trading.huobi.data.websocket.model.market.MarketTradeEvent;
import com.yami.trading.huobi.data.websocket.model.market.PriceLevel;
import com.yami.trading.huobi.hobi.Config;
import com.yami.trading.huobi.hobi.HobiDataService;
import com.yami.trading.huobi.hobi.constant.TraderMadeOptions;
import com.yami.trading.huobi.hobi.http.HttpHelper;
import com.yami.trading.huobi.hobi.http.HttpMethodType;
import com.yami.trading.service.item.ItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.*;
 
@Component
public class HobiDataServiceImpl implements HobiDataService {
    private static Logger logger = LoggerFactory.getLogger(HobiDataServiceImpl.class);
 
    @Autowired
    private XueQiuDataServiceImpl xueQiuDataService;
    @Autowired
    private XinLangDataServiceImpl xinLangDataService;
    @Autowired
    private ItemService itemService;
    @Autowired
    private KlineService klineService;
    /**
     * 接口调用间隔(毫秒)
     */
    private int interval = 100;
 
    private int sleep = 100;
    /**
     * 最后一次访问接口时间
     */
    private volatile Date last_time = new Date();
 
    private volatile boolean lock = false;
 
    public static void main(String[] args) {
        HobiDataServiceImpl huobi = new HobiDataServiceImpl();
        Map<String, List<Kline>> etcusd = huobi.getDailyWeekMonthHistory("ETCUSD");
        System.out.println(etcusd);
    }
 
    // 针对虚拟货币的
    @Override
    public List<Realtime> realtime(int maximum) {
        List<Realtime> list = new ArrayList<Realtime>();
        boolean current_lock = false;
        if (lock || (new Date().getTime() - last_time.getTime()) < interval) {
            ThreadUtils.sleep(sleep);
            if (maximum >= 100) {
                return list;
            } else {
                return realtime(++maximum);
            }
 
        } else {
            try {
                current_lock = true;
                lock = true;
                Map<String, Object> param = new HashMap<String, Object>();
                String result = HttpHelper.getJSONFromHttp(Config.url + Config.tickers, param, HttpMethodType.GET);
                JSONObject resultJson = JSON.parseObject(result);
                String status = resultJson.getString("status");
                if ("ok".equals(status)) {
                    JSONArray dataArray = resultJson.getJSONArray("data");
                    Long ts = resultJson.getLongValue("ts");
                    for (int i = 0; i < dataArray.size(); i++) {
                        JSONObject realtimeJson = dataArray.getJSONObject(i);
                        Realtime realtime = new Realtime();
                        Item item = itemService.findBySymbol(realtimeJson.getString("symbol"));
                        if (item == null) {
                            continue;
                        }
                        realtime.setSymbol(item.getSymbol());
                        realtime.setName(item.getName());
                        realtime.setTs(ts);
                        realtime.setOpen(realtimeJson.getBigDecimal("open"));
                        realtime.setClose(realtimeJson.getBigDecimal("close"));
                        realtime.setHigh(realtimeJson.getBigDecimal("high"));
                        realtime.setLow(realtimeJson.getBigDecimal("low"));
                        realtime.setAmount(realtimeJson.getBigDecimal("amount"));
                        realtime.setVolume(realtimeJson.getBigDecimal("vol"));
                        list.add(realtime);
                    }
 
                } else {
                    logger.error(" realtime()error, resultJson [ " + resultJson.toJSONString() + " ]");
                }
            } catch (Exception e) {
                logger.error("error", e);
            } finally {
                if (current_lock) {
                    lock = false;
                    last_time = new Date();
                }
 
            }
        }
        return list;
    }
 
    @Override
    public List<Kline> kline(String symbol, String period, Integer num, int maximum) {
        List<Kline> list = new ArrayList<Kline>();
        Item item = itemService.findBySymbol(symbol);
        if (item == null) {
            return list;
        }
        boolean current_lock = false;
        if (lock || (new Date().getTime() - last_time.getTime()) < interval) {
            ThreadUtils.sleep(sleep);
            if (maximum >= 100) {
                return list;
            } else {
                return this.kline(symbol, period, num, ++maximum);
            }
 
        } else {
            try {
                current_lock = true;
                lock = true;
                Map<String, Object> param = new HashMap<String, Object>();
                param.put("symbol", symbol);
                param.put("period", period);
                if (num == null) {
                    if (Kline.PERIOD_1MIN.equals(period)) {
                        param.put("size", 1440);
                    }
                    if (Kline.PERIOD_5MIN.equals(period)) {
                        param.put("size", 576);
                    }
                    if (Kline.PERIOD_15MIN.equals(period)) {
                        param.put("size", 576);
                    }
                    if (Kline.PERIOD_30MIN.equals(period)) {
                        param.put("size", 576);
                    }
                    if (Kline.PERIOD_60MIN.equals(period)) {
                        param.put("size", 576);
                    }
 
                    if (Kline.PERIOD_4HOUR.equals(period)) {
                        param.put("size", 576);
                    }
                    if (Kline.PERIOD_1DAY.equals(period)) {
                        param.put("size", 500);
                    }
                    if (Kline.PERIOD_1MON.equals(period)) {
                        param.put("size", 500);
                    }
                    if (Kline.PERIOD_1WEEK.equals(period)) {
                        param.put("size", 500);
                    }
 
                } else {
                    param.put("size", num);
                }
 
                String result = HttpHelper.getJSONFromHttp(Config.url + Config.kline, param, HttpMethodType.GET);
                JSONObject resultJson = JSON.parseObject(result);
                String status = resultJson.getString("status");
                if ("ok".equals(status)) {
                    JSONArray dataArray = resultJson.getJSONArray("data");
                    /**
                     * 丢弃第一行数据
                     */
                    int start = 1;
                    if (num != null && num == 1) start = 0;
                    for (int i = start; i < dataArray.size(); i++) {
                        JSONObject realtimeJson = dataArray.getJSONObject(i);
                        Kline kline = new Kline();
                        kline.setSymbol(item.getSymbol());
                        kline.setPeriod(period);
                        kline.setTs(Long.valueOf(realtimeJson.getString("id") + "000"));
                        kline.setOpen(realtimeJson.getBigDecimal("open"));
                        kline.setClose(realtimeJson.getBigDecimal("close"));
                        kline.setHigh(realtimeJson.getBigDecimal("high"));
                        kline.setLow(realtimeJson.getBigDecimal("low"));
                        kline.setVolume(realtimeJson.getBigDecimal("vol"));
                        list.add(kline);
                    }
 
                }
            } catch (Exception e) {
                logger.error("error", e);
            } finally {
                if (current_lock) {
                    lock = false;
                    last_time = new Date();
                }
 
            }
        }
        return list;
    }
 
    /**
     * 市场深度数据(20档),包装,数据本地化处理
     */
    public Depth depthDecorator(String symbol, int maximum) {
        Depth depth = this.depth(symbol, maximum);
        Item item = itemService.findBySymbol(symbol);
        if ((depth == null || item.getAdjustmentValue() == null || item.getAdjustmentValue().intValue() == 0) && (item.getMultiple().intValue() == 0 || item.getMultiple().intValue() == 1)) {
            return depth;
        }
        if(CollectionUtil.isNotEmpty(depth.getAsks()) ){
            List<DepthEntry> asks = depth.getAsks();
            for (int i = 0; i < asks.size(); i++) {
                DepthEntry depthEntry = asks.get(i);
 
                /**
                 * 调整交易量倍数和 行情值
                 */
                if (item.getMultiple().doubleValue() > 0) {
                    depthEntry.setAmount(Arith.mul(depthEntry.getAmount(), item.getMultiple().doubleValue()));
                } else {
                    depthEntry.setAmount(depthEntry.getAmount());
                }
                depthEntry.setPrice(Arith.add(depthEntry.getPrice(), item.getAdjustmentValue().doubleValue()));
            }
        }
 
        if(CollectionUtil.isNotEmpty(depth.getBids())){
            List<DepthEntry> bids = depth.getBids();
            for (int i = 0; i < bids.size(); i++) {
                DepthEntry depthEntry = bids.get(i);
                /**
                 * 调整交易量倍数和 行情值
                 */
                if (item.getMultiple().doubleValue() > 0) {
                    depthEntry.setAmount(Arith.mul(depthEntry.getAmount(), item.getMultiple().doubleValue()));
                } else {
                    depthEntry.setAmount(depthEntry.getAmount());
                }
                depthEntry.setPrice(Arith.add(depthEntry.getPrice(), item.getAdjustmentValue().doubleValue()));
            }
        }
        return depth;
    }
 
    /**
     * 市场深度数据(20档),包装,数据本地化处理
     */
    public Depth depthDecorator(MarketDepthEvent event, Item item) {
        Depth depth = new Depth();
        depth.setSymbol(item.getSymbol());
        depth.setTs(event.getTs());
 
        double multiple = item.getMultiple().doubleValue() == 0 ? 1 : item.getMultiple().doubleValue();
        double adjustmentValue = item.getAdjustmentValue() == null ? 0 : item.getMultiple().doubleValue();
 
        for (PriceLevel priceLevel : event.getDepth().getAsks()) {
            DepthEntry depthEntry = new DepthEntry();
            depthEntry.setPrice(Arith.add(depthEntry.getPrice(), adjustmentValue));
            depthEntry.setAmount(Arith.mul(priceLevel.getAmount().doubleValue(), multiple));
            depth.getAsks().add(depthEntry);
        }
 
        for (PriceLevel priceLevel : event.getDepth().getBids()) {
            DepthEntry depthEntry = new DepthEntry();
            depthEntry.setPrice(Arith.add(depthEntry.getPrice(), adjustmentValue));
            depthEntry.setAmount(Arith.mul(priceLevel.getAmount().doubleValue(), multiple));
            depth.getBids().add(depthEntry);
        }
 
        return depth;
    }
 
    @Override
    public Depth depth(String symbol, int maximum) {
        boolean current_lock = false;
        if (StringUtils.isNullOrEmpty(symbol)) {
            return null;
        }
        if (lock || (new Date().getTime() - last_time.getTime()) < interval) {
            ThreadUtils.sleep(sleep);
            if (maximum >= 100) {
                return null;
            } else {
                return this.depth(symbol, ++maximum);
            }
        } else {
            try {
                current_lock = true;
                lock = true;
                Map<String, Object> param = new HashMap<String, Object>();
                param.put("symbol", symbol);
                param.put("type", "step2");
 
                String result = HttpHelper.getJSONFromHttp(Config.url + Config.depth, param, HttpMethodType.GET);
                JSONObject resultJson = JSON.parseObject(result);
                String status = resultJson.getString("status");
                if ("ok".equals(status)) {
                    JSONObject dataJson = resultJson.getJSONObject("tick");
                    Long ts = resultJson.getLongValue("ts");
                    Depth depth = new Depth();
 
                    Item item = itemService.findBySymbol(symbol);
                    if (item == null) {
                        return null;
                    }
                    depth.setSymbol(item.getSymbol());
                    depth.setTs(ts);
 
                    JSONArray bidsArray = dataJson.getJSONArray("bids");
                    for (int i = 0; i < bidsArray.size(); i++) {
 
                        JSONArray object = (JSONArray) bidsArray.get(i);
                        DepthEntry depthEntry = new DepthEntry();
                        depthEntry.setPrice(object.getDouble(0));
                        depthEntry.setAmount(object.getDouble(1));
                        depth.getBids().add(depthEntry);
 
                    }
 
                    JSONArray asksArray = dataJson.getJSONArray("asks");
                    for (int i = 0; i < asksArray.size(); i++) {
                        JSONArray object = (JSONArray) asksArray.get(i);
                        DepthEntry depthEntry = new DepthEntry();
                        depthEntry.setPrice(object.getDouble(0));
                        depthEntry.setAmount(object.getDouble(1));
                        depth.getAsks().add(depthEntry);
 
                    }
 
                    return depth;
                }
 
            } catch (Exception e) {
                logger.error("error", e);
            } finally {
                if (current_lock) {
                    lock = false;
                    last_time = new Date();
                }
 
            }
        }
        return null;
    }
 
    /**
     * 获得近期交易记录,包装,数据本地化处理
     */
    public Trade tradeDecorator(String symbol, int maximum) {
        Trade trade = this.trade(symbol, maximum);
        Item item = itemService.findBySymbol(symbol);
        if ((trade == null || item.getAdjustmentValue() == null || item.getAdjustmentValue().doubleValue() == 0) && (item.getMultiple().doubleValue() == 0 || item.getMultiple().doubleValue() == 1)) {
            return trade;
        }
        if(CollectionUtil.isNotEmpty(trade.getData())){
            List<TradeEntry> data = trade.getData();
            for (int i = 0; i < data.size(); i++) {
                TradeEntry tradeEntry = data.get(i);
 
                /**
                 * 调整交易量倍数和 行情值
                 */
                if (item.getMultiple().doubleValue() > 0) {
                    tradeEntry.setAmount(Arith.mul(tradeEntry.getAmount(), item.getMultiple().doubleValue()));
                } else {
                    tradeEntry.setAmount(tradeEntry.getAmount());
                }
                tradeEntry.setPrice(Arith.add(tradeEntry.getPrice(), item.getAdjustmentValue().doubleValue()));
            }
        }
        return trade;
 
    }
 
    /**
     * 获得近期交易记录,包装,数据本地化处理
     */
    public Trade tradeDecorator(MarketTradeEvent event, Item item) {
        Trade trade = new Trade();
        trade.setSymbol(item.getSymbol());
        trade.setTs(event.getTs());
        double multiple = item.getMultiple().doubleValue() == 0 ? 1 : item.getMultiple().doubleValue();
        double adjustmentValue = item.getAdjustmentValue() == null ? 0 : item.getMultiple().doubleValue();
        for (MarketTrade value : event.getList()) {
            TradeEntry entry = new TradeEntry();
            entry.setAmount(Arith.mul(value.getAmount().doubleValue(), multiple));
            entry.setPrice(Arith.add(value.getPrice().doubleValue(), adjustmentValue));
            entry.setTs(value.getTs());
            entry.setPrice(value.getPrice().doubleValue());
            entry.setAmount(value.getAmount().doubleValue());
            entry.setDirection(value.getDirection());
            trade.getData().add(entry);
        }
        return trade;
    }
 
    @Override
    public Trade trade(String symbol, int maximum) {
        boolean current_lock = false;
        if (StringUtils.isNullOrEmpty(symbol)) {
            return null;
        }
        if (lock || (new Date().getTime() - last_time.getTime()) < interval) {
            ThreadUtils.sleep(sleep);
            if (maximum >= 100) {
 
                return null;
            } else {
                return this.trade(symbol, ++maximum);
            }
        } else {
            try {
                current_lock = true;
                lock = true;
                Map<String, Object> param = new HashMap<String, Object>();
                param.put("symbol", symbol);
 
                String result = HttpHelper.getJSONFromHttp(Config.url + Config.trade, param, HttpMethodType.GET);
                JSONObject resultJson = JSON.parseObject(result);
                String status = resultJson.getString("status");
                if ("ok".equals(status)) {
                    JSONObject dataJson = resultJson.getJSONObject("tick");
                    Long ts = resultJson.getLongValue("ts");
 
                    Trade trade = new Trade();
 
                    Item item = itemService.findBySymbol(symbol);
                    if (item == null) {
                        return null;
                    }
                    trade.setSymbol(item.getSymbol());
                    trade.setTs(ts);
 
                    JSONArray dataArray = dataJson.getJSONArray("data");
                    for (int i = 0; i < dataArray.size(); i++) {
                        JSONObject object = dataArray.getJSONObject(i);
                        TradeEntry tradeEntry = new TradeEntry();
                        tradeEntry.setTs(object.getLong("ts"));
                        tradeEntry.setPrice(object.getDouble("price"));
                        tradeEntry.setAmount(object.getDouble("amount"));
                        tradeEntry.setDirection(object.getString("direction"));
                        trade.getData().add(tradeEntry);
 
                    }
                    return trade;
                }
 
            } catch (Exception e) {
                logger.error("error", e);
            } finally {
                if (current_lock) {
                    lock = false;
                    last_time = new Date();
                }
 
            }
        }
        return null;
    }
 
    @Override
    public List<Symbols> symbols() {
        List<Symbols> list = new ArrayList<Symbols>();
        boolean current_lock = false;
        if (lock || (new Date().getTime() - last_time.getTime()) < interval) {
 
            return list;
        } else {
            try {
                current_lock = true;
                lock = true;
                Map<String, Object> param = new HashMap<String, Object>();
                String result = HttpHelper.getJSONFromHttp(Config.url + Config.symbols, param, HttpMethodType.GET);
                JSONObject resultJson = JSON.parseObject(result);
                String status = resultJson.getString("status");
                if ("ok".equals(status)) {
                    JSONArray dataArray = resultJson.getJSONArray("data");
                    for (int i = 0; i < dataArray.size(); i++) {
                        JSONObject realtimeJson = dataArray.getJSONObject(i);
                        Symbols symbols = new Symbols();
                        symbols.setBaseCurrency(realtimeJson.getString("base-currency"));
                        symbols.setQuoteCurrency(realtimeJson.getString("quote-currency"));
                        symbols.setLeverageRatio(realtimeJson.getBigDecimal("leverage-ratio"));
                        symbols.setPricePrecision(realtimeJson.getIntValue("price-precision"));
                        symbols.setState(realtimeJson.getString("state"));
                        symbols.setSymbol(realtimeJson.getString("symbol"));
                        list.add(symbols);
                    }
 
                } else {
                    logger.error(" symbols()error, resultJson [ " + resultJson.toJSONString() + " ]");
                }
            } catch (Exception e) {
                logger.error("error", e);
            } finally {
                if (current_lock) {
                    lock = false;
                    last_time = new Date();
                }
 
            }
        }
        return list;
    }
 
    public void setItemService(ItemService itemService) {
        this.itemService = itemService;
    }
 
    public boolean isXueQiu(String symbol) {
        String type = itemService.findBySymbol(symbol).getType();
        return type.contains("stock") || (type.equalsIgnoreCase(Item.indices));
    }
 
    public boolean isXinlang(String symbol) {
        if("XAUUSD,XAGUSD,OIL".contains(symbol)){
            return false;
 
        }
        Item bySymbol = itemService.findBySymbol(symbol);
        String type = bySymbol.getType();
        return Item.forex.contains(type) && Item.forex.equals(bySymbol.getCategory());
    }
 
    public List<Realtime> realtimeSingle(String symbol) {
        if (isXueQiu(symbol)) {
            return xueQiuDataService.realtimeSingle(symbol);
        }
        if (isXinlang(symbol)) {
            return xinLangDataService.realtimeSingle(symbol);
        }
        List<Realtime> list = new ArrayList<Realtime>();
        try {
            Map<String, String> param = new HashMap<>();
            param.put("currency", symbol);
            String result = HttpHelper.getJSONFromHttpNew(TraderMadeOptions.live, param, HttpMethodType.GET);
            JSONObject resultJson = JSON.parseObject(result);
            String code = resultJson.getString("code");
            if ("ok".equals(code)) {
                JSONArray dataArray = resultJson.getJSONArray("data");
                for (int i = 0; i < dataArray.size(); i++) {
                    JSONObject realtimeJson = dataArray.getJSONObject(i);
                    Realtime realtime = new Realtime();
                    String currency = symbol;
                    currency = realtimeJson.getString("currency");
                    int decimal = itemService.getDecimal(currency);
                    realtime.setSymbol(currency);
                    realtime.setName(currency);
                    realtime.setTs(realtimeJson.getLong("timestamp"));
                    realtime.setOpen(realtimeJson.getBigDecimal("open").setScale(decimal, RoundingMode.HALF_UP));
                    realtime.setClose(realtimeJson.getBigDecimal("mid").setScale(decimal, RoundingMode.HALF_UP));
                    realtime.setHigh(realtimeJson.getBigDecimal("high").setScale(decimal, RoundingMode.HALF_UP));
                    realtime.setLow(realtimeJson.getBigDecimal("low").setScale(decimal, RoundingMode.HALF_UP));
                    realtime.setAmount(BigDecimal.ZERO);
                    realtime.setVolume(BigDecimal.ZERO);
                    realtime.setAsk(realtimeJson.getBigDecimal("ask").setScale(decimal, RoundingMode.HALF_UP));
                    realtime.setBid(realtimeJson.getBigDecimal("bid").setScale(decimal, RoundingMode.HALF_UP));
                    list.add(realtime);
                }
            } else {
                logger.error(" realtime()error, resultJson [ " + resultJson.toJSONString() + " ]");
            }
        } catch (Exception e) {
            logger.error("error", e);
        }
        return list;
    }
 
    public List<Realtime> realtime(String symbols) {
        List<Realtime> realtimeList = Collections.synchronizedList(new ArrayList<Realtime>());
        Splitter.on(",").omitEmptyStrings().splitToList(symbols).parallelStream().map(this::realtimeSingle).forEach(realtimeList::addAll);
        return realtimeList;
    }
 
    @Override
    public List<Realtime> realtimeXueQiu(String symbols) {
        return xueQiuDataService.realtimeSingle(symbols);
    }
 
    @Override
    public List<Realtime> realtimeXinLang(String symbols) {
        return xinLangDataService.realtimeSingle(symbols);
    }
 
    /**
     * 1day       历史数据  : 周期 1年
     * 1week,1mon 历史数据  : 周期 5年
     * 请求 350次
     */
    public Map<String, List<Kline>> getDailyWeekMonthHistory(String symbol) {
        if (isXueQiu(symbol)) {
            return xueQiuDataService.getDailyWeekMonthHistory(symbol);
        }else if(isXinlang(symbol)){
            return xinLangDataService.getDailyWeekMonthHistory(symbol);
 
        }
        Map<String, List<Kline>> map = new HashMap<>();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        f.setTimeZone(TimeZone.getTimeZone(UTCDateUtils.GMT_TIME_ZONE));
        Date now = new Date();
        // 每次只能取一年的数据,需要遍历5年
        for (int i = 0; i < TraderMadeOptions.weekAndMonthPeriod; i++) {
            String startDate = UTCDateUtils.addYear(now, -1);
            String endDate = f.format(now);
            now = UTCDateUtils.toDate(startDate, "yyyy-MM-dd");
 
            Map<String, String> param = new HashMap<>();
            param.put("currency", symbol);
            param.put("start_date", startDate);
            param.put("end_date", endDate);
            param.put("format", "records");
            param.put("api_key", TraderMadeOptions.apiKey);
            String json = null;
            try {
                json = HttpHelper.getJSONFromHttpNew(TraderMadeOptions.timeseries, param, HttpMethodType.GET);
            } catch (Exception e) {
                logger.error("采集外汇k线图失败:{} ", param);
                continue;
            }
 
            JSONObject resultJson = JSON.parseObject(json);
            JSONArray dataArray = resultJson.getJSONArray("quotes");
            if (dataArray.size() > 0) {
                List<TimeseriesResult> list = JSONObject.parseArray(JSONObject.toJSONString(dataArray), TimeseriesResult.class);
                Map<String, List<TimeseriesResult>> monthMap = new LinkedHashMap<>();
                Map<String, List<TimeseriesResult>> weekMap = new LinkedHashMap<>();
                for (TimeseriesResult result : list) {
                    String month = result.getDate().substring(0, 7);
                    if (monthMap.containsKey(month)) {
                        monthMap.get(month).add(result);
                    } else {
                        List<TimeseriesResult> monthList = new ArrayList<>();
                        monthList.add(result);
                        monthMap.put(month, monthList);
                    }
 
                    String firstDateOfWeek = UTCDateUtils.getFirstDateOfWeek(UTCDateUtils.toDate(result.getDate(), "yyyy-MM-dd"));
                    if (weekMap.containsKey(firstDateOfWeek)) {
                        weekMap.get(firstDateOfWeek).add(result);
                    } else {
                        List<TimeseriesResult> weekList = new ArrayList<>();
                        weekList.add(result);
                        weekMap.put(firstDateOfWeek, weekList);
                    }
                }
 
                map.put(Kline.PERIOD_1WEEK, buildOneWeekPeriod(weekMap, symbol));
                map.put(Kline.PERIOD_1MON, buildOneMonthPeriod(monthMap, symbol));
 
                // 1day历史数据  : 周期 1年
                if (0 == i) {
                    map.put(Kline.PERIOD_1DAY, buildOneDayPeriod(list, symbol));
                }
            }
        }
        try {
            List<Kline> dayList = map.get(Kline.PERIOD_1DAY);
            if (CollectionUtil.isNotEmpty(dayList)) {
                map.put(Kline.PERIOD_5DAY, klineService.calculateKline(symbol, 5, Kline.PERIOD_5DAY, dayList));
            }
            List<Kline> montList = map.get(Kline.PERIOD_1MON);
 
            if (CollectionUtil.isNotEmpty(montList)) {
                map.put(Kline.PERIOD_QUARTER, klineService.calculateKline(symbol, 3, Kline.PERIOD_1MON, montList));
            }
 
        } catch (Exception e) {
            logger.error("外汇计算 5日和季度k线图失败", e);
        }
 
 
        return map;
    }
 
 
    /**
     * 获取分钟数据
     */
    public Map<String, List<Kline>> getHourlyAndMinuteHistory(String symbol) {
        Map<String, List<Kline>> map = new HashMap<>();
 
        List<Kline> fourHourlyList = getTimeseriesForFourHourly(symbol);
        map.put(KlineConstant.PERIOD_4HOUR, fourHourlyList);
 
        List<Kline> oneHourlyList = getTimeseriesForOneHourly(symbol);
        map.put(KlineConstant.PERIOD_60MIN, oneHourlyList);
 
        List<Kline> twoHourlyList = getTimeseriesForTwoHourly(symbol);
        if (CollectionUtil.isEmpty(twoHourlyList)) {
            try {
                List<Kline> hourList = map.get(Kline.PERIOD_60MIN);
                if (CollectionUtil.isNotEmpty(hourList)) {
                    map.put(Kline.PERIOD_2HOUR, klineService.calculateKline(symbol, 2, Kline.PERIOD_2HOUR, hourList));
                }
            } catch (Exception e) {
                logger.error("外汇计算 120mink线图失败", e);
            }
        } else {
            map.put(KlineConstant.PERIOD_2HOUR, twoHourlyList);
 
        }
 
 
        List<Kline> thirtyMinuteList = getTimeseriesThirtyMinute(symbol);
        map.put(KlineConstant.PERIOD_30MIN, thirtyMinuteList);
 
        List<Kline> fifteenMinuteList = getTimeseriesFifteenMinute(symbol);
        map.put(KlineConstant.PERIOD_15MIN, fifteenMinuteList);
 
        List<Kline> fiveMinuteList = getTimeseriesFiveMinute(symbol);
        map.put(KlineConstant.PERIOD_5MIN, fiveMinuteList);
 
        List<Kline> oneMinuteList = getTimeseriesOneMinute(symbol);
        map.put(KlineConstant.PERIOD_1MIN, oneMinuteList);
        return map;
    }
 
    public List<Kline> buildOneDayPeriod(List<TimeseriesResult> list, String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.buildOneDayPeriod(currency);
        }if (isXinlang(currency)) {
            return xinLangDataService.buildOneDayPeriod(currency);
        }
        List<Kline> resList = new ArrayList<>();
        for (TimeseriesResult result : list) {
            Kline kline = new Kline();
            kline.setSymbol(currency);
            kline.setPeriod(Kline.PERIOD_1DAY);
            kline.setTs(UTCDateUtils.toDate(result.getDate(), "yyyy-MM-dd").getTime());
            kline.setOpen(result.getOpen());
            kline.setClose(result.getClose());
            kline.setHigh(result.getHigh());
            kline.setLow(result.getLow());
            kline.setVolume(BigDecimal.ZERO);
            resList.add(kline);
        }
        return resList;
    }
 
 
 
    public List<Kline> buildOneWeekPeriod(Map<String, List<TimeseriesResult>> weekMap, String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.buildOneWeekPeriod(currency);
        }
 
        List<Kline> resList = new ArrayList<>();
        for (List<TimeseriesResult> list : weekMap.values()) {
            BigDecimal high = list.stream().map(TimeseriesResult::getHigh).filter(Objects::nonNull).max(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
            BigDecimal low = list.stream().map(TimeseriesResult::getLow).filter(Objects::nonNull).min(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
            Kline kline = new Kline();
            kline.setSymbol(currency);
            kline.setPeriod(Kline.PERIOD_1WEEK);
            // 毫秒
            kline.setTs(UTCDateUtils.toDate(list.get(list.size() - 1).getDate()).getTime());
            kline.setOpen(list.get(0).getOpen());
            kline.setClose(list.get(list.size() - 1).getClose());
            kline.setHigh(high);
            kline.setLow(low);
            kline.setVolume(BigDecimal.ZERO);
            resList.add(kline);
        }
        return resList;
    }
 
    public List<Kline> buildOneMonthPeriod(Map<String, List<TimeseriesResult>> monthMap, String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.buildOneMonthPeriod(currency);
        }
        List<Kline> resList = new ArrayList<>();
        for (List<TimeseriesResult> list : monthMap.values()) {
            BigDecimal high = list.stream().map(TimeseriesResult::getHigh).filter(Objects::nonNull).max(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
            BigDecimal low = list.stream().map(TimeseriesResult::getLow).filter(Objects::nonNull).min(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
            Kline kline = new Kline();
            kline.setSymbol(currency);
            kline.setPeriod(Kline.PERIOD_1MON);
            // 毫秒
            kline.setTs(UTCDateUtils.toDate(list.get(list.size() - 1).getDate()).getTime());
            kline.setOpen(list.get(0).getOpen());
            kline.setClose(list.get(list.size() - 1).getClose());
            kline.setHigh(high);
            kline.setLow(low);
            kline.setVolume(BigDecimal.ZERO);
            resList.add(kline);
        }
        return resList;
    }
 
    public List<Kline> buildQuarterPeriod(Map<String, List<TimeseriesResult>> quarterMap, String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.buildOneMonthPeriod(currency);
        }
        List<Kline> resList = new ArrayList<>();
        for (List<TimeseriesResult> list : quarterMap.values()) {
            BigDecimal high = list.stream().map(TimeseriesResult::getHigh).filter(Objects::nonNull).max(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
            BigDecimal low = list.stream().map(TimeseriesResult::getLow).filter(Objects::nonNull).min(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
            Kline kline = new Kline();
            kline.setSymbol(currency);
            kline.setPeriod(Kline.PERIOD_QUARTER);
            // 毫秒
            kline.setTs(UTCDateUtils.toDate(list.get(list.size() - 1).getDate()).getTime());
            kline.setOpen(list.get(0).getOpen());
            kline.setClose(list.get(list.size() - 1).getClose());
            kline.setHigh(high);
            kline.setLow(low);
            kline.setVolume(BigDecimal.ZERO);
            resList.add(kline);
        }
        return resList;
    }
 
    public List<Kline> buildYearPeriod(Map<String, List<TimeseriesResult>> yearMap, String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.buildOneMonthPeriod(currency);
        }
        List<Kline> resList = new ArrayList<>();
        for (List<TimeseriesResult> list : yearMap.values()) {
            BigDecimal high = list.stream().map(TimeseriesResult::getHigh).filter(Objects::nonNull).max(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
            BigDecimal low = list.stream().map(TimeseriesResult::getLow).filter(Objects::nonNull).min(BigDecimal::compareTo).orElse(BigDecimal.ZERO);
            Kline kline = new Kline();
            kline.setSymbol(currency);
            kline.setPeriod(Kline.PERIOD_YEAR);
            // 毫秒
            kline.setTs(UTCDateUtils.toDate(list.get(list.size() - 1).getDate()).getTime());
            kline.setOpen(list.get(0).getOpen());
            kline.setClose(list.get(list.size() - 1).getClose());
            kline.setHigh(high);
            kline.setLow(low);
            kline.setVolume(BigDecimal.ZERO);
            resList.add(kline);
        }
        return resList;
    }
 
    /**
     * Hourly
     * 4hourly 3月
     */
    public List<Kline> getTimeseriesForFourHourly(String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.getTimeseriesForFourHourly(currency);
        } else if (isXinlang(currency)) {
            return xinLangDataService.getTimeseriesForFourHourly(currency);
 
        }
        List<Kline> resList = new ArrayList<>();
        // 每次只能取一个月的数据,需要遍历3个月
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH:mm");
        f.setTimeZone(TimeZone.getTimeZone(UTCDateUtils.GMT_TIME_ZONE));
        // Date now = UTCDateUtils.toDate(UTCDateUtils.addHour(new Date(), -4), "yyyy-MM-dd-HH:mm");
        Date now = new Date();
        for (int i = 0; i < TraderMadeOptions.fourHourlyPeriod; i++) {
            String startDate = UTCDateUtils.addDay(now, -30);
            String endDate = f.format(now);
            now = UTCDateUtils.toDate(startDate, "yyyy-MM-dd-HH:mm");
 
            Map<String, String> param = new HashMap<>();
            param.put("currency", currency);
            param.put("start_date", startDate);
            param.put("end_date", endDate);
            param.put("interval", "hourly");
            param.put("period", "4");
            param.put("format", "records");
            param.put("api_key", TraderMadeOptions.apiKey);
            String json = HttpHelper.getJSONFromHttpNew(TraderMadeOptions.timeseries, param, HttpMethodType.GET);
            JSONObject resultJson = JSON.parseObject(json);
            JSONArray dataArray = resultJson.getJSONArray("quotes");
            if (dataArray.size() > 0) {
                List<TimeseriesResult> list = JSONObject.parseArray(JSONObject.toJSONString(dataArray), TimeseriesResult.class);
                for (TimeseriesResult result : list) {
                    Kline kline = new Kline();
                    kline.setSymbol(currency);
                    kline.setPeriod(Kline.PERIOD_4HOUR);
                    // 毫秒
                    kline.setTs(UTCDateUtils.toDate(result.getDate(), "yyyy-MM-dd HH:mm").getTime());
                    kline.setOpen(result.getOpen());
                    kline.setClose(result.getClose());
                    kline.setHigh(result.getHigh());
                    kline.setLow(result.getLow());
                    kline.setVolume(BigDecimal.ZERO);
                    resList.add(kline);
                }
            }
        }
        return resList;
    }
 
    /**
     * Hourly
     * 1hourly 1月
     */
    public List<Kline> getTimeseriesForOneHourly(String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.getTimeseriesForOneHourly(currency);
        }
        if (isXinlang(currency)) {
            return xinLangDataService.getTimeseriesForOneHourly(currency);
        }
        List<Kline> resList = new ArrayList<>();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH:mm");
        f.setTimeZone(TimeZone.getTimeZone(UTCDateUtils.GMT_TIME_ZONE));
        // Date now = UTCDateUtils.toDate(UTCDateUtils.addHour(new Date(), -1), "yyyy-MM-dd-HH:mm");
        Date now = new Date();
        String startDate = UTCDateUtils.addDay(now, -30);
        String endDate = f.format(now);
 
        Map<String, String> param = new HashMap<>();
        param.put("currency", currency);
        param.put("start_date", startDate);
        param.put("end_date", endDate);
        param.put("interval", "hourly");
        param.put("period", "1");
        param.put("format", "records");
        param.put("api_key", TraderMadeOptions.apiKey);
        String json = HttpHelper.getJSONFromHttpNew(TraderMadeOptions.timeseries, param, HttpMethodType.GET);
        JSONObject resultJson = JSON.parseObject(json);
        JSONArray dataArray = resultJson.getJSONArray("quotes");
        if (dataArray.size() > 0) {
            List<TimeseriesResult> list = JSONObject.parseArray(JSONObject.toJSONString(dataArray), TimeseriesResult.class);
            for (TimeseriesResult result : list) {
                Kline kline = new Kline();
                kline.setSymbol(currency);
                kline.setPeriod(Kline.PERIOD_60MIN);
                // 毫秒
                kline.setTs(UTCDateUtils.toDate(result.getDate(), "yyyy-MM-dd HH:mm").getTime());
                kline.setOpen(result.getOpen());
                kline.setClose(result.getClose());
                kline.setHigh(result.getHigh());
                kline.setLow(result.getLow());
                kline.setVolume(BigDecimal.ZERO);
                resList.add(kline);
            }
        }
        return resList;
    }
 
    @Override
    public List<Kline> getTimeseriesForTwoHourly(String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.getTimeseriesForTwoHourly(currency);
        }
        if (isXinlang(currency)) {
            return xinLangDataService.getTimeseriesForTwoHourly(currency);
        }
        return Lists.newArrayList();
    }
 
    /**
     * Minute
     * 30minute 10天
     * 15minute 5天
     * 5minute  2天
     * 1minute  1天
     */
    public List<Kline> getTimeseriesOneMinute(String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.getTimeseriesOneMinute(currency);
        }
        if (isXinlang(currency)) {
            return xinLangDataService.getTimeseriesOneMinute(currency);
        }
        List<Kline> resList = new ArrayList<>();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH:mm");
        f.setTimeZone(TimeZone.getTimeZone(UTCDateUtils.GMT_TIME_ZONE));
        Date now = new Date();
        String startDate = UTCDateUtils.addDay(now, -1);
        String endDate = f.format(now);
 
        Map<String, String> param = new HashMap<>();
        param.put("currency", currency);
        param.put("start_date", startDate);
        param.put("end_date", endDate);
        param.put("interval", "minute");
        param.put("period", "1");
        param.put("format", "records");
        param.put("api_key", TraderMadeOptions.apiKey);
        String json = HttpHelper.getJSONFromHttpNew(TraderMadeOptions.timeseries, param, HttpMethodType.GET);
        JSONObject resultJson = JSON.parseObject(json);
        JSONArray dataArray = resultJson.getJSONArray("quotes");
        if (dataArray.size() > 0) {
            List<TimeseriesResult> list = JSONObject.parseArray(JSONObject.toJSONString(dataArray), TimeseriesResult.class);
            for (TimeseriesResult result : list) {
                Kline kline = new Kline();
                kline.setSymbol(currency);
                kline.setPeriod(Kline.PERIOD_1MIN);
                // 毫秒
                kline.setTs(UTCDateUtils.toDate(result.getDate(), "yyyy-MM-dd HH:mm").getTime());
                kline.setOpen(result.getOpen());
                kline.setClose(result.getClose());
                kline.setHigh(result.getHigh());
                kline.setLow(result.getLow());
                kline.setVolume(BigDecimal.ZERO);
                resList.add(kline);
            }
        }
        return resList;
    }
 
    /**
     * Minute
     * 30minute 10天
     * 15minute 5天
     * 5minute  2天
     * 1minute  1天
     */
    public List<Kline> getTimeseriesFiveMinute(String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.getTimeseriesFiveMinute(currency);
        }
        if (isXinlang(currency)) {
            return xinLangDataService.getTimeseriesFiveMinute(currency);
        }
        List<Kline> resList = new ArrayList<>();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH:mm");
        f.setTimeZone(TimeZone.getTimeZone(UTCDateUtils.GMT_TIME_ZONE));
        Date now = new Date();
        String startDate = UTCDateUtils.addDay(now, -2);
        String endDate = f.format(now);
 
        Map<String, String> param = new HashMap<>();
        param.put("currency", currency);
        param.put("start_date", startDate);
        param.put("end_date", endDate);
        param.put("interval", "minute");
        param.put("period", "5");
        param.put("format", "records");
        param.put("api_key", TraderMadeOptions.apiKey);
        String json = HttpHelper.getJSONFromHttpNew(TraderMadeOptions.timeseries, param, HttpMethodType.GET);
        JSONObject resultJson = JSON.parseObject(json);
        JSONArray dataArray = resultJson.getJSONArray("quotes");
        if (dataArray.size() > 0) {
            List<TimeseriesResult> list = JSONObject.parseArray(JSONObject.toJSONString(dataArray), TimeseriesResult.class);
            for (TimeseriesResult result : list) {
                Kline kline = new Kline();
                kline.setSymbol(currency);
                kline.setPeriod(Kline.PERIOD_5MIN);
                // 毫秒
                kline.setTs(UTCDateUtils.toDate(result.getDate(), "yyyy-MM-dd HH:mm").getTime());
                kline.setOpen(result.getOpen());
                kline.setClose(result.getClose());
                kline.setHigh(result.getHigh());
                kline.setLow(result.getLow());
                kline.setVolume(BigDecimal.ZERO);
                resList.add(kline);
            }
        }
        return resList;
    }
 
    /**
     * Minute
     * 30minute 10天
     * 15minute 5天
     * 5minute  2天
     * 1minute  1天
     */
    public List<Kline> getTimeseriesFifteenMinute(String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.getTimeseriesFifteenMinute(currency);
        }
        if (isXinlang(currency)) {
            return xinLangDataService.getTimeseriesFifteenMinute(currency);
        }
        List<Kline> resList = new ArrayList<>();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH:mm");
        f.setTimeZone(TimeZone.getTimeZone(UTCDateUtils.GMT_TIME_ZONE));
        Date now = new Date();
        for (int i = 0; i < TraderMadeOptions.fifteenMinutePeriod; i++) {
            String startDate = UTCDateUtils.addDay(now, -2);
            String endDate = f.format(now);
            now = UTCDateUtils.toDate(startDate, "yyyy-MM-dd-HH:mm");
            Map<String, String> param = new HashMap<>();
            param.put("currency", currency);
            param.put("start_date", startDate);
            param.put("end_date", endDate);
            param.put("interval", "minute");
            param.put("period", "15");
            param.put("format", "records");
            param.put("api_key", TraderMadeOptions.apiKey);
            String json = HttpHelper.getJSONFromHttpNew(TraderMadeOptions.timeseries, param, HttpMethodType.GET);
            JSONObject resultJson = JSON.parseObject(json);
            JSONArray dataArray = resultJson.getJSONArray("quotes");
            if (dataArray.size() > 0) {
                List<TimeseriesResult> list = JSONObject.parseArray(JSONObject.toJSONString(dataArray), TimeseriesResult.class);
                for (TimeseriesResult result : list) {
                    Kline kline = new Kline();
                    kline.setSymbol(currency);
                    kline.setPeriod(Kline.PERIOD_15MIN);
                    // 毫秒
                    kline.setTs(UTCDateUtils.toDate(result.getDate(), "yyyy-MM-dd HH:mm").getTime());
                    kline.setOpen(result.getOpen());
                    kline.setClose(result.getClose());
                    kline.setHigh(result.getHigh());
                    kline.setLow(result.getLow());
                    kline.setVolume(BigDecimal.ZERO);
                    resList.add(kline);
                }
            }
        }
        return resList;
    }
 
    /**
     * Minute
     * 30minute 10天
     * 15minute 5天
     * 5minute  2天
     * 1minute  1天
     */
    public List<Kline> getTimeseriesThirtyMinute(String currency) {
        if (isXueQiu(currency)) {
            return xueQiuDataService.getTimeseriesThirtyMinute(currency);
        }
        if (isXinlang(currency)) {
            return xinLangDataService.getTimeseriesThirtyMinute(currency);
        }
        List<Kline> resList = new ArrayList<>();
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd-HH:mm");
        f.setTimeZone(TimeZone.getTimeZone(UTCDateUtils.GMT_TIME_ZONE));
        Date now = new Date();
        for (int i = 0; i < TraderMadeOptions.thirtyMinutePeriod; i++) {
            String startDate = UTCDateUtils.addDay(now, -2);
            String endDate = f.format(now);
            now = UTCDateUtils.toDate(startDate, "yyyy-MM-dd-HH:mm");
            Map<String, String> param = new HashMap<>();
            param.put("currency", currency);
            param.put("start_date", startDate);
            param.put("end_date", endDate);
            param.put("interval", "minute");
            param.put("period", "15");
            param.put("format", "records");
            param.put("api_key", TraderMadeOptions.apiKey);
            String json = HttpHelper.getJSONFromHttpNew(TraderMadeOptions.timeseries, param, HttpMethodType.GET);
            JSONObject resultJson = JSON.parseObject(json);
            JSONArray dataArray = resultJson.getJSONArray("quotes");
            if (dataArray.size() > 0) {
                List<TimeseriesResult> list = JSONObject.parseArray(JSONObject.toJSONString(dataArray), TimeseriesResult.class);
                for (TimeseriesResult result : list) {
                    Kline kline = new Kline();
                    kline.setSymbol(currency);
                    kline.setPeriod(Kline.PERIOD_30MIN);
                    // 毫秒
                    kline.setTs(UTCDateUtils.toDate(result.getDate(), "yyyy-MM-dd HH:mm").getTime());
                    kline.setOpen(result.getOpen());
                    kline.setClose(result.getClose());
                    kline.setHigh(result.getHigh());
                    kline.setLow(result.getLow());
                    kline.setVolume(BigDecimal.ZERO);
                    resList.add(kline);
                }
            }
        }
        return resList;
    }
}