aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/report_ops/__main__.py17
-rw-r--r--python/report_ops/wires.py39
-rw-r--r--sql/dawn.sql7
3 files changed, 50 insertions, 13 deletions
diff --git a/python/report_ops/__main__.py b/python/report_ops/__main__.py
index a5172a24..856fe928 100644
--- a/python/report_ops/__main__.py
+++ b/python/report_ops/__main__.py
@@ -97,11 +97,18 @@ if args.isosel_reports:
logger.warning(e)
if args.wire_reports:
- for fund in ("BOWDST", "ISOSEL"):
- try:
- Wire[fund].to_db(args.date)
- except ValueError as e:
- logger.warning(e)
+ for fund, custodians in _fund_custodians.items():
+ for custodian in custodians:
+ report = Wire[
+ (
+ fund,
+ custodian,
+ )
+ ]
+ try:
+ report.to_db(args.date)
+ except ValueError as e:
+ logger.warning(e)
if args.send_to_custodians:
for account in (
diff --git a/python/report_ops/wires.py b/python/report_ops/wires.py
index 50f8284d..a2f5ce1d 100644
--- a/python/report_ops/wires.py
+++ b/python/report_ops/wires.py
@@ -1,8 +1,9 @@
from dataclasses import dataclass
+from typing import Literal
import datetime
from serenitas.ops.trade_dataclasses import Deal, Ccy
from typing import ClassVar
-from .custodians import NT, BNY
+from .custodians import NT, BNY, UMB
from .misc import get_dir, dt_from_fname
from dataclasses import field
from csv import DictReader
@@ -10,11 +11,14 @@ from functools import partial
_nt_to_currency = {"EURO - EUR": "EUR", "U.S. DOLLARS - USD": "USD"}
+CUSTODIAN = Literal["UMB", "NT", "BNY"]
+
@dataclass
class Wire(Deal, table_name="custodian_wires", deal_type="custodian_wires"):
date: datetime.date
- fund: ClassVar[str]
+ fund: ClassVar[CUSTODIAN]
+ custodian: ClassVar[str]
entry_date: datetime.date
value_date: datetime.date
pay_date: datetime.date
@@ -24,13 +28,19 @@ 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, dtkey, **kwargs):
+ def __init_subclass__(cls, fund, custodian, dtkey, **kwargs):
cls._sql_insert = (
cls._sql_insert.removesuffix("RETURNING *")
+ "ON CONFLICT (unique_ref) DO NOTHING RETURNING *"
)
cls.fund = fund
- cls._registry[fund] = cls
+ cls.custodian = custodian
+ cls._registry[
+ (
+ fund,
+ custodian,
+ )
+ ] = cls
cls.dtkey = dtkey
def __post_init__(self):
@@ -53,7 +63,7 @@ class Wire(Deal, table_name="custodian_wires", deal_type="custodian_wires"):
return p
-class BowdstWire(Wire, BNY, fund="BOWDST", dtkey="%Y%m%d%H%M%S"):
+class BowdstBNYWire(Wire, BNY, fund="BOWDST", custodian="BNY", dtkey="%Y%m%d%H%M%S"):
@classmethod
def from_report_line(cls, line: dict):
return cls(
@@ -79,7 +89,7 @@ class BowdstWire(Wire, BNY, fund="BOWDST", dtkey="%Y%m%d%H%M%S"):
cls.commit()
-class SeleneWire(Wire, NT, fund="ISOSEL", dtkey="%Y%m%d%H%M"):
+class SeleneNTWire(Wire, NT, fund="ISOSEL", custodian="NT", dtkey="%Y%m%d%H%M"):
@classmethod
def from_report_line(cls, line: dict):
return cls(
@@ -102,3 +112,20 @@ class SeleneWire(Wire, NT, fund="ISOSEL", dtkey="%Y%m%d%H%M"):
if "sponsor" in line["narrative"].lower():
cls.from_report_line(line).stage()
cls.commit()
+
+
+class SerenitasUMBWire(
+ Wire, UMB, fund="SERCGMAST", custodian="UMB", dtkey="%Y%m%d%H%M"
+):
+ @classmethod
+ def from_report_line(cls, line: dict):
+ return
+
+ @classmethod
+ def to_db(cls, date):
+ # conn = cls._conn
+ # with conn.cursor() as c:
+ # c.execute("DELETE FROM custodian_wires WHERE date=%s AND fund=%s AND custodian=%s", (date, cls.fund, cls.custodian,))
+ # conn.commit()
+ # the unique ref will be generated from the row + the date and reports will only be delivered at 7pm daily
+ pass
diff --git a/sql/dawn.sql b/sql/dawn.sql
index e454b175..cabe0f43 100644
--- a/sql/dawn.sql
+++ b/sql/dawn.sql
@@ -3997,7 +3997,8 @@ CREATE TABLE custodian_wires(
currency currency,
amount float8 NOT NULL,
wire_details text,
- unique_ref text PRIMARY KEY);
+ unique_ref text PRIMARY KEY,
+ custodian custodian NOT NULL);
@@ -4191,4 +4192,6 @@ si.currency, si.fund, COALESCE(pfm.folder::text, strategy::text) AS folder
FROM (SELECT *, rank() OVER(PARTITION BY si.broker,si.fund ORDER BY date desc)
FROM strategy_im si WHERE si.fund=p_fund AND si.date<=p_date ORDER BY date DESC) si
LEFT JOIN portfolio_folder_mapping pfm ON pfm.clean_folder=si.strategy::TEXT
-WHERE RANK=1 and abs(amount) >= .01; END $$ LANGUAGE plpgsql; \ No newline at end of file
+WHERE RANK=1 and abs(amount) >= .01; END $$ LANGUAGE plpgsql;
+
+CREATE TYPE custodian AS ENUM('BNY', 'UMB', 'NT'); \ No newline at end of file