|
| 1 | +package com.binance.api.client.domain.account; |
| 2 | + |
| 3 | +import com.binance.api.client.constant.BinanceApiConstants; |
| 4 | +import com.binance.api.client.domain.OrderSide; |
| 5 | +import com.binance.api.client.domain.OrderType; |
| 6 | +import com.binance.api.client.domain.TimeInForce; |
| 7 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 8 | +import org.apache.commons.lang3.builder.ToStringBuilder; |
| 9 | + |
| 10 | +/** |
| 11 | + * A trade order to enter or exit a position. |
| 12 | + */ |
| 13 | +@JsonIgnoreProperties(ignoreUnknown = true) |
| 14 | +public class MarginNewOrder { |
| 15 | + |
| 16 | + /** |
| 17 | + * Symbol to place the order on. |
| 18 | + */ |
| 19 | + private String symbol; |
| 20 | + |
| 21 | + /** |
| 22 | + * Buy/Sell order side. |
| 23 | + */ |
| 24 | + private OrderSide side; |
| 25 | + |
| 26 | + /** |
| 27 | + * Type of order. |
| 28 | + */ |
| 29 | + private OrderType type; |
| 30 | + |
| 31 | + /** |
| 32 | + * Time in force to indicate how long will the order remain active. |
| 33 | + */ |
| 34 | + private TimeInForce timeInForce; |
| 35 | + |
| 36 | + /** |
| 37 | + * Quantity. |
| 38 | + */ |
| 39 | + private String quantity; |
| 40 | + |
| 41 | + /** |
| 42 | + * Quote quantity. |
| 43 | + */ |
| 44 | + private String quoteOrderQty; |
| 45 | + |
| 46 | + /** |
| 47 | + * Price. |
| 48 | + */ |
| 49 | + private String price; |
| 50 | + |
| 51 | + /** |
| 52 | + * A unique id for the order. Automatically generated if not sent. |
| 53 | + */ |
| 54 | + private String newClientOrderId; |
| 55 | + |
| 56 | + /** |
| 57 | + * Used with stop orders. |
| 58 | + */ |
| 59 | + private String stopPrice; |
| 60 | + |
| 61 | + /** |
| 62 | + * Used with iceberg orders. |
| 63 | + */ |
| 64 | + private String icebergQty; |
| 65 | + |
| 66 | + /** |
| 67 | + * Set the response JSON. ACK, RESULT, or FULL; default: RESULT. |
| 68 | + */ |
| 69 | + private NewOrderResponseType newOrderRespType; |
| 70 | + |
| 71 | + /** |
| 72 | + * Set the margin order side-effect. NO_SIDE_EFFECT, MARGIN_BUY, AUTO_REPAY; default: NO_SIDE_EFFECT. |
| 73 | + */ |
| 74 | + private SideEffectType sideEffectType; |
| 75 | + |
| 76 | + /** |
| 77 | + * Receiving window. |
| 78 | + */ |
| 79 | + private Long recvWindow; |
| 80 | + |
| 81 | + /** |
| 82 | + * Order timestamp. |
| 83 | + */ |
| 84 | + private long timestamp; |
| 85 | + |
| 86 | + /** |
| 87 | + * Creates a new order with all required parameters. |
| 88 | + */ |
| 89 | + public MarginNewOrder(String symbol, OrderSide side, OrderType type, TimeInForce timeInForce, String quantity) { |
| 90 | + this.symbol = symbol; |
| 91 | + this.side = side; |
| 92 | + this.type = type; |
| 93 | + this.timeInForce = timeInForce; |
| 94 | + this.quantity = quantity; |
| 95 | + this.newOrderRespType = NewOrderResponseType.RESULT; |
| 96 | + this.timestamp = System.currentTimeMillis(); |
| 97 | + this.recvWindow = BinanceApiConstants.DEFAULT_RECEIVING_WINDOW; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Creates a new order with all required parameters plus price, which is optional for MARKET orders. |
| 102 | + */ |
| 103 | + public MarginNewOrder(String symbol, OrderSide side, OrderType type, TimeInForce timeInForce, String quantity, String price) { |
| 104 | + this(symbol, side, type, timeInForce, quantity); |
| 105 | + this.price = price; |
| 106 | + } |
| 107 | + |
| 108 | + public String getSymbol() { |
| 109 | + return symbol; |
| 110 | + } |
| 111 | + |
| 112 | + public MarginNewOrder symbol(String symbol) { |
| 113 | + this.symbol = symbol; |
| 114 | + return this; |
| 115 | + } |
| 116 | + |
| 117 | + public OrderSide getSide() { |
| 118 | + return side; |
| 119 | + } |
| 120 | + |
| 121 | + public MarginNewOrder side(OrderSide side) { |
| 122 | + this.side = side; |
| 123 | + return this; |
| 124 | + } |
| 125 | + |
| 126 | + public OrderType getType() { |
| 127 | + return type; |
| 128 | + } |
| 129 | + |
| 130 | + public MarginNewOrder type(OrderType type) { |
| 131 | + this.type = type; |
| 132 | + return this; |
| 133 | + } |
| 134 | + |
| 135 | + public TimeInForce getTimeInForce() { |
| 136 | + return timeInForce; |
| 137 | + } |
| 138 | + |
| 139 | + public MarginNewOrder timeInForce(TimeInForce timeInForce) { |
| 140 | + this.timeInForce = timeInForce; |
| 141 | + return this; |
| 142 | + } |
| 143 | + |
| 144 | + public String getQuantity() { |
| 145 | + return quantity; |
| 146 | + } |
| 147 | + |
| 148 | + public MarginNewOrder quantity(String quantity) { |
| 149 | + this.quantity = quantity; |
| 150 | + return this; |
| 151 | + } |
| 152 | + |
| 153 | + public String getQuoteOrderQty() { |
| 154 | + return quoteOrderQty; |
| 155 | + } |
| 156 | + |
| 157 | + public MarginNewOrder quoteOrderQty(String quoteOrderQty) { |
| 158 | + this.quoteOrderQty = quoteOrderQty; |
| 159 | + return this; |
| 160 | + } |
| 161 | + |
| 162 | + public String getPrice() { |
| 163 | + return price; |
| 164 | + } |
| 165 | + |
| 166 | + public MarginNewOrder price(String price) { |
| 167 | + this.price = price; |
| 168 | + return this; |
| 169 | + } |
| 170 | + |
| 171 | + public String getNewClientOrderId() { |
| 172 | + return newClientOrderId; |
| 173 | + } |
| 174 | + |
| 175 | + public MarginNewOrder newClientOrderId(String newClientOrderId) { |
| 176 | + this.newClientOrderId = newClientOrderId; |
| 177 | + return this; |
| 178 | + } |
| 179 | + |
| 180 | + public String getStopPrice() { |
| 181 | + return stopPrice; |
| 182 | + } |
| 183 | + |
| 184 | + public MarginNewOrder stopPrice(String stopPrice) { |
| 185 | + this.stopPrice = stopPrice; |
| 186 | + return this; |
| 187 | + } |
| 188 | + |
| 189 | + public String getIcebergQty() { |
| 190 | + return icebergQty; |
| 191 | + } |
| 192 | + |
| 193 | + public MarginNewOrder icebergQty(String icebergQty) { |
| 194 | + this.icebergQty = icebergQty; |
| 195 | + return this; |
| 196 | + } |
| 197 | + |
| 198 | + public NewOrderResponseType getNewOrderRespType() { |
| 199 | + return newOrderRespType; |
| 200 | + } |
| 201 | + |
| 202 | + public MarginNewOrder newOrderRespType(NewOrderResponseType newOrderRespType) { |
| 203 | + this.newOrderRespType = newOrderRespType; |
| 204 | + return this; |
| 205 | + } |
| 206 | + |
| 207 | + public SideEffectType getSideEffectType() { |
| 208 | + return sideEffectType; |
| 209 | + } |
| 210 | + |
| 211 | + public MarginNewOrder sideEffectType(SideEffectType sideEffectType) { |
| 212 | + this.sideEffectType = sideEffectType; |
| 213 | + return this; |
| 214 | + } |
| 215 | + |
| 216 | + public Long getRecvWindow() { |
| 217 | + return recvWindow; |
| 218 | + } |
| 219 | + |
| 220 | + public MarginNewOrder recvWindow(Long recvWindow) { |
| 221 | + this.recvWindow = recvWindow; |
| 222 | + return this; |
| 223 | + } |
| 224 | + |
| 225 | + public long getTimestamp() { |
| 226 | + return timestamp; |
| 227 | + } |
| 228 | + |
| 229 | + public MarginNewOrder timestamp(long timestamp) { |
| 230 | + this.timestamp = timestamp; |
| 231 | + return this; |
| 232 | + } |
| 233 | + |
| 234 | + /** |
| 235 | + * Places a MARKET buy order for the given <code>quantity</code>. |
| 236 | + * |
| 237 | + * @return a new order which is pre-configured with MARKET as the order type and BUY as the order side. |
| 238 | + */ |
| 239 | + public static MarginNewOrder marketBuy(String symbol, String quantity) { |
| 240 | + return new MarginNewOrder(symbol, OrderSide.BUY, OrderType.MARKET, null, quantity); |
| 241 | + } |
| 242 | + |
| 243 | + /** |
| 244 | + * Places a MARKET sell order for the given <code>quantity</code>. |
| 245 | + * |
| 246 | + * @return a new order which is pre-configured with MARKET as the order type and SELL as the order side. |
| 247 | + */ |
| 248 | + public static MarginNewOrder marketSell(String symbol, String quantity) { |
| 249 | + return new MarginNewOrder(symbol, OrderSide.SELL, OrderType.MARKET, null, quantity); |
| 250 | + } |
| 251 | + |
| 252 | + /** |
| 253 | + * Places a LIMIT buy order for the given <code>quantity</code> and <code>price</code>. |
| 254 | + * |
| 255 | + * @return a new order which is pre-configured with LIMIT as the order type and BUY as the order side. |
| 256 | + */ |
| 257 | + public static MarginNewOrder limitBuy(String symbol, TimeInForce timeInForce, String quantity, String price) { |
| 258 | + return new MarginNewOrder(symbol, OrderSide.BUY, OrderType.LIMIT, timeInForce, quantity, price); |
| 259 | + } |
| 260 | + |
| 261 | + /** |
| 262 | + * Places a LIMIT sell order for the given <code>quantity</code> and <code>price</code>. |
| 263 | + * |
| 264 | + * @return a new order which is pre-configured with LIMIT as the order type and SELL as the order side. |
| 265 | + */ |
| 266 | + public static MarginNewOrder limitSell(String symbol, TimeInForce timeInForce, String quantity, String price) { |
| 267 | + return new MarginNewOrder(symbol, OrderSide.SELL, OrderType.LIMIT, timeInForce, quantity, price); |
| 268 | + } |
| 269 | + |
| 270 | + @Override |
| 271 | + public String toString() { |
| 272 | + return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) |
| 273 | + .append("symbol", symbol) |
| 274 | + .append("side", side) |
| 275 | + .append("type", type) |
| 276 | + .append("timeInForce", timeInForce) |
| 277 | + .append("quantity", quantity) |
| 278 | + .append("quoteOrderQty", quoteOrderQty) |
| 279 | + .append("price", price) |
| 280 | + .append("newClientOrderId", newClientOrderId) |
| 281 | + .append("stopPrice", stopPrice) |
| 282 | + .append("icebergQty", icebergQty) |
| 283 | + .append("newOrderRespType", newOrderRespType) |
| 284 | + .append("sideEffectType", sideEffectType) |
| 285 | + .append("recvWindow", recvWindow) |
| 286 | + .append("timestamp", timestamp) |
| 287 | + .toString(); |
| 288 | + } |
| 289 | +} |
0 commit comments