ybf

ybf


1.4币汇汇率抓取代码参考

/**

  • 币汇 **/ @Slf4j @Service public class BiHuiExchangePrice implements CoinPriceFetchService {

    @DubboReference private OtcOrderPendingService orderPendingService; private final BaseExchangeRateServiceImpl baseExchangeRateService; private final ExchangeRateCheckService exchangeRateService;

    @Autowired public BiHuiExchangePrice(BaseExchangeRateServiceImpl baseExchangeRateService , ExchangeRateCheckService exchangeRateService ) { this.baseExchangeRateService = baseExchangeRateService; this.exchangeRateService = exchangeRateService; }

    @Override public void fetchPriceJsonAndSave() { getAndSavePriceInfo(AssetType.USDT); getAndSavePriceInfo(AssetType.BTC); }

    private void getAndSavePriceInfo(AssetType assetType) { long start = System.currentTimeMillis(); // 买一价就是最具买入意向的投资者的挂单情况,即所有买单中的最高价 BigDecimal buyPrice = null; // 卖一价就是最具卖出意向的投资者的挂单情况,即所有卖单中的最低价 BigDecimal sellPrice = null; try { // 爬取币汇的买1价和卖1价,从自己系统获取 ApiInfoEnum apiInfoEnum = null; final StopWatch stopWatch=new StopWatch(); stopWatch.start(); buyPrice = orderPendingService.getHighestBuyCommitmentOrderPrice(assetType, AssetType.CNY); stopWatch.stop(); log.info("【汇率抓取】获取币汇买价汇率 rpc耗时:{}ms",stopWatch.getLastTaskTimeMillis()); try { if (AssetType.USDT.getCode().equals(assetType.getCode())) { apiInfoEnum = ApiInfoEnum.BH_OTC_USDT_FIRST_BUY_PRICE; } else if (AssetType.BTC.equals(assetType)) { apiInfoEnum = ApiInfoEnum.BH_OTC_BTC_FIRST_BUY_PRICE; } log.info("币汇抓取到的{}的buyPrice为:{}", assetType, buyPrice); // influxDbHelperService.saveToInfluxDB("BASE", assetType, apiInfoEnum, BUY_DIRECTION, buyPrice); // exchangeRateService.checkPrice(assetType, buyPrice); } catch (Exception e) { return; } stopWatch.start(); sellPrice = orderPendingService.getLowestSellCommitmentOrderPrice(assetType, AssetType.CNY); stopWatch.stop(); log.info("【汇率抓取】获取币汇卖价汇率 rpc耗时:{}ms",stopWatch.getLastTaskTimeMillis()); try { if (AssetType.USDT.getCode().equals(assetType.getCode())) { apiInfoEnum = ApiInfoEnum.BH_OTC_USDT_FIRST_SELL_PRICE; } else if (AssetType.BTC.getCode().equals(assetType.getCode())) { apiInfoEnum = ApiInfoEnum.BH_OTC_BTC_FIRST_SELL_PRICE; } log.info("币汇抓取到的{}的sellPrice为:{}", assetType, sellPrice); // influxDbHelperService.saveToInfluxDB("BASE", assetType, apiInfoEnum, SELL_DIRECTION, sellPrice); // exchangeRateService.checkPrice(assetType, sellPrice); } catch (Exception e) { return; } } catch (Exception e) { log.error("获取币汇系统之{}价格失败.{}", assetType, e.getMessage()); }

    parseAndSave(assetType, buyPrice, sellPrice, System.currentTimeMillis() - start);

    }

    private void parseAndSave(AssetType assetType, BigDecimal buyPrice, BigDecimal sellPrice, long duration) { /log.info("币汇系统之{}买单最高价为{},卖单最低价为{}",assetType.getSymbol(),buyPrice,sellPrice);/ try { BaseExchangeRateHistoryDTO baseExchangeRateHistoryDTO = new BaseExchangeRateHistoryDTO(); baseExchangeRateHistoryDTO.setPriceUnit(AssetType.CNY);

        baseExchangeRateHistoryDTO.setCoinType(assetType);
        baseExchangeRateHistoryDTO.setDuration(duration);
        baseExchangeRateHistoryDTO.setResponse(null);
        baseExchangeRateHistoryDTO.setPrice(buyPrice);
        if (AssetType.USDT.getCode().equals(assetType.getCode())) {
            baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.BH_OTC_USDT_FIRST_BUY_PRICE);
            baseExchangeRateHistoryDTO.setPriceTrading(RateTradingEnum.CNY_USDT);
        } else if (AssetType.BTC.getCode().equals(assetType.getCode())) {
            baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.BH_OTC_BTC_FIRST_BUY_PRICE);
            baseExchangeRateHistoryDTO.setPriceTrading(RateTradingEnum.CNY_BTC);
        }
        baseExchangeRateHistoryDTO.setApiSource(RateSourceEnum.BH);
        baseExchangeRateHistoryDTO.setDirection(BUY_DIRECTION);
        baseExchangeRateService.mergeBaseExchangeRate(baseExchangeRateHistoryDTO, false);
    
        baseExchangeRateHistoryDTO.setPrice(sellPrice);
        if (AssetType.USDT.getCode().equals(assetType.getCode())) {
            baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.BH_OTC_USDT_FIRST_SELL_PRICE);
        } else if (AssetType.BTC.getCode().equals(assetType.getCode())) {
            baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.BH_OTC_BTC_FIRST_SELL_PRICE);
        }
        baseExchangeRateHistoryDTO.setDirection(SELL_DIRECTION);
        baseExchangeRateService.mergeBaseExchangeRate(baseExchangeRateHistoryDTO, false);
    } catch (Exception e) {
        log.error("币汇汇率更新失败:{}", e.getMessage());
    }

    } }

页面列表

ITEM_HTML