-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy patheventEmitters.js
91 lines (79 loc) · 2.58 KB
/
eventEmitters.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
var BlinkTradeWS = require('blinktrade').BlinkTradeWS;
var blinktrade = new BlinkTradeWS();
function onBalanceUpdate(newBalance) {
console.log('Balance Updated', newBalance);
}
function onExecutionReportNew(data) {
console.log('EXECUTION_REPORT:NEW', data);
}
function onExecutionReportPartial(data) {
console.log('EXECUTION_REPORT:PARTIAL', data);
}
function onExecutionReportExecution(data) {
console.log('EXECUTION_REPORT:EXECUTION', data);
}
function onExecutionReportCanceled(data) {
console.log('EXECUTION_REPORT:CANCELED', data);
}
function onExecutionReportRejected(data) {
console.log('EXECUTION_REPORT:REJECTED', data);
}
function onOrderBookNewOrder(data) {
console.log('OB:NEW_ORDER', data);
}
function onOrderBookUpdateOrder(data) {
console.log('OB:UPDATE_ORDER', data);
}
function onOrderBookDeleteOrder(data) {
console.log('OB:DELETE_ORDER', data);
}
function onOrderBookDeleteThruOrder(data) {
console.log('OB:DELETE_ORDERS_THRU', data);
}
function onOrderBookTradeNew(data) {
console.log('OB:TRADE_NEW', data);
}
function onAnyTicker(data) {
console.log('Any Ticker Updated');
}
function onBTCBRL(data) {
console.log('BTCBRL', data);
}
blinktrade.connect().then(function() {
return blinktrade.login({ username: 'rodrigo', password: 'abc12345' });
}).then(function(logged) {
return blinktrade.balance().on('BALANCE', onBalanceUpdate);
}).then(function(balance) {
console.log('Balance', balance);
blinktrade.executionReport()
.on('EXECUTION_REPORT:NEW', onExecutionReportNew)
.on('EXECUTION_REPORT:PARTIAL', onExecutionReportPartial)
.on('EXECUTION_REPORT:EXECUTION', onExecutionReportExecution)
.on('EXECUTION_REPORT:CANCELED', onExecutionReportCanceled)
.on('EXECUTION_REPORT:REJECTED', onExecutionReportRejected);
return blinktrade.subscribeMarketData(['BTCBRL'])
.on('OB:NEW_ORDER', onOrderBookNewOrder)
.on('OB:UPDATE_ORDER', onOrderBookUpdateOrder)
.on('OB:DELETE_ORDER', onOrderBookDeleteOrder)
.on('OB:DELETE_ORDERS_THRU', onOrderBookDeleteThruOrder)
.on('OB:TRADE_NEW', onOrderBookTradeNew);
}).then(function(orderbook) {
return blinktrade.subscribeTicker(['BLINK:BTCBRL'])
.on('BLINK:*', onAnyTicker)
.on('BLINK:BTCBRL', onBTCBRL)
.many('BLINK:BTCBRL', 2, onBTCBRL);
}).then(function(ticker) {
return blinktrade.sendOrder({
side: '1',
price: parseInt(10 * 1e8, 10),
amount: parseInt(0.05 * 1e8, 10),
symbol: 'BTCBRL',
});
}).then(function(order) {
return blinktrade.cancelOrder({
orderId: order.OrderID,
clientId: order.ClOrdID
});
}).catch(function(err) {
console.log(err);
});