Skip to content

Commit

Permalink
Update trading_pair_fetcher.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ccraighead authored Apr 1, 2021
1 parent 068ea8d commit ad4627e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions hummingbot/core/utils/trading_pair_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
Any,
Optional,
)
from hummingbot.core.utils.async_utils import safe_gather
from hummingbot.logger import HummingbotLogger
from hummingbot.client.settings import CONNECTOR_SETTINGS, ConnectorType
import logging
import asyncio
import requests

from .async_utils import safe_ensure_future

Expand All @@ -35,6 +35,8 @@ def __init__(self):
safe_ensure_future(self.fetch_all())

async def fetch_all(self):
tasks = []
fetched_connectors = []
for conn_setting in CONNECTOR_SETTINGS.values():
module_name = f"{conn_setting.base_name()}_connector" if conn_setting.type is ConnectorType.Connector \
else f"{conn_setting.base_name()}_api_order_book_data_source"
Expand All @@ -46,14 +48,13 @@ async def fetch_all(self):
module = getattr(importlib.import_module(module_path), class_name)
args = {}
args = conn_setting.add_domain_parameter(args)
safe_ensure_future(self.call_fetch_pairs(module.fetch_trading_pairs(**args), conn_setting.name))

tasks.append(asyncio.wait_for(asyncio.shield(module.fetch_trading_pairs(**args)), timeout=3))
fetched_connectors.append(conn_setting.name)

results = await safe_gather(*tasks, return_exceptions=True)
self.trading_pairs = dict(zip(fetched_connectors, results))
# In case trading pair fetching returned timeout, using empty list
for connector, result in self.trading_pairs.items():
if isinstance(result, asyncio.TimeoutError):
self.trading_pairs[connector] = []

self.ready = True
self.ready = True

0 comments on commit ad4627e

Please sign in to comment.