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 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.4.2</version>
<version>2.5.0</version>
<packaging>jar</packaging>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,8 @@ public ApiClient(

SignatureConfiguration signatureConfiguration = configuration.getSignatureConfiguration();
if (signatureConfiguration != null) {
Authentication authentication =
binanceAuthenticationFactory.getAuthentication(signatureConfiguration);
if (authentication != null) {
authentications.put(BINANCE_SIGNATURE, authentication);
}
Map<String, Authentication> customAuthentications = getCustomAuthentications(binanceAuthenticationFactory, signatureConfiguration);
authentications.putAll(customAuthentications);
}

Authentication binanceApiKeyOnly =
Expand Down Expand Up @@ -515,6 +512,21 @@ public Map<String, Authentication> getAuthentications() {
return authentications;
}

/**
* Get custom authentications to be added (key: authentication name, value: authentication).
*
* @return Map of authentication objects
*/
protected Map<String, Authentication> getCustomAuthentications(BinanceAuthenticationFactory binanceAuthenticationFactory, SignatureConfiguration signatureConfiguration) {
Map<String, Authentication> authentications = new HashMap<>();
Authentication authentication =
binanceAuthenticationFactory.getAuthentication(signatureConfiguration);
if (authentication != null) {
authentications.put(BINANCE_SIGNATURE, authentication);
}
return authentications;
}

/**
* Get authentication for the given name.
*
Expand Down Expand Up @@ -1215,8 +1227,7 @@ public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiExceptio
try {
Response response = call.execute();
T data = handleResponse(response, returnType);
Map<RateLimitType, RateLimit> rateLimit =
getRateLimit(response.code(), response.headers());
Map<RateLimitType, ? extends RateLimit> rateLimit = getRateLimit(response.code(), response.headers());
return new ApiResponse<T>(
response.code(), response.headers().toMultimap(), data, rateLimit);
} catch (IOException e) {
Expand Down Expand Up @@ -1571,7 +1582,7 @@ public void updateParamsForAuth(
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) {
if (BINANCE_SIGNATURE.equals(authName)) {
if (isRequiredAuth(authName)) {
throw new RuntimeException(
"Request is signed, please add signatureConfiguration to"
+ " clientConfiguration");
Expand All @@ -1586,6 +1597,10 @@ public void updateParamsForAuth(
}
}

protected boolean isRequiredAuth(String authName) {
return BINANCE_SIGNATURE.equals(authName);
}

/**
* Build a form-encoding request body with the given form parameters.
*
Expand Down Expand Up @@ -1819,7 +1834,7 @@ private String requestBodyToString(RequestBody requestBody) throws ApiException
return "";
}

private Map<RateLimitType, RateLimit> getRateLimit(Integer responseCode, Headers headers) {
protected Map<RateLimitType, ? extends RateLimit> getRateLimit(Integer responseCode, Headers headers) {
HashMap<RateLimitType, RateLimit> rateLimitMap = new HashMap<>();
Integer retryAfter = null;
if (Arrays.asList(HTTP_TEA_POT, HTTP_TOO_MANY_REQS).contains(responseCode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ApiResponse<T> {
private final int statusCode;
private final Map<String, List<String>> headers;
private final T data;
private final Map<RateLimitType, RateLimit> rateLimits;
private final Map<RateLimitType, ? extends RateLimit> rateLimits;

/**
* Constructor for ApiResponse.
Expand Down Expand Up @@ -57,7 +57,7 @@ public ApiResponse(
int statusCode,
Map<String, List<String>> headers,
T data,
Map<RateLimitType, RateLimit> rateLimits) {
Map<RateLimitType, ? extends RateLimit> rateLimits) {
this.statusCode = statusCode;
this.headers = headers;
this.data = data;
Expand Down Expand Up @@ -96,7 +96,7 @@ public T getData() {
*
* @return the rate limits info
*/
public Map<RateLimitType, RateLimit> getRateLimits() {
public Map<RateLimitType, ? extends RateLimit> getRateLimits() {
return rateLimits;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.binance.connector.client.common.dtos;

/** DTOs for rate limits */
public final class RateLimit {
public class RateLimit {
private RateLimitType rateLimitType;
private RateLimitInterval interval;
private Integer intervalNum;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.binance.connector.client.common.dtos;

public enum RateLimitType {
DEFAULT,
REQUEST_WEIGHT,
ORDERS
}
Loading