diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/report_ops/__main__.py | 14 | ||||
| -rw-r--r-- | python/report_ops/misc.py | 1 | ||||
| -rw-r--r-- | python/report_ops/utils.py | 59 |
3 files changed, 71 insertions, 3 deletions
diff --git a/python/report_ops/__main__.py b/python/report_ops/__main__.py index 194dd536..0f8f2440 100644 --- a/python/report_ops/__main__.py +++ b/python/report_ops/__main__.py @@ -1,5 +1,6 @@ from serenitas.analytics.dates import prev_business_day from serenitas.utils.exchange import ExchangeMessage +from serenitas.utils.db import dbconn import logging import argparse import datetime @@ -18,6 +19,7 @@ from .cash import NTCashReport, UMBCashReport, BNYCashReport from .admin import AccruedReport, AllReport from .wires import BowdstWire, NTWire from .custodians import upload_to_custodian +from .utils import notify_payment_settlements, PaymentMonitor logger = logging.getLogger(__name__) @@ -48,6 +50,12 @@ parser.add_argument( help="upload trade files to notify custodians", ) parser.add_argument( + "-ps", + "--payment_settlements", + action="store_true", + help="notify payment settlements by email", +) +parser.add_argument( "-n", "--no-upload", action="store_true", help="do not upload, just create files" ) parser.add_argument( @@ -111,3 +119,9 @@ if args.send_to_custodians: upload_to_custodian(account, args.date, not args.no_upload, em) except ValueError as e: logger.info(e) + +if args.payment_settlements: + conn = dbconn("dawndb") + for fund in ("SERCGMAST", "BRINKER", "BOWDST", "ISOSEL"): + notify_payment_settlements(date, fund, conn) + PaymentMonitor._insert_queue.clear() diff --git a/python/report_ops/misc.py b/python/report_ops/misc.py index e1edb7f3..5c39eac3 100644 --- a/python/report_ops/misc.py +++ b/python/report_ops/misc.py @@ -46,6 +46,7 @@ _settlement_recipients = { "BOWDST": _sma_recipients["BOWDST"], "SERCGMAST": ("lmcgcustody@umb.com",), "ISOSEL": ("derivative_settlements@citco.com",), + "BRINKER": ("nyops@lmcg.com",), } _cc_recipients = { diff --git a/python/report_ops/utils.py b/python/report_ops/utils.py index 1360f102..325a4179 100644 --- a/python/report_ops/utils.py +++ b/python/report_ops/utils.py @@ -15,14 +15,14 @@ from decimal import Decimal import math import re from zoneinfo import ZoneInfo -from .misc import _recipients, _cc_recipients +from .misc import _recipients, _cc_recipients, _settlement_recipients from tabulate import tabulate logger = logging.getLogger(__name__) def next_business_days(date, offset): - for i in range(offset): + for i in range(offset + 1): date = next_business_day(date) return date @@ -65,6 +65,20 @@ def round_up(n, decimals=0): return math.ceil(n * multiplier) / multiplier +def notify_payment_settlements(date, fund, conn): + end_date = next_business_days(date, 2) + with conn.cursor() as c: + c.execute( + "SELECT * from payment_settlements WHERE settle_date BETWEEN %s AND %s AND fund= %s AND asset_class in ('SPOT', 'SWAPTION', 'TRANCHE') ORDER BY settle_date asc", + (date, end_date, fund), + ) + for row in c: + d = row._asdict() + d["settlement_amount"] = d["payment_amount"] + PaymentMonitor.stage(row._asdict()) + PaymentMonitor.email(fund) + + @dataclass class CitcoSubmission(Deal, deal_type=None, table_name="citco_submission2"): id: int = field(init=False, metadata={"insert": False}) @@ -320,7 +334,7 @@ class SettlementMonitor( </style> </head> <body> - Good morning,<br><br>We see a projected overdraft on the below dates. Please move to cover:<br><br>{cls.to_tabulate()} + Hello,<br><br>We see a projected overdraft on the below dates. Please move to cover:<br><br>{cls.to_tabulate()} </body> </html>""" ), @@ -329,6 +343,45 @@ class SettlementMonitor( ) +class PaymentMonitor( + Monitor, + headers=( + "settle_date", + "account", + "name", + "cp_code", + "settlement_amount", + "currency", + "asset_class", + "ids", + ), + num_format=[("{0:,.2f}", 4)], +): + @classmethod + def email(cls, fund): + if not cls._insert_queue: + return + cls._em.send_email( + f"Projected Settlements: {fund}", + 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 settlements in the next two days (Positive=Receive, Negative=Pay):<br><br>{cls.to_tabulate()} + </body> +</html>""" + ), + to_recipients=_settlement_recipients[fund], + cc_recipients=_cc_recipients[fund], + ) + + @dataclass class EmailOps: _em = ExchangeMessage() |
