From c1ab5a431c7693244b5b3f84d2d04268b70ec1c5 Mon Sep 17 00:00:00 2001 From: Mahdi Sheikh Hosseini Date: Fri, 2 Apr 2021 15:59:47 +0430 Subject: [PATCH] Refactor whole project --- .../client/BinanceApiFuturesRestClient.java | 70 ---------- .../binance/api/client/BinanceEngineType.java | 2 + .../client/{ => api}/BinanceApiCallback.java | 2 +- .../api/client/{ => api}/BinanceApiError.java | 2 +- .../{ => api}/BinanceApiWebSocketClient.java | 2 +- .../BinanceApiAsyncFuturesRestClient.java | 3 +- .../BinanceApiAsyncMarginRestClient.java | 11 +- .../async/BinanceApiSpotAsyncRestClient.java} | 5 +- .../api/sync/BinanceApiFuturesRestClient.java | 21 +++ .../sync/BinanceApiGeneralRestClient.java} | 118 +--------------- .../sync}/BinanceApiMarginRestClient.java | 29 ++-- .../api/sync/BinanceApiSpotRestClient.java | 130 ++++++++++++++++++ .../sync}/BinanceApiSwapRestClient.java | 2 +- .../domain/account/FuturesNewOrder.java | 27 +++- .../client/domain/general/SymbolStatus.java | 21 ++- .../client/exception/BinanceApiException.java | 2 +- .../factory/BinanceAbstractFactory.java | 103 ++++++++++++++ .../api/client/factory/BinanceFactory.java | 20 ++- .../BinanceFuturesApiClientFactory.java | 36 ++--- .../BinanceMarginApiClientFactory.java | 73 ++++++++++ .../factory/BinanceSpotApiClientFactory.java | 41 ++---- .../factory/BinanceSwapApiClientFactory.java | 70 ++++++++++ .../impl/BinanceApiCallbackAdapter.java | 4 +- .../api/client/impl/BinanceApiService.java | 5 - .../impl/BinanceApiServiceGenerator.java | 2 +- .../client/impl/BinanceFuturesApiService.java | 3 - .../BinanceApiAsyncFuturesRestClientImpl.java | 9 +- .../BinanceApiAsyncMarginRestClientImpl.java | 14 +- .../BinanceApiSpotAsyncRestClientImpl.java} | 13 +- .../BinanceApiFuturesRestClientImpl.java | 83 +++++++++-- .../BinanceApiMarginRestClientImpl.java | 11 +- .../BinanceApiSpotRestClientImpl.java} | 10 +- .../BinanceApiSwapRestClientImpl.java | 6 +- .../BinanceApiWebSocketClientImpl.java | 6 +- .../{ => ws}/BinanceApiWebSocketListener.java | 4 +- .../examples/AccountBalanceCacheExample.java | 6 +- .../api/examples/AccountEndpointsExample.java | 4 +- .../AccountEndpointsExampleAsync.java | 4 +- .../api/examples/AggTradesCacheExample.java | 6 +- .../api/examples/AllMarketTickersExample.java | 2 +- .../examples/CandlesticksCacheExample.java | 6 +- .../api/examples/DepthCacheExample.java | 8 +- .../api/examples/GeneralEndpointsExample.java | 4 +- .../GeneralEndpointsExampleAsync.java | 4 +- .../MarginAccountEndpointsExample.java | 22 +-- .../MarginAccountEndpointsExampleAsync.java | 22 +-- ...arginAccountEndpointsLoanQueryExample.java | 8 +- .../api/examples/MarginOrdersExample.java | 8 +- .../examples/MarginOrdersExampleAsync.java | 8 +- .../examples/MarginUserDataStreamExample.java | 6 +- .../examples/MarketDataEndpointsExample.java | 4 +- .../MarketDataEndpointsExampleAsync.java | 4 +- .../api/examples/MarketDataStreamExample.java | 2 +- .../binance/api/examples/OrdersExample.java | 4 +- .../api/examples/OrdersExampleAsync.java | 4 +- .../api/examples/SwapEndpointExample.java | 9 +- .../examples/TotalAccountBalanceExample.java | 6 +- .../api/examples/UserDataStreamExample.java | 6 +- .../futures/FuturesAccountExample.java | 4 +- .../futures/FuturesOrdersAsyncExample.java | 2 +- .../futures/FuturesOrdersExample.java | 7 +- .../futures/FuturesUserDataStreamExample.java | 6 +- .../futures/FuturesWebSocketExample.java | 2 +- .../testnet/TestnetAccountExample.java | 4 +- .../testnet/TestnetGeneralExample.java | 47 +++++++ .../testnet/TestnetOrdersAsyncExample.java | 2 +- .../testnet/TestnetOrdersExample.java | 42 ++++-- .../testnet/TestnetWebSocketExample.java | 2 +- 68 files changed, 791 insertions(+), 444 deletions(-) delete mode 100755 src/main/java/com/binance/api/client/BinanceApiFuturesRestClient.java rename src/main/java/com/binance/api/client/{ => api}/BinanceApiCallback.java (90%) rename src/main/java/com/binance/api/client/{ => api}/BinanceApiError.java (89%) rename src/main/java/com/binance/api/client/{ => api}/BinanceApiWebSocketClient.java (99%) rename src/main/java/com/binance/api/client/{ => api/async}/BinanceApiAsyncFuturesRestClient.java (89%) rename src/main/java/com/binance/api/client/{ => api/async}/BinanceApiAsyncMarginRestClient.java (89%) rename src/main/java/com/binance/api/client/{BinanceApiAsyncRestClient.java => api/async/BinanceApiSpotAsyncRestClient.java} (98%) create mode 100755 src/main/java/com/binance/api/client/api/sync/BinanceApiFuturesRestClient.java rename src/main/java/com/binance/api/client/{BinanceApiRestClient.java => api/sync/BinanceApiGeneralRestClient.java} (61%) rename src/main/java/com/binance/api/client/{ => api/sync}/BinanceApiMarginRestClient.java (82%) create mode 100755 src/main/java/com/binance/api/client/api/sync/BinanceApiSpotRestClient.java rename src/main/java/com/binance/api/client/{ => api/sync}/BinanceApiSwapRestClient.java (94%) create mode 100755 src/main/java/com/binance/api/client/factory/BinanceMarginApiClientFactory.java create mode 100755 src/main/java/com/binance/api/client/factory/BinanceSwapApiClientFactory.java rename src/main/java/com/binance/api/client/impl/{ => async}/BinanceApiAsyncFuturesRestClientImpl.java (89%) rename src/main/java/com/binance/api/client/impl/{ => async}/BinanceApiAsyncMarginRestClientImpl.java (90%) rename src/main/java/com/binance/api/client/impl/{BinanceApiAsyncRestClientImpl.java => async/BinanceApiSpotAsyncRestClientImpl.java} (95%) rename src/main/java/com/binance/api/client/impl/{ => sync}/BinanceApiFuturesRestClientImpl.java (50%) rename src/main/java/com/binance/api/client/impl/{ => sync}/BinanceApiMarginRestClientImpl.java (91%) rename src/main/java/com/binance/api/client/impl/{BinanceApiRestClientImpl.java => sync/BinanceApiSpotRestClientImpl.java} (95%) rename src/main/java/com/binance/api/client/impl/{ => sync}/BinanceApiSwapRestClientImpl.java (92%) rename src/main/java/com/binance/api/client/impl/{ => ws}/BinanceApiWebSocketClientImpl.java (96%) rename src/main/java/com/binance/api/client/impl/{ => ws}/BinanceApiWebSocketListener.java (91%) create mode 100755 src/test/java/com/binance/api/examples/testnet/TestnetGeneralExample.java diff --git a/src/main/java/com/binance/api/client/BinanceApiFuturesRestClient.java b/src/main/java/com/binance/api/client/BinanceApiFuturesRestClient.java deleted file mode 100755 index faca20e4f..000000000 --- a/src/main/java/com/binance/api/client/BinanceApiFuturesRestClient.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.binance.api.client; - -import com.binance.api.client.domain.account.FuturesAccount; -import com.binance.api.client.domain.account.FuturesNewOrder; -import com.binance.api.client.domain.account.FuturesNewOrderResponse; -import com.binance.api.client.domain.account.Order; -import com.binance.api.client.domain.account.request.CancelOrderRequest; -import com.binance.api.client.domain.account.request.CancelOrderResponse; -import com.binance.api.client.domain.account.request.OrderRequest; -import com.binance.api.client.domain.account.request.OrderStatusRequest; - -import java.util.List; - -public interface BinanceApiFuturesRestClient { - /** - * Get current margin account information using default parameters. - */ - FuturesAccount getAccount(); - - /** - * Get all open orders on margin account for a symbol. - * - * @param orderRequest order request parameters - */ - List getOpenOrders(OrderRequest orderRequest); - - /** - * Send in a new margin order. - * - * @param order the new order to submit. - * @return a response containing details about the newly placed order. - */ - FuturesNewOrderResponse newOrder(FuturesNewOrder order); - - /** - * Cancel an active margin order. - * - * @param cancelOrderRequest order status request parameters - */ - CancelOrderResponse cancelOrder(CancelOrderRequest cancelOrderRequest); - - /** - * Check margin order's status. - * - * @param orderStatusRequest order status request options/filters - * @return an order - */ - Order getOrderStatus(OrderStatusRequest orderStatusRequest); - - /** - * Start a new user data stream. - * - * @return a listen key that can be used with data streams - */ - String startUserDataStream(); - - /** - * PING a user data stream to prevent a time out. - * - * @param listenKey listen key that identifies a data stream - */ - void keepAliveUserDataStream(String listenKey); - - /** - * Close out a new user data stream. - * - * @param listenKey listen key that identifies a data stream - */ - void closeUserDataStream(String listenKey); -} diff --git a/src/main/java/com/binance/api/client/BinanceEngineType.java b/src/main/java/com/binance/api/client/BinanceEngineType.java index 2a07a9545..3ed096184 100644 --- a/src/main/java/com/binance/api/client/BinanceEngineType.java +++ b/src/main/java/com/binance/api/client/BinanceEngineType.java @@ -5,6 +5,8 @@ */ public enum BinanceEngineType { SPOT, + MARGIN, + SWAP, FUTURES, TESTNET } diff --git a/src/main/java/com/binance/api/client/BinanceApiCallback.java b/src/main/java/com/binance/api/client/api/BinanceApiCallback.java similarity index 90% rename from src/main/java/com/binance/api/client/BinanceApiCallback.java rename to src/main/java/com/binance/api/client/api/BinanceApiCallback.java index 3112bd793..b77f715a4 100755 --- a/src/main/java/com/binance/api/client/BinanceApiCallback.java +++ b/src/main/java/com/binance/api/client/api/BinanceApiCallback.java @@ -1,4 +1,4 @@ -package com.binance.api.client; +package com.binance.api.client.api; /** * BinanceApiCallback is a functional interface used together with the BinanceApiAsyncClient to provide a non-blocking REST client. diff --git a/src/main/java/com/binance/api/client/BinanceApiError.java b/src/main/java/com/binance/api/client/api/BinanceApiError.java similarity index 89% rename from src/main/java/com/binance/api/client/BinanceApiError.java rename to src/main/java/com/binance/api/client/api/BinanceApiError.java index b0d98ab8c..9a89e9ef4 100755 --- a/src/main/java/com/binance/api/client/BinanceApiError.java +++ b/src/main/java/com/binance/api/client/api/BinanceApiError.java @@ -1,4 +1,4 @@ -package com.binance.api.client; +package com.binance.api.client.api; import com.binance.api.client.constant.BinanceApiConstants; import org.apache.commons.lang3.builder.ToStringBuilder; diff --git a/src/main/java/com/binance/api/client/BinanceApiWebSocketClient.java b/src/main/java/com/binance/api/client/api/BinanceApiWebSocketClient.java similarity index 99% rename from src/main/java/com/binance/api/client/BinanceApiWebSocketClient.java rename to src/main/java/com/binance/api/client/api/BinanceApiWebSocketClient.java index bc048d464..95ed31e06 100755 --- a/src/main/java/com/binance/api/client/BinanceApiWebSocketClient.java +++ b/src/main/java/com/binance/api/client/api/BinanceApiWebSocketClient.java @@ -1,4 +1,4 @@ -package com.binance.api.client; +package com.binance.api.client.api; import com.binance.api.client.domain.event.*; import com.binance.api.client.domain.market.CandlestickInterval; diff --git a/src/main/java/com/binance/api/client/BinanceApiAsyncFuturesRestClient.java b/src/main/java/com/binance/api/client/api/async/BinanceApiAsyncFuturesRestClient.java similarity index 89% rename from src/main/java/com/binance/api/client/BinanceApiAsyncFuturesRestClient.java rename to src/main/java/com/binance/api/client/api/async/BinanceApiAsyncFuturesRestClient.java index b932df43d..ecd8dc228 100755 --- a/src/main/java/com/binance/api/client/BinanceApiAsyncFuturesRestClient.java +++ b/src/main/java/com/binance/api/client/api/async/BinanceApiAsyncFuturesRestClient.java @@ -1,5 +1,6 @@ -package com.binance.api.client; +package com.binance.api.client.api.async; +import com.binance.api.client.api.BinanceApiCallback; import com.binance.api.client.domain.account.*; import com.binance.api.client.domain.account.request.CancelOrderRequest; import com.binance.api.client.domain.account.request.CancelOrderResponse; diff --git a/src/main/java/com/binance/api/client/BinanceApiAsyncMarginRestClient.java b/src/main/java/com/binance/api/client/api/async/BinanceApiAsyncMarginRestClient.java similarity index 89% rename from src/main/java/com/binance/api/client/BinanceApiAsyncMarginRestClient.java rename to src/main/java/com/binance/api/client/api/async/BinanceApiAsyncMarginRestClient.java index 8d1d8486f..f8d3ab715 100755 --- a/src/main/java/com/binance/api/client/BinanceApiAsyncMarginRestClient.java +++ b/src/main/java/com/binance/api/client/api/async/BinanceApiAsyncMarginRestClient.java @@ -1,5 +1,6 @@ -package com.binance.api.client; +package com.binance.api.client.api.async; +import com.binance.api.client.api.BinanceApiCallback; import com.binance.api.client.domain.TransferType; import com.binance.api.client.domain.account.*; import com.binance.api.client.domain.account.request.CancelOrderRequest; @@ -58,14 +59,6 @@ public interface BinanceApiAsyncMarginRestClient { */ void getOrderStatus(OrderStatusRequest orderStatusRequest, BinanceApiCallback callback); - /** - * Get margin trades for a specific symbol (async). - * - * @param symbol symbol to get trades from - * @return a list of trades - */ - void getMyTrades(String symbol, BinanceApiCallback> callback); - // User stream endpoints /** diff --git a/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java b/src/main/java/com/binance/api/client/api/async/BinanceApiSpotAsyncRestClient.java similarity index 98% rename from src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java rename to src/main/java/com/binance/api/client/api/async/BinanceApiSpotAsyncRestClient.java index 989562868..509eaebf0 100755 --- a/src/main/java/com/binance/api/client/BinanceApiAsyncRestClient.java +++ b/src/main/java/com/binance/api/client/api/async/BinanceApiSpotAsyncRestClient.java @@ -1,5 +1,6 @@ -package com.binance.api.client; +package com.binance.api.client.api.async; +import com.binance.api.client.api.BinanceApiCallback; import com.binance.api.client.domain.account.*; import com.binance.api.client.domain.account.request.*; import com.binance.api.client.domain.event.ListenKey; @@ -12,7 +13,7 @@ /** * Binance API facade, supporting asynchronous/non-blocking access Binance's REST API. */ -public interface BinanceApiAsyncRestClient { +public interface BinanceApiSpotAsyncRestClient { // General endpoints diff --git a/src/main/java/com/binance/api/client/api/sync/BinanceApiFuturesRestClient.java b/src/main/java/com/binance/api/client/api/sync/BinanceApiFuturesRestClient.java new file mode 100755 index 000000000..bedc6b758 --- /dev/null +++ b/src/main/java/com/binance/api/client/api/sync/BinanceApiFuturesRestClient.java @@ -0,0 +1,21 @@ +package com.binance.api.client.api.sync; + +import com.binance.api.client.domain.account.FuturesAccount; +import com.binance.api.client.domain.account.FuturesNewOrder; +import com.binance.api.client.domain.account.FuturesNewOrderResponse; + +public interface BinanceApiFuturesRestClient extends BinanceApiGeneralRestClient { + + /** + * Get current margin account information using default parameters. + */ + FuturesAccount getAccount(); + + /** + * Send in a new margin order. + * + * @param order the new order to submit. + * @return a response containing details about the newly placed order. + */ + FuturesNewOrderResponse newOrder(FuturesNewOrder order); +} diff --git a/src/main/java/com/binance/api/client/BinanceApiRestClient.java b/src/main/java/com/binance/api/client/api/sync/BinanceApiGeneralRestClient.java similarity index 61% rename from src/main/java/com/binance/api/client/BinanceApiRestClient.java rename to src/main/java/com/binance/api/client/api/sync/BinanceApiGeneralRestClient.java index 97c6dbe90..594666dbe 100755 --- a/src/main/java/com/binance/api/client/BinanceApiRestClient.java +++ b/src/main/java/com/binance/api/client/api/sync/BinanceApiGeneralRestClient.java @@ -1,4 +1,4 @@ -package com.binance.api.client; +package com.binance.api.client.api.sync; import com.binance.api.client.domain.account.*; import com.binance.api.client.domain.account.request.*; @@ -10,7 +10,7 @@ /** * Binance API facade, supporting synchronous/blocking access Binance's REST API. */ -public interface BinanceApiRestClient { +public interface BinanceApiGeneralRestClient { // General endpoints @@ -112,11 +112,6 @@ public interface BinanceApiRestClient { */ List getAll24HrPriceStatistics(); - /** - * Get Latest price for all symbols. - */ - List getAllPrices(); - /** * Get latest price for symbol. * @@ -124,27 +119,6 @@ public interface BinanceApiRestClient { */ TickerPrice getPrice(String symbol); - /** - * Get best price/qty on the order book for all symbols. - */ - List getBookTickers(); - - // Account endpoints - - /** - * Send in a new order. - * - * @param order the new order to submit. - * @return a response containing details about the newly placed order. - */ - NewOrderResponse newOrder(NewOrder order); - - /** - * Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine. - * - * @param order the new TEST order to submit. - */ - void newOrderTest(NewOrder order); /** * Check an order's status. @@ -169,94 +143,6 @@ public interface BinanceApiRestClient { */ List getOpenOrders(OrderRequest orderRequest); - /** - * Get all account orders; active, canceled, or filled. - * - * @param orderRequest order request parameters - * @return a list of all account orders - */ - List getAllOrders(AllOrdersRequest orderRequest); - - /** - * Get current account information. - */ - Account getAccount(Long recvWindow, Long timestamp); - - /** - * Get current account information using default parameters. - */ - Account getAccount(); - - /** - * Get trades for a specific account and symbol. - * - * @param symbol symbol to get trades from - * @param limit default 500; max 1000 - * @param fromId TradeId to fetch from. Default gets most recent trades. - * @return a list of trades - */ - List getMyTrades(String symbol, Integer limit, Long fromId, Long recvWindow, Long timestamp); - - /** - * Get trades for a specific account and symbol. - * - * @param symbol symbol to get trades from - * @param limit default 500; max 1000 - * @return a list of trades - */ - List getMyTrades(String symbol, Integer limit); - - /** - * Get trades for a specific account and symbol. - * - * @param symbol symbol to get trades from - * @return a list of trades - */ - List getMyTrades(String symbol); - - List getMyTrades(String symbol, Long fromId); - - /** - * Submit a withdraw request. - *

