-
Notifications
You must be signed in to change notification settings - Fork 205
/
Main.java
47 lines (46 loc) · 1.83 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
import com.cryptochassis.ccapi.Event;
import com.cryptochassis.ccapi.EventHandler;
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)));
} else if (event.getType() == Event.Type.SUBSCRIPTION_DATA) {
for (var message : event.getMessageList()) {
System.out.println(String.format("Best bid and ask at %s are:", message.getTimeISO()));
for (var element : message.getElementList()) {
var elementNameValueMap = element.getNameValueMap();
for (var entry : elementNameValueMap.entrySet()) {
var name = entry.getKey();
var value = entry.getValue();
System.out.println(String.format(" %s = %s", name, value));
}
}
}
}
return true;
}
}
public static void main(String[] args) {
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", "MARKET_DEPTH"));
session.subscribe(subscriptionList);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
session.stop();
System.out.println("Bye");
}
}