aboutsummaryrefslogtreecommitdiffstats
path: root/python/admin_security_upload.py
blob: e63f33c8ee2d9395609aaf951355f6819aae3960 (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
from itertools import groupby
import datetime

from serenitas.utils.db2 import dbconn
from serenitas.ops.trade_dataclasses import BondDeal

from report_ops.services import get_service

conn = dbconn("dawndb")

with conn.cursor() as c:
    c.execute(
        "SELECT bt.*, accounts.counterparty AS account_counterparty FROM bond_trades bt LEFT JOIN accounts ON bt.account=accounts.code WHERE bt.fund=%s AND bt.trade_date=%s;",
        ("BOWDST", datetime.date(2023, 5, 9)),
    )
    trades = [t._asdict() for t in c]
    for account_counterparty, trades in groupby(
        trades, lambda x: x["account_counterparty"]
    ):
        service = get_service(account_counterparty)
        for t in trades:
            trade = BondDeal.from_dict(**t, scaled=True)
            service.push_trade(trade, "NEW")
        service.build_buffer("bond")

if __name__ == "__main__":
    pass