- * Enable Withdrawals option has to be active in the API settings. - * - * @param asset asset symbol to withdraw - * @param address address to withdraw to - * @param amount amount to withdraw - * @param name description/alias of the address - * @param addressTag Secondary address identifier for coins like XRP,XMR etc. - */ - WithdrawResult withdraw(String asset, String address, String amount, String name, String addressTag); - - /** - * Fetch account deposit history. - * - * @return deposit history, containing a list of deposits - */ - DepositHistory getDepositHistory(String asset); - - /** - * Fetch account withdraw history. - * - * @return withdraw history, containing a list of withdrawals - */ - WithdrawHistory getWithdrawHistory(String asset); - - /** - * Fetch sub-account transfer history. - * - * @return sub-account transfers - */ - List getSubAccountTransfers(); - - /** - * Fetch deposit address. - * - * @return deposit address for a given asset. - */ - DepositAddress getDepositAddress(String asset); - // User stream endpoints /** * Start a new user data stream. diff --git a/src/main/java/com/binance/api/client/BinanceApiMarginRestClient.java b/src/main/java/com/binance/api/client/api/sync/BinanceApiMarginRestClient.java similarity index 82% rename from src/main/java/com/binance/api/client/BinanceApiMarginRestClient.java rename to src/main/java/com/binance/api/client/api/sync/BinanceApiMarginRestClient.java index fd051bd6b..bc5ff7c3e 100755 --- a/src/main/java/com/binance/api/client/BinanceApiMarginRestClient.java +++ b/src/main/java/com/binance/api/client/api/sync/BinanceApiMarginRestClient.java @@ -1,4 +1,4 @@ -package com.binance.api.client; +package com.binance.api.client.api.sync; import com.binance.api.client.domain.TransferType; import com.binance.api.client.domain.account.*; @@ -39,23 +39,16 @@ public interface BinanceApiMarginRestClient { /** * Check margin order's status. - * @param orderStatusRequest order status request options/filters * + * @param orderStatusRequest order status request options/filters * @return an order */ Order getOrderStatus(OrderStatusRequest orderStatusRequest); - /** - * Get margin trades for a specific symbol. - * - * @param symbol symbol to get trades from - * @return a list of trades - */ - List getMyTrades(String symbol); - /** * Execute transfer between spot account and margin account - * @param asset asset to repay + * + * @param asset asset to repay * @param amount amount to repay * @return transaction id */ @@ -63,7 +56,8 @@ public interface BinanceApiMarginRestClient { /** * Apply for a loan - * @param asset asset to repay + * + * @param asset asset to repay * @param amount amount to repay * @return transaction id */ @@ -71,6 +65,7 @@ public interface BinanceApiMarginRestClient { /** * Query loan record + * * @param asset asset to query * @return repay records */ @@ -78,6 +73,7 @@ public interface BinanceApiMarginRestClient { /** * Query max borrowable + * * @param asset asset to query * @return max borrowable */ @@ -85,15 +81,17 @@ public interface BinanceApiMarginRestClient { /** * Query loan record + * * @param asset asset to query - * @param txId the tranId in POST /sapi/v1/margin/repay + * @param txId the tranId in POST /sapi/v1/margin/repay * @return loan records */ RepayQueryResult queryRepay(String asset, String txId); /** * Repay loan for margin account - * @param asset asset to repay + * + * @param asset asset to repay * @param amount amount to repay * @return transaction id */ @@ -101,8 +99,9 @@ public interface BinanceApiMarginRestClient { /** * Query loan record + * * @param asset asset to query - * @param txId the tranId in POST /sapi/v1/margin/loan + * @param txId the tranId in POST /sapi/v1/margin/loan * @return loan records */ LoanQueryResult queryLoan(String asset, String txId); diff --git a/src/main/java/com/binance/api/client/api/sync/BinanceApiSpotRestClient.java b/src/main/java/com/binance/api/client/api/sync/BinanceApiSpotRestClient.java new file mode 100755 index 000000000..58e7b1213 --- /dev/null +++ b/src/main/java/com/binance/api/client/api/sync/BinanceApiSpotRestClient.java @@ -0,0 +1,130 @@ +package com.binance.api.client.api.sync; + +import com.binance.api.client.domain.account.*; +import com.binance.api.client.domain.account.request.AllOrdersRequest; +import com.binance.api.client.domain.market.BookTicker; +import com.binance.api.client.domain.market.TickerPrice; + +import java.util.List; + +/** + * Binance API facade, supporting synchronous/blocking access Binance's REST API. + */ +public interface BinanceApiSpotRestClient extends BinanceApiGeneralRestClient { + + // Account endpoints + + /** + * Send in a new order. + * + * @param order the new order to submit. + * @return a response containing details about the newly placed order. + */ + NewOrderResponse newOrder(NewOrder order); + + + /** + * Get Latest price for all symbols. + */ + List getAllPrices(); + + /** + * Get best price/qty on the order book for all symbols. + */ + List getBookTickers(); + + /** + * Get all account orders; active, canceled, or filled. + * + * @param orderRequest order request parameters + * @return a list of all account orders + */ + List getAllOrders(AllOrdersRequest orderRequest); + + /** + * Test new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine. + * + * @param order the new TEST order to submit. + */ + void newOrderTest(NewOrder order); + + /** + * Get current account information. + */ + Account getAccount(Long recvWindow, Long timestamp); + + /** + * Get current account information using default parameters. + */ + Account getAccount(); + + /** + * Get trades for a specific account and symbol. + * + * @param symbol symbol to get trades from + * @param limit default 500; max 1000 + * @param fromId TradeId to fetch from. Default gets most recent trades. + * @return a list of trades + */ + List getMyTrades(String symbol, Integer limit, Long fromId, Long recvWindow, Long timestamp); + + /** + * Get trades for a specific account and symbol. + * + * @param symbol symbol to get trades from + * @param limit default 500; max 1000 + * @return a list of trades + */ + List getMyTrades(String symbol, Integer limit); + + /** + * Get trades for a specific account and symbol. + * + * @param symbol symbol to get trades from + * @return a list of trades + */ + List getMyTrades(String symbol); + + List getMyTrades(String symbol, Long fromId); + + /** + * Submit a withdraw request. + *

