diff --git a/clients/common/pom.xml b/clients/common/pom.xml index 9d8cfa413..298fecba4 100644 --- a/clients/common/pom.xml +++ b/clients/common/pom.xml @@ -10,6 +10,6 @@ binance-common common - 2.4.2 + 2.5.0 jar \ No newline at end of file diff --git a/clients/common/src/main/java/com/binance/connector/client/common/ApiClient.java b/clients/common/src/main/java/com/binance/connector/client/common/ApiClient.java index d56da0790..754e26a4a 100644 --- a/clients/common/src/main/java/com/binance/connector/client/common/ApiClient.java +++ b/clients/common/src/main/java/com/binance/connector/client/common/ApiClient.java @@ -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 customAuthentications = getCustomAuthentications(binanceAuthenticationFactory, signatureConfiguration); + authentications.putAll(customAuthentications); } Authentication binanceApiKeyOnly = @@ -515,6 +512,21 @@ public Map getAuthentications() { return authentications; } + /** + * Get custom authentications to be added (key: authentication name, value: authentication). + * + * @return Map of authentication objects + */ + protected Map getCustomAuthentications(BinanceAuthenticationFactory binanceAuthenticationFactory, SignatureConfiguration signatureConfiguration) { + Map authentications = new HashMap<>(); + Authentication authentication = + binanceAuthenticationFactory.getAuthentication(signatureConfiguration); + if (authentication != null) { + authentications.put(BINANCE_SIGNATURE, authentication); + } + return authentications; + } + /** * Get authentication for the given name. * @@ -1215,8 +1227,7 @@ public ApiResponse execute(Call call, Type returnType) throws ApiExceptio try { Response response = call.execute(); T data = handleResponse(response, returnType); - Map rateLimit = - getRateLimit(response.code(), response.headers()); + Map rateLimit = getRateLimit(response.code(), response.headers()); return new ApiResponse( response.code(), response.headers().toMultimap(), data, rateLimit); } catch (IOException e) { @@ -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"); @@ -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. * @@ -1819,7 +1834,7 @@ private String requestBodyToString(RequestBody requestBody) throws ApiException return ""; } - private Map getRateLimit(Integer responseCode, Headers headers) { + protected Map getRateLimit(Integer responseCode, Headers headers) { HashMap rateLimitMap = new HashMap<>(); Integer retryAfter = null; if (Arrays.asList(HTTP_TEA_POT, HTTP_TOO_MANY_REQS).contains(responseCode)) { diff --git a/clients/common/src/main/java/com/binance/connector/client/common/ApiResponse.java b/clients/common/src/main/java/com/binance/connector/client/common/ApiResponse.java index a5a99e855..e7dfec44b 100644 --- a/clients/common/src/main/java/com/binance/connector/client/common/ApiResponse.java +++ b/clients/common/src/main/java/com/binance/connector/client/common/ApiResponse.java @@ -22,7 +22,7 @@ public class ApiResponse { private final int statusCode; private final Map> headers; private final T data; - private final Map rateLimits; + private final Map rateLimits; /** * Constructor for ApiResponse. @@ -57,7 +57,7 @@ public ApiResponse( int statusCode, Map> headers, T data, - Map rateLimits) { + Map rateLimits) { this.statusCode = statusCode; this.headers = headers; this.data = data; @@ -96,7 +96,7 @@ public T getData() { * * @return the rate limits info */ - public Map getRateLimits() { + public Map getRateLimits() { return rateLimits; } } diff --git a/clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimit.java b/clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimit.java index f8c4e8f27..3f45382c5 100644 --- a/clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimit.java +++ b/clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimit.java @@ -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; diff --git a/clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimitType.java b/clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimitType.java index 3088682c9..74558e6ce 100644 --- a/clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimitType.java +++ b/clients/common/src/main/java/com/binance/connector/client/common/dtos/RateLimitType.java @@ -1,6 +1,7 @@ package com.binance.connector.client.common.dtos; public enum RateLimitType { + DEFAULT, REQUEST_WEIGHT, ORDERS }