aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/Dawn/views.py4
-rw-r--r--python/process_queue.py24
2 files changed, 13 insertions, 15 deletions
diff --git a/python/Dawn/views.py b/python/Dawn/views.py
index 7be9ff1f..14591589 100644
--- a/python/Dawn/views.py
+++ b/python/Dawn/views.py
@@ -370,14 +370,14 @@ def trade_manage(tradeid, kind):
trade.cashaccount = trade.fcm_account.cash_account
session.commit()
if form.upload_globeop.data and form.fund.data == "SERCGMAST":
- if kind == "bond":
+ if kind in ["bond", "cds"]:
buf = simple_serialize(trade, upload=True)
else:
buf = simple_serialize(trade)
q = get_queue()
q.rpush(f"{kind}_trades", buf)
else:
- if kind == "bond":
+ if kind in ["bond", "cds"]:
q = get_queue()
q.rpush(f"{kind}_trades", simple_serialize(trade))
return redirect(url_for('list_trades', kind=kind))
diff --git a/python/process_queue.py b/python/process_queue.py
index 6c509cd4..384da785 100644
--- a/python/process_queue.py
+++ b/python/process_queue.py
@@ -390,14 +390,15 @@ def send_email(trade):
def is_tranche_trade(trade):
return trade['swap_type'] in ('CD_INDEX_TRANCHE', 'BESPOKE')
-def cds_trade_process(serenitasdb, dawndb, session, trade):
- sqlstr = 'SELECT indexfactor/100 FROM index_version WHERE redindexcode=%(security_id)s'
+def cds_trade_process(conn, session, trade):
+ sqlstr = ("SELECT indexfactor/100 FROM index_version "
+ "WHERE redindexcode=%(security_id)s")
try:
- with serenitasdb.cursor() as c:
+ with conn.cursor() as c:
c.execute(sqlstr, trade)
factor, = c.fetchone()
except ValueError:
- bbg_data = get_bbg_data(dawndb, session, trade['security_id'],
+ bbg_data = get_bbg_data(conn, session, trade['security_id'],
isin=trade['security_id'],
asset_class='Subprime')
@@ -469,28 +470,25 @@ if __name__ == "__main__":
except KeyError:
sys.exit("Please set path of daily directory in 'DAILY_DIR'")
- serenitasdb = dbconn('serenitasdb')
dawndb = dbconn('dawndb')
for queue_name in ['bond_trades', 'cds_trades', 'swaption_trades',
'future_trades', 'wires', 'spot_trades']:
list_trades = get_trades(q, queue_name)
if list_trades:
- if queue_name == 'bond_trades':
+ if queue_name in ['bond_trades', 'cds_trades']:
+ process_fun = globals()[queue_name[:-1] + "_process"]
with init_bbg_session(BBG_IP) as session:
for trade in list_trades:
- bond_trade_process(dawndb, session, trade)
+ process_fun(dawndb, session, trade)
list_trades = [t for t in list_trades if t.get("upload", False)]
- for trade in list_trades:
- send_email(trade)
- elif queue_name == 'cds_trades':
- with init_bbg_session(BBG_IP) as session:
+ if queue_name == ['bond_trades']:
for trade in list_trades:
- cds_trade_process(serenitasdb, dawndb, session, trade)
+ send_email(trade)
+
if list_trades:
buf = generate_csv(list_trades, queue_name)
file_path = write_buffer(buf, DAILY_DIR, queue_name)
if not args.no_upload:
upload_file(file_path, queue_name)
q.delete(queue_name)
- serenitasdb.close()
dawndb.close()