Skip to content

Commit

Permalink
Change names of asset specific retrieval.
Browse files Browse the repository at this point in the history
Use sid as a parameter for consistency.

To squash.
  • Loading branch information
Eddie Hebert committed Jul 13, 2015
1 parent f9e3fc5 commit f6fe643
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions zipline/assets/assets.py
Expand Up @@ -210,9 +210,9 @@ def retrieve_asset(self, sid, default_none=False):

asset_type = self.asset_type_by_sid(sid)
if asset_type == 'equity':
asset = self.equity_for_id(sid)
asset = self._retrieve_equity(sid)
elif asset_type == 'future':
asset = self.futures_contract_for_id(sid)
asset = self._retrieve_futures_contract(sid)
else:
asset = None

Expand All @@ -224,7 +224,7 @@ def retrieve_asset(self, sid, default_none=False):
raise SidNotFound(sid=sid)

@lru_cache(maxsize=None)
def equity_for_id(self, sid):
def _retrieve_equity(self, sid):
c = self.conn.cursor()
t = (sid,)
c.row_factory = dict_factory
Expand All @@ -239,9 +239,10 @@ def equity_for_id(self, sid):
data['end_date'], tz='UTC')
return Equity(**data)

def futures_contract_for_id(self, contract_id):
@lru_cache(maxsize=None)
def _retrieve_futures_contract(self, sid):
c = self.conn.cursor()
t = (contract_id,)
t = (sid,)
c.row_factory = dict_factory
c.execute(FUTURES_BY_ID_QUERY, t)
data = c.fetchone()
Expand Down Expand Up @@ -291,7 +292,7 @@ def lookup_symbol_resolve_multiple(self, symbol, as_of_date=None):
candidates = c.fetchall()

if len(candidates) == 1:
return self.equity_for_id(candidates[0]['sid'])
return self._retrieve_equity(candidates[0]['sid'])

# If no SID exists for symbol, return SID with the
# highest-but-not-over end_date
Expand All @@ -306,7 +307,7 @@ def lookup_symbol_resolve_multiple(self, symbol, as_of_date=None):
data = c.fetchone()

if data:
return self.equity_for_id(data['sid'])
return self._retrieve_equity(data['sid'])

# If multiple SIDs exist for symbol, return latest start_date with
# end_date as a tie-breaker
Expand All @@ -321,7 +322,7 @@ def lookup_symbol_resolve_multiple(self, symbol, as_of_date=None):
data = c.fetchone()

if data:
return self.equity_for_id(data['sid'])
return self._retrieve_equity(data['sid'])

raise SymbolNotFound(symbol=symbol)

Expand All @@ -332,7 +333,7 @@ def lookup_symbol_resolve_multiple(self, symbol, as_of_date=None):
data = c.fetchall()

if len(data) == 1:
return self.equity_for_id(data[0]['sid'])
return self._retrieve_equity(data[0]['sid'])
elif not data:
raise SymbolNotFound(symbol=symbol)
else:
Expand Down Expand Up @@ -370,7 +371,7 @@ def lookup_symbol(self, symbol, as_of_date, fuzzy=False):

# If one SID exists for symbol, return that symbol
if len(candidates) == 1:
return self.equity_for_id(candidates[0]['sid'])
return self._retrieve_equity(candidates[0]['sid'])

# If multiple SIDs exist for symbol, return latest start_date with
# end_date as a tie-breaker
Expand All @@ -384,7 +385,7 @@ def lookup_symbol(self, symbol, as_of_date, fuzzy=False):
c.execute(query, t)
data = c.fetchone()
if data:
return self.equity_for_id(data['sid'])
return self._retrieve_equity(data['sid'])

def lookup_future_chain(self, root_symbol, as_of_date, knowledge_date):
""" Return the futures chain for a given root symbol.
Expand Down Expand Up @@ -418,7 +419,7 @@ def lookup_future_chain(self, root_symbol, as_of_date, knowledge_date):
order by notice_date asc
""", t)
sids = [r[0] for r in c.fetchall()]
return [self.futures_contract_for_id(sid) for sid in sids]
return [self._retrieve_futures_contract(sid) for sid in sids]

@property
def sids(self):
Expand Down

0 comments on commit f6fe643

Please sign in to comment.