if ba.server.LOG_PATH == '': ba.server.LOG_PATH = os.path.join(ba.server.PROJECT_PATH, 'runtime', 'app.log') if ba.server.API_DOCUMENT_ROOT == '': ba.server.API_DOCUMENT_ROOT = os.path.join(ba.server.PROJECT_PATH, 'api') ba.server.API_DOCUMENT_ROOT_NOGOX = os.path.join( ba.server.API_DOCUMENT_ROOT, 'no-mtgox') if ba.server.WWW_DOCUMENT_ROOT == '': ba.server.WWW_DOCUMENT_ROOT = os.path.join(ba.server.PROJECT_PATH, 'www') if ba.server.HISTORY_DOCUMENT_ROOT == '': ba.server.HISTORY_DOCUMENT_ROOT = os.path.join(ba.server.PROJECT_PATH, 'api', 'history') helpers.write_log('script started', 'LOG') helpers.write_js_config() helpers.write_fiat_rates_config() last_fiat_exchange_rate_update = time.time() helpers.write_api_index_files() while True: if last_fiat_exchange_rate_update < int( time.time()) - FIAT_RATES_QUERY_FREQUENCY: helpers.write_fiat_rates_config() start_time = int(time.time()) exchanges_rates, exchanges_ignored = ba.api_parsers.callAll() total_currency_volumes, total_currency_volumes_ask, total_currency_volumes_bid = calculateTotalVolumes( exchanges_rates) calculated_volumes = calculateRelativeVolumes(exchanges_rates,
ba.server.LOG_PATH = os.path.join(ba.server.PROJECT_PATH, 'runtime', 'app.log') if ba.server.API_DOCUMENT_ROOT == '': ba.server.API_DOCUMENT_ROOT = os.path.join(ba.server.PROJECT_PATH, 'api') ba.server.API_DOCUMENT_ROOT_NOGOX = os.path.join(ba.server.API_DOCUMENT_ROOT, 'no-mtgox') if ba.server.WWW_DOCUMENT_ROOT == '': ba.server.WWW_DOCUMENT_ROOT = os.path.join(ba.server.PROJECT_PATH, 'www') if ba.server.HISTORY_DOCUMENT_ROOT == '': ba.server.HISTORY_DOCUMENT_ROOT = os.path.join(ba.server.PROJECT_PATH, 'api', 'history') write_log('script started', 'LOG') write_config() last_fiat_exchange_rate_update = 0 while True: if last_fiat_exchange_rate_update < int(time.time())-FIAT_RATES_QUERY_FREQUENCY: write_fiat_rates_config() last_fiat_exchange_rate_update = int(time.time()) start_time = int(time.time()) exchanges_rates, exchanges_ignored = ba.api_parsers.callAll() calculated_average_rates = {} total_currency_volumes = {} total_currency_volumes_ask = {} total_currency_volumes_bid = {} calculated_volumes = {} for currency in CURRENCY_LIST: calculated_average_rates[currency] = {'last': DEC_PLACES, 'ask': DEC_PLACES, 'bid': DEC_PLACES,
import redis import simplejson as json import bitcoinaverage as ba import bitcoinaverage.server from bitcoinaverage import api_custom_writers from bitcoinaverage.config import API_WRITE_FREQUENCY, FIAT_RATES_QUERY_FREQUENCY import bitcoinaverage.helpers as helpers from bitcoinaverage.api_calculations import calculateTotalVolumes, calculateRelativeVolumes, calculateAverageRates, formatDataForAPI, writeAPIFiles, calculateAllGlobalAverages logger = logging.getLogger("api_daemon") logger.info("script started") helpers.write_js_config() helpers.write_fiat_rates_config() last_fiat_exchange_rate_update = time.time() helpers.write_api_index_files() red = redis.StrictRedis(host="localhost", port=6379, db=0) while True: if last_fiat_exchange_rate_update < int(time.time())-FIAT_RATES_QUERY_FREQUENCY: helpers.write_fiat_rates_config() start_time = int(time.time()) if not red.exists("ba:exchanges"): logger.warning("database is empty") time.sleep(API_WRITE_FREQUENCY) continue