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)