diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/mtm_status.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/python/mtm_status.py b/python/mtm_status.py index f60f0666..b2af76cc 100644 --- a/python/mtm_status.py +++ b/python/mtm_status.py @@ -4,6 +4,7 @@ import pandas as pd from serenitas.utils.db import dbconn from psycopg2.errors import UniqueViolation from zipfile import ZipFile +import numpy as np def latest(f): @@ -20,11 +21,14 @@ def run(conn, date): df = pd.read_csv(zip_handle, skiprows=2) df = df[(df["SwapType"] == "NEW") & (df["Executed"])] + breakpoint() + df = df.replace({np.nan: None}) place_holders = ",".join(["%s"] * 7) sql_str = f"INSERT INTO mtm_submissions VALUES({place_holders})" with conn.cursor() as c: for row in df.itertuples(): + cpty_id = ( int(row.BrokerSecRef) if type(row.BrokerSecRef) == float @@ -40,7 +44,7 @@ def run(conn, date): row.ProductType, row.BrokerId, row.SwapType, - cpty_id, + cpty_id if cpty_id else None, ), ) except UniqueViolation: @@ -48,7 +52,7 @@ def run(conn, date): else: _product_type = {"CDISW": "swaptions", "TRN": "cds"} sql_str = f"UPDATE {_product_type[row.ProductType]} SET cpty_id = %s WHERE dealid = %s" - if row.SwapType == "NEW" and row.BrokerId != "BNPBNY": + if (row.SwapType == "NEW") and (row.BrokerId != "BNPBNY") and (cpty_id): c.execute(sql_str, (cpty_id, row.TicketNo)) conn.commit() |
