-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.order.js
62 lines (59 loc) · 2.4 KB
/
test.order.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
'use strict';
const assert = require ('assert');
function testOrder (exchange, order, symbol, now) {
assert (order);
assert ('id' in order);
assert (typeof order['id'] === 'string');
assert ('clientOrderId' in order);
assert ((order['clientOrderId'] === undefined) || (typeof order['clientOrderId'] === 'string'));
assert ('timestamp' in order);
assert (typeof order['timestamp'] === 'number');
assert (order['timestamp'] > 1230940800000); // 03 Jan 2009 - first block
assert (order['timestamp'] < now);
assert ('lastTradeTimestamp' in order);
assert ('datetime' in order);
assert (order['datetime'] === exchange.iso8601 (order['timestamp']));
assert ('status' in order);
assert ((order['status'] === 'open') || (order['status'] === 'closed') || (order['status'] === 'canceled'));
assert ('symbol' in order);
assert (order['symbol'] === symbol);
assert ('type' in order);
assert ((order['type'] === undefined) || (typeof order['type'] === 'string'));
assert ('timeInForce' in order);
assert ((order['timeInForce'] === undefined) || (typeof order['timeInForce'] === 'string'));
assert ('side' in order);
assert ((order['side'] === 'buy') || (order['side'] === 'sell'));
assert ('price' in order);
assert ((order['price'] === undefined) || (typeof order['price'] === 'number'));
if (order['price'] !== undefined) {
assert (order['price'] > 0);
}
assert ('amount' in order);
assert (typeof order['amount'] === 'number');
assert (order['amount'] >= 0);
assert ('filled' in order);
if (order['filled'] !== undefined) {
assert (typeof order['filled'] === 'number');
assert ((order['filled'] >= 0) && (order['filled'] <= order['amount']));
}
assert ('remaining' in order);
if (order['remaining'] !== undefined) {
assert (typeof order['remaining'] === 'number');
assert ((order['remaining'] >= 0) && (order['remaining'] <= order['amount']));
}
assert ('trades' in order);
if (order['trades']) {
assert (Array.isArray (order['trades']));
}
assert ('fee' in order);
const fee = order['fee'];
if (fee) {
assert (typeof fee['cost'] === 'number');
if (fee['cost'] !== 0) {
assert (typeof fee['currency'] === 'string');
}
}
assert ('info' in order);
assert (order['info']);
}
module.exports = testOrder;