diff --git a/catalyst/exchange/bundle_utils.py b/catalyst/exchange/bundle_utils.py index 56fa6359..ce0130a1 100644 --- a/catalyst/exchange/bundle_utils.py +++ b/catalyst/exchange/bundle_utils.py @@ -7,6 +7,7 @@ import pandas as pd import pytz from catalyst.data.bundles import from_bundle_ingest_dirname +from catalyst.exchange.exchange_errors import ApiCandlesError from catalyst.utils.deprecate import deprecated from catalyst.utils.paths import data_path @@ -96,7 +97,7 @@ def get_history(exchange_name, data_frequency, symbol, start=None, end=None): data = response.json() if 'error' in data: - raise ValueError(data['error']) + raise ApiCandlesError(error=data['error']) for candle in data: last_traded = pd.Timestamp.utcfromtimestamp(candle['ts']) diff --git a/catalyst/exchange/exchange.py b/catalyst/exchange/exchange.py index 96969692..36eb9628 100644 --- a/catalyst/exchange/exchange.py +++ b/catalyst/exchange/exchange.py @@ -489,7 +489,7 @@ class Exchange: candles = bundle_utils.get_history( exchange_name=self.name, data_frequency=data_frequency, - symbol=asset.exchange_symbol, # TODO: use Catalyst symbol + symbol=asset.symbol, # TODO: use Catalyst symbol start=catalyst_start, end=catalyst_end ) diff --git a/catalyst/exchange/exchange_bundle.py b/catalyst/exchange/exchange_bundle.py index 7504f7c0..34d5330b 100644 --- a/catalyst/exchange/exchange_bundle.py +++ b/catalyst/exchange/exchange_bundle.py @@ -131,18 +131,14 @@ class ExchangeBundle: write_metadata = False if start_dt < metadata.start_session: write_metadata = True - start_session = start_dt.floor('1d') + start_session = start_dt else: start_session = metadata.start_session if end_dt > metadata.end_session: write_metadata = True - # TODO: workaround, improve the calendar logic? - if end_dt == start_dt: - end_dt += timedelta(days=1) - - end_session = end_dt.floor('1d') + end_session = end_dt else: end_session = metadata.end_session diff --git a/catalyst/exchange/exchange_errors.py b/catalyst/exchange/exchange_errors.py index 7e751981..2d5904cc 100644 --- a/catalyst/exchange/exchange_errors.py +++ b/catalyst/exchange/exchange_errors.py @@ -167,3 +167,7 @@ class PricingDataNotLoadedError(ZiplineError): 'Please ingest data using the command ' '`catalyst ingest -b exchange_{exchange}`. ' 'See catalyst documentation for details.').strip() + + +class ApiCandlesError(ZiplineError): + msg = ('Unable to fetch candles from the remote API: {error}.').strip() diff --git a/tests/exchange/test_bundle.py b/tests/exchange/test_bundle.py index 643326a9..f99ced28 100644 --- a/tests/exchange/test_bundle.py +++ b/tests/exchange/test_bundle.py @@ -1,3 +1,4 @@ +from datetime import timedelta from logging import Logger import pandas as pd @@ -12,8 +13,9 @@ class ExchangeBundleTestCase: def test_ingest_minute(self): exchange_name = 'bitfinex' - start = pd.to_datetime('2017-09-01', utc=True) - end = pd.Timestamp.utcnow() + # start = pd.to_datetime('2017-09-01', utc=True) + end = pd.Timestamp.utcnow() - timedelta(minutes=5) + start = end - timedelta(minutes=30) exchange_bundle = ExchangeBundle(get_exchange(exchange_name))