aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/process_queue.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/python/process_queue.py b/python/process_queue.py
index 03e9695b..1bc86c3e 100644
--- a/python/process_queue.py
+++ b/python/process_queue.py
@@ -835,14 +835,22 @@ def cds_trade_process(conn, session, trade):
value_date=trade["trade_date"],
)
index.direction = trade["protection"]
- index.ref = trade["ref"]
- trade["upfront"] = -index.pv
- with conn.cursor() as c:
- c.execute(
- "UPDATE cds SET upfront=%s WHERE dealid=%s",
- (trade["upfront"], trade["dealid"]),
- )
- conn.commit()
+ with conn.cursor() as c:
+ if trade["ref"]:
+ index.ref = trade["ref"]
+ trade["upfront"] = -index.pv
+ c.execute(
+ "UPDATE cds SET upfront=%s WHERE dealid=%s",
+ (trade["upfront"], trade["dealid"]),
+ )
+ else:
+ index.pv = trade["upfront"]
+ trade["ref"] = index.ref
+ c.execute(
+ "UPDATE cds SET ref=%s WHERE dealid=%s",
+ (trade["ref"], trade["dealid"]),
+ )
+ conn.commit()
return trade