-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoloniex.js
More file actions
32 lines (22 loc) · 875 Bytes
/
poloniex.js
File metadata and controls
32 lines (22 loc) · 875 Bytes
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
let getBooks => {
// Subscribe to order book and trade updates for BTC_ETH
poloPush.orderTrade("BTC_ETH", (err, response) => {
if (err) {
// Log error message
winston.log('error', "An error occurred: " + err.msg);
// Disconnect
return true;
}
// Handle the newly received orders/trades
for (var i = 0; i < response.length; i++) {
handleOrder(response[i]);
}
// Check if any out-of-sequence orders stored in the buffer can be added to the books
checkResponseBuffer();
}, true);
// Wait 500ms after subscribing to the orders/trades push API before using the
// public API to retrieve the entire order book. This prevents us from missing
// updates while doing the retrieval.
// Documentation: https://nodejs.org/api/timers.html
setTimeout(getOrderBook, 500);
}