aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/otc_fx.py85
-rw-r--r--python/report_ops/misc.py6
2 files changed, 90 insertions, 1 deletions
diff --git a/python/otc_fx.py b/python/otc_fx.py
new file mode 100644
index 00000000..870cf1be
--- /dev/null
+++ b/python/otc_fx.py
@@ -0,0 +1,85 @@
+import datetime
+from tabulate import tabulate
+from exchangelib import HTMLBody
+
+from serenitas.utils.db2 import dbconn
+from serenitas.utils.exchange import ExchangeMessage
+
+from report_ops.utils import Monitor
+
+from report_ops.misc import _settlement_recipients, _cc_recipients
+
+
+class FXMonitor(
+ Monitor,
+ headers=(
+ "dealid",
+ "trade_date",
+ "settle_date",
+ "cp_code",
+ "name",
+ "buy_currency",
+ "buy_amount",
+ "sell_currency",
+ "sell_amount",
+ ),
+ num_format=[("{0:,.2f}", 6), ("{0:,.2f}", 8)],
+):
+ @classmethod
+ def email(cls, fund, settle_date):
+ if not cls._staging_queue:
+ return
+ cls._em.send_email(
+ f"FX Settlements {fund}: {settle_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>We see the below FX Settlements for VD {settle_date}. Could you please draft wires and reach out to the counterparty? As these are electronically agreed, please send out the funds regardless of confirmation from counterparty.<br><br>{cls.to_tabulate()}
+ </body>
+</html>"""
+ ),
+ to_recipients=_settlement_recipients[fund],
+ cc_recipients=_cc_recipients[fund],
+ )
+
+
+def email_setts(settle_date, conn, fund):
+ QUERY = "SELECT dealid, trade_date, settle_date, ft.cp_code, ft.name, buy_currency, buy_amount, sell_currency, sell_amount FROM forward_trades ft LEFT JOIN accounts2 USING (cash_account) WHERE accounts2.fund=%s AND ft.settle_date=%s;"
+ with conn.cursor() as c:
+ c.execute(
+ QUERY,
+ (fund, settle_date),
+ )
+ for rec in c:
+ d = rec._asdict()
+ FXMonitor.stage(d)
+ FXMonitor.email(fund, settle_date)
+ FXMonitor.clear()
+
+
+if __name__ == "__main__":
+ import argparse
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "date",
+ nargs="?",
+ type=datetime.date.fromisoformat,
+ default=datetime.date.today(),
+ help="working date",
+ )
+ args = parser.parse_args()
+ conn = dbconn("dawndb")
+ for fund in (
+ "SERCGMAST",
+ "ISOSEL",
+ "BOWDST",
+ ):
+ email_setts(args.date, conn, fund)
diff --git a/python/report_ops/misc.py b/python/report_ops/misc.py
index 5e63d56e..0ad79388 100644
--- a/python/report_ops/misc.py
+++ b/python/report_ops/misc.py
@@ -66,7 +66,11 @@ _settlement_recipients = {
"serenitas.otc@sscinc.com",
"serenitas.ops@sscinc.com",
),
- "ISOSEL": ("derivatives_settlements@citco.com",),
+ "ISOSEL": (
+ "derivatives_settlements@citco.com",
+ "bci-ops@innocap.com",
+ "margincalls@innocap.com",
+ ),
"BRINKER": ("nyops@lmcg.com",),
}