Skip to content

Commit 574e926

Browse files
authored
v3.0.4 (#25)
1 parent ba694ff commit 574e926

File tree

8 files changed

+54
-14
lines changed

8 files changed

+54
-14
lines changed

.github/workflows/java.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
java-version: [ 8, 11, 17 ]
1414

1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v3
1717
- name: Set up JDK 8
18-
uses: actions/setup-java@v2
18+
uses: actions/setup-java@v3
1919
with:
2020
java-version: ${{ matrix.java-version }}
2121
distribution: 'adopt'

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Checkout source code
1212
uses: actions/checkout@v2
1313
- name: Set up Apache Maven Central
14-
uses: actions/setup-java@v2
14+
uses: actions/setup-java@v3
1515
with: # running setup-java again overwrites the settings.xml
1616
distribution: 'adopt' # See 'Supported distributions' for available options
1717
java-version: '8'

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 3.0.4 - 2024-01-10
2+
3+
### Fixed
4+
- `DecimalFormat` with `Locale.ENGLISH` for requests with `Double` to have `.` as decimal separator.
5+
6+
### Updated
7+
- Bumped `logback-classic` dependency to `1.2.13`.
8+
19
## 3.0.3 - 2023-10-18
210

311
### Updated

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
<dependency>
182182
<groupId>ch.qos.logback</groupId>
183183
<artifactId>logback-classic</artifactId>
184-
<version>1.2.11</version>
184+
<version>1.2.13</version>
185185
</dependency>
186186
<dependency>
187187
<groupId>org.apache.maven.plugins</groupId>

src/main/java/com/binance/connector/futures/client/utils/UrlBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import java.net.URLEncoder;
55
import java.nio.charset.StandardCharsets;
66
import java.text.DecimalFormat;
7+
import java.text.DecimalFormatSymbols;
78
import java.util.ArrayList;
89
import java.util.LinkedHashMap;
10+
import java.util.Locale;
911
import java.util.Map;
1012

1113

@@ -115,7 +117,9 @@ public static String urlEncode(String s) {
115117

116118
private static DecimalFormat getFormatter() {
117119
if (null == df) {
118-
df = new DecimalFormat();
120+
// Overrides the default Locale
121+
DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ENGLISH);
122+
df = new DecimalFormat("#,##0.###", symbols);
119123
df.setMaximumFractionDigits(MAX_DECIMAL_DIGITS);
120124
df.setGroupingUsed(false);
121125
}

src/test/java/examples/cm_futures/account/QueryOrder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ public final class QueryOrder {
1212
private QueryOrder() {
1313
}
1414

15+
private static final Integer orderId = 123;
1516
private static final Logger logger = LoggerFactory.getLogger(QueryOrder.class);
17+
1618
public static void main(String[] args) {
1719
LinkedHashMap<String, Object> parameters = new LinkedHashMap<>();
1820

1921
CMFuturesClientImpl client = new CMFuturesClientImpl(PrivateConfig.TESTNET_API_KEY, PrivateConfig.TESTNET_SECRET_KEY, PrivateConfig.TESTNET_BASE_URL);
2022

2123
parameters.put("symbol", "BNBUSD_PERP");
24+
parameters.put("orderId", orderId);
2225

2326
try {
2427
String result = client.account().queryOrder(parameters);

src/test/java/examples/um_futures/account/QueryOrder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
public final class QueryOrder {
1212
private QueryOrder() {
1313
}
14-
14+
15+
private static final Integer orderId = 123;
1516
private static final Logger logger = LoggerFactory.getLogger(QueryOrder.class);
17+
1618
public static void main(String[] args) {
1719
LinkedHashMap<String, Object> parameters = new LinkedHashMap<>();
1820

1921
UMFuturesClientImpl client = new UMFuturesClientImpl(PrivateConfig.TESTNET_API_KEY, PrivateConfig.TESTNET_SECRET_KEY, PrivateConfig.TESTNET_BASE_URL);
2022

2123
parameters.put("symbol", "BNBUSDT");
24+
parameters.put("orderId", orderId);
2225

2326
try {
2427
String result = client.account().queryOrder(parameters);

src/test/java/unit/TestUrlBuilder.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@
33
import com.binance.connector.futures.client.utils.UrlBuilder;
44
import java.util.ArrayList;
55
import java.util.LinkedHashMap;
6+
import java.util.Locale;
67
import static org.junit.Assert.assertEquals;
78
import org.junit.Test;
89

910
public class TestUrlBuilder {
1011
private final String baseUrl = "www.test.com";
1112
private final String urlPath = "/url/path";
12-
private final double key3 = 0.0006;
13-
private final double key4 = 0.000000000000000000001;
14-
private final int value2 = 2;
13+
private final double doubleValue = 0.0006;
14+
private final double extensiveDecimalsDouble = 1.123456789101112;
15+
private final double highDouble = 10000.1;
16+
private final int intValue = 2;
1517
private final LinkedHashMap<String, Object> mockParameters = new LinkedHashMap<String, Object>() {{
1618
put("key1", "value1");
17-
put("key2", value2);
18-
put("key3", key3);
19+
put("key2", intValue);
20+
put("key3", doubleValue);
1921
}};
20-
private final ArrayList<String> mockStreams = new ArrayList<String>() {{
22+
private final LinkedHashMap<String, Object> mockDoubleParameters = new LinkedHashMap<String, Object>() {{
23+
put("key1", extensiveDecimalsDouble);
24+
put("key2", highDouble);
25+
26+
}};
27+
private final ArrayList<String> mockStreams = new ArrayList<String>() {{
2128
add("stream1");
2229
add("stream2");
2330
add("stream3");
@@ -43,8 +50,9 @@ public void testJoinQueryParameters() {
4350

4451
@Test
4552
public void testJoinLargeQueryParameters() {
46-
mockParameters.put("key4", key4);
47-
String joinedQuery = "key1=value1&key2=2&key3=0.0006&key4=0.000000000000000000001";
53+
mockParameters.put("key4", extensiveDecimalsDouble);
54+
mockParameters.put("key5", highDouble);
55+
String joinedQuery = "key1=value1&key2=2&key3=0.0006&key4=1.123456789101112&key5=10000.1";
4856
assertEquals(joinedQuery, UrlBuilder.joinQueryParameters(mockParameters));
4957
}
5058

@@ -53,6 +61,20 @@ public void testJoinQueryParametersWithoutParams() {
5361
assertEquals("", UrlBuilder.joinQueryParameters(null));
5462
}
5563

64+
/**
65+
* Tests the JoinQueryParameters with Locale.IT to ensure that the originated Double maintains the '.' decimal separator instead of being changed to a ','.
66+
* Additionally, the test verifies that there is no dropping of zeros, addition of group separators (','), and limitation on the number of decimal places.
67+
*/
68+
@Test
69+
public void testJoinQueryParametersWithLocaleIT() {
70+
71+
Locale.setDefault(new Locale("it", "IT"));
72+
73+
String joinedQuery = String.format("key1=%s&key2=%s", extensiveDecimalsDouble, highDouble);
74+
String buildQuery = UrlBuilder.joinQueryParameters(mockDoubleParameters);
75+
assertEquals(joinedQuery, buildQuery);
76+
}
77+
5678
@Test
5779
public void testBuildStreamUrl() {
5880
String streamUrl = "www.test.com?streams=stream1/stream2/stream3";

0 commit comments

Comments
 (0)