Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
61 lines (60 loc) · 2.43 KB
/
Copy pathMain.java
File metadata and controls
61 lines (60 loc) · 2.43 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
importcom.cryptochassis.ccapi.Event;
importcom.cryptochassis.ccapi.EventHandler;
importcom.cryptochassis.ccapi.MapStringString;
importcom.cryptochassis.ccapi.Message;
importcom.cryptochassis.ccapi.Request;
importcom.cryptochassis.ccapi.Session;
importcom.cryptochassis.ccapi.SessionConfigs;
importcom.cryptochassis.ccapi.SessionOptions;
importcom.cryptochassis.ccapi.Subscription;
importcom.cryptochassis.ccapi.SubscriptionList;
publicclassMain {
staticclassMyEventHandlerextendsEventHandler {
@Override
publicvoidprocessEvent(Eventevent, Sessionsession) {
if (event.getType() == Event.Type.SUBSCRIPTION_STATUS) {
System.out.println(String.format("Received an event of type SUBSCRIPTION_STATUS:\n%s", event.toPrettyString(2, 2)));
varmessage = event.getMessageList().get(0);
if (message.getType() == Message.Type.SUBSCRIPTION_STARTED) {
varrequest = newRequest(Request.Operation.CREATE_ORDER, "okx", "BTC-USDT");
varparam = newMapStringString();
param.put("SIDE", "BUY");
param.put("QUANTITY", "0.0005");
param.put("LIMIT_PRICE", "20000");
request.appendParam(param);
session.sendRequest(request);
}
} elseif (event.getType() == Event.Type.SUBSCRIPTION_DATA) {
System.out.println(String.format("Received an event of type SUBSCRIPTION_DATA:\n%s", event.toPrettyString(2, 2)));
}
}
}
publicstaticvoidmain(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");
vareventHandler = newMyEventHandler();
varoption = newSessionOptions();
varconfig = newSessionConfigs();
varsession = newSession(option, config, eventHandler);
varsubscriptionList = newSubscriptionList();
subscriptionList.add(newSubscription("okx", "BTC-USDT", "ORDER_UPDATE"));
session.subscribe(subscriptionList);
try {
Thread.sleep(10000);
} catch (InterruptedExceptione) {
}
session.stop();
System.out.println("Bye");
}
}