|
10 | 10 | import com.binance.connector.client.common.websocket.dtos.ApiRequestWrapperDTO; |
11 | 11 | import com.binance.connector.client.common.websocket.dtos.BaseRequestDTO; |
12 | 12 | import com.binance.connector.client.common.websocket.dtos.RequestWrapperDTO; |
13 | | -import com.binance.connector.client.common.websocket.dtos.SessionLogonResponse; |
| 13 | +import com.binance.connector.client.common.websocket.dtos.SessionResponse; |
14 | 14 | import com.binance.connector.client.common.websocket.service.DeserializeExclusionStrategy; |
15 | 15 | import com.binance.connector.client.common.websocket.service.SerializeExclusionStrategy; |
16 | 16 | import com.google.gson.Gson; |
@@ -64,13 +64,13 @@ public class ConnectionWrapper implements WebSocketListener, ConnectionInterface |
64 | 64 | // -2015 for wrong API Keys, -1022 for wrong signature |
65 | 65 | private static final List<Integer> ERROR_CODE_WRONG_CREDENTIALS = Arrays.asList(-2015, -1022); |
66 | 66 |
|
67 | | - private static final String LOGON_METHOD = "session.logon"; |
68 | | - private static final String LOGOUT_METHOD = "session.logout"; |
69 | | - |
70 | 67 | protected Map<String, RequestWrapperDTO> pendingRequest = new HashMap<>(); |
71 | 68 | protected Session session; |
72 | 69 | protected Session oldSession; |
73 | 70 |
|
| 71 | + protected List<String> logonMethods = new ArrayList<>(); |
| 72 | + protected List<String> logoutMethods = new ArrayList<>(); |
| 73 | + |
74 | 74 | private String userAgent = |
75 | 75 | String.format( |
76 | 76 | "binance-connector-java/1.0.0 (Java/%s; %s; %s)", |
@@ -193,7 +193,7 @@ public void connect() { |
193 | 193 | public void connect(Consumer<Session> customCallback) |
194 | 194 | throws IOException, URISyntaxException, InterruptedException { |
195 | 195 | pendingReconnect = false; |
196 | | - boolean autoLogon = configuration.getAutoLogon(); |
| 196 | + boolean autoLogon = !logonMethods.isEmpty() && (configuration.getAutoLogon() || isLoggedOn); |
197 | 197 |
|
198 | 198 | // For LogOn mode, we need the logon to be completed before changing the session |
199 | 199 | countDownLatch = new CountDownLatch(autoLogon ? 1 : 0); |
@@ -399,12 +399,12 @@ public void logOn(Session session) throws CryptoException { |
399 | 399 | .build(); |
400 | 400 |
|
401 | 401 | build.setSignature(signatureGenerator.signAsString(build.toString())); |
402 | | - RequestWrapperDTO<? extends BaseRequestDTO, SessionLogonResponse> request = |
403 | | - new RequestWrapperDTO.Builder<BaseRequestDTO, SessionLogonResponse>() |
| 402 | + RequestWrapperDTO<? extends BaseRequestDTO, SessionResponse> request = |
| 403 | + new RequestWrapperDTO.Builder<BaseRequestDTO, SessionResponse>() |
404 | 404 | .id(UUID.randomUUID().toString()) |
405 | | - .method("session.logon") |
| 405 | + .method(logonMethods.get(0)) |
406 | 406 | .params(build) |
407 | | - .responseType(SessionLogonResponse.class) |
| 407 | + .responseType(SessionResponse.class) |
408 | 408 | .build(); |
409 | 409 |
|
410 | 410 | request.getResponseCallback() |
@@ -462,13 +462,13 @@ public void onWebSocketText(String message) { |
462 | 462 | Object responseResult = gson.fromJson(root, responseType); |
463 | 463 | pendingRequest.remove(id); |
464 | 464 |
|
465 | | - if (LOGON_METHOD.equals(requestWrapperDTO.getMethod())) { |
| 465 | + if (this.logonMethods.contains(requestWrapperDTO.getMethod())) { |
466 | 466 | if (obj.get("status").getAsInt() == 200) { |
467 | 467 | isLoggedOn = true; |
468 | 468 | } |
469 | 469 | } |
470 | 470 |
|
471 | | - if (LOGOUT_METHOD.equals(requestWrapperDTO.getMethod())) { |
| 471 | + if (this.logoutMethods.contains(requestWrapperDTO.getMethod())) { |
472 | 472 | if (obj.get("status").getAsInt() == 200) { |
473 | 473 | isLoggedOn = false; |
474 | 474 | } |
@@ -509,6 +509,16 @@ public boolean isConnected() { |
509 | 509 | return session != null && session.isOpen(); |
510 | 510 | } |
511 | 511 |
|
| 512 | + @Override |
| 513 | + public void setLogonMethods(List<String> logonMethods) { |
| 514 | + this.logonMethods = logonMethods; |
| 515 | + } |
| 516 | + |
| 517 | + @Override |
| 518 | + public void setLogoutMethods(List<String> logoutMethods) { |
| 519 | + this.logoutMethods = logoutMethods; |
| 520 | + } |
| 521 | + |
512 | 522 | public URI getUri(String uri) throws URISyntaxException { |
513 | 523 | URI oldUri = new URI(uri); |
514 | 524 |
|
|
0 commit comments