新版仿ok交易所-后端
zyy
2026-02-06 fa1b970c8fa7772ce123ab84e8cc4240065bcd26
trading-order-huobi/src/main/java/com.yami.trading.huobi/hobi/internal/HobiDataServiceImpl.java
@@ -221,6 +221,83 @@
        return list;
    }
    @Override
    public List<Kline> kline(String symbol, String period, Integer num) {
        List<Kline> list = new ArrayList<Kline>();
        Item item = itemService.findBySymbol(symbol);
        if (item == null) {
            return list;
        }
        try {
            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"));
                    kline.setAmount(realtimeJson.getBigDecimal("amount"));
                    list.add(kline);
                }
            }
        } catch (Exception e) {
            logger.error("error", e);
        }
        return list;
    }
    /**
     * 市场深度数据(20档),包装,数据本地化处理
     */
@@ -230,7 +307,7 @@
        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()) ){
        if(depth != null && CollectionUtil.isNotEmpty(depth.getAsks()) ){
            List<DepthEntry> asks = depth.getAsks();
            for (int i = 0; i < asks.size(); i++) {
                DepthEntry depthEntry = asks.get(i);
@@ -247,7 +324,7 @@
            }
        }
        if(CollectionUtil.isNotEmpty(depth.getBids())){
        if(depth != null && CollectionUtil.isNotEmpty(depth.getBids())){
            List<DepthEntry> bids = depth.getBids();
            for (int i = 0; i < bids.size(); i++) {
                DepthEntry depthEntry = bids.get(i);
@@ -375,7 +452,7 @@
        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())){
        if(trade != null && CollectionUtil.isNotEmpty(trade.getData())){
            List<TradeEntry> data = trade.getData();
            for (int i = 0; i < data.size(); i++) {
                TradeEntry tradeEntry = data.get(i);