1
zj
2024-07-20 378b31595f7eebdf46149fa2052cec41f7ce9565
websocketClient/src/main/java/org/example/WsBean/MexcWsBean.java
@@ -1,6 +1,8 @@
package org.example.WsBean;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -15,6 +17,7 @@
import org.example.wsClient.GateClient;
import org.example.wsClient.KucoinClient;
import org.example.wsClient.MexcClient;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -60,31 +63,33 @@
//        }
//    }
    @Bean
    public void gateWebsocketRunClientMap() {
        List<Currency> mexc = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "gate"));
        if (!CollectionUtils.isEmpty(mexc)) {
            int batchSize = 100; // 每个线程处理的数据量
            int totalSize = mexc.size();
            int threadCount = (int) Math.ceil((double) totalSize / batchSize); // 计算需要的线程数
            for (int i = 0; i < threadCount; i++) {
                int fromIndex = i * batchSize;
                int toIndex = Math.min(fromIndex + batchSize, totalSize);
                List<Currency> sublist = mexc.subList(fromIndex, toIndex);
                // 使用自定义线程池提交任务
                threadPoolTaskExecutor.execute(new GateClient(sublist)::start);
            }
        }
    }
//    @Bean
//    public void gateWebsocketRunClientMap() {
//        List<Currency> mexc = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "gate"));
//        if (!CollectionUtils.isEmpty(mexc)) {
//            int batchSize = 100; // 每个线程处理的数据量
//            int totalSize = mexc.size();
//            int threadCount = (int) Math.ceil((double) totalSize / batchSize); // 计算需要的线程数
//
//            for (int i = 0; i < threadCount; i++) {
//                int fromIndex = i * batchSize;
//                int toIndex = Math.min(fromIndex + batchSize, totalSize);
//                List<Currency> sublist = mexc.subList(fromIndex, toIndex);
//
//                // 使用自定义线程池提交任务
//                threadPoolTaskExecutor.execute(new GateClient(sublist)::start);
//            }
//
//        }
//    }
    @Bean
    public void kucoinWebsocketRunClientMap() throws Exception {
        List<Currency> mexc = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "gate"));
        List<Currency> mexc = currencyService.list(new LambdaQueryWrapper<Currency>().eq(Currency::getSource, "kucoin"));
        if (!CollectionUtils.isEmpty(mexc)) {
            String token = doPost();
            String result = doPost();
            JSONObject jsonObject = new JSONObject(result);
            String token = jsonObject.getJSONObject("data").getString("token");
            int batchSize = 100; // 每个线程处理的数据量
            int totalSize = mexc.size();
            int threadCount = (int) Math.ceil((double) totalSize / batchSize); // 计算需要的线程数