aboutsummaryrefslogtreecommitdiffstats
path: root/python/upload_umb_bonds.py
blob: 438734f9d23d8a5d35ae064d18aa504f8a78790a (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
import argparse
import datetime
from serenitas.ops.trade_dataclasses import BondDeal
from serenitas.ops.funds import UMB

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "trade_date",
        type=datetime.date.fromisoformat,
        default=datetime.date.today(),
    )
    args = parser.parse_args()
    sql_query = (
        "SELECT bonds.*, bond_allocation.notional, fund, custodian, "
        "cash_account, bond_submission.id as sid, allocation_id, action, "
        "counterparties.name, dtc_number "
        "FROM bonds "
        "INNER JOIN bond_allocation ON bond_allocation.tradeid=bonds.id "
        "INNER JOIN accounts USING (code) "
        "INNER JOIN bond_submission ON allocation_id=bond_allocation.id "
        "INNER JOIN counterparties ON counterparties.code = bonds.cp_code "
        "WHERE fund= %s and trade_date = %s "
        "ORDER BY fund, allocation_id, bonds"
    )
    with BondDeal._conn.cursor() as c:
        c.execute(
            sql_query,
            (
                "SERCGMAST",
                args.trade_date,
            ),
        )
        for row in c:
            UMB.stage(row._asdict(), trade_type="bond", redis_pipeline=None)
    buf, dest = UMB.build_buffer("bond")
    UMB.upload(buf, dest)