mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-13 17:42:42 +08:00
Making errors more verbose and user-friendly
This commit is contained in:
@@ -311,7 +311,7 @@ class DataPortalExchangeBacktest(DataPortalExchangeBase):
|
||||
field=field,
|
||||
first_trading_day=self._get_first_trading_day(assets),
|
||||
exchange=exchange.name,
|
||||
symbols=[asset.symbol for asset in assets],
|
||||
symbols=[asset.symbol.encode('utf-8') for asset in assets],
|
||||
)
|
||||
|
||||
series = dict()
|
||||
@@ -332,7 +332,8 @@ class DataPortalExchangeBacktest(DataPortalExchangeBase):
|
||||
raise PricingDataBeforeTradingError(
|
||||
first_trading_day=first_trading_day,
|
||||
exchange=assets[0].exchange,
|
||||
symbols=[asset.symbol for asset in assets],
|
||||
symbols=[asset.symbol.encode('utf-8') for asset in assets],
|
||||
dt = dt,
|
||||
)
|
||||
|
||||
def get_exchange_spot_value(self, exchange, assets, field, dt,
|
||||
@@ -356,7 +357,8 @@ class DataPortalExchangeBacktest(DataPortalExchangeBase):
|
||||
field=field,
|
||||
first_trading_day=self._get_first_trading_day(assets),
|
||||
exchange=exchange.name,
|
||||
symbols=[asset.symbol for asset in assets],
|
||||
symbols=[asset.symbol.encode('utf-8') for asset in assets],
|
||||
symbol_list = ''.join([asset.symbol.encode('utf-8') for asset in assets])
|
||||
)
|
||||
|
||||
return values
|
||||
|
||||
@@ -2,11 +2,12 @@ import sys, traceback
|
||||
from catalyst.errors import ZiplineError
|
||||
|
||||
def silent_except_hook(exctype, excvalue, exctraceback):
|
||||
if exctype in [SymbolNotFoundOnExchange,]:
|
||||
if exctype in [ PricingDataBeforeTradingError, PricingDataNotLoadedError,
|
||||
SymbolNotFoundOnExchange, ]:
|
||||
fn = traceback.extract_tb(exctraceback)[-1][0]
|
||||
ln = traceback.extract_tb(exctraceback)[-1][1]
|
||||
print "Error traceback: {1} (line {2})\n" \
|
||||
"{0.__name__}: {3}.".format(exctype, fn, ln, excvalue)
|
||||
"{0.__name__}: {3}".format(exctype, fn, ln, excvalue)
|
||||
else:
|
||||
sys.__excepthook__(exctype, excvalue, exctraceback)
|
||||
|
||||
@@ -169,15 +170,16 @@ class BundleNotFoundError(ZiplineError):
|
||||
|
||||
class PricingDataBeforeTradingError(ZiplineError):
|
||||
msg = ('Pricing data for trading pairs {symbols} on exchange {exchange} '
|
||||
'starts on {first_trading_day}.').strip()
|
||||
'starts on {first_trading_day}, but you are either trying to trade or '
|
||||
'retrieve pricing data on {dt}. Adjust your dates accordingly.').strip()
|
||||
|
||||
|
||||
class PricingDataNotLoadedError(ZiplineError):
|
||||
msg = ('Pricing data {field} for trading pairs {symbols} trading on '
|
||||
'exchange {exchange} since {first_trading_day} is unavailable. '
|
||||
'The bundle data is either out-of-date or has not been loaded yet.'
|
||||
'The bundle data is either out-of-date or has not been loaded yet. '
|
||||
'Please ingest data using the command '
|
||||
'`catalyst ingest -b exchange_{exchange}`. '
|
||||
'`catalyst ingest-exchange -x {exchange} -i {symbol_list}`. '
|
||||
'See catalyst documentation for details.').strip()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user