aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/Dawn/views.py54
1 files changed, 39 insertions, 15 deletions
diff --git a/python/Dawn/views.py b/python/Dawn/views.py
index 120cf292..fc76fe4f 100644
--- a/python/Dawn/views.py
+++ b/python/Dawn/views.py
@@ -16,7 +16,8 @@ from sqlalchemy.exc import IntegrityError
from wtforms.fields import BooleanField
from pandas.tseries.offsets import CustomBusinessDay
-from pandas.tseries.holiday import get_calendar, HolidayCalendarFactory, GoodFriday
+from pandas.tseries.holiday import (get_calendar, HolidayCalendarFactory,
+ GoodFriday)
from .utils import bump_rev, simple_serialize
from PyPDF2 import PdfFileMerger
@@ -28,6 +29,7 @@ fed_cal = get_calendar('USFederalHolidayCalendar')
bond_cal = HolidayCalendarFactory('BondCalendar', fed_cal, GoodFriday)
bus_day = CustomBusinessDay(calendar=bond_cal())
+
def cp_choices(kind='bond'):
if kind == 'bond':
return (Counterparties.query.order_by('name').
@@ -40,9 +42,11 @@ def cp_choices(kind='bond'):
filter(Counterparties.name.ilike('%CDS%')).
with_entities(Counterparties.code, Counterparties.name))
+
def account_codes():
return Accounts.query.order_by('code').with_entities(Accounts.code, Accounts.name)
+
def get_queue():
q = getattr(g, 'queue', None)
if q is None:
@@ -53,6 +57,7 @@ def get_queue():
q = g.queue = redis.Redis(host='ziggy')
return q
+
def get_db():
db = getattr(g, '_database', None)
if db is None:
@@ -61,46 +66,58 @@ def get_db():
host="debian")
return db
+
@app.teardown_appcontext
def close_connection(exception):
db = getattr(g, '_database', None)
if db is not None:
db.close()
+
class CounterpartyForm(ModelForm):
class Meta:
model = Counterparties
include_primary_keys = True
+
class BondForm(ModelForm):
upload_globeop = BooleanField(label="Upload to globeop?")
+
class Meta:
model = BondDeal
include_foreign_keys = True
- exclude = ['dealid', 'lastupdate', #we generate it with a trigger at the server level
+ exclude = ['dealid', 'lastupdate', # we generate it with a trigger at the server level
'principal_payment', 'accrued_payment']
+
class CDSForm(ModelForm):
upload_globeop = BooleanField(label="Upload to globeop?")
+
class Meta:
model = CDSDeal
include_foreign_keys = True
- exclude = ['dealid', 'lastupdate']
+ exclude = ['dealid', 'lastupdate', 'termination_amount',
+ 'termination_cp']
class SwaptionForm(ModelForm):
upload_globeop = BooleanField(label="Upload to globeop?")
+
class Meta:
model = SwaptionDeal
include_foreign_keys = True
- exclude = ['dealid', 'lastupdate']
+ exclude = ['dealid', 'lastupdate', 'termination_amount',
+ 'termination_cp']
+
class FutureForm(ModelForm):
upload_globeop = BooleanField(label="Upload to globeop?")
+
class Meta:
model = FutureDeal
include_foreign_keys = True
exclude = ['dealid', 'lastupdate']
+
def get_deal(kind):
if kind == 'cds':
return CDSDeal
@@ -113,6 +130,7 @@ def get_deal(kind):
else:
raise RuntimeError(f'Unknown Deal type: {kind}')
+
def _get_form(kind):
if kind == 'cds':
return CDSForm
@@ -125,6 +143,7 @@ def _get_form(kind):
else:
raise RuntimeError('Unknown Deal type')
+
def get_form(trade, kind):
Form = _get_form(kind)
if trade.id:
@@ -150,18 +169,12 @@ def get_form(trade, kind):
continue
return form
-def get_wire_form(wire):
- if wire.id:
- return WireForm(obj=trade)
- else:
- today = pd.datetime.today()
- form = WireForm(trade_date=today.date())
- 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:
if old_ticket_name:
@@ -175,6 +188,7 @@ def save_ticket(trade, old_ticket_name):
else:
trade.ticket = old_ticket_name
+
def split_direction(g, direction):
if direction == "outgoing":
return [{"folder": cf.folder, "amount": -cf.amount, "code": cf.code,
@@ -187,6 +201,7 @@ def split_direction(g, direction):
else:
raise ValueError("direction can be one of 'outgoing' or 'incoming'")
+
def gen_cashflow_deals(form, session, wire_id=None):
to_date = lambda s: datetime.datetime.strptime(s, "%Y-%m-%d")
d = {'action': form.get("action"),
@@ -214,7 +229,9 @@ def gen_cashflow_deals(form, session, wire_id=None):
yield cf
else:
cf = CashFlowDeal(**d)
- session.add(cf); yield cf
+ session.add(cf)
+ yield cf
+
@app.route('/wires/<int:wire_id>', methods = ['GET', 'POST'])
@app.route('/wires/', defaults={'wire_id': None}, methods=['GET', 'POST'])
@@ -255,8 +272,10 @@ def wire_manage(wire_id):
@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('/trades/<kind>/', defaults={'tradeid': None},
+ methods=['GET', 'POST'])
+@app.route('/trades/', defaults={'tradeid': None, 'kind': 'bond'},
+ methods=['GET', 'POST'])
def trade_manage(tradeid, kind):
trade = get_trade(tradeid, kind)
form = _get_form(kind)()
@@ -290,6 +309,7 @@ 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('/', defaults={'kind': 'bond'})
@app.route('/<kind>')
def list_trades(kind):
@@ -300,6 +320,7 @@ def list_trades(kind):
trade_list = Deal.query.order_by(Deal.trade_date.desc(), Deal.id.desc())
return render_template(f'{kind}_blotter.html', trades=trade_list.all())
+
@app.route('/tickets/<int:tradeid>')
def download_ticket(tradeid):
trade = BondDeal.query.get(tradeid)
@@ -312,7 +333,8 @@ def download_ticket(tradeid):
fh.seek(0)
return send_file(fh, mimetype='application/pdf')
-@app.route('/counterparties/<path:instr>', methods = ['GET'])
+
+@app.route('/counterparties/<path:instr>', methods=['GET'])
@app.route('/counterparties/', defaults={'instr': None}, methods=['GET'])
def list_counterparties(instr):
if instr:
@@ -323,6 +345,7 @@ def list_counterparties(instr):
cp_list = Counterparties.query.order_by(Counterparties.name)
return render_template('counterparties.html', counterparties=cp_list.all())
+
@app.route('/edit_cp/<cpcode>', methods=['GET', 'POST'])
@app.route('/edit_cp/', defaults={'cpcode': None}, methods=['GET', 'POST'])
def edit_counterparty(cpcode):
@@ -350,6 +373,7 @@ def edit_counterparty(cpcode):
else:
return render_template('edit_cp.html', form=CounterpartyForm(obj=cp), code=cpcode)
+
@app.route('/_ajax', methods=['GET'])
def get_bbg_id():
bbg_id = request.args.get('bbg_id')