Created
September 13, 2016 16:16
-
-
Save vcealicu/e9d831f2cf0c8e3e249fd1b8356f5c53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.connection = streamerUtilities.initConnection(); | |
$scope.progressBar = streamerUtilities.initProgressBar(); | |
$scope.ordering = streamerUtilities.initOrdering(); | |
$scope.isStreaming = streamerUtilities.getStreamingStatus(); | |
$scope.connection.subs = ['5~CCCAGG~BTC~USD'] //will give you the BTC-USD price | |
$scope.connection.subs.push('5~CCAGG~ETH~BTC') //will add the ETH-BTC price as well | |
//The format of the subscriptions is: for our index: 5~CCCAGG~{FromSymbol}~{ToSyombol} | |
//For trades it is: 0~{ExchangeName}~{FromSymbol}~{ToSyombol} | |
//For current price individual exchange: 2~{ExchangeName}~{FromSymbol}~{ToSyombol} | |
$scope.currentMessage = $rootScope.$on('CurrentMessage',function(event,messageInfo){ | |
$scope.parseMessage(messageInfo); | |
}); | |
streamerUtilities.addGlobalPageSubs($scope.connection.subs,function(messageInfo){$scope.parseMessage(messageInfo);}); | |
$scope.parseMessage = function(messageInfo){ | |
var subKey = messageInfo.SubKey; | |
if($scope.connection.subs.indexOf(subKey) > -1){ | |
if(subKey == messageInfo.Raw){ | |
$scope.progressBar.current++; | |
if($scope.progressBar.current == $scope.progressBar.max){ | |
$scope.connection.loadingData = false; | |
} | |
}else{ | |
var messageObject = messageInfo.Obj; | |
//remeber we need to recretae the key to position each time we sort the array | |
var arrayKey = 0; | |
if($scope.connection.keyToPosition[subKey]!=0){ | |
arrayKey = $scope.connection.keyToPosition[subKey]||$scope.connection.data.length; | |
} | |
$scope.connection.data[arrayKey] = streamerUtilities.decorateCurrent($scope.connection.data[arrayKey],messageInfo); | |
$scope.connection.totalvolume24hour=$scope.connection.data.reduce(function(a, b) { | |
return {DATA:{VOLUME24HOUR:a.DATA.VOLUME24HOUR + b.DATA.VOLUME24HOUR}}; | |
}).DATA.VOLUME24HOUR; | |
if($scope.connection.loadingData){ | |
$scope.connection.keyToPosition[subKey] = arrayKey; | |
$scope.connection.data[arrayKey]['VISUAL'] = {}; | |
$scope.progressBar.current++; | |
$scope.progressBar.message=messageObject.MARKET+':'+messageObject.FROMSYMBOL+'/'+messageObject.TOSYMBOL; | |
if($scope.progressBar.current >= $scope.progressBar.max){ | |
$scope.connection.loadingData = false; | |
if($scope.connection.data.length>1){ | |
$scope.sortKeys("VOLUME24HOURTO"); | |
} | |
} | |
}else{ | |
//have the timout on the subKey not the arrayKey as elements can be reordered before the timeout finishes. | |
$scope.connection.data[arrayKey].timeout = $timeout(function () { | |
$scope.handleTimeout(subKey); | |
}, 1500, false); | |
if($scope.isSortRequired(arrayKey)){ | |
$scope.sortAndSaveOrder(); | |
} | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment