|
|
@@ -41,6 +41,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
@@ -206,7 +207,7 @@ public class CoinServiceImpl implements CoinService {
|
|
|
String coinmarketcapIdmapParams4aux = InitRunner.dicCodeMap.get("coinmarketcap_idmap_params_aux").getCodeValue();
|
|
|
Map<String, String> headerMap = new HashMap<>();
|
|
|
headerMap.put("Accept", "application/json");
|
|
|
- headerMap.put("Accept-Encoding", "deflate, gzip");
|
|
|
+ headerMap.put("Accept-Encoding", "deflate,gzip");
|
|
|
headerMap.put("X-CMC_PRO_API_KEY", coinmarketcapApikey);
|
|
|
|
|
|
String[] listingStatusArr = coinmarketcapIdmapParams4listingStatus.split(",");
|
|
|
@@ -789,6 +790,7 @@ public class CoinServiceImpl implements CoinService {
|
|
|
params.put("sort", "desc");
|
|
|
List<CoinWatchlist> watchlistList = coinMapper.findWatchlistList(params);
|
|
|
|
|
|
+ Map<Long, CoinWatchlist> watchlistMap4CmC = new HashMap<>();
|
|
|
for (CoinWatchlist coinWatchlist : watchlistList) {
|
|
|
try {
|
|
|
Thread.sleep(5000L);
|
|
|
@@ -805,12 +807,19 @@ public class CoinServiceImpl implements CoinService {
|
|
|
if (marketData.containsKey("market_cap_rank") && null != marketData.get("market_cap_rank")) {
|
|
|
Integer totalMarketRanking = marketData.getInteger("market_cap_rank");
|
|
|
coinWatchlist.setTotalMarketRanking(totalMarketRanking);
|
|
|
+ } else {
|
|
|
+ watchlistMap4CmC.put(coinWatchlist.getCmcId(), coinWatchlist);
|
|
|
}
|
|
|
|
|
|
// 总市值
|
|
|
if (marketData.containsKey("market_cap") && null != marketData.get("market_cap")) {
|
|
|
BigDecimal totalMarketValue = marketData.getJSONObject("market_cap").getBigDecimal("usd");
|
|
|
coinWatchlist.setTotalMarketValue(totalMarketValue);
|
|
|
+ if (totalMarketValue.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ watchlistMap4CmC.put(coinWatchlist.getCmcId(), coinWatchlist);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ watchlistMap4CmC.put(coinWatchlist.getCmcId(), coinWatchlist);
|
|
|
}
|
|
|
|
|
|
// 市场价格
|
|
|
@@ -861,6 +870,10 @@ public class CoinServiceImpl implements CoinService {
|
|
|
log.error("jsoup CoinWatchlist error,coinWatchlist={}", coinWatchlist, ex);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (watchlistMap4CmC.size() > 0) {
|
|
|
+ parseWatchlistMap4CmC(watchlistMap4CmC);
|
|
|
+ }
|
|
|
}, 0, 1, TimeUnit.HOURS);
|
|
|
|
|
|
// Upbit交易所监控报警
|
|
|
@@ -910,6 +923,37 @@ public class CoinServiceImpl implements CoinService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public void parseWatchlistMap4CmC(Map<Long, CoinWatchlist> watchlistMap4CmC) {
|
|
|
+ String coinmarketcapApikey = InitRunner.dicCodeMap.get("coinmarketcap_apikey").getCodeValue();
|
|
|
+ String coinmarketcapQuotesLatestUrl = InitRunner.dicCodeMap.get("coinmarketcap_quotes_latest_url").getCodeValue();
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
+ headerMap.put("Accept", "application/json");
|
|
|
+ headerMap.put("Accept-Encoding", "deflate,gzip");
|
|
|
+ headerMap.put("X-CMC_PRO_API_KEY", coinmarketcapApikey);
|
|
|
+
|
|
|
+ Map<String, String> paramMap = new LinkedHashMap<>();
|
|
|
+ paramMap.put("id", StringUtils.join(watchlistMap4CmC.keySet(), ","));
|
|
|
+ AtomicInteger i = new AtomicInteger();
|
|
|
+ try {
|
|
|
+ Connection.Response response = JsoupUtil.requestBody(coinmarketcapQuotesLatestUrl, JsoupUtil.HTTP_GET, InitRunner.proxy, headerMap, paramMap);
|
|
|
+ JSONObject result = JSONObject.parseObject(response.body());
|
|
|
+ JSONObject dataJO = result.getJSONObject("data");
|
|
|
+
|
|
|
+ watchlistMap4CmC.forEach((key, value) -> {
|
|
|
+ i.getAndIncrement();
|
|
|
+ if (dataJO.containsKey(key)) {
|
|
|
+ JSONObject jsonObject = dataJO.getJSONObject(String.valueOf(key));
|
|
|
+ value.setTotalMarketRanking(jsonObject.getInteger("cmc_rank"));
|
|
|
+ value.setTotalMarketValue(jsonObject.getBigDecimal("self_reported_market_cap").setScale(2, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ coinMapper.updateCoinWatchlist(value);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("parseWatchlistMap4CmC error,size={},i={}", watchlistMap4CmC.size(), i.get(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Async("coinTaskExecutor")
|
|
|
public void monitorAlarm4APP_TEXT_CARD(String content, JSONObject params, WxCpService wxCpServiceFinal) {
|