diff options
Diffstat (limited to 'python/bondallocation_email.py')
| -rw-r--r-- | python/bondallocation_email.py | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/python/bondallocation_email.py b/python/bondallocation_email.py index 5ae8902e..12c63145 100644 --- a/python/bondallocation_email.py +++ b/python/bondallocation_email.py @@ -1,5 +1,6 @@ from serenitas.utils.db import dbconn from serenitas.utils.exchange import ExchangeMessage, FileAttachment +from exchangelib import HTMLBody import pandas as pd from io import StringIO import datetime @@ -24,34 +25,44 @@ if __name__ == "__main__": con=dawndb, params=(args.trade_date,), ) - for row in df.itertuples(): - with dawndb.cursor() as d: + with dawndb.cursor() as d: + for row in df.itertuples(): d.execute( - f"SELECT tradeid, notional, fund FROM bond_allocation LEFT JOIN accounts a USING (code) WHERE account_type='Cash' AND active AND trade_date={row.trade_date};" + f"SELECT tradeid, notional, fund FROM bond_allocation LEFT JOIN accounts a USING (code) WHERE account_type='Cash' AND active AND tradeid=%s;", + (row.tradeid,), ) em = ExchangeMessage() subject = ( f"LMCG - Trade Allocations - TD {row.trade_date} - {row.counterparty}" ) - cc_recipients = ("fyu@lmcg.com", "NYOPs") - allocations = "\n\t".join( - [f"- {row.notional:,.0f} to {alert[row.fund]}" for row in d] + cc_recipients = ("fyu@lmcg.com",) + # allocations = "<br>".join( + # [f"- {row.notional:,.0f} to {alert[row.fund]}" for row in d] + # ) + allocations = [ + "<li>" + f"- {row.notional:,.0f} to {alert[row.fund]}" + "</li>" + for row in d + ] + buf = StringIO() + bondtrade = ( + df[df["tradeid"] == row.tradeid] + .drop(columns=["allocation_contacts", "tradeid"]) + .round(2) ) + bondtrade.to_csv(buf, index=False) body = ( - f"For {row.identifier} please allocate :\n\n\t" - + allocations - + "\n\nTrade Details are attached in csv." - + "\n\n\nThanks,\nFlint" + f"<p>For {row.identifier} please allocate :<br><br><ul>" + + "".join(allocations) + + "</ul><br><br>Trade Details are attached in csv." + + "<br><br><br>Thanks,<br>Flint<br></p>" + + bondtrade.to_html(index=False) ) - buf = StringIO() - df[df["tradeid"] == row.tradeid].to_csv(buf) em.send_email( subject=subject, - to_recipients=row.allocation_contacts - if row.allocation_contacts - else ("fyu@lmcg.com,"), + # to_recipients=row.allocation_contacts if row.allocation_contacts else ('fyu@lmcg.com,'), + to_recipients=("fyu@lmcg.com",), cc_recipients=cc_recipients, - body=body, + body=HTMLBody(body), attach=[ FileAttachment( name=f"{row.trade_date}-{row.counterparty}-{row.identifier}.csv", |
