Learn, Share, Build

248
September 25, 2017, at 09:28 AM

I have a method that subscribes to a websocket to receive its information. It then uses this information to compare parts of it to locally populated variables. However, These locally populated variables arent static, they're re-calculated every 5 minutes.

Here's an example:

function subscribeToTicker(ticker, indicator){
    subscribe(something, obj ==>{
        var percentVariance = ((obj.price-indicator)/indicator)*100;
        if (variance > 1.5){
            console.log("above");
        }
        else{
            console.log("below");
    }
}
function calculateIndicator(ticker){
    indicator = SomeCalculation;
    subscribeToTicker('ABC', indicator);        
}
setInterval(function(){calculateIndicator();}, 300000);

Essentially, the calculateIndicator function is supposed to run every 5 minutes, update the indicator and pass it to the websocket itself.

With the example above I end up creating a NEW websocket connection every 5 mins, and essentially making the check on two different values. What would be a creative way to pass indicator in a way that its constantly fetching the newer value?

I considered writing the indicator out to a JSON file and reading the file over and over, but it seems rather inefficient (and don't really know if this would work).

Rent Charter Buses Company
READ ALSO
Learn, Share, Build

Learn, Share, Build

how can i do this image

263
Learn, Share, Build

Learn, Share, Build

hi i'm working with jade and bootstrap in node i'm trying to display three images in a rowI'm not getting error but still not working properly

219
Learn, Share, Build

Learn, Share, Build

I'm given an array of stringsIts a text with actions in brackets

214