|
|
@@ -36,6 +36,7 @@ import java.io.UnsupportedEncodingException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.MathContext;
|
|
|
import java.math.RoundingMode;
|
|
|
+import java.net.Proxy;
|
|
|
import java.security.InvalidKeyException;
|
|
|
import java.text.DecimalFormat;
|
|
|
import java.time.Duration;
|
|
|
@@ -930,6 +931,131 @@ public class CoinServiceImpl implements CoinService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ private void initCexSpotFlag(Map<String, CoinWatchlistOther> coinWatchlistOtherMap4Symbol) {
|
|
|
+ // spot
|
|
|
+ String coingeckoExchangeTickersUrl = InitRunner.dicCodeMap.get("coingecko_exchange_tickers_url").getCodeValue();
|
|
|
+ String[] coingeckoExchangeIdArr = InitRunner.dicCodeMap.get("coingecko_exchange_ids").getCodeValue().split(",");
|
|
|
+
|
|
|
+ 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("coin_ids", StringUtils.join(coinWatchlistOtherMap4Symbol.keySet(), ","));
|
|
|
+
|
|
|
+ int iii = 0;
|
|
|
+ JSONArray result = null;
|
|
|
+ for (String coingeckoExchangeId : coingeckoExchangeIdArr) {
|
|
|
+ iii++;
|
|
|
+ try {
|
|
|
+ Thread.sleep(10000L);
|
|
|
+
|
|
|
+ Connection.Response response = JsoupUtil.requestBody(String.format(coingeckoExchangeTickersUrl, coingeckoExchangeId), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, headerMap, paramMap);
|
|
|
+ result = JSONObject.parseObject(response.body()).getJSONArray("tickers");
|
|
|
+
|
|
|
+ if (result == null) {
|
|
|
+ Thread.sleep(10000L);
|
|
|
+ response = JsoupUtil.requestBody(String.format(coingeckoExchangeTickersUrl, coingeckoExchangeId), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, headerMap, paramMap);
|
|
|
+ result = JSONObject.parseObject(response.body()).getJSONArray("tickers");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, JSONObject> resultMap = result.stream().collect(Collectors.toMap(i -> {
|
|
|
+ JSONObject a = (JSONObject) i;
|
|
|
+ String k = a.getString("base").concat(a.getString("target"));
|
|
|
+ return k;
|
|
|
+ }, i -> (JSONObject) i, (existing, replacement) -> existing));
|
|
|
+
|
|
|
+
|
|
|
+ for (CoinWatchlistOther coinWatchlistOther : coinWatchlistOtherMap4Symbol.values()) {
|
|
|
+ String baseTarget = coinWatchlistOther.getSymbol().concat("USDT");
|
|
|
+ if (iii == 1) {
|
|
|
+ coinWatchlistOther.setCexSpot("");
|
|
|
+ }
|
|
|
+ if (resultMap.containsKey(baseTarget)) {
|
|
|
+ coinWatchlistOther.setCexSpot(coinWatchlistOther.getCexSpot() + "1");
|
|
|
+ } else {
|
|
|
+ coinWatchlistOther.setCexSpot(coinWatchlistOther.getCexSpot() + "0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("initCexSpotFlag error,url={},paramMap={},result={}", String.format(coingeckoExchangeTickersUrl, coingeckoExchangeId), paramMap, result, e);
|
|
|
+ throw new RuntimeException("initCexSpotFlag error");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析交易所现货+合约标志
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Async
|
|
|
+ public void syncCexFlag() {
|
|
|
+ List<CoinWatchlistOther> watchlistOtherList = coinMapper.findAllCoinWatchlistOther();
|
|
|
+
|
|
|
+ // Perpetual
|
|
|
+ String coingeckoExchangeFuturesTickersUrl = InitRunner.dicCodeMap.get("coingecko_exchange_futures_tickers_url").getCodeValue();
|
|
|
+ String[] coingeckoExchangeFutruesIdArr = InitRunner.dicCodeMap.get("coingecko_exchange_futures_ids").getCodeValue().split(",");
|
|
|
+
|
|
|
+ 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("include_tickers", "unexpired");
|
|
|
+
|
|
|
+ int jjj = 0;
|
|
|
+ JSONArray result = null;
|
|
|
+ for (String coingeckoExchangeFutruesId : coingeckoExchangeFutruesIdArr) {
|
|
|
+ jjj++;
|
|
|
+ try {
|
|
|
+ Thread.sleep(10000L);
|
|
|
+
|
|
|
+ Connection.Response response = JsoupUtil.requestBody(String.format(coingeckoExchangeFuturesTickersUrl, coingeckoExchangeFutruesId), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, headerMap, paramMap);
|
|
|
+ result = JSONObject.parseObject(response.body()).getJSONArray("tickers");
|
|
|
+
|
|
|
+ if (result == null) {
|
|
|
+ Thread.sleep(10000L);
|
|
|
+ response = JsoupUtil.requestBody(String.format(coingeckoExchangeFuturesTickersUrl, coingeckoExchangeFutruesId), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, headerMap, paramMap);
|
|
|
+ result = JSONObject.parseObject(response.body()).getJSONArray("tickers");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, JSONObject> resultMap = result.stream().collect(Collectors.toMap(i -> {
|
|
|
+ JSONObject a = (JSONObject) i;
|
|
|
+ String k = a.getString("base").concat(a.getString("target"));
|
|
|
+ return k;
|
|
|
+ }, i -> (JSONObject) i, (existing, replacement) -> existing));
|
|
|
+
|
|
|
+ for (CoinWatchlistOther coinWatchlistOther : watchlistOtherList) {
|
|
|
+ String baseTarget = coinWatchlistOther.getSymbol().concat("USDT");
|
|
|
+ if (jjj == 1) {
|
|
|
+ coinWatchlistOther.setCexPerpetual("");
|
|
|
+ }
|
|
|
+ if (resultMap.containsKey(baseTarget) || resultMap.containsKey("1000".concat(baseTarget))) {
|
|
|
+ coinWatchlistOther.setCexPerpetual(coinWatchlistOther.getCexPerpetual() + "1");
|
|
|
+ } else {
|
|
|
+ coinWatchlistOther.setCexPerpetual(coinWatchlistOther.getCexPerpetual() + "0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("initCexFlag error,url={},paramMap={},result={}", String.format(coingeckoExchangeFuturesTickersUrl, coingeckoExchangeFutruesId), paramMap, result, e);
|
|
|
+ throw new RuntimeException("initCexFlag error");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ int MAX_NUMBER2 = 10;
|
|
|
+ Stream.iterate(0, n -> n + 1).limit((watchlistOtherList.size() + MAX_NUMBER2 - 1) / MAX_NUMBER2)
|
|
|
+ .forEach(i -> {
|
|
|
+ try {
|
|
|
+ Thread.sleep(5000L);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, CoinWatchlistOther> coinWatchlistOtherMap4Symbol = watchlistOtherList.stream().skip((long) i * MAX_NUMBER2).limit(MAX_NUMBER2).collect(Collectors.toMap(CoinWatchlistOther::getCoingeckoId, coinWatchlistOther -> coinWatchlistOther));
|
|
|
+ initCexSpotFlag(coinWatchlistOtherMap4Symbol);
|
|
|
+ });
|
|
|
+
|
|
|
+ coinMapper.insertOrUpdateCoinWatchlistOtherList(watchlistOtherList);
|
|
|
+ }
|
|
|
+
|
|
|
public void parseWatchlistMap4Coingecko(Map<String, CoinWatchlist> watchlistMap4Coingecko) {
|
|
|
String coingeckoCoinsMarketsUrl = InitRunner.dicCodeMap.get("coingecko_coins_markets_url").getCodeValue();
|
|
|
Map<String, String> headerMap = new HashMap<>();
|
|
|
@@ -2034,14 +2160,16 @@ public class CoinServiceImpl implements CoinService {
|
|
|
symbolList.add("SNX");
|
|
|
symbolList.add("REEF");
|
|
|
|
|
|
- List<CoinWatchlist> watchlistList = coinMapper.findWatchlistList(params);
|
|
|
- watchlistList = watchlistList.stream().filter(x -> symbolList.contains(x.getSymbol())).collect(Collectors.toList());
|
|
|
+ //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);
|
|
|
+ //Map<Long, CoinWatchlist> coinWatchlistMap4CmcId = watchlistList.stream().collect(Collectors.toMap(CoinWatchlist::getCmcId, coinWatchlist -> coinWatchlist));
|
|
|
+ // parseWatchlistMap4CmC(coinWatchlistMap4CmcId);
|
|
|
+
|
|
|
+ syncCexFlag();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -2049,6 +2177,8 @@ public class CoinServiceImpl implements CoinService {
|
|
|
public void initWatchlist(CoinWatchlist coinWatchlist2) {
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("symbol", coinWatchlist2.getSymbol());
|
|
|
+ params.put("sortField", Collections.singletonList("create_time"));
|
|
|
+ params.put("sort", "desc");
|
|
|
List<CoinWatchlist> watchlistListCKO = coinMapper.findWatchlistList(params);
|
|
|
|
|
|
Map<String, CoinWatchlist> coinWatchlistMap4CoingeckoId = watchlistListCKO.stream().collect(Collectors.toMap(CoinWatchlist::getCoingeckoId, coinWatchlist -> coinWatchlist));
|