Skip to content

Commit

Permalink
Merge branch 'binance-futures' into latest
Browse files Browse the repository at this point in the history
# Conflicts:
#	xchange-stream-okex/src/main/java/info/bitrich/xchangestream/okex/OkexStreamingExchange.java
  • Loading branch information
makarid committed May 3, 2023
2 parents 751d1a2 + c2df50c commit 5ef017e
Show file tree
Hide file tree
Showing 37 changed files with 1,244 additions and 356 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright 2015-2021 Knowm Inc. (http://knowm.org) and contributors.
Copyright 2015-2023 Knowm Inc. (http://knowm.org) and contributors.
Copyright 2012-2015 Xeiam LLC (http://xeiam.com) and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -19,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<module>xchange-stream-hitbtc</module>
<module>xchange-stream-huobi</module>
<module>xchange-stream-kraken</module>
<module>xchange-stream-kucoin</module>
<module>xchange-stream-lgo</module>
<module>xchange-stream-okcoin</module>
<module>xchange-stream-okex</module>
Expand Down
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
@@ -0,0 +1,43 @@
package org.knowm.xchange.binance.dto.trade;

import org.knowm.xchange.dto.Order.IOrderFlags;

/**
* @see <a
* href="https://github.com/binance/binance-spot-api-docs/blob/master/faqs/trailing-stop-faq.md">trailing-stop-faq</a>
* @author mrmx
*/
public enum TrailingFlag implements IOrderFlags {
/** Trailing of 0.01% */
P0_01(1),
/** Trailing of 0.1% */
P0_1(10),
/** Trailing of 1% */
P1(100),
/** Trailing of 10% */
P10(1000);
/** Basis Points, also known as BIP or BIPS, are used to indicate a percentage change. */
private final long trailingBip;

private TrailingFlag(long trailingBip) {
this.trailingBip = trailingBip;
}

public long getTrailingBip() {
return trailingBip;
}

static TrailingFlag of(Number percent) {
switch (percent.toString()) {
case "0.01":
return P0_01;
case "0.1":
return P0_1;
case "1":
return P1;
case "10":
return P10;
}
throw new IllegalArgumentException("Invalid trailing " + percent);
}
}
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
Loading

0 comments on commit 5ef017e

Please sign in to comment.