diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/admin_security_upload.py | 27 | ||||
| -rw-r--r-- | python/report_ops/headers.py | 10 | ||||
| -rw-r--r-- | python/report_ops/services.py | 56 |
3 files changed, 93 insertions, 0 deletions
diff --git a/python/admin_security_upload.py b/python/admin_security_upload.py new file mode 100644 index 00000000..e63f33c8 --- /dev/null +++ b/python/admin_security_upload.py @@ -0,0 +1,27 @@ +from itertools import groupby +import datetime + +from serenitas.utils.db2 import dbconn +from serenitas.ops.trade_dataclasses import BondDeal + +from report_ops.services import get_service + +conn = dbconn("dawndb") + +with conn.cursor() as c: + c.execute( + "SELECT bt.*, accounts.counterparty AS account_counterparty FROM bond_trades bt LEFT JOIN accounts ON bt.account=accounts.code WHERE bt.fund=%s AND bt.trade_date=%s;", + ("BOWDST", datetime.date(2023, 5, 9)), + ) + trades = [t._asdict() for t in c] + for account_counterparty, trades in groupby( + trades, lambda x: x["account_counterparty"] + ): + service = get_service(account_counterparty) + for t in trades: + trade = BondDeal.from_dict(**t, scaled=True) + service.push_trade(trade, "NEW") + service.build_buffer("bond") + +if __name__ == "__main__": + pass diff --git a/python/report_ops/headers.py b/python/report_ops/headers.py index b3c53175..07d02287 100644 --- a/python/report_ops/headers.py +++ b/python/report_ops/headers.py @@ -372,3 +372,13 @@ def get_position_headers(fund): case _: return POSITION_HEADERS + + +def get_bny_headers(trade_type): + match trade_type: + case "repo": + return BNY_REPO_HEADER + case "cls": + return BNY_CLS_HEADER + case "bond" | "stock": + return BNY_SECURITY_HEADER diff --git a/python/report_ops/services.py b/python/report_ops/services.py new file mode 100644 index 00000000..8bebfe9a --- /dev/null +++ b/python/report_ops/services.py @@ -0,0 +1,56 @@ +from serenitas.ops.funds import Service +from serenitas.ops.headers import HEADERS + +from .headers import get_bny_headers + + +class BNY(Service, service_name="BNY"): + filepath_pattern = "BNY.{timestamp:%Y%m%d.%H%M%S}.{trade_tag}.csv" + credential = "bny_upload" + + @classmethod + def set_headers(cls, trade_type): + cls.headers = get_bny_headers(trade_type) + + @classmethod + def push_trade(cls, trade, action): + cls.staging_queue.append(trade.to_bny(action)) + + @classmethod + def upload(cls, buf, dest): + super().upload(buf, dest) + em = ExchangeMessage() + em.send_email( + "BNY Upload Receipt", + "", + to_recipients="NYOPs@lmcg.com", + attach=(FileAttachment(name=dest, content=buf),), + ) + + +class UMB(Service, service_name="UMB"): + filepath_pattern = "Serenitas.ALL.{timestamp:%Y%m%d.%H%M%S}.csv" + credential = "umb" + + @classmethod + def set_headers(cls, *args): + cls.headers = HEADERS["bond"] + [ + "DTC", + "AccruedPayment", + "PrincipalPayment", + "CurrentFace", + ] + + @classmethod + def push_trade(cls, trade, action): + cls.staging_queue.append(trade.to_umb(action)) + + +def get_service(account_counterparty): + match account_counterparty: + case "UMB": + return UMB + case "BONY": + return BNY + case "BBH": + return Service[account_counterparty] |
