var coinsForChecking = {};
coinsForChecking = {
fifteenMin: [],
thirtyMin: [],
fiveMin: [],
};
var yourIntrestingMarkets = ['BTC-ETH','USDT-BTC', 'USDT-ETH'];
var marketRegex = new RegExp(yourIntrestingMarkets.join('|'));
var percentageCollection = {
fifteenMin: [],
thirtyMin: [],
fiveMin: [],
};
$.signalR.coreHub.connection.received(function(data) {
if( data.M == 'updateSummaryState' )
{
var coins = data.A[0].Deltas;
coins.map(function(coin){
if( coin.MarketName.match(marketRegex) )
{
Object.keys(coinsForChecking).map(function(intervalKey){
if( !coinsForChecking[intervalKey].hasOwnProperty(coin.MarketName) )
{
coinsForChecking[intervalKey][coin.MarketName] = [];
}
coinsForChecking[intervalKey][coin.MarketName].push({
price: coin.Last,
high: coin.High,
low: coin.Low,
todayChagne: ((coin.Last - coin.PrevDay)/coin.PrevDay)*100,
_date: new Date(),
});
});
}
})
}
});
function toCheck(interval, percentageToCheck){
percentageToCheck = percentageToCheck || 5;
var coinData = coinsForChecking[ interval ];
Object.keys(coinData).map(function(name){
var prices = coinData[name];
var firstPrice = coinData[ name ][0];
var lastPrice = coinData[ name ].pop();
if( (lastPrice && lastPrice.price) && (firstPrice && firstPrice.price) && lastPrice.price !== firstPrice.price )
{
var change = lastPrice.todayChagne - firstPrice.todayChagne;
if( firstPrice.todayChagne > lastPrice.todayChagne )
{
console.log('Goin Down',name, change)
}
else{
console.log('Goin Up',name, change)
}
coinsForChecking[ interval ] = {};
}
});
}
setInterval(function(){
console.info('********************Timeout Running fifteenMin*********************************');
toCheck('fifteenMin');
console.info(new Date());
}, (1000 * 60) * 15 );
setInterval(function(){
console.info('********************Timeout Running thirtyMin*********************************');
toCheck('thirtyMin');
console.info(new Date());
}, (1000 * 60) * 30 );
setInterval(function(){
console.info('********************Timeout Running thirtySec*********************************');
toCheck('fiveMin');
console.info(new Date());
}, (1000 * 60) * 5 );