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
|
from itertools import groupby
import datetime
import argparse
from serenitas.utils.db2 import dbconn
from serenitas.ops.trade_dataclasses import BondDeal
from report_ops.services import get_service
conn = dbconn("dawndb")
def upload_to_custodian(fund, trade_date):
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;",
(
fund,
trade_date,
),
)
trades = [t._asdict() for t in c]
for account_counterparty, trades in groupby(
trades, lambda x: x["account_counterparty"]
):
if account_counterparty == "NT":
continue
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__":
parser = argparse.ArgumentParser()
parser.add_argument(
"trade_date",
type=datetime.date.fromisoformat,
default=datetime.date.today(),
nargs="?",
)
parser.add_argument(
"-n", "--no-upload", action="store_true", help="do not upload to CTM"
)
args = parser.parse_args()
for fund in ("SERCGMAST", "BOWDST", "BRINKER", "ISOSEL"):
upload_to_custodian(fund, args.trade_date)
|