diff --git a/pom.xml b/pom.xml index 67e7af532..8aa27c741 100755 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.binance.api binance-api-client - 1.0.1 + 1.1.0 The MIT License diff --git a/src/main/java/com/binance/api/client/BinanceApiRestClient.java b/src/main/java/com/binance/api/client/BinanceApiRestClient.java index ebe0b9667..866ba6f12 100755 --- a/src/main/java/com/binance/api/client/BinanceApiRestClient.java +++ b/src/main/java/com/binance/api/client/BinanceApiRestClient.java @@ -181,6 +181,13 @@ public interface BinanceApiRestClient { */ List getOpenOrders(OrderRequest orderRequest); + /** + * Get all the open orders for an account + * @param allOpenOrdersRequest all open orders request + * @return list of all the open orders for an account + */ + List getAllOpenOrders(AllOpenOrdersRequest allOpenOrdersRequest); + /** * Get all account orders; active, canceled, or filled. * diff --git a/src/main/java/com/binance/api/client/domain/account/request/AllOpenOrdersRequest.java b/src/main/java/com/binance/api/client/domain/account/request/AllOpenOrdersRequest.java new file mode 100644 index 000000000..76b543df5 --- /dev/null +++ b/src/main/java/com/binance/api/client/domain/account/request/AllOpenOrdersRequest.java @@ -0,0 +1,50 @@ +package com.binance.api.client.domain.account.request; + + +import com.binance.api.client.constant.BinanceApiConstants; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.apache.commons.lang3.builder.ToStringBuilder; + +/** + * Request object to retrieve all the open orders without symbol + */ + +@JsonIgnoreProperties(ignoreUnknown = true) +public class AllOpenOrdersRequest { + + private Long recvWindow; + + private Long timestamp; + + public AllOpenOrdersRequest() { + this.timestamp = System.currentTimeMillis(); + this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW; + } + + public Long getRecvWindow() { + return recvWindow; + } + + public AllOpenOrdersRequest recvWindow(Long recvWindow) { + this.recvWindow = recvWindow; + return this; + } + + public Long getTimestamp() { + return timestamp; + } + + public AllOpenOrdersRequest timestamp(Long timestamp) { + this.timestamp = timestamp; + return this; + } + + @Override + public String toString() { + return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) + .append("recvWindow", recvWindow) + .append("timestamp", timestamp) + .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..061f14862 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java @@ -40,212 +40,212 @@ */ public class BinanceApiAsyncRestClientImpl implements BinanceApiAsyncRestClient { - private final BinanceApiService binanceApiService; - - public BinanceApiAsyncRestClientImpl(String apiKey, String secret) { - binanceApiService = createService(BinanceApiService.class, apiKey, secret); - } - - // General endpoints - - @Override - public void ping(BinanceApiCallback callback) { - binanceApiService.ping().enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getServerTime(BinanceApiCallback callback) { - binanceApiService.getServerTime().enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getExchangeInfo(BinanceApiCallback callback) { - binanceApiService.getExchangeInfo().enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getAllAssets(BinanceApiCallback> callback) { - binanceApiService.getAllAssets(BinanceApiConfig.getAssetInfoApiBaseUrl() + "assetWithdraw/getAllAsset.html") - .enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - // Market Data endpoints - - @Override - public void getOrderBook(String symbol, Integer limit, BinanceApiCallback callback) { - binanceApiService.getOrderBook(symbol, limit).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getTrades(String symbol, Integer limit, BinanceApiCallback> callback) { - binanceApiService.getTrades(symbol, limit).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getHistoricalTrades(String symbol, Integer limit, Long fromId, BinanceApiCallback> callback) { - binanceApiService.getHistoricalTrades(symbol, limit, fromId).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getAggTrades(String symbol, String fromId, Integer limit, Long startTime, Long endTime, BinanceApiCallback> callback) { - binanceApiService.getAggTrades(symbol, fromId, limit, startTime, endTime).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getAggTrades(String symbol, BinanceApiCallback> callback) { - getAggTrades(symbol, null, null, null, null, callback); - } - - @Override - public void getCandlestickBars(String symbol, CandlestickInterval interval, Integer limit, Long startTime, Long endTime, BinanceApiCallback> callback) { - binanceApiService.getCandlestickBars(symbol, interval.getIntervalId(), limit, startTime, endTime).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getCandlestickBars(String symbol, CandlestickInterval interval, BinanceApiCallback> callback) { - getCandlestickBars(symbol, interval, null, null, null, callback); - } - - @Override - public void get24HrPriceStatistics(String symbol, BinanceApiCallback callback) { - binanceApiService.get24HrPriceStatistics(symbol).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getAll24HrPriceStatistics(BinanceApiCallback> callback) { - binanceApiService.getAll24HrPriceStatistics().enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getAllPrices(BinanceApiCallback> callback) { - binanceApiService.getLatestPrices().enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getPrice(String symbol , BinanceApiCallback callback) { - binanceApiService.getLatestPrice(symbol).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getBookTickers(BinanceApiCallback> callback) { - binanceApiService.getBookTickers().enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void newOrder(NewOrder order, BinanceApiCallback callback) { - if (order.getQuoteOrderQty() == null) { - binanceApiService.newOrder(order.getSymbol(), order.getSide(), order.getType(), - order.getTimeInForce(), order.getQuantity(), order.getPrice(), - order.getNewClientOrderId(), order.getStopPrice(), order.getIcebergQty(), order.getNewOrderRespType(), - order.getRecvWindow(), order.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } else { - binanceApiService.newOrderQuoteQty(order.getSymbol(), order.getSide(), order.getType(), - order.getTimeInForce(), order.getQuoteOrderQty(), order.getPrice(), - order.getNewClientOrderId(), order.getStopPrice(), order.getIcebergQty(), order.getNewOrderRespType(), - order.getRecvWindow(), order.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - } - - @Override - public void newOrderTest(NewOrder order, BinanceApiCallback callback) { - binanceApiService.newOrderTest(order.getSymbol(), order.getSide(), order.getType(), - order.getTimeInForce(), order.getQuantity(), order.getPrice(), order.getNewClientOrderId(), order.getStopPrice(), - order.getIcebergQty(), order.getNewOrderRespType(), order.getRecvWindow(), order.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - // Account endpoints - - @Override - public void getOrderStatus(OrderStatusRequest orderStatusRequest, BinanceApiCallback callback) { - binanceApiService.getOrderStatus(orderStatusRequest.getSymbol(), - orderStatusRequest.getOrderId(), orderStatusRequest.getOrigClientOrderId(), - orderStatusRequest.getRecvWindow(), orderStatusRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void cancelOrder(CancelOrderRequest cancelOrderRequest, BinanceApiCallback callback) { - binanceApiService.cancelOrder(cancelOrderRequest.getSymbol(), - cancelOrderRequest.getOrderId(), cancelOrderRequest.getOrigClientOrderId(), cancelOrderRequest.getNewClientOrderId(), - cancelOrderRequest.getRecvWindow(), cancelOrderRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getOpenOrders(OrderRequest orderRequest, BinanceApiCallback> callback) { - binanceApiService.getOpenOrders(orderRequest.getSymbol(), - orderRequest.getRecvWindow(), orderRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getAllOrders(AllOrdersRequest orderRequest, BinanceApiCallback> callback) { - binanceApiService.getAllOrders(orderRequest.getSymbol(), - orderRequest.getOrderId(), orderRequest.getLimit(), - orderRequest.getRecvWindow(), orderRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getAccount(Long recvWindow, Long timestamp, BinanceApiCallback callback) { - binanceApiService.getAccount(recvWindow, timestamp).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getAccount(BinanceApiCallback callback) { - long timestamp = System.currentTimeMillis(); - binanceApiService.getAccount(BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, timestamp).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getMyTrades(String symbol, Integer limit, Long fromId, Long recvWindow, Long timestamp, BinanceApiCallback> callback) { - binanceApiService.getMyTrades(symbol, limit, fromId, recvWindow, timestamp).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getMyTrades(String symbol, Integer limit, BinanceApiCallback> callback) { - getMyTrades(symbol, limit, null, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis(), callback); - } - - @Override - public void getMyTrades(String symbol, BinanceApiCallback> callback) { - getMyTrades(symbol, null, null, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis(), callback); - } - - @Override - public void withdraw(String asset, String address, String amount, String name, String addressTag, BinanceApiCallback callback) { - binanceApiService.withdraw(asset, address, amount, name, addressTag, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) - .enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getDepositHistory(String asset, BinanceApiCallback callback) { - binanceApiService.getDepositHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) - .enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getWithdrawHistory(String asset, BinanceApiCallback callback) { - binanceApiService.getWithdrawHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) - .enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void getDepositAddress(String asset, BinanceApiCallback callback) { - binanceApiService.getDepositAddress(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) - .enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - // User stream endpoints - - @Override - public void startUserDataStream(BinanceApiCallback callback) { - binanceApiService.startUserDataStream().enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void keepAliveUserDataStream(String listenKey, BinanceApiCallback callback) { - binanceApiService.keepAliveUserDataStream(listenKey).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - - @Override - public void closeUserDataStream(String listenKey, BinanceApiCallback callback) { - binanceApiService.closeAliveUserDataStream(listenKey).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } + private final BinanceApiService binanceApiService; + + public BinanceApiAsyncRestClientImpl(String apiKey, String secret) { + binanceApiService = createService(BinanceApiService.class, apiKey, secret); + } + + // General endpoints + + @Override + public void ping(BinanceApiCallback callback) { + binanceApiService.ping().enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getServerTime(BinanceApiCallback callback) { + binanceApiService.getServerTime().enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getExchangeInfo(BinanceApiCallback callback) { + binanceApiService.getExchangeInfo().enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAllAssets(BinanceApiCallback> callback) { + binanceApiService.getAllAssets(BinanceApiConfig.getAssetInfoApiBaseUrl() + "assetWithdraw/getAllAsset.html") + .enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + // Market Data endpoints + + @Override + public void getOrderBook(String symbol, Integer limit, BinanceApiCallback callback) { + binanceApiService.getOrderBook(symbol, limit).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getTrades(String symbol, Integer limit, BinanceApiCallback> callback) { + binanceApiService.getTrades(symbol, limit).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getHistoricalTrades(String symbol, Integer limit, Long fromId, BinanceApiCallback> callback) { + binanceApiService.getHistoricalTrades(symbol, limit, fromId).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAggTrades(String symbol, String fromId, Integer limit, Long startTime, Long endTime, BinanceApiCallback> callback) { + binanceApiService.getAggTrades(symbol, fromId, limit, startTime, endTime).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAggTrades(String symbol, BinanceApiCallback> callback) { + getAggTrades(symbol, null, null, null, null, callback); + } + + @Override + public void getCandlestickBars(String symbol, CandlestickInterval interval, Integer limit, Long startTime, Long endTime, BinanceApiCallback> callback) { + binanceApiService.getCandlestickBars(symbol, interval.getIntervalId(), limit, startTime, endTime).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getCandlestickBars(String symbol, CandlestickInterval interval, BinanceApiCallback> callback) { + getCandlestickBars(symbol, interval, null, null, null, callback); + } + + @Override + public void get24HrPriceStatistics(String symbol, BinanceApiCallback callback) { + binanceApiService.get24HrPriceStatistics(symbol).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAll24HrPriceStatistics(BinanceApiCallback> callback) { + binanceApiService.getAll24HrPriceStatistics().enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAllPrices(BinanceApiCallback> callback) { + binanceApiService.getLatestPrices().enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getPrice(String symbol, BinanceApiCallback callback) { + binanceApiService.getLatestPrice(symbol).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getBookTickers(BinanceApiCallback> callback) { + binanceApiService.getBookTickers().enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void newOrder(NewOrder order, BinanceApiCallback callback) { + if (order.getQuoteOrderQty() == null) { + binanceApiService.newOrder(order.getSymbol(), order.getSide(), order.getType(), order.getTimeInForce(), + order.getQuantity(), order.getPrice(), + order.getNewClientOrderId(), order.getStopPrice(), order.getIcebergQty(), order.getNewOrderRespType(), + order.getRecvWindow(), order.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } else { + binanceApiService.newOrderQuoteQty(order.getSymbol(), order.getSide(), order.getType(), + order.getTimeInForce(), order.getQuoteOrderQty(), order.getPrice(), + order.getNewClientOrderId(), order.getStopPrice(), order.getIcebergQty(), order.getNewOrderRespType(), + order.getRecvWindow(), order.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + } + + @Override + public void newOrderTest(NewOrder order, BinanceApiCallback callback) { + binanceApiService.newOrderTest(order.getSymbol(), order.getSide(), order.getType(), + order.getTimeInForce(), order.getQuantity(), order.getPrice(), order.getNewClientOrderId(), order.getStopPrice(), + order.getIcebergQty(), order.getNewOrderRespType(), order.getRecvWindow(), order.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + // Account endpoints + + @Override + public void getOrderStatus(OrderStatusRequest orderStatusRequest, BinanceApiCallback callback) { + binanceApiService.getOrderStatus(orderStatusRequest.getSymbol(), + orderStatusRequest.getOrderId(), orderStatusRequest.getOrigClientOrderId(), + orderStatusRequest.getRecvWindow(), orderStatusRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void cancelOrder(CancelOrderRequest cancelOrderRequest, BinanceApiCallback callback) { + binanceApiService.cancelOrder(cancelOrderRequest.getSymbol(), + cancelOrderRequest.getOrderId(), cancelOrderRequest.getOrigClientOrderId(), cancelOrderRequest.getNewClientOrderId(), + cancelOrderRequest.getRecvWindow(), cancelOrderRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getOpenOrders(OrderRequest orderRequest, BinanceApiCallback> callback) { + binanceApiService.getOpenOrders(orderRequest.getSymbol(), + orderRequest.getRecvWindow(), orderRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAllOrders(AllOrdersRequest orderRequest, BinanceApiCallback> callback) { + binanceApiService.getAllOrders(orderRequest.getSymbol(), + orderRequest.getOrderId(), orderRequest.getLimit(), + orderRequest.getRecvWindow(), orderRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAccount(Long recvWindow, Long timestamp, BinanceApiCallback callback) { + binanceApiService.getAccount(recvWindow, timestamp).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getAccount(BinanceApiCallback callback) { + long timestamp = System.currentTimeMillis(); + binanceApiService.getAccount(BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, timestamp).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getMyTrades(String symbol, Integer limit, Long fromId, Long recvWindow, Long timestamp, BinanceApiCallback> callback) { + binanceApiService.getMyTrades(symbol, limit, fromId, recvWindow, timestamp).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getMyTrades(String symbol, Integer limit, BinanceApiCallback> callback) { + getMyTrades(symbol, limit, null, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis(), callback); + } + + @Override + public void getMyTrades(String symbol, BinanceApiCallback> callback) { + getMyTrades(symbol, null, null, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis(), callback); + } + + @Override + public void withdraw(String asset, String address, String amount, String name, String addressTag, BinanceApiCallback callback) { + binanceApiService.withdraw(asset, address, amount, name, addressTag, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) + .enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getDepositHistory(String asset, BinanceApiCallback callback) { + binanceApiService.getDepositHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) + .enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getWithdrawHistory(String asset, BinanceApiCallback callback) { + binanceApiService.getWithdrawHistory(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) + .enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void getDepositAddress(String asset, BinanceApiCallback callback) { + binanceApiService.getDepositAddress(asset, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()) + .enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + // User stream endpoints + + @Override + public void startUserDataStream(BinanceApiCallback callback) { + binanceApiService.startUserDataStream().enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void keepAliveUserDataStream(String listenKey, BinanceApiCallback callback) { + binanceApiService.keepAliveUserDataStream(listenKey).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } + + @Override + public void closeUserDataStream(String listenKey, BinanceApiCallback callback) { + binanceApiService.closeAliveUserDataStream(listenKey).enqueue(new BinanceApiCallbackAdapter<>(callback)); + } } 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 c80c7a06d..0ff80b6ec 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java @@ -162,6 +162,11 @@ public List getOpenOrders(OrderRequest orderRequest) { orderRequest.getTimestamp())); } + @Override + public List getAllOpenOrders(AllOpenOrdersRequest allOpenOrdersRequest){ + return executeSync(binanceApiService.getAllOpenOrders(allOpenOrdersRequest.getRecvWindow(),allOpenOrdersRequest.getTimestamp())); + } + @Override public List getAllOrders(AllOrdersRequest orderRequest) { return executeSync(binanceApiService.getAllOrders(orderRequest.getSymbol(), orderRequest.getOrderId(), 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 5825f9844..1a1c7eca5 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiService.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiService.java @@ -77,7 +77,8 @@ Call> getCandlestickBars(@Query("symbol") String symbol, @Quer @Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER) @POST("/api/v3/order") Call newOrder(@Query("symbol") String symbol, @Query("side") OrderSide side, @Query("type") OrderType type, - @Query("timeInForce") TimeInForce timeInForce, @Query("quantity") String quantity, @Query("price") String price, + @Query("timeInForce") TimeInForce timeInForce, + @Query("quantity") String quantity, @Query("price") String price, @Query("newClientOrderId") String newClientOrderId, @Query("stopPrice") String stopPrice, @Query("icebergQty") String icebergQty, @Query("newOrderRespType") NewOrderResponseType newOrderRespType, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp); @@ -114,6 +115,10 @@ Call cancelOrder(@Query("symbol") String symbol, @Query("or @GET("/api/v3/openOrders") Call> getOpenOrders(@Query("symbol") String symbol, @Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp); + @Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER) + @GET("/api/v3/openOrders") + Call> getAllOpenOrders(@Query("recvWindow") Long recvWindow, @Query("timestamp") Long timestamp); + @Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER) @GET("/api/v3/allOrders") Call> getAllOrders(@Query("symbol") String symbol, @Query("orderId") Long orderId, @@ -123,8 +128,8 @@ Call> getAllOrders(@Query("symbol") String symbol, @Query("orderId") @POST("/api/v3/order/oco") Call newOCO(@Query("symbol") String symbol, @Query("listClientOrderId") String listClientOrderId, @Query("side") OrderSide side, @Query("quantity") String quantity, @Query("limitClientOrderId") String limitClientOrderId, @Query("price") String price, - @Query("limitIcebergQty") String limitIcebergQty, @Query("stopClientOrderId")String stopClientOrderId, @Query("stopPrice") String stopPrice, - @Query("stopLimitPrice")String stopLimitPrice, @Query("stopIcebergQty") String stopIcebergQty, @Query("stopLimitTimeInForce") TimeInForce stopLimitTimeInForce, + @Query("limitIcebergQty") String limitIcebergQty, @Query("stopClientOrderId") String stopClientOrderId, @Query("stopPrice") String stopPrice, + @Query("stopLimitPrice") String stopLimitPrice, @Query("stopIcebergQty") String stopIcebergQty, @Query("stopLimitTimeInForce") TimeInForce stopLimitTimeInForce, @Query("newOrderRespType") NewOrderResponseType newOrderRespType, @Query("recvWindow") Long recvWindow, @Query("timestamp") long timestamp); @Headers(BinanceApiConstants.ENDPOINT_SECURITY_TYPE_SIGNED_HEADER) diff --git a/src/test/java/com/binance/api/examples/OrdersExample.java b/src/test/java/com/binance/api/examples/OrdersExample.java index a1dd9d6cd..027136c74 100755 --- a/src/test/java/com/binance/api/examples/OrdersExample.java +++ b/src/test/java/com/binance/api/examples/OrdersExample.java @@ -6,6 +6,7 @@ import com.binance.api.client.domain.account.NewOrderResponse; import com.binance.api.client.domain.account.NewOrderResponseType; import com.binance.api.client.domain.account.Order; +import com.binance.api.client.domain.account.request.AllOpenOrdersRequest; import com.binance.api.client.domain.account.request.AllOrdersRequest; import com.binance.api.client.domain.account.request.CancelOrderRequest; import com.binance.api.client.domain.account.request.CancelOrderResponse; @@ -23,39 +24,51 @@ */ public class OrdersExample { - public static void main(String[] args) { - BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiRestClient client = factory.newRestClient(); + public static void main(String[] args) { + BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance("pXONV6u97xgMLxGSWpZY00LQN6mAjSWUWKvyjZoRQsQUbcKsSwagM1laZG5cScz7", "YmnZvrHDbjH7KLV8Dn9d8iuTogMgtyMZQL02M5JHUxjqF9YegG3KuiMqYlYyp6Ak"); + BinanceApiRestClient client = factory.newRestClient(); - // Getting list of open orders - List openOrders = client.getOpenOrders(new OrderRequest("LINKETH")); - System.out.println(openOrders); + // Getting list of open orders + List openOrders = client.getOpenOrders(new OrderRequest("LINKETH")); + System.out.println(openOrders); - // Getting list of all orders with a limit of 10 - List allOrders = client.getAllOrders(new AllOrdersRequest("LINKETH").limit(10)); - System.out.println(allOrders); + // Getting list of all open orders + List allOpenOrders = client.getAllOpenOrders(new AllOpenOrdersRequest()); + System.out.println(allOpenOrders); - // Get status of a particular order - Order order = client.getOrderStatus(new OrderStatusRequest("LINKETH", 751698L)); - System.out.println(order); + // Getting list of all orders with a limit of 10 + List allOrders = client.getAllOrders(new AllOrdersRequest("LINKETH").limit(10)); + System.out.println(allOrders); - // Canceling an order - try { - CancelOrderResponse cancelOrderResponse = client.cancelOrder(new CancelOrderRequest("LINKETH", 756762l)); - System.out.println(cancelOrderResponse); - } catch (BinanceApiException e) { - System.out.println(e.getError().getMsg()); - } + // Get status of a particular order + try { + Order order = client.getOrderStatus(new OrderStatusRequest("LINKETH", 751698L)); + System.out.println(order); + } catch (BinanceApiException e) { + System.err.println(e); + } + + // Canceling an order + try { + CancelOrderResponse cancelOrderResponse = client.cancelOrder(new CancelOrderRequest("LINKETH", 756762l)); + System.out.println(cancelOrderResponse); + } catch (BinanceApiException e) { + System.out.println(e.getError().getMsg()); + } - // Placing a test LIMIT order - client.newOrderTest(limitBuy("LINKETH", TimeInForce.GTC, "1000", "0.0001")); + // Placing a test LIMIT order + try { + client.newOrder(limitBuy("LINKETH", TimeInForce.GTC, "1000", "0.0001")); + } catch (BinanceApiException e) { + e.printStackTrace(); + } - // Placing a test MARKET order - client.newOrderTest(marketBuy("LINKETH", "1000")); + // Placing a test MARKET order + client.newOrderTest(marketBuy("LINKETH", "1000")); - // Placing a real LIMIT order - NewOrderResponse newOrderResponse = client.newOrder(limitBuy("LINKETH", TimeInForce.GTC, "1000", "0.0001").newOrderRespType(NewOrderResponseType.FULL)); - System.out.println(newOrderResponse); - } + // Placing a real LIMIT order + NewOrderResponse newOrderResponse = client.newOrder(limitBuy("LINKETH", TimeInForce.GTC, "1000", "0.0001").newOrderRespType(NewOrderResponseType.FULL)); + System.out.println(newOrderResponse); + } }