aboutsummaryrefslogtreecommitdiffstats
path: root/python/baml_fcm_fx.py
blob: 56d2068f7ec0db2df3fe4d2b01b276bed9bb9778 (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
71
import datetime
from citco_ops.utils import BamlFcmNotify
from serenitas.utils.db2 import dbconn
from tabulate import tabulate

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()
    sql_str = (
        "SELECT settle_date, buy_currency, buy_amount, "
        "sell_currency, sell_amount, spot_rate, cash_account FROM spots "
        "WHERE cash_account in ('V0NSCLMSPT', '6MZ20K79') AND trade_date = %s"
    )
    dawndb = dbconn("dawndb")
    with dawndb.cursor() as c:
        c.execute(sql_str, (args.date,))
        rec = next(iter(c))
    if rec:
        if rec.buy_currency == "EUR":
            cash_account = (
                "6MZ20049" if rec.cash_account == "V0NSCLMSPT" else rec.cash_account
            )
            data = [
                cash_account,
                "EUR",
                -rec.buy_amount,
                "USD",
                rec.spot_rate,
                rec.sell_amount,
                "Buy",
                rec.settle_date,
            ]
        else:
            data = [
                cash_account,
                "EUR",
                rec.sell_amount,
                "USD",
                rec.spot_rate,
                rec.buy_amount,
                "Sell",
                rec.settle_date,
            ]
        num_format = [("{0:,.2f}", 2), ("{0:.5f}", 4), ("{0:,.2f}", 5)]
        for f, i in num_format:
            data[i] = f.format(data[i])

        t = tabulate(
            [data],
            headers=[
                "account",
                "curr",
                "TotBal",
                "HomeCurrency",
                "fxRate",
                "convTotBal",
                "BuySell",
                "Value Date",
            ],
            tablefmt="unsafehtml",
        )
        BamlFcmNotify.email_fcm(args.date, t, cash_account)