From 021e4fb7894ff442f3d479938fe3ec1542510439 Mon Sep 17 00:00:00 2001 From: Makarid <30500991+makarid@users.noreply.github.com> Date: Sun, 30 Jul 2023 15:50:34 +0300 Subject: [PATCH] [Binance] Fix issue with Binance US init after adding Binance Futures (#4665) * [Binance] Fix issue with Binance US init after adding Binance Futures * [Binance] Add support for clientOrderId in Binance orders. * [Kucoin-Stream] Fix xchange version --- .../xchange/binance/BinanceExchange.java | 10 +++++++++- .../service/BinanceAccountService.java | 9 +++++---- .../binance/service/BinanceTradeService.java | 20 +++---------------- .../src/test/resources/logback.xml | 2 +- 4 files changed, 18 insertions(+), 23 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/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 { 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 @@ - +