|
|
@@ -844,13 +844,13 @@ public class CoinServiceImpl implements CoinService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ int MAX_NUMBER = 100;
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("sortField", Collections.singletonList("create_time"));
|
|
|
params.put("sort", "desc");
|
|
|
- List<CoinWatchlist> watchlistList = coinMapper.findWatchlistList(params);
|
|
|
|
|
|
- int MAX_NUMBER = 100;
|
|
|
- Stream.iterate(0, n -> n + 1).limit((watchlistList.size() + MAX_NUMBER - 1) / MAX_NUMBER)
|
|
|
+ List<CoinWatchlist> watchlistListCKO = coinMapper.findWatchlistList(params);
|
|
|
+ Stream.iterate(0, n -> n + 1).limit((watchlistListCKO.size() + MAX_NUMBER - 1) / MAX_NUMBER)
|
|
|
.forEach(i -> {
|
|
|
try {
|
|
|
Thread.sleep(2000L);
|
|
|
@@ -858,10 +858,11 @@ public class CoinServiceImpl implements CoinService {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
- Map<String, CoinWatchlist> coinWatchlistMap4CoingeckoId = watchlistList.stream().skip((long) i * MAX_NUMBER).limit(MAX_NUMBER).collect(Collectors.toMap(CoinWatchlist::getCoingeckoId, coinWatchlist -> coinWatchlist));
|
|
|
+ Map<String, CoinWatchlist> coinWatchlistMap4CoingeckoId = watchlistListCKO.stream().skip((long) i * MAX_NUMBER).limit(MAX_NUMBER).collect(Collectors.toMap(CoinWatchlist::getCoingeckoId, coinWatchlist -> coinWatchlist));
|
|
|
parseWatchlistMap4Coingecko(coinWatchlistMap4CoingeckoId);
|
|
|
});
|
|
|
- Stream.iterate(0, n -> n + 1).limit((watchlistList.size() + MAX_NUMBER - 1) / MAX_NUMBER)
|
|
|
+ List<CoinWatchlist> watchlistListCMC = coinMapper.findWatchlistList(params);
|
|
|
+ Stream.iterate(0, n -> n + 1).limit((watchlistListCMC.size() + MAX_NUMBER - 1) / MAX_NUMBER)
|
|
|
.forEach(i -> {
|
|
|
try {
|
|
|
Thread.sleep(2000L);
|
|
|
@@ -869,7 +870,7 @@ public class CoinServiceImpl implements CoinService {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
- Map<Long, CoinWatchlist> coinWatchlistMap4CmcId = watchlistList.stream().skip((long) i * MAX_NUMBER).limit(MAX_NUMBER).collect(Collectors.toMap(CoinWatchlist::getCmcId, coinWatchlist -> coinWatchlist));
|
|
|
+ Map<Long, CoinWatchlist> coinWatchlistMap4CmcId = watchlistListCMC.stream().skip((long) i * MAX_NUMBER).limit(MAX_NUMBER).collect(Collectors.toMap(CoinWatchlist::getCmcId, coinWatchlist -> coinWatchlist));
|
|
|
parseWatchlistMap4CmC(coinWatchlistMap4CmcId);
|
|
|
});
|
|
|
}, 0, 1, TimeUnit.HOURS);
|
|
|
@@ -1064,6 +1065,38 @@ public class CoinServiceImpl implements CoinService {
|
|
|
}
|
|
|
|
|
|
coinMapper.updateCoinWatchlist(value);
|
|
|
+
|
|
|
+ // 解析CoinWatchlistOther
|
|
|
+ CoinWatchlistOther coinWatchlistOther = new CoinWatchlistOther();
|
|
|
+ coinWatchlistOther.setSymbol(value.getSymbol());
|
|
|
+ if (null != jsonObject.get("max_supply")) {
|
|
|
+ coinWatchlistOther.setMaxSupply(jsonObject.getBigDecimal("max_supply").setScale(0, RoundingMode.HALF_UP).toPlainString());
|
|
|
+ }
|
|
|
+ if (null != jsonObject.get("circulating_supply")) {
|
|
|
+ coinWatchlistOther.setCirculatingSupply(jsonObject.getBigDecimal("circulating_supply").setScale(0, RoundingMode.HALF_UP).toPlainString());
|
|
|
+ if ("0".equals(coinWatchlistOther.getCirculatingSupply()) && null != jsonObject.get("self_reported_circulating_supply")) {
|
|
|
+ coinWatchlistOther.setCirculatingSupply(jsonObject.getBigDecimal("self_reported_circulating_supply").setScale(0, RoundingMode.HALF_UP).toPlainString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != coinWatchlistOther.getMaxSupply() && null != coinWatchlistOther.getCirculatingSupply()) {
|
|
|
+ coinWatchlistOther.setCirculatingRate(new BigDecimal(coinWatchlistOther.getCirculatingSupply()).divide(new BigDecimal(coinWatchlistOther.getMaxSupply()), 3, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).toPlainString());
|
|
|
+ }
|
|
|
+ if (null != jsonObject.get("total_supply")) {
|
|
|
+ coinWatchlistOther.setTotalSupply(jsonObject.getBigDecimal("total_supply").setScale(0, RoundingMode.HALF_UP).toPlainString());
|
|
|
+ }
|
|
|
+ JSONObject usdQuote = jsonObject.getJSONObject("quote").getJSONObject("USD");
|
|
|
+ if (null != usdQuote.get("market_cap")) {
|
|
|
+ coinWatchlistOther.setMarketCap(usdQuote.getBigDecimal("market_cap").setScale(0, RoundingMode.HALF_UP).toPlainString());
|
|
|
+ if ("0".equals(coinWatchlistOther.getMarketCap()) && null != jsonObject.get("self_reported_market_cap")) {
|
|
|
+ coinWatchlistOther.setMarketCap(jsonObject.getBigDecimal("self_reported_market_cap").setScale(0, RoundingMode.HALF_UP).toPlainString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != usdQuote.get("fully_diluted_market_cap")) {
|
|
|
+ coinWatchlistOther.setFullyDilutedMarketCap(usdQuote.getBigDecimal("fully_diluted_market_cap").setScale(0, RoundingMode.HALF_UP).toPlainString());
|
|
|
+ }
|
|
|
+
|
|
|
+ coinMapper.insertOrUpdateCoinWatchlistOther(coinWatchlistOther);
|
|
|
}
|
|
|
});
|
|
|
} catch (Exception e) {
|
|
|
@@ -1995,12 +2028,34 @@ public class CoinServiceImpl implements CoinService {
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("sortField", Collections.singletonList("create_time"));
|
|
|
params.put("sort", "desc");
|
|
|
+
|
|
|
+ ArrayList symbolList = new ArrayList();
|
|
|
+ symbolList.add("PYTH");
|
|
|
+ symbolList.add("SNX");
|
|
|
+ symbolList.add("REEF");
|
|
|
+
|
|
|
List<CoinWatchlist> watchlistList = coinMapper.findWatchlistList(params);
|
|
|
+ watchlistList = watchlistList.stream().filter(x -> symbolList.contains(x.getSymbol())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //Map<String, CoinWatchlist> coinWatchlistMap4CoingeckoId = watchlistList.stream().collect(Collectors.toMap(CoinWatchlist::getCoingeckoId, coinWatchlist -> coinWatchlist));
|
|
|
+ //parseWatchlistMap4Coingecko(coinWatchlistMap4CoingeckoId);
|
|
|
+
|
|
|
+ Map<Long, CoinWatchlist> coinWatchlistMap4CmcId = watchlistList.stream().collect(Collectors.toMap(CoinWatchlist::getCmcId, coinWatchlist -> coinWatchlist));
|
|
|
+ parseWatchlistMap4CmC(coinWatchlistMap4CmcId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Async("coinTaskExecutor")
|
|
|
+ public void initWatchlist(CoinWatchlist coinWatchlist2) {
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("symbol", coinWatchlist2.getSymbol());
|
|
|
+ List<CoinWatchlist> watchlistListCKO = coinMapper.findWatchlistList(params);
|
|
|
|
|
|
- Map<String, CoinWatchlist> coinWatchlistMap4CoingeckoId = watchlistList.stream().collect(Collectors.toMap(CoinWatchlist::getCoingeckoId, coinWatchlist -> coinWatchlist));
|
|
|
+ Map<String, CoinWatchlist> coinWatchlistMap4CoingeckoId = watchlistListCKO.stream().collect(Collectors.toMap(CoinWatchlist::getCoingeckoId, coinWatchlist -> coinWatchlist));
|
|
|
parseWatchlistMap4Coingecko(coinWatchlistMap4CoingeckoId);
|
|
|
|
|
|
- Map<Long, CoinWatchlist> coinWatchlistMap4CmcId = coinWatchlistMap4CoingeckoId.values().stream().collect(Collectors.toMap(CoinWatchlist::getCmcId, coinWatchlist -> coinWatchlist));
|
|
|
+ List<CoinWatchlist> watchlistListCMC = coinMapper.findWatchlistList(params);
|
|
|
+ Map<Long, CoinWatchlist> coinWatchlistMap4CmcId = watchlistListCMC.stream().collect(Collectors.toMap(CoinWatchlist::getCmcId, coinWatchlist -> coinWatchlist));
|
|
|
parseWatchlistMap4CmC(coinWatchlistMap4CmcId);
|
|
|
}
|
|
|
}
|