extracting a value from existing script to insert into redis

19 views
Skip to first unread message

crackers

unread,
Apr 14, 2015, 10:05:24 AM4/14/15
to nod...@googlegroups.com
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!

Reply all
Reply to author
Forward
0 new messages