aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/baml_fcm_fx.py43
-rw-r--r--python/report_ops/utils.py61
2 files changed, 65 insertions, 39 deletions
diff --git a/python/baml_fcm_fx.py b/python/baml_fcm_fx.py
index 2ac9af9b..927f8b02 100644
--- a/python/baml_fcm_fx.py
+++ b/python/baml_fcm_fx.py
@@ -5,49 +5,20 @@ from tabulate import tabulate
_fcm_alias = {"V0NSCLMSPT": "6MZ20049"}
+_sql_query = (
+ "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;"
+)
+
def main(trade_date, conn, fund):
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;",
+ _sql_query,
(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)
+ BamlFcmNotify.process(trade_date, rec._asdict())
if __name__ == "__main__":
diff --git a/python/report_ops/utils.py b/python/report_ops/utils.py
index 36839865..a1c3f42d 100644
--- a/python/report_ops/utils.py
+++ b/python/report_ops/utils.py
@@ -294,12 +294,62 @@ class GFSMonitor(Payment):
)
+@dataclass
class BamlFcmNotify:
+ account: str
+ curr: str
+ totbal: float
+ homecurrency: str
+ fxrate: float
+ convtotbal: float
+ buysell: bool
+ valuedate: datetime.date
+
@classmethod
- def email_fcm(cls, date, cash_account, data):
+ def from_dict(cls, d):
+ _fcm_alias = {"V0NSCLMSPT": "6MZ20049"}
+ if d["sell_currency"] == "USD":
+ key1, key2 = "buy", "sell"
+ else:
+ key1, key2 = "sell", "buy"
+ return cls(
+ account=_fcm_alias.get(d["cash_account"], d["cash_account"]),
+ curr=d[f"{key1}_currency"],
+ totbal=d[f"{key1}_amount"],
+ homecurrency=d[f"{key2}_currency"],
+ fxrate=d["spot_rate"],
+ convtotbal=d[f"{key2}_amount"],
+ buysell="Buy" if d["sell_currency"] == "USD" else "Sell",
+ valuedate=d["settle_date"],
+ )
+
+ def to_list(self):
+ return list(self.__dict__.values())
+
+ def to_tabulate(self):
+ line = self.to_list()
+ num_format = [("{0:,.2f}", 2), ("{0:.5f}", 4), ("{0:,.2f}", 5)]
+ for f, i in num_format:
+ line[i] = f.format(line[i])
+ return tabulate(
+ [line],
+ headers=[
+ "account",
+ "curr",
+ "TotBal",
+ "HomeCurrency",
+ "fxRate",
+ "convTotBal",
+ "BuySell",
+ "Value Date",
+ ],
+ tablefmt="unsafehtml",
+ )
+
+ def email_fcm(self, trade_date):
em = ExchangeMessage()
em.send_email(
- f"FX Details: {cash_account} {date}",
+ f"FX Details: {self.account} Trade Date: {trade_date}",
HTMLBody(
f"""
<html>
@@ -310,7 +360,7 @@ class BamlFcmNotify:
</style>
</head>
<body>
- Hello,<br><br>Please see below details for an FX Spot Trade we did with the desk today for account {cash_account} Please let me know if you need more information.<br><br>{data}
+ Hello,<br><br>Please see below details for an FX Spot Trade we did with the desk today for account {self.account} Please let me know if you need more information.<br><br>{self.to_tabulate()}
</body>
</html>"""
),
@@ -318,6 +368,11 @@ class BamlFcmNotify:
cc_recipients=("nyops@lmcg.com",),
)
+ @classmethod
+ def process(cls, trade_date, d):
+ trade = cls.from_dict(d)
+ trade.email_fcm(trade_date)
+
@dataclass
class EmailOps: