diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/figi_backfill.py | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/python/figi_backfill.py b/python/figi_backfill.py index 12d33453..218e73e1 100644 --- a/python/figi_backfill.py +++ b/python/figi_backfill.py @@ -22,7 +22,7 @@ class Figi: } @sleep_and_retry - @limits(calls=6, period=1) + @limits(calls=25, period=8) def submit(self, job): response = requests.post( url=self.openfigi_url, headers=self.openfigi_headers, json=job @@ -152,6 +152,52 @@ def populate_et_tranche_model_numbers(conn): conn.commit() +def get_jobs_bloomberg_corp_ref(conn): + with conn.cursor() as c: + c.execute("SELECT id_bb_unique FROM bloomberg_corp_ref") + for (id_bb_unique,) in c: + yield {"idType": "ID_BB_UNIQUE", "idValue": id_bb_unique} + + +def populate_bloomberg_corp_ref(conn): + for job, response in submit(get_jobs_bloomberg_corp_ref(conn)): + with conn.cursor() as c: + for j, r in zip(job, response): + try: + figi = get_figi(r) + except ValueError: + continue + else: + c.execute( + "UPDATE bloomberg_corp_ref SET figi=%s WHERE id_bb_unique=%s", + (figi, j["idValue"]), + ) + conn.commit() + + +def get_jobs_bloomberg_corp(conn): + with conn.cursor() as c: + c.execute("SELECT DISTINCT id_bb_unique FROM bloomberg_corp") + for (id_bb_unique,) in c: + yield {"idType": "ID_BB_UNIQUE", "idValue": id_bb_unique} + + +def populate_bloomberg_corp(conn): + for job, response in submit(get_jobs_bloomberg_corp(conn)): + with conn.cursor() as c: + for j, r in zip(job, response): + try: + figi = get_figi(r) + except ValueError: + continue + else: + c.execute( + "UPDATE bloomberg_corp SET figi=%s WHERE id_bb_unique=%s", + (figi, j["idValue"]), + ) + conn.commit() + + if __name__ == "__main__": conn = dbconn("etdb") - populate_et_collateral(conn) + populate_bloomberg_corp(conn) |
