Exemplo n.º 1
0
def _writeCustomAPI_HiveMacDesktopWallet(
        api_path, api_file_name, human_timestamp,
        calculated_average_rates_formatted, calculated_volumes_formatted,
        calculated_global_average_rates_formatted, exchanges_ignored):

    result = {}
    major_currencies = []
    index = 0
    for currency_code in CURRENCY_LIST:
        major_currencies.append(currency_code)
        index = index + 1
        if index == FRONTEND_MAJOR_CURRENCIES:
            break

    for currency_code in calculated_global_average_rates_formatted:
        if "24h_avg" in calculated_global_average_rates_formatted[
                currency_code]:
            result[currency_code] = {
                '24h_avg':
                calculated_global_average_rates_formatted[currency_code]
                ['24h_avg']
            }
        elif "last" in calculated_global_average_rates_formatted[
                currency_code]:
            result[currency_code] = {
                'last':
                calculated_global_average_rates_formatted[currency_code]
                ['last']
            }

    helpers.write_api_file(
        os.path.join(api_path, API_FILES['CUSTOM_API'], api_file_name),
        json.dumps(result))
def _writeCustomAPI_HiveAndroidWallet(api_path, api_file_name, human_timestamp, calculated_average_rates_formatted,
                                         calculated_volumes_formatted, calculated_global_average_rates_formatted,
                                         exchanges_ignored):

    result = {}
    major_currencies = []
    index = 0
    for currency_code in CURRENCY_LIST:
        major_currencies.append(currency_code)
        index = index + 1
        if index == FRONTEND_MAJOR_CURRENCIES:
            break

    for currency_code in calculated_global_average_rates_formatted:
        if "24h_avg" in calculated_global_average_rates_formatted[currency_code]:
            result[currency_code] = {'24h_avg': calculated_global_average_rates_formatted[currency_code]['24h_avg']}
        elif "last" in calculated_global_average_rates_formatted[currency_code]:
            result[currency_code] = {'last': calculated_global_average_rates_formatted[currency_code]['last']}

    helpers.write_api_file(
        os.path.join(api_path, API_FILES['CUSTOM_API'], api_file_name),
        json.dumps(result))
Exemplo n.º 3
0
def writeAPIFiles(api_path, timestamp, calculated_average_rates_formatted, calculated_volumes_formatted,
                  calculated_global_average_rates_formatted, exchanges_ignored):
    try:
        # /all
        all_data = {}
        all_data['timestamp'] = timestamp
        all_data['ignored_exchanges'] = exchanges_ignored
        for currency in CURRENCY_LIST:
            if (currency in calculated_volumes_formatted
            and currency in calculated_average_rates_formatted
            and currency in calculated_global_average_rates_formatted):
                cur_data = {'exchanges': calculated_volumes_formatted[currency],
                            'averages': calculated_average_rates_formatted[currency],
                            'global_averages': calculated_global_average_rates_formatted[currency],
                            }
                all_data[currency] = cur_data

        helpers.write_api_file(
            os.path.join(api_path, API_FILES['ALL_FILE']),
            json.dumps(all_data,  indent=2, sort_keys=True, separators=(',', ': ')))

        # /ticker/*
        for currency in CURRENCY_LIST:
            if (currency in calculated_volumes_formatted and currency in calculated_average_rates_formatted
            and currency in calculated_global_average_rates_formatted):
                ticker_cur = calculated_average_rates_formatted[currency]
                ticker_cur['timestamp'] = timestamp
                ticker_currency_path = os.path.join(api_path, API_FILES['TICKER_PATH'], currency)
                helpers.write_api_file(
                    os.path.join(ticker_currency_path, INDEX_DOCUMENT_NAME),
                    json.dumps(ticker_cur, indent=2, sort_keys=True, separators=(',', ': ')))
                for key in ticker_cur:
                    helpers.write_api_file(
                        os.path.join(ticker_currency_path, key),
                        str(ticker_cur[key]),
                        compress=False)

        # /ticker/all
        rates_all = calculated_average_rates_formatted
        rates_all['timestamp'] = timestamp
        helpers.write_api_file(
            os.path.join(api_path, API_FILES['TICKER_PATH'], 'all'),
            json.dumps(rates_all, indent=2, sort_keys=True, separators=(',', ': ')))

        # /ticker/global/*
        for currency in calculated_global_average_rates_formatted:
            ticker_cur = calculated_global_average_rates_formatted[currency]
            ticker_cur['timestamp'] = timestamp
            ticker_currency_path = os.path.join(api_path, API_FILES['GLOBAL_TICKER_PATH'], currency)
            helpers.write_api_file(
                os.path.join(ticker_currency_path, INDEX_DOCUMENT_NAME),
                json.dumps(ticker_cur, indent=2, sort_keys=True, separators=(',', ': ')))
            for key in ticker_cur:
                helpers.write_api_file(
                    os.path.join(ticker_currency_path, key),
                    str(ticker_cur[key]),
                    compress=False)

        # /ticker/global/all
        rates_all = calculated_global_average_rates_formatted
        rates_all['timestamp'] = timestamp
        try:
            helpers.write_api_file(
                os.path.join(api_path, API_FILES['GLOBAL_TICKER_PATH'], 'all'),
                json.dumps(rates_all, indent=2, sort_keys=True, separators=(',', ': ')))
        except IOError as error:
            #pass on Windows if there is currency with code ALL and it will interfer with file called 'all'
            pass

        # /exchanges/all
        volumes_all = calculated_volumes_formatted
        volumes_all['timestamp'] = timestamp
        helpers.write_api_file(
            os.path.join(api_path, API_FILES['EXCHANGES_PATH'], 'all'),
            json.dumps(volumes_all, indent=2, sort_keys=True, separators=(',', ': ')))

        # /exchanges/*
        for currency in CURRENCY_LIST:
            if (currency in calculated_volumes_formatted and currency in calculated_average_rates_formatted
                and currency in calculated_global_average_rates_formatted):
                volume_cur = calculated_volumes_formatted[currency]
                volume_cur['timestamp'] = timestamp
                helpers.write_api_file(
                    os.path.join(api_path, API_FILES['EXCHANGES_PATH'], currency),
                    json.dumps(volume_cur,  indent=2, sort_keys=True, separators=(',', ': ')))

        # /ignored
        helpers.write_api_file(
            os.path.join(api_path, API_FILES['IGNORED_FILE']),
            json.dumps(exchanges_ignored,  indent=2, sort_keys=True, separators=(',', ': ')))

    except IOError as error:
        error_text = '%s, %s ' % (sys.exc_info()[0], error)
        logger.error(error_text)
        raise error
