Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Binance] Fix issue with Binance US init after adding Binance Futures #4665

Merged
merged 4 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
walec51 marked this conversation as resolved.
Show resolved Hide resolved

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
2 changes: 1 addition & 1 deletion xchange-stream-kucoin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-parent</artifactId>
<version>5.0.14-SNAPSHOT</version>
<version>5.1.1-SNAPSHOT</version>
</parent>

<name>XChange Kucoin Stream</name>
Expand Down