diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/reallocate_iam.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/python/reallocate_iam.py b/python/reallocate_iam.py index ca1d9207..f444aa06 100644 --- a/python/reallocate_iam.py +++ b/python/reallocate_iam.py @@ -94,18 +94,22 @@ def gen_strat_alloc(conn, trade_date): def process_trades(conn, trade_date): # We will be grabbing the IAM deals from the DB for the new trades and for the updated trades deals = [] - actions = { - "NEW": ( - "UPDATE iam_tickets set uploaded=True where maturity is null and trade_date =%s and trade_date =%s " - "and action='NEW' and not uploaded returning *" + actions = [ + ( + "NEW", + "UPDATE iam_tickets set uploaded=True where maturity is null and trade_date =%s " + "and action='NEW' and not uploaded returning *", + (trade_date,), ), - "UPDATE": ( - "UPDATE iam_tickets set maturity=%s where trade_date != %s and maturity is null and action='NEW' returning *" + ( + "UPDATE", + "UPDATE iam_tickets set maturity=%s where trade_date != %s and maturity is null and action='NEW' returning *", + (trade_date, trade_date), ), - } - for action, query in actions.items(): + ] + for action, query, params in actions: with conn.cursor() as c: - c.execute(query, (trade_date, trade_date)) + c.execute(query, params) for row in c: deals.append(iam_serialize(row._asdict(), action, trade_date)) return deals @@ -116,8 +120,8 @@ def gen_iam_deals(conn, trade_date): iam_deals = [] with conn.cursor() as c: insert_query = ( - """INSERT INTO iam_tickets(trade_date, action, strategy, counterparty, maturity, start_money, currency, "offset") """ - """VALUES (%s, %s, %s, %s, %s, %s, %s, %s);""" + 'INSERT INTO iam_tickets(trade_date, action, strategy, counterparty, maturity, start_money, currency, "offset") ' + "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)" ) try: c.executemany(insert_query, new_iam) |
