def testComputeCryptoFiatRate_current_CHSB_USD(self):
        PRINT = False

        cryptoFiatCsvFileName = 'cryptoFiatExchange.csv'
        self.initializeComputerClasses(cryptoFiatCsvFileName)

        crypto = 'CHSB'
        unit = 'BTC'
        fiat = 'USD'
        exchange1 = 'HitBTC'
        exchange2 = 'Kraken'
        priceRequester = PriceRequester()

        actualCryptoFiatRate = self.cryptoFiatRateComputer.computeCryptoFiatRate(
            crypto, fiat)

        resultData = priceRequester.getCurrentPrice(crypto, unit, exchange1)
        cryptoUnitRate = resultData.getValue(resultData.RESULT_KEY_PRICE)
        resultData = priceRequester.getCurrentPrice(unit, fiat, exchange2)
        unitFiatRate = resultData.getValue(resultData.RESULT_KEY_PRICE)
        expectedCryptoFiatRate = cryptoUnitRate * unitFiatRate

        if PRINT:
            print(actualCryptoFiatRate)
        else:
            self.assertAlmostEqual(expectedCryptoFiatRate,
                                   actualCryptoFiatRate, 3)
Example #2
0
	def setUp(self):
		if os.name == 'posix':
			FILE_PATH = '/sdcard/cryptopricer.ini'
		else:
			FILE_PATH = 'c:\\temp\\cryptopricer.ini'

		self.priceRequester = PriceRequester()
Example #3
0
    def setUp(self):
        if os.name == 'posix':
            FILE_PATH = '/sdcard/cryptopricer.ini'
        else:
            FILE_PATH = 'c:\\temp\\cryptopricer.ini'

        self.configMgr = ConfigurationManager(FILE_PATH)
        self.priceRequester = PriceRequester()
    def initializeComputerClasses(self, cryptoFiatCsvFileName):
        if os.name == 'posix':
            dataPath = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/SByield/data/'
            cryptoFiatCsvFilePathName = dataPath + cryptoFiatCsvFileName
        else:
            dataPath = 'D:\\Development\\Python\\SByield\\data\\'
            cryptoFiatCsvFilePathName = dataPath + cryptoFiatCsvFileName

        self.cryptoFiatRateComputer = CryptoFiatRateComputer(
            PriceRequester(), cryptoFiatCsvFilePathName)
Example #5
0
    def setUp(self):
        if os.name == 'posix':
            FILE_PATH = '/sdcard/cryptopricer.ini'
        else:
            FILE_PATH = 'c:\\temp\\cryptopricer.ini'

        self.configMgr = ConfigurationManager(FILE_PATH)
        self.priceRequester = PriceRequester()
        self.crypCompExchanges = CrypCompExchanges()
        self.processor = Processor(self.configMgr, self.priceRequester,
                                   self.crypCompExchanges)
    def testComputeCryptoFiatRate_current_ETH_USD(self):
        PRINT = False

        cryptoFiatCsvFileName = 'cryptoFiatExchange.csv'
        self.initializeComputerClasses(cryptoFiatCsvFileName)

        crypto = 'ETH'
        fiat = 'USD'
        exchange = 'Kraken'
        priceRequester = PriceRequester()

        actualCryptoFiatRate = self.cryptoFiatRateComputer.computeCryptoFiatRate(
            crypto, fiat)
        resultData = priceRequester.getCurrentPrice(crypto, fiat, exchange)
        expectedCryptoFiatRate = resultData.getValue(
            resultData.RESULT_KEY_PRICE)

        if PRINT:
            print(actualCryptoFiatRate)
        else:
            self.assertAlmostEqual(expectedCryptoFiatRate,
                                   actualCryptoFiatRate, 1)
Example #7
0
def main():
    '''
	Maincl means main command line !
	Command line main which instanciate a Controller which uses a ConsoleOutputFormatter
	instead of a GuiOutputFormatter, what maingui does !
	'''
    if os.name == 'posix':
        configPath = '/sdcard/cryptopricer.ini'
    else:
        configPath = 'c:\\temp\\cryptopricer.ini'

    configMgr = ConfigurationManager(configPath)
    controller = Controller(ConsoleOutputFormatter(configMgr), configMgr,
                            PriceRequester())

    controller.commandLineLoop()
