package com.xcong.excoin.modules.okxNewPrice.okxWs;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.xcong.excoin.modules.okxNewPrice.okxWs.enums.ExchangeInfoEnum;
|
import com.xcong.excoin.modules.okxNewPrice.utils.SignUtils;
|
import com.xcong.excoin.modules.okxNewPrice.utils.WsParamBuild;
|
import lombok.extern.slf4j.Slf4j;
|
import org.java_websocket.client.WebSocketClient;
|
|
/**
|
* @author Administrator
|
*/
|
@Slf4j
|
public class LoginWs {
|
public static void websocketLogin(WebSocketClient webSocketClient, ExchangeInfoEnum account) {
|
|
// log.info("开始执行LoginWs......");
|
try {
|
|
JSONArray argsArray = new JSONArray();
|
JSONObject loginArgs = new JSONObject();
|
// 获取登录凭证信息(需要从配置或Redis中获取)
|
String apiKey = account.getApiKey();
|
String passphrase = account.getPassphrase();
|
String timestamp = String.valueOf(System.currentTimeMillis() /1000);
|
String sign = SignUtils.signWebsocket(timestamp, account.getSecretKey());
|
|
loginArgs.put("apiKey", apiKey);
|
loginArgs.put("passphrase", passphrase);
|
loginArgs.put("timestamp", timestamp);
|
loginArgs.put("sign", sign);
|
argsArray.add(loginArgs);
|
|
String option = "login";
|
JSONObject login = WsParamBuild.buildJsonObject(null,option, argsArray);
|
webSocketClient.send(login.toJSONString());
|
log.info("发送登录:{}",option);
|
} catch (Exception e) {
|
log.error("WebSocket登录请求构建失败", e);
|
}
|
}
|
}
|