Skip to content

Commit

Permalink
Merge branch 'knowm-develop' into enforcer-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
bigscoop committed Nov 19, 2024
2 parents 1d92136 + 586be46 commit c42e22a
Show file tree
Hide file tree
Showing 276 changed files with 3,226 additions and 3,138 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@
<plugin>
<groupId>com.spotify.fmt</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.23</version>
<version>2.25</version>
<configuration>
<filesNamePattern>.*\.java</filesNamePattern>
<skip>false</skip>
Expand Down Expand Up @@ -529,7 +529,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.7.0</version>
<version>3.10.1</version>
<configuration>
<quiet>true</quiet>
<doclint>none</doclint>
Expand Down Expand Up @@ -611,7 +611,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.7.0</version>
<version>3.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
return BiboxAdapters.adaptUserTrades(getBiboxOrderHistory());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public class BinanceAdapters {

private static final Map<String, CurrencyPair> SYMBOL_TO_CURRENCY_PAIR = new HashMap<>();


private BinanceAdapters() {}

/**
Expand Down Expand Up @@ -186,17 +185,14 @@ public static OrderType convertType(boolean isBuyer) {
return isBuyer ? OrderType.BID : OrderType.ASK;
}


public static void putSymbolMapping(String symbol, CurrencyPair currencyPair) {
SYMBOL_TO_CURRENCY_PAIR.put(symbol, currencyPair);
}


public static CurrencyPair toCurrencyPair(String symbol) {
return SYMBOL_TO_CURRENCY_PAIR.get(symbol);
}


public static Instrument adaptSymbol(String symbol, boolean isFuture) {
CurrencyPair currencyPair = toCurrencyPair(symbol);

Expand Down Expand Up @@ -247,9 +243,11 @@ public static Order adaptOrder(BinanceOrder order, boolean isFuture) {
return builder.build();
}


public static Ticker toTicker(BinanceTicker24h binanceTicker24h, boolean isFuture) {
Instrument instrument = (isFuture) ? new FuturesContract(binanceTicker24h.getCurrencyPair(), "PERP"): binanceTicker24h.getCurrencyPair();
Instrument instrument =
(isFuture)
? new FuturesContract(binanceTicker24h.getCurrencyPair(), "PERP")
: binanceTicker24h.getCurrencyPair();
return new Ticker.Builder()
.instrument(instrument)
.open(binanceTicker24h.getOpenPrice())
Expand All @@ -269,7 +267,6 @@ public static Ticker toTicker(BinanceTicker24h binanceTicker24h, boolean isFutur
.build();
}


static CurrencyMetaData adaptCurrencyMetaData(
Map<Currency, CurrencyMetaData> currencies,
Currency currency,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ BinanceDustLog getDustLog(
@QueryParam(SIGNATURE) ParamsDigest signature)
throws IOException, BinanceException;


@GET
@Path("/sapi/v1/capital/config/getall")
List<BinanceCurrencyInfo> getCurrencyInfos(
Expand All @@ -348,7 +347,6 @@ List<BinanceCurrencyInfo> getCurrencyInfos(
@QueryParam(SIGNATURE) ParamsDigest signature)
throws IOException, BinanceException;


/**
* Submit a withdraw request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ public void applySpecification(ExchangeSpecification exchangeSpecification) {
}

public boolean isFuturesEnabled() {
return ExchangeType.FUTURES.equals(exchangeSpecification.
getExchangeSpecificParametersItem(EXCHANGE_TYPE));
return ExchangeType.FUTURES.equals(
exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE));
}

public boolean isPortfolioMarginEnabled() {
return ExchangeType.PORTFOLIO_MARGIN.equals(exchangeSpecification
.getExchangeSpecificParametersItem(EXCHANGE_TYPE));
return ExchangeType.PORTFOLIO_MARGIN.equals(
exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE));
}

public boolean usingSandbox() {
Expand All @@ -103,7 +103,8 @@ public boolean usingSandbox() {
@Override
public void remoteInit() {
try {
BinanceMarketDataServiceRaw marketDataServiceRaw = (BinanceMarketDataServiceRaw) marketDataService;
BinanceMarketDataServiceRaw marketDataServiceRaw =
(BinanceMarketDataServiceRaw) marketDataService;
BinanceAccountService accountService = (BinanceAccountService) getAccountService();
Map<String, AssetDetail> assetDetailMap = null;
if (!usingSandbox() && isAuthenticated()) {
Expand All @@ -112,7 +113,10 @@ public void remoteInit() {

BinanceExchangeInfo exchangeInfo;
// get exchange type or SPOT as default
ExchangeType exchangeType = (ExchangeType) ObjectUtils.defaultIfNull(exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE), SPOT);
ExchangeType exchangeType =
(ExchangeType)
ObjectUtils.defaultIfNull(
exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE), SPOT);

switch (exchangeType) {
case FUTURES:
Expand All @@ -126,8 +130,15 @@ public void remoteInit() {

// init symbol mappings
exchangeInfo.getSymbols().stream()
.filter(symbol -> ObjectUtils.allNotNull(symbol.getBaseAsset(), symbol.getQuoteAsset(), symbol.getSymbol()))
.forEach(symbol -> BinanceAdapters.putSymbolMapping(symbol.getSymbol(), new CurrencyPair(symbol.getBaseAsset(), symbol.getQuoteAsset())));
.filter(
symbol ->
ObjectUtils.allNotNull(
symbol.getBaseAsset(), symbol.getQuoteAsset(), symbol.getSymbol()))
.forEach(
symbol ->
BinanceAdapters.putSymbolMapping(
symbol.getSymbol(),
new CurrencyPair(symbol.getBaseAsset(), symbol.getQuoteAsset())));

} catch (Exception e) {
throw new ExchangeException("Failed to initialize: " + e.getMessage(), e);
Expand All @@ -140,38 +151,37 @@ protected boolean isAuthenticated() {
&& exchangeSpecification.getSecretKey() != null;
}

/**
* Adjust host parameters depending on exchange specific parameters
*/
/** Adjust host parameters depending on exchange specific parameters */
private static void concludeHostParams(ExchangeSpecification exchangeSpecification) {
if(exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE) != null) {
switch ((ExchangeType)exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE)) {
case SPOT: {
if (enabledSandbox(exchangeSpecification))
exchangeSpecification.setSslUri(SANDBOX_SPOT_URL);
break;
}
case FUTURES: {
if (!enabledSandbox(exchangeSpecification))
exchangeSpecification.setSslUri(FUTURES_URL);
else
exchangeSpecification.setSslUri(SANDBOX_FUTURES_URL);
break;
}
case INVERSE: {
if (!enabledSandbox(exchangeSpecification))
exchangeSpecification.setSslUri(INVERSE_FUTURES_URL);
else
exchangeSpecification.setSslUri(SANDBOX_INVERSE_FUTURES_URL);
break;
}
if (exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE) != null) {
switch ((ExchangeType)
exchangeSpecification.getExchangeSpecificParametersItem(EXCHANGE_TYPE)) {
case SPOT:
{
if (enabledSandbox(exchangeSpecification))
exchangeSpecification.setSslUri(SANDBOX_SPOT_URL);
break;
}
case FUTURES:
{
if (!enabledSandbox(exchangeSpecification))
exchangeSpecification.setSslUri(FUTURES_URL);
else exchangeSpecification.setSslUri(SANDBOX_FUTURES_URL);
break;
}
case INVERSE:
{
if (!enabledSandbox(exchangeSpecification))
exchangeSpecification.setSslUri(INVERSE_FUTURES_URL);
else exchangeSpecification.setSslUri(SANDBOX_INVERSE_FUTURES_URL);
break;
}
}
}
}


