-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathexecutionReport.js
44 lines (40 loc) · 1.2 KB
/
executionReport.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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS;
var blinktrade = new BlinkTradeWS();
function onNew(data) {
console.log('New Order Received', data);
}
function onPartial(data) {
console.log('Order Partially Executed', data);
}
function onExecution(data) {
console.log('Order Executed', data);
}
function onCanceled(data) {
console.log('Order Canceled', data);
}
function onRejected(data) {
console.log('Order Rejected', data);
}
blinktrade.connect().then(function() {
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' });
}).then(function(logged) {
blinktrade.executionReport()
.on('EXECUTION_REPORT:NEW', onNew)
.on('EXECUTION_REPORT:PARTIAL', onPartial)
.on('EXECUTION_REPORT:EXECUTION', onExecution)
.on('EXECUTION_REPORT:CANCELED', onCanceled)
.on('EXECUTION_REPORT:REJECTED', onRejected);
return blinktrade.sendOrder({
side: '1',
price: parseInt(10 * 1e8, 10),
amount: parseInt(0.05 * 1e8, 10),
symbol: 'BTCBRL',
});
}).then(function(order) {
// Cancel order after 5 seconds
setTimeout(function() {
return blinktrade.cancelOrder({ orderId: order.OrderID, clientId: order.ClOrdID });
}, 5000)
}).catch(function(err) {
console.log(err);
});