def parse_exchange_ids(exchange_list): ids_list = [x.strip() for x in exchange_list.split(',') if x.strip()] exchanges_ids = [] for exchange_name in ids_list: new_exchange_id = get_exchange_id_by_name(exchange_name) if new_exchange_id in EXCHANGE.values(): exchanges_ids.append(new_exchange_id) else: log_wrong_exchange_id(new_exchange_id) assert new_exchange_id in EXCHANGE.values() return exchanges_ids
def dummy_order_state_init(): order_state_by_exchange = {} for exchange_id in EXCHANGE.values(): order_state_by_exchange[exchange_id] = None return order_state_by_exchange
def load_keys(path): """ :param path: full path to folder with public keys, each key should be named as corresponding exchange :return: """ global access_keys for exchange_id in EXCHANGE.values(): exchange_name = get_exchange_name_by_id(exchange_id) key = ExchangeKey.from_file(path, exchange_name) access_keys[exchange_id] = key
def dummy_balance_init(timest, default_volume, default_available_volume): balance = {} total_balance = {} available_balance = {} for currency_id in ARBITRAGE_CURRENCY: total_balance[currency_id] = default_volume for currency_id in ARBITRAGE_CURRENCY: available_balance[currency_id] = default_available_volume for exchange_id in EXCHANGE.values(): balance[exchange_id] = Balance(exchange_id, timest, available_balance, total_balance) return BalanceState(balance)
def get_history_speedup(date_start, date_end, processor): history_async_requests = [] for exchange_id in EXCHANGE.values(): if exchange_id == EXCHANGE.KRAKEN: continue for pair_id in CURRENCY_PAIR.values(): pair_name = get_currency_pair_name_by_exchange_id(pair_id, exchange_id) if pair_name: method_for_url = get_history_url_by_exchange_id(exchange_id) request_url = method_for_url(pair_name, date_start, date_end) constructor = get_history_constructor_by_exchange_id(exchange_id) history_async_requests.append(WorkUnit(request_url, constructor, pair_name, date_end)) return processor.process_async_get(history_async_requests, HTTP_TIMEOUT_SECONDS)
def get_order_book_speedup(date_end, processor): order_book_async_requests = [] for exchange_id in EXCHANGE.values(): for pair_id in CURRENCY_PAIR.values(): pair_name = get_currency_pair_name_by_exchange_id( pair_id, exchange_id) if pair_name: method_for_url = get_order_book_url_by_exchange_id(exchange_id) request_url = method_for_url(pair_name) constructor = get_order_book_constructor_by_exchange_id( exchange_id) order_book_async_requests.append( WorkUnit(request_url, constructor, pair_name, date_end)) return processor.process_async_get(order_book_async_requests, HTTP_TIMEOUT_SECONDS)
def __init__(self, logging_level_id=LOG_ALL_DEBUG, log_folder=LOGS_FOLDER, key_path=API_KEY_PATH, cache_host=CACHE_HOST, cache_port=CACHE_PORT, db_host=DB_HOST, db_port=DB_PORT, db_name=DB_NAME, exchanges_ids=None): # Logging self.logging_level_id = logging_level_id self.logging_level_name = get_debug_level_name_by_id( self.logging_level_id) self.log_folder = log_folder # Keys self.key_path = key_path # Cache - Redis so far self.cache_host = cache_host self.cache_port = cache_port # Postgres self.db_host = db_host self.db_port = db_port self.db_name = db_name # Exchanges if not exchanges_ids: self.exchanges = EXCHANGE.values() else: self.exchanges = exchanges_ids