aboutsummaryrefslogtreecommitdiffstats
path: root/python/book_bbg.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/book_bbg.py')
-rw-r--r--python/book_bbg.py61
1 files changed, 21 insertions, 40 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py
index 6f8d6f17..369251b1 100644
--- a/python/book_bbg.py
+++ b/python/book_bbg.py
@@ -86,35 +86,23 @@ def cdx_booking_process(path, conn):
CDSDeal.commit()
-def bond_booking_process(path, fname, _cache):
- df = pd.read_csv(path)
- for _, line in df.iterrows():
- trade = BondDeal(
- faceamount=Decimal(line["Quantity"]),
- price=Decimal(line["Price (Dec)"]),
- cp_code=_bond_cp[line["Brkr"]],
- cusip=line["Cusip"],
- identifier=line["Cusip"],
- trade_date=datetime.datetime.strptime(line["Trade Dt"], "%m/%d/%Y"),
- settle_date=datetime.datetime.strptime(line["SetDt"], "%m/%d/%Y"),
- portfolio="UNALLOCATED",
- asset_class=None,
- description=line["Security"].removesuffix(" Mtge"),
- buysell=line["Side"] == "B",
- bbg_ticket_id=fname,
- )
- trade.stage()
- df["bbg_ticket_id"] = [fname]
- try:
- df.to_sql("bond_tickets", dawn_engine, if_exists="append", index=False)
- except SQLAlchemyError as e:
- error = str(e.__dict__["orig"])
- BondDeal._insert_queue.clear()
- print(error)
- else:
- _cache[fname] = None
- finally:
- BondDeal.commit()
+def bond_booking_process(path, fname):
+ with open(path) as fh:
+ reader = csv.DictReader(fh)
+ for line in reader:
+ line["bbg_ticket_id"] = fname
+ trade = BondDeal.from_bbg_line(line)
+ trade.stage()
+ try:
+ BondDeal.insert_bbg_line(line)
+ except Exception as e:
+ pass
+ BondDeal._insert_queue.clear()
+ print("error")
+ else:
+ _cache[fname] = None
+ finally:
+ BondDeal.commit()
def get_bbg_id(name):
@@ -133,17 +121,10 @@ if __name__ == "__main__":
for f in filter(
lambda f: all(filt(f) for filt in filters), sftp.client.listdir_iter("/")
):
- if ("CDX" in f.filename) or ("BOND" in f.filename):
- if get_bbg_id(f.filename) in _cache.keys():
+ if "BOND" in f.filename:
+ bbg_id = get_bbg_id(f.filename)
+ if bbg_id in BondDeal._cache.keys():
continue
else:
- if "CDX" in f.filename:
- # cds_booking_process(sftp.client.open(f"/{f.filename}"), conn, get_bbg_id(f.filename), _cache)
- pass
- elif "BOND" in f.filename:
- bond_booking_process(
- sftp.client.open(f"/{f.filename}"),
- get_bbg_id(f.filename),
- _cache,
- )
+ bond_booking_process(sftp.client.open(f"/{f.filename}"), bbg_id)
time.sleep(60)