-
Notifications
You must be signed in to change notification settings - Fork 794
/
BinanceApiAsyncRestClient.java
264 lines (229 loc) · 9.77 KB
/
BinanceApiAsyncRestClient.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package com.binance.api.client;
import com.binance.api.client.domain.account.Account;
import com.binance.api.client.domain.account.DepositAddress;
import com.binance.api.client.domain.account.DepositHistory;
import com.binance.api.client.domain.account.NewOrder;
import com.binance.api.client.domain.account.NewOrderResponse;
import com.binance.api.client.domain.account.Order;
import com.binance.api.client.domain.account.Trade;
import com.binance.api.client.domain.account.WithdrawHistory;
import com.binance.api.client.domain.account.request.AllOrdersRequest;
import com.binance.api.client.domain.account.request.CancelOrderRequest;
import com.binance.api.client.domain.account.request.OrderRequest;
import com.binance.api.client.domain.account.request.OrderStatusRequest;
import com.binance.api.client.domain.event.ListenKey;
import com.binance.api.client.domain.general.ServerTime;
import com.binance.api.client.domain.market.AggTrade;
import com.binance.api.client.domain.market.BookTicker;
import com.binance.api.client.domain.market.Candlestick;
import com.binance.api.client.domain.market.CandlestickInterval;
import com.binance.api.client.domain.market.OrderBook;
import com.binance.api.client.domain.market.TickerPrice;
import com.binance.api.client.domain.market.TickerStatistics;
import java.util.List;
/**
* Binance API façade, supporting asynchronous/non-blocking access Binance's REST API.
*/
public interface BinanceApiAsyncRestClient {
// General endpoints
/**
* Test connectivity to the Rest API.
*/
void ping(BinanceApiCallback<Void> callback);
/**
* Check server time.
*/
void getServerTime(BinanceApiCallback<ServerTime> callback);
// Market Data endpoints
/**
* Get order book of a symbol (asynchronous)
*
* @param symbol ticker symbol (e.g. ETHBTC)
* @param limit depth of the order book (max 100)
* @param callback the callback that handles the response
*/
void getOrderBook(String symbol, Integer limit, BinanceApiCallback<OrderBook> callback);
/**
* Get compressed, aggregate trades. Trades that fill at the time, from the same order, with
* the same price will have the quantity aggregated.
*
* If both <code>startTime</code> and <code>endTime</code> are sent, <code>limit</code>should not
* be sent AND the distance between <code>startTime</code> and <code>endTime</code> must be less than 24 hours.
*
* @param symbol symbol to aggregate (mandatory)
* @param fromId ID to get aggregate trades from INCLUSIVE (optional)
* @param limit Default 500; max 500 (optional)
* @param startTime Timestamp in ms to get aggregate trades from INCLUSIVE (optional).
* @param endTime Timestamp in ms to get aggregate trades until INCLUSIVE (optional).
* @param callback the callback that handles the response
* @return a list of aggregate trades for the given symbol
*/
void getAggTrades(String symbol, String fromId, Integer limit, Long startTime, Long endTime, BinanceApiCallback<List<AggTrade>> callback);
/**
* Return the most recent aggregate trades for <code>symbol</code>
*
* @see #getAggTrades(String, String, Integer, Long, Long, BinanceApiCallback)
*/
void getAggTrades(String symbol, BinanceApiCallback<List<AggTrade>> callback);
/**
* Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
*
* @param symbol symbol to aggregate (mandatory)
* @param interval candlestick interval (mandatory)
* @param limit Default 500; max 500 (optional)
* @param startTime Timestamp in ms to get candlestick bars from INCLUSIVE (optional).
* @param endTime Timestamp in ms to get candlestick bars until INCLUSIVE (optional).
* @param callback the callback that handles the response containing a candlestick bar for the given symbol and interval
*/
void getCandlestickBars(String symbol, CandlestickInterval interval, Integer limit, Long startTime, Long endTime, BinanceApiCallback<List<Candlestick>> callback);
/**
* Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
*
* @see #getCandlestickBars(String, CandlestickInterval, BinanceApiCallback)
*/
void getCandlestickBars(String symbol, CandlestickInterval interval, BinanceApiCallback<List<Candlestick>> callback);
/**
* Get 24 hour price change statistics (asynchronous).
*
* @param symbol ticker symbol (e.g. ETHBTC)
* @param callback the callback that handles the response
*/
void get24HrPriceStatistics(String symbol, BinanceApiCallback<TickerStatistics> callback);
/**
* Get Latest price for all symbols (asynchronous).
*
* @param callback the callback that handles the response
*/
void getAllPrices(BinanceApiCallback<List<TickerPrice>> callback);
/**
* Get best price/qty on the order book for all symbols (asynchronous).
*
* @param callback the callback that handles the response
*/
void getBookTickers(BinanceApiCallback<List<BookTicker>> callback);
// Account endpoints
/**
* Send in a new order (asynchronous)
*
* @param order the new order to submit.
* @param callback the callback that handles the response
*/
void newOrder(NewOrder order, BinanceApiCallback<NewOrderResponse> callback);
/**
* 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.
* @param callback the callback that handles the response
*/
void newOrderTest(NewOrder order, BinanceApiCallback<Void> callback);
/**
* Check an order's status (asynchronous).
*
* @param orderStatusRequest order status request parameters
* @param callback the callback that handles the response
*/
void getOrderStatus(OrderStatusRequest orderStatusRequest, BinanceApiCallback<Order> callback);
/**
* Cancel an active order (asynchronous).
*
* @param cancelOrderRequest order status request parameters
* @param callback the callback that handles the response
*/
void cancelOrder(CancelOrderRequest cancelOrderRequest, BinanceApiCallback<Void> callback);
/**
* Get all open orders on a symbol (asynchronous).
*
* @param orderRequest order request parameters
* @param callback the callback that handles the response
*/
void getOpenOrders(OrderRequest orderRequest, BinanceApiCallback<List<Order>> callback);
/**
* Get all account orders; active, canceled, or filled.
*
* @param orderRequest order request parameters
* @param callback the callback that handles the response
*/
void getAllOrders(AllOrdersRequest orderRequest, BinanceApiCallback<List<Order>> callback);
/**
* Get current account information (async).
*/
void getAccount(Long recvWindow, Long timestamp, BinanceApiCallback<Account> callback);
/**
* Get current account information using default parameters (async).
*/
void getAccount(BinanceApiCallback<Account> callback);
/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @param limit default 500; max 500
* @param fromId TradeId to fetch from. Default gets most recent trades.
* @param callback the callback that handles the response with a list of trades
*/
void getMyTrades(String symbol, Integer limit, Long fromId, Long recvWindow, Long timestamp, BinanceApiCallback<List<Trade>> callback);
/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @param limit default 500; max 500
* @param callback the callback that handles the response with a list of trades
*/
void getMyTrades(String symbol, Integer limit, BinanceApiCallback<List<Trade>> callback);
/**
* Get trades for a specific account and symbol.
*
* @param symbol symbol to get trades from
* @param callback the callback that handles the response with a list of trades
*/
void getMyTrades(String symbol, BinanceApiCallback<List<Trade>> callback);
/**
* 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
*/
void withdraw(String asset, String address, String amount, String name, BinanceApiCallback<Void> callback);
/**
* Fetch account deposit history.
*
* @param callback the callback that handles the response and returns the deposit history
*/
void getDepositHistory(String asset, BinanceApiCallback<DepositHistory> callback);
/**
* Fetch account withdraw history.
*
* @param callback the callback that handles the response and returns the withdraw history
*/
void getWithdrawHistory(String asset, BinanceApiCallback<WithdrawHistory> callback);
/**
* Fetch deposit address.
*
* @param callback the callback that handles the response and returns the deposit address
*/
void getDepositAddress(String asset, BinanceApiCallback<DepositAddress> callback);
// User stream endpoints
/**
* Start a new user data stream.
*
* @param callback the callback that handles the response which contains a listenKey
*/
void startUserDataStream(BinanceApiCallback<ListenKey> callback);
/**
* PING a user data stream to prevent a time out.
*
* @param listenKey listen key that identifies a data stream
* @param callback the callback that handles the response which contains a listenKey
*/
void keepAliveUserDataStream(String listenKey, BinanceApiCallback<Void> callback);
/**
* Close out a new user data stream.
*
* @param listenKey listen key that identifies a data stream
* @param callback the callback that handles the response which contains a listenKey
*/
void closeUserDataStream(String listenKey, BinanceApiCallback<Void> callback);
}