Skip to content

Commit 97a37b4

Browse files
authored
Merge pull request binance-exchange#341 from yaniferhaoui/master
Implementation of OCO orders
2 parents 239f15c + d63938b commit 97a37b4

20 files changed

+1212
-48
lines changed

src/main/java/com/binance/api/client/BinanceApiRestClient.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package com.binance.api.client;
22

33
import com.binance.api.client.domain.account.*;
4-
import com.binance.api.client.domain.account.request.AllOrdersRequest;
5-
import com.binance.api.client.domain.account.request.CancelOrderRequest;
6-
import com.binance.api.client.domain.account.request.CancelOrderResponse;
7-
import com.binance.api.client.domain.account.request.OrderRequest;
8-
import com.binance.api.client.domain.account.request.OrderStatusRequest;
4+
import com.binance.api.client.domain.account.request.*;
95
import com.binance.api.client.domain.general.ExchangeInfo;
106
import com.binance.api.client.domain.general.Asset;
117
import com.binance.api.client.domain.market.AggTrade;
@@ -193,6 +189,38 @@ public interface BinanceApiRestClient {
193189
*/
194190
List<Order> getAllOrders(AllOrdersRequest orderRequest);
195191

192+
/**
193+
* Send in a new OCO;
194+
*
195+
* @param oco
196+
* the OCO to submit
197+
* @return a response containing details about the newly placed OCO.
198+
*/
199+
NewOCOResponse newOCO(NewOCO oco);
200+
201+
/**
202+
* Cancel an entire Order List
203+
*
204+
* @return
205+
*/
206+
CancelOrderListResponse cancelOrderList(CancelOrderListRequest cancelOrderListRequest);
207+
208+
/**
209+
* Check an order list status
210+
*
211+
* @param orderListStatusRequest
212+
* @return an orderList
213+
*/
214+
OrderList getOrderListStatus(OrderListStatusRequest orderListStatusRequest);
215+
216+
/**
217+
* Get all list os orders
218+
*
219+
* @param allOrderListRequest
220+
* @return
221+
*/
222+
List<OrderList> getAllOrderList(AllOrderListRequest allOrderListRequest);
223+
196224
/**
197225
* Get current account information.
198226
*/
@@ -245,6 +273,12 @@ public interface BinanceApiRestClient {
245273
*/
246274
WithdrawResult withdraw(String asset, String address, String amount, String name, String addressTag);
247275

276+
/**
277+
* Conver a list of assets to BNB
278+
* @param asset the list of assets to convert
279+
*/
280+
DustTransferResponse dustTranfer(List<String> asset);
281+
248282
/**
249283
* Fetch account deposit history.
250284
*
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.binance.api.client.domain;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
@JsonIgnoreProperties(ignoreUnknown = true)
6+
public enum ContingencyType {
7+
OCO
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.binance.api.client.domain;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
@JsonIgnoreProperties(ignoreUnknown = true)
6+
public enum OCOOrderStatus {
7+
EXECUTING,
8+
ALL_DONE,
9+
REJECT
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.binance.api.client.domain;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
5+
@JsonIgnoreProperties(ignoreUnknown = true)
6+
public enum OCOStatus {
7+
RESPONSE,
8+
EXEC_STARTED,
9+
ALL_DONE
10+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.binance.api.client.domain.account;
2+
3+
import java.util.List;
4+
5+
import org.apache.commons.lang3.builder.ToStringBuilder;
6+
7+
import com.binance.api.client.constant.BinanceApiConstants;
8+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
9+
10+
@JsonIgnoreProperties(ignoreUnknown = true)
11+
public class DustTransferResponse {
12+
13+
private String totalServiceCharge;
14+
15+
private String totalTransfered;
16+
17+
private List<TransferResult> transferResult;
18+
19+
public String getTotalServiceCharge() {
20+
return totalServiceCharge;
21+
}
22+
23+
public void setTotalServiceCharge(String totalServiceCharge) {
24+
this.totalServiceCharge = totalServiceCharge;
25+
}
26+
27+
public String getTotalTransfered() {
28+
return totalTransfered;
29+
}
30+
31+
public void setTotalTransfered(String totalTransfered) {
32+
this.totalTransfered = totalTransfered;
33+
}
34+
35+
public List<TransferResult> getTransferResult() {
36+
return transferResult;
37+
}
38+
39+
public void setTransferResult(List<TransferResult> transferResult) {
40+
this.transferResult = transferResult;
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE)
46+
.append("totalServiceCharge", totalServiceCharge)
47+
.append("totalTransfered", totalTransfered)
48+
.append("transferResult", transferResult)
49+
.toString();
50+
}
51+
52+
}
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
package com.binance.api.client.domain.account;
2+
3+
import org.apache.commons.lang3.builder.ToStringBuilder;
4+
5+
import com.binance.api.client.constant.BinanceApiConstants;
6+
import com.binance.api.client.domain.OrderSide;
7+
import com.binance.api.client.domain.TimeInForce;
8+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
9+
10+
@JsonIgnoreProperties(ignoreUnknown = true)
11+
public class NewOCO {
12+
13+
/**
14+
* Symbol to place the order on.
15+
*/
16+
private String symbol;
17+
18+
/**
19+
* A unique Id for the entire orderList
20+
*/
21+
private String listClientOrderId;
22+
23+
/**
24+
* Buy/Sell order side.
25+
*/
26+
private OrderSide side;
27+
28+
/**
29+
* Quantity.
30+
*/
31+
private String quantity;
32+
33+
/**
34+
* A unique Id for the limit order
35+
*/
36+
private String limitClientOrderId;
37+
38+
/**
39+
* Price.
40+
*/
41+
private String price;
42+
43+
/**
44+
* Used to make the LIMIT_MAKER leg an iceberg order.
45+
*/
46+
private String limitIcebergQty;
47+
48+
/**
49+
* A unique Id for the stop loss/stop loss limit leg
50+
*/
51+
private String stopClientOrderId;
52+
53+
/**
54+
* Stop Price.
55+
*/
56+
private String stopPrice;
57+
58+
/**
59+
* If provided, stopLimitTimeInForce is required.
60+
*/
61+
private String stopLimitPrice;
62+
63+
/**
64+
* Used with STOP_LOSS_LIMIT leg to make an iceberg order.
65+
*/
66+
private String stopIcebergQty;
67+
68+
/**
69+
* Valid values are GTC/FOK/IOC
70+
*/
71+
private TimeInForce stopLimitTimeInForce;
72+
73+
/**
74+
* Set the response JSON. ACK, RESULT, or FULL; default: RESULT.
75+
*/
76+
private NewOrderResponseType newOrderRespType;
77+
78+
/**
79+
* Receiving window.
80+
*/
81+
private Long recvWindow;
82+
83+
/**
84+
* Order timestamp.
85+
*/
86+
private long timestamp;
87+
88+
/**
89+
* Creates a new OCO with all required parameters.
90+
*/
91+
public NewOCO(String symbol, OrderSide side, String quantity, String price, String stopPrice) {
92+
this.symbol = symbol;
93+
this.side = side;
94+
this.quantity = quantity;
95+
this.price = price;
96+
this.stopPrice = stopPrice;
97+
this.timestamp = System.currentTimeMillis();
98+
this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW;
99+
}
100+
101+
public String getSymbol() {
102+
return symbol;
103+
}
104+
105+
public void setSymbol(String symbol) {
106+
this.symbol = symbol;
107+
}
108+
109+
public String getListClientOrderId() {
110+
return listClientOrderId;
111+
}
112+
113+
public void setListClientOrderId(String listClientOrderId) {
114+
this.listClientOrderId = listClientOrderId;
115+
}
116+
117+
public OrderSide getSide() {
118+
return side;
119+
}
120+
121+
public void setSide(OrderSide side) {
122+
this.side = side;
123+
}
124+
125+
public String getQuantity() {
126+
return quantity;
127+
}
128+
129+
public void setQuantity(String quantity) {
130+
this.quantity = quantity;
131+
}
132+
133+
public String getLimitClientOrderId() {
134+
return limitClientOrderId;
135+
}
136+
137+
public void setLimitClientOrderId(String limitClientOrderId) {
138+
this.limitClientOrderId = limitClientOrderId;
139+
}
140+
141+
public String getPrice() {
142+
return price;
143+
}
144+
145+
public void setPrice(String price) {
146+
this.price = price;
147+
}
148+
149+
public String getLimitIcebergQty() {
150+
return limitIcebergQty;
151+
}
152+
153+
public void setLimitIcebergQty(String limitIcebergQty) {
154+
this.limitIcebergQty = limitIcebergQty;
155+
}
156+
157+
public String getStopClientOrderId() {
158+
return stopClientOrderId;
159+
}
160+
161+
public void setStopClientOrderId(String stopClientOrderId) {
162+
this.stopClientOrderId = stopClientOrderId;
163+
}
164+
165+
public String getStopPrice() {
166+
return stopPrice;
167+
}
168+
169+
public void setStopPrice(String stopPrice) {
170+
this.stopPrice = stopPrice;
171+
}
172+
173+
public String getStopLimitPrice() {
174+
return stopLimitPrice;
175+
}
176+
177+
public void setStopLimitPrice(String stopLimitPrice) {
178+
this.stopLimitPrice = stopLimitPrice;
179+
}
180+
181+
public String getStopIcebergQty() {
182+
return stopIcebergQty;
183+
}
184+
185+
public void setStopIcebergQty(String stopIcebergQty) {
186+
this.stopIcebergQty = stopIcebergQty;
187+
}
188+
189+
public TimeInForce getStopLimitTimeInForce() {
190+
return stopLimitTimeInForce;
191+
}
192+
193+
public void setStopLimitTimeInForce(TimeInForce stopLimitTimeInForce) {
194+
this.stopLimitTimeInForce = stopLimitTimeInForce;
195+
}
196+
197+
public NewOrderResponseType getNewOrderRespType() {
198+
return newOrderRespType;
199+
}
200+
201+
public void setNewOrderRespType(NewOrderResponseType newOrderRespType) {
202+
this.newOrderRespType = newOrderRespType;
203+
}
204+
205+
public Long getRecvWindow() {
206+
return recvWindow;
207+
}
208+
209+
public void setRecvWindow(Long recvWindow) {
210+
this.recvWindow = recvWindow;
211+
}
212+
213+
public long getTimestamp() {
214+
return timestamp;
215+
}
216+
217+
public void setTimestamp(long timestamp) {
218+
this.timestamp = timestamp;
219+
}
220+
221+
@Override
222+
public String toString() {
223+
return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol)
224+
.append("listClientOrderId", listClientOrderId)
225+
.append("side", side)
226+
.append("quantity", quantity)
227+
.append("limitClientOrderId", limitClientOrderId)
228+
.append("price", price)
229+
.append("limitIcebergQty", limitIcebergQty)
230+
.append("stopClientOrderId", stopClientOrderId)
231+
.append("stopPrice", stopPrice)
232+
.append("stopLimitPrice", stopLimitPrice)
233+
.append("stopIcebergQty", stopIcebergQty)
234+
.append("stopLimitTimeInForce", stopLimitTimeInForce)
235+
.append("newOrderRespType", newOrderRespType)
236+
.append("recvWindow", recvWindow)
237+
.append("timestamp", timestamp)
238+
.toString();
239+
}
240+
241+
}

0 commit comments

Comments
 (0)