Skip to content

Commit

Permalink
[Binance] Fix issue with Binance US init after adding Binance Futures (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
makarid authored Jul 30, 2023
1 parent 7a4dd95 commit 021e4fb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -157,7 +157,7 @@ private String placeOrderAllProducts(
order.getOriginalAmount(),
quoteOrderQty,
limitPrice,
getClientOrderId(order),
order.getUserReference(),
stopPrice,
trailingDelta,
null,
Expand Down Expand Up @@ -193,7 +193,7 @@ public void placeTestOrder(
order.getOriginalAmount(),
quoteOrderQty,
limitPrice,
getClientOrderId(order),
order.getUserReference(),
stopPrice,
trailingDelta,
null);
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion xchange-binance/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</appender>


<root level="WARN">
<root level="DEBUG">
<appender-ref ref="CONSOLE_APPENDER"/>
</root>

Expand Down

0 comments on commit 021e4fb

Please sign in to comment.