1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
from .misc import _recipients
import datetime
from serenitas.utils.exchange import ExchangeMessage
from tabulate import tabulate
from exchangelib import HTMLBody
from dataclasses import dataclass
@dataclass
class BamlFcmNotify:
account: str
curr: str
totbal: float
homecurrency: str
fxrate: float
convtotbal: float
buysell: bool
valuedate: datetime.date
@classmethod
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: {self.account} Trade Date: {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 {self.account} Please let me know if you need more information.<br><br>{self.to_tabulate()}
</body>
</html>"""
),
to_recipients=_recipients["BAML_FCM"],
cc_recipients=_recipients["NYOPS"],
)
@classmethod
def process(cls, trade_date, d):
trade = cls.from_dict(d)
trade.email_fcm(trade_date)
|