If I move socket.emit outside of that function, the socket emit event happens. However, I need to get a hold of 'values' data, which is in the promise call back. The socket emit event in that case doesn't happen.
app.io.on('connection', function(socket) {
setInterval(function() {
var bitfinex = new Promise(
function(resolve, reject) {
const orderBook = 'https://api.bitfinex.com/v2/book/tBTCUSD/P0'
axios.get(orderBook)
.then(function(response) {
resolve(response)
})
.catch(function(error) {
reject(error)
});
});
var bitmex = new Promise(
function(resolve, reject) {
const orderBook = 'https://www.bitmex.com/api/v1/orderBook/L2?symbol=xbt&depth=25'
axios.get(orderBook)
.then(function(response) {
resolve(response)
})
.catch(function(error) {
reject(error)
});
});
Promise.all([bitmex, bitfinex]).then(values => {
socket.emit('feed', {
data: values
})
});
}, 3000)