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
|
from serenitas.utils.db import dbconn
import numpy as np
import datetime
import pandas as pd
from serenitas.utils.exchange import ExchangeMessage
from io import StringIO
from exchangelib import FileAttachment
import argparse
from serenitas.utils import SerenitasFileHandler
import logging
conn = dbconn("dawndb")
parser = argparse.ArgumentParser(description="determine sender destination")
parser.add_argument("--globeop", action="store_true", help="send to globeop")
args = parser.parse_args()
args = parser.parse_args()
logger = logging.getLogger(__name__)
if not logger.handlers:
fh = SerenitasFileHandler("quote_diff_bowdst.log")
logger.addHandler(fh)
logger.setLevel(logging.INFO)
with conn.cursor() as c:
df = pd.read_sql(
sql="SELECT * FROM list_bowd_quotes(%s)",
con=conn,
params=(datetime.date.today() - datetime.timedelta(1),),
)
try:
mask = np.isclose(df["bowd_price"], df["closeprice"], atol=0.15)
diff = df[~mask].rename(mapper={"closeprice": "our_price"}, axis=1)
except TypeError as e:
logger.error(e)
else:
if not diff.empty:
buf = StringIO()
diff = diff.round(decimals=2)
diff.to_csv(buf, index=False)
subject = "ACTION REQUESTED: Stale/Inaccurate Quotes"
msg = (
"Good morning,\n\n"
f"We notice a difference in our quotes by more than 15 cents for the following indices:\n\n"
f"{diff.to_string(index=False)}\n\n"
"We have also attached a copy of the csv for your convenience."
f"Thanks for your help.\n\n"
f"Flint"
)
attachments = [
FileAttachment(
name=f"quote_differences.csv", content=buf.getvalue().encode()
)
]
em = ExchangeMessage()
if args.globeop:
recipients = (
"hm-operations@bnymellon.com",
"caagprim@bnymellon.com",
)
cc_recipients = (
"fyu@lmcg.com",
"Bowdoin-Ops@LMCG.com",
)
else:
recipients = ("fyu@lmcg.com",)
cc_recipients = ()
em.send_email(
subject,
msg,
to_recipients=recipients,
cc_recipients=cc_recipients,
attach=attachments,
)
logger.info(diff)
logger.info("Program Executed")
|