from serenitas.analytics.dates import prev_business_day from serenitas.utils.db import dbconn from serenitas.utils.exchange import ExchangeMessage import datetime import logging _recipients = { "BOWDST": ( "shkumar@sscinc.com", "hedgemark.lmcg.ops@sscinc.com", "hm-operations@bnymellon.com", ), "SERCGMAST": ( "SERENITAS.FA@sscinc.com", "SERENITAS.ops@sscinc.com", ), } def _formatting(gfs_values): if not gfs_values: return None else: return "\n".join( f"\t* {amount:,.2f} {currency}" for currency, amount in gfs_values.items() ) def gfs_values(ped, conn, fund): sql_str = "SELECT endqty, invccy FROM valuation_reports vr WHERE fund=%s AND port ='GFS_HELPER_BUSINESS_UNIT' AND periodenddate =%s AND abs(endqty) > 50000;" with conn.cursor() as c: c.execute(sql_str, (fund, ped)) return _formatting({row.invccy: row.endqty for row in c}) if __name__ == "__main__": import argparse parser = argparse.ArgumentParser() parser.add_argument( "workdate", nargs="?", type=datetime.date.fromisoformat, default=prev_business_day(datetime.date.today()), help="working date", ) args = parser.parse_args() logger = logging.getLogger(__name__) conn = dbconn("dawndb") em = ExchangeMessage() for fund in ("BOWDST", "SERCGMAST"): if vals := gfs_values(args.workdate, conn, fund): em.send_email( f"GFS Helper Strategy Issue: {fund}", "Good morning, \n\nWe noticed some cash in the GFS helper strategy that shouldn't be there:\n\n" + vals, to_recipients=_recipients[fund], cc_recipients=( "Bowdoin-Ops@LMCG.com" if fund == "BOWDST" else "NYOps@lmcg.com", ), )