aboutsummaryrefslogtreecommitdiffstats
path: root/python/Dawn
diff options
context:
space:
mode:
Diffstat (limited to 'python/Dawn')
-rw-r--r--python/Dawn/views.py98
1 files changed, 56 insertions, 42 deletions
diff --git a/python/Dawn/views.py b/python/Dawn/views.py
index 91ec2cc2..bbe9e01e 100644
--- a/python/Dawn/views.py
+++ b/python/Dawn/views.py
@@ -1,6 +1,6 @@
from flask import (request, render_template, redirect,
url_for, send_from_directory, send_file, g, jsonify)
-from .models import ModelForm, BondDeal, CDSDeal, Counterparties
+from .models import ModelForm, BondDeal, CDSDeal, SwaptionDeal, Counterparties
from sqlalchemy.exc import IntegrityError
from wtforms.fields import BooleanField
import pandas as pd
@@ -68,34 +68,56 @@ class CDSForm(ModelForm):
include_foreign_keys = True
exclude = ['dealid', 'lastupdate']
-def cds_trade(tradeid):
- return CDSDeal.query.get(tradeid) if tradeid else CDSDeal()
+class SwaptionForm(ModelForm):
+ upload_globeop = BooleanField(label="Upload to globeop?")
+ class Meta:
+ model = SwaptionDeal
+ include_foreign_keys = True
+ exclude = ['dealid', 'lastupdate']
-def bond_trade(tradeid):
- return BondDeal.query.get(tradeid) if tradeid else BondDeal()
-def bond_form(trade):
- if trade.id:
- bond_form = BondForm(obj = trade)
+def get_deal(kind):
+ if kind == 'cds':
+ return CDSDeal
+ elif kind == 'bond':
+ return BondDeal
+ elif kind == 'swaption':
+ return SwaptionDeal
else:
- bond_form = BondForm(trade_date = pd.datetime.today().date(),
- settle_date = pd.datetime.today().date() + 3 * bus_day)
- #add extra empty fields
- bond_form.folder.choices = [(None, '')] + bond_form.folder.choices
- bond_form.buysell.choices = [(None, '')] + bond_form.buysell.choices
- bond_form.asset_class.choices = [(None, '')] + bond_form.asset_class.choices
- return bond_form
+ raise RuntimeError('Unknown Deal type')
-def cds_form(trade):
+def get_form(trade, kind):
+ if kind == 'cds':
+ Form = CDSForm
+ elif kind == 'bond':
+ Form = BondForm
+ elif kind == 'swaption':
+ Form = SwaptionForm
+ else:
+ raise RuntimeError('Unknown Deal type')
if trade.id:
- cds_form = CDSForm(obj = trade)
+ form = Form(obj = trade)
else:
today = pd.datetime.today()
- tomorrow = today + pd.DateOffset(1)
- cds_form = CDSForm(trade_date = today.date(),
- effective_date= tomorrow.date(),
- upfront_settle_date = today.date() + 3 * bus_day)
- return cds_form
+ if kind == 'cds':
+ tomorrow = today + pd.DateOffset(1)
+ form = Form(trade_date = today.date(),
+ effective_date = tomorrow.date(),
+ upfront_settle_date = today.date() + 3 * bus_day)
+ else:
+ form = Form(trade_date = today.date(),
+ settle_date = today.date() + 3 * bus_day)
+ #add extra empty fields
+ for attr in ['folder', 'buysell', 'asset_class', 'swaption_type']:
+ try:
+ getattr(form, attr).choices.insert(0, (None, ''))
+ except AttributeError:
+ continue
+ return form
+
+def get_trade(tradeid, kind):
+ Deal = get_deal(kind)
+ return Deal.query.get(tradeid) if tradeid else Deal()
def save_ticket(trade, old_ticket_name):
if trade.ticket.filename:
@@ -110,14 +132,13 @@ def save_ticket(trade, old_ticket_name):
else:
trade.ticket = old_ticket_name
-@app.route('/trades/<int:tradeid>', defaults={'kind': 'bond'}, methods=['GET', 'POST'])
+@app.route('/trades/<kind>/<int:tradeid>', methods=['GET', 'POST'])
+@app.route('/trades/<kind>/', defaults={'tradeid': None}, methods=['GET', 'POST'])
@app.route('/trades/', defaults={'tradeid': None, 'kind': 'bond'}, methods=['GET', 'POST'])
-@app.route('/cdstrades/<int:tradeid>', defaults={'kind': 'cds'}, methods=['GET', 'POST'])
-@app.route('/cdstrades/', defaults={'tradeid': None, 'kind': 'cds'}, methods=['GET', 'POST'])
def trade_manage(tradeid, kind):
- trade = globals()['{0}_trade'.format(kind)](tradeid)
- form = globals()['{0}_form'.format(kind)](trade)
- if kind=='bond':
+ trade = get_trade(tradeid, kind)
+ form = get_form(trade, kind)
+ if kind == 'bond':
old_ticket_name = trade.ticket
form.cp_code.choices = form.cp_code.choices + list(cp_choices())
if form.validate_on_submit():
@@ -143,21 +164,14 @@ def trade_manage(tradeid, kind):
return render_template('trade_entry.html', form=form,
action_url = url_for('trade_manage', tradeid = tradeid, kind = kind))
-@app.route('/')
-@app.route('/blotter/')
-def list_bond_trades():
- trade_list = BondDeal.query.order_by(BondDeal.trade_date.desc(), BondDeal.id.desc())
- return render_template('blotter.html', trades=trade_list.all())
-
-@app.route('/cdsblotter')
-def list_cds_trades():
- trade_list = CDSDeal.query.order_by(CDSDeal.trade_date.desc(), CDSDeal.id.desc())
- return render_template('cds_blotter.html', trades=trade_list.all())
+@app.route('/', defaults={'kind': 'bond'})
+@app.route('/blotter/<kind>')
+@app.route('/blotter/', defaults={'kind': 'bond'})
+def list_trades(kind):
+ Deal = get_deal(kind)
+ trade_list = Deal.query.order_by(Deal.trade_date.desc(), Deal.id.desc())
+ return render_template('{}_blotter.html'.format(kind), trades=trade_list.all())
-@app.route('/repoblotter')
-def list_repo_trades():
- trade_list = RepoDeal.query.order_by(RepoDeal.trade_date.desc(), RepoDeal.id.desc())
- return render_template('repo_blotter.html', trades=trade_list.all())
@app.route('/tickets/<int:tradeid>')
def download_ticket(tradeid):