From 51c8933a438087f0c1edd4fe6a9fafce9f462543 Mon Sep 17 00:00:00 2001 From: makarid Date: Thu, 19 Jan 2023 21:50:41 +0200 Subject: [PATCH 1/3] [Binance] Fix issue with Binance US init after adding Binance Futures --- .../org/knowm/xchange/binance/BinanceExchange.java | 10 +++++++++- .../xchange/binance/service/BinanceAccountService.java | 9 +++++---- xchange-binance/src/test/resources/logback.xml | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/BinanceExchange.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/BinanceExchange.java index 1e98fb2075f..64f4d1c0551 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/BinanceExchange.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/BinanceExchange.java @@ -16,6 +16,7 @@ public class BinanceExchange extends BaseExchange implements Exchange { public static final String SPECIFIC_PARAM_USE_SANDBOX = "Use_Sandbox"; public static final String SPECIFIC_PARAM_USE_FUTURES_SANDBOX = "Use_Sandbox_Futures"; + public static final String SPECIFIC_PARAM_FUTURES_ENABLED = "Futures_Enabled"; private static final String SPOT_URL = "https://api.binance.com"; public static final String FUTURES_URL = "https://fapi.binance.com"; @@ -77,6 +78,11 @@ public boolean isFuturesSandbox(){ exchangeSpecification.getExchangeSpecificParametersItem(SPECIFIC_PARAM_USE_FUTURES_SANDBOX)); } + public boolean isFuturesEnabled(){ + return Boolean.TRUE.equals( + exchangeSpecification.getExchangeSpecificParametersItem(SPECIFIC_PARAM_FUTURES_ENABLED)); + } + public boolean usingSandbox() { return enabledSandbox(exchangeSpecification); } @@ -101,7 +107,9 @@ public void remoteInit() { } } else { exchangeMetaData = BinanceAdapters.adaptExchangeMetaData(marketDataService.getExchangeInfo(), assetDetailMap); - BinanceAdapters.adaptFutureExchangeMetaData(exchangeMetaData, marketDataService.getFutureExchangeInfo()); + if(isFuturesEnabled()){ + BinanceAdapters.adaptFutureExchangeMetaData(exchangeMetaData, marketDataService.getFutureExchangeInfo()); + } } } catch (Exception e) { diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java index f73ee801f5f..6aab63f855e 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java @@ -104,11 +104,12 @@ public AccountInfo getAccountInfo() throws IOException { wallets.add(BinanceAdapters.adaptBinanceSpotWallet(account())); } } else { - BinanceFutureAccountInformation futureAccountInformation = futuresAccount(); + if(exchange.isFuturesEnabled()){ + BinanceFutureAccountInformation futureAccountInformation = futuresAccount(); + wallets.add(BinanceAdapters.adaptBinanceFutureWallet(futureAccountInformation)); + openPositions.addAll(BinanceAdapters.adaptOpenPositions(futureAccountInformation.getPositions())); + } wallets.add(BinanceAdapters.adaptBinanceSpotWallet(account())); - wallets.add(BinanceAdapters.adaptBinanceFutureWallet(futureAccountInformation)); - openPositions.addAll(BinanceAdapters.adaptOpenPositions(futureAccountInformation.getPositions())); - } return new AccountInfo( exchange.getExchangeSpecification().getUserName(), diff --git a/xchange-binance/src/test/resources/logback.xml b/xchange-binance/src/test/resources/logback.xml index 5809b573500..8c86d2fa1c3 100644 --- a/xchange-binance/src/test/resources/logback.xml +++ b/xchange-binance/src/test/resources/logback.xml @@ -11,7 +11,7 @@ - + From c2df50c5325deff91d34062ded93bf30f9785595 Mon Sep 17 00:00:00 2001 From: makarid Date: Wed, 3 May 2023 19:27:22 +0300 Subject: [PATCH 2/3] [Binance] Add support for clientOrderId in Binance orders. --- .../binance/service/BinanceTradeService.java | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceTradeService.java b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceTradeService.java index db8c9b2bcc2..357b6d9aef4 100644 --- a/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceTradeService.java +++ b/xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceTradeService.java @@ -139,7 +139,7 @@ private String placeOrderAllProducts( order.hasFlag( org.knowm.xchange.binance.dto.trade.BinanceOrderFlags.REDUCE_ONLY), limitPrice, - getClientOrderId(order), + order.getUserReference(), stopPrice, false, null, @@ -157,7 +157,7 @@ private String placeOrderAllProducts( order.getOriginalAmount(), quoteOrderQty, limitPrice, - getClientOrderId(order), + order.getUserReference(), stopPrice, trailingDelta, null, @@ -193,7 +193,7 @@ public void placeTestOrder( order.getOriginalAmount(), quoteOrderQty, limitPrice, - getClientOrderId(order), + order.getUserReference(), stopPrice, trailingDelta, null); @@ -202,20 +202,6 @@ public void placeTestOrder( } } - private String getClientOrderId(Order order) { - - String clientOrderId = null; - for (IOrderFlags flags : order.getOrderFlags()) { - if (flags instanceof BinanceOrderFlags) { - BinanceOrderFlags bof = (BinanceOrderFlags) flags; - if (clientOrderId == null) { - clientOrderId = bof.getClientId(); - } - } - } - return clientOrderId; - } - @Override public boolean cancelOrder(CancelOrderParams params) throws IOException { try { From a754f312444a418df6cd2187a740e8c94872a1f1 Mon Sep 17 00:00:00 2001 From: makarid Date: Wed, 3 May 2023 19:43:06 +0300 Subject: [PATCH 3/3] [Kucoin-Stream] Fix xchange version --- xchange-stream-kucoin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xchange-stream-kucoin/pom.xml b/xchange-stream-kucoin/pom.xml index 68d8b9a24a5..64f9dd498e6 100644 --- a/xchange-stream-kucoin/pom.xml +++ b/xchange-stream-kucoin/pom.xml @@ -6,7 +6,7 @@ org.knowm.xchange xchange-parent - 5.0.14-SNAPSHOT + 5.1.1-SNAPSHOT XChange Kucoin Stream