diff options
Diffstat (limited to 'python/process_queue.py')
| -rw-r--r-- | python/process_queue.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/python/process_queue.py b/python/process_queue.py index 2194328d..bff34cb7 100644 --- a/python/process_queue.py +++ b/python/process_queue.py @@ -136,32 +136,33 @@ def bond_trade_process(conn, session, trade): currentface = trade['faceamount'] * bbg_data['MTG_FACTOR_SET_DT'] accrued_payment = bbg_data['INT_ACC'] * currentface /100. principal_payment = currentface * trade['price'] / 100. - with conn.cursor() as c: - c.execute("UPDATE bonds SET principal_payment = %s, accrued_payment = %s " - "WHERE id = %s", (principal_payment, accrued_payment, int(trade['id']))) - conn.commit() + with conn: + with conn.cursor() as c: + c.execute("UPDATE bonds SET principal_payment = %s, accrued_payment = %s " + "WHERE id = %s", (principal_payment, accrued_payment, int(trade['id']))) #mark it at buy price if trade.buysell: sqlstr = "INSERT INTO marks VALUES(%s, %s, %s)" try: - with conn.cursor() as c: - c.execute(sqlstr, (trade['trade_date'], trade['identifier'], trade['price'])) + with conn: + with conn.cursor() as c: + c.execute(sqlstr, (trade['trade_date'], trade['identifier'], trade['price'])) except psycopg2.IntegrityError: logging.error('We already have a mark') conn.rollback() - finally: - conn.commit() def cds_trade_process(serenitasdb, dawndb, session, trade): sqlstr = 'SELECT indexfactor FROM index_version WHERE redindexcode=%s' - with serenitasdb.cursor() as c: - c.execute(sqlstr, (trade.security_id,)) - try: - factor, = c.fetchone() - except ValueError: - bbg_data = get_bbg_data(dawndb, session, trade['security_id'], isin = trade['security_id'], - asset_class='Subprime') - factor = bbg_data['MTG_FACTOR_SET_DT'] + try: + with serenitasdb: + with serenitasdb.cursor() as c: + c.execute(sqlstr, (trade.security_id,)) + factor, = c.fetchone() + except ValueError: + bbg_data = get_bbg_data(dawndb, session, trade['security_id'], isin = trade['security_id'], + asset_class='Subprime') + + factor = bbg_data['MTG_FACTOR_SET_DT'] trade['curr_notional'] = trade['notional'] * factor return trade |
