Created
May 19, 2017 15:06
-
-
Save vcealicu/2e8cb0215938b713806da3e4ad4c6c2f 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
........... | |
calculateVolumePriceConversionCoefficient = function(currentObj1, currentObj2, timestampForCalculation){ | |
var timePassedObj1 = timestampForCalculation - currentObj1.LASTUPDATE; | |
var timePassedObj2 = timestampForCalculation - currentObj2.LASTUPDATE; | |
//negative or 0 cap it at 1 | |
if(timePassedObj1 <=0 ){ timePassedObj1 = 1; } | |
if(timePassedObj2 <=0 ){ timePassedObj2 = 1; } | |
//if last update is more than 1 day ago cap it at 1 day | |
if(timePassedObj1 > 86400){ timePassedObj1 = 86400; } | |
if(timePassedObj2 > 86400){ timePassedObj2 = 86400; } | |
/*divide in conversion symbol*/ | |
if(currentObj1.FROMSYMBOL == currentObj2.FROMSYMBOL){ | |
return (currentObj1.VOLUME24HOUR / timePassedObj1) * (currentObj2.VOLUME24HOUR / timePassedObj2); | |
} | |
/*divide in conversion symbol*/ | |
if(currentObj1.TOSYMBOL == currentObj2.TOSYMBOL){ | |
return (currentObj1.VOLUME24HOURTO / timePassedObj1) * (currentObj2.VOLUME24HOURTO / timePassedObj2); | |
} | |
/**/ | |
if(currentObj1.FROMSYMBOL == currentObj2.TOSYMBOL){ | |
return (currentObj1.VOLUME24HOUR / timePassedObj1) * (currentObj2.VOLUME24HOURTO / timePassedObj2); | |
} | |
/*multiply in convresion symbol*/ | |
if(currentObj1.TOSYMBOL == currentObj2.FROMSYMBOL){ | |
return (currentObj1.VOLUME24HOURTO / timePassedObj1) * (currentObj2.VOLUME24HOUR / timePassedObj2); | |
} | |
}; | |
overrideCoefficient = function(currentObj1,timestampForCalculation){ | |
if (currentObj1.LASTUPDATE < timestampForCalculation - 3600 || currentObj1.VOLUME24HOUR < 1000 || currentObj1.VOLUME24HOURTO < 10000) { | |
return false; | |
} | |
return true; | |
}; | |
calculateVolumePriceDirectCoefficient = function(currentObj1, timestampForCalculation){ | |
var timePassedObj1 = timestampForCalculation - currentObj1.LASTUPDATE; | |
if(timePassedObj1 <= 0){ timePassedObj1 = 1; } | |
if(timePassedObj1 > 86400){ timePassedObj1 = 86400; } | |
return currentObj1.VOLUME24HOUR / timePassedObj1; | |
}; | |
calculateVolumePriceInvertCoefficient = function(currentObj2, timestampForCalculation){ | |
var timePassedObj2 = timestampForCalculation - currentObj2.LASTUPDATE; | |
if(timePassedObj2 <= 0){ timePassedObj2 = 1; } | |
if(timePassedObj2 > 86400){ timePassedObj2 = 86400; } | |
return currentObj2.VOLUME24HOURTO / timePassedObj2; | |
}; | |
............ | |
/// for the actual function that calls this we use: | |
var predConv = predictConversion(fromSymbol, toSymbol, market, tryConversion); | |
var tryNextStep = true; | |
if (predConv == 'direct') { | |
overridePVC = overrideCoefficient(globalCoinInfo[fromSymbol].DATA[toSymbol][market][conversionKey],hitTimestamp); | |
directPVC = calculateVolumePriceDirectCoefficient(globalCoinInfo[fromSymbol].DATA[toSymbol][market][conversionKey],hitTimestamp); | |
if (tradesIn(toSymbol, fromSymbol)) { | |
invertPVC = calculateVolumePriceInvertCoefficient(globalCoinInfo[toSymbol].DATA[fromSymbol][market][conversionKey],hitTimestamp); | |
if( invertPVC > directPVC && !overridePVC ){ | |
predConv = 'invert'; | |
tryNextStep = false; | |
} | |
} | |
if (tryNextStep && tradesIn(fromSymbol, conversionSymbol) && tradesIn(conversionSymbol, toSymbol)) { | |
multiplyPVC = calculateVolumePriceConversionCoefficient(globalCoinInfo[fromSymbol].DATA[conversionSymbol][market][conversionKey],globalCoinInfo[conversionSymbol].DATA[toSymbol][market][conversionKey],hitTimestamp); | |
if(multiplyPVC > directPVC && !overridePVC ){ | |
predConv = 'multiply'; | |
tryNextStep = false; | |
} | |
} | |
if (tryNextStep && tradesIn(fromSymbol, conversionSymbol) && tradesIn(toSymbol, conversionSymbol)) { | |
dividePVC = calculateVolumePriceConversionCoefficient(globalCoinInfo[fromSymbol].DATA[conversionSymbol][market][conversionKey],globalCoinInfo[toSymbol].DATA[conversionSymbol][market][conversionKey],hitTimestamp); | |
if(dividePVC > directPVC && !overridePVC ){ | |
predConv = 'divide'; | |
tryNextStep = false; | |
} | |
} | |
if (tryNextStep && tradesIn(conversionSymbol, fromSymbol) && tradesIn(toSymbol, conversionSymbol)) { | |
invertMultiplyPVC = calculateVolumePriceConversionCoefficient(globalCoinInfo[conversionSymbol].DATA[fromSymbol][market][conversionKey],globalCoinInfo[toSymbol].DATA[conversionSymbol][market][conversionKey],hitTimestamp); | |
if(invertMultiplyPVC > directPVC && !overridePVC ){ | |
predConv = 'invert_multiply'; | |
tryNextStep = false; | |
} | |
} | |
if (tryNextStep && tradesIn(conversionSymbol, fromSymbol) && tradesIn(conversionSymbol, toSymbol)) { | |
invertDividePVC = calculateVolumePriceConversionCoefficient(globalCoinInfo[conversionSymbol].DATA[fromSymbol][market][conversionKey],globalCoinInfo[conversionSymbol].DATA[toSymbol][market][conversionKey],hitTimestamp); | |
if(invertDividePVC > directPVC && !overridePVC ){ | |
predConv = 'invert_divide'; | |
tryNextStep = false; | |
} | |
} | |
} | |
tryNextStep = true; | |
if (predConv == 'invert') { | |
..... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment