Skip to content

Commit 4cf3ed8

Browse files
authored
Merge pull request #234 from binance/common_v2.5.0
Release common v2.5.0
2 parents df0c9e8 + 12df662 commit 4cf3ed8

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

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>2.4.2</version>
13+
<version>2.5.0</version>
1414
<packaging>jar</packaging>
1515
</project>

clients/common/src/main/java/com/binance/connector/client/common/ApiClient.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,8 @@ public ApiClient(
215215

216216
SignatureConfiguration signatureConfiguration = configuration.getSignatureConfiguration();
217217
if (signatureConfiguration != null) {
218-
Authentication authentication =
219-
binanceAuthenticationFactory.getAuthentication(signatureConfiguration);
220-
if (authentication != null) {
221-
authentications.put(BINANCE_SIGNATURE, authentication);
222-
}
218+
Map<String, Authentication> customAuthentications = getCustomAuthentications(binanceAuthenticationFactory, signatureConfiguration);
219+
authentications.putAll(customAuthentications);
223220
}
224221

225222
Authentication binanceApiKeyOnly =
@@ -515,6 +512,21 @@ public Map<String, Authentication> getAuthentications() {
515512
return authentications;
516513
}
517514

515+
/**
516+
* Get custom authentications to be added (key: authentication name, value: authentication).
517+
*
518+
* @return Map of authentication objects
519+
*/
520+
protected Map<String, Authentication> getCustomAuthentications(BinanceAuthenticationFactory binanceAuthenticationFactory, SignatureConfiguration signatureConfiguration) {
521+
Map<String, Authentication> authentications = new HashMap<>();
522+
Authentication authentication =
523+
binanceAuthenticationFactory.getAuthentication(signatureConfiguration);
524+
if (authentication != null) {
525+
authentications.put(BINANCE_SIGNATURE, authentication);
526+
}
527+
return authentications;
528+
}
529+
518530
/**
519531
* Get authentication for the given name.
520532
*
@@ -1215,8 +1227,7 @@ public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiExceptio
12151227
try {
12161228
Response response = call.execute();
12171229
T data = handleResponse(response, returnType);
1218-
Map<RateLimitType, RateLimit> rateLimit =
1219-
getRateLimit(response.code(), response.headers());
1230+
Map<RateLimitType, ? extends RateLimit> rateLimit = getRateLimit(response.code(), response.headers());
12201231
return new ApiResponse<T>(
12211232
response.code(), response.headers().toMultimap(), data, rateLimit);
12221233
} catch (IOException e) {
@@ -1571,7 +1582,7 @@ public void updateParamsForAuth(
15711582
for (String authName : authNames) {
15721583
Authentication auth = authentications.get(authName);
15731584
if (auth == null) {
1574-
if (BINANCE_SIGNATURE.equals(authName)) {
1585+
if (isRequiredAuth(authName)) {
15751586
throw new RuntimeException(
15761587
"Request is signed, please add signatureConfiguration to"
15771588
+ " clientConfiguration");
@@ -1586,6 +1597,10 @@ public void updateParamsForAuth(
15861597
}
15871598
}
15881599

1600+
protected boolean isRequiredAuth(String authName) {
1601+
return BINANCE_SIGNATURE.equals(authName);
1602+
}
1603+
15891604
/**
15901605
* Build a form-encoding request body with the given form parameters.
15911606
*
@@ -1819,7 +1834,7 @@ private String requestBodyToString(RequestBody requestBody) throws ApiException
18191834
return "";
18201835
}
18211836

1822-
private Map<RateLimitType, RateLimit> getRateLimit(Integer responseCode, Headers headers) {
1837+
protected Map<RateLimitType, ? extends RateLimit> getRateLimit(Integer responseCode, Headers headers) {
18231838
HashMap<RateLimitType, RateLimit> rateLimitMap = new HashMap<>();
18241839
Integer retryAfter = null;
18251840
if (Arrays.asList(HTTP_TEA_POT, HTTP_TOO_MANY_REQS).contains(responseCode)) {

clients/common/src/main/java/com/binance/connector/client/common/ApiResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class ApiResponse<T> {
2222
private final int statusCode;
2323
private final Map<String, List<String>> headers;
2424
private final T data;
25-
private final Map<RateLimitType, RateLimit> rateLimits;
25+
private final Map<RateLimitType, ? extends RateLimit> rateLimits;
2626

2727
/**
2828
* Constructor for ApiResponse.
@@ -57,7 +57,7 @@ public ApiResponse(
5757
int statusCode,
5858
Map<String, List<String>> headers,
5959
T data,
60-
Map<RateLimitType, RateLimit> rateLimits) {
60+
Map<RateLimitType, ? extends RateLimit> rateLimits) {
6161
this.statusCode = statusCode;
6262
this.headers = headers;
6363
this.data = data;
@@ -96,7 +96,7 @@ public T getData() {
9696
*
9797
* @return the rate limits info
9898
*/
99-
public Map<RateLimitType, RateLimit> getRateLimits() {
99+
public Map<RateLimitType, ? extends RateLimit> getRateLimits() {
100100
return rateLimits;
101101
}
102102
}

clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.binance.connector.client.common.dtos;
22

33
/** DTOs for rate limits */
4-
public final class RateLimit {
4+
public class RateLimit {
55
private RateLimitType rateLimitType;
66
private RateLimitInterval interval;
77
private Integer intervalNum;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.binance.connector.client.common.dtos;
22

33
public enum RateLimitType {
4+
DEFAULT,
45
REQUEST_WEIGHT,
56
ORDERS
67
}

0 commit comments

Comments
 (0)