Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For Spot (Spot package):
<dependency>
<groupId>io.github.binance</groupId>
<artifactId>binance-spot</artifactId>
<version>5.0.1</version>
<version>6.0.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Each connector is published as a separate maven dependency. For example:
<dependency>
<groupId>io.github.binance</groupId>
<artifactId>binance-spot</artifactId>
<version>5.0.1</version>
<version>6.0.0</version>
</dependency>
```

Expand Down
19 changes: 16 additions & 3 deletions clients/common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# Changelog

## 2.0.1 - 2025-08-20

- Inject session log on and log out method names.
- Auto re-logon after reconnect.

## 2.0.0 - 2025-08-07

- authNames param as Set instead of array of String.

## 1.4.0 - 2025-07-17

- Handle streams through WebSocket API

## 1.3.0 - 2025-07-08

- Support custom headers for REST API requests (`customHeaders` option on `ClientConfiguration`).
- Added `messageMaxSize` configuration for websocket.
- Added getter for `RateLimits` in `ApiResponse`
- Added getter for `RateLimits` in `ApiResponse`.

## 1.2.0 - 2025-05-13

- Add proxy authentication for websocket
- Add proxy authentication for websocket.

## 1.1.0 - 2025-05-02

Expand All @@ -17,4 +30,4 @@

## 1.0.0 - 2025-04-24

- Initial release
- Initial release.
2 changes: 1 addition & 1 deletion clients/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

<artifactId>binance-common</artifactId>
<name>common</name>
<version>2.0.0</version>
<version>2.0.1</version>
<packaging>jar</packaging>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.binance.connector.client.common.websocket.dtos.ApiRequestWrapperDTO;
import com.binance.connector.client.common.websocket.dtos.RequestWrapperDTO;

import java.util.List;
import java.util.concurrent.BlockingQueue;

public interface ConnectionInterface {
Expand All @@ -16,4 +18,9 @@ public interface ConnectionInterface {
void setUserAgent(String userAgent);

boolean isConnected();

void setLogonMethods(List<String> logonMethods);

void setLogoutMethods(List<String> logoutMethods);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.binance.connector.client.common.websocket.dtos.ApiRequestWrapperDTO;
import com.binance.connector.client.common.websocket.dtos.BaseRequestDTO;
import com.binance.connector.client.common.websocket.dtos.RequestWrapperDTO;
import com.binance.connector.client.common.websocket.dtos.SessionLogonResponse;
import com.binance.connector.client.common.websocket.dtos.SessionResponse;
import com.binance.connector.client.common.websocket.service.DeserializeExclusionStrategy;
import com.binance.connector.client.common.websocket.service.SerializeExclusionStrategy;
import com.google.gson.Gson;
Expand Down Expand Up @@ -64,13 +64,13 @@ public class ConnectionWrapper implements WebSocketListener, ConnectionInterface
// -2015 for wrong API Keys, -1022 for wrong signature
private static final List<Integer> ERROR_CODE_WRONG_CREDENTIALS = Arrays.asList(-2015, -1022);

private static final String LOGON_METHOD = "session.logon";
private static final String LOGOUT_METHOD = "session.logout";

protected Map<String, RequestWrapperDTO> pendingRequest = new HashMap<>();
protected Session session;
protected Session oldSession;

protected List<String> logonMethods = new ArrayList<>();
protected List<String> logoutMethods = new ArrayList<>();

private String userAgent =
String.format(
"binance-connector-java/1.0.0 (Java/%s; %s; %s)",
Expand Down Expand Up @@ -193,7 +193,7 @@ public void connect() {
public void connect(Consumer<Session> customCallback)
throws IOException, URISyntaxException, InterruptedException {
pendingReconnect = false;
boolean autoLogon = configuration.getAutoLogon();
boolean autoLogon = !logonMethods.isEmpty() && (configuration.getAutoLogon() || isLoggedOn);

// For LogOn mode, we need the logon to be completed before changing the session
countDownLatch = new CountDownLatch(autoLogon ? 1 : 0);
Expand Down Expand Up @@ -399,12 +399,12 @@ public void logOn(Session session) throws CryptoException {
.build();

build.setSignature(signatureGenerator.signAsString(build.toString()));
RequestWrapperDTO<? extends BaseRequestDTO, SessionLogonResponse> request =
new RequestWrapperDTO.Builder<BaseRequestDTO, SessionLogonResponse>()
RequestWrapperDTO<? extends BaseRequestDTO, SessionResponse> request =
new RequestWrapperDTO.Builder<BaseRequestDTO, SessionResponse>()
.id(UUID.randomUUID().toString())
.method("session.logon")
.method(logonMethods.get(0))
.params(build)
.responseType(SessionLogonResponse.class)
.responseType(SessionResponse.class)
.build();

request.getResponseCallback()
Expand Down Expand Up @@ -462,13 +462,13 @@ public void onWebSocketText(String message) {
Object responseResult = gson.fromJson(root, responseType);
pendingRequest.remove(id);

if (LOGON_METHOD.equals(requestWrapperDTO.getMethod())) {
if (this.logonMethods.contains(requestWrapperDTO.getMethod())) {
if (obj.get("status").getAsInt() == 200) {
isLoggedOn = true;
}
}

if (LOGOUT_METHOD.equals(requestWrapperDTO.getMethod())) {
if (this.logoutMethods.contains(requestWrapperDTO.getMethod())) {
if (obj.get("status").getAsInt() == 200) {
isLoggedOn = false;
}
Expand Down Expand Up @@ -509,6 +509,16 @@ public boolean isConnected() {
return session != null && session.isOpen();
}

@Override
public void setLogonMethods(List<String> logonMethods) {
this.logonMethods = logonMethods;
}

@Override
public void setLogoutMethods(List<String> logoutMethods) {
this.logoutMethods = logoutMethods;
}

public URI getUri(String uri) throws URISyntaxException {
URI oldUri = new URI(uri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import com.binance.connector.client.common.websocket.dtos.ApiRequestWrapperDTO;
import com.binance.connector.client.common.websocket.dtos.RequestWrapperDTO;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Timer;
import java.util.TimerTask;
Expand All @@ -22,6 +25,9 @@ public class PoolConnectionWrapper implements ConnectionInterface {
"binance-connector-java/1.0.0 (Java/%s; %s; %s)",
SystemUtil.getJavaVersion(), SystemUtil.getOs(), SystemUtil.getArch());

protected List<String> logonMethod = new ArrayList<>();
protected List<String> logoutMethod = new ArrayList<>();

public PoolConnectionWrapper(WebSocketClientConfiguration clientConfiguration) {
this(clientConfiguration, null);
}
Expand Down Expand Up @@ -73,6 +79,8 @@ public void run() {
public void connect() {
for (ConnectionWrapper connectionWrapper : connectionList) {
connectionWrapper.setUserAgent(userAgent);
connectionWrapper.setLogonMethods(logonMethod);
connectionWrapper.setLogoutMethods(logoutMethod);
connectionWrapper.connect();
}
isConnected = true;
Expand Down Expand Up @@ -113,7 +121,19 @@ public ConnectionWrapper getConnection() {
}

@Override
public void setUserAgent(String userAgent) {}
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}

@Override
public void setLogonMethods(List<String> logonMethods) {
this.logonMethod = logonMethods;
}

@Override
public void setLogoutMethods(List<String> logoutMethods) {
this.logoutMethod = logoutMethods;
}

@Override
public boolean isConnected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void setTimestamp(String timestamp) {
}

public String toUrlQueryString() {
return "timestamp=" + getTimestamp();
return "apiKey=" + apiKey + "&timestamp=" + timestamp;
}

@Override
Expand Down
Loading
Loading