forked from crypto-chassis/ccapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
62 lines (61 loc) · 2.44 KB
/
Main.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
61
62
import com.cryptochassis.ccapi.Event;
import com.cryptochassis.ccapi.EventHandler;
import com.cryptochassis.ccapi.MapStringString;
import com.cryptochassis.ccapi.Message;
import com.cryptochassis.ccapi.Request;
import com.cryptochassis.ccapi.Session;
import com.cryptochassis.ccapi.SessionConfigs;
import com.cryptochassis.ccapi.SessionOptions;
import com.cryptochassis.ccapi.Subscription;
import com.cryptochassis.ccapi.SubscriptionList;
public class Main {
static class MyEventHandler extends EventHandler {
@Override
public boolean processEvent(Event event, Session session) {
if (event.getType() == Event.Type.SUBSCRIPTION_STATUS) {
System.out.println(String.format("Received an event of type SUBSCRIPTION_STATUS:\n%s", event.toStringPretty(2, 2)));
var message = event.getMessageList().get(0);
if (message.getType() == Message.Type.SUBSCRIPTION_STARTED) {
var request = new Request(Request.Operation.CREATE_ORDER, "okx", "BTC-USDT");
var param = new MapStringString();
param.put("SIDE", "BUY");
param.put("QUANTITY", "0.0005");
param.put("LIMIT_PRICE", "20000");
request.appendParam(param);
session.sendRequest(request);
}
} else if (event.getType() == Event.Type.SUBSCRIPTION_DATA) {
System.out.println(String.format("Received an event of type SUBSCRIPTION_DATA:\n%s", event.toStringPretty(2, 2)));
}
return true;
}
}
public static void main(String[] args) {
if (System.getenv("OKX_API_KEY") == null) {
System.err.println("Please set environment variable OKX_API_KEY");
return;
}
if (System.getenv("OKX_API_SECRET") == null) {
System.err.println("Please set environment variable OKX_API_SECRET");
return;
}
if (System.getenv("OKX_API_PASSPHRASE") == null) {
System.err.println("Please set environment variable OKX_API_PASSPHRASE");
return;
}
System.loadLibrary("ccapi_binding_java");
var eventHandler = new MyEventHandler();
var option = new SessionOptions();
var config = new SessionConfigs();
var session = new Session(option, config, eventHandler);
var subscriptionList = new SubscriptionList();
subscriptionList.add(new Subscription("okx", "BTC-USDT", "ORDER_UPDATE"));
session.subscribe(subscriptionList);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
session.stop();
System.out.println("Bye");
}
}