ybf

ybf


1.16OverBit抓取代码参考

<p>/**</p> <ul> <li> <p>@author */ @Slf4j @Service public class OverBitExchangePrice implements CoinPriceFetchService { @Autowired private CoinPriceRedisService coinPriceRedisService;</p> <p>@Autowired Environment environment;</p> <p>List<AssetType> supportDigitalCurrencyTypeList = new ArrayList<>(); List<AssetType> supportFiatMoneyTypeList = new ArrayList<>();</p> <p>@Autowired public OverBitExchangePrice() { supportDigitalCurrencyTypeList.add(AssetType.BTC); supportDigitalCurrencyTypeList.add(AssetType.ETH); supportDigitalCurrencyTypeList.add(AssetType.USDT); supportFiatMoneyTypeList.add(AssetType.CNY); supportFiatMoneyTypeList.add(AssetType.USD); }</p> <p>@Override public void fetchPriceJsonAndSave() { String scheme = &quot;https&quot;; String host = &quot;www.overbit.com&quot;; String path = &quot;app/data&quot;; Map&lt;String, String&gt; headers = new HashMap<>(1); Map&lt;String, String&gt; params = new HashMap<>(2); params.put(&quot;symbols&quot;, &quot;BTCUSD,ETHUSD,BTCCNY,USDCNY&quot;); 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); } }</p> <p>public void parseAndSave(String responseString, long duration) { OverBitResponse overBitResponse = GsonUtil.getInstance().fromJson(responseString, OverBitResponse.class); log.info(&quot;overbit overBitResponse:{}&quot;, overBitResponse); coinPriceRedisService.putCoinPrice(AssetType.BTC, AssetType.USD, Float.valueOf(overBitResponse.getBtcUsd().getMid().replace(&quot;,&quot;, &quot;&quot;))); coinPriceRedisService.putCoinPrice(AssetType.ETH, AssetType.USD, Float.valueOf(overBitResponse.getEthUsd().getMid().replace(&quot;,&quot;, &quot;&quot;))); coinPriceRedisService.putCoinPrice(AssetType.BTC, AssetType.CNY, Float.valueOf(overBitResponse.getBtcCny().getMid().replace(&quot;,&quot;, &quot;&quot;))); coinPriceRedisService.putCoinPrice(AssetType.USD, AssetType.CNY, Float.valueOf(overBitResponse.getUsdCny().getMid().replace(&quot;,&quot;, &quot;&quot;))); }</p> <p>/**</p> <ul> <li>获取TRX价格数据 */ public void fetchTrxToUsdFromCryptocompare() { String scheme = &quot;https&quot;; String host = &quot;min-api.cryptocompare.com&quot;; String path = &quot;data/price&quot;; Map&lt;String, String&gt; headers = new HashMap<>(1); Map&lt;String, String&gt; params = new HashMap<>(2); params.put(&quot;fsym&quot;, &quot;TRX&quot;); params.put(&quot;tsyms&quot;, &quot;USD&quot;); String cryptocompare_api_keys= environment.getProperty(&quot;trx.cryptocompare.api.keys&quot; ,String.class,&quot;ae095874cf5489a7273269e6a82882a4a5ffddcbc0b25712e52930de707733ee&quot;); String defaultTrxRate= environment.getProperty(&quot;default.trx.rate&quot; ,String.class,&quot;0.055F&quot;); if (!NumberUtils.isCreatable(defaultTrxRate)) { defaultTrxRate =&quot;0.055F&quot;; } params.put(&quot;api_key&quot;, 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(&quot;获取TRX-USD汇率,{}&quot;,responseString); JSONObject json = new JSONObject(responseString); Double trxRate = Double.valueOf(json.get(&quot;USD&quot;).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(&quot;获取TRX-USD汇率失败,{}&quot;, e); }</li> </ul> <p>} }</p> </li> </ul>

页面列表

ITEM_HTML