Skip to content
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
8 changes: 8 additions & 0 deletions log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Define the root logger with appender file
log4j.rootLogger = INFO, stdout

# Define the file appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p %c{1}: %m%n
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public interface BinanceApiAsyncRestClient {
*/
void getExchangeInfo(BinanceApiCallback<ExchangeInfo> callback);

/**
* ALL supported assets and whether they can be withdrawn.
*/
void getAllAssets(BinanceApiCallback<List<Asset>> callback);

// Market Data endpoints

/**
Expand Down Expand Up @@ -142,13 +137,6 @@ public interface BinanceApiAsyncRestClient {
*/
void getAll24HrPriceStatistics(BinanceApiCallback<List<TickerStatistics>> callback);

/**
* Get the latest price for all symbols (asynchronous).
*
* @param callback the callback that handles the response
*/
void getAllPrices(BinanceApiCallback<List<TickerPrice>> callback);

/**
* Get the latest price for <code>symbol</code> (asynchronous).
*
Expand All @@ -157,13 +145,6 @@ public interface BinanceApiAsyncRestClient {
*/
void getPrice(String symbol, BinanceApiCallback<TickerPrice> callback);

/**
* Get best price/qty on the order book for all symbols (asynchronous).
*
* @param callback the callback that handles the response
*/
void getBookTickers(BinanceApiCallback<List<BookTicker>> callback);

// Account endpoints

/**
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/binance/api/client/BinanceApiRestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public interface BinanceApiRestClient {
*/
ExchangeInfo getExchangeInfo();

/**
* @return All the supported assets and whether they can be withdrawn.
*/
List<Asset> getAllAssets();

// Market Data endpoints

/**
Expand Down Expand Up @@ -132,23 +127,13 @@ public interface BinanceApiRestClient {
*/
List<TickerStatistics> getAll24HrPriceStatistics();

/**
* Get the latest price for all symbols.
*/
List<TickerPrice> getAllPrices();

/**
* Get the latest price for <code>symbol</code>.
*
* @param symbol ticker symbol (e.g. ETHBTC)
*/
TickerPrice getPrice(String symbol);

/**
* Get best price/qty on the order book for all symbols.
*/
List<BookTicker> getBookTickers();

// Account endpoints

/**
Expand Down
49 changes: 47 additions & 2 deletions src/main/java/com/binance/api/client/constant/TimeRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public TimeRange(long startTime, long endTime) {
* Create a time range for the given month.
*
* @param monthString The month as a string, in the format YYYY-mm
* @return
* @return TimeRange from 00:00:00 on the first day until 23:59:59 on the last day of the month
* @throws IllegalArgumentException If the provided month string is invalid
*/
public static TimeRange createForMonth(String monthString) throws IllegalArgumentException {
Expand All @@ -36,13 +36,51 @@ public static TimeRange createForMonth(String monthString) throws IllegalArgumen

int year = parseInteger(parts[0]);
int month = parseInteger(parts[1]);
return TimeRange.createForMonth(month, year);
}

/**
* Create a time range for the given month.
*
* @param month The month as an integer in the range 1-12
* @param year The year as a four-digit integer
* @return TimeRange from 00:00:00 on the first day until 23:59:59 on the last day of the month
* @throws IllegalArgumentException If the provided month or year is invalid
*/
public static TimeRange createForMonth(int month, int year) throws IllegalArgumentException {
if (month < 1 || month > 12) throw new IllegalArgumentException("Invalid month: " + month);
if (year < 1000 || year > 9999) throw new IllegalArgumentException("Invalid year: " + year);

int lastDayOfMonth = getDaysInMonth(year, month);
String startString = year + "-" + month + "-01 00:00:00";
String endString = year + "-" + month + "-" + lastDayOfMonth + " 23:59:59";

return new TimeRange(Util.getTimestampFor(startString), Util.getTimestampFor(endString));
}

/**
* Create a time range for a given day.
*
* @param day The day as an integer
* @param month The month as an integer in the range 1-12
* @param year The year as a four-digit integer
* @return TimeRange from 00:00:00 on the first day until 23:59:59 on the last day of the month
* @throws IllegalArgumentException If the provided month or year is invalid
*/
public static TimeRange createForDay(int day, int month, int year) {
if (month < 1 || month > 12) throw new IllegalArgumentException("Invalid month: " + month);
if (year < 1000 || year > 9999) throw new IllegalArgumentException("Invalid year: " + year);
if (day < 1 || day > getDaysInMonth(year, month)) {
throw new IllegalArgumentException("Invalid dat: " + month);
}

String dayString = year + "-" + month + "-" + day;
String startString = dayString + " 00:00:00";
String endString = dayString + " 23:59:59";

return new TimeRange(Util.getTimestampFor(startString), Util.getTimestampFor(endString));
}

/**
* Get the start time of the range, including milliseconds.
*
Expand All @@ -61,7 +99,14 @@ public long getEndTime() {
return endTime;
}

private static int getDaysInMonth(int year, int month) {
/**
* Get the number of days in a given month.
*
* @param year The year to consider
* @param month The month to consider
* @return The number of days in the given month: from 28 to 31
*/
public static int getDaysInMonth(int year, int month) {
YearMonth yearMonthObject = YearMonth.of(year, month);
return yearMonthObject.lengthOfMonth();
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/binance/api/client/constant/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ public static long getTimestampFor(String timeString) {
throw new RuntimeException("Invalid time string: " + timeString);
}
}

/**
* Convert a unix timestamp into a human-readable string.
*
* @param timestamp Unix timestamp, including milliseconds
* @return A human-readable string
*/
public static String humanReadableTimestamp(long timestamp) {
return dateFormat.format(new Date(timestamp));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public AssetBalance getAssetBalance(String symbol) {
return assetBalance;
}
}
return createEmptyBalance(symbol);
}

