forked from KillerInk/binance-java-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOrdersExample.java
executable file
·60 lines (46 loc) · 2.57 KB
/
OrdersExample.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
package com.binance.api.examples;
import com.binance.api.client.api.sync.BinanceApiSpotRestClient;
import com.binance.api.client.domain.TimeInForce;
import com.binance.api.client.domain.account.NewOrderResponse;
import com.binance.api.client.domain.account.NewOrderResponseType;
import com.binance.api.client.domain.account.Order;
import com.binance.api.client.domain.account.request.*;
import com.binance.api.client.exception.BinanceApiException;
import com.binance.api.client.factory.BinanceAbstractFactory;
import com.binance.api.client.factory.BinanceSpotApiClientFactory;
import java.util.List;
import static com.binance.api.client.domain.account.NewOrder.limitBuy;
import static com.binance.api.client.domain.account.NewOrder.marketBuy;
/**
* Examples on how to place orders, cancel them, and query account information.
*/
public class OrdersExample {
private static final String SYMBOL = "LINKUSDT";
public static void main(String[] args) {
BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("MWzDJFwWf4jaCkqEv6NFYZyv2fDhdY3c1FMNN0E639wAlKvvD6oH2QxMlg5Be8jP", "ioIv2eCzPCtKeD6DcN5YYHiOA2X6Wn5Ao5kPbQ184wPZkn9Z7bv2F1apafh2f3Mm");
BinanceApiSpotRestClient client = factory.newRestClient();
// Getting list of open orders
List<Order> openOrders = client.getOpenOrders(new OrderRequest(SYMBOL));
System.out.println(openOrders);
// Getting list of all orders with a limit of 10
List<Order> allOrders = client.getAllOrders(new AllOrdersRequest(SYMBOL).limit(10));
System.out.println(allOrders);
// Get status of a particular order
Order order = client.getOrderStatus(new OrderStatusRequest(SYMBOL, 751698L));
System.out.println(order);
// Canceling an order
try {
CancelOrderResponse cancelOrderResponse = client.cancelOrder(new CancelOrderRequest(SYMBOL, 756762L));
System.out.println(cancelOrderResponse);
} catch (BinanceApiException e) {
System.out.println(e.getError().getMsg());
}
// Placing a test LIMIT order
client.newOrderTest(limitBuy("LINKETH", TimeInForce.GTC, "1000", "0.0001"));
// Placing a test MARKET order
client.newOrderTest(marketBuy("LINKETH", "1000"));
// Placing a real LIMIT order
NewOrderResponse newOrderResponse = client.newOrder(limitBuy("LINKETH", TimeInForce.GTC, "1000", "0.0001").newOrderRespType(NewOrderResponseType.FULL));
System.out.println(newOrderResponse);
}
}