aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops/custodians.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/report_ops/custodians.py')
-rw-r--r--python/report_ops/custodians.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/python/report_ops/custodians.py b/python/report_ops/custodians.py
index eab6cb9f..36703f54 100644
--- a/python/report_ops/custodians.py
+++ b/python/report_ops/custodians.py
@@ -1,8 +1,8 @@
-from serenitas.utils.exchange import ExchangeMessage
+from serenitas.utils.exchange import ExchangeMessage, FileAttachment
from serenitas.utils.env import DAILY_DIR
import warnings
import datetime
-from .misc import get_dir
+from .misc import get_dir, _recipients, _cc_recipients
import gpg
from serenitas.ops.trade_dataclasses import BondDeal
from serenitas.ops.funds import Service
@@ -11,21 +11,28 @@ from dataclasses import dataclass
_sql = (
"INSERT INTO bond_csv_upload (allocationid, identifier, principal, interest) SELECT id, identifier, principal_payment, "
- "accrued_payment FROM bond_trades WHERE trade_date=%s AND account=%s AND tradeid IS NOT NULL ON CONFLICT DO NOTHING RETURNING *"
+ "accrued_payment FROM bond_trades WHERE trade_date=%s AND account=%s AND tradeid IS NOT NULL ON CONFLICT DO NOTHING RETURNING allocationid;"
)
+_bond_query = "SELECT * FROM bond_trades WHERE id in %s;"
-def upload_to_custodian(account, trade_date, conn, upload):
- _fund = {"BBH": "BRINKER", "UMB": "UMB"}
- custodian = Service[_fund[account]]
+
+def upload_to_custodian(account, trade_date, conn, upload, em):
+ _service = {"BBH": "BRINKER", "UMB": "UMB"}
+ _fund = {"BBH": "BRINKER", "UMB": "SERCGMAST"}
+ custodian = Service[_service[account]]
with conn.cursor() as c:
c.execute(
_sql,
(
trade_date,
- account,
+ "BAC" if account == "UMB" else account,
),
)
+ tids = tuple(row.allocationid for row in c)
+ if not tids:
+ return
+ c.execute(_bond_query, (tids,))
for row in c:
trade = BondDeal.from_dict(**row._asdict(), scaled=True)
match account:
@@ -37,6 +44,15 @@ def upload_to_custodian(account, trade_date, conn, upload):
custodian.staging_queue.clear()
conn.commit()
if upload:
+ em = ExchangeMessage()
+ em.send_email(
+ f"{account}: Bond Positions Uploaded for {trade_date}",
+ "Hi, \nWe've just uploaded the positions via SFTP. File receipt attached to this email",
+ _recipients.get(account, _cc_recipients[_fund[account]]),
+ cc_recipients=_cc_recipients[_fund[account]],
+ reply_to=_cc_recipients[_fund[account]],
+ attach=(FileAttachment(name=dest.name, content=buf),),
+ )
custodian.upload(buf, dest.name, confirm=account != "UMB")
@@ -82,7 +98,7 @@ class UMB(Custodian, account="UMB"):
for attach in msg.attachments:
timestamp = attach.last_modified_time
if (
- attach.name.startswith("cash_reporting")
+ attach.name.startswith("cash_balances_umb")
and timestamp.date() == date
):
dest = get_dir(timestamp.date(), archived=False)
@@ -138,7 +154,3 @@ class BNY(Custodian, account="BONY2"):
p.parent.mkdir(parents=True, exist_ok=True)
if not p.exists():
p.write_bytes(attach.content)
-
-
-class BBH(Custodian, account="BBH"):
- pass