private static AssetBalance createEmptyBalance(String symbol) {
AssetBalance emptyBalance = new AssetBalance();
emptyBalance.setAsset(symbol);
emptyBalance.setFree("0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public class AllOrdersRequest extends OrderRequest {

private Long orderId;

private Long startTime;

private Long endTime;

private Integer limit;

public AllOrdersRequest(String symbol) {
Expand All @@ -37,10 +41,30 @@ public AllOrdersRequest limit(Integer limit) {
return this;
}

public Long getStartTime() {
return startTime;
}

public AllOrdersRequest startTime(Long startTime) {
this.startTime = startTime;
return this;
}

public Long getEndTime() {
return endTime;
}

public AllOrdersRequest endTime(Long endTime) {
this.endTime = endTime;
return this;
}

@Override
public String toString() {
return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE)
.append("orderId", orderId)
.append("startTime", startTime)
.append("endTime", endTime)
.append("limit", limit)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ public void getExchangeInfo(BinanceApiCallback<ExchangeInfo> callback) {
binanceApiService.getExchangeInfo().enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void getAllAssets(BinanceApiCallback<List<Asset>> callback) {
binanceApiService.getAllAssets(BinanceApiConfig.getAssetInfoApiBaseUrl() + "assetWithdraw/getAllAsset.html")
.enqueue(new BinanceApiCallbackAdapter<>(callback));
}

// Market Data endpoints

@Override
Expand Down Expand Up @@ -116,21 +110,11 @@ public void getAll24HrPriceStatistics(BinanceApiCallback<List<TickerStatistics>>
binanceApiService.getAll24HrPriceStatistics().enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void getAllPrices(BinanceApiCallback<List<TickerPrice>> callback) {
binanceApiService.getLatestPrices().enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void getPrice(String symbol, BinanceApiCallback<TickerPrice> callback) {
binanceApiService.getLatestPrice(symbol).enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void getBookTickers(BinanceApiCallback<List<BookTicker>> callback) {
binanceApiService.getBookTickers().enqueue(new BinanceApiCallbackAdapter<>(callback));
}

@Override
public void newOrder(NewOrder order, BinanceApiCallback<NewOrderResponse> callback) {
if (order.getQuoteOrderQty() == null) {
Expand Down Expand Up @@ -178,6 +162,7 @@ public void getOpenOrders(OrderRequest orderRequest, BinanceApiCallback<List<Ord
@Override
public void getAllOrders(AllOrdersRequest orderRequest, BinanceApiCallback<List<Order>> callback) {
binanceApiService.getAllOrders(orderRequest.getSymbol(),
orderRequest.getStartTime(), orderRequest.getEndTime(),
orderRequest.getOrderId(), orderRequest.getLimit(),
orderRequest.getRecvWindow(), orderRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ public ExchangeInfo getExchangeInfo() {
return executeSync(binanceApiService.getExchangeInfo());
}

@Override
public List<Asset> getAllAssets() {
return executeSync(binanceApiService
.getAllAssets(BinanceApiConfig.getAssetInfoApiBaseUrl() + "assetWithdraw/getAllAsset.html"));
}

// Market Data endpoints

@Override
Expand Down Expand Up @@ -113,16 +107,6 @@ public TickerPrice getPrice(String symbol) {
return executeSync(binanceApiService.getLatestPrice(symbol));
}

@Override
public List<TickerPrice> getAllPrices() {
return executeSync(binanceApiService.getLatestPrices());
}

@Override
public List<BookTicker> getBookTickers() {
return executeSync(binanceApiService.getBookTickers());
}

@Override
public NewOrderResponse newOrder(NewOrder order) {
final Call<NewOrderResponse> call;
Expand Down Expand Up @@ -173,8 +157,11 @@ public List<Order> getOpenOrders(OrderRequest orderRequest) {

@Override
public List<Order> getAllOrders(AllOrdersRequest orderRequest) {
return executeSync(binanceApiService.getAllOrders(orderRequest.getSymbol(), orderRequest.getOrderId(),
orderRequest.getLimit(), orderRequest.getRecvWindow(), orderRequest.getTimestamp()));
return executeSync(binanceApiService.getAllOrders(
orderRequest.getSymbol(), orderRequest.getOrderId(),
orderRequest.getStartTime(), orderRequest.getEndTime(),
orderRequest.getLimit(), orderRequest.getRecvWindow(),
orderRequest.getTimestamp()));
}

@Override
Expand Down
Loading