Example #8
0
    def computeYield(self, sbAccountSheetFileName, yieldCrypto,
                     sbAccountSheetFiat, language):
        if yieldCrypto == SB_ACCOUNT_SHEET_CURRENCY_USDC:
            depositSheetFileName = 'depositUsdc.csv'
        elif yieldCrypto == SB_ACCOUNT_SHEET_CURRENCY_CHSB:
            depositSheetFileName = 'depositChsb.csv'
        elif yieldCrypto == SB_ACCOUNT_SHEET_CURRENCY_ETH:
            depositSheetFileName = 'depositEth.csv'
        elif yieldCrypto == SB_ACCOUNT_SHEET_CURRENCY_BNB:
            depositSheetFileName = 'depositBnb.csv'
        else:
            raise ValueError(
                'Yield crypto {} not supported. Program closed.'.format(
                    yieldCrypto))

        cryptoFiatCsvFileName = 'cryptoFiatExchange.csv'

        if os.name == 'posix':
            dataPath = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/SByield/data/'
            sbAccountSheetFilePathName = dataPath + sbAccountSheetFileName
            depositSheetFilePathName = dataPath + depositSheetFileName
        else:
            dataPath = 'D:\\Development\\Python\\SByield\\data\\'
            sbAccountSheetFilePathName = dataPath + sbAccountSheetFileName
            depositSheetFilePathName = dataPath + depositSheetFileName

        sbYieldRateComputer = SBYieldRateComputer(
            sbAccountSheetFilePathName=sbAccountSheetFilePathName,
            sbAccountSheetFiat=sbAccountSheetFiat,
            depositSheetFilePathName=depositSheetFilePathName)
        self.ownerDepositYieldComputer = OwnerDepositYieldComputer(
            sbYieldRateComputer)

        cryptoFiatCsvFilePathName = dataPath + cryptoFiatCsvFileName
        processor = Processor(
            sbYieldRateComputer, self.ownerDepositYieldComputer,
            CryptoFiatRateComputer(PriceRequester(),
                                   cryptoFiatCsvFilePathName),
            sbAccountSheetFiat, language)

        processor.activateHelpNumbers()

        return processor.addFiatConversionInfo()
Example #9
0
    def __init__(self, printer, configMgr):
        if os.name == 'posix':
            FILE_PATH = '/sdcard/cryptopricer.ini'
        else:
            FILE_PATH = 'c:\\temp\\cryptopricer.ini'

        self.configMgr = configMgr
        self.priceRequester = PriceRequester()
        self.crypCompTranslator = CrypCompExchanges()
        self.processor = Processor(self.configMgr, self.priceRequester, self.crypCompTranslator)
        self.requester = Requester(self.configMgr)

        self.commandPrice = CommandPrice(self.processor, self.configMgr)
        self.commandCrypto = CommandCrypto(self.processor)
        self.requester.commandPrice = self.commandPrice
        self.requester.commandCrypto = self.commandCrypto

        self.commandQuit = CommandQuit(sys)
        self.requester.commandQuit = self.commandQuit

        self.commandError = CommandError(None)
        self.requester.commandError = self.commandError

        self.printer = printer
Example #10
0

if __name__ == '__main__':
    from configurationmanager import ConfigurationManager
    from pricerequester import PriceRequester
    from crypcompexchanges import CrypCompExchanges
    from processor import Processor
    import os

    if os.name == 'posix':
        FILE_PATH = '/sdcard/cryptopricer.ini'
    else:
        FILE_PATH = 'c:\\temp\\cryptopricer.ini'

    cm = ConfigurationManager(FILE_PATH)
    pr = PriceRequester()
    cryp = CrypCompExchanges()
    proc = Processor(cm, pr, cryp)

    cpr = CommandPrice(proc, cm)

    print('HISTORICAL')

    cpr.parsedParmData[cpr.CRYPTO] = 'btc'
    cpr.parsedParmData[cpr.FIAT] = 'usd'
    cpr.parsedParmData[cpr.EXCHANGE] = 'bittrex'
    cpr.parsedParmData[cpr.DAY] = '12'
    cpr.parsedParmData[cpr.MONTH] = '9'
    cpr.parsedParmData[cpr.YEAR] = '2017'
    cpr.parsedParmData[cpr.HOUR] = '10'
    cpr.parsedParmData[cpr.MINUTE] = '5'
Example #11
0
class TestPriceRequester(unittest.TestCase):
    def setUp(self):
        if os.name == 'posix':
            FILE_PATH = '/sdcard/cryptopricer.ini'
        else:
            FILE_PATH = 'c:\\temp\\cryptopricer.ini'

        self.configMgr = ConfigurationManager(FILE_PATH)
        self.priceRequester = PriceRequester()


    def test_getHistoDayPriceAtUTCTimeStampEndOfDay(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'CCCAGG'
        utcArrowDateTimeObj_endOfDay = DateTimeUtil.dateTimeStringToArrowLocalDate("2017/09/30 23:59:59", 'UTC',
                                                                                   "YYYY/MM/DD HH:mm:ss")
        resultData = ResultData()
        resultData = self.priceRequester._getHistoDayPriceAtUTCTimeStamp(crypto,
                                                                          fiat,
                                                                          utcArrowDateTimeObj_endOfDay.timestamp,
                                                                          exchange,
                                                                          resultData)
        self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
                                                                       'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual('30/09/17', priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))


    def test_getHistoDayPriceAtUTCTimeStampMidOfDay(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'CCCAGG'
        utcArrowDateTimeObj_midOfDay = DateTimeUtil.dateTimeStringToArrowLocalDate("2017/09/30 12:59:59", 'UTC',
                                                                                   "YYYY/MM/DD HH:mm:ss")
        resultData = ResultData()
        resultData = self.priceRequester._getHistoDayPriceAtUTCTimeStamp(crypto,
                                                                          fiat,
                                                                          utcArrowDateTimeObj_midOfDay.timestamp,
                                                                          exchange,
                                                                          resultData)
        self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
                                                                       'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual('30/09/17', priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))


    def testGetHistoricalPriceAtUTCTimeStampEndOfDay(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'CCCAGG'
        timeStampLocal = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 23:59:59", 'Europe/Zurich',
                                                                "YYYY/MM/DD HH:mm:ss")
        timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 00:00:00", 'UTC',
                                                                    "YYYY/MM/DD HH:mm:ss")
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto, fiat,
                                                                             timeStampLocal,
                                                                             timeStampUtcNoHHMM,
                                                                             exchange)
        self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
                                                                       'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual('30/09/17', priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetHistoricalPriceAtUTCTimeStampMidOfDay(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'CCCAGG'

        timeStampLocal = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 12:59:59", 'Europe/Zurich',
                                                                "YYYY/MM/DD HH:mm:ss")
        timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 00:00:00", 'UTC',
                                                                    "YYYY/MM/DD HH:mm:ss")
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto, fiat,
                                                                             timeStampLocal,
                                                                             timeStampUtcNoHHMM,
                                                                             exchange)

        self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
                                                                       'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual('30/09/17', priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetHistoricalPriceAtTimeStampZurichMidOfDayUseTimeStamp(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'CCCAGG'

        #time stamp is always UTC !
        timeStampLocalMidDay = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 12:59:59", 'Europe/Zurich',
                                                                "YYYY/MM/DD HH:mm:ss")
        timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 00:00:00", 'UTC',
                                                                    "YYYY/MM/DD HH:mm:ss")
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto, fiat,
                                                                             timeStampLocalMidDay,
                                                                             timeStampUtcNoHHMM,
                                                                             exchange)
        self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
                                                                       'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual('30/09/17', priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetHistoricalPriceAtUTCTimeStampLessThanSevenDay(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'CCCAGG'
        utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
        utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-2)

        # for histominute price,
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto, fiat,
                                                                             utcArrowDateTimeObj.timestamp,
                                                                             utcArrowDateTimeObj.timestamp,
                                                                             exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_MINUTE)
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetCurrentPrice(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'CCCAGG'

        resultData = self.priceRequester.getCurrentPrice(crypto, fiat, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetHistoricalPriceAtUTCTimeStampLessThanSevenDayWrongExchange(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'unknown'

        utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
        utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-2)

        #here, since histominute price is fetched, time stamp UTC no HHMM for histoDay wil not be used !
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto, fiat,
                                                                             utcArrowDateTimeObj.timestamp,
                                                                             utcArrowDateTimeObj.timestamp,
                                                                             exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_MINUTE)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - unknown market does not exist for this coin pair (BTC-USD)")
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetHistoricalPriceAtUTCTimeStampMoreThanSevenDayWrongExchange(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'unknown'

        utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
        utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-12)

        #here, since histominute price is fetched, time stamp UTC no HHMM for histoDay wil not be used !
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto, fiat,
                                                                             utcArrowDateTimeObj.timestamp,
                                                                             utcArrowDateTimeObj.timestamp,
                                                                             exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - unknown market does not exist for this coin pair (BTC-USD)")
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetHistoricalPriceAtUTCTimeStampMidOfDayWrongExchange(self):
        crypto = 'BTC'

        fiat = 'USD'
        exchange = 'unknown'
        #time stamp is always UTC !
        timeStampLocalMidDay = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 12:59:59", 'Europe/Zurich',
                                                                "YYYY/MM/DD HH:mm:ss")
        timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 00:00:00", 'UTC',
                                                                    "YYYY/MM/DD HH:mm:ss")
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto,
                                                                           fiat,
                                                                           timeStampLocalMidDay,
                                                                           timeStampUtcNoHHMM,
                                                                           exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - unknown market does not exist for this coin pair (BTC-USD)")
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetCurrentPriceWrongExchange(self):
        crypto = 'BTC'
        fiat = 'USD'
        exchange = 'unknown'

        resultData = self.priceRequester.getCurrentPrice(crypto, fiat, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - unknown market does not exist for this coin pair (BTC-USD)")
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetCurrentPriceWrongCrypto(self):
        crypto = 'BTa'
        fiat = 'USD'
        exchange = 'all'

        resultData = self.priceRequester.getCurrentPrice(crypto, fiat, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - There is no data for the symbol BTa")
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


    def testGetCurrentPriceWrongFiat(self):
        crypto = 'BTC'
        fiat = 'USL'
        exchange = 'all'

        resultData = self.priceRequester.getCurrentPrice(crypto, fiat, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - There is no data for any of the toSymbols USL")
        self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(fiat, resultData.getValue(resultData.RESULT_KEY_FIAT))
        self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))
Example #12
0
			print(resultData.getAllWarningMessages())

		return isProblem


if __name__ == "__main__":
	cryptoFiatCsvFileName = 'cryptoFiatExchange.csv'
	
	if os.name == 'posix':
		dataPath = '/storage/emulated/0/Android/data/ru.iiec.pydroid3/files/SByield/data/'
		cryptoFiatCsvFilePathName = dataPath + cryptoFiatCsvFileName
	else:
		dataPath = 'D:\\Development\\Python\\SByield\\data\\'
		cryptoFiatCsvFilePathName = dataPath + cryptoFiatCsvFileName

	cfc = CryptoFiatRateComputer(PriceRequester(),
								 cryptoFiatCsvFilePathName)

	print(cfc.cryptoFiatDf)

	crypto = 'CHSB'
	fiat = 'CHF'

	unitFiatDf = cfc.cryptoFiatDf.loc[cryptoFiatDf['UNIT'] == fiat]
	print('Available unitFiatDf')
	print(unitFiatDf)

	for index, row in unitFiatDf.iterrows():
		cfc.cryptoUnitDf = cfc.cryptoFiatDf.loc[(cfc.cryptoFiatDf['CRYPTO'] == crypto) & (cfc.cryptoFiatDf['UNIT'] == row['CRYPTO'])]
		if not cfc.cryptoUnitDf.empty:
			print('self.cryptoUnitDf')
Example #13
0
            nameU = name.upper()
            if not nameU in self._dic:
                print("'{}': ['{}', 'ETH', 'BTC'],".format(nameU, name))


if __name__ == '__main__':
    from pricerequester import PriceRequester
    from resultdata import ResultData
    import sys

    cc = CrypCompExchanges()

    # cc._checkIfHandled()
    # sys.exit(0)

    pp = PriceRequester()

    ts = 1506729600

    keyList = cc._dic.keys()

    print('\n--- HISTO PRICES ---\n')

    for key in keyList:
        exchTestData = cc._getExchangeTestData(key)
        exch = exchTestData[0]
        fiat = exchTestData[2]
        crypto = exchTestData[1]

        resultData = pp.getHistoricalPriceAtUTCTimeStamp(
            crypto, fiat, ts, ts, exch)
Example #14
0
class TestPriceRequester(unittest.TestCase):
	def setUp(self):
		if os.name == 'posix':
			FILE_PATH = '/sdcard/cryptopricer.ini'
		else:
			FILE_PATH = 'c:\\temp\\cryptopricer.ini'

		self.priceRequester = PriceRequester()


	def test_getHistoDayPriceAtUTCTimeStampEndOfDay(self):
		crypto = 'BTC'
		unit = 'USD'
		exchange = 'CCCAGG'
		utcArrowDateTimeObj_endOfDay = DateTimeUtil.dateTimeStringToArrowLocalDate("2017/09/30 23:59:59", 'UTC',
																				   "YYYY/MM/DD HH:mm:ss")
		resultData = ResultData()
		resultData = self.priceRequester._getHistoDayPriceAtUTCTimeStamp(crypto,
																		  unit,
																		  utcArrowDateTimeObj_endOfDay.int_timestamp,
																		  exchange,
																		  resultData)
		self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
		priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
																	   'UTC')
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
		self.assertEqual('30/09/17', priceArrowUTCDateTime.format('DD/MM/YY'))
		self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))


	def test_getHistoDayPriceAtUTCTimeStampMidOfDay(self):
		crypto = 'BTC'
		unit = 'USD'
		exchange = 'CCCAGG'
		utcArrowDateTimeObj_midOfDay = DateTimeUtil.dateTimeStringToArrowLocalDate("2017/09/30 12:59:59", 'UTC',
																				   "YYYY/MM/DD HH:mm:ss")
		resultData = ResultData()
		resultData = self.priceRequester._getHistoDayPriceAtUTCTimeStamp(crypto,
																		  unit,
																		  utcArrowDateTimeObj_midOfDay.int_timestamp,
																		  exchange,
																		  resultData)
		self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
		priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
																	   'UTC')
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
		self.assertEqual('30/09/17', priceArrowUTCDateTime.format('DD/MM/YY'))
		self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))


	def testGetHistoricalPriceAtUTCTimeStampEndOfDay(self):
		crypto = 'BTC'
		unit = 'USD'
		exchange = 'CCCAGG'
		localTimeZone = 'Europe/Zurich'
		timeStampLocal = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 23:59:59", localTimeZone,
																"YYYY/MM/DD HH:mm:ss")
		timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 00:00:00", 'UTC',
																	"YYYY/MM/DD HH:mm:ss")
		resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto,
																		  unit,
																		  timeStampLocal,
																		  localTimeZone,
																		  timeStampUtcNoHHMM,
																		  exchange)
		self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
		priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
																	   'UTC')
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
		self.assertEqual('30/09/17', priceArrowUTCDateTime.format('DD/MM/YY'))
		self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


	def testGetHistoricalPriceAtUTCTimeStampMidOfDay(self):
		crypto = 'BTC'
		unit = 'USD'
		exchange = 'CCCAGG'
		localTimeZone = 'Europe/Zurich'

		timeStampLocal = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 12:59:59", localTimeZone,
																"YYYY/MM/DD HH:mm:ss")
		timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 00:00:00", 'UTC',
																	"YYYY/MM/DD HH:mm:ss")
		resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto,
																		  unit,
																		  timeStampLocal,
																		  localTimeZone,
																		  timeStampUtcNoHHMM,
																		  exchange)

		self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
		priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
																	   'UTC')
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
		self.assertEqual('30/09/17', priceArrowUTCDateTime.format('DD/MM/YY'))
		self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


	def testGetHistoricalPriceAtTimeStampZurichMidOfDayUseTimeStamp(self):
		crypto = 'BTC'
		unit = 'USD'
		exchange = 'CCCAGG'

		#time stamp is always UTC !
		timeStampLocalMidDay = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 12:59:59", 'Europe/Zurich',
																"YYYY/MM/DD HH:mm:ss")
		timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp("2017/09/30 00:00:00", 'UTC',
																	"YYYY/MM/DD HH:mm:ss")
		resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto, unit,
																		  timeStampLocalMidDay,
																		  'Europe/Zurich',
																		  timeStampUtcNoHHMM,
																		  exchange)
		self.assertEqual(1506729600, resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
		priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP),
																	   'UTC')
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_DAY)
		self.assertEqual('30/09/17', priceArrowUTCDateTime.format('DD/MM/YY'))
		self.assertEqual(4360.62, resultData.getValue(resultData.RESULT_KEY_PRICE))
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


	def testGetHistoricalPriceAtUTCTimeStampLessThanSevenDay(self):
		crypto = 'BTC'
		unit = 'USD'
		exchange = 'CCCAGG'
		utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
		utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-2)

		# for histominute price,
		resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(crypto,
																		  unit,
																		  timeStampLocalForHistoMinute=utcArrowDateTimeObj.int_timestamp,
																		  localTz=None,
																		  timeStampUTCNoHHMMForHistoDay=utcArrowDateTimeObj.int_timestamp,
																		  exchange=exchange)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_HISTO_MINUTE)
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


	def testGetCurrentPrice(self):
		crypto = 'BTC'
		unit = 'USD'
		exchange = 'CCCAGG'

		resultData = self.priceRequester.getCurrentPrice(crypto, unit, exchange)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

	def testGetCurrentPriceWrongExchange(self):
		crypto = 'BTC'
		unit = 'USD'
		exchange = 'unknown'

		resultData = self.priceRequester.getCurrentPrice(crypto, unit, exchange)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - unknown market does not exist for this coin pair (BTC/USD).")
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


	def testGetCurrentPriceWrongCrypto(self):
		crypto = 'BBB'
		unit = 'USD'
		exchange = 'all'

		resultData = self.priceRequester.getCurrentPrice(crypto, unit, exchange)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
		self.assertEqual("PROVIDER ERROR - all market does not exist for this coin pair (BBB/USD).", resultData.getValue(resultData.RESULT_KEY_ERROR_MSG))
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


	def testGetCurrentPriceWrongPair(self):
		crypto = 'BTA'
		unit = 'CHF'
		exchange = 'all'

		resultData = self.priceRequester.getCurrentPrice(crypto, unit, exchange)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - all market does not exist for this coin pair (BTA/CHF).")
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))


	def testGetCurrentPriceWrongUnit(self):
		crypto = 'BTC'
		unit = 'USL'
		exchange = 'all'

		resultData = self.priceRequester.getCurrentPrice(crypto, unit, exchange)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE), resultData.PRICE_TYPE_RT)
		self.assertEqual(resultData.getValue(resultData.RESULT_KEY_ERROR_MSG), "PROVIDER ERROR - all market does not exist for this coin pair (BTC/USL).")
		self.assertEqual(crypto, resultData.getValue(resultData.RESULT_KEY_CRYPTO))
		self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
		self.assertEqual(exchange, resultData.getValue(resultData.RESULT_KEY_EXCHANGE))
