Skip to content

Commit

Permalink
MAINT: Insert data into asset_router
Browse files Browse the repository at this point in the history
  • Loading branch information
StewartDouglas committed Aug 4, 2015
1 parent 53ce07c commit 1940139
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions zipline/assets/asset_writer.py
Expand Up @@ -159,8 +159,14 @@ def _write_root_symbols(self, root_symbols, db_conn):

def _write_futures(self, futures, db_conn):

# Retrieve the data to add to the futures_contracts table
data = [tuple(x) for x in futures.to_records()]

# Retrieve the data to add to the asset_router table
sids = [x[0] for x in data]
futs = ['future'] * len(sids)
to_insert = zip(sids, futs)

c = db_conn.cursor()
c.executemany("""
INSERT OR IGNORE INTO futures_contracts
Expand All @@ -170,15 +176,27 @@ def _write_futures(self, futures, db_conn):
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", data)

c.executemany("""
INSERT INTO asset_router
('sid', 'asset_type')
VALUES(?,?)
""", to_insert)

def _write_equities(self, equities, db_conn):

# Apply fuzzy matching.
if self.fuzzy_char:
equities['fuzzy'] = equities['symbol'].str.\
replace(self.fuzzy_char, '')

# Retrieve the data to add to the equitites table
data = [tuple(x) for x in equities.to_records()]

# Retrieve the data to add to the asset_router table
sids = [x[0] for x in data]
eqs = ['equity'] * len(sids)
to_insert = zip(sids, eqs)

c = db_conn.cursor()
c.executemany("""
INSERT OR IGNORE INTO equities
Expand All @@ -187,6 +205,12 @@ def _write_equities(self, equities, db_conn):
VALUES(?, ?, ?, ?, ?, ?, ?, ?)
""", data)

c.executemany("""
INSERT INTO asset_router
('sid', 'asset_type')
VALUES(?,?)
""", to_insert)

def init_db(self,
db_conn,
constraints=False):
Expand Down

0 comments on commit 1940139

Please sign in to comment.