+ * Enable Withdrawals option has to be active in the API settings. + * + * @param asset asset symbol to withdraw + * @param address address to withdraw to + * @param amount amount to withdraw + * @param name description/alias of the address + * @param addressTag Secondary address identifier for coins like XRP,XMR etc. + */ + WithdrawResult withdraw(String asset, String address, String amount, String name, String addressTag); + + /** + * Fetch account deposit history. + * + * @return deposit history, containing a list of deposits + */ + DepositHistory getDepositHistory(String asset); + + /** + * Fetch account withdraw history. + * + * @return withdraw history, containing a list of withdrawals + */ + WithdrawHistory getWithdrawHistory(String asset); + + /** + * Fetch sub-account transfer history. + * + * @return sub-account transfers + */ + List getSubAccountTransfers(); + + /** + * Fetch deposit address. + * + * @return deposit address for a given asset. + */ + DepositAddress getDepositAddress(String asset); +} diff --git a/src/main/java/com/binance/api/client/BinanceApiSwapRestClient.java b/src/main/java/com/binance/api/client/api/sync/BinanceApiSwapRestClient.java similarity index 94% rename from src/main/java/com/binance/api/client/BinanceApiSwapRestClient.java rename to src/main/java/com/binance/api/client/api/sync/BinanceApiSwapRestClient.java index f7baf2c2e..f8d5c0623 100755 --- a/src/main/java/com/binance/api/client/BinanceApiSwapRestClient.java +++ b/src/main/java/com/binance/api/client/api/sync/BinanceApiSwapRestClient.java @@ -1,4 +1,4 @@ -package com.binance.api.client; +package com.binance.api.client.api.sync; import com.binance.api.client.domain.SwapRemoveType; import com.binance.api.client.domain.account.*; diff --git a/src/main/java/com/binance/api/client/domain/account/FuturesNewOrder.java b/src/main/java/com/binance/api/client/domain/account/FuturesNewOrder.java index 5c995f60f..91c6c81d9 100644 --- a/src/main/java/com/binance/api/client/domain/account/FuturesNewOrder.java +++ b/src/main/java/com/binance/api/client/domain/account/FuturesNewOrder.java @@ -129,6 +129,19 @@ public FuturesNewOrder(String symbol, OrderSide side, OrderType type, String qua this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW; } + public FuturesNewOrder(String symbol, OrderSide side, OrderType type, TimeInForce timeInForce, String quantity, String price, boolean reduceOnly) { + this.symbol = symbol; + this.side = side; + this.type = type; + this.timeInForce = timeInForce; + this.quantity = quantity; + this.price = price; + this.reduceOnly = reduceOnly; + this.newOrderRespType = NewOrderResponseType.RESULT; + this.timestamp = System.currentTimeMillis(); + this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW; + } + public String getSymbol() { return symbol; } @@ -273,12 +286,12 @@ public void setTimestamp(long timestamp) { this.timestamp = timestamp; } - public static FuturesNewOrder limitLong(String symbol, TimeInForce timeInForce, WorkingType workingType, String quantity, String price, boolean reduceOnly) { - return new FuturesNewOrder(symbol, OrderSide.BUY, OrderType.LIMIT, timeInForce, workingType, quantity, price, reduceOnly); + public static FuturesNewOrder limitLong(String symbol, TimeInForce timeInForce, String quantity, String price, boolean reduceOnly) { + return new FuturesNewOrder(symbol, OrderSide.BUY, OrderType.LIMIT, timeInForce, quantity, price, reduceOnly); } - public static FuturesNewOrder limitShort(String symbol, TimeInForce timeInForce, WorkingType workingType, String quantity, String price, boolean reduceOnly) { - return new FuturesNewOrder(symbol, OrderSide.SELL, OrderType.LIMIT, timeInForce, workingType, quantity, price, reduceOnly); + public static FuturesNewOrder limitShort(String symbol, TimeInForce timeInForce, String quantity, String price, boolean reduceOnly) { + return new FuturesNewOrder(symbol, OrderSide.SELL, OrderType.LIMIT, timeInForce, quantity, price, reduceOnly); } public static FuturesNewOrder MarketLong(String symbol, String quantity, boolean reduceOnly) { @@ -289,6 +302,12 @@ public static FuturesNewOrder MarketShort(String symbol, String quantity, boolea return new FuturesNewOrder(symbol, OrderSide.SELL, OrderType.MARKET, quantity, reduceOnly); } + public static FuturesNewOrder stopLimitShort(String symbol, String quantity, String stopPrice, boolean reduceOnly) { + FuturesNewOrder order = new FuturesNewOrder(symbol, OrderSide.SELL, OrderType.STOP_MARKET, quantity, reduceOnly); + order.setStopPrice(stopPrice); + return order; + } + /* public static FuturesNewOrder stopLimitLong(String symbol, String quantity, boolean reduceOnly) { return new FuturesNewOrder(symbol, OrderSide.SELL, OrderType.MARKET, quantity); }*/ diff --git a/src/main/java/com/binance/api/client/domain/general/SymbolStatus.java b/src/main/java/com/binance/api/client/domain/general/SymbolStatus.java index 77291ee77..25bfdb38a 100755 --- a/src/main/java/com/binance/api/client/domain/general/SymbolStatus.java +++ b/src/main/java/com/binance/api/client/domain/general/SymbolStatus.java @@ -7,11 +7,18 @@ */ @JsonIgnoreProperties(ignoreUnknown = true) public enum SymbolStatus { - PRE_TRADING, - TRADING, - POST_TRADING, - END_OF_DAY, - HALT, - AUCTION_MATCH, - BREAK; + PRE_TRADING, + TRADING, + POST_TRADING, + END_OF_DAY, + HALT, + AUCTION_MATCH, + BREAK, + SETTLING, + PENDING_TRADING, + DELIVERING, + DELIVERED, + PRE_SETTLE, + CLOSE, + PRE_DELIVERING; } diff --git a/src/main/java/com/binance/api/client/exception/BinanceApiException.java b/src/main/java/com/binance/api/client/exception/BinanceApiException.java index 80430fd8d..7b12cfb2b 100755 --- a/src/main/java/com/binance/api/client/exception/BinanceApiException.java +++ b/src/main/java/com/binance/api/client/exception/BinanceApiException.java @@ -1,6 +1,6 @@ package com.binance.api.client.exception; -import com.binance.api.client.BinanceApiError; +import com.binance.api.client.api.BinanceApiError; /** * An exception which can occur while invoking methods of the Binance API. diff --git a/src/main/java/com/binance/api/client/factory/BinanceAbstractFactory.java b/src/main/java/com/binance/api/client/factory/BinanceAbstractFactory.java index 7e0ba0864..4bfadef27 100644 --- a/src/main/java/com/binance/api/client/factory/BinanceAbstractFactory.java +++ b/src/main/java/com/binance/api/client/factory/BinanceAbstractFactory.java @@ -4,14 +4,33 @@ import com.binance.api.client.config.*; import com.binance.api.client.exception.BinanceIllegalException; +/** + * @author Mahdi Shiekh Hosseini + */ public abstract class BinanceAbstractFactory { + /** + * General binance factory . + * this method create a factory by type of engine you choose . + * + * @param apiKey + * @param secretKey + * @param engineType + * @param apiConfigClass + * @return instance of object extended BinanceFactory + * @see BinanceApiConfig + * @see BinanceEngineType + */ public static BinanceFactory createFactory(String apiKey, String secretKey, BinanceEngineType engineType, Class apiConfigClass) { final String apiUrl = getApiUrl(apiConfigClass); final String websocketUrl = getWebsocketUrl(apiConfigClass); switch (engineType) { case SPOT: return BinanceSpotApiClientFactory.newInstance(apiKey, secretKey, apiUrl, websocketUrl); + case MARGIN: + return BinanceMarginApiClientFactory.newInstance(apiKey, secretKey, apiUrl, websocketUrl); + case SWAP: + return BinanceSwapApiClientFactory.newInstance(apiKey, secretKey, apiUrl); case FUTURES: case TESTNET: return BinanceFuturesApiClientFactory.newInstance(apiKey, secretKey, apiUrl, websocketUrl); @@ -19,10 +38,21 @@ public static BinanceFactory createFactory(String apiKey, String secretKey, Bina throw new IllegalArgumentException(); } + /** + * @param apiKey + * @param secretKey + * @param engineType + * @return instance of object extended BinanceFactory + * @see BinanceEngineType + */ public static BinanceFactory createFactory(String apiKey, String secretKey, BinanceEngineType engineType) { switch (engineType) { case SPOT: return createSpotFactory(apiKey, secretKey); + case MARGIN: + return createMarginFactory(apiKey, secretKey); + case SWAP: + return createSwapFactory(apiKey, secretKey); case FUTURES: return createFuturesFactory(apiKey, secretKey); case TESTNET: @@ -31,44 +61,117 @@ public static BinanceFactory createFactory(String apiKey, String secretKey, Bina throw new IllegalArgumentException(); } + /** + * Basic and simple create spot engine factory . + * + * @param apiKey + * @param secretKey + * @return instance of object extended BinanceFactory + */ public static BinanceSpotApiClientFactory createSpotFactory(String apiKey, String secretKey) { final String apiUrl = getApiUrl(SpotApiConfig.class); final String websocketUrl = getWebsocketUrl(SpotApiConfig.class); return BinanceSpotApiClientFactory.newInstance(apiKey, secretKey, apiUrl, websocketUrl); } + /** + * Basic and simple create margin engine factory . + * + * @param apiKey + * @param secretKey + * @return instance of object extended BinanceFactory + */ + public static BinanceMarginApiClientFactory createMarginFactory(String apiKey, String secretKey) { + final String apiUrl = getApiUrl(SpotApiConfig.class); + final String websocketUrl = getWebsocketUrl(SpotApiConfig.class); + return BinanceMarginApiClientFactory.newInstance(apiKey, secretKey, apiUrl, websocketUrl); + } + + /** + * Basic and simple create margin swap factory . + * + * @param apiKey + * @param secretKey + * @return instance of object extended BinanceFactory + */ + public static BinanceSwapApiClientFactory createSwapFactory(String apiKey, String secretKey) { + final String apiUrl = getApiUrl(SpotApiConfig.class); + return BinanceSwapApiClientFactory.newInstance(apiKey, secretKey, apiUrl); + } + + /** + * Basic and simple create futures engine factory . + * + * @param apiKey + * @param secretKey + * @return instance of object extended BinanceFactory + */ public static BinanceFuturesApiClientFactory createFuturesFactory(String apiKey, String secretKey) { final String apiUrl = getApiUrl(FuturesApiConfig.class); final String websocketUrl = getWebsocketUrl(FuturesApiConfig.class); return BinanceFuturesApiClientFactory.newInstance(apiKey, secretKey, apiUrl, websocketUrl); } + /** + * Basic and simple create testnet engine factory . + * + * @param apiKey + * @param secretKey + * @return instance of object extended BinanceFactory + */ public static BinanceFuturesApiClientFactory createTestnetFactory(String apiKey, String secretKey) { final String apiUrl = getApiUrl(TestnetApiConfig.class); final String websocketUrl = getWebsocketUrl(TestnetApiConfig.class); return BinanceFuturesApiClientFactory.newInstance(apiKey, secretKey, apiUrl, websocketUrl); } + /** + * @return instance of BinanceSpotApiClientFactory + */ public static BinanceSpotApiClientFactory createSpotFactory() { return createSpotFactory(null, null); } + /** + * @return instance of BinanceSpotApiClientFactory + */ public static BinanceFuturesApiClientFactory createFuturesFactory() { return createFuturesFactory(null, null); } + /** + * @return instance of BinanceSpotApiClientFactory + */ public static BinanceFuturesApiClientFactory createTestnetFactory() { return createTestnetFactory(null, null); } + /** + * get apiUrl from ApiConfig annotation + * + * @param apiConfigClass + * @return apiUrl + * @see ApiConfig + */ private static String getApiUrl(Class apiConfigClass) { return getApiConfig(apiConfigClass).apiUrl(); } + /** + * get websocketUrl from ApiConfig annotation + * + * @param apiConfigClass + * @return websocketUrl + * @see ApiConfig + */ private static String getWebsocketUrl(Class apiConfigClass) { return getApiConfig(apiConfigClass).webSocketUrl(); } + /** + * @param apiConfigClass + * @return + */ private static ApiConfig getApiConfig(Class apiConfigClass) { if (apiConfigClass.isAnnotationPresent(ApiConfig.class)) { return apiConfigClass.getAnnotation(ApiConfig.class); diff --git a/src/main/java/com/binance/api/client/factory/BinanceFactory.java b/src/main/java/com/binance/api/client/factory/BinanceFactory.java index 4daa32477..a80ee70e5 100644 --- a/src/main/java/com/binance/api/client/factory/BinanceFactory.java +++ b/src/main/java/com/binance/api/client/factory/BinanceFactory.java @@ -1,10 +1,20 @@ package com.binance.api.client.factory; -public interface BinanceFactory { +/** + * Generic binance factory used for any implementation of new engines + * + * @author Mahdi Shiekh Hosseini + * @see com.binance.api.client.BinanceEngineType + */ +public interface BinanceFactory { - T newAsyncRestClient(); + /** + * @return instance of asynchronous class + */ + ASYNC newAsyncRestClient(); - T newRestClient(); - - T newWebSocketClient(); + /** + * @return instance of synchronous class + */ + SYNC newRestClient(); } diff --git a/src/main/java/com/binance/api/client/factory/BinanceFuturesApiClientFactory.java b/src/main/java/com/binance/api/client/factory/BinanceFuturesApiClientFactory.java index 77c07e02e..8df444537 100755 --- a/src/main/java/com/binance/api/client/factory/BinanceFuturesApiClientFactory.java +++ b/src/main/java/com/binance/api/client/factory/BinanceFuturesApiClientFactory.java @@ -1,20 +1,18 @@ package com.binance.api.client.factory; -import com.binance.api.client.BinanceApiAsyncFuturesRestClient; -import com.binance.api.client.BinanceApiFuturesRestClient; -import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; -import com.binance.api.client.impl.BinanceApiAsyncFuturesRestClientImpl; -import com.binance.api.client.impl.BinanceApiFuturesRestClientImpl; -import com.binance.api.client.impl.BinanceApiRestClientImpl; -import com.binance.api.client.impl.BinanceApiWebSocketClientImpl; +import com.binance.api.client.api.BinanceApiWebSocketClient; +import com.binance.api.client.api.async.BinanceApiAsyncFuturesRestClient; +import com.binance.api.client.api.sync.BinanceApiFuturesRestClient; +import com.binance.api.client.impl.async.BinanceApiAsyncFuturesRestClientImpl; +import com.binance.api.client.impl.sync.BinanceApiFuturesRestClientImpl; +import com.binance.api.client.impl.ws.BinanceApiWebSocketClientImpl; import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient; /** * A factory for creating BinanceApi client objects. */ -public class BinanceFuturesApiClientFactory implements BinanceFactory { +public class BinanceFuturesApiClientFactory implements BinanceFactory { /** * API Key @@ -62,19 +60,18 @@ public static BinanceFuturesApiClientFactory newInstance() { return new BinanceFuturesApiClientFactory(null, null, null, null); } - /** - * Creates a new asynchronous/non-blocking Futures REST client. + * Creates a new synchronous/blocking Futures REST client. */ - public BinanceApiAsyncFuturesRestClient newAsyncRestClient() { - return new BinanceApiAsyncFuturesRestClientImpl(apiKey, secret, apiUrl); + public BinanceApiFuturesRestClient newRestClient() { + return new BinanceApiFuturesRestClientImpl(apiKey, secret, apiUrl); } /** - * Creates a new synchronous/blocking Futures REST client. + * Creates a new asynchronous/non-blocking Futures REST client. */ - public BinanceApiRestClient newRestClient() { - return new BinanceApiRestClientImpl(apiKey, secret, apiUrl); + public BinanceApiAsyncFuturesRestClient newAsyncRestClient() { + return new BinanceApiAsyncFuturesRestClientImpl(apiKey, secret, apiUrl); } /** @@ -83,11 +80,4 @@ public BinanceApiRestClient newRestClient() { public BinanceApiWebSocketClient newWebSocketClient() { return new BinanceApiWebSocketClientImpl(getSharedClient(), websocketUrl); } - - /** - * Creates a new synchronous/blocking Futures REST client. - */ - public BinanceApiFuturesRestClient newFuturesRestClient() { - return new BinanceApiFuturesRestClientImpl(apiKey, secret, apiUrl); - } } diff --git a/src/main/java/com/binance/api/client/factory/BinanceMarginApiClientFactory.java b/src/main/java/com/binance/api/client/factory/BinanceMarginApiClientFactory.java new file mode 100755 index 000000000..37cdff3f0 --- /dev/null +++ b/src/main/java/com/binance/api/client/factory/BinanceMarginApiClientFactory.java @@ -0,0 +1,73 @@ +package com.binance.api.client.factory; + +import com.binance.api.client.api.async.BinanceApiAsyncMarginRestClient; +import com.binance.api.client.api.sync.BinanceApiMarginRestClient; +import com.binance.api.client.impl.async.BinanceApiAsyncMarginRestClientImpl; +import com.binance.api.client.impl.sync.BinanceApiMarginRestClientImpl; + +/** + * A factory for creating BinanceApi client objects. + */ +public class BinanceMarginApiClientFactory implements BinanceFactory { + + /** + * API Key + */ + private final String apiKey; + + /** + * Secret. + */ + private final String secret; + + private final String apiUrl; + private final String websocketUrl; + + /** + * Instantiates a new binance api client factory. + * + * @param apiKey the API key + * @param secret the Secret + */ + private BinanceMarginApiClientFactory(String apiKey, String secret, String apiUrl, String websocketUrl) { + this.apiKey = apiKey; + this.secret = secret; + this.apiUrl = apiUrl; + this.websocketUrl = websocketUrl; + } + + /** + * New instance. + * + * @param apiKey the API key + * @param secret the Secret + * @return the binance api client factory + */ + public static BinanceMarginApiClientFactory newInstance(String apiKey, String secret, String apiUrl, String websocketUrl) { + return new BinanceMarginApiClientFactory(apiKey, secret, apiUrl, websocketUrl); + } + + /** + * New instance without authentication. + * + * @return the binance api client factory + * @see BinanceAbstractFactory + */ + public static BinanceMarginApiClientFactory newInstance() { + return new BinanceMarginApiClientFactory(null, null, null, null); + } + + /** + * Creates a new asynchronous/non-blocking Margin REST client. + */ + public BinanceApiAsyncMarginRestClient newAsyncRestClient() { + return new BinanceApiAsyncMarginRestClientImpl(apiKey, secret, apiUrl); + } + + /** + * Creates a new synchronous/blocking Margin REST client. + */ + public BinanceApiMarginRestClient newRestClient() { + return new BinanceApiMarginRestClientImpl(apiKey, secret, apiUrl); + } +} diff --git a/src/main/java/com/binance/api/client/factory/BinanceSpotApiClientFactory.java b/src/main/java/com/binance/api/client/factory/BinanceSpotApiClientFactory.java index 483b79dd6..f7f5b5e8d 100755 --- a/src/main/java/com/binance/api/client/factory/BinanceSpotApiClientFactory.java +++ b/src/main/java/com/binance/api/client/factory/BinanceSpotApiClientFactory.java @@ -1,14 +1,18 @@ package com.binance.api.client.factory; -import com.binance.api.client.*; -import com.binance.api.client.impl.*; +import com.binance.api.client.api.BinanceApiWebSocketClient; +import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; +import com.binance.api.client.impl.async.BinanceApiSpotAsyncRestClientImpl; +import com.binance.api.client.impl.sync.BinanceApiSpotRestClientImpl; +import com.binance.api.client.impl.ws.BinanceApiWebSocketClientImpl; import static com.binance.api.client.impl.BinanceApiServiceGenerator.getSharedClient; /** * A factory for creating BinanceApi client objects. */ -public class BinanceSpotApiClientFactory implements BinanceFactory { +public class BinanceSpotApiClientFactory implements BinanceFactory { /** * API Key @@ -52,9 +56,7 @@ public static BinanceSpotApiClientFactory newInstance(String apiKey, String secr * * @return the binance api client factory * @see BinanceAbstractFactory - * @deprecated please use BinanceAbstractFactory.createSpotFactory() */ - @Deprecated public static BinanceSpotApiClientFactory newInstance() { return new BinanceSpotApiClientFactory(null, null, null, null); } @@ -62,29 +64,15 @@ public static BinanceSpotApiClientFactory newInstance() { /** * Creates a new synchronous/blocking REST client. */ - public BinanceApiRestClient newRestClient() { - return new BinanceApiRestClientImpl(apiKey, secret, apiUrl); + public BinanceApiSpotRestClient newRestClient() { + return new BinanceApiSpotRestClientImpl(apiKey, secret, apiUrl); } /** * Creates a new asynchronous/non-blocking REST client. */ - public BinanceApiAsyncRestClient newAsyncRestClient() { - return new BinanceApiAsyncRestClientImpl(apiKey, secret, apiUrl); - } - - /** - * Creates a new asynchronous/non-blocking Margin REST client. - */ - public BinanceApiAsyncMarginRestClient newAsyncMarginRestClient() { - return new BinanceApiAsyncMarginRestClientImpl(apiKey, secret, apiUrl); - } - - /** - * Creates a new synchronous/blocking Margin REST client. - */ - public BinanceApiMarginRestClient newMarginRestClient() { - return new BinanceApiMarginRestClientImpl(apiKey, secret, apiUrl); + public BinanceApiSpotAsyncRestClient newAsyncRestClient() { + return new BinanceApiSpotAsyncRestClientImpl(apiKey, secret, apiUrl); } /** @@ -93,11 +81,4 @@ public BinanceApiMarginRestClient newMarginRestClient() { public BinanceApiWebSocketClient newWebSocketClient() { return new BinanceApiWebSocketClientImpl(getSharedClient(), websocketUrl); } - - /** - * Creates a new synchronous/blocking Swap REST client. - */ - public BinanceApiSwapRestClient newSwapRestClient() { - return new BinanceApiSwapRestClientImpl(apiKey, secret, apiUrl); - } } diff --git a/src/main/java/com/binance/api/client/factory/BinanceSwapApiClientFactory.java b/src/main/java/com/binance/api/client/factory/BinanceSwapApiClientFactory.java new file mode 100755 index 000000000..68b42f4b9 --- /dev/null +++ b/src/main/java/com/binance/api/client/factory/BinanceSwapApiClientFactory.java @@ -0,0 +1,70 @@ +package com.binance.api.client.factory; + +import com.binance.api.client.api.sync.BinanceApiSwapRestClient; +import com.binance.api.client.impl.sync.BinanceApiSwapRestClientImpl; + +/** + * A factory for creating BinanceApi client objects. + */ +public class BinanceSwapApiClientFactory implements BinanceFactory { + + /** + * API Key + */ + private final String apiKey; + + /** + * Secret. + */ + private final String secret; + + private final String apiUrl; + + /** + * Instantiates a new binance api client factory. + * + * @param apiKey the API key + * @param secret the Secret + */ + private BinanceSwapApiClientFactory(String apiKey, String secret, String apiUrl) { + this.apiKey = apiKey; + this.secret = secret; + this.apiUrl = apiUrl; + } + + /** + * New instance. + * + * @param apiKey the API key + * @param secret the Secret + * @return the binance api client factory + */ + public static BinanceSwapApiClientFactory newInstance(String apiKey, String secret, String apiUrl) { + return new BinanceSwapApiClientFactory(apiKey, secret, apiUrl); + } + + /** + * New instance without authentication. + * + * @return the binance api client factory + * @see BinanceAbstractFactory + */ + public static BinanceSwapApiClientFactory newInstance() { + return new BinanceSwapApiClientFactory(null, null, null); + } + + /** + * Creates a new synchronous/blocking Swap REST client. + */ + public BinanceApiSwapRestClient newRestClient() { + return new BinanceApiSwapRestClientImpl(apiKey, secret, apiUrl); + } + + /** + * Creates a new asynchronous/non-blocking REST client. + */ + public T newAsyncRestClient() { + //FIXME: not implemented yet ... + return null; + } +} diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiCallbackAdapter.java b/src/main/java/com/binance/api/client/impl/BinanceApiCallbackAdapter.java index 355fa1348..8cd6859ca 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiCallbackAdapter.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiCallbackAdapter.java @@ -1,7 +1,7 @@ package com.binance.api.client.impl; -import com.binance.api.client.BinanceApiCallback; -import com.binance.api.client.BinanceApiError; +import com.binance.api.client.api.BinanceApiCallback; +import com.binance.api.client.api.BinanceApiError; import com.binance.api.client.exception.BinanceApiException; import retrofit2.Call; import retrofit2.Callback; 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 fd6016c3b..ffad69676 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiService.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiService.java @@ -8,7 +8,6 @@ import com.binance.api.client.domain.account.*; import com.binance.api.client.domain.account.request.CancelOrderResponse; import com.binance.api.client.domain.event.ListenKey; -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.market.*; @@ -33,11 +32,7 @@ public interface BinanceApiService { @GET("/api/v3/exchangeInfo") Call getExchangeInfo(); - @GET - Call> getAllAssets(@Url String url); - // Market data endpoints - @GET("/api/v1/depth") Call getOrderBook(@Query("symbol") String symbol, @Query("limit") Integer limit); diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiServiceGenerator.java b/src/main/java/com/binance/api/client/impl/BinanceApiServiceGenerator.java index 9d3e9ac94..58b65e1cb 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiServiceGenerator.java +++ b/src/main/java/com/binance/api/client/impl/BinanceApiServiceGenerator.java @@ -1,6 +1,6 @@ package com.binance.api.client.impl; -import com.binance.api.client.BinanceApiError; +import com.binance.api.client.api.BinanceApiError; import com.binance.api.client.exception.BinanceApiException; import com.binance.api.client.security.AuthenticationInterceptor; import okhttp3.Dispatcher; diff --git a/src/main/java/com/binance/api/client/impl/BinanceFuturesApiService.java b/src/main/java/com/binance/api/client/impl/BinanceFuturesApiService.java index 1867a0f56..a0028e883 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceFuturesApiService.java +++ b/src/main/java/com/binance/api/client/impl/BinanceFuturesApiService.java @@ -33,9 +33,6 @@ public interface BinanceFuturesApiService { @GET("/fapi/v1/exchangeInfo") Call getExchangeInfo(); - @GET - Call> getAllAssets(@Url String url); - // Market data endpoints @GET("/fapi/v1/depth") diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncFuturesRestClientImpl.java b/src/main/java/com/binance/api/client/impl/async/BinanceApiAsyncFuturesRestClientImpl.java similarity index 89% rename from src/main/java/com/binance/api/client/impl/BinanceApiAsyncFuturesRestClientImpl.java rename to src/main/java/com/binance/api/client/impl/async/BinanceApiAsyncFuturesRestClientImpl.java index 321c0167d..44699eaeb 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncFuturesRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/async/BinanceApiAsyncFuturesRestClientImpl.java @@ -1,7 +1,7 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.async; -import com.binance.api.client.BinanceApiAsyncFuturesRestClient; -import com.binance.api.client.BinanceApiCallback; +import com.binance.api.client.api.async.BinanceApiAsyncFuturesRestClient; +import com.binance.api.client.api.BinanceApiCallback; import com.binance.api.client.constant.BinanceApiConstants; import com.binance.api.client.domain.account.FuturesAccount; import com.binance.api.client.domain.account.FuturesNewOrder; @@ -11,6 +11,9 @@ import com.binance.api.client.domain.account.request.CancelOrderResponse; import com.binance.api.client.domain.account.request.OrderRequest; import com.binance.api.client.domain.account.request.OrderStatusRequest; +import com.binance.api.client.impl.BinanceApiCallbackAdapter; +import com.binance.api.client.impl.BinanceApiServiceGenerator; +import com.binance.api.client.impl.BinanceFuturesApiService; import java.util.List; diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncMarginRestClientImpl.java b/src/main/java/com/binance/api/client/impl/async/BinanceApiAsyncMarginRestClientImpl.java similarity index 90% rename from src/main/java/com/binance/api/client/impl/BinanceApiAsyncMarginRestClientImpl.java rename to src/main/java/com/binance/api/client/impl/async/BinanceApiAsyncMarginRestClientImpl.java index 3c2ed5c7f..c7030f872 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncMarginRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/async/BinanceApiAsyncMarginRestClientImpl.java @@ -1,7 +1,7 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.async; -import com.binance.api.client.BinanceApiAsyncMarginRestClient; -import com.binance.api.client.BinanceApiCallback; +import com.binance.api.client.api.async.BinanceApiAsyncMarginRestClient; +import com.binance.api.client.api.BinanceApiCallback; import com.binance.api.client.constant.BinanceApiConstants; import com.binance.api.client.domain.TransferType; import com.binance.api.client.domain.account.*; @@ -10,6 +10,9 @@ import com.binance.api.client.domain.account.request.OrderRequest; import com.binance.api.client.domain.account.request.OrderStatusRequest; import com.binance.api.client.domain.event.ListenKey; +import com.binance.api.client.impl.BinanceApiCallbackAdapter; +import com.binance.api.client.impl.BinanceApiService; +import com.binance.api.client.impl.BinanceApiServiceGenerator; import java.util.List; @@ -65,11 +68,6 @@ public void getOrderStatus(OrderStatusRequest orderStatusRequest, BinanceApiCall orderStatusRequest.getRecvWindow(), orderStatusRequest.getTimestamp()).enqueue(new BinanceApiCallbackAdapter<>(callback)); } - @Override - public void getMyTrades(String symbol, BinanceApiCallback> callback) { - binanceApiService.getMyTrades(symbol, null, null, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis()).enqueue(new BinanceApiCallbackAdapter<>(callback)); - } - // user stream endpoints @Override diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java b/src/main/java/com/binance/api/client/impl/async/BinanceApiSpotAsyncRestClientImpl.java similarity index 95% rename from src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java rename to src/main/java/com/binance/api/client/impl/async/BinanceApiSpotAsyncRestClientImpl.java index 2ae969d8b..886293ab4 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiAsyncRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/async/BinanceApiSpotAsyncRestClientImpl.java @@ -1,7 +1,7 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.async; -import com.binance.api.client.BinanceApiAsyncRestClient; -import com.binance.api.client.BinanceApiCallback; +import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient; +import com.binance.api.client.api.BinanceApiCallback; import com.binance.api.client.constant.BinanceApiConstants; import com.binance.api.client.domain.account.*; import com.binance.api.client.domain.account.request.*; @@ -9,6 +9,9 @@ import com.binance.api.client.domain.general.ExchangeInfo; import com.binance.api.client.domain.general.ServerTime; import com.binance.api.client.domain.market.*; +import com.binance.api.client.impl.BinanceApiCallbackAdapter; +import com.binance.api.client.impl.BinanceApiService; +import com.binance.api.client.impl.BinanceApiServiceGenerator; import java.util.List; @@ -16,11 +19,11 @@ /** * Implementation of Binance's REST API using Retrofit with asynchronous/non-blocking method calls. */ -public class BinanceApiAsyncRestClientImpl implements BinanceApiAsyncRestClient { +public class BinanceApiSpotAsyncRestClientImpl implements BinanceApiSpotAsyncRestClient { private final BinanceApiService binanceApiService; - public BinanceApiAsyncRestClientImpl(String apiKey, String secret, String apiUrl) { + public BinanceApiSpotAsyncRestClientImpl(String apiKey, String secret, String apiUrl) { binanceApiService = BinanceApiServiceGenerator.createService(BinanceApiService.class, apiKey, secret, apiUrl); } diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiFuturesRestClientImpl.java b/src/main/java/com/binance/api/client/impl/sync/BinanceApiFuturesRestClientImpl.java similarity index 50% rename from src/main/java/com/binance/api/client/impl/BinanceApiFuturesRestClientImpl.java rename to src/main/java/com/binance/api/client/impl/sync/BinanceApiFuturesRestClientImpl.java index 48e3f6b1e..72e140660 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiFuturesRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/sync/BinanceApiFuturesRestClientImpl.java @@ -1,15 +1,13 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.sync; -import com.binance.api.client.BinanceApiFuturesRestClient; +import com.binance.api.client.api.sync.BinanceApiFuturesRestClient; import com.binance.api.client.constant.BinanceApiConstants; -import com.binance.api.client.domain.account.FuturesAccount; -import com.binance.api.client.domain.account.FuturesNewOrder; -import com.binance.api.client.domain.account.FuturesNewOrderResponse; -import com.binance.api.client.domain.account.Order; -import com.binance.api.client.domain.account.request.CancelOrderRequest; -import com.binance.api.client.domain.account.request.CancelOrderResponse; -import com.binance.api.client.domain.account.request.OrderRequest; -import com.binance.api.client.domain.account.request.OrderStatusRequest; +import com.binance.api.client.domain.account.*; +import com.binance.api.client.domain.account.request.*; +import com.binance.api.client.domain.general.ExchangeInfo; +import com.binance.api.client.domain.market.*; +import com.binance.api.client.impl.BinanceApiServiceGenerator; +import com.binance.api.client.impl.BinanceFuturesApiService; import java.util.List; @@ -26,6 +24,21 @@ public BinanceApiFuturesRestClientImpl(String apiKey, String secret, String apiU binanceApiService = BinanceApiServiceGenerator.createService(BinanceFuturesApiService.class, apiKey, secret, apiUrl); } + @Override + public void ping() { + executeSync(binanceApiService.ping()); + } + + @Override + public Long getServerTime() { + return executeSync(binanceApiService.getServerTime()).getServerTime(); + } + + @Override + public ExchangeInfo getExchangeInfo() { + return executeSync(binanceApiService.getExchangeInfo()); + } + @Override public FuturesAccount getAccount() { long timestamp = System.currentTimeMillis(); @@ -74,4 +87,54 @@ public void keepAliveUserDataStream(String listenKey) { public void closeUserDataStream(String listenKey) { executeSync(binanceApiService.closeAliveUserDataStream(listenKey)); } + + @Override + public OrderBook getOrderBook(String symbol, Integer limit) { + return executeSync(binanceApiService.getOrderBook(symbol, limit)); + } + + @Override + public List getTrades(String symbol, Integer limit) { + return executeSync(binanceApiService.getTrades(symbol, limit)); + } + + @Override + public List getHistoricalTrades(String symbol, Integer limit, Long fromId) { + return executeSync(binanceApiService.getHistoricalTrades(symbol, limit, fromId)); + } + + @Override + public List getAggTrades(String symbol, String fromId, Integer limit, Long startTime, Long endTime) { + return executeSync(binanceApiService.getAggTrades(symbol, fromId, limit, startTime, endTime)); + } + + @Override + public List getAggTrades(String symbol) { + return executeSync(binanceApiService.getAggTrades(symbol, null, null, null, null)); + } + + @Override + public List getCandlestickBars(String symbol, CandlestickInterval interval, Integer limit, Long startTime, Long endTime) { + return executeSync(binanceApiService.getCandlestickBars(symbol, interval.getIntervalId(), limit, startTime, endTime)); + } + + @Override + public List getCandlestickBars(String symbol, CandlestickInterval interval) { + return getCandlestickBars(symbol, interval, null, null, null); + } + + @Override + public TickerStatistics get24HrPriceStatistics(String symbol) { + return executeSync(binanceApiService.get24HrPriceStatistics(symbol)); + } + + @Override + public List getAll24HrPriceStatistics() { + return executeSync(binanceApiService.getAll24HrPriceStatistics()); + } + + @Override + public TickerPrice getPrice(String symbol) { + return executeSync(binanceApiService.getLatestPrice(symbol)); + } } \ No newline at end of file diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiMarginRestClientImpl.java b/src/main/java/com/binance/api/client/impl/sync/BinanceApiMarginRestClientImpl.java similarity index 91% rename from src/main/java/com/binance/api/client/impl/BinanceApiMarginRestClientImpl.java rename to src/main/java/com/binance/api/client/impl/sync/BinanceApiMarginRestClientImpl.java index c00b51043..f2bb10d1f 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiMarginRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/sync/BinanceApiMarginRestClientImpl.java @@ -1,6 +1,6 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.sync; -import com.binance.api.client.BinanceApiMarginRestClient; +import com.binance.api.client.api.sync.BinanceApiMarginRestClient; import com.binance.api.client.constant.BinanceApiConstants; import com.binance.api.client.domain.TransferType; import com.binance.api.client.domain.account.*; @@ -8,6 +8,8 @@ import com.binance.api.client.domain.account.request.CancelOrderResponse; import com.binance.api.client.domain.account.request.OrderRequest; import com.binance.api.client.domain.account.request.OrderStatusRequest; +import com.binance.api.client.impl.BinanceApiService; +import com.binance.api.client.impl.BinanceApiServiceGenerator; import java.util.List; @@ -57,11 +59,6 @@ public Order getOrderStatus(OrderStatusRequest orderStatusRequest) { orderStatusRequest.getRecvWindow(), orderStatusRequest.getTimestamp())); } - @Override - public List getMyTrades(String symbol) { - return executeSync(binanceApiService.getMyTrades(symbol, null, null, BinanceApiConstants.DEFAULT_RECEIVING_WINDOW, System.currentTimeMillis())); - } - @Override public MarginTransaction transfer(String asset, String amount, TransferType type) { long timestamp = System.currentTimeMillis(); diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java b/src/main/java/com/binance/api/client/impl/sync/BinanceApiSpotRestClientImpl.java similarity index 95% rename from src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java rename to src/main/java/com/binance/api/client/impl/sync/BinanceApiSpotRestClientImpl.java index d91857286..bdd7fc01c 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/sync/BinanceApiSpotRestClientImpl.java @@ -1,11 +1,13 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.sync; -import com.binance.api.client.BinanceApiRestClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; 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.ExchangeInfo; import com.binance.api.client.domain.market.*; +import com.binance.api.client.impl.BinanceApiService; +import com.binance.api.client.impl.BinanceApiServiceGenerator; import retrofit2.Call; import java.util.List; @@ -16,11 +18,11 @@ * Implementation of Binance's REST API using Retrofit with synchronous/blocking * method calls. */ -public class BinanceApiRestClientImpl implements BinanceApiRestClient { +public class BinanceApiSpotRestClientImpl implements BinanceApiSpotRestClient { private final BinanceApiService binanceApiService; - public BinanceApiRestClientImpl(String apiKey, String secret, String apiUrl) { + public BinanceApiSpotRestClientImpl(String apiKey, String secret, String apiUrl) { binanceApiService = BinanceApiServiceGenerator.createService(BinanceApiService.class, apiKey, secret, apiUrl); } diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiSwapRestClientImpl.java b/src/main/java/com/binance/api/client/impl/sync/BinanceApiSwapRestClientImpl.java similarity index 92% rename from src/main/java/com/binance/api/client/impl/BinanceApiSwapRestClientImpl.java rename to src/main/java/com/binance/api/client/impl/sync/BinanceApiSwapRestClientImpl.java index 71d1e050f..53daaf1dc 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiSwapRestClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/sync/BinanceApiSwapRestClientImpl.java @@ -1,9 +1,11 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.sync; -import com.binance.api.client.BinanceApiSwapRestClient; +import com.binance.api.client.api.sync.BinanceApiSwapRestClient; import com.binance.api.client.constant.BinanceApiConstants; import com.binance.api.client.domain.SwapRemoveType; import com.binance.api.client.domain.account.*; +import com.binance.api.client.impl.BinanceApiService; +import com.binance.api.client.impl.BinanceApiServiceGenerator; import java.util.List; diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketClientImpl.java b/src/main/java/com/binance/api/client/impl/ws/BinanceApiWebSocketClientImpl.java similarity index 96% rename from src/main/java/com/binance/api/client/impl/BinanceApiWebSocketClientImpl.java rename to src/main/java/com/binance/api/client/impl/ws/BinanceApiWebSocketClientImpl.java index 056bd251a..6581e0f32 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketClientImpl.java +++ b/src/main/java/com/binance/api/client/impl/ws/BinanceApiWebSocketClientImpl.java @@ -1,7 +1,7 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.ws; -import com.binance.api.client.BinanceApiCallback; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.BinanceApiCallback; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.event.*; import com.binance.api.client.domain.market.CandlestickInterval; import com.fasterxml.jackson.core.type.TypeReference; diff --git a/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketListener.java b/src/main/java/com/binance/api/client/impl/ws/BinanceApiWebSocketListener.java similarity index 91% rename from src/main/java/com/binance/api/client/impl/BinanceApiWebSocketListener.java rename to src/main/java/com/binance/api/client/impl/ws/BinanceApiWebSocketListener.java index e2004090e..0278e59b6 100755 --- a/src/main/java/com/binance/api/client/impl/BinanceApiWebSocketListener.java +++ b/src/main/java/com/binance/api/client/impl/ws/BinanceApiWebSocketListener.java @@ -1,6 +1,6 @@ -package com.binance.api.client.impl; +package com.binance.api.client.impl.ws; -import com.binance.api.client.BinanceApiCallback; +import com.binance.api.client.api.BinanceApiCallback; import com.binance.api.client.exception.BinanceApiException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/src/test/java/com/binance/api/examples/AccountBalanceCacheExample.java b/src/test/java/com/binance/api/examples/AccountBalanceCacheExample.java index e0d8ede45..3e267cf77 100755 --- a/src/test/java/com/binance/api/examples/AccountBalanceCacheExample.java +++ b/src/test/java/com/binance/api/examples/AccountBalanceCacheExample.java @@ -1,7 +1,7 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.account.Account; import com.binance.api.client.domain.account.AssetBalance; import com.binance.api.client.factory.BinanceAbstractFactory; @@ -42,7 +42,7 @@ public AccountBalanceCacheExample(String apiKey, String secret) { * @return a listenKey that can be used with the user data streaming API. */ private String initializeAssetBalanceCacheAndStreamSession() { - BinanceApiRestClient client = clientFactory.newRestClient(); + BinanceApiSpotRestClient client = clientFactory.newRestClient(); Account account = client.getAccount(); this.accountBalanceCache = new TreeMap<>(); diff --git a/src/test/java/com/binance/api/examples/AccountEndpointsExample.java b/src/test/java/com/binance/api/examples/AccountEndpointsExample.java index 7e82db9a2..b9f42c9f5 100755 --- a/src/test/java/com/binance/api/examples/AccountEndpointsExample.java +++ b/src/test/java/com/binance/api/examples/AccountEndpointsExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; import com.binance.api.client.domain.account.Account; import com.binance.api.client.domain.account.Trade; import com.binance.api.client.factory.BinanceAbstractFactory; @@ -15,7 +15,7 @@ public class AccountEndpointsExample { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); // Get account balances Account account = client.getAccount(60_000L, System.currentTimeMillis()); diff --git a/src/test/java/com/binance/api/examples/AccountEndpointsExampleAsync.java b/src/test/java/com/binance/api/examples/AccountEndpointsExampleAsync.java index 65d6a6ffa..c79fe0de5 100755 --- a/src/test/java/com/binance/api/examples/AccountEndpointsExampleAsync.java +++ b/src/test/java/com/binance/api/examples/AccountEndpointsExampleAsync.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiAsyncRestClient; +import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient; import com.binance.api.client.domain.account.Account; import com.binance.api.client.factory.BinanceAbstractFactory; import com.binance.api.client.factory.BinanceSpotApiClientFactory; @@ -12,7 +12,7 @@ public class AccountEndpointsExampleAsync { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiAsyncRestClient client = factory.newAsyncRestClient(); + BinanceApiSpotAsyncRestClient client = factory.newAsyncRestClient(); // Get account balances (async) client.getAccount((Account response) -> System.out.println(response.getAssetBalance("ETH"))); diff --git a/src/test/java/com/binance/api/examples/AggTradesCacheExample.java b/src/test/java/com/binance/api/examples/AggTradesCacheExample.java index 90fea3bf5..07c27851c 100755 --- a/src/test/java/com/binance/api/examples/AggTradesCacheExample.java +++ b/src/test/java/com/binance/api/examples/AggTradesCacheExample.java @@ -1,7 +1,7 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.market.AggTrade; import com.binance.api.client.factory.BinanceSpotApiClientFactory; @@ -30,7 +30,7 @@ public AggTradesCacheExample(String symbol) { */ private void initializeAggTradesCache(String symbol) { BinanceSpotApiClientFactory factory = BinanceSpotApiClientFactory.newInstance(); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); List aggTrades = client.getAggTrades(symbol.toUpperCase()); this.aggTradesCache = new HashMap<>(); diff --git a/src/test/java/com/binance/api/examples/AllMarketTickersExample.java b/src/test/java/com/binance/api/examples/AllMarketTickersExample.java index 8afc52005..4fa051fc3 100755 --- a/src/test/java/com/binance/api/examples/AllMarketTickersExample.java +++ b/src/test/java/com/binance/api/examples/AllMarketTickersExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.factory.BinanceSpotApiClientFactory; /** diff --git a/src/test/java/com/binance/api/examples/CandlesticksCacheExample.java b/src/test/java/com/binance/api/examples/CandlesticksCacheExample.java index 0e18faa1c..772b5428b 100755 --- a/src/test/java/com/binance/api/examples/CandlesticksCacheExample.java +++ b/src/test/java/com/binance/api/examples/CandlesticksCacheExample.java @@ -1,7 +1,7 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.market.Candlestick; import com.binance.api.client.domain.market.CandlestickInterval; import com.binance.api.client.factory.BinanceSpotApiClientFactory; @@ -30,7 +30,7 @@ public CandlesticksCacheExample(String symbol, CandlestickInterval interval) { */ private void initializeCandlestickCache(String symbol, CandlestickInterval interval) { BinanceSpotApiClientFactory factory = BinanceSpotApiClientFactory.newInstance(); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); List candlestickBars = client.getCandlestickBars(symbol.toUpperCase(), interval); this.candlesticksCache = new TreeMap<>(); diff --git a/src/test/java/com/binance/api/examples/DepthCacheExample.java b/src/test/java/com/binance/api/examples/DepthCacheExample.java index 2bc4460e4..61d0e0e8f 100755 --- a/src/test/java/com/binance/api/examples/DepthCacheExample.java +++ b/src/test/java/com/binance/api/examples/DepthCacheExample.java @@ -1,8 +1,8 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiCallback; -import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.BinanceApiCallback; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.event.DepthEvent; import com.binance.api.client.domain.market.OrderBook; import com.binance.api.client.domain.market.OrderBookEntry; @@ -40,7 +40,7 @@ public class DepthCacheExample { private static final String ASKS = "ASKS"; private final String symbol; - private final BinanceApiRestClient restClient; + private final BinanceApiSpotRestClient restClient; private final BinanceApiWebSocketClient wsClient; private final WsCallback wsCallback = new WsCallback(); private final Map> depthCache = new HashMap<>(); diff --git a/src/test/java/com/binance/api/examples/GeneralEndpointsExample.java b/src/test/java/com/binance/api/examples/GeneralEndpointsExample.java index 757c4d283..f696381e8 100755 --- a/src/test/java/com/binance/api/examples/GeneralEndpointsExample.java +++ b/src/test/java/com/binance/api/examples/GeneralEndpointsExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; import com.binance.api.client.domain.general.ExchangeInfo; import com.binance.api.client.domain.general.FilterType; import com.binance.api.client.domain.general.SymbolFilter; @@ -14,7 +14,7 @@ public class GeneralEndpointsExample { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceSpotApiClientFactory.newInstance(); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); // Test connectivity client.ping(); diff --git a/src/test/java/com/binance/api/examples/GeneralEndpointsExampleAsync.java b/src/test/java/com/binance/api/examples/GeneralEndpointsExampleAsync.java index 38d86f1e6..6cc60311e 100755 --- a/src/test/java/com/binance/api/examples/GeneralEndpointsExampleAsync.java +++ b/src/test/java/com/binance/api/examples/GeneralEndpointsExampleAsync.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiAsyncRestClient; +import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient; import com.binance.api.client.domain.general.FilterType; import com.binance.api.client.domain.general.SymbolFilter; import com.binance.api.client.domain.general.SymbolInfo; @@ -13,7 +13,7 @@ public class GeneralEndpointsExampleAsync { public static void main(String[] args) throws InterruptedException { BinanceSpotApiClientFactory factory = BinanceSpotApiClientFactory.newInstance(); - BinanceApiAsyncRestClient client = factory.newAsyncRestClient(); + BinanceApiSpotAsyncRestClient client = factory.newAsyncRestClient(); // Test connectivity client.ping(response -> System.out.println("Ping succeeded.")); diff --git a/src/test/java/com/binance/api/examples/MarginAccountEndpointsExample.java b/src/test/java/com/binance/api/examples/MarginAccountEndpointsExample.java index b1476b871..e296f726b 100755 --- a/src/test/java/com/binance/api/examples/MarginAccountEndpointsExample.java +++ b/src/test/java/com/binance/api/examples/MarginAccountEndpointsExample.java @@ -1,11 +1,13 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiMarginRestClient; +import com.binance.api.client.api.sync.BinanceApiMarginRestClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; import com.binance.api.client.domain.TransferType; import com.binance.api.client.domain.account.MarginAccount; import com.binance.api.client.domain.account.MarginTransaction; import com.binance.api.client.domain.account.Trade; import com.binance.api.client.factory.BinanceAbstractFactory; +import com.binance.api.client.factory.BinanceMarginApiClientFactory; import com.binance.api.client.factory.BinanceSpotApiClientFactory; import java.util.List; @@ -16,27 +18,29 @@ public class MarginAccountEndpointsExample { public static void main(String[] args) { - BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiMarginRestClient client = factory.newMarginRestClient(); + BinanceMarginApiClientFactory marginFactory = BinanceAbstractFactory.createMarginFactory("YOUR_API_KEY", "YOUR_SECRET"); + BinanceSpotApiClientFactory spotFactory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); + BinanceApiMarginRestClient marginClient = marginFactory.newRestClient(); + BinanceApiSpotRestClient spotClient = spotFactory.newRestClient(); // Get account balances - MarginAccount marginAccount = client.getAccount(); + MarginAccount marginAccount = marginClient.getAccount(); System.out.println(marginAccount.getUserAssets()); System.out.println(marginAccount.getAssetBalance("ETH")); System.out.println(marginAccount.getMarginLevel()); // Get list of trades - List myTrades = client.getMyTrades("NEOETH"); + List myTrades = spotClient.getMyTrades("NEOETH"); System.out.println(myTrades); // Transfer, borrow, repay - MarginTransaction spotToMargin = client.transfer("USDT", "1", TransferType.SPOT_TO_MARGIN); + MarginTransaction spotToMargin = marginClient.transfer("USDT", "1", TransferType.SPOT_TO_MARGIN); System.out.println(spotToMargin.getTranId()); - MarginTransaction borrowed = client.borrow("USDT", "1"); + MarginTransaction borrowed = marginClient.borrow("USDT", "1"); System.out.println(borrowed.getTranId()); - MarginTransaction repayed = client.repay("USDT", "1"); + MarginTransaction repayed = marginClient.repay("USDT", "1"); System.out.println(repayed.getTranId()); - MarginTransaction marginToSpot = client.transfer("USDT", "1", TransferType.MARGIN_TO_SPOT); + MarginTransaction marginToSpot = marginClient.transfer("USDT", "1", TransferType.MARGIN_TO_SPOT); System.out.println(marginToSpot.getTranId()); } } diff --git a/src/test/java/com/binance/api/examples/MarginAccountEndpointsExampleAsync.java b/src/test/java/com/binance/api/examples/MarginAccountEndpointsExampleAsync.java index 5d342b31b..bbd72e4bc 100755 --- a/src/test/java/com/binance/api/examples/MarginAccountEndpointsExampleAsync.java +++ b/src/test/java/com/binance/api/examples/MarginAccountEndpointsExampleAsync.java @@ -1,8 +1,10 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiAsyncMarginRestClient; +import com.binance.api.client.api.async.BinanceApiAsyncMarginRestClient; +import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient; import com.binance.api.client.domain.TransferType; import com.binance.api.client.factory.BinanceAbstractFactory; +import com.binance.api.client.factory.BinanceMarginApiClientFactory; import com.binance.api.client.factory.BinanceSpotApiClientFactory; /** @@ -11,23 +13,25 @@ public class MarginAccountEndpointsExampleAsync { public static void main(String[] args) { - BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiAsyncMarginRestClient client = factory.newAsyncMarginRestClient(); + BinanceMarginApiClientFactory marginFactory = BinanceAbstractFactory.createMarginFactory("YOUR_API_KEY", "YOUR_SECRET"); + BinanceSpotApiClientFactory spotFactory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); + BinanceApiAsyncMarginRestClient marginClient = marginFactory.newAsyncRestClient(); + BinanceApiSpotAsyncRestClient spotClient = spotFactory.newAsyncRestClient(); // Get account balances - client.getAccount(marginAccount -> { + marginClient.getAccount(marginAccount -> { System.out.println(marginAccount.getUserAssets()); System.out.println(marginAccount.getAssetBalance("ETH")); System.out.println(marginAccount.getMarginLevel()); }); // Get list of trades - client.getMyTrades("NEOETH", System.out::println); + spotClient.getMyTrades("NEOETH", System.out::println); // Transfer, borrow, repay - client.transfer("USDT", "1", TransferType.SPOT_TO_MARGIN, transaction -> System.out.println(transaction.getTranId())); - client.borrow("USDT", "1", transaction -> System.out.println(transaction.getTranId())); - client.repay("USDT", "1", transaction -> System.out.println(transaction.getTranId())); - client.transfer("USDT", "1", TransferType.MARGIN_TO_SPOT, transaction -> System.out.println(transaction.getTranId())); + marginClient.transfer("USDT", "1", TransferType.SPOT_TO_MARGIN, transaction -> System.out.println(transaction.getTranId())); + marginClient.borrow("USDT", "1", transaction -> System.out.println(transaction.getTranId())); + marginClient.repay("USDT", "1", transaction -> System.out.println(transaction.getTranId())); + marginClient.transfer("USDT", "1", TransferType.MARGIN_TO_SPOT, transaction -> System.out.println(transaction.getTranId())); } } diff --git a/src/test/java/com/binance/api/examples/MarginAccountEndpointsLoanQueryExample.java b/src/test/java/com/binance/api/examples/MarginAccountEndpointsLoanQueryExample.java index 967328a79..90d2385b3 100755 --- a/src/test/java/com/binance/api/examples/MarginAccountEndpointsLoanQueryExample.java +++ b/src/test/java/com/binance/api/examples/MarginAccountEndpointsLoanQueryExample.java @@ -1,11 +1,11 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiMarginRestClient; +import com.binance.api.client.api.sync.BinanceApiMarginRestClient; import com.binance.api.client.domain.account.MarginTransaction; import com.binance.api.client.domain.account.MaxBorrowableQueryResult; import com.binance.api.client.domain.account.RepayQueryResult; import com.binance.api.client.factory.BinanceAbstractFactory; -import com.binance.api.client.factory.BinanceSpotApiClientFactory; +import com.binance.api.client.factory.BinanceMarginApiClientFactory; /** * Examples on how to get margin account information. @@ -13,8 +13,8 @@ public class MarginAccountEndpointsLoanQueryExample { public static void main(String[] args) { - BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiMarginRestClient client = factory.newMarginRestClient(); + BinanceMarginApiClientFactory factory = BinanceAbstractFactory.createMarginFactory("YOUR_API_KEY", "YOUR_SECRET"); + BinanceApiMarginRestClient client = factory.newRestClient(); MaxBorrowableQueryResult usdt = client.queryMaxBorrowable("USDT"); System.out.println(usdt.getAmount()); MaxBorrowableQueryResult bnb = client.queryMaxBorrowable("BNB"); diff --git a/src/test/java/com/binance/api/examples/MarginOrdersExample.java b/src/test/java/com/binance/api/examples/MarginOrdersExample.java index 59780a64e..f94e523bb 100755 --- a/src/test/java/com/binance/api/examples/MarginOrdersExample.java +++ b/src/test/java/com/binance/api/examples/MarginOrdersExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiMarginRestClient; +import com.binance.api.client.api.sync.BinanceApiMarginRestClient; import com.binance.api.client.domain.TimeInForce; import com.binance.api.client.domain.account.MarginNewOrderResponse; import com.binance.api.client.domain.account.NewOrderResponseType; @@ -11,7 +11,7 @@ import com.binance.api.client.domain.account.request.OrderStatusRequest; import com.binance.api.client.exception.BinanceApiException; import com.binance.api.client.factory.BinanceAbstractFactory; -import com.binance.api.client.factory.BinanceSpotApiClientFactory; +import com.binance.api.client.factory.BinanceMarginApiClientFactory; import java.util.List; @@ -23,8 +23,8 @@ public class MarginOrdersExample { public static void main(String[] args) { - BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiMarginRestClient client = factory.newMarginRestClient(); + BinanceMarginApiClientFactory factory = BinanceAbstractFactory.createMarginFactory("YOUR_API_KEY", "YOUR_SECRET"); + BinanceApiMarginRestClient client = factory.newRestClient(); // Getting list of open orders List openOrders = client.getOpenOrders(new OrderRequest("LINKETH")); diff --git a/src/test/java/com/binance/api/examples/MarginOrdersExampleAsync.java b/src/test/java/com/binance/api/examples/MarginOrdersExampleAsync.java index e9a61ab9a..a3ff13666 100755 --- a/src/test/java/com/binance/api/examples/MarginOrdersExampleAsync.java +++ b/src/test/java/com/binance/api/examples/MarginOrdersExampleAsync.java @@ -1,12 +1,12 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiAsyncMarginRestClient; +import com.binance.api.client.api.async.BinanceApiAsyncMarginRestClient; import com.binance.api.client.domain.TimeInForce; import com.binance.api.client.domain.account.request.CancelOrderRequest; import com.binance.api.client.domain.account.request.OrderRequest; import com.binance.api.client.domain.account.request.OrderStatusRequest; import com.binance.api.client.factory.BinanceAbstractFactory; -import com.binance.api.client.factory.BinanceSpotApiClientFactory; +import com.binance.api.client.factory.BinanceMarginApiClientFactory; import static com.binance.api.client.domain.account.MarginNewOrder.limitBuy; @@ -16,8 +16,8 @@ public class MarginOrdersExampleAsync { public static void main(String[] args) { - BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiAsyncMarginRestClient client = factory.newAsyncMarginRestClient(); + BinanceMarginApiClientFactory factory = BinanceAbstractFactory.createMarginFactory("YOUR_API_KEY", "YOUR_SECRET"); + BinanceApiAsyncMarginRestClient client = factory.newAsyncRestClient(); // Getting list of open orders client.getOpenOrders(new OrderRequest("LINKETH"), System.out::println); diff --git a/src/test/java/com/binance/api/examples/MarginUserDataStreamExample.java b/src/test/java/com/binance/api/examples/MarginUserDataStreamExample.java index 120cb0d81..17718af44 100755 --- a/src/test/java/com/binance/api/examples/MarginUserDataStreamExample.java +++ b/src/test/java/com/binance/api/examples/MarginUserDataStreamExample.java @@ -1,7 +1,7 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.event.AccountUpdateEvent; import com.binance.api.client.domain.event.OrderTradeUpdateEvent; import com.binance.api.client.domain.event.UserDataUpdateEvent.UserDataUpdateEventType; @@ -20,7 +20,7 @@ public class MarginUserDataStreamExample { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory(API_KEY, SECRET_KEY); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); // First, we obtain a listenKey which is required to interact with the user data stream String listenKey = client.startUserDataStream(); diff --git a/src/test/java/com/binance/api/examples/MarketDataEndpointsExample.java b/src/test/java/com/binance/api/examples/MarketDataEndpointsExample.java index 8893a42e1..e7456b255 100755 --- a/src/test/java/com/binance/api/examples/MarketDataEndpointsExample.java +++ b/src/test/java/com/binance/api/examples/MarketDataEndpointsExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; import com.binance.api.client.domain.market.*; import com.binance.api.client.exception.BinanceApiException; import com.binance.api.client.factory.BinanceSpotApiClientFactory; @@ -14,7 +14,7 @@ public class MarketDataEndpointsExample { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceSpotApiClientFactory.newInstance(); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); // Getting depth of a symbol OrderBook orderBook = client.getOrderBook("NEOETH", 10); diff --git a/src/test/java/com/binance/api/examples/MarketDataEndpointsExampleAsync.java b/src/test/java/com/binance/api/examples/MarketDataEndpointsExampleAsync.java index 2888ac2ae..bd5176bc7 100755 --- a/src/test/java/com/binance/api/examples/MarketDataEndpointsExampleAsync.java +++ b/src/test/java/com/binance/api/examples/MarketDataEndpointsExampleAsync.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiAsyncRestClient; +import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient; import com.binance.api.client.domain.market.CandlestickInterval; import com.binance.api.client.domain.market.OrderBook; import com.binance.api.client.exception.BinanceApiException; @@ -13,7 +13,7 @@ public class MarketDataEndpointsExampleAsync { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceSpotApiClientFactory.newInstance(); - BinanceApiAsyncRestClient client = factory.newAsyncRestClient(); + BinanceApiSpotAsyncRestClient client = factory.newAsyncRestClient(); // Getting depth of a symbol (async) client.getOrderBook("NEOETH", 10, (OrderBook response) -> { diff --git a/src/test/java/com/binance/api/examples/MarketDataStreamExample.java b/src/test/java/com/binance/api/examples/MarketDataStreamExample.java index fef44d045..441b3c2b5 100755 --- a/src/test/java/com/binance/api/examples/MarketDataStreamExample.java +++ b/src/test/java/com/binance/api/examples/MarketDataStreamExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.market.CandlestickInterval; import com.binance.api.client.factory.BinanceSpotApiClientFactory; diff --git a/src/test/java/com/binance/api/examples/OrdersExample.java b/src/test/java/com/binance/api/examples/OrdersExample.java index 7249cc2af..52bf7e1aa 100755 --- a/src/test/java/com/binance/api/examples/OrdersExample.java +++ b/src/test/java/com/binance/api/examples/OrdersExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; import com.binance.api.client.domain.TimeInForce; import com.binance.api.client.domain.account.NewOrderResponse; import com.binance.api.client.domain.account.NewOrderResponseType; @@ -24,7 +24,7 @@ public class OrdersExample { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("MWzDJFwWf4jaCkqEv6NFYZyv2fDhdY3c1FMNN0E639wAlKvvD6oH2QxMlg5Be8jP", "ioIv2eCzPCtKeD6DcN5YYHiOA2X6Wn5Ao5kPbQ184wPZkn9Z7bv2F1apafh2f3Mm"); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); // Getting list of open orders List openOrders = client.getOpenOrders(new OrderRequest(SYMBOL)); diff --git a/src/test/java/com/binance/api/examples/OrdersExampleAsync.java b/src/test/java/com/binance/api/examples/OrdersExampleAsync.java index 1b4728b7d..208a613b8 100755 --- a/src/test/java/com/binance/api/examples/OrdersExampleAsync.java +++ b/src/test/java/com/binance/api/examples/OrdersExampleAsync.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiAsyncRestClient; +import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient; import com.binance.api.client.domain.TimeInForce; import com.binance.api.client.domain.account.request.AllOrdersRequest; import com.binance.api.client.domain.account.request.CancelOrderRequest; @@ -19,7 +19,7 @@ public class OrdersExampleAsync { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiAsyncRestClient client = factory.newAsyncRestClient(); + BinanceApiSpotAsyncRestClient client = factory.newAsyncRestClient(); // Getting list of open orders client.getOpenOrders(new OrderRequest("LINKETH"), System.out::println); diff --git a/src/test/java/com/binance/api/examples/SwapEndpointExample.java b/src/test/java/com/binance/api/examples/SwapEndpointExample.java index b789777fe..eb4bd625d 100755 --- a/src/test/java/com/binance/api/examples/SwapEndpointExample.java +++ b/src/test/java/com/binance/api/examples/SwapEndpointExample.java @@ -1,17 +1,18 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiSwapRestClient; +import com.binance.api.client.api.sync.BinanceApiSwapRestClient; import com.binance.api.client.domain.account.*; import com.binance.api.client.factory.BinanceAbstractFactory; -import com.binance.api.client.factory.BinanceSpotApiClientFactory; +import com.binance.api.client.factory.BinanceSwapApiClientFactory; import java.util.List; public class SwapEndpointExample { public static void main(String[] args) { - BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiSwapRestClient swapClient = factory.newSwapRestClient(); +// BinanceSwapApiClientFactory factory = (BinanceSwapApiClientFactory) BinanceAbstractFactory.createFactory("YOUR_API_KEY", "YOUR_SECRET", BinanceEngineType.SWAP); + BinanceSwapApiClientFactory factory = BinanceAbstractFactory.createSwapFactory("YOUR_API_KEY", "YOUR_SECRET"); + BinanceApiSwapRestClient swapClient = factory.newRestClient(); List pools = swapClient.listAllSwapPools(); for (Pool pool : pools) { System.out.println(pool); diff --git a/src/test/java/com/binance/api/examples/TotalAccountBalanceExample.java b/src/test/java/com/binance/api/examples/TotalAccountBalanceExample.java index b82cc7391..5ac55a7dd 100755 --- a/src/test/java/com/binance/api/examples/TotalAccountBalanceExample.java +++ b/src/test/java/com/binance/api/examples/TotalAccountBalanceExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; import com.binance.api.client.constant.Util; import com.binance.api.client.domain.account.Account; import com.binance.api.client.domain.account.AssetBalance; @@ -15,7 +15,7 @@ public class TotalAccountBalanceExample { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); // Get account balances Account account = client.getAccount(60_000L, System.currentTimeMillis()); @@ -32,7 +32,7 @@ public static void main(String[] args) { } // Get total account balance in BTC (spot only) - public double getTotalAccountBalance(BinanceApiRestClient client, Account account) { + public double getTotalAccountBalance(BinanceApiSpotRestClient client, Account account) { double totalBalance = 0; for (AssetBalance balance : account.getBalances()) { double free = Double.parseDouble(balance.getFree()); diff --git a/src/test/java/com/binance/api/examples/UserDataStreamExample.java b/src/test/java/com/binance/api/examples/UserDataStreamExample.java index d8dc3c5e0..abbcc4131 100755 --- a/src/test/java/com/binance/api/examples/UserDataStreamExample.java +++ b/src/test/java/com/binance/api/examples/UserDataStreamExample.java @@ -1,7 +1,7 @@ package com.binance.api.examples; -import com.binance.api.client.BinanceApiRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.sync.BinanceApiSpotRestClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.event.AccountUpdateEvent; import com.binance.api.client.domain.event.OrderTradeUpdateEvent; import com.binance.api.client.domain.event.UserDataUpdateEvent.UserDataUpdateEventType; @@ -18,7 +18,7 @@ public class UserDataStreamExample { public static void main(String[] args) { BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET"); - BinanceApiRestClient client = factory.newRestClient(); + BinanceApiSpotRestClient client = factory.newRestClient(); // First, we obtain a listenKey which is required to interact with the user data stream String listenKey = client.startUserDataStream(); diff --git a/src/test/java/com/binance/api/examples/futures/FuturesAccountExample.java b/src/test/java/com/binance/api/examples/futures/FuturesAccountExample.java index fc9c514e1..4fc193d71 100755 --- a/src/test/java/com/binance/api/examples/futures/FuturesAccountExample.java +++ b/src/test/java/com/binance/api/examples/futures/FuturesAccountExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples.futures; -import com.binance.api.client.BinanceApiFuturesRestClient; +import com.binance.api.client.api.sync.BinanceApiFuturesRestClient; import com.binance.api.client.domain.account.FuturesAccount; import com.binance.api.client.factory.BinanceAbstractFactory; import com.binance.api.client.factory.BinanceFuturesApiClientFactory; @@ -15,7 +15,7 @@ public class FuturesAccountExample { public static void main(String[] args) { BinanceFuturesApiClientFactory factory = BinanceAbstractFactory.createFuturesFactory(API_KEY, SECRET_KEY); - BinanceApiFuturesRestClient client = factory.newFuturesRestClient(); + BinanceApiFuturesRestClient client = factory.newRestClient(); FuturesAccount account = client.getAccount(); System.out.println("Available Balance: " + account.getAvailableBalance()); diff --git a/src/test/java/com/binance/api/examples/futures/FuturesOrdersAsyncExample.java b/src/test/java/com/binance/api/examples/futures/FuturesOrdersAsyncExample.java index b48c57bd2..370515eb7 100755 --- a/src/test/java/com/binance/api/examples/futures/FuturesOrdersAsyncExample.java +++ b/src/test/java/com/binance/api/examples/futures/FuturesOrdersAsyncExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples.futures; -import com.binance.api.client.BinanceApiAsyncFuturesRestClient; +import com.binance.api.client.api.async.BinanceApiAsyncFuturesRestClient; import com.binance.api.client.domain.account.request.OrderRequest; import com.binance.api.client.factory.BinanceAbstractFactory; import com.binance.api.client.factory.BinanceFuturesApiClientFactory; diff --git a/src/test/java/com/binance/api/examples/futures/FuturesOrdersExample.java b/src/test/java/com/binance/api/examples/futures/FuturesOrdersExample.java index 6a9775c2a..584942cee 100755 --- a/src/test/java/com/binance/api/examples/futures/FuturesOrdersExample.java +++ b/src/test/java/com/binance/api/examples/futures/FuturesOrdersExample.java @@ -1,8 +1,7 @@ package com.binance.api.examples.futures; -import com.binance.api.client.BinanceApiFuturesRestClient; +import com.binance.api.client.api.sync.BinanceApiFuturesRestClient; import com.binance.api.client.domain.TimeInForce; -import com.binance.api.client.domain.WorkingType; import com.binance.api.client.domain.account.FuturesNewOrderResponse; import com.binance.api.client.domain.account.request.CancelOrderRequest; import com.binance.api.client.domain.account.request.CancelOrderResponse; @@ -23,9 +22,9 @@ public class FuturesOrdersExample { public static void main(String[] args) { BinanceFuturesApiClientFactory futuresApiClientFactory = BinanceAbstractFactory.createFuturesFactory(API_KEY, SECRET_KEY); - BinanceApiFuturesRestClient client = futuresApiClientFactory.newFuturesRestClient(); + BinanceApiFuturesRestClient client = futuresApiClientFactory.newRestClient(); - FuturesNewOrderResponse futuresOrderResponse = client.newOrder(limitLong(SYMBOL, TimeInForce.GTC, WorkingType.CONTRACT_PRICE, "13", "27", false)); + FuturesNewOrderResponse futuresOrderResponse = client.newOrder(limitLong(SYMBOL, TimeInForce.GTC, "13", "27", false)); long orderId = futuresOrderResponse.getOrderId(); System.out.println("OrderID: " + orderId); diff --git a/src/test/java/com/binance/api/examples/futures/FuturesUserDataStreamExample.java b/src/test/java/com/binance/api/examples/futures/FuturesUserDataStreamExample.java index 37cce47c4..24d292d53 100755 --- a/src/test/java/com/binance/api/examples/futures/FuturesUserDataStreamExample.java +++ b/src/test/java/com/binance/api/examples/futures/FuturesUserDataStreamExample.java @@ -1,7 +1,7 @@ package com.binance.api.examples.futures; -import com.binance.api.client.BinanceApiFuturesRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.sync.BinanceApiFuturesRestClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.event.AccountUpdateEvent; import com.binance.api.client.domain.event.OrderTradeUpdateEvent; import com.binance.api.client.domain.event.UserDataUpdateEvent.UserDataUpdateEventType; @@ -20,7 +20,7 @@ public class FuturesUserDataStreamExample { public static void main(String[] args) { BinanceFuturesApiClientFactory factory = BinanceAbstractFactory.createFuturesFactory(API_KEY, SECRET_KEY); - BinanceApiFuturesRestClient client = factory.newFuturesRestClient(); + BinanceApiFuturesRestClient client = factory.newRestClient(); // First, we obtain a listenKey which is required to interact with the user data stream String listenKey = client.startUserDataStream(); diff --git a/src/test/java/com/binance/api/examples/futures/FuturesWebSocketExample.java b/src/test/java/com/binance/api/examples/futures/FuturesWebSocketExample.java index 6ce47c016..a7a85ed15 100755 --- a/src/test/java/com/binance/api/examples/futures/FuturesWebSocketExample.java +++ b/src/test/java/com/binance/api/examples/futures/FuturesWebSocketExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples.futures; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.market.CandlestickInterval; import com.binance.api.client.factory.BinanceAbstractFactory; import com.binance.api.client.factory.BinanceFuturesApiClientFactory; diff --git a/src/test/java/com/binance/api/examples/testnet/TestnetAccountExample.java b/src/test/java/com/binance/api/examples/testnet/TestnetAccountExample.java index 6b1cdd9e1..0c1ef8b9d 100755 --- a/src/test/java/com/binance/api/examples/testnet/TestnetAccountExample.java +++ b/src/test/java/com/binance/api/examples/testnet/TestnetAccountExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples.testnet; -import com.binance.api.client.BinanceApiFuturesRestClient; +import com.binance.api.client.api.sync.BinanceApiFuturesRestClient; import com.binance.api.client.domain.account.FuturesAccount; import com.binance.api.client.factory.BinanceAbstractFactory; import com.binance.api.client.factory.BinanceFuturesApiClientFactory; @@ -14,7 +14,7 @@ public class TestnetAccountExample { public static void main(String[] args) { BinanceFuturesApiClientFactory factory = BinanceAbstractFactory.createTestnetFactory(API_KEY, SECRET_KEY); - BinanceApiFuturesRestClient client = factory.newFuturesRestClient(); + BinanceApiFuturesRestClient client = factory.newRestClient(); FuturesAccount account = client.getAccount(); System.out.println("Available Balance: " + account.getAvailableBalance()); diff --git a/src/test/java/com/binance/api/examples/testnet/TestnetGeneralExample.java b/src/test/java/com/binance/api/examples/testnet/TestnetGeneralExample.java new file mode 100755 index 000000000..125e44902 --- /dev/null +++ b/src/test/java/com/binance/api/examples/testnet/TestnetGeneralExample.java @@ -0,0 +1,47 @@ +package com.binance.api.examples.testnet; + +import com.binance.api.client.api.sync.BinanceApiFuturesRestClient; +import com.binance.api.client.domain.market.CandlestickInterval; +import com.binance.api.client.factory.BinanceAbstractFactory; +import com.binance.api.client.factory.BinanceFuturesApiClientFactory; + +/** + * Examples on how to place orders, cancel them. + * + * @author Mahdi Sheikh Hosseini + */ +public class TestnetGeneralExample { + private static final String SYMBOL = "BTCUSDT"; + private static final String API_KEY = ""; + private static final String SECRET_KEY = ""; + + + public static void main(String[] args) throws InterruptedException { + BinanceFuturesApiClientFactory testnetFactory = BinanceAbstractFactory.createTestnetFactory(API_KEY, SECRET_KEY); + BinanceApiFuturesRestClient futureClient = testnetFactory.newRestClient(); + + // Get account information + System.out.println(futureClient.getAccount()); + + // Test ping + futureClient.ping(); + + // Get 24h price statistics + System.out.println(futureClient.get24HrPriceStatistics(SYMBOL)); + + // Get Exchange Info + System.out.println(futureClient.getExchangeInfo()); + + // Get symbol aggregate trades + System.out.println("aggTrade size : " + futureClient.getAggTrades(SYMBOL).size()); + + // Get symbol candle bars + System.out.println("Candles bars size : " + futureClient.getCandlestickBars(SYMBOL, CandlestickInterval.ONE_MINUTE).size()); + + // Get listen key + System.out.println(futureClient.startUserDataStream()); + + // Get price + System.out.println("Price " + futureClient.getPrice(SYMBOL)); + } +} diff --git a/src/test/java/com/binance/api/examples/testnet/TestnetOrdersAsyncExample.java b/src/test/java/com/binance/api/examples/testnet/TestnetOrdersAsyncExample.java index 011236d5f..05fefc350 100755 --- a/src/test/java/com/binance/api/examples/testnet/TestnetOrdersAsyncExample.java +++ b/src/test/java/com/binance/api/examples/testnet/TestnetOrdersAsyncExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples.testnet; -import com.binance.api.client.BinanceApiAsyncFuturesRestClient; +import com.binance.api.client.api.async.BinanceApiAsyncFuturesRestClient; import com.binance.api.client.domain.account.request.OrderRequest; import com.binance.api.client.factory.BinanceAbstractFactory; import com.binance.api.client.factory.BinanceFuturesApiClientFactory; diff --git a/src/test/java/com/binance/api/examples/testnet/TestnetOrdersExample.java b/src/test/java/com/binance/api/examples/testnet/TestnetOrdersExample.java index 8518aaec0..e44e4d58c 100755 --- a/src/test/java/com/binance/api/examples/testnet/TestnetOrdersExample.java +++ b/src/test/java/com/binance/api/examples/testnet/TestnetOrdersExample.java @@ -1,7 +1,6 @@ package com.binance.api.examples.testnet; -import com.binance.api.client.BinanceApiFuturesRestClient; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.sync.BinanceApiFuturesRestClient; import com.binance.api.client.domain.account.FuturesNewOrder; import com.binance.api.client.domain.account.FuturesNewOrderResponse; import com.binance.api.client.factory.BinanceAbstractFactory; @@ -20,24 +19,41 @@ public class TestnetOrdersExample { public static void main(String[] args) throws InterruptedException { BinanceFuturesApiClientFactory testnetFactory = BinanceAbstractFactory.createTestnetFactory(API_KEY, SECRET_KEY); - BinanceApiWebSocketClient streamClient = testnetFactory.newWebSocketClient(); - BinanceApiFuturesRestClient restClient = testnetFactory.newFuturesRestClient(); + BinanceApiFuturesRestClient futureClient = testnetFactory.newRestClient(); - String listenKey = restClient.startUserDataStream(); + // Market Long Order +// FuturesNewOrderResponse longResponse = futureClient.newOrder(FuturesNewOrder.MarketLong(SYMBOL, "1", false)); +// System.out.println(longResponse); - streamClient.onUserDataUpdateEvent(listenKey, System.out::println); - System.out.println("Waiting for events..."); + // Market Short Order +// FuturesNewOrderResponse shortResponse = futureClient.newOrder(FuturesNewOrder.MarketShort(SYMBOL, "0.5", false)); +// System.out.println(shortResponse); + // Get open orders +// List openOrders = futureClient.getOpenOrders(new OrderRequest(SYMBOL)); +// if (!openOrders.isEmpty()) { +// openOrders.forEach(System.out::println); +// } else { +// System.out.println("You have not any open order"); +// } - BinanceApiFuturesRestClient futureClient = testnetFactory.newFuturesRestClient(); - FuturesNewOrderResponse response1 = futureClient.newOrder(FuturesNewOrder.MarketLong(SYMBOL, "1", false)); - System.out.println(response1.getStatus()); + // Cancel Order +// CancelOrderResponse cancelOrderResponse = futureClient.cancelOrder(new CancelOrderRequest(SYMBOL, longLimit.getOrderId())); +// System.out.println(cancelOrderResponse); + + // Long Limit Order +// FuturesNewOrderResponse longLimit = futureClient.newOrder(FuturesNewOrder.limitLong(SYMBOL, TimeInForce.GTC, "1", "58000", false)); +// System.out.println(longLimit); + + // Short Limit Order +// FuturesNewOrderResponse shortLimit = futureClient.newOrder(FuturesNewOrder.limitShort(SYMBOL, TimeInForce.GTC, "1.5", "59050", false)); +// System.out.println(shortLimit); + + FuturesNewOrderResponse stopLimitShort = futureClient.newOrder(FuturesNewOrder.stopLimitShort(SYMBOL, "1", "58814", false)); + System.out.println(stopLimitShort); - Thread.sleep(5000); - FuturesNewOrderResponse response2 = futureClient.newOrder(FuturesNewOrder.MarketShort(SYMBOL, "1", false)); - System.out.println(response2); } } diff --git a/src/test/java/com/binance/api/examples/testnet/TestnetWebSocketExample.java b/src/test/java/com/binance/api/examples/testnet/TestnetWebSocketExample.java index 671832905..2e795cb3e 100755 --- a/src/test/java/com/binance/api/examples/testnet/TestnetWebSocketExample.java +++ b/src/test/java/com/binance/api/examples/testnet/TestnetWebSocketExample.java @@ -1,6 +1,6 @@ package com.binance.api.examples.testnet; -import com.binance.api.client.BinanceApiWebSocketClient; +import com.binance.api.client.api.BinanceApiWebSocketClient; import com.binance.api.client.domain.market.CandlestickInterval; import com.binance.api.client.factory.BinanceAbstractFactory; import com.binance.api.client.factory.BinanceFuturesApiClientFactory;