| | |
| | | CoinProcessor processor = processorFactory.getProcessor(symbol); |
| | | Map<String, Candlestick> currentKlineMap = processor.getCurrentKlineMap(); |
| | | Collection<Candlestick> values = currentKlineMap.values(); |
| | | BigDecimal newPrice = trades.get(trades.size()-1).getPrice(); |
| | | BigDecimal newPrice =null; |
| | | for (Candlestick candlestick : values) { |
| | | for (ExchangeTrade exchangeTrade : trades) { |
| | | if(exchangeTrade==null){ |
| | | continue; |
| | | } |
| | | processor.processTrade(candlestick, exchangeTrade); |
| | | newPrice=exchangeTrade.getPrice(); |
| | | } |
| | | } |
| | | |
| | | // 更新今日高地价 |
| | | BigDecimal min=BigDecimal.ZERO; |
| | | BigDecimal max=BigDecimal.ZERO; |
| | | BigDecimal vol = BigDecimal.ZERO; |
| | | for (ExchangeTrade exchangeTrade : trades) { |
| | | if(exchangeTrade==null){ |
| | | continue; |
| | | } |
| | | min=exchangeTrade.getPrice().min(min); |
| | | max=exchangeTrade.getPrice().max(max); |
| | | vol=vol.add(exchangeTrade.getAmount()); |
| | | } |
| | | Object o = redisUtils.get(symbolUsdt); |
| | | if(o!=null){ |
| | | Candlestick today = (Candlestick)o; |
| | | today.setHigh(today.getHigh().max(max)); |
| | | today.setLow(today.getLow().min(min)); |
| | | today.setVolume(today.getVolume().add(vol)); |
| | | redisUtils.set(symbolUsdt,today); |
| | | }else{ |
| | | Candlestick today = new Candlestick(); |
| | | today.setClose(newPrice); |
| | | today.setLow(newPrice); |
| | | today.setHigh(newPrice); |
| | | today.setHigh(today.getHigh().max(max)); |
| | | today.setLow(today.getLow().min(min)); |
| | | today.setLow(vol); |
| | | redisUtils.set(symbolUsdt,today); |
| | | } |
| | | // 存入redis,websocket去取 |
| | | String key = "NEW_KINE_{}"; |
| | | key = StrUtil.format(key, symbolUsdt); |
| | | redisUtils.set(key,currentKlineMap); |
| | | // 更新最新价 |
| | | redisUtils.set(CoinTypeConvert.convertToKey(symbolUsdt), newPrice); |
| | | if(newPrice!=null){ |
| | | redisUtils.set(CoinTypeConvert.convertToKey(symbolUsdt), newPrice); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |