This repository was archived by the owner on Oct 30, 2023. It is now read-only.
forked from joaopsilva/binance-java-api
-
Notifications
You must be signed in to change notification settings - Fork 599
Expand file tree
/
Copy pathNewOrder.java
More file actions
executable file
·321 lines (267 loc) · 8.01 KB
/
NewOrder.java
File metadata and controls
executable file
·321 lines (267 loc) · 8.01 KB
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
package com.binance.api.client.domain.account;
import org.apache.commons.lang3.builder.ToStringBuilder;
import com.binance.api.client.constant.BinanceApiConstants;
import com.binance.api.client.domain.OrderSide;
import com.binance.api.client.domain.OrderType;
import com.binance.api.client.domain.TimeInForce;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/**
* A trade order to enter or exit a position.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class NewOrder {
/**
* Symbol to place the order on.
*/
private String symbol;
/**
* Buy/Sell order side.
*/
private OrderSide side;
/**
* Type of order.
*/
private OrderType type;
/**
* Time in force to indicate how long will the order remain active.
*/
private TimeInForce timeInForce;
/**
* Quantity.
*/
private String quantity;
/**
* Quote quantity.
*/
private String quoteOrderQty;
/**
* Price.
*/
private String price;
/**
* A unique id for the order. Automatically generated if not sent.
*/
private String newClientOrderId;
/**
* Used with stop orders.
*/
private String stopPrice;
/**
* Used with stop orders.
*/
private String stopLimitPrice;
/**
* Used with iceberg orders.
*/
private String icebergQty;
/**
* Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
*/
private NewOrderResponseType newOrderRespType;
/**
* Receiving window.
*/
private Long recvWindow;
/**
* Order timestamp.
*/
private long timestamp;
/**
* Creates a new order with all required parameters.
*/
public NewOrder(String symbol, OrderSide side, OrderType type, TimeInForce timeInForce, String quantity) {
this.symbol = symbol;
this.side = side;
this.type = type;
this.timeInForce = timeInForce;
this.quantity = quantity;
this.newOrderRespType = NewOrderResponseType.RESULT;
this.timestamp = System.currentTimeMillis();
this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW;
}
/**
* Creates a new order with all required parameters plus price, which is optional for MARKET orders.
*/
public NewOrder(String symbol, OrderSide side, OrderType type, TimeInForce timeInForce, String quantity, String price) {
this(symbol, side, type, timeInForce, quantity);
this.price = price;
}
public String getSymbol() {
return symbol;
}
public NewOrder symbol(String symbol) {
this.symbol = symbol;
return this;
}
public OrderSide getSide() {
return side;
}
public NewOrder side(OrderSide side) {
this.side = side;
return this;
}
public OrderType getType() {
return type;
}
public NewOrder type(OrderType type) {
this.type = type;
return this;
}
public TimeInForce getTimeInForce() {
return timeInForce;
}
public NewOrder timeInForce(TimeInForce timeInForce) {
this.timeInForce = timeInForce;
return this;
}
public String getQuantity() {
return quantity;
}
public NewOrder quantity(String quantity) {
this.quantity = quantity;
return this;
}
public String getQuoteOrderQty() {
return quoteOrderQty;
}
public NewOrder quoteOrderQty(String quoteOrderQty) {
this.quoteOrderQty = quoteOrderQty;
return this;
}
public String getPrice() {
return price;
}
public NewOrder price(String price) {
this.price = price;
return this;
}
public String getNewClientOrderId() {
return newClientOrderId;
}
public NewOrder newClientOrderId(String newClientOrderId) {
this.newClientOrderId = newClientOrderId;
return this;
}
public String getStopPrice() {
return stopPrice;
}
public NewOrder stopPrice(String stopPrice) {
this.stopPrice = stopPrice;
return this;
}
public String getStopLimitPrice() {
return stopLimitPrice;
}
public NewOrder stopLimitPrice(String stopLimitPrice) {
this.stopLimitPrice = stopLimitPrice;
return this;
}
public String getIcebergQty() {
return icebergQty;
}
public NewOrder icebergQty(String icebergQty) {
this.icebergQty = icebergQty;
return this;
}
public NewOrderResponseType getNewOrderRespType() {
return newOrderRespType;
}
public NewOrder newOrderRespType(NewOrderResponseType newOrderRespType) {
this.newOrderRespType = newOrderRespType;
return this;
}
public Long getRecvWindow() {
return recvWindow;
}
public NewOrder recvWindow(Long recvWindow) {
this.recvWindow = recvWindow;
return this;
}
public long getTimestamp() {
return timestamp;
}
public NewOrder timestamp(long timestamp) {
this.timestamp = timestamp;
return this;
}
/**
* Places a MARKET buy order for the given <code>quantity</code>.
*
* @return a new order which is pre-configured with MARKET as the order type and BUY as the order side.
*/
public static NewOrder marketBuy(String symbol, String quantity) {
return new NewOrder(symbol, OrderSide.BUY, OrderType.MARKET, null, quantity);
}
/**
* Places a MARKET sell order for the given <code>quantity</code>.
*
* @return a new order which is pre-configured with MARKET as the order type and SELL as the order side.
*/
public static NewOrder marketSell(String symbol, String quantity) {
return new NewOrder(symbol, OrderSide.SELL, OrderType.MARKET, null, quantity);
}
/**
* Places a LIMIT buy order for the given <code>quantity</code> and <code>price</code>.
*
* @return a new order which is pre-configured with LIMIT as the order type and BUY as the order side.
*/
public static NewOrder limitBuy(String symbol, TimeInForce timeInForce, String quantity, String price) {
return new NewOrder(symbol, OrderSide.BUY, OrderType.LIMIT, timeInForce, quantity, price);
}
/**
* Places a LIMIT sell order for the given <code>quantity</code> and <code>price</code>.
*
* @return a new order which is pre-configured with LIMIT as the order type and SELL as the order side.
*/
public static NewOrder limitSell(String symbol, TimeInForce timeInForce, String quantity, String price) {
return new NewOrder(symbol, OrderSide.SELL, OrderType.LIMIT, timeInForce, quantity, price);
}
/**
* Places a STOP buy order for the given <code>quantity</code> and
* <code>price</code>.
*
* @return a new order which is pre-configured with STOP as the order type and
* BUY as the order side.
*/
public static NewOrder stopBuy(String symbol, String quantity, String stopPrice, String stopLimitPrice,
TimeInForce timeInForce) {
NewOrder newOrder = new NewOrder(symbol, OrderSide.BUY, OrderType.STOP_LOSS_LIMIT, timeInForce, quantity, null);
newOrder.stopPrice = stopPrice;
newOrder.price = stopLimitPrice;
return newOrder;
}
/**
* Places a STOP sell order for the given <code>quantity</code> and
* <code>price</code>.
*
* @return a new order which is pre-configured with STOP as the order type and
* SELL as the order side.
*/
public static NewOrder stopSell(String symbol, String quantity, String stopPrice, String stopLimitPrice,
TimeInForce timeInForce) {
NewOrder newOrder = new NewOrder(symbol, OrderSide.SELL, OrderType.STOP_LOSS_LIMIT, timeInForce, quantity,
null);
newOrder.stopPrice = stopPrice;
newOrder.price = stopLimitPrice;
return newOrder;
}
@Override
public String toString() {
return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE)
.append("symbol", symbol)
.append("side", side)
.append("type", type)
.append("timeInForce", timeInForce)
.append("quantity", quantity)
.append("quoteOrderQty", quoteOrderQty)
.append("price", price)
.append("newClientOrderId", newClientOrderId)
.append("stopPrice", stopPrice)
.append("stopLimitPrice", stopLimitPrice)
.append("icebergQty", icebergQty)
.append("newOrderRespType", newOrderRespType)
.append("recvWindow", recvWindow)
.append("timestamp", timestamp)
.toString();
}
}