diff options
Diffstat (limited to 'python/process_queue.py')
| -rw-r--r-- | python/process_queue.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/python/process_queue.py b/python/process_queue.py index 73242324..fe701dc2 100644 --- a/python/process_queue.py +++ b/python/process_queue.py @@ -345,16 +345,22 @@ def build_termination( with dawndb.cursor() as c: c.execute( - f"SELECT dealid, cp_code, notional FROM {table} where id=%s", (dealid,) + "SELECT dealid, cp_code, notional, termination_amount, globeop_id " + f"FROM {table} where id=%s", + (dealid,), ) - dealid, cp_code, notional = c.fetchone() + dealid, cp_code, notional, partial_amounts, globeopid = c.fetchone() + remaining_notional = notional - sum(partial_amounts) + termination_amount = termination_amount or remaining_notional c.execute( f"UPDATE {table} " - "SET termination_amount=%s, termination_cp=%s, termination_fee=%s, " - "termination_date=%s " + "SET termination_amount=termination_amount||%s::float8, " + "termination_cp=termination_cp||%s::text, " + "termination_fee=termination_fee||%s::float8, " + "termination_date=termination_date||%s::date " "WHERE dealid=%s", ( - termination_amount or notional, + termination_amount, termination_cp or cp_code, fee, termination_date, @@ -415,17 +421,18 @@ def build_termination( headers += ["InitialMargin", "InitialMarginCurrency"] if termination_cp is None: headers += ["Reserved"] * 4 + ["CreditEventOccured"] - d = { "DealType": deal_type, - "DealId": dealid, + "GoTradeId": int(globeopid[3:9]), "Action": "Update", "Client": "Serenitas", "SubAction": "Termination", - "PartialTermination": "N" if termination_amount is None else "Y", + "PartialTermination": "Y" + if remaining_notional - termination_amount > 0 + else "N", "TerminationAmount": termination_amount, "TerminationDate": termination_date, - "FeesPaid": fee if fee < 0 else None, + "FeesPaid": -fee if fee < 0 else None, "FeesReceived": fee if fee > 0 else None, "FeePaymentDate": (termination_date + 3 * bus_day).date(), } |
