diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/admin_cls_upload.py | 74 | ||||
| -rw-r--r-- | python/report_ops/services.py | 8 |
2 files changed, 49 insertions, 33 deletions
diff --git a/python/admin_cls_upload.py b/python/admin_cls_upload.py index c290bb6a..1f9d9d88 100644 --- a/python/admin_cls_upload.py +++ b/python/admin_cls_upload.py @@ -4,34 +4,50 @@ from serenitas.ops.trade_dataclasses import SpotDeal from report_ops.services import get_service -fund = "BOWDST" -trade_date = datetime.date(2023, 6, 8) -conn = SpotDeal._conn -with conn.cursor() as c: - c.execute( - "SELECT ft.*, accounts2.cp_code as account_counterparty FROM forward_trades ft LEFT JOIN accounts2 USING (cash_account) WHERE ft.fund=%s AND ft.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 not in ("BONY",): - continue - service = get_service(account_counterparty) - for t in trades: - t["dealid"] = ( - f"{t['dealid']}.{t['fx_type'][0]}" - if t["fx_type"] != "SPOT" - else t["dealid"] - ) - trade = SpotDeal.from_dict(**t) - service.push_trade(trade, "NEW") - buf, dest = service.build_buffer("spot") - service.upload( - buf, - dest.name, - fund, - "CLS", +def upload_cls_file(conn, fund, trade_date, upload): + with conn.cursor() as c: + c.execute( + "SELECT ft.*, accounts2.cp_code as account_counterparty FROM forward_trades ft LEFT JOIN accounts2 USING (cash_account) WHERE ft.fund=%s AND ft.settle_date=%s AND accounts2.account_type='Cash';", + (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 not in ("BONY",): # Working on CLS + continue + service = get_service(account_counterparty) + for t in trades: + t["dealid"] = ( + f"{t['dealid']}.{t['fx_type'][0]}" + if t["fx_type"] != "SPOT" + else t["dealid"] + ) + trade = SpotDeal.from_dict(**t) + service.push_trade(trade, "NEW") + buf, dest = service.build_buffer("spot") + if upload: + service.upload( + buf, + dest.name, + fund, + "CLS", + ) + + +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() + conn = SpotDeal._conn + for fund in ("BOWDST",): + upload_cls_file(conn, fund, args.trade_date, not args.no_uplaod) diff --git a/python/report_ops/services.py b/python/report_ops/services.py index 23090b8c..7cb87047 100644 --- a/python/report_ops/services.py +++ b/python/report_ops/services.py @@ -3,11 +3,11 @@ from serenitas.ops.headers import HEADERS from serenitas.utils.exchange import ExchangeMessage, FileAttachment from .headers import get_bny_headers -from .misc import _settlement_recipients +from .misc import _settlement_recipients, _cc_recipients class BNY(Service, service_name="BNY"): - filepath_pattern = "CLS.{timestamp:%Y%m%d.%H%M%S}.{trade_tag}.csv" + filepath_pattern = "BNY.{timestamp:%Y%m%d.%H%M%S}.{trade_tag}.csv" credential = "bny_upload" @classmethod @@ -25,8 +25,8 @@ class BNY(Service, service_name="BNY"): em.send_email( f"BNY Upload Receipt {upload_type}", "", - to_recipients=(_settlement_recipients[fund],), - cc_recipients=(_cc_recipients[fund]), + to_recipients=_settlement_recipients[fund], + cc_recipients=_cc_recipients[fund], attach=(FileAttachment(name=dest, content=buf),), ) |
