diff --git a/README.md b/README.md index bf74d5d02..ba11f5a74 100755 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ binance-java-api is a lightweight Java library for interacting with the [Binance com.binance.api binance-api-client - 1.0.0 + 1.0.1 ``` diff --git a/pom.xml b/pom.xml index 863f5c234..ecb6a80f7 100755 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,7 @@ org.apache.maven.plugins maven-compiler-plugin + 3.8.1 1.8 1.8 diff --git a/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java b/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java index d0e3b1c01..812ed75aa 100755 --- a/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java +++ b/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java @@ -19,6 +19,7 @@ import com.binance.api.client.domain.general.Asset; import com.binance.api.client.domain.general.ExchangeInfo; import com.binance.api.client.domain.general.ServerTime; +import com.binance.api.client.domain.general.TradeFee; import com.binance.api.client.domain.market.AggTrade; import com.binance.api.client.domain.market.BookTicker; import com.binance.api.client.domain.market.Candlestick; @@ -56,6 +57,11 @@ public interface BinanceApiAsyncRestClient { */ void getAllAssets(BinanceApiCallback> callback); + /** + * @return All trade fees for each asset. + */ + void getAllTradeFees(long timestamp, String symbol, Long recvWindow, BinanceApiCallback> callback); + // Market Data endpoints /** diff --git a/src/main/java/com/binance/api/client/BinanceApiRestClient.java b/src/main/java/com/binance/api/client/BinanceApiRestClient.java index bfc4797c4..7f5f0e7df 100755 --- a/src/main/java/com/binance/api/client/BinanceApiRestClient.java +++ b/src/main/java/com/binance/api/client/BinanceApiRestClient.java @@ -7,6 +7,7 @@ import com.binance.api.client.domain.account.request.OrderRequest; import com.binance.api.client.domain.account.request.OrderStatusRequest; import com.binance.api.client.domain.general.ExchangeInfo; +import com.binance.api.client.domain.general.TradeFee; import com.binance.api.client.domain.general.Asset; import com.binance.api.client.domain.market.AggTrade; import com.binance.api.client.domain.market.BookTicker; @@ -47,6 +48,11 @@ public interface BinanceApiRestClient { */ List getAllAssets(); + /** + * @return All trade fees for each asset. + */ + List getAllTradeFees(long timestamp, String symbol, Long recvWindow); + // Market Data endpoints /** diff --git a/src/main/java/com/binance/api/client/domain/general/Asset.java b/src/main/java/com/binance/api/client/domain/general/Asset.java index 715190f31..d58ba1330 100755 --- a/src/main/java/com/binance/api/client/domain/general/Asset.java +++ b/src/main/java/com/binance/api/client/domain/general/Asset.java @@ -1,123 +1,92 @@ -package com.binance.api.client.domain.general; - -import com.binance.api.client.constant.BinanceApiConstants; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.ToStringBuilder; - -/** - * An asset Binance supports. - */ - @JsonIgnoreProperties(ignoreUnknown = true) - public class Asset { - - @JsonProperty("id") - private String id; - - @JsonProperty("assetCode") - private String assetCode; - - @JsonProperty("assetName") - private String assetName; - - @JsonProperty("unit") - private String unit; - - @JsonProperty("transactionFee") - private String transactionFee; - - @JsonProperty("commissionRate") - private String commissionRate; - - @JsonProperty("freeAuditWithdrawAmt") - private String freeAuditWithdrawAmount; - - @JsonProperty("freeUserChargeAmount") - private String freeUserChargeAmount; - - @JsonProperty("minProductWithdraw") - private String minProductWithdraw; - - @JsonProperty("withdrawIntegerMultiple") - private String withdrawIntegerMultiple; - - @JsonProperty("confirmTimes") - private long confirmTimes; - - @JsonProperty("enableWithdraw") - private boolean enableWithdraw; - - @JsonProperty("isLegalMoney") - private boolean isLegalMoney; - - public String getId() { - return id; - } - - public String getAssetCode() { - return assetCode; - } - - public String getAssetName() { - return assetName; - } - - public String getUnit() { - return unit; - } - - public String getTransactionFee() { - return transactionFee; - } - - public String getCommissionRate() { - return commissionRate; - } - - public String getFreeAuditWithdrawAmount() { - return freeAuditWithdrawAmount; - } - - public String getFreeUserChargeAmount() { - return freeUserChargeAmount; - } - - public String minProductWithdraw() { - return minProductWithdraw; - } - - public String getWithdrawIntegerMultiple() { - return withdrawIntegerMultiple; - } - - public long getConfirmTimes() { - return confirmTimes; - } - - public boolean canWithraw() { - return enableWithdraw; - } - - public boolean isLegalMoney() { - return isLegalMoney; - } - - @Override - public String toString() { - return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) - .append("id", id) - .append("assetCode", assetCode) - .append("assetName", assetName) - .append("unit", unit) - .append("transactionFee", transactionFee) - .append("commissionRate", commissionRate) - .append("freeAuditWithdrawAmount", freeAuditWithdrawAmount) - .append("freeUserChargeAmount", freeUserChargeAmount) - .append("minProductWithdraw", minProductWithdraw) - .append("withdrawIntegerMultiple", withdrawIntegerMultiple) - .append("confirmTimes", confirmTimes) - .append("enableWithdraw", enableWithdraw) - .append("isLegalMoney", isLegalMoney) - .toString(); - } - } +package com.binance.api.client.domain.general; + +import com.binance.api.client.constant.BinanceApiConstants; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * An asset Binance supports. Representing the provided Asset model. See + * Doku + */ + @JsonIgnoreProperties(ignoreUnknown = true) + public class Asset { + + @JsonProperty("assetName") + private String assetName; + + @JsonProperty("assetFullName") + private String assetFullName; + + @JsonProperty("isBorrowable") + private boolean borrowable; + + @JsonProperty("isMortgageable") + private boolean mortgageable; + + @JsonProperty("userMinBorrow") + private double userMinBorrow; + + @JsonProperty("userMinRepay") + private double userMinRepay; + + public String getAssetName() { + return assetName; + } + + public void setAssetName(String assetName) { + this.assetName = assetName; + } + + public String getAssetFullName() { + return assetFullName; + } + + public void setAssetFullName(String assetFullName) { + this.assetFullName = assetFullName; + } + + public boolean isBorrowable() { + return borrowable; + } + + public void setBorrowable(boolean borrowable) { + this.borrowable = borrowable; + } + + public boolean isMortgageable() { + return mortgageable; + } + + public void setMortgageable(boolean mortgageable) { + this.mortgageable = mortgageable; + } + + public double getUserMinBorrow() { + return userMinBorrow; + } + + public void setUserMinBorrow(double userMinBorrow) { + this.userMinBorrow = userMinBorrow; + } + + public double getUserMinRepay() { + return userMinRepay; + } + + public void setUserMinRepay(double userMinRepay) { + this.userMinRepay = userMinRepay; + } + + @Override + public String toString() { + return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("assetName", assetName) + .append("assetFullName", assetFullName) + .append("isBorrowable", borrowable) + .append("isMortgageable", mortgageable) + .append("userMinBorrow", userMinBorrow) + .append("userMinRepay", userMinRepay) + .toString(); + } +} diff --git a/src/main/java/com/binance/api/client/domain/general/TradeFee.java b/src/main/java/com/binance/api/client/domain/general/TradeFee.java new file mode 100644 index 000000000..3179566ed --- /dev/null +++ b/src/main/java/com/binance/api/client/domain/general/TradeFee.java @@ -0,0 +1,57 @@ +package com.binance.api.client.domain.general; + +import org.apache.commons.lang3.builder.ToStringBuilder; + +import com.binance.api.client.constant.BinanceApiConstants; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * An TradeFee Binance supports. + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class TradeFee { + + @JsonProperty("symbol") + private String symbol; + + @JsonProperty("makerCommission") + private double maker; + + @JsonProperty("takerCommission") + private double taker; + + public String getSymbol() { + return symbol; + } + + public void setSymbol(String symbol) { + this.symbol = symbol; + } + + public double getMaker() { + return maker; + } + + public void setMaker(double maker) { + this.maker = maker; + } + + public double getTaker() { + return taker; + } + + public void setTaker(double taker) { + this.taker = taker; + } + + @Override + public String toString() { + return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) + .append("id", symbol) + .append("symbol", symbol) + .append("maker", maker) + .append("taker", taker) + .toString(); + } +} diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java b/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java index e6ea387b9..6c9c83c17 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java @@ -2,7 +2,6 @@ import com.binance.api.client.BinanceApiAsyncRestClient; import com.binance.api.client.BinanceApiCallback; -import com.binance.api.client.config.BinanceApiConfig; import com.binance.api.client.constant.BinanceApiConstants; import com.binance.api.client.domain.account.Account; import com.binance.api.client.domain.account.DepositAddress; @@ -23,6 +22,7 @@ import com.binance.api.client.domain.general.Asset; import com.binance.api.client.domain.general.ExchangeInfo; import com.binance.api.client.domain.general.ServerTime; +import com.binance.api.client.domain.general.TradeFee; import com.binance.api.client.domain.market.AggTrade; import com.binance.api.client.domain.market.BookTicker; import com.binance.api.client.domain.market.Candlestick; @@ -65,8 +65,12 @@ public void getExchangeInfo(BinanceApiCallback callback) { @Override public void getAllAssets(BinanceApiCallback> callback) { - binanceApiService.getAllAssets(BinanceApiConfig.getAssetInfoApiBaseUrl() + "assetWithdraw/getAllAsset.html") - .enqueue(new BinanceApiCallbackAdapter<>(callback)); + binanceApiService.getAllAssets().enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAllTradeFees(long timestamp, String symbol, Long recvWindow, BinanceApiCallback> callback) { + binanceApiService.getAllTradeFees(timestamp, symbol, recvWindow).enqueue(new BinanceApiCallbackAdapter<>(callback)); } // Market Data endpoints diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java b/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java index dd647166d..8891293d2 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java @@ -1,12 +1,12 @@ package com.binance.api.client.impl; import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.config.BinanceApiConfig; import com.binance.api.client.constant.BinanceApiConstants; import com.binance.api.client.domain.account.*; import com.binance.api.client.domain.account.request.*; import com.binance.api.client.domain.general.Asset; import com.binance.api.client.domain.general.ExchangeInfo; +import com.binance.api.client.domain.general.TradeFee; import com.binance.api.client.domain.market.*; import retrofit2.Call; @@ -46,8 +46,12 @@ public ExchangeInfo getExchangeInfo() { @Override public List getAllAssets() { - return executeSync(binanceApiService - .getAllAssets(BinanceApiConfig.getAssetInfoApiBaseUrl() + "assetWithdraw/getAllAsset.html")); + return executeSync(binanceApiService.getAllAssets()); + } + + @Override + public List getAllTradeFees(long timestamp, String symbol, Long recvWindow) { + return executeSync(binanceApiService.getAllTradeFees(timestamp, symbol, recvWindow)); } // Market Data endpoints diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiService.java b/src/main/java/com/binance/api/client/impl/BinanceApiService.java index 35e21de0c..9cca7eca3 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiService.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiService.java @@ -11,6 +11,7 @@ import com.binance.api.client.domain.general.Asset; import com.binance.api.client.domain.general.ExchangeInfo; import com.binance.api.client.domain.general.ServerTime; +import com.binance.api.client.domain.general.TradeFee; import com.binance.api.client.domain.market.*; import retrofit2.Call; import retrofit2.http.*; @@ -33,8 +34,14 @@ public interface BinanceApiService { @GET("/api/v3/exchangeInfo") Call getExchangeInfo(); - @GET - Call> getAllAssets(@Url String url); + @Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_APIKEY_HEADER) + @GET("/sapi/v1/margin/allAssets") + Call> getAllAssets(); + + @Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER) + @GET("/sapi/v1/asset/tradeFee") + Call> getAllTradeFees(@Query("timestamp") long timestamp, @Query("symbol") String symbol, + @Query("recvWindow") Long recvWindow); // Market data endpoints diff --git a/src/test/java/com/binance/api/examples/GeneralEndpointsExample.java b/src/test/java/com/binance/api/examples/GeneralEndpointsExample.java index 760d6f26a..b8b252ba0 100755 --- a/src/test/java/com/binance/api/examples/GeneralEndpointsExample.java +++ b/src/test/java/com/binance/api/examples/GeneralEndpointsExample.java @@ -1,46 +1,50 @@ -package com.binance.api.examples; - -import com.binance.api.client.BinanceApiClientFactory; -import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.domain.general.Asset; -import com.binance.api.client.domain.general.ExchangeInfo; -import com.binance.api.client.domain.general.FilterType; -import com.binance.api.client.domain.general.SymbolFilter; -import com.binance.api.client.domain.general.SymbolInfo; - -import java.util.List; - -/** - * Examples on how to use the general endpoints. - */ -public class GeneralEndpointsExample { - - public static void main(String[] args) { - BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(); - BinanceApiRestClient client = factory.newRestClient(); - - // Test connectivity - client.ping(); - - // Check server time - long serverTime = client.getServerTime(); - System.out.println(serverTime); - - // Exchange info - ExchangeInfo exchangeInfo = client.getExchangeInfo(); - System.out.println(exchangeInfo.getTimezone()); - System.out.println(exchangeInfo.getSymbols()); - - // Obtain symbol information - SymbolInfo symbolInfo = exchangeInfo.getSymbolInfo("ETHBTC"); - System.out.println(symbolInfo.getStatus()); - - SymbolFilter priceFilter = symbolInfo.getSymbolFilter(FilterType.PRICE_FILTER); - System.out.println(priceFilter.getMinPrice()); - System.out.println(priceFilter.getTickSize()); - - // Obtain asset information - List allAssets = client.getAllAssets(); - System.out.println(allAssets.stream().filter(asset -> asset.getAssetCode().equals("BNB")).findFirst().get()); - } -} +package com.binance.api.examples; + +import com.binance.api.client.BinanceApiClientFactory; +import com.binance.api.client.BinanceApiRestClient; +import com.binance.api.client.domain.general.Asset; +import com.binance.api.client.domain.general.ExchangeInfo; +import com.binance.api.client.domain.general.FilterType; +import com.binance.api.client.domain.general.SymbolFilter; +import com.binance.api.client.domain.general.SymbolInfo; +import com.binance.api.client.domain.general.TradeFee; + +import java.util.List; + +/** + * Examples on how to use the general endpoints. + */ +public class GeneralEndpointsExample { + + public static void main(String[] args) { + BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(); + BinanceApiRestClient client = factory.newRestClient(); + + // Test connectivity + client.ping(); + + // Check server time + long serverTime = client.getServerTime(); + System.out.println(serverTime); + + // Exchange info + ExchangeInfo exchangeInfo = client.getExchangeInfo(); + System.out.println(exchangeInfo.getTimezone()); + System.out.println(exchangeInfo.getSymbols()); + + // Obtain symbol information + SymbolInfo symbolInfo = exchangeInfo.getSymbolInfo("ETHBTC"); + System.out.println(symbolInfo.getStatus()); + + SymbolFilter priceFilter = symbolInfo.getSymbolFilter(FilterType.PRICE_FILTER); + System.out.println(priceFilter.getMinPrice()); + System.out.println(priceFilter.getTickSize()); + + // Obtain asset information + List allAssets = client.getAllAssets(); + System.out.println(allAssets.stream().filter(asset -> asset.getAssetName().equals("BNB")).findFirst().get()); + + List allTradeFees = client.getAllTradeFees(System.currentTimeMillis(), null, null); + System.out.println(allTradeFees.stream().filter(fee -> fee.getSymbol().equals("ETHBTC")).findFirst().get()); + } +} diff --git a/src/test/java/com/binance/api/examples/GeneralEndpointsExampleAsync.java b/src/test/java/com/binance/api/examples/GeneralEndpointsExampleAsync.java index 96739a5c2..8e7886691 100755 --- a/src/test/java/com/binance/api/examples/GeneralEndpointsExampleAsync.java +++ b/src/test/java/com/binance/api/examples/GeneralEndpointsExampleAsync.java @@ -1,45 +1,50 @@ -package com.binance.api.examples; - -import com.binance.api.client.BinanceApiAsyncRestClient; -import com.binance.api.client.BinanceApiClientFactory; -import com.binance.api.client.domain.general.Asset; -import com.binance.api.client.domain.general.FilterType; -import com.binance.api.client.domain.general.SymbolFilter; -import com.binance.api.client.domain.general.SymbolInfo; - -import java.util.List; - -/** - * Examples on how to use the general endpoints. - */ -public class GeneralEndpointsExampleAsync { - - public static void main(String[] args) throws InterruptedException { - BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(); - BinanceApiAsyncRestClient client = factory.newAsyncRestClient(); - - // Test connectivity - client.ping(response -> System.out.println("Ping succeeded.")); - - // Check server time - client.getServerTime(response -> System.out.println(response.getServerTime())); - - // Exchange info - client.getExchangeInfo(exchangeInfo -> { - System.out.println(exchangeInfo.getTimezone()); - System.out.println(exchangeInfo.getSymbols()); - - // Obtain symbol information - SymbolInfo symbolInfo = exchangeInfo.getSymbolInfo("ETHBTC"); - System.out.println(symbolInfo.getStatus()); - - SymbolFilter priceFilter = symbolInfo.getSymbolFilter(FilterType.PRICE_FILTER); - System.out.println(priceFilter.getMinPrice()); - System.out.println(priceFilter.getTickSize()); - }); - - // Obtain asset information - client.getAllAssets(allAssets -> - System.out.println(allAssets.stream().filter(asset -> asset.getAssetCode().equals("BNB")).findFirst().get())); - } -} +package com.binance.api.examples; + +import com.binance.api.client.BinanceApiAsyncRestClient; +import com.binance.api.client.BinanceApiClientFactory; +import com.binance.api.client.domain.general.Asset; +import com.binance.api.client.domain.general.FilterType; +import com.binance.api.client.domain.general.SymbolFilter; +import com.binance.api.client.domain.general.SymbolInfo; + +import java.util.List; + +/** + * Examples on how to use the general endpoints. + */ +public class GeneralEndpointsExampleAsync { + + public static void main(String[] args) throws InterruptedException { + BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance(); + BinanceApiAsyncRestClient client = factory.newAsyncRestClient(); + + // Test connectivity + client.ping(response -> System.out.println("Ping succeeded.")); + + // Check server time + client.getServerTime(response -> System.out.println(response.getServerTime())); + + // Exchange info + client.getExchangeInfo(exchangeInfo -> { + System.out.println(exchangeInfo.getTimezone()); + System.out.println(exchangeInfo.getSymbols()); + + // Obtain symbol information + SymbolInfo symbolInfo = exchangeInfo.getSymbolInfo("ETHBTC"); + System.out.println(symbolInfo.getStatus()); + + SymbolFilter priceFilter = symbolInfo.getSymbolFilter(FilterType.PRICE_FILTER); + System.out.println(priceFilter.getMinPrice()); + System.out.println(priceFilter.getTickSize()); + }); + + // Obtain asset information + client.getAllAssets(allAssets -> + System.out.println(allAssets.stream().filter(asset -> asset.getAssetName().equals("BNB")).findFirst().get())); + + // Obtain tradeFee + client.getAllTradeFees(System.currentTimeMillis(), "ETHBTC", null, allTradeFees -> { + System.out.println(allTradeFees); + }); + } +}