aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops/services.py
blob: 7cb87047b272e6f5f465455a5ac1478dddc6bf2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from serenitas.ops.funds import Service
from serenitas.ops.headers import HEADERS
from serenitas.utils.exchange import ExchangeMessage, FileAttachment

from .headers import get_bny_headers
from .misc import _settlement_recipients, _cc_recipients


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, fund, upload_type):
        super().upload(buf, dest, confirm=False)
        em = ExchangeMessage()
        em.send_email(
            f"BNY Upload Receipt {upload_type}",
            "",
            to_recipients=_settlement_recipients[fund],
            cc_recipients=_cc_recipients[fund],
            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["BRINKER"]
        case _:
            return None