private static boolean enabledSandbox(ExchangeSpecification exchangeSpecification) {
return Boolean.TRUE.equals(exchangeSpecification.getExchangeSpecificParametersItem(USE_SANDBOX));
return Boolean.TRUE.equals(
exchangeSpecification.getExchangeSpecificParametersItem(USE_SANDBOX));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ BinanceTicker24h ticker24h(@QueryParam("symbol") String symbol)
*/
@GET
@Path("fapi/v1/ticker/24hr")
List<BinanceTicker24h> ticker24h()
throws IOException, BinanceException;
List<BinanceTicker24h> ticker24h() throws IOException, BinanceException;

/**
* Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ public enum ExchangeType {
INVERSE,
PORTFOLIO_MARGIN;
}

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class BinanceCurrencyInfo {
@JsonProperty("networkList")
private List<Network> networks;


@Data
@Builder
@Jacksonized
Expand Down Expand Up @@ -133,6 +132,5 @@ public static class Network {

@JsonProperty("contractAddress")
private String contractAddress;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ public class BinancePrice {
public boolean isValid() {
return currencyPair != null && price != null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public final class BinancePriceQuantity {
public boolean isValid() {
return ObjectUtils.allNotNull(currencyPair, bidPrice, bidQty, askPrice, askQty);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public final class BinanceTicker24h {
@JsonDeserialize(converter = StringToCurrencyPairConverter.class)
private CurrencyPair currencyPair;


public boolean isValid() {
return currencyPair != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
public class BinanceSystemStatus {

// 0: normal,1:system maintenance
@JsonProperty
String status;
@JsonProperty String status;

// normal or system maintenance
@JsonProperty
String msg;

@JsonProperty String msg;
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,21 @@ public AccountInfo getAccountInfo() throws IOException {
try {
List<Wallet> wallets = new ArrayList<>();
List<OpenPosition> openPositions = new ArrayList<>();
switch ((ExchangeType)exchange.getExchangeSpecification().getExchangeSpecificParametersItem(
EXCHANGE_TYPE)) {
case SPOT: {
wallets.add(BinanceAdapters.adaptBinanceSpotWallet(account()));
break;
}
case FUTURES: {
BinanceFutureAccountInformation futureAccountInformation = futuresAccount();
wallets.add(BinanceAdapters.adaptBinanceFutureWallet(futureAccountInformation));
openPositions.addAll(
BinanceAdapters.adaptOpenPositions(futureAccountInformation.getPositions()));
break;
}
switch ((ExchangeType)
exchange.getExchangeSpecification().getExchangeSpecificParametersItem(EXCHANGE_TYPE)) {
case SPOT:
{
wallets.add(BinanceAdapters.adaptBinanceSpotWallet(account()));
break;
}
case FUTURES:
{
BinanceFutureAccountInformation futureAccountInformation = futuresAccount();
wallets.add(BinanceAdapters.adaptBinanceFutureWallet(futureAccountInformation));
openPositions.addAll(
BinanceAdapters.adaptOpenPositions(futureAccountInformation.getPositions()));
break;
}
}
return new AccountInfo(
exchange.getExchangeSpecification().getUserName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public BinanceAccountInformation account() throws BinanceException, IOException
.call();
}


public List<BinanceCurrencyInfo> currencyInfos() throws BinanceException, IOException {
return decorateApiCall(
() -> binance.getCurrencyInfos(getRecvWindow(), getTimestampFactory(), apiKey, signatureCreator))
() ->
binance.getCurrencyInfos(
getRecvWindow(), getTimestampFactory(), apiKey, signatureCreator))
.withRetry(retry("currencyInfo"))
.withRateLimiter(rateLimiter(REQUEST_WEIGHT_RATE_LIMITER), 5)
.call();
}


public BinanceFutureAccountInformation futuresAccount() throws BinanceException, IOException {
return decorateApiCall(
() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,34 @@ protected BinanceBaseService(
.build();
ExchangeSpecification futuresSpec;
ExchangeSpecification inverseFuturesSpec;
if(exchange.getExchangeSpecification().getExchangeSpecificParametersItem(EXCHANGE_TYPE) != null)
{
switch ((ExchangeType) exchange.getExchangeSpecification()
.getExchangeSpecificParametersItem(EXCHANGE_TYPE)) {
case SPOT: {
break;
}
case FUTURES: {
futuresSpec = exchange.getExchangeSpecification();
binanceFutures =
ExchangeRestProxyBuilder.forInterface(BinanceFuturesAuthenticated.class, futuresSpec)
.build();
inverseBinanceFutures = null;
break;
}
case INVERSE: {
inverseFuturesSpec = exchange.getExchangeSpecification();
inverseBinanceFutures =
ExchangeRestProxyBuilder.forInterface(BinanceFuturesAuthenticated.class,
inverseFuturesSpec)
.build();
binanceFutures = null;
break;
}
if (exchange.getExchangeSpecification().getExchangeSpecificParametersItem(EXCHANGE_TYPE)
!= null) {
switch ((ExchangeType)
exchange.getExchangeSpecification().getExchangeSpecificParametersItem(EXCHANGE_TYPE)) {
case SPOT:
{
break;
}
case FUTURES:
{
futuresSpec = exchange.getExchangeSpecification();
binanceFutures =
ExchangeRestProxyBuilder.forInterface(
BinanceFuturesAuthenticated.class, futuresSpec)
.build();
inverseBinanceFutures = null;
break;
}
case INVERSE:
{
inverseFuturesSpec = exchange.getExchangeSpecification();
inverseBinanceFutures =
ExchangeRestProxyBuilder.forInterface(
BinanceFuturesAuthenticated.class, inverseFuturesSpec)
.build();
binanceFutures = null;
break;
}
}
}
this.apiKey = exchange.getExchangeSpecification().getApiKey();
Expand Down
Loading

0 comments on commit c42e22a

Please sign in to comment.