ybf

ybf


1.16OverBit抓取代码参考

/**

  • @author */ @Slf4j @Service public class OverBitExchangePrice implements CoinPriceFetchService { @Autowired private CoinPriceRedisService coinPriceRedisService;

    @Autowired Environment environment;

    List<AssetType> supportDigitalCurrencyTypeList = new ArrayList<>(); List<AssetType> supportFiatMoneyTypeList = new ArrayList<>();

    @Autowired public OverBitExchangePrice() { supportDigitalCurrencyTypeList.add(AssetType.BTC); supportDigitalCurrencyTypeList.add(AssetType.ETH); supportDigitalCurrencyTypeList.add(AssetType.USDT); supportFiatMoneyTypeList.add(AssetType.CNY); supportFiatMoneyTypeList.add(AssetType.USD); }

    @Override public void fetchPriceJsonAndSave() { String scheme = "https"; String host = "www.overbit.com"; String path = "app/data"; Map<String, String> headers = new HashMap<>(1); Map<String, String> params = new HashMap<>(2); params.put("symbols", "BTCUSD,ETHUSD,BTCCNY,USDCNY"); HttpGetRequestBean requestBean = new HttpGetRequestBean(); requestBean.setHeaders(headers); requestBean.setHost(host); requestBean.setParams(params); requestBean.setPath(path); requestBean.setScheme(scheme); long start = System.currentTimeMillis(); String responseString; try { responseString = HttpUtil.getResponse(requestBean); log.info(responseString); parseAndSave(responseString, System.currentTimeMillis() - start); } catch (IOException e) { log.error(e.getMessage(), e); } }

    public void parseAndSave(String responseString, long duration) { OverBitResponse overBitResponse = GsonUtil.getInstance().fromJson(responseString, OverBitResponse.class); log.info("overbit overBitResponse:{}", overBitResponse); coinPriceRedisService.putCoinPrice(AssetType.BTC, AssetType.USD, Float.valueOf(overBitResponse.getBtcUsd().getMid().replace(",", ""))); coinPriceRedisService.putCoinPrice(AssetType.ETH, AssetType.USD, Float.valueOf(overBitResponse.getEthUsd().getMid().replace(",", ""))); coinPriceRedisService.putCoinPrice(AssetType.BTC, AssetType.CNY, Float.valueOf(overBitResponse.getBtcCny().getMid().replace(",", ""))); coinPriceRedisService.putCoinPrice(AssetType.USD, AssetType.CNY, Float.valueOf(overBitResponse.getUsdCny().getMid().replace(",", ""))); }

    /**

    • 获取TRX价格数据 */ public void fetchTrxToUsdFromCryptocompare() { String scheme = "https"; String host = "min-api.cryptocompare.com"; String path = "data/price"; Map<String, String> headers = new HashMap<>(1); Map<String, String> params = new HashMap<>(2); params.put("fsym", "TRX"); params.put("tsyms", "USD"); String cryptocompare_api_keys= environment.getProperty("trx.cryptocompare.api.keys" ,String.class,"ae095874cf5489a7273269e6a82882a4a5ffddcbc0b25712e52930de707733ee"); String defaultTrxRate= environment.getProperty("default.trx.rate" ,String.class,"0.055F"); if (!NumberUtils.isCreatable(defaultTrxRate)) { defaultTrxRate ="0.055F"; } params.put("api_key", cryptocompare_api_keys); HttpGetRequestBean requestBean = new HttpGetRequestBean(); requestBean.setHeaders(headers); requestBean.setHost(host); requestBean.setParams(params); requestBean.setPath(path); requestBean.setScheme(scheme); String responseString; try { responseString = HttpUtil.getResponse(requestBean); log.info("获取TRX-USD汇率,{}",responseString); JSONObject json = new JSONObject(responseString); Double trxRate = Double.valueOf(json.get("USD").toString()); coinPriceRedisService.putCoinPrice(AssetType.TRX, AssetType.USD, Float.valueOf( trxRate.floatValue()) ); } catch (Throwable e) { coinPriceRedisService.putCoinPrice(AssetType.TRX, AssetType.USD, Float.valueOf(defaultTrxRate) ); log.error("获取TRX-USD汇率失败,{}", e); }

    } }

页面列表

ITEM_HTML