diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/trade_dataclasses.py | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py index 0fef4285..30d69138 100644 --- a/python/trade_dataclasses.py +++ b/python/trade_dataclasses.py @@ -443,8 +443,9 @@ class Citco: csvwriter.writerow(cls._citco_headers) ###### Static Values for Now for h in cls._citco_queue: - h["OrdStatus"] = "N" - h["ExecTransType"] = 2 if h["OrdStatus"] == "N" else 0 + _citco_to_action = {"R": "UPDATE", "D": "CANCEL"} + # h["OrdStatus"] = "N" + # h["ExecTransType"] = 2 if h["OrdStatus"] == "N" else 0 h["Fund"] = "ISOSEL" h["SettleCurrency"] = "USD" identifier = ( @@ -455,7 +456,15 @@ class Citco: if cls.file_tag == "i.innocap_serenitas." else h["ClientOrderID"] ) - cls._submission_queue.append([unique_id, "NEW", identifier]) + cls._submission_queue.append( + [ + unique_id, + "NEW" + if h["OrdStatus"] == "N" + else _citco_to_action[h["OrdStatus"]], + identifier, + ] + ) ###### csvwriter.writerows( @@ -470,8 +479,8 @@ class Citco: cls._citco_queue.clear() cls._submission_queue.clear() - def citco_stage(self): - self._citco_queue.append(self.to_citco()) + def citco_stage(self, action): + self._citco_queue.append(self.to_citco(action)) @classmethod def fname(cls): @@ -505,7 +514,7 @@ class CitcoProduct(Citco): if results := c.fetchone(): (self.id, self.dealid, self.committed) = results - def to_citco(self): + def to_citco(self, action): obj = self.serialize("citco") obj["Birth_date"] = obj["Birth_date"].strftime("%Y%m%d") obj["Death_date"] = obj["Death_date"].strftime("%Y%m%d") @@ -517,8 +526,9 @@ class CitcoTrade(Citco): _citco_headers = GTL file_tag = "innocap_serenitas_trades_" - def to_citco(self): + def to_citco(self, action): obj = self.serialize("citco") + obj["OrdStatus"], obj["ExecTransType"] = self._action_to_citco(action) obj["FillID"] = obj["ClientOrderID"] obj["Trader"] = "DFLT" obj["StrategyCode"] = f"{obj['portfolio']}/{obj['folder']}" @@ -535,6 +545,16 @@ class CitcoTrade(Citco): obj["FXRate"] = 1 return obj + @staticmethod + def _action_to_citco(action): + match action: + case "NEW": + return ("N", 2) + case "UPDATE": + return ("R", 0) + case "CANCEL": + return ("D", 0) + @dataclass class CDSDeal( @@ -634,8 +654,8 @@ class CDSDeal( obj["Contractual Supplement"] = "StandardiTraxxEuropeTranche" return obj - def to_citco(self): - obj = super().to_citco() + def to_citco(self, action): + obj = super().to_citco(action) obj["SecurityType"] = "CDS" obj["AvgPrice"] = ( obj["OrderQty"] / obj["upfront"] / obj["factor"] / 100 @@ -651,7 +671,6 @@ class CDSDeal( obj["IDSource"] = "USERID" obj["ExecutionBroker"] = _citco_cp_isda[obj["ExecutionBroker"]] obj["ClearingAgent"] = obj["ExecutionBroker"] - self.product.citco_stage() obj["SecurityID"] = self.product.dealid else: # cleared cds process @@ -808,8 +827,8 @@ class BondDeal( setattr(cls, "faceamount", notional) return cls - def to_citco(self): - obj = super().to_citco() + def to_citco(self, action): + obj = super().to_citco(action) obj["SecurityType"] = "CMO" obj["ClearingAgent"] = "NT" obj["FXRate"] = 1 @@ -910,8 +929,8 @@ class SwaptionDeal( obj["Effective Date"] = obj["Trade Date"] return obj - def to_citco(self): - obj = super().to_citco() + def to_citco(self, action): + obj = super().to_citco(action) obj["ExecutionBroker"] = _citco_cp_isda[obj["ExecutionBroker"]] obj["ClearingAgent"] = obj["ExecutionBroker"] obj["SecurityType"] = "BNDOPT" @@ -1113,8 +1132,8 @@ class SpotDeal( **d, ) - def to_citco(self): - obj = super().to_citco() + def to_citco(self, action): + obj = super().to_citco(action) if obj["buy_currency"] == "USD": key1, key2 = "sell", "buy" else: @@ -1220,8 +1239,8 @@ class FxSwapDeal( **d, ) - def to_citco(self): - obj = super().to_citco() + def to_citco(self, action): + obj = super().to_citco(action) if obj["near_buy_currency"] == "USD": # This is for strict FX Swaps key1, key2 = "buy", "sell" else: @@ -1254,7 +1273,6 @@ class FxSwapDeal( cp_code=obj["cp_code"], cash_account=obj["cash_account"], ) - near_trade.citco_stage() obj["ClientOrderID"] = obj["ClientOrderID"] + "_F" obj["FXRate"] = 1 return obj @@ -1393,15 +1411,14 @@ class TRSDeal( obj.update(d) return obj - def to_citco(self): - obj = super().to_citco() + def to_citco(self, action): + obj = super().to_citco(action) obj["ExecutionBroker"] = _citco_cp_isda[obj["ExecutionBroker"]] obj["ClearingAgent"] = obj["ExecutionBroker"] obj["SecurityType"] = "TRS" obj["BuySellShortCover"] = "B" if obj["buysell"] else "S" obj["IDSource"] = "USERID" obj["Fee"] = -obj["Fee"] if obj["buysell"] else obj["Fee"] - self.product.citco_stage() obj["SecurityID"] = self.product.dealid return obj @@ -1512,15 +1529,14 @@ class IRSDeal( obj.update(d) return obj - def to_citco(self): - obj = super().to_citco() + def to_citco(self, action): + obj = super().to_citco(action) obj["ExecutionBroker"] = _citco_cp_cdea[obj["ExecutionBroker"]] obj["SecurityType"] = "IRS" obj["StrategyCode"] = f"{obj['portfolio']}/{obj['folder']}" obj["FillPrice"] = obj["AvgPrice"] obj["BuySellShortCover"] = "B" if obj["payreceive"] else "S" obj["IDSource"] = "USERID" - self.product.citco_stage() obj["SecurityID"] = self.product.dealid obj["ClearingAgent"] = "BOA_FC" return obj @@ -1621,7 +1637,7 @@ class TrancheProduct( self.stage() self.commit() self.get_productid() - obj = super().to_citco() + obj = super().to_citco(action) obj["Command"] = "N" obj["Active"] = "Y" obj["CouponRate"] = obj["CouponRate"] / 100 @@ -1697,8 +1713,10 @@ class SwaptionProduct( self.stage() self.commit() self.get_productid() - obj = super().to_citco() - if self.underlying_id_source == "USERID": + obj = super().to_citco(action) + if ( + self.underlying_id_source == "USERID" + ): # Implies this is a Interest Rate Swaption irs = IRSProduct( birth_date=self.birth_date, death_date=self.death_date, @@ -1781,7 +1799,7 @@ class IRSProduct( self.commit() self.get_productid() - obj = super().to_citco() + obj = super().to_citco(action) d = { "S_P_CurrencyCode": self.currency, "S_P_PaymentFreqID": _citco_frequency[self.fixed_payment_freq], @@ -1851,7 +1869,7 @@ class TRSProduct( self.stage() self.commit() self.get_productid() - obj = super().to_citco() + obj = super().to_citco(action) d = { f"S_P_CurrencyCode": self.currency, f"S_P_PaymentFreqID": _citco_frequency[self.funding_freq], |
