WebSocket 连接问题:多个账户订阅余额和持仓频道,为何只有最后一个账户建立连接?
The reason only the last account establishes a connection is because the 'WebSocketClient' instance is a static variable. When you call 'WebSocketConfig.loginConnect(webSocketClient, apikey, passphrase, secretkey);' for each account, you are overwriting the previous connection with a new one.
To fix this issue, you can create a new 'WebSocketClient' instance for each account. Here's an updated version of the code:
@Override
public void subscribe(String apikey, String secretkey, String passphrase) {
log.info('账户余额和持仓频道');
WebSocketClient webSocketClient = new WebSocketClient(); // Create a new WebSocketClient instance
WebSocketConfig.loginConnect(webSocketClient, apikey, passphrase, secretkey);
ArrayList<Map> channelLists = new ArrayList<>();
Map spotTickerMap = new HashMap();
spotTickerMap.put('channel', 'balance_and_position');
channelLists.add(spotTickerMap);
//调用订阅方法
WebSocketClient.subscribe(channelLists);
}
By creating a new 'WebSocketClient' instance for each account, you can establish a separate connection for each account.
原文地址: https://www.cveoy.top/t/topic/o9Dh 著作权归作者所有。请勿转载和采集!