Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApplication.java
More file actions
Latest commit
94 lines (79 loc) · 3.06 KB
/
Copy pathApplication.java
File metadata and controls
94 lines (79 loc) · 3.06 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
packageio.gate.apidemo;
importio.gate.gateapi.ApiException;
importorg.apache.commons.cli.*;
importjava.net.URISyntaxException;
importjava.util.List;
publicclassApplication {
publicstaticvoidmain(String[] args) throwsApiException {
Optionsoptions = newOptions();
OptionapiKey = newOption("k", "key", true, "Gate APIv4 Key");
apiKey.setArgs(1);
apiKey.setType(String.class);
apiKey.setRequired(true);
OptionapiSecret = newOption("s", "secret", true, "Gate APIv4 Secret");
apiSecret.setArgs(1);
apiSecret.setType(String.class);
apiSecret.setRequired(true);
OptionbaseUrl = newOption("u", "url", true, "API base URL used to test");
baseUrl.setType(String.class);
baseUrl.setRequired(false);
options.addOption(apiKey);
options.addOption(apiSecret);
options.addOption(baseUrl);
CommandLineParserparser = newDefaultParser();
HelpFormatterformatter = newHelpFormatter();
StringusageSyntax = "<test-to-run> --key <api-key> --secret <api-secret>";
CommandLinecmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseExceptione) {
System.out.println(e.getMessage());
formatter.printHelp(usageSyntax, options);
System.exit(1);
}
StringinputKey = cmd.getOptionValue("key");
StringinputSecret = cmd.getOptionValue("secret");
StringhostUsed = cmd.getOptionValue("url");
List<String> testsToRun = cmd.getArgList();
if (testsToRun.size() < 1) {
System.err.println("missing <test-to-run>, available tests: spot, margin, futures");
formatter.printHelp(usageSyntax, options);
System.exit(1);
}
if (hostUsed == null || "".equals(hostUsed)) {
hostUsed = "https://api.gateio.ws/api/v4";
}
if (!hostUsed.startsWith("http")) {
hostUsed = "https://" + hostUsed;
}
hostUsed = hostUsed.replaceAll("/$", "");
if (!hostUsed.endsWith("/api/v4")) {
hostUsed += "/api/v4";
}
RunConfigconfig = null;
try {
config = newRunConfig(inputKey, inputSecret, hostUsed);
} catch (URISyntaxExceptione) {
System.err.println("invalid url format. full base url is required");
formatter.printHelp(usageSyntax, options);
System.exit(1);
}
for (Stringtest : testsToRun) {
System.out.println("run " + test + " API demo");
switch (test) {
case"spot":
newSpotTest(config).run();
break;
case"margin":
newMarginTest(config).run();
break;
case"futures":
newFutureTest(config).run();
break;
default:
System.out.println("ignore unknown test " + test);
break;
}
}
}
}