| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.yami.trading.bean.data.domain.Kline; |
| | | import com.yami.trading.bean.data.domain.Realtime; |
| | | import com.yami.trading.bean.data.dto.BeforeClose; |
| | | import com.yami.trading.bean.ico.domain.Ico; |
| | | import com.yami.trading.bean.item.domain.Item; |
| | | import com.yami.trading.common.domain.Result; |
| | |
| | | import com.yami.trading.common.util.DateUtils; |
| | | import com.yami.trading.common.web.ResultObject; |
| | | import com.yami.trading.huobi.data.AdjustmentValueCache; |
| | | import com.yami.trading.huobi.data.DataCache; |
| | | import com.yami.trading.huobi.data.internal.DataDBService; |
| | | import com.yami.trading.huobi.data.internal.KlineService; |
| | | import com.yami.trading.service.data.DataService; |
| | | import com.yami.trading.service.etf.MarketService; |
| | |
| | | private DataService dataService; |
| | | @Autowired |
| | | private IcoService icoService; |
| | | |
| | | @Autowired |
| | | private DataDBService dataDBService; |
| | | |
| | | @ApiOperation(value = "行情") |
| | | @GetMapping(HOBI + "getKline.action") |
| | |
| | | return Result.succeed(this.build(data, line, symbol)); |
| | | } catch (Exception e) { |
| | | logger.error("getKline error", e); |
| | | throw new YamiShopBindException("k线图获取失败"); |
| | | throw new YamiShopBindException(""); |
| | | } |
| | | } |
| | | |
| | | private List<Map<String, Object>> build(List<Kline> data, String line, String symbol) { |
| | | Collections.sort(data); |
| | | // 相同时间戳保留最新一条(进行中K线会覆盖缓存中的旧数据) |
| | | Map<Long, Kline> latestByTs = new LinkedHashMap<>(); |
| | | for (Kline kline : data) { |
| | | latestByTs.put(kline.getTs(), kline); |
| | | } |
| | | data = new ArrayList<>(latestByTs.values()); |
| | | Collections.sort(data); |
| | | int len = data.size(); |
| | | for (int i = 1; i < len; i++) { |
| | | data.get(i).setOpen(data.get(i - 1).getClose()); |
| | | } |
| | | |
| | | |
| | | Set<Long> tsSet = new HashSet<Long>(); |
| | | List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); |
| | | Item bySymbol = itemService.findBySymbol(symbol); |
| | | |
| | | for (int i = 0; i < data.size(); i++) { |
| | | Kline kline = data.get(i); |
| | | Long ts = kline.getTs(); |
| | | if (tsSet.contains(ts)) { |
| | | continue; |
| | | } else { |
| | | tsSet.add(ts); |
| | | } |
| | | String fake = bySymbol.getFake(); |
| | | // if("1".equalsIgnoreCase(fake)){ |
| | | // klineService.smoothlyKline(kline, 0.99); |
| | |
| | | map.put("high", high.setScale(decimal, RoundingMode.HALF_UP)); |
| | | map.put("low", low.setScale(decimal, RoundingMode.HALF_UP)); |
| | | map.put("volume", kline.getVolume()); |
| | | |
| | | if (i == data.size() - 1) { |
| | | Realtime realtime = DataCache.getLatestRealTime(symbol); |
| | | if (realtime != null && realtime.getClose() != null) { |
| | | close = realtime.getClose(); |
| | | map.put("close", close.setScale(decimal, RoundingMode.HALF_UP)); |
| | | if (close.compareTo(high) > 0) { |
| | | high = close; |
| | | } |
| | | if (close.compareTo(low) < 0) { |
| | | low = close; |
| | | } |
| | | } |
| | | BeforeClose beforeClose = dataDBService.getBeforeClose(kline.getSymbol(), line, ts, realtime); |
| | | if (beforeClose != null) { |
| | | if (beforeClose.getMaxClose() != null |
| | | && beforeClose.getMaxClose().compareTo(BigDecimal.ZERO) > 0) { |
| | | high = beforeClose.getMaxClose(); |
| | | } |
| | | if (beforeClose.getMinClose() != null |
| | | && beforeClose.getMinClose().compareTo(BigDecimal.ZERO) > 0) { |
| | | low = beforeClose.getMinClose(); |
| | | } |
| | | } |
| | | map.put("high", high.setScale(decimal, RoundingMode.HALF_UP)); |
| | | map.put("low", low.setScale(decimal, RoundingMode.HALF_UP)); |
| | | } |
| | | list.add(map); |
| | | } |
| | | return list; |