From f9b54de2ee29e6ea04512295505d06bcb71e2f28 Mon Sep 17 00:00:00 2001 From: JMak-Security <271474413+JMak-Security@users.noreply.github.com> Date: Mon, 2 Nov 2026 23:47:00 +0800 Subject: [PATCH] Preserve decimal margin borrow amounts Fixes #221 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../docs/MarginAccountNewOrderResponse.md | 3 +- .../model/MarginAccountNewOrderResponse.java | 8 ++-- .../MarginAccountNewOrderResponseTest.java | 45 +++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 clients/margin-trading/src/test/java/com/binance/connector/client/margin_trading/rest/model/MarginAccountNewOrderResponseTest.java diff --git a/clients/margin-trading/docs/MarginAccountNewOrderResponse.md b/clients/margin-trading/docs/MarginAccountNewOrderResponse.md index 190c4f706..03bfa7e7b 100644 --- a/clients/margin-trading/docs/MarginAccountNewOrderResponse.md +++ b/clients/margin-trading/docs/MarginAccountNewOrderResponse.md @@ -21,9 +21,8 @@ |**type** | **String** | type. | [optional] | |**side** | **String** | side. | [optional] | |**selfTradePreventionMode** | **String** | self Trade Prevention Mode. | [optional] | -|**marginBuyBorrowAmount** | **Long** | margin Buy Borrow Amount. | [optional] | +|**marginBuyBorrowAmount** | **String** | margin Buy Borrow Amount. | [optional] | |**marginBuyBorrowAsset** | **String** | margin Buy Borrow Asset. | [optional] | |**fills** | [**List<MarginAccountNewOrderResponseFillsInner>**](MarginAccountNewOrderResponseFillsInner.md) | fills list. | [optional] | - diff --git a/clients/margin-trading/src/main/java/com/binance/connector/client/margin_trading/rest/model/MarginAccountNewOrderResponse.java b/clients/margin-trading/src/main/java/com/binance/connector/client/margin_trading/rest/model/MarginAccountNewOrderResponse.java index 0d40707cc..820247e1a 100644 --- a/clients/margin-trading/src/main/java/com/binance/connector/client/margin_trading/rest/model/MarginAccountNewOrderResponse.java +++ b/clients/margin-trading/src/main/java/com/binance/connector/client/margin_trading/rest/model/MarginAccountNewOrderResponse.java @@ -131,7 +131,7 @@ public class MarginAccountNewOrderResponse { @SerializedName(SERIALIZED_NAME_MARGIN_BUY_BORROW_AMOUNT) @jakarta.annotation.Nullable - private Long marginBuyBorrowAmount; + private String marginBuyBorrowAmount; public static final String SERIALIZED_NAME_MARGIN_BUY_BORROW_ASSET = "marginBuyBorrowAsset"; @@ -422,7 +422,7 @@ public void setSelfTradePreventionMode( } public MarginAccountNewOrderResponse marginBuyBorrowAmount( - @jakarta.annotation.Nullable Long marginBuyBorrowAmount) { + @jakarta.annotation.Nullable String marginBuyBorrowAmount) { this.marginBuyBorrowAmount = marginBuyBorrowAmount; return this; } @@ -433,11 +433,11 @@ public MarginAccountNewOrderResponse marginBuyBorrowAmount( * @return marginBuyBorrowAmount */ @jakarta.annotation.Nullable - public Long getMarginBuyBorrowAmount() { + public String getMarginBuyBorrowAmount() { return marginBuyBorrowAmount; } - public void setMarginBuyBorrowAmount(@jakarta.annotation.Nullable Long marginBuyBorrowAmount) { + public void setMarginBuyBorrowAmount(@jakarta.annotation.Nullable String marginBuyBorrowAmount) { this.marginBuyBorrowAmount = marginBuyBorrowAmount; } diff --git a/clients/margin-trading/src/test/java/com/binance/connector/client/margin_trading/rest/model/MarginAccountNewOrderResponseTest.java b/clients/margin-trading/src/test/java/com/binance/connector/client/margin_trading/rest/model/MarginAccountNewOrderResponseTest.java new file mode 100644 index 000000000..8ad5c2697 --- /dev/null +++ b/clients/margin-trading/src/test/java/com/binance/connector/client/margin_trading/rest/model/MarginAccountNewOrderResponseTest.java @@ -0,0 +1,45 @@ +package com.binance.connector.client.margin_trading.rest.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + +import java.io.IOException; +import org.junit.jupiter.api.Test; + +class MarginAccountNewOrderResponseTest { + + @Test + void deserializesFractionalBorrowAmount() throws IOException { + MarginAccountNewOrderResponse response = + MarginAccountNewOrderResponse.fromJson("{\"marginBuyBorrowAmount\":\"0.001\"}"); + + assertEquals("0.001", response.getMarginBuyBorrowAmount()); + assertEquals("0.001", MarginAccountNewOrderResponse.fromJson(response.toJson()) + .getMarginBuyBorrowAmount()); + } + + @Test + void deserializesNumericFractionalBorrowAmount() throws IOException { + MarginAccountNewOrderResponse response = + MarginAccountNewOrderResponse.fromJson("{\"marginBuyBorrowAmount\":0.001}"); + + assertEquals("0.001", response.getMarginBuyBorrowAmount()); + } + + @Test + void preservesBorrowAmountScale() throws IOException { + MarginAccountNewOrderResponse response = + MarginAccountNewOrderResponse.fromJson( + "{\"marginBuyBorrowAmount\":\"0.00100\"}"); + + assertEquals("0.00100", response.getMarginBuyBorrowAmount()); + } + + @Test + void allowsNullOrMissingBorrowAmount() throws IOException { + assertNull( + MarginAccountNewOrderResponse.fromJson("{\"marginBuyBorrowAmount\":null}") + .getMarginBuyBorrowAmount()); + assertNull(MarginAccountNewOrderResponse.fromJson("{}").getMarginBuyBorrowAmount()); + } +}