aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/baml_fcm_fx.py108
1 files changed, 70 insertions, 38 deletions
diff --git a/python/baml_fcm_fx.py b/python/baml_fcm_fx.py
index d24f02d5..2d332db3 100644
--- a/python/baml_fcm_fx.py
+++ b/python/baml_fcm_fx.py
@@ -2,52 +2,83 @@ import datetime
from report_ops.fcm import BamlFcmNotify
from serenitas.utils.db2 import dbconn
from tabulate import tabulate
+from report_ops.misc import _recipients, _cc_recipients
+from serenitas.utils.exchange import ExchangeMessage
+from exchangelib import HTMLBody
_fcm_alias = {"V0NSCLMSPT": "6MZ20049"}
-def main(trade_date, conn, fund):
+def email_fcm(em, d):
+ em = ExchangeMessage()
+ fcm_account = _fcm_alias.get(d["cash_account"], d["cash_account"])
+ em.send_email(
+ f"FX Details: {fcm_account} Trade Date: {d['trade_date']}",
+ HTMLBody(
+ f"""
+<html>
+ <head>
+ <style>
+ table, th, td {{ border: 1px solid black; border-collapse: collapse;}}
+ th, td {{ padding: 5px; }}
+ </style>
+ </head>
+ <body>
+ Hello,<br><br>Please see below details for an FX Spot Trade we did with the desk today for account {fcm_account} Please let me know if you need more information.<br><br>{to_tabulate(d)}
+ </body>
+</html>"""
+ ),
+ to_recipients=_recipients["BAML_FCM"],
+ cc_recipients=_cc_recipients[d["fund"]],
+ )
+
+
+def to_tabulate(d):
+ if d["sell_currency"] == "USD":
+ key1, key2 = "buy", "sell"
+ else:
+ key1, key2 = "sell", "buy"
+ fcm_account = _fcm_alias.get(d["cash_account"], d["cash_account"])
+ line = [
+ fcm_account,
+ d[f"{key1}_currency"],
+ d[f"{key1}_amount"],
+ d[f"{key2}_currency"],
+ d["spot_rate"],
+ d[f"{key2}_amount"],
+ "Buy" if d["sell_currency"] == "USD" else "Sell",
+ d["settle_date"],
+ ]
+
+ num_format = [("{0:,.2f}", 2), ("{0:.5f}", 4), ("{0:,.2f}", 5)]
+ for f, i in num_format:
+ line[i] = f.format(line[i])
+ t = tabulate(
+ [line],
+ headers=[
+ "account",
+ "curr",
+ "TotBal",
+ "HomeCurrency",
+ "fxRate",
+ "convTotBal",
+ "BuySell",
+ "Value Date",
+ ],
+ tablefmt="unsafehtml",
+ )
+ return t
+
+
+def main(trade_date, conn, fund, em):
with conn.cursor() as c:
c.execute(
- "SELECT spots.cash_account, buy_currency, sell_currency, buy_amount, sell_amount, spot_rate, settle_date FROM spots LEFT JOIN accounts2 USING (cash_account) WHERE account_type='Fcm' AND spots.cp_code='BAMSNY' AND spots.trade_date =%s AND spots.fund=%s;",
+ "SELECT spots.cash_account, buy_currency, sell_currency, buy_amount, sell_amount, spot_rate, settle_date, trade_date FROM spots LEFT JOIN accounts2 USING (cash_account) WHERE account_type='Fcm' AND spots.cp_code='BAMSNY' AND spots.trade_date =%s AND spots.fund=%s;",
(trade_date, fund),
)
for rec in c:
- rec = rec._asdict()
- if rec["sell_currency"] == "USD":
- key1, key2 = "buy", "sell"
- else:
- key1, key2 = "sell", "buy"
- fcm_account = _fcm_alias.get(rec["cash_account"], rec["cash_account"])
- line = [
- fcm_account,
- rec[f"{key1}_currency"],
- rec[f"{key1}_amount"],
- rec[f"{key2}_currency"],
- rec["spot_rate"],
- rec[f"{key2}_amount"],
- "Buy" if rec["sell_currency"] == "USD" else "Sell",
- rec["settle_date"],
- ]
-
- num_format = [("{0:,.2f}", 2), ("{0:.5f}", 4), ("{0:,.2f}", 5)]
- for f, i in num_format:
- line[i] = f.format(line[i])
- t = tabulate(
- [line],
- headers=[
- "account",
- "curr",
- "TotBal",
- "HomeCurrency",
- "fxRate",
- "convTotBal",
- "BuySell",
- "Value Date",
- ],
- tablefmt="unsafehtml",
- )
- BamlFcmNotify.email_fcm(trade_date, fcm_account, t)
+ d = rec._asdict()
+ email_fcm(em, d)
if __name__ == "__main__":
@@ -63,8 +94,9 @@ if __name__ == "__main__":
)
args = parser.parse_args()
conn = dbconn("dawndb")
+ em = ExchangeMessage()
for fund in (
"SERCGMAST",
"ISOSEL",
):
- main(args.date, conn, fund)
+ main(args.date, conn, fund, em)