diff options
Diffstat (limited to 'python/report_ops')
| -rw-r--r-- | python/report_ops/__main__.py | 6 | ||||
| -rw-r--r-- | python/report_ops/cash.py | 12 | ||||
| -rw-r--r-- | python/report_ops/custodians.py | 4 | ||||
| -rw-r--r-- | python/report_ops/wires.py | 24 |
4 files changed, 17 insertions, 29 deletions
diff --git a/python/report_ops/__main__.py b/python/report_ops/__main__.py index d91e788c..487954dd 100644 --- a/python/report_ops/__main__.py +++ b/python/report_ops/__main__.py @@ -1,12 +1,13 @@ from serenitas.analytics.dates import prev_business_day from serenitas.utils.db import dbconn +from serenitas.utils.exchange import ExchangeMessage import logging import argparse import datetime from .sma import SMA from .cash import CashReport from .admin import CitcoReport -from .wires import Wire +from .wires import WireReport from .custodians import upload_to_custodian, get_custodian_download_fun from .utils import notify_payment_settlements, notify_fx_hedge from .misc import _fund_custodians @@ -78,10 +79,11 @@ if args.sma_positions: logger.warning(e) if args.cash_reports: + em = ExchangeMessage() for fund, custodians in _fund_custodians.items(): for custodian in custodians: try: - get_custodian_download_fun(custodian).download_reports(args.date, fund) + get_custodian_download_fun(custodian)(args.date, fund, em=em) cash_report = CashReport[custodian] cash_report.to_db(args.date, fund) except ValueError as e: diff --git a/python/report_ops/cash.py b/python/report_ops/cash.py index 7068d649..ffc5f4c8 100644 --- a/python/report_ops/cash.py +++ b/python/report_ops/cash.py @@ -79,7 +79,7 @@ class CashReport: self.clear() -class NTCashReport(CashReport, NT, custodian="NT", dtkey="%Y%m%d%H%M"): +class NTCashReport(CashReport, custodian="NT", dtkey="%Y%m%d%H%M"): def yield_rows(self, fund): p = self.get_cash_report(f"NT_CASH_{fund}") df = pd.read_csv(p, on_bad_lines="warn") @@ -90,9 +90,7 @@ class NTCashReport(CashReport, NT, custodian="NT", dtkey="%Y%m%d%H%M"): yield from df.itertuples() -class UMBCashReport( - CashReport, UMB, fund="SERCGMAST", custodian="UMB", dtkey="%Y%m%d%H%M" -): +class UMBCashReport(CashReport, custodian="UMB", dtkey="%Y%m%d%H%M"): def yield_rows(self, fund): p = self.get_cash_report("UMB_CASH_{fund}") df = pd.read_excel(p, skiprows=3) @@ -101,9 +99,7 @@ class UMBCashReport( ].items() -class BNYCashReport( - CashReport, BNY, fund="BOWDST", custodian="BNY", dtkey="%Y%m%d%H%M%S" -): +class BNYCashReport(CashReport, custodian="BNY", dtkey="%Y%m%d%H%M%S"): def yield_rows(self): p = self.get_cash_report("BNY_CASH_{fund}") df = pd.read_csv(p) @@ -118,7 +114,7 @@ class BNYCashReport( )["Beginning Balance Local"].items() -class ScotiaCashReport(CashReport, SCOTIA, custodian="SCOTIA", dtkey="%Y%m%d%H%M%S"): +class ScotiaCashReport(CashReport, custodian="SCOTIA", dtkey="%Y%m%d%H%M%S"): def yield_rows(self): p = self.get_cash_report() df = pd.read_excel(p, skipfooter=1) diff --git a/python/report_ops/custodians.py b/python/report_ops/custodians.py index 90e081d5..2f9bf6fd 100644 --- a/python/report_ops/custodians.py +++ b/python/report_ops/custodians.py @@ -184,7 +184,7 @@ def download_bny_reports(date, fund, em): p.write_bytes(attach.content) -def download_scotia_reports(date, fund): +def download_scotia_reports(date, fund, **kwargs): try: return download_scotia_report(date) except ( @@ -195,7 +195,7 @@ def download_scotia_reports(date, fund): raise ValueError(f"No Scotia report {fund}:{date}") -def download_gstx_reports(date, fund): +def download_gstx_reports(date, fund, **kwargs): sftp = Client.from_creds("gstx") pattern = r"(\d{4}-\d{2}-\d{2}T\d{2}_\d{2}_\d{2}\.\d{6})" for f in sftp.client.listdir(): diff --git a/python/report_ops/wires.py b/python/report_ops/wires.py index b4076784..297d5e58 100644 --- a/python/report_ops/wires.py +++ b/python/report_ops/wires.py @@ -9,7 +9,6 @@ from serenitas.ops.trade_dataclasses import Deal, Ccy from serenitas.analytics.dates import prev_business_day from serenitas.utils.env import DAILY_DIR -from .custodians import NT, BNY, UMB, SCOTIA from .misc import get_dir, dt_from_fname _nt_to_currency = {"EURO - EUR": "EUR", "U.S. DOLLARS - USD": "USD"} @@ -18,9 +17,8 @@ CUSTODIAN = Literal["UMB", "NT", "BNY"] @dataclass -class Wire(Deal, table_name="custodian_wires", deal_type="custodian_wires"): +class WireReport(Deal, table_name="custodian_wires", deal_type="custodian_wires"): date: datetime.date - fund: ClassVar[CUSTODIAN] custodian: ClassVar[str] entry_date: datetime.date value_date: datetime.date @@ -31,19 +29,13 @@ class Wire(Deal, table_name="custodian_wires", deal_type="custodian_wires"): unique_ref: str dtkey: ClassVar = field(metadata={"insert": False, "select": False}) - def __init_subclass__(cls, fund, custodian, dtkey, **kwargs): + def __init_subclass__(cls, custodian, dtkey, **kwargs): cls._sql_insert = ( cls._sql_insert.removesuffix("RETURNING *") + "ON CONFLICT (unique_ref) DO NOTHING RETURNING *" ) - cls.fund = fund cls.custodian = custodian - cls._registry[ - ( - fund, - custodian, - ) - ] = cls + cls._registry[custodian] = cls cls.dtkey = dtkey def __post_init__(self): @@ -67,7 +59,7 @@ class Wire(Deal, table_name="custodian_wires", deal_type="custodian_wires"): return p -class BowdstBNYWire(Wire, BNY, fund="BOWDST", custodian="BNY", dtkey="%Y%m%d%H%M%S"): +class BNYWireReport(WireReport, custodian="BNY", dtkey="%Y%m%d%H%M%S"): @classmethod def from_report_line(cls, line: dict): return cls( @@ -93,7 +85,7 @@ class BowdstBNYWire(Wire, BNY, fund="BOWDST", custodian="BNY", dtkey="%Y%m%d%H%M cls.commit() -class SeleneNTWire(Wire, NT, fund="ISOSEL", custodian="NT", dtkey="%Y%m%d%H%M"): +class NTWireReport(WireReport, custodian="NT", dtkey="%Y%m%d%H%M"): @classmethod def from_report_line(cls, line: dict): return cls( @@ -118,9 +110,7 @@ class SeleneNTWire(Wire, NT, fund="ISOSEL", custodian="NT", dtkey="%Y%m%d%H%M"): cls.commit() -class SerenitasUMBWire( - Wire, UMB, fund="SERCGMAST", custodian="UMB", dtkey="%Y%m%d%H%M" -): +class UMBWireReport(WireReport, custodian="UMB", dtkey="%Y%m%d%H%M"): @classmethod def from_report_line(cls, line: dict): return cls( @@ -159,7 +149,7 @@ class SerenitasUMBWire( cls.commit() -class SeleneSCOTIAWire(Wire, SCOTIA, fund="ISOSEL", custodian="SCOTIA", dtkey=None): +class SCOTIAWireReport(WireReport, custodian="SCOTIA", dtkey=None): @classmethod def from_report_line(cls, line: dict): return cls( |
