-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathcli.js
executable file
·153 lines (117 loc) · 3.09 KB
/
cli.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env nodejs
const ApiClient = require('./apiclient');
var startTime = new Date();
var cli = new ApiClient();
if (process.argv.length < 3) {
console.log("missing arguments");
process.exit(1);
}
var cli_cmd = process.argv[2];
var cli_args = process.argv.slice(3);
if (cli_cmd == "help") {
const msg =
"Commands:\n" +
"info\t\t\t\tShow server info\n" +
"market.list\t\t\tShow all markets\n" +
"market.add SYMBOL [booktype]\tAdd new market\n" +
"book SYMBOL [depth]\t\tShow order book\n" +
"order order-id\t\t\tShow info on a single order\n" +
"order.cancel order-id\t\tCancel a single order\n" +
"order.modify order-id\t\tModify a single order\n" +
"order.add [json order info]\tAdd new order\n";
console.log(msg);
} else if (cli_cmd == "info") {
cli.info(function(err, res) {
if (err) { throw new Error(err); }
console.dir(res);
});
} else if (cli_cmd == "market.list") {
cli.marketList(function(err, res) {
if (err) { throw new Error(err); }
console.dir(res);
});
} else if (cli_cmd == "market.add") {
if (cli_args.length != 1) {
console.log("missing symbol argument");
process.exit(1);
}
var marketInfo = {
symbol: cli_args[0],
booktype: "simple",
};
if (cli_args.length > 1)
marketInfo.booktype = cli_args[1];
cli.marketAdd(marketInfo, function(err, res) {
if (err) { throw new Error(err); }
console.dir(res);
});
} else if (cli_cmd == "book") {
if (cli_args.length < 1) {
console.log("missing symbol argument");
process.exit(1);
}
var symbol = cli_args[0];
var depth = 1;
if (cli_args.length > 1) {
depth = parseInt(cli_args[1]);
if ((depth < 1) || (depth > 3)) {
console.log("invalid depth argument");
process.exit(1);
}
}
var bookOpt = {
"symbol": symbol,
"depth": depth,
};
cli.book(bookOpt, function(err, res) {
if (err) { throw new Error(err); }
console.dir(res);
});
} else if (cli_cmd == "order") {
if (cli_args.length != 1) {
console.log("missing order-id argument");
process.exit(1);
}
var orderId = cli_args[0];
cli.orderGetInfo(orderId, function(err, res) {
if (err) { throw new Error(err); }
console.dir(res);
});
} else if (cli_cmd == "order.cancel") {
if (cli_args.length != 1) {
console.log("missing order-id argument");
process.exit(1);
}
var orderId = cli_args[0];
cli.orderCancel(orderId, function(err, res) {
if (err) { throw new Error(err); }
console.dir(res);
});
} else if (cli_cmd == "order.modify") {
if (cli_args.length != 3) {
console.log("missing order-id,price,qtyDelta arguments");
process.exit(1);
}
var orderInfo = {
oid: cli_args[0],
price: parseInt(cli_args[1]),
qtyDelta: parseInt(cli_args[2]),
};
cli.orderModify(orderInfo, function(err, res) {
if (err) { throw new Error(err); }
console.dir(res);
});
} else if (cli_cmd == "order.add") {
if (cli_args.length != 1) {
console.log("missing json-order argument");
process.exit(1);
}
var orderInfo = JSON.parse(cli_args[0]);
cli.orderAdd(orderInfo, function(err, res) {
if (err) { throw new Error(err); }
console.dir(res);
});
} else {
console.log("unknown command");
process.exit(1);
}