diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/ctm_allocation.py | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/python/ctm_allocation.py b/python/ctm_allocation.py index 7b612244..ba143ce7 100644 --- a/python/ctm_allocation.py +++ b/python/ctm_allocation.py @@ -3,6 +3,26 @@ import datetime from serenitas.ops.trade_dataclasses import BondDeal from serenitas.ops.funds import CTM + +def main(trade_date, upload): + with BondDeal._conn.cursor() as c, BondDeal._conn.cursor() as d: + c.execute( + "SELECT id FROM bonds LEFT JOIN counterparties ON cp_code=code " + "WHERE trade_date=%s AND ctm_code IS NOT NULL AND not emailed", + (trade_date,), + ) + for (tid,) in c: + trade = BondDeal.from_tradeid(tid) + CTM.stage(trade) + d.execute("UPDATE bonds SET emailed=True WHERE id=%s", (tid,)) + if not CTM.staging_queue: + return + buf, dest = CTM.build_buffer() + if upload: + CTM.upload(buf) + BondDeal._conn.commit() + + if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( @@ -10,15 +30,8 @@ if __name__ == "__main__": type=datetime.date.fromisoformat, default=datetime.date.today(), ) + parser.add_argument( + "-n", "--no-upload", action="store_true", help="do not upload to CTM" + ) args = parser.parse_args() - with BondDeal._conn.cursor() as c: - c.execute( - "SELECT id FROM bonds LEFT JOIN counterparties ON cp_code=code " - "WHERE trade_date=%s AND ctm_code IS NOT NULL", - (args.trade_date,), - ) - for (tid,) in c: - trade = BondDeal.from_tradeid(tid) - CTM.stage(trade) - buf, dest = CTM.build_buffer() - CTM.upload(buf) + main(args.trade_date, not args.no_upload) |
