aboutsummaryrefslogtreecommitdiffstats
path: root/python/trade_dataclasses.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/trade_dataclasses.py')
-rw-r--r--python/trade_dataclasses.py78
1 files changed, 37 insertions, 41 deletions
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py
index ee462e5b..0b0b88d5 100644
--- a/python/trade_dataclasses.py
+++ b/python/trade_dataclasses.py
@@ -262,8 +262,10 @@ class Deal:
def __class_getitem__(cls, deal_type: DealType):
return cls._registry[deal_type]
- def __init_subclass__(cls, deal_type: DealType, table_name: str, insert_ignore=()):
- super().__init_subclass__()
+ def __init_subclass__(
+ cls, deal_type: DealType, table_name: str, insert_ignore=(), **kwargs
+ ):
+ super().__init_subclass__(**kwargs)
cls._registry[deal_type] = cls
cls._table_name = table_name
insert_columns = [c for c in cls.__annotations__ if c not in insert_ignore]
@@ -428,35 +430,10 @@ class MTMDeal:
return cls(**{k: v for k, v in kwargs.items() if k in cls._sql_fields})
-from csv_headers.citco import GIL, GTL
-
-
-class CitcoDeal:
+class Citco:
_citco_queue: ClassVar[list] = []
- _citco_trade_queue: ClassVar[list] = []
- _citco_headers = None
- _citco_trade_headers = None
+ _citco_headers = []
_sftp = SftpClient.from_creds("citco")
- product_key = ()
-
- def __init_subclass__(cls, deal_type, product_key, **kwargs):
- super().__init_subclass__(deal_type, **kwargs)
- cls._citco_headers = GIL
- cls._citco_trade_headers = GTL
- cls.product_key = product_key
-
- def get_dealid(self):
- filter_clause = " AND ".join([f"{k}=%s" for k in self.product_key])
- sql_str = (
- f"SELECT id, dealid, committed FROM {self.table_name} WHERE {filter_clause}"
- )
- with self._conn.cursor() as c:
- c.execute(
- sql_str,
- tuple([getattr(self, k) for k in self.product_key]),
- )
- if results := c.fetchone():
- (self.id, self.dealid, self.committed) = results
@classmethod
def citco_upload(cls):
@@ -504,6 +481,25 @@ class CitcoDeal:
self._citco_trade_queue.append(self.to_citco())
+class CitcoProduct(Citco):
+ _citco_headers = GIL
+ product_key = ()
+
+ def __init_subclass__(cls, product_key, **kwargs):
+ cls.product_key = product_key
+
+ def get_productid(self):
+ filter_clause = " AND ".join([f"{k}=%s" for k in self.product_key])
+ sql_str = f"SELECT id, dealid, committed FROM {self._table_name} WHERE {filter_clause}"
+ with self._conn.cursor() as c:
+ c.execute(
+ sql_str,
+ tuple([getattr(self, k) for k in self.product_key]),
+ )
+ if results := c.fetchone():
+ (self.id, self.dealid, self.committed) = results
+
+
@dataclass
class CDSDeal(
CitcoDeal,
@@ -1314,8 +1310,8 @@ class TrancheType(IntEnum):
@dataclass
class TrancheProduct(
- CitcoProduct,
Deal,
+ CitcoProduct,
deal_type=DealType.TrancheProduct,
table_name="citco_tranche",
product_key=("underlying_security_id", "attach", "detach"),
@@ -1364,7 +1360,7 @@ class TrancheProduct(
index,
series,
) = c.fetchone()
- self.get_dealid()
+ self.get_productid()
self.security_desc = (
f"{desc_str(index, series, '5')} {self.attach}-{self.detach}"
)
@@ -1374,7 +1370,7 @@ class TrancheProduct(
if not self.id:
self.stage()
self.commit()
- self.get_dealid()
+ self.get_productid()
obj = self.serialize("citco")
obj["Command"] = "N"
obj["Active"] = "Y"
@@ -1387,8 +1383,8 @@ class TrancheProduct(
@dataclass
class SwaptionProduct(
- CitcoProduct,
Deal,
+ CitcoProduct,
deal_type=DealType.SwaptionProduct,
table_name="citco_swaption",
product_key=(
@@ -1430,7 +1426,7 @@ class SwaptionProduct(
)
def __post_init__(self):
- self.get_dealid()
+ self.get_productid()
if self.underlying_id_source == "RED":
sql_str = "SELECT issue_date, maturity, coupon, index, series FROM index_desc WHERE tenor='5yr' AND redindexcode=%s"
with self._conn.cursor() as c:
@@ -1453,7 +1449,7 @@ class SwaptionProduct(
if not self.id:
self.stage()
self.commit()
- self.get_dealid()
+ self.get_productid()
obj = self.serialize("citco")
if self.underlying_id_source == "USERID":
irs = IRSProduct(
@@ -1482,8 +1478,8 @@ _citco_ratesource = {"SOFRRATE": 17819}
@dataclass
class IRSProduct(
- CitcoProduct,
Deal,
+ CitcoProduct,
deal_type=DealType.IRSProduct,
table_name="citco_irs",
product_key=("birth_date", "death_date", "float_index", "fixed_rate"),
@@ -1514,14 +1510,14 @@ class IRSProduct(
)
def __post_init__(self):
- self.get_dealid()
+ self.get_productid()
self.security_desc = f"SWAP IRS {self.float_index}-{self.fixed_rate}"
def to_citco(self):
if not self.id:
self.stage()
self.commit()
- self.get_dealid()
+ self.get_productid()
obj = self.serialize("citco")
d = {
@@ -1552,8 +1548,8 @@ class IRSProduct(
@dataclass
class TRSProduct(
- CitcoProduct,
Deal,
+ CitcoProduct,
deal_type=DealType.TRSProduct,
table_name="citco_trs",
product_key=("birth_date", "death_date", "funding_index", "underlying_security"),
@@ -1585,7 +1581,7 @@ class TRSProduct(
)
def __post_init__(self):
- self.get_dealid()
+ self.get_productid()
_citco_trs = {"4J623JAA8": "IBOXHY_TRS"}
self.security_desc = _citco_trs[self.underlying_security]
@@ -1594,7 +1590,7 @@ class TRSProduct(
self.stage()
self.commit()
- self.get_dealid()
+ self.get_productid()
obj = self.serialize("citco")
d = {