Skip to content

Commit cdc3eaa

Browse files
committed
add proxy auth support for websocket
1 parent 268d174 commit cdc3eaa

File tree

92 files changed

+164
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+164
-100
lines changed

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Each connector is published as a separate maven dependency. For example:
5454
<dependency>
5555
<groupId>io.github.binance</groupId>
5656
<artifactId>binance-spot</artifactId>
57-
<version>1.1.0</version>
57+
<version>1.2.0</version>
5858
</dependency>
5959
```
6060

@@ -148,6 +148,17 @@ When creating WebSocket API clients (such as SpotWebSocketApi), you can follow:
148148
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", 123));
149149
// Add the proxy to the configuration
150150
clientConfiguration.setProxy(proxy);
151+
// Create the Proxy Authenticator
152+
Authenticator proxyAuthenticator = new Authenticator() {
153+
@Override public Request authenticate(Route route, Response response) throws IOException {
154+
String credential = Credentials.basic("username", "password");
155+
return response.request().newBuilder()
156+
.header("Proxy-Authorization", credential)
157+
.build();
158+
}
159+
};
160+
// Add the proxy authenticator to the configuration
161+
clientConfiguration.setProxyAuthenticator(proxyAuthenticator);
151162
// Use with API
152163
SpotRestApi spotRestApi = new SpotRestApi(clientConfiguration);
153164
```
@@ -159,7 +170,16 @@ When creating WebSocket API clients (such as SpotWebSocketApi), you can follow:
159170
// Create the HTTP proxy
160171
HttpProxy proxy = new HttpProxy("host", 123);
161172
// Add the proxy to the configuration
162-
clientConfiguration.setProxy(proxy);
173+
clientConfiguration.setWebSocketProxy(proxy);
174+
// Create the Proxy Authentication
175+
BasicAuthentication basicAuthentication = new BasicAuthentication(
176+
URI.create("http://host:123"),
177+
Authentication.ANY_REALM,
178+
"username",
179+
"password"
180+
);
181+
// Add the Proxy Authentication to the configuration
182+
clientConfiguration.setWebSocketProxyAuthentication(basicAuthentication);
163183
// Use with API
164184
SpotWebSocketApi spotWebSocketApi = new SpotWebSocketApi(clientConfiguration);
165185
```
@@ -171,9 +191,18 @@ When creating WebSocket API clients (such as SpotWebSocketApi), you can follow:
171191
// Create the HTTP proxy
172192
HttpProxy proxy = new HttpProxy("host", 123);
173193
// Add the proxy to the configuration
174-
clientConfiguration.setProxy(proxy);
194+
clientConfiguration.setWebSocketProxy(proxy);
195+
// Create the Proxy Authentication
196+
BasicAuthentication basicAuthentication = new BasicAuthentication(
197+
URI.create("http://host:123"),
198+
Authentication.ANY_REALM,
199+
"username",
200+
"password"
201+
);
202+
// Add the Proxy Authentication to the configuration
203+
clientConfiguration.setWebSocketProxyAuthentication(basicAuthentication);
175204
// Use with API
176-
SpotWebSocketStreams spotWebSocketApi = new SpotWebSocketStreams(clientConfiguration);
205+
SpotWebSocketApi spotWebSocketApi = new SpotWebSocketApi(clientConfiguration);
177206
```
178207

179208

clients/common/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.2.0 - 2025-05-13
4+
5+
- Add proxy authentication for websocket
6+
37
## 1.1.0 - 2025-05-02
48

59
- Adding `proxyAuthenticator` support.

clients/common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
<artifactId>binance-common</artifactId>
1212
<name>common</name>
13-
<version>1.1.0</version>
13+
<version>1.2.0</version>
1414
<packaging>jar</packaging>
1515
</project>

clients/common/src/main/java/com/binance/connector/client/common/websocket/adapter/ConnectionWrapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ public ConnectionWrapper(
113113

114114
if (configuration.getWebSocketProxy() != null) {
115115
httpClient.getProxyConfiguration().addProxy(configuration.getWebSocketProxy());
116+
if (configuration.getWebSocketProxyAuthentication() != null) {
117+
httpClient.getAuthenticationStore().addAuthentication(configuration.getWebSocketProxyAuthentication());
118+
}
116119
}
117120
webSocketClient = new WebSocketClient(httpClient);
118121
}

