1
zj
2024-08-12 440f0f0b37a10c82e54f402be8d4d99c7406b4d4
websocketSerivce/src/main/java/org/example/server/impl/CurrencySerivceImpl.java
@@ -197,9 +197,14 @@
                if (markets1.getBids() == null) continue;
                for (int j = 0; j < exchanges.length; j++) {
                    if (i == j) continue;
                    MarketBo markets2 = exchangeMap.get(exchanges[j]);
                    if(markets1.getExchange().equals(markets2.getExchange())){
                        continue;
                    }
                    if (markets2.getAsks() == null) continue;
                    CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
@@ -237,13 +242,13 @@
    private static void assembleMarketDataOut(String coinName, MarketBo markets1, MarketBo markets2, BigDecimal profitPercentage, BigDecimal buyPrice, BigDecimal sellPrice, List<MarketDataOut> marketDataOuts, String formattedDateTime) {
        MarketDataOut marketDataOut = new MarketDataOut();
        marketDataOut.setBaseAsset(coinName.replaceAll("USDT","").toLowerCase().toUpperCase()); // 设置基础资产
        marketDataOut.setBuyingPlatform(markets1.getExchange().toUpperCase()); // 设置买入平台
        marketDataOut.setSellPlatform(markets2.getExchange().toUpperCase()); // 设置卖出平台
        marketDataOut.setBuyingPlatform(capitalizeFirstLetter(markets1.getExchange())); // 设置买入平台,首字母大写
        marketDataOut.setSellPlatform(capitalizeFirstLetter(markets2.getExchange())); // 设置卖出平台,首字母大写
        marketDataOut.setSpread(profitPercentage.setScale(4, RoundingMode.DOWN).toPlainString()); // 设置利润百分比
        marketDataOut.setBuyPrice(buyPrice.toPlainString()); // 设置买入价格
        marketDataOut.setSellPrice(sellPrice.toPlainString()); // 设置卖出价格
        marketDataOut.setBuyNumber(markets1.getBids().getV().toPlainString()); // 设置买入数量
        marketDataOut.setSellNumber(markets2.getAsks().getV().toPlainString()); // 设置卖出数量
        marketDataOut.setBuyNumber(markets1.getBids().getV().setScale(4, RoundingMode.HALF_UP).toPlainString()); // 设置买入数量
        marketDataOut.setSellNumber(markets2.getAsks().getV().setScale(4, RoundingMode.HALF_UP).toPlainString()); // 设置卖出数量
        marketDataOut.setBuyTotalPrice((markets1.getBids().getP().multiply(markets1.getBids().getV())).setScale(0, RoundingMode.HALF_UP).toPlainString()); // 设置买入总价
        marketDataOut.setSellTotalPrice((markets2.getAsks().getP().multiply(markets2.getAsks().getV())).setScale(0,RoundingMode.HALF_UP).toPlainString()); // 设置卖出总价
        marketDataOut.setServceTime(formattedDateTime); // 设置服务时间
@@ -251,6 +256,14 @@
        marketDataOuts.add(marketDataOut); // 添加到输出列表
    }
    public static String capitalizeFirstLetter(String word) {
        if (word == null || word.isEmpty()) {
            return word;
        }
        return Character.toUpperCase(word.charAt(0)) + word.substring(1);
    }
    private void pushWs(List<MarketDataOut> marketDataOuts) {
//        String key = "MARKET_Date";
//        // 创建 Gson 对象