forked from crypto-chassis/ccapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
49 lines (48 loc) · 1.69 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
import com.cryptochassis.ccapi.Event;
import com.cryptochassis.ccapi.EventHandler;
import com.cryptochassis.ccapi.MapStringString;
import com.cryptochassis.ccapi.Request;
import com.cryptochassis.ccapi.Session;
import com.cryptochassis.ccapi.SessionConfigs;
import com.cryptochassis.ccapi.SessionOptions;
public class Main {
static class MyEventHandler extends EventHandler {
@Override
public boolean processEvent(Event event, Session session) {
System.out.println(String.format("Received an event:\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 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);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
session.stop();
System.out.println("Bye");
}
}