Exemplo n.º 4
0
def writeAPIFiles(api_path, timestamp, calculated_average_rates_formatted,
                  calculated_volumes_formatted,
                  calculated_global_average_rates_formatted,
                  exchanges_ignored):
    try:
        # /all
        all_data = {}
        all_data['timestamp'] = timestamp
        all_data['ignored_exchanges'] = exchanges_ignored
        for currency in CURRENCY_LIST:
            if (currency in calculated_volumes_formatted
                    and currency in calculated_average_rates_formatted
                    and currency in calculated_global_average_rates_formatted):
                cur_data = {
                    'exchanges':
                    calculated_volumes_formatted[currency],
                    'averages':
                    calculated_average_rates_formatted[currency],
                    'global_averages':
                    calculated_global_average_rates_formatted[currency],
                }
                all_data[currency] = cur_data

        helpers.write_api_file(
            os.path.join(api_path, API_FILES['ALL_FILE']),
            json.dumps(all_data,
                       indent=2,
                       sort_keys=True,
                       separators=(',', ': ')))

        # /ticker/*
        for currency in CURRENCY_LIST:
            if (currency in calculated_volumes_formatted
                    and currency in calculated_average_rates_formatted
                    and currency in calculated_global_average_rates_formatted):
                ticker_cur = calculated_average_rates_formatted[currency]
                ticker_cur['timestamp'] = timestamp
                ticker_currency_path = os.path.join(api_path,
                                                    API_FILES['TICKER_PATH'],
                                                    currency)
                helpers.write_api_file(
                    os.path.join(ticker_currency_path, INDEX_DOCUMENT_NAME),
                    json.dumps(ticker_cur,
                               indent=2,
                               sort_keys=True,
                               separators=(',', ': ')))
                for key in ticker_cur:
                    helpers.write_api_file(os.path.join(
                        ticker_currency_path, key),
                                           str(ticker_cur[key]),
                                           compress=False)

        # /ticker/all
        rates_all = calculated_average_rates_formatted
        rates_all['timestamp'] = timestamp
        helpers.write_api_file(
            os.path.join(api_path, API_FILES['TICKER_PATH'], 'all'),
            json.dumps(rates_all,
                       indent=2,
                       sort_keys=True,
                       separators=(',', ': ')))

        # /ticker/global/*
        for currency in calculated_global_average_rates_formatted:
            ticker_cur = calculated_global_average_rates_formatted[currency]
            ticker_cur['timestamp'] = timestamp
            ticker_currency_path = os.path.join(
                api_path, API_FILES['GLOBAL_TICKER_PATH'], currency)
            helpers.write_api_file(
                os.path.join(ticker_currency_path, INDEX_DOCUMENT_NAME),
                json.dumps(ticker_cur,
                           indent=2,
                           sort_keys=True,
                           separators=(',', ': ')))
            for key in ticker_cur:
                helpers.write_api_file(os.path.join(ticker_currency_path, key),
                                       str(ticker_cur[key]),
                                       compress=False)

        # /ticker/global/all
        rates_all = calculated_global_average_rates_formatted
        rates_all['timestamp'] = timestamp
        try:
            helpers.write_api_file(
                os.path.join(api_path, API_FILES['GLOBAL_TICKER_PATH'], 'all'),
                json.dumps(rates_all,
                           indent=2,
                           sort_keys=True,
                           separators=(',', ': ')))
        except IOError as error:
            #pass on Windows if there is currency with code ALL and it will interfer with file called 'all'
            pass

        # /exchanges/all
        volumes_all = calculated_volumes_formatted
        volumes_all['timestamp'] = timestamp
        helpers.write_api_file(
            os.path.join(api_path, API_FILES['EXCHANGES_PATH'], 'all'),
            json.dumps(volumes_all,
                       indent=2,
                       sort_keys=True,
                       separators=(',', ': ')))

        # /exchanges/*
        for currency in CURRENCY_LIST:
            if (currency in calculated_volumes_formatted
                    and currency in calculated_average_rates_formatted
                    and currency in calculated_global_average_rates_formatted):
                volume_cur = calculated_volumes_formatted[currency]
                volume_cur['timestamp'] = timestamp
                helpers.write_api_file(
                    os.path.join(api_path, API_FILES['EXCHANGES_PATH'],
                                 currency),
                    json.dumps(volume_cur,
                               indent=2,
                               sort_keys=True,
                               separators=(',', ': ')))

        # /ignored
        helpers.write_api_file(
            os.path.join(api_path, API_FILES['IGNORED_FILE']),
            json.dumps(exchanges_ignored,
                       indent=2,
                       sort_keys=True,
                       separators=(',', ': ')))

    except IOError as error:
        error_text = '%s, %s ' % (sys.exc_info()[0], error)
        logger.error(error_text)
        raise error