aboutsummaryrefslogtreecommitdiffstats
path: root/python/position_file_bowdst.py
blob: c8a8424f87c0285c4d6134eb900d64fc26721502 (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
from report_ops.sma import build_position_file
import argparse
from serenitas.utils.remote import Client
from serenitas.utils.exchange import ExchangeMessage, FileAttachment
from report_ops.misc import _recipients, _cc_recipients
import datetime
from serenitas.analytics.dates import prev_business_day


def main(cob, fund, upload):
    buf, dest = build_position_file(
        cob,
        fund,
    )

    if upload:
        client = Client.from_creds("hm_globeop")
        client.put(buf, dest.name)
        em = ExchangeMessage()
        em.send_email(
            subject=f"Position_files for Bowdoin Street as of {cob}",
            body=f"Please see monthend positions for Bowdoin Street as of {cob}. They have been uploaded to the SFTP as well.",
            to_recipients=_recipients[fund],
            cc_recipients=_cc_recipients[fund],
            reply_to=_cc_recipients[fund],
            attach=[FileAttachment(name=dest.name, content=buf)],
        )


parser = argparse.ArgumentParser(
    description="Generate position files for Bowdoin Street"
)
parser.add_argument(
    "date",
    nargs="?",
    type=datetime.date.fromisoformat,
    default=prev_business_day((datetime.date.today().replace(day=1))),
)
parser.add_argument(
    "--no-upload",
    "-n",
    action="store_true",
    default=False,
    help="uploads to globeop",
)
args = parser.parse_args()
if (
    not prev_business_day(datetime.date.today()) == args.date and not args.no_upload
):  # We only want to upload if the previous business day was monthend
    pass
else:
    main(args.date, "BOWDST", not args.no_upload)