aboutsummaryrefslogtreecommitdiffstats
path: root/python/baml_fcm_fx.py
blob: 2ac9af9b8914d1ad32aac652fc79333f92b5cc0c (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
62
63
64
65
66
67
68
69
70
import datetime
from report_ops.utils import BamlFcmNotify
from serenitas.utils.db2 import dbconn
from tabulate import tabulate

_fcm_alias = {"V0NSCLMSPT": "6MZ20049"}


def main(trade_date, conn, fund):
    with conn.cursor() as c:
        c.execute(
            "SELECT spots.cash_account, buy_currency, sell_currency, buy_amount, sell_amount, spot_rate, settle_date FROM spots LEFT JOIN accounts2 USING (cash_account) WHERE account_type='Fcm' AND spots.cp_code='BAMSNY' AND spots.trade_date =%s AND spots.fund=%s;",
            (trade_date, fund),
        )
        for rec in c:
            rec = rec._asdict()
            if rec["sell_currency"] == "USD":
                key1, key2 = "buy", "sell"
            else:
                key1, key2 = "sell", "buy"
            fcm_account = _fcm_alias.get(rec["cash_account"], rec["cash_account"])
            line = [
                fcm_account,
                rec[f"{key1}_currency"],
                rec[f"{key1}_amount"],
                rec[f"{key2}_currency"],
                rec["spot_rate"],
                rec[f"{key2}_amount"],
                "Buy" if rec["sell_currency"] == "USD" else "Sell",
                rec["settle_date"],
            ]

            num_format = [("{0:,.2f}", 2), ("{0:.5f}", 4), ("{0:,.2f}", 5)]
            for f, i in num_format:
                line[i] = f.format(line[i])
            t = tabulate(
                [line],
                headers=[
                    "account",
                    "curr",
                    "TotBal",
                    "HomeCurrency",
                    "fxRate",
                    "convTotBal",
                    "BuySell",
                    "Value Date",
                ],
                tablefmt="unsafehtml",
            )
            BamlFcmNotify.email_fcm(trade_date, fcm_account, t)


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "date",
        nargs="?",
        type=datetime.date.fromisoformat,
        default=datetime.date.today(),
        help="working date",
    )
    args = parser.parse_args()
    conn = dbconn("dawndb")
    for fund in (
        "SERCGMAST",
        "ISOSEL",
    ):
        main(args.date, conn, fund)