-
Notifications
You must be signed in to change notification settings - Fork 793
/
Copy pathBinanceApiRestClient.java
251 lines (216 loc) · 7.58 KB
/
BinanceApiRestClient.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
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.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 synchronous/blocking access Binance's REST API.
*/
public interface BinanceApiRestClient {
// General endpoints
/**
* Test connectivity to the Rest API.
*/
void ping();
/**
* Check server time.
*/
Long getServerTime();
// Market Data endpoints
/**
* Get order book of a symbol.
*
* @param symbol ticker symbol (e.g. ETHBTC)
* @param limit depth of the order book (max 100)
*/
OrderBook getOrderBook(String symbol, Integer limit);
/**
* 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).
* @return a list of aggregate trades for the given symbol
*/
List<AggTrade> getAggTrades(String symbol, String fromId, Integer limit, Long startTime, Long endTime);
/**
* Return the most recent aggregate trades for <code>symbol</code>
*
* @see #getAggTrades(String, String, Integer, Long, Long)
*/
List<AggTrade> getAggTrades(String symbol);
/**
* 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).
* @return a candlestick bar for the given symbol and interval
*/
List<Candlestick> getCandlestickBars(String symbol, CandlestickInterval interval, Integer limit, Long startTime, Long endTime);
/**
* Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
*
* @see #getCandlestickBars(String, CandlestickInterval, Integer, Long, Long)
*/
List<Candlestick> getCandlestickBars(String symbol, CandlestickInterval interval);
/**
* Get 24 hour price change statistics.
*
* @param symbol ticker symbol (e.g. ETHBTC)
*/
TickerStatistics get24HrPriceStatistics(String symbol);
/**
* Get Latest price for all symbols.
*/
List<TickerPrice> getAllPrices();
/**
* Get best price/qty on the order book for all symbols.
*/
List<BookTicker> 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.
* @param orderStatusRequest order status request options/filters
*
* @return an order
*/
Order getOrderStatus(OrderStatusRequest orderStatusRequest);
/**
* Cancel an active order.
*
* @param cancelOrderRequest order status request parameters
*/
void cancelOrder(CancelOrderRequest cancelOrderRequest);
/**
* Get all open orders on a symbol.
*
* @param orderRequest order request parameters
* @return a list of all account open orders on a symbol.
*/
List<Order> getOpenOrders(OrderRequest orderRequest);
/**
* Get all account orders; active, canceled, or filled.
*
* @param orderRequest order request parameters
* @return a list of all account orders
*/
List<Order> 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 500
* @param fromId TradeId to fetch from. Default gets most recent trades.
* @return a list of trades
*/
List<Trade> 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 500
* @return a list of trades
*/
List<Trade> 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<Trade> getMyTrades(String symbol);
/**
* 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);
/**
* 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 deposit address.
*
* @return deposit address for a given asset.
*/
DepositAddress getDepositAddress(String asset);
// User stream endpoints
/**
* 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);
}