diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/notify_bowdst.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/python/notify_bowdst.py b/python/notify_bowdst.py index e5d8df58..616853e5 100644 --- a/python/notify_bowdst.py +++ b/python/notify_bowdst.py @@ -11,12 +11,14 @@ import logging fh = SerenitasFileHandler("mismatched_trades.log") logger = logging.getLogger(__name__) +if logger.hasHandlers(): + logger.handlers.clear() logger.addHandler(fh) logger.setLevel(logging.WARNING) conn = dbconn("dawndb") cob = (datetime.date.today() - BDay(1)).date() -dates = pd.bdate_range(end=cob, periods=50) +dates = pd.date_range(end=cob, periods=50) df = pd.concat( { d: pd.read_sql_query( @@ -41,7 +43,11 @@ for row in inaccurate_balances.itertuples(): new_df = df[df["security_desc"] == row.security_desc] try: - data = new_df[new_df["globeop_notional"] == new_df["db_notional"]].iloc[0, :] + data = ( + new_df[new_df["globeop_notional"] == new_df["db_notional"]] + .sort_index(ascending=False) + .iloc[0, :] + ) security_desc = data.security_desc date = data.name globeop_notional = data.globeop_notional @@ -50,19 +56,22 @@ for row in inaccurate_balances.itertuples(): continue buf = StringIO() - df = pd.read_sql_query( - "SELECT * FROM cds WHERE trade_date > %s " + output = pd.read_sql_query( + "SELECT * FROM cds WHERE trade_date > %s and trade_date <= %s " "AND fund = 'BOWDST' AND security_desc = %s " "AND orig_detach IS NULL AND orig_attach IS NULL ORDER BY trade_date DESC", conn, - params=(date, security_desc), + params=(date, cob, security_desc), ) - if not df[df.trade_date >= cob - BDay(1)].empty: + if not output[output.trade_date >= cob - BDay(1)].empty: + print( + f"Mismatch balance {row.security_desc} {row.globeop_notional} :{row.db_notional} Trades Recently" + ) logger.error( f"Mismatch balance {row.security_desc} {row.globeop_notional} :{row.db_notional} Trades Recently" ) continue - df.to_csv(buf) + output.to_csv(buf) attachments = [ FileAttachment(name=f"{security_desc}.csv", content=buf.getvalue().encode()) ] |