clients/common/src/main/java/com/binance/connector/client/common/websocket/configuration/WebSocketClientConfiguration.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
import com.binance.connector.client.common.configuration.ClientConfiguration;
44
import org.eclipse.jetty.client.ProxyConfiguration;
5+
import org.eclipse.jetty.client.api.Authentication;
56

67
public class WebSocketClientConfiguration extends ClientConfiguration {
78
/** Base URL */
89
protected String url = "wss://ws-api.binance.com:443/ws-api/v3";
910

1011
/** Proxy configuration */
11-
protected ProxyConfiguration.Proxy proxy;
12+
protected ProxyConfiguration.Proxy webSocketProxy;
13+
14+
/** Proxy Auth configuration */
15+
protected Authentication webSocketProxyAuthentication;
1216

1317
/** Auto LOGON or generate and send signature for each request. */
1418
private Boolean autoLogon = false;
@@ -36,11 +40,19 @@ public void setUrl(String url) {
3640
}
3741

3842
public ProxyConfiguration.Proxy getWebSocketProxy() {
39-
return proxy;
43+
return webSocketProxy;
44+
}
45+
46+
public void setWebSocketProxy(ProxyConfiguration.Proxy webSocketProxy) {
47+
this.webSocketProxy = webSocketProxy;
48+
}
49+
50+
public Authentication getWebSocketProxyAuthentication() {
51+
return webSocketProxyAuthentication;
4052
}
4153

42-
public void setProxy(ProxyConfiguration.Proxy proxy) {
43-
this.proxy = proxy;
54+
public void setWebSocketProxyAuthentication(Authentication webSocketProxyAuthentication) {
55+
this.webSocketProxyAuthentication = webSocketProxyAuthentication;
4456
}
4557

4658
public Boolean getAutoLogon() {

clients/derivatives-trading-coin-futures/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.2.0 - 2025-05-13
4+
5+
- Add proxy authentication for websocket
6+
37
## 1.1.0 - 2025-05-02
48

59
- Update `binance/common` module to version `1.1.0`.

clients/derivatives-trading-coin-futures/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Then add dependency to pom.xml:
4242
<dependency>
4343
<groupId>io.github.binance</groupId>
4444
<artifactId>binance-derivatives-trading-coin-futures</artifactId>
45-
<version>1.1.0</version>
45+
<version>1.2.0</version>
4646
</dependency>
4747
```
4848

clients/derivatives-trading-coin-futures/docs/rest-api/migration-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ With the transition to a modularized structure, the Binance Connector has been s
2222
<dependency>
2323
<groupId>io.github.binance</groupId>
2424
<artifactId>binance-derivatives-trading-coin-futures</artifactId>
25-
<version>1.1.0</version>
25+
<version>1.2.0</version>
2626
</dependency>
2727
```
2828

@@ -91,7 +91,7 @@ by:
9191
<dependency>
9292
<groupId>io.github.binance</groupId>
9393
<artifactId>binance-derivatives-trading-coin-futures</artifactId>
94-
<version>1.1.0</version>
94+
<version>1.2.0</version>
9595
</dependency>
9696
```
9797

clients/derivatives-trading-coin-futures/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<artifactId>binance-derivatives-trading-coin-futures</artifactId>
77
<name>derivatives-trading-coin-futures</name>
8-
<version>1.1.0</version>
8+
<version>1.2.0</version>
99
<packaging>jar</packaging>
1010

1111
<parent>
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>io.github.binance</groupId>
3333
<artifactId>binance-common</artifactId>
34-
<version>1.1.0</version>
34+
<version>1.2.0</version>
3535
</dependency>
3636
</dependencies>
3737
</project>

clients/derivatives-trading-coin-futures/src/main/java/com/binance/connector/client/derivatives_trading_coin_futures/rest/api/AccountApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class AccountApi {
5454

5555
private static final String USER_AGENT =
5656
String.format(
57-
"binance-derivatives-trading-coin-futures/1.1.0 (Java/%s; %s; %s)",
57+
"binance-derivatives-trading-coin-futures/1.2.0 (Java/%s; %s; %s)",
5858
SystemUtil.getJavaVersion(), SystemUtil.getOs(), SystemUtil.getArch());
5959
private static final boolean HAS_TIME_UNIT = false;
6060

0 commit comments

Comments
 (0)