aboutsummaryrefslogtreecommitdiffstats
path: root/python/citco_ops/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/citco_ops/utils.py')
-rw-r--r--python/citco_ops/utils.py54
1 files changed, 48 insertions, 6 deletions
diff --git a/python/citco_ops/utils.py b/python/citco_ops/utils.py
index 450b2204..0c42306b 100644
--- a/python/citco_ops/utils.py
+++ b/python/citco_ops/utils.py
@@ -10,10 +10,19 @@ from psycopg.errors import UniqueViolation
from exchangelib import HTMLBody
from tabulate import tabulate
from functools import lru_cache
+from serenitas.analytics.dates import next_business_day
+from decimal import Decimal
+import math
logger = logging.getLogger(__name__)
+def next_business_days(date, offset):
+ for i in range(offset):
+ date = next_business_day(date)
+ return date
+
+
def get_file_status(s):
is_processed, fname_short = s.rsplit("_", 1)
is_processed = is_processed.rsplit("-")[1] == "PROCESSED"
@@ -58,6 +67,11 @@ def instrument_table(instrument_id):
return "citco_trs"
+def round_up(n, decimals=0):
+ multiplier = 10**decimals
+ return math.ceil(n * multiplier) / multiplier
+
+
@dataclass
class CitcoSubmission(Deal, deal_type=None, table_name="citco_submission"):
fname: str = field()
@@ -218,19 +232,47 @@ class Payment:
class PaymentSettlement(Payment):
@classmethod
- def email_innocap(cls, date):
+ def email_innocap(cls, date, account_balance):
if not cls._insert_queue:
return
+ cls.subtract_cash_balance(account_balance)
+ move_cash = ""
+ for currency in ("USD", "EUR"):
+ biggest_deficit = min(
+ list(
+ map(
+ lambda x: int(x.amount) if x.currency == currency else 0,
+ cls._insert_queue,
+ )
+ )
+ )
+ if biggest_deficit < 0:
+ move_cash += f"\n\n***Please move ${round_up(abs(biggest_deficit), -6):,.2f} {currency} to Northern Trust from Scotia and confirm when done.***"
em = ExchangeMessage()
em.send_email(
- f"Payment Settlements Bond/FX NT: ISOSEL {date}",
- "Good morning, \n\nWe have the following amounts settling in the next 4 calendar days at Northern Trust: (Positive Amounts = Receive, Negative Amounts=Pay)\n\n"
+ f"{'*ACTION REQUESTED* ' if move_cash else ''}Payment Settlements Bond/FX NT: ISOSEL {date}",
+ "Good morning, \n\nProjected Balances at Northern Trust: (Positive Amounts = Positive Balance, Negative Amounts = Negative Balance)\n\n"
+ "\n".join(
settlement.to_email_format() for settlement in cls._insert_queue
- ),
- to_recipients=_recipients["ISOSEL"],
- cc_recipients=("Selene-Ops@lmcg.com",),
+ )
+ + move_cash,
+ to_recipients=("fyu@lmcg.com",),
+ # cc_recipients=("Selene-Ops@lmcg.com",),
)
+ cls._insert_queue.clear()
+
+ @classmethod
+ def stage_payment(cls, settlements, date):
+ for row in settlements:
+ cls._insert_queue.append(cls(date, row.currency, row.payment_amount))
+
+ @classmethod
+ def subtract_cash_balance(cls, account_balance):
+ overdraft = []
+ for settlement in cls._insert_queue:
+ settlement.amount = Decimal(account_balance[settlement.currency]) - (
+ -settlement.amount
+ )
class GFSMonitor(Payment):