mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-02 16:29:14 +08:00
Merge pull request #1715 from quantopian/missing-cf-error
Better error message for non-existent root symbol
This commit is contained in:
@@ -34,6 +34,7 @@ from zipline.assets.continuous_futures import (
|
||||
delivery_predicate
|
||||
)
|
||||
from zipline.data.minute_bars import FUTURES_MINUTES_PER_DAY
|
||||
from zipline.errors import SymbolNotFound
|
||||
from zipline.testing.fixtures import (
|
||||
WithAssetFinder,
|
||||
WithCreateBarData,
|
||||
@@ -417,6 +418,11 @@ class ContinuousFuturesTestCase(WithCreateBarData,
|
||||
|
||||
self.assertNotEqual(cf_primary, cf_secondary)
|
||||
|
||||
# Assert that the proper exception is raised if the given root symbol
|
||||
# does not exist.
|
||||
with self.assertRaises(SymbolNotFound):
|
||||
self.asset_finder.create_continuous_future('NO', 0, 'calendar')
|
||||
|
||||
def test_current_contract(self):
|
||||
cf_primary = self.asset_finder.create_continuous_future(
|
||||
'FO', 0, 'calendar')
|
||||
|
||||
@@ -996,8 +996,13 @@ class AssetFinder(object):
|
||||
|
||||
fields = (fc_cols.exchange,)
|
||||
|
||||
return sa.select(fields).where(
|
||||
fc_cols.root_symbol == root_symbol).execute().fetchone()[0]
|
||||
exchange = sa.select(fields).where(
|
||||
fc_cols.root_symbol == root_symbol).execute().scalar()
|
||||
|
||||
if exchange is not None:
|
||||
return exchange
|
||||
else:
|
||||
raise SymbolNotFound(symbol=root_symbol)
|
||||
|
||||
def get_ordered_contracts(self, root_symbol):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user