forked from binance-exchange/binance-java-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrdersExampleAsync.java
More file actions
executable file
·46 lines (35 loc) · 2.12 KB
/
OrdersExampleAsync.java
File metadata and controls
executable file
·46 lines (35 loc) · 2.12 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
package com.binance.api.examples;
import com.binance.api.client.api.async.BinanceApiSpotAsyncRestClient;
import com.binance.api.client.domain.TimeInForce;
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.factory.BinanceAbstractFactory;
import com.binance.api.client.factory.BinanceSpotApiClientFactory;
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 OrdersExampleAsync {
public static void main(String[] args) {
BinanceSpotApiClientFactory factory = BinanceAbstractFactory.createSpotFactory("YOUR_API_KEY", "YOUR_SECRET");
BinanceApiSpotAsyncRestClient client = factory.newAsyncRestClient();
// Getting list of open orders
client.getOpenOrders(new OrderRequest("LINKETH"), System.out::println);
// Get status of a particular order
client.getOrderStatus(new OrderStatusRequest("LINKETH", 745262L), System.out::println);
// Getting list of all orders with a limit of 10
client.getAllOrders(new AllOrdersRequest("LINKETH").limit(10), System.out::println);
// Canceling an order
client.cancelOrder(new CancelOrderRequest("LINKETH", 756703L), System.out::println);
// Placing a test LIMIT order
client.newOrderTest(limitBuy("LINKETH", TimeInForce.GTC, "1000", "0.0001"),
response -> System.out.println("Test order has succeeded."));
// Placing a test MARKET order
client.newOrderTest(marketBuy("LINKETH", "1000"), response -> System.out.println("Test order has succeeded."));
// Placing a real LIMIT order
client.newOrder(limitBuy("LINKETH", TimeInForce.GTC, "1000", "0.0001"), System.out::println);
}
}