1
zj
2024-08-15 8d53c609a6589158d68b5945cdb3061460a43d47
websocketSerivce/src/main/java/org/example/task/KucoinStock.java
@@ -11,6 +11,7 @@
import org.apache.commons.lang.StringUtils;
import org.example.common.MarketDataClient;
import org.example.pojo.Currency;
import org.example.pojo.bo.CurrencyGateBo;
import org.example.pojo.bo.CurrencyKucoin;
import org.example.server.impl.CurrencySerivceImpl;
import org.example.util.ConverterUtil;
@@ -43,7 +44,7 @@
    /**
     * 同步kucoin交易所交易对
     */
    @Scheduled(cron = "0 0/35 * * * ?")
    @Scheduled(cron = "0 0/40 * * * ?")
//    @Scheduled(cron = "0/10 * * * * ?")
    public void syncCurrency() {
        //  使用Lock来确保同步
@@ -74,8 +75,11 @@
            }.getType());
            getList.parallelStream().forEach(person -> person.setSymbol(StringUtils.remove(person.getSymbol(), "-")));
            List<Currency> dbList = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "kucoin"));
            Set<String> symbolSet = dbList.stream().map(Currency::getSymbol).collect(Collectors.toSet());
            //  删除已经下架的币种
            Set<String> symbolSet = getList.stream().map(CurrencyKucoin::getSymbol).collect(Collectors.toSet());
            List<Currency> removeList = dbList.stream()
                    .filter(currency -> !symbolSet.contains(currency.getSymbol()))
                    .collect(Collectors.toList());
@@ -83,13 +87,17 @@
            if(CollectionUtils.isNotEmpty(removeList)){
                removeList.forEach(f->{
                    RedisUtil.delete("kucoin"+f.getSymbol());
                    currencyService.remove(new LambdaQueryWrapper<Currency>().eq(Currency::getSymbol,f.getSymbol()));
                });
            }
            currencyService.remove(new LambdaQueryWrapper<Currency>().eq(Currency::getSource,"kucoin"));
            //  比对接口返回的数据和数据库中已有的数据,找出新增的数据
            Set<String> loclSymbolSet = dbList.stream().map(Currency::getSymbol).collect(Collectors.toSet());
            List<Currency> saveList = getList.stream()
                    .filter(currency -> !loclSymbolSet.contains(currency.getSymbol()))
                    .map(currency -> {
                        Currency newCurrency = new Currency();
                        newCurrency.setSymbol(currency.getSymbol());