ybf

ybf


1.7各网站的各币种的USD转换价格代码参考

/**

  • 各网站的各币种的USD转换价格
  • @author **/ @Slf4j @Service public class CoinDisposeExchangePrice {

    @Autowired private BaseExchangeRateServiceImpl baseExchangeRateService; @Autowired private BankChinaExchangePrice bankChinaExchangePrice;

    public void fetchPriceJsonAndSave(String assetType,String rateSourceEnum) { getAndSavePriceInfo(assetType, rateSourceEnum);

    }

    private void getAndSavePriceInfo(String assetType,String rateSourceEnum) { //要处理的数据 List<BaseExchangeRate> list = baseExchangeRateService.list(new LambdaQueryWrapper<BaseExchangeRate>() //.eq(BaseExchangeRate::getStatus, 1) .eq(BaseExchangeRate::getPriceUnit, AssetType.getBySymbol(assetType).getCode()) .eq(BaseExchangeRate::getApiSource, rateSourceEnum) ); if(list==null || list.isEmpty()){ return; } parseAndSave(list); }

    private void parseAndSave(List<BaseExchangeRate> list) { //List<BaseExchangeRateHistoryDTO> bankChinaExchangeList = bankChinaExchangePrice.getBankChinaExchangeList(); //取银行的默认汇率数据 List<BaseExchangeRate> bankChinaExchangeList = baseExchangeRateService.list(new LambdaQueryWrapper<BaseExchangeRate>() //.eq(BaseExchangeRate::getStatus, 1) .ge(BaseExchangeRate::getApiInfoId, ApiInfoEnum.DEFAULT_CNY_USD_FIRST_BUY_PRICE.getId()) .le(BaseExchangeRate::getApiInfoId, ApiInfoEnum.DEFAULT_CNY_USD_FIRST_SELL_PRICE.getId()) ); if(bankChinaExchangeList==null || bankChinaExchangeList.isEmpty()){ log.warn("coinDispose 没有取到默认的银行汇率数据"); return; } //银行汇率数据 for (BaseExchangeRate bankChinaExchangeRateDTO: bankChinaExchangeList) { //要转换的网站汇率数据 for (BaseExchangeRate baseExchangeRate: list) { //买价 if(TradeDirectionEnum.BUY_FROM_USER.getCode().equals(bankChinaExchangeRateDTO.getDirection()) && TradeDirectionEnum.BUY_FROM_USER.getCode().equals(baseExchangeRate.getDirection())){ disposeDataAndSave(baseExchangeRate, bankChinaExchangeRateDTO); continue; } //卖价 if(TradeDirectionEnum.SELL_TO_USER.getCode().equals(bankChinaExchangeRateDTO.getDirection()) && TradeDirectionEnum.SELL_TO_USER.getCode().equals(baseExchangeRate.getDirection())){ disposeDataAndSave(baseExchangeRate, bankChinaExchangeRateDTO); } } } }

    private void disposeDataAndSave(BaseExchangeRate baseExchangeRate, BaseExchangeRate bankChinaExchangeRateDTO) { BaseExchangeRateHistoryDTO baseExchangeRateHistoryDTO = new BaseExchangeRateHistoryDTO(); baseExchangeRateHistoryDTO.setCoinType(AssetType.USDT); baseExchangeRateHistoryDTO.setPriceTrading(RateTradingEnum.CNY_USDT); baseExchangeRateHistoryDTO.setPriceUnit(AssetType.CNY); baseExchangeRateHistoryDTO.setDuration(0L); baseExchangeRateHistoryDTO.setResponse(JacksonUtils.toJson(baseExchangeRate));

    BigDecimal usdUsdtPrice = baseExchangeRate.getPrice();
    BigDecimal cnyUsdPrice = bankChinaExchangeRateDTO.getPrice();
    BigDecimal thePrice = NumberUtil.mul(usdUsdtPrice, cnyUsdPrice);
    baseExchangeRateHistoryDTO.setPrice(thePrice);
    baseExchangeRateHistoryDTO.setDirection(baseExchangeRate.getDirection());
    
    if(ApiInfoEnum.OKEX_USD_USDT_FIRST_BUY_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.OKEX_BANKCHINA_CNY_USDT_FIRST_BUY_PRICE);
    }
    if(ApiInfoEnum.OKEX_USD_USDT_FIRST_SELL_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.OKEX_BANKCHINA_CNY_USDT_FIRST_SELL_PRICE);
    }
    if(ApiInfoEnum.HT_USDT_USD_FIRST_BUY_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.HT_BANKCHINA_CNY_USDT_FIRST_BUY_PRICE);
    }
    if(ApiInfoEnum.HT_USDT_USD_FIRST_SELL_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.HT_BANKCHINA_CNY_USDT_FIRST_SELL_PRICE);
    }
    if(ApiInfoEnum.BNB_USDT_USD_FIRST_BUY_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.BNB_BANKCHINA_CNY_USDT_FIRST_BUY_PRICE);
    }
    if(ApiInfoEnum.BNB_USDT_USD_FIRST_SELL_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.BNB_BANKCHINA_CNY_USDT_FIRST_SELL_PRICE);
    }
    if(ApiInfoEnum.COINBASE_USDT_USD_FIRST_BUY_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.COINBASE_BANKCHINA_CNY_USDT_FIRST_BUY_PRICE);
    }
    if(ApiInfoEnum.COINBASE_USDT_USD_FIRST_SELL_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.COINBASE_BANKCHINA_CNY_USDT_FIRST_SELL_PRICE);
    }
    if(ApiInfoEnum.OTC_CNY_USDT_AVG_FIRST_BUY_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.OTC_BANKCHINA_CNY_USDT_AVG_FIRST_BUY_PRICE);
    }
    if(ApiInfoEnum.OTC_CNY_USDT_AVG_FIRST_SELL_PRICE.getId().equals(baseExchangeRate.getApiInfoId())){
        baseExchangeRateHistoryDTO.setApiInfo(ApiInfoEnum.OTC_BANKCHINA_CNY_USDT_AVG_FIRST_SELL_PRICE);
    }
    baseExchangeRateHistoryDTO.setApiSource(RateSourceEnum.SYSTEM);
    log.info(&quot;coinDispose baseExchangeRateHistoryDTO: {}&quot;, JacksonUtils.toJson(baseExchangeRateHistoryDTO));
    baseExchangeRateService.mergeBaseExchangeRate(baseExchangeRateHistoryDTO, true);

    }

}

页面列表

ITEM_HTML