aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/book_bbg.py12
-rw-r--r--python/trade_dataclasses.py39
2 files changed, 41 insertions, 10 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py
index 45abe0d3..a0809d26 100644
--- a/python/book_bbg.py
+++ b/python/book_bbg.py
@@ -3,6 +3,9 @@ from trade_dataclasses import Deal, DealType, BbgDeal
from stat import S_ISREG
import re
import time
+import logging
+
+logger = logging.getLogger(__name__)
def get_bbg_id(s):
@@ -24,8 +27,13 @@ def run():
continue
if bbg_id not in BbgDeal._cache:
with sftp.client.open(f.filename) as fh:
- Deal[DealType(deal_type)].process(fh, bbg_id)
- BbgDeal._cache[bbg_id] = None
+ try:
+ Deal[DealType(deal_type)].process(fh, bbg_id)
+ except TypeError as e:
+ logger.warning(f"{bbg_id} missing cp in db")
+ pass
+ else:
+ BbgDeal._cache[bbg_id] = None
except OSError:
sftp.client.close()
sftp = SftpClient.from_creds("bbg")
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"