class TestPriceRequester(unittest.TestCase):
    def setUp(self):
        if os.name == 'posix':
            FILE_PATH = '/sdcard/cryptopricer.ini'
        else:
            FILE_PATH = 'c:\\temp\\cryptopricer.ini'

        self.configMgr = ConfigurationManager(FILE_PATH)
        self.priceRequester = PriceRequester()

    def test_getHistoDayPriceAtUTCTimeStampEndOfDay(self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'CCCAGG'
        utcArrowDateTimeObj_endOfDay = DateTimeUtil.dateTimeStringToArrowLocalDate(
            "2017/09/30 23:59:59", 'UTC', "YYYY/MM/DD HH:mm:ss")
        resultData = ResultData()
        resultData = self.priceRequester._getHistoDayPriceAtUTCTimeStamp(
            crypto, unit, utcArrowDateTimeObj_endOfDay.timestamp(), exchange,
            resultData)
        self.assertEqual(
            1506729600,
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP), 'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(
            '30/09/17',
            priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62,
                         resultData.getValue(resultData.RESULT_KEY_PRICE))

    def test_getHistoDayPriceAtUTCTimeStampMidOfDay(self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'CCCAGG'
        utcArrowDateTimeObj_midOfDay = DateTimeUtil.dateTimeStringToArrowLocalDate(
            "2017/09/30 12:59:59", 'UTC', "YYYY/MM/DD HH:mm:ss")
        resultData = ResultData()
        resultData = self.priceRequester._getHistoDayPriceAtUTCTimeStamp(
            crypto, unit, utcArrowDateTimeObj_midOfDay.timestamp(), exchange,
            resultData)
        self.assertEqual(
            1506729600,
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP), 'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(
            '30/09/17',
            priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62,
                         resultData.getValue(resultData.RESULT_KEY_PRICE))

    def testGetHistoricalPriceAtUTCTimeStampEndOfDay(self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'CCCAGG'
        localTimeZone = 'Europe/Zurich'
        timeStampLocal = DateTimeUtil.dateTimeStringToTimeStamp(
            "2017/09/30 23:59:59", localTimeZone, "YYYY/MM/DD HH:mm:ss")
        timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp(
            "2017/09/30 00:00:00", 'UTC', "YYYY/MM/DD HH:mm:ss")
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto, unit, timeStampLocal, localTimeZone, timeStampUtcNoHHMM,
            exchange)
        self.assertEqual(
            1506729600,
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP), 'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(
            '30/09/17',
            priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62,
                         resultData.getValue(resultData.RESULT_KEY_PRICE))
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetHistoricalPriceAtUTCTimeStampMidOfDay(self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'CCCAGG'
        localTimeZone = 'Europe/Zurich'

        timeStampLocal = DateTimeUtil.dateTimeStringToTimeStamp(
            "2017/09/30 12:59:59", localTimeZone, "YYYY/MM/DD HH:mm:ss")
        timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp(
            "2017/09/30 00:00:00", 'UTC', "YYYY/MM/DD HH:mm:ss")
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto, unit, timeStampLocal, localTimeZone, timeStampUtcNoHHMM,
            exchange)

        self.assertEqual(
            1506729600,
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP), 'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(
            '30/09/17',
            priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62,
                         resultData.getValue(resultData.RESULT_KEY_PRICE))
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetHistoricalPriceAtTimeStampZurichMidOfDayUseTimeStamp(self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'CCCAGG'

        #time stamp is always UTC !
        timeStampLocalMidDay = DateTimeUtil.dateTimeStringToTimeStamp(
            "2017/09/30 12:59:59", 'Europe/Zurich', "YYYY/MM/DD HH:mm:ss")
        timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp(
            "2017/09/30 00:00:00", 'UTC', "YYYY/MM/DD HH:mm:ss")
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto, unit, timeStampLocalMidDay, 'Europe/Zurich',
            timeStampUtcNoHHMM, exchange)
        self.assertEqual(
            1506729600,
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP))
        priceArrowUTCDateTime = DateTimeUtil.timeStampToArrowLocalDate(
            resultData.getValue(resultData.RESULT_KEY_PRICE_TIME_STAMP), 'UTC')
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(
            '30/09/17',
            priceArrowUTCDateTime.format(self.configMgr.dateOnlyFormat))
        self.assertEqual(4360.62,
                         resultData.getValue(resultData.RESULT_KEY_PRICE))
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetHistoricalPriceAtUTCTimeStampLessThanSevenDay(self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'CCCAGG'
        utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
        utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-2)

        # for histominute price,
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto,
            unit,
            timeStampLocalForHistoMinute=utcArrowDateTimeObj.timestamp(),
            localTz=None,
            timeStampUTCNoHHMMForHistoDay=utcArrowDateTimeObj.timestamp(),
            exchange=exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_MINUTE)
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetHistoricalPriceAtUTCTimeStampLessThanSevenDay_USD_CHF(self):
        crypto = 'USD'
        unit = 'CHF'
        exchange = 'CCCAGG'
        now = DateTimeUtil.localNow('Europe/Zurich')
        oneDaysBeforeArrowDate = now.shift(days=-1).date()

        utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
        utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-1)
        utcArrowDateTimeStamp = DateTimeUtil.shiftTimeStampToEndOfDay(
            utcArrowDateTimeObj.timestamp())

        # for histominute price,
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto,
            unit,
            timeStampLocalForHistoMinute=utcArrowDateTimeStamp,
            localTz=None,
            timeStampUTCNoHHMMForHistoDay=utcArrowDateTimeStamp,
            exchange=exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_MINUTE)
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetCurrentPrice(self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'CCCAGG'

        resultData = self.priceRequester.getCurrentPrice(
            crypto, unit, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_RT)
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetHistoricalPriceAtUTCTimeStampLessThanSevenDayWrongExchange(
            self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'unknown'

        utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
        utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-2)

        #here, since histominute price is fetched, time stamp UTC no HHMM for histoDay wil not be used !
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto,
            unit,
            timeStampLocalForHistoMinute=utcArrowDateTimeObj.timestamp(),
            localTz=None,
            timeStampUTCNoHHMMForHistoDay=utcArrowDateTimeObj.timestamp(),
            exchange=exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_MINUTE)
        self.assertEqual(
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG),
            "PROVIDER ERROR - unknown market does not exist for this coin pair (BTC/USD)."
        )
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetHistoricalPriceAtUTCTimeStampMoreThanSevenDayWrongExchange(
            self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'unknown'

        utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
        utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-12)

        #here, since histominute price is fetched, time stamp UTC no HHMM for histoDay wil not be used !
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto,
            unit,
            timeStampLocalForHistoMinute=utcArrowDateTimeObj.timestamp(),
            localTz=None,
            timeStampUTCNoHHMMForHistoDay=utcArrowDateTimeObj.timestamp(),
            exchange=exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG),
            "PROVIDER ERROR - unknown market does not exist for this coin pair (BTC/USD)."
        )
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetHistoricalPriceAtUTCTimeStampMoreThanSevenDayForCryptoUnitPairNotSupportedByExchange(
            self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'Binance'

        utcArrowDateTimeObj = DateTimeUtil.localNow('UTC')
        utcArrowDateTimeObj = utcArrowDateTimeObj.shift(days=-12)

        #here, since histominute price is fetched, time stamp UTC no HHMM for histoDay wil not be used !
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto,
            unit,
            timeStampLocalForHistoMinute=utcArrowDateTimeObj.timestamp(),
            localTz=None,
            timeStampUTCNoHHMMForHistoDay=utcArrowDateTimeObj.timestamp(),
            exchange=exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG),
            "PROVIDER ERROR - Binance market does not exist for this coin pair (BTC/USD)."
        )
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetMinuteHistoricalPriceForCryptoUnitPairNotSupportedByExchange(
            self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'Binance'
        localTimeZone = 'Europe/Zurich'
        #time stamp is always UTC !
        now = DateTimeUtil.localNow(localTimeZone)
        timeStampLocalNow = now.timestamp()
        timeStampUtcNow = DateTimeUtil.utcNowTimeStamp()
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto, unit, timeStampLocalNow, localTimeZone, timeStampUtcNow,
            exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_MINUTE)
        self.assertEqual(
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG),
            "PROVIDER ERROR - Binance market does not exist for this coin pair (BTC/USD)."
        )
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetHistoricalPriceAtUTCTimeStampMidOfDayWrongExchange(self):
        crypto = 'BTC'

        unit = 'USD'
        exchange = 'Binance'
        localTimeZone = 'Europe/Zurich'
        #time stamp is always UTC !
        timeStampLocalMidDay = DateTimeUtil.dateTimeStringToTimeStamp(
            "2017/09/30 12:59:59", localTimeZone, "YYYY/MM/DD HH:mm:ss")
        timeStampUtcNoHHMM = DateTimeUtil.dateTimeStringToTimeStamp(
            "2017/09/30 00:00:00", 'UTC', "YYYY/MM/DD HH:mm:ss")
        resultData = self.priceRequester.getHistoricalPriceAtUTCTimeStamp(
            crypto, unit, timeStampLocalMidDay, localTimeZone,
            timeStampUtcNoHHMM, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_HISTO_DAY)
        self.assertEqual(
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG),
            "PROVIDER ERROR - Binance market does not exist for this coin pair (BTC/USD)."
        )
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetCurrentPriceWrongExchange(self):
        crypto = 'BTC'
        unit = 'USD'
        exchange = 'unknown'

        resultData = self.priceRequester.getCurrentPrice(
            crypto, unit, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_RT)
        self.assertEqual(
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG),
            "PROVIDER ERROR - unknown market does not exist for this coin pair (BTC/USD)."
        )
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetCurrentPriceWrongCrypto(self):
        crypto = 'BBB'
        unit = 'USD'
        exchange = 'all'

        resultData = self.priceRequester.getCurrentPrice(
            crypto, unit, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_RT)
        self.assertEqual(
            "PROVIDER ERROR - all market does not exist for this coin pair (BBB/USD).",
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG))
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetCurrentPriceWrongPair(self):
        crypto = 'BTA'
        unit = 'CHF'
        exchange = 'all'

        resultData = self.priceRequester.getCurrentPrice(
            crypto, unit, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_RT)
        self.assertEqual(
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG),
            "PROVIDER ERROR - all market does not exist for this coin pair (BTA/CHF)."
        )
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))

    def testGetCurrentPriceWrongUnit(self):
        crypto = 'BTC'
        unit = 'USL'
        exchange = 'all'

        resultData = self.priceRequester.getCurrentPrice(
            crypto, unit, exchange)
        self.assertEqual(resultData.getValue(resultData.RESULT_KEY_PRICE_TYPE),
                         resultData.PRICE_TYPE_RT)
        self.assertEqual(
            resultData.getValue(resultData.RESULT_KEY_ERROR_MSG),
            "PROVIDER ERROR - all market does not exist for this coin pair (BTC/USL)."
        )
        self.assertEqual(crypto,
                         resultData.getValue(resultData.RESULT_KEY_CRYPTO))
        self.assertEqual(unit, resultData.getValue(resultData.RESULT_KEY_UNIT))
        self.assertEqual(exchange,
                         resultData.getValue(resultData.RESULT_KEY_EXCHANGE))