|
|
@@ -883,6 +883,12 @@ public class CoinServiceImpl implements CoinService {
|
|
|
parseWatchlistMap4CmC(coinWatchlistMap4CmcId);
|
|
|
});
|
|
|
|
|
|
+ // CoinCurrencyHolding同步
|
|
|
+ params.put("sortField", Collections.singletonList("cch.buy_time"));
|
|
|
+ params.put("sort", "desc");
|
|
|
+ List<CoinCurrencyHolding> currentHoldingList = coinMapper.findCurrentHoldingList(params);
|
|
|
+ parseCurrentHoldingMap4Coingecko(currentHoldingList);
|
|
|
+
|
|
|
log.warn("watchlist-coingecko-cmc scheduler end");
|
|
|
}, 0, 1, TimeUnit.HOURS);
|
|
|
|
|
|
@@ -941,6 +947,68 @@ public class CoinServiceImpl implements CoinService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private void parseCurrentHoldingMap4Coingecko(List<CoinCurrencyHolding> currentHoldingList) {
|
|
|
+ String coingeckoCoinsMarketsUrl = InitRunner.dicCodeMap.get("coingecko_coins_markets_url").getCodeValue();
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
+ headerMap.put("Accept", "application/json");
|
|
|
+ headerMap.put("Accept-Encoding", "deflate,gzip");
|
|
|
+
|
|
|
+ Map<String, String> paramMap = new LinkedHashMap<>();
|
|
|
+ paramMap.put("ids", currentHoldingList.stream().map(CoinCurrencyHolding::getCoingeckoId).distinct().collect(Collectors.joining(",")));
|
|
|
+ paramMap.put("vs_currency", "usd");
|
|
|
+ AtomicInteger i = new AtomicInteger();
|
|
|
+ Connection.Response response = null;
|
|
|
+ try {
|
|
|
+ response = JsoupUtil.requestBody(coingeckoCoinsMarketsUrl, JsoupUtil.HTTP_GET, InitRunner.proxy, headerMap, paramMap);
|
|
|
+ JSONArray result = JSONArray.parseArray(response.body());
|
|
|
+
|
|
|
+ Map<String, List<CoinCurrencyHolding>> currencyHoldingMap = currentHoldingList.stream().collect(Collectors.groupingBy(CoinCurrencyHolding::getCoingeckoId));
|
|
|
+
|
|
|
+
|
|
|
+ for (int j = 0; j < result.size(); j++) {
|
|
|
+ JSONObject marketData = result.getJSONObject(j);
|
|
|
+ String id = marketData.getString("id");
|
|
|
+
|
|
|
+ if (currencyHoldingMap.containsKey(id)) {
|
|
|
+ List<CoinCurrencyHolding> currencyHoldingSubList = currencyHoldingMap.get(id);
|
|
|
+
|
|
|
+ for (CoinCurrencyHolding currencyHolding : currencyHoldingSubList) {
|
|
|
+ // 市场价格
|
|
|
+ if (marketData.containsKey("current_price") && null != marketData.get("current_price")) {
|
|
|
+ String markPrice = marketData.getBigDecimal("current_price").toPlainString();
|
|
|
+ currencyHolding.setCurrentPrice(markPrice);
|
|
|
+ }
|
|
|
+ // 入场总额
|
|
|
+ if (StringUtils.isNotEmpty(currencyHolding.getBuyPrice()) && StringUtils.isNotEmpty(currencyHolding.getBuyQuantity())) {
|
|
|
+ currencyHolding.setBuyAmount(new BigDecimal(currencyHolding.getBuyPrice()).multiply(new BigDecimal(currencyHolding.getBuyQuantity())).setScale(2, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ }
|
|
|
+ // 当前总额
|
|
|
+ if (StringUtils.isNotEmpty(currencyHolding.getCurrentPrice()) && StringUtils.isNotEmpty(currencyHolding.getCurrentQuantity())) {
|
|
|
+ currencyHolding.setCurrentAmount(new BigDecimal(currencyHolding.getCurrentPrice()).multiply(new BigDecimal(currencyHolding.getCurrentQuantity())).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ // 涨跌幅比例
|
|
|
+ if (StringUtils.isNotEmpty(currencyHolding.getBuyPrice()) && StringUtils.isNotEmpty(currencyHolding.getCurrentPrice())) {
|
|
|
+ BigDecimal changePercentage = new BigDecimal(currencyHolding.getCurrentPrice()).divide(new BigDecimal(currencyHolding.getBuyPrice()), 2, RoundingMode.HALF_UP);
|
|
|
+ currencyHolding.setChangePercentage(changePercentage);
|
|
|
+ }
|
|
|
+
|
|
|
+ coinMapper.updateCurrentHolding(currencyHolding);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("parseCurrentHoldingMap4Coingecko error,response={},size={},i={}", response != null ? response.body() : "--", currentHoldingList.size(), i.get(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getCurrentHoldingTotalAmout(JSONObject params) {
|
|
|
+ BigDecimal totalAmout = coinMapper.getCurrentHoldingTotalAmout(params.toJavaObject(Map.class));
|
|
|
+ return totalAmout;
|
|
|
+ }
|
|
|
+
|
|
|
private void initCexSpotFlag(Map<String, CoinWatchlistOther> coinWatchlistOtherMap4Symbol) {
|
|
|
// spot
|
|
|
String coingeckoExchangeTickersUrl = InitRunner.dicCodeMap.get("coingecko_exchange_tickers_url").getCodeValue();
|
|
|
@@ -1631,7 +1699,27 @@ public class CoinServiceImpl implements CoinService {
|
|
|
}
|
|
|
|
|
|
private void renderMainSearch4CurrencyHolding(List<CoinCurrencyHolding> currentHoldingList) {
|
|
|
+ for (CoinCurrencyHolding coinCurrencyHolding : currentHoldingList) {
|
|
|
+ // 名称
|
|
|
+ coinCurrencyHolding.setSymbolStyle(" style=\"background-color:rgba(70,169,244,.72);font-weight: bold;\"");
|
|
|
+ // 当前价格
|
|
|
+ coinCurrencyHolding.setCurrentPriceStyle(" style=\"color:#252B31;background-color:#C4ADE9;\"");
|
|
|
+ if (StringUtils.isNotEmpty(coinCurrencyHolding.getCurrentPrice())) {
|
|
|
+ coinCurrencyHolding.setCurrentPrice(new BigDecimal(coinCurrencyHolding.getCurrentPrice()).divide(BigDecimal.ONE, new MathContext(3)).toPlainString());
|
|
|
+ }
|
|
|
+ // 入场价格
|
|
|
+ if (StringUtils.isNotEmpty(coinCurrencyHolding.getBuyPrice())) {
|
|
|
+ coinCurrencyHolding.setBuyPrice(new BigDecimal(coinCurrencyHolding.getBuyPrice()).divide(BigDecimal.ONE, new MathContext(3)).toPlainString());
|
|
|
+ }
|
|
|
|
|
|
+ // 涨跌幅比例
|
|
|
+ if (coinCurrencyHolding.getChangePercentage() == null) {
|
|
|
+ } else if (coinCurrencyHolding.getChangePercentage().compareTo(BigDecimal.ONE) < 0) {
|
|
|
+ coinCurrencyHolding.setChangePercentageStyle(" style=\"color:#000000;background-color:#f1a8a4;\"");
|
|
|
+ } else {
|
|
|
+ coinCurrencyHolding.setChangePercentageStyle(" style=\"color:#000000;background-color:#aad6f5;\"");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|