MAINT: Insert data into asset_router

This commit is contained in:
Stewart Douglas
2015-08-04 17:53:05 -04:00
committed by jfkirk
parent 449400426d
commit 696d8f2846
+24
View File
@@ -163,8 +163,14 @@ class AssetDBWriter(with_metaclass(ABCMeta)):
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
@@ -174,6 +180,12 @@ class AssetDBWriter(with_metaclass(ABCMeta)):
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""", data)
c.executemany("""
INSERT INTO asset_router
('sid', 'asset_type')
VALUES(?,?)
""", to_insert)
def _write_equities(self, equities, db_conn):
# Apply fuzzy matching.
@@ -181,8 +193,14 @@ class AssetDBWriter(with_metaclass(ABCMeta)):
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
@@ -191,6 +209,12 @@ class AssetDBWriter(with_metaclass(ABCMeta)):
VALUES(?, ?, ?, ?, ?, ?, ?, ?)
""", data)
c.executemany("""
INSERT INTO asset_router
('sid', 'asset_type')
VALUES(?,?)
""", to_insert)
def init_db(self,
db_conn,
constraints=False):