From 87c1bc8dcc2a08028c182e10b59de815e4e81ffa Mon Sep 17 00:00:00 2001 From: Jonte <114036008+jonte-z@users.noreply.github.com> Date: Tue, 27 Jun 2023 16:26:33 +1000 Subject: [PATCH] Release 3.0.2 --- CHANGELOG.md | 9 ++- pom.xml | 2 +- .../futures/client/utils/RequestBuilder.java | 60 ++++--------------- 3 files changed, 21 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d5aa4..4ca5ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,14 @@ +## 3.0.2 - 2023-06-27 + +### Added +- Added User-Agent header + ## 3.0.1 - 2023-03-08 -## Fixed +### Fixed - Removed `symbol` as mandatory parameter in `currentAllOpenOrders()` within `UMAccount.java` and `CMAccount.java` classes -## Updated +### Updated - Bumped `org.json` package version to `20230227` ## 3.0.0 - 2023-03-06 diff --git a/pom.xml b/pom.xml index 9baeeba..8925126 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.binance binance-futures-connector-java - 3.0.1 + 3.0.2 jar ${project.groupId}:${project.artifactId} lightweight connector to Futures API diff --git a/src/main/java/com/binance/connector/futures/client/utils/RequestBuilder.java b/src/main/java/com/binance/connector/futures/client/utils/RequestBuilder.java index cbafbdd..b17ef2b 100644 --- a/src/main/java/com/binance/connector/futures/client/utils/RequestBuilder.java +++ b/src/main/java/com/binance/connector/futures/client/utils/RequestBuilder.java @@ -8,80 +8,46 @@ public final class RequestBuilder { private static final MediaType JSON_TYPE = MediaType.parse("application/json; charset=utf-8"); + private static final String USER_AGENT = "binance-futures-connector-java/3.0.2"; + private static final String CONTENT_TYPE = "application/x-www-form-urlencoded"; private RequestBuilder() { } public static Request buildPublicRequest(String fullUrl, HttpMethod httpMethod) { try { - final Request request; + final Request.Builder requestBuilder = new Request.Builder().addHeader("User-Agent", USER_AGENT).addHeader("Content-Type", CONTENT_TYPE).url(fullUrl); switch (httpMethod) { case POST: - request = new Request.Builder().url(fullUrl) - .post(RequestBody.create("", JSON_TYPE)) - .build(); - break; + return requestBuilder.post(RequestBody.create("", JSON_TYPE)).build(); case GET: - request = new Request.Builder().url(fullUrl) - .get() - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .build(); - break; + return requestBuilder.get().build(); case PUT: - request = new Request.Builder().url(fullUrl) - .put(RequestBody.create("", JSON_TYPE)) - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .build(); - break; + return requestBuilder.put(RequestBody.create("", JSON_TYPE)).build(); case DELETE: - request = new Request.Builder().url(fullUrl) - .delete() - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .build(); - break; + return requestBuilder.delete().build(); default: throw new BinanceConnectorException("Invalid HTTP method: " + httpMethod); } - return request; } catch (IllegalArgumentException e) { throw new BinanceConnectorException("Invalid URL: " + e.getMessage()); } - } + } public static Request buildApiKeyRequest(String fullUrl, HttpMethod httpMethod, String apiKey) { try { - final Request request; + final Request.Builder requestBuilder = new Request.Builder().addHeader("User-Agent", USER_AGENT).addHeader("Content-Type", CONTENT_TYPE).addHeader("X-MBX-APIKEY", apiKey).url(fullUrl); switch (httpMethod) { case POST: - request = new Request.Builder().url(fullUrl) - .post(RequestBody.create("", JSON_TYPE)) - .addHeader("X-MBX-APIKEY", apiKey) - .build(); - break; + return requestBuilder.post(RequestBody.create("", JSON_TYPE)).build(); case GET: - request = new Request.Builder().url(fullUrl) - .get() - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .addHeader("X-MBX-APIKEY", apiKey) - .build(); - break; + return requestBuilder.get().build(); case PUT: - request = new Request.Builder().url(fullUrl) - .put(RequestBody.create("", JSON_TYPE)) - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .addHeader("X-MBX-APIKEY", apiKey) - .build(); - break; + return requestBuilder.put(RequestBody.create("", JSON_TYPE)).build(); case DELETE: - request = new Request.Builder().url(fullUrl) - .delete() - .addHeader("Content-Type", "application/x-www-form-urlencoded") - .addHeader("X-MBX-APIKEY", apiKey) - .build(); - break; + return requestBuilder.delete().build(); default: throw new BinanceConnectorException("Invalid HTTP method: " + httpMethod); } - return request; } catch (IllegalArgumentException e) { throw new BinanceConnectorException("Invalid URL: " + e.getMessage()); }