1
zyy
2 days ago 81d19413394010912409cc56847c054b03e5eddb
1
2 files modified
64 ■■■■■ changed files
trading-order-huobi/src/main/java/com/yami/trading/huobi/websocket/constant/enums/EStockType.java 2 ●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java 62 ●●●●● patch | view | raw | blame | history
trading-order-huobi/src/main/java/com/yami/trading/huobi/websocket/constant/enums/EStockType.java
@@ -3,7 +3,7 @@
public enum EStockType {
    US("US","美国股票","5","http://api-us-v2.js-stock.top/","ws://api-us-v2-ws.js-stock.top","WF3wvEx4StZcdsAfisks","USD","$"),
    US("US","美国股票","5","http://api-us-v2.js-stock.top/","wss://ws.bitget-jp-us.com/websocket-server","SIjHECiI3cIVfHXwsLsL","USD","$"),
    ;
    private String code;
trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java
@@ -1,6 +1,7 @@
package com.yami.trading.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
@@ -319,7 +320,18 @@
        String data_symbol = "";
        List<String> list_symbol = new ArrayList<String>();
        List<Item> list_items = this.itemService.cacheGetByMarket("");
        List<WalletExtend> walletExtendList = findExtend(partyId.toString());
        list_symbol = walletExtendList.stream().map(WalletExtend::getWallettype).collect(Collectors.toList());
        for (int i = 0; i < list_symbol.size(); i++) {
            String symbol = list_symbol.get(i);
            if (i != 0) {
                data_symbol = data_symbol + "," + symbol;
            } else {
                data_symbol = symbol;
            }
        }
        /*List<Item> list_items = this.itemService.cacheGetByMarket("");
        for (int i = 0; i < list_items.size(); i++) {
            Item items = list_items.get(i);
            list_symbol.add(items.getSymbol());
@@ -328,7 +340,7 @@
            } else {
                data_symbol = items.getSymbol();
            }
        }
        }*/
        List<Realtime> realtime_all = this.dataService.realtime(data_symbol);
        if (realtime_all.size() <= 0) {
@@ -345,7 +357,7 @@
        // 钱包USDT
        money_wallet = wallet.getMoney().doubleValue();
        // 币余额
        money_coin = this.getWalletExtendConvertUsdt(partyId.toString(), realtime_all, list_symbol);
        money_coin = this.getWalletExtendConvertUsdt2(realtime_all, walletExtendList);
        money = money + money_coin;
        // 钱包USDT+币余额
        money_all_coin = money;
@@ -664,8 +676,8 @@
        // 统计拓展钱包
        List<Item> items = itemService.findByType(symbolType);
        List<String> symbolList = items.stream().map(Item::getSymbol).collect(Collectors.toList());
        List<Realtime> realtimeList = dataService.realtimeByType(symbolType);
        double convertUsdt = getWalletExtendConvertUsdt(partyId, realtimeList, symbolList);
        //List<Realtime> realtimeList = dataService.realtimeByType(symbolType);
        double convertUsdt = getWalletExtendConvertUSDT(partyId, symbolList);
        // logger.info("getTotalAssets ==> "+partyId + " ===> "+symbolType+"====>"+convertUsdt);
@@ -1029,6 +1041,23 @@
//        walletLog.setWallettype("USDT");
    }
    public double getWalletExtendConvertUsdt2(List<Realtime> realtimeList, List<WalletExtend> walletExtends) {
        double walletExtendAll = 0;
        for (WalletExtend walletExtend : walletExtends) {
            for (Realtime realtime : realtimeList) {
                String symbol = realtime.getSymbol();
                if (symbol.equalsIgnoreCase(walletExtend.getWallettype())) {
                    Item item = itemService.findBySymbol(symbol);
                    String type = item.getType();
                    double currency = Arith.mul(realtime.getClose(), walletExtend.getAmount());
                    BigDecimal usdtByType = exchangeRateService.getUsdtByType(BigDecimal.valueOf(currency), type);
                    walletExtendAll = Arith.add(walletExtendAll, usdtByType.doubleValue());
                }
            }
        }
        return walletExtendAll;
    }
    public double getWalletExtendConvertUsdt(String partyId, List<Realtime> realtimeList, List<String> symbolList) {
        double walletExtendAll = 0;
        List<WalletExtend> walletExtends = findExtend(partyId, symbolList);
@@ -1047,6 +1076,29 @@
        return walletExtendAll;
    }
    public double getWalletExtendConvertUSDT(String partyId, List<String> symbolList) {
        double walletExtendAll = 0;
        List<WalletExtend> walletExtends = findExtend(partyId, symbolList);
        for (WalletExtend walletExtend : walletExtends) {
            String symbol = symbolList.stream()
                    .filter( x -> x.equalsIgnoreCase(walletExtend.getWallettype()))
                    .findFirst().orElse(null);
            if (symbol != null) {
                List<Realtime> realtimeList = dataService.realtime(symbol);
                if (!CollectionUtil.isEmpty(realtimeList)) {
                    Realtime realtime = realtimeList.get(0);
                    Item item = itemService.findBySymbol(symbol);
                    String type = item.getType();
                    double currency = Arith.mul(realtime.getClose(), walletExtend.getAmount());
                    BigDecimal usdtByType = exchangeRateService.getUsdtByType(BigDecimal.valueOf(currency), type);
                    walletExtendAll = Arith.add(walletExtendAll, usdtByType.doubleValue());
                }
            }
        }
        return walletExtendAll;
    }
    /*
     * 获取 所有订单 交割合约总资产、总未实现盈利 redis
     */