Object.keys(symbolToAlgorithmMap).forEach(function(symbol){
var exchangeInfo = profitStatus[symbolToAlgorithmMap[symbol]][symbol].exchangeInfo;
if (!exchangeInfo.hasOwnProperty('Exchange'))
exchangeInfo['Exchange'] = {};
var marketData = exchangeInfo['Exchange'];
var results = data.return.markets;
if (results && results.hasOwnProperty(symbol + '/BTC')) {
if (!marketData.hasOwnProperty('BTC'))
marketData['BTC'] = {};
var btcData = results[symbol + '/BTC'];
marketData['BTC'].last = new Number(btcData.lasttradeprice);
marketData['BTC'].baseVolume = new Number(marketData['BTC'].last / btcData.volume);
marketData['BTC'].quoteVolume = new Number(btcData.volume);
if (btcData.sellorders != null)
marketData['BTC'].ask = new Number(btcData.sellorders[0].price);
if (btcData.buyorders != null) {
marketData['BTC'].bid = new Number(btcData.buyorders[0].price);
var limit = new Number(marketData['BTC'].bid * portalConfig.profitSwitch.depth);
var depth = new Number(0);
var totalQty = new Number(0);
btcData['buyorders'].forEach(function(order){
var price = new Number(order.price);
var qty = new Number(order.quantity);
if (price >= limit){
depth += (qty * price);
totalQty += qty;
}
});
marketData['BTC'].depth = depth;
if (totalQty > 0) {
marketData['BTC'].weightedBid = new Number(depth / totalQty);
marketData['BTC'].quantity = totalQty;
}
}
//var output = redisClient2
var redisClient2 = redis.createClient(portalConfig.redis.port, portalConfig.redis.host);
redisClient2.select(1 ,function(err,res){
if(err) {
console.log('Error selecting DB1 ')
}
redisClient2.set(symbol+'_profit',JSON.stringify(btcData.lasttradeprice) );
console.log(symbol,JSON.stringify(btcData.lasttradeprice));
//console.log(redisClient2.toString())
//console.log(redisClient2)
});
}