diff options
Diffstat (limited to 'python/trade_dataclasses.py')
| -rw-r--r-- | python/trade_dataclasses.py | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py index 60b232e1..f0efbbe4 100644 --- a/python/trade_dataclasses.py +++ b/python/trade_dataclasses.py @@ -440,8 +440,8 @@ class CDSDeal( @classmethod def from_bbg_line(cls, line: dict): - if line["Coupon"] == "": - with cls._conn.cursor() as c: + with cls._conn.cursor() as c: + if line["Coupon"] == "": c.execute( "SELECT coupon, index, series, tenor FROM index_desc " "WHERE redindexcode=%s AND maturity =%s", @@ -451,8 +451,13 @@ class CDSDeal( ), ) coupon, index, series, tenor = c.fetchone() - line["Security"] = desc_str(index, series, tenor.removesuffix("yr")) - line["Coupon"] = coupon + line["Security"] = desc_str(index, series, tenor.removesuffix("yr")) + line["Coupon"] = coupon + c.execute( + "SELECT cp_code from bbg_ticket_mapping where bbg_code=%s and code_type='CDX'", + (line["Brkr"],), + ) + (cp_code,) = c.fetchone() cls._bbg_insert_queue.append(list(line.values())) return cls( fund=_funds[line["Account"]], @@ -468,7 +473,7 @@ class CDSDeal( currency=line["Curncy"], protection="Buyer" if line["Side"] == "B" else "Seller", upfront=line["Net"], - cp_code=_cdx_cp[line["Brkr"]], + cp_code=cp_code, account_code=_fcms[line["Client FCM"]], bbg_ticket_id=line["bbg_ticket_id"], ) @@ -503,10 +508,16 @@ class BondDeal(BbgDeal, Deal, deal_type=DealType.Bond, table_name="bonds"): ) results = c.fetchone() line["asset_class"] = results[0] if results else None + c.execute( + "SELECT cp_code from bbg_ticket_mapping where bbg_code=%s and code_type='BOND'", + (line["Brkr"],), + ) + (cp_code,) = c.fetchone() + return cls( faceamount=Decimal(line["Quantity"]), price=Decimal(line["Price (Dec)"]), - cp_code=_bond_cp[line["Brkr"]], + cp_code=cp_code, cusip=line["Cusip"], identifier=line["Cusip"], trade_date=datetime.datetime.strptime(line["Trade Dt"], "%m/%d/%Y"), @@ -729,6 +740,12 @@ class SpotDeal( @classmethod def from_bbg_line(cls, line: dict): + with cls._conn.cursor() as c: + c.execute( + "SELECT cp_code from bbg_ticket_mapping where bbg_code=%s and code_type='FX'", + (line["Counterparty Deal Code"],), + ) + (cp_code,) = c.fetchone() if line["Side"] == "S": key1, key2 = "buy", "sell" else: @@ -747,7 +764,7 @@ class SpotDeal( return cls( folder="*", portfolio="UNALLOCATED", - cp_code=_fx_cp[line["Counterparty Deal Code"]], + cp_code=cp_code, trade_date=datetime.datetime.strptime(line["Date Of Deal"], "%Y%m%d"), settle_date=datetime.datetime.strptime( line["Value Date Period 1 Currency 1"], "%Y%m%d" @@ -806,6 +823,12 @@ class FxSwapDeal( @classmethod def from_bbg_line(cls, line: dict): + with cls._conn.cursor() as c: + c.execute( + "SELECT cp_code from bbg_ticket_mapping where bbg_code=%s and code_type='FX'", + (line["Counterparty Deal Code"],), + ) + (cp_code,) = c.fetchone() if line["Side"] == "S": key1, key2 = "buy", "sell" else: @@ -828,7 +851,7 @@ class FxSwapDeal( return cls( folder="*", portfolio="UNALLOCATED", - cp_code=_fx_cp[line["Counterparty Deal Code"]], + cp_code=cp_code, trade_date=datetime.datetime.strptime(line["Date Of Deal"], "%Y%m%d"), near_settle_date=datetime.datetime.strptime( line["Value Date Period 1 Currency 1"], "%Y%m%d" |
