-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwap-order.js
68 lines (57 loc) · 1.68 KB
/
twap-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
63
64
65
66
67
68
const Axios = require('axios');
const Crypto = require('crypto')
const { v4: GUID } = require('uuid');
// Do not submit actual keys that give access to anything of value to GIT :-)
const API_KEY = 'w6AcfksrG7GiEFoN'
const SECRET = 'gZ0kkI9p8bHHDaBjO3Cyij87SrToYPA3'
const now = new Date();
var orderID = GUID()
var order = JSON.stringify({
orderId: orderID,
originalTimestamp: now,
side: "BUY",
quantity: 1,
limitPrice: 3700,
symbol: "BTCUSD",
orderType: "LIMIT",
destinationId: "TWAP",
timeInForce: "GOOD_TILL_CANCEL",
account: "TEST",
attributes: [{"key": 6002, "value": "05:03:30"}, {"key": 6023, "value": "25"}]
});
var signature = Crypto.createHmac('sha384', SECRET).update(order).digest('hex');
var a = Axios.post('http://localhost:8988/api/v1/order/new', order, // https:// for PROD
{
headers: {
"Content-Type": "application/json",
"X-API-KEY": API_KEY,
"X-SIGNATURE": signature,
},
}
).then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error(error);
});
// sleep for 1 sec and then request order status
setTimeout(() => {
var request = JSON.stringify({
orderId: orderID
});
signature = Crypto.createHmac('sha384', SECRET).update(request).digest('hex');
a = Axios.post('http://localhost:8988/api/v1/order/status', request, // https:// for PROD
{
headers: {
"Content-Type": "application/json",
"X-API-KEY": API_KEY,
"X-SIGNATURE": signature,
}
}
).then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error(error);
});
}, 1000);