diff options
Diffstat (limited to 'python/book_bbg.py')
| -rw-r--r-- | python/book_bbg.py | 44 |
1 files changed, 6 insertions, 38 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py index 4856ae5d..5f4c303c 100644 --- a/python/book_bbg.py +++ b/python/book_bbg.py @@ -5,48 +5,16 @@ from trade_dataclasses import CDSDeal, BondDeal, BbgDeal, _funds, _cdx_cp, _fcms from decimal import Decimal from stat import S_ISREG +_deal = {"BOND": BondDeal, "CDX": CDSDeal} -def get_indic_data(conn, redcode, tenor): - sql_str = ( - "SELECT maturity, coupon " - "FROM index_desc " - "WHERE tenor=%s AND redindexcode=%s " - ) - with conn.cursor() as c: - c.execute(sql_str, (redcode, tenor)) - return c.fetchone() - -def cdx_booking_process(path, conn): - reader = csv.DictReader(path) - for line in reader: - trade = CDSDeal( - fund=_funds[line["Account"]], - folder="*", - portfolio="UNALLOCATED", - security_id=line["Red Code"], - security_desc=line["Security"].removesuffix(" PRC"), - traded_level=Decimal(line["Price (Dec)"]), - notional=line["Quantity"], - fixed_rate=float(line["Coupon"]) * 0.01, - trade_date=datetime.datetime.strptime(line["Trade Dt"], "%m/%d/%Y").date(), - maturity=datetime.datetime.strptime(line["Mat Dt"], "%m/%d/%Y").date(), - currency=line["Curncy"], - protection="Buyer" if line["Side"] == "B" else "Seller", - upfront=line["Principal"], - cp_code=_cdx_cp[line["Brkr"]], - account_code=_fcms[line["Client FCM"]], - ) - trade.stage() - CDSDeal.commit() - - -def bond_booking_process(file_handle, index): +def trade_booking_process(file_handle, index, asset_class): + deal = _deal[asset_class] for row in csv.DictReader(file_handle): line = {"bbg_ticket_id": index, **row} - trade = BondDeal.from_bbg_line(line) + trade = deal.from_bbg_line(line) trade.stage() - BondDeal.commit() + deal.commit() def get_bbg_id(name): @@ -63,7 +31,7 @@ if __name__ == "__main__": if S_ISREG(f.st_mode): if (bbg_id := get_bbg_id(f.filename)) not in BbgDeal._cache: with sftp.client.open(f.filename) as fh: - booker[f.filename.split("-", 1)[0]](fh, bbg_id) + trade_booking_process(fh, bbg_id, f.filename.split("-", 1)[0]) BbgDeal._cache[bbg_id] = None time.sleep(60) |
