Hi, 

I've been fighting with getting a value inserted into a new redis key in an 
existing script. I'm just trying to take one of the value pull from an API, 
and put it into a separate redis key. I'm not that savy with node, but I 
have the same modification further down in the script which does work as I 
am expecting this one to. However, it just will not create the key in redis 
with the value. I've added a console.log and it does print the data that I 
need, just not inserting it.

Hoping someone can spot an issue and point out when needs to be changed.

Here is the code snip with my addition of the redisClient2 to pull out 
the btcData.lasttradeprice and put it into a key named <symbol>_profit

                    
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)
                                });



                        }

The redisClient2.set works further down in my script simply with different 
variable...

Thanks in advanced!

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/8556d8e7-6ff5-4db3-9cc0-d0cac79e16e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to