| | |
| | | public static void main(String[] args) { |
| | | EStockType eStockType = EStockType.US; |
| | | StockTask stockTask = new StockTask(); |
| | | List<StockRealTimeBean> list = new ArrayList<>(); |
| | | /*List<StockRealTimeBean> list = new ArrayList<>(); |
| | | try { |
| | | Map<String, Object> paramMap = new HashMap<>(); |
| | | |
| | |
| | | log.info("init US股票 数据 成功"); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage(), e); |
| | | }*/ |
| | | List<StockRealTimeBean> list = new ArrayList<>(); |
| | | int totleStock = 1; |
| | | int page = 0; |
| | | try { |
| | | while (totleStock > list.size()) { |
| | | try { |
| | | String result = HttpClientRequest.doGet(eStockType.stockUrl + "list?country_id=" + eStockType.getContryId() + "&size=100000&page=" + page + "&key=" + eStockType.stockKey); |
| | | ReponseBase reponseBase = new Gson().fromJson(result, ReponseBase.class); |
| | | list.addAll(reponseBase.getData()); |
| | | page++; |
| | | totleStock = reponseBase.getTotal(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | break; |
| | | } |
| | | } |
| | | if (list.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | log.info("同步股票 获取数据 {}", list.size()); |
| | | List<Realtime> realtimeList = new ArrayList<>(); |
| | | for (StockRealTimeBean o : list) { |
| | | Realtime realtime = new Realtime(); |
| | | realtime.setUuid(o.getId()); |
| | | realtime.setSymbol(o.getSymbol()); |
| | | realtime.setName(o.getName()); |
| | | realtime.setClose(new BigDecimal(o.getLast().trim()).doubleValue()); |
| | | realtime.setLow(new BigDecimal(o.getLow().trim()).doubleValue()); |
| | | realtime.setHigh(new BigDecimal(o.getHigh().trim()).doubleValue()); |
| | | realtime.setOpen(new BigDecimal(o.getOpen().trim()).doubleValue()); |
| | | realtime.setPrevClose(new BigDecimal(o.getPrevClose().trim()).doubleValue()); |
| | | realtime.setTs(Long.valueOf(o.getTime() + "000")); |
| | | realtime.setVolume(new BigDecimal(o.getVolume().trim()).doubleValue()); |
| | | realtime.setNetChange(new BigDecimal(o.getChg().trim()).doubleValue()); |
| | | realtime.setChangeRatio(new BigDecimal(o.getChgPct()).doubleValue()); |
| | | realtime.setType(o.getType()); |
| | | realtime.setBid(new BigDecimal(o.getBid()).doubleValue()); |
| | | realtime.setAsk(new BigDecimal(o.getAsk()).doubleValue()); |
| | | |
| | | realtimeList.add(realtime); |
| | | } |
| | | realtimeList.sort(Comparator.comparing(Realtime::getChangeRatio).reversed()); |
| | | log.info("同步股票 数据 成功 总共同步数据 {}", realtimeList.size()); |
| | | realtimeList.forEach(x -> { |
| | | System.out.println(x.getName() + "=====" + x.getChangeRatio()); |
| | | }); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("同步出错", e); |
| | | } |
| | | } |
| | | |