from serenitas.utils.db import dbconn import numpy as np import datetime import pandas as pd from serenitas.utils.exchange import ExchangeMessage from io import StringIO from exchangelib import FileAttachment import argparse conn = dbconn("dawndb") parser = argparse.ArgumentParser(description="determine sender destination") parser.add_argument("--globeop", action="store_true", help="send to globeop") args = parser.parse_args() with conn.cursor() as c: df = pd.read_sql( sql="SELECT * FROM list_bowd_quotes(%s)", con=conn, params=(datetime.date.today() - datetime.timedelta(1),), ) try: diff = df[~np.isclose(df["bowd_price"], df["closeprice"], atol=0.15)].rename( mapper={"closeprice": "our_price"}, axis=1 ) except TypeError: breakpoint() else: if not diff.empty: buf = StringIO() diff.to_csv(buf, index=False) subject = "ACTION REQUESTED: Stale/Inaccurate Quotes" msg = ( "Good morning,\n\n" f"We notice a difference in our quotes by more than 15 cents for the following indices:\n\n" f"{diff.to_string(index=False)}\n\n" "We have also attached a copy of the csv for your convenience." f"Thanks for your help.\n\n" f"Flint" ) attachments = [ FileAttachment( name=f"quote_differences.csv", content=buf.getvalue().encode() ) ] em = ExchangeMessage() if args.globeop: recipients = ( "hm-operations@bnymellon.com", "caagprim@bnymellon.com", ) cc_recipients = ( "fyu@lmcg.com", "Bowdoin-Ops@LMCG.com", ) else: recipients = ("fyu@lmcg.com",) cc_recipients = () em.send_email( subject, msg, to_recipients=recipients, cc_recipients=cc_recipients, attach=attachments, )