forked from jahinzee/theouchteam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_application.py
133 lines (108 loc) · 4.14 KB
/
web_application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from flask import Flask, render_template, request, url_for, redirect
from flask_bootstrap import Bootstrap
from forms import Enter_Order, Replace_Order, Cancel_Order, Submit_Order
import threading
import time
import json
from src.client import Client
app = Flask(__name__)
app.secret_key = "adkljrhLKJFHELJKFh"
bootstrap = Bootstrap(app)
order_number_index = 1
normalisedList = []
@app.route("/", methods = ["GET", "POST"])
def home():
form = Submit_Order()
if form.validate_on_submit():
send()
return render_template("completed.html")
return render_template('dashboard.html', form=form)
def send():
outbound = {
'actions': normalisedList
}
with open('test_inputs/client_100.json', 'w') as fp:
json.dump(outbound, fp)
Client(path='test_inputs/client_100.json')
def normalise_enter(form_info):
global normalisedList
normalised = {
'message_type': str(form_info['message_type']),
'order_token': int(form_info['order_token']),
'client_reference': str(form_info['client_reference']),
'buy_sell_indicator': str(form_info['indicator']),
'quantity': int(form_info['quantity']),
'orderbook_id': int(form_info['orderbook_id']),
'group': str(form_info['group']),
'price': float(form_info['price']),
'time_in_force': int(form_info['time_in_force']),
'firm_id': int(form_info['firm_id']),
'display': str(form_info['display']),
'capacity': str(form_info['capacity']),
'minimum_quantity': int(form_info['minimum_quantity']),
'order_classification': str(form_info['order_classification']),
'cash_margin_type': str(form_info['cash_margin_type'])
}
normalisedList.append(normalised)
def normalised_replace(form_info):
global normalisedList
normalised = {
'message_type': str(form_info['message_type']),
'existing_order_token': int(form_info['existing_order_token']),
'replacement_order_token': int(form_info['replacement_order_token']),
'quantity': int(form_info['quantity']),
'price': float(form_info['price']),
'time_in_force': int(form_info['time_in_force']),
'display': str(form_info['display']),
'minimum_quantity': int(form_info['minimum_quantity']),
}
normalisedList.append(normalised)
def normalised_cancel(form_info):
global normalisedList
normalised = {
'message_type': str(form_info['message_type']),
'order_token': int(form_info['order_token']),
'quantity': int(form_info['quantity']),
}
normalisedList.append(normalised)
@app.route('/enter_order', methods = ['GET', 'POST'])
def enter_order_page():
global order_number_index
form = Enter_Order()
if form.validate_on_submit():
order_number_index += 1
form_info = request.form
normalise_enter(form_info)
return redirect(url_for('enter_order_page'))
return render_template('enter.html', form = form, num = order_number_index)
@app.route('/replace_order', methods = ['GET', 'POST'])
def replace_order_page():
global order_number_index
form = Replace_Order()
if form.validate_on_submit():
order_number_index += 1
form_info = request.form
normalised_replace(form_info)
return redirect(url_for('replace_order_page'))
return render_template('replace.html', form = form, num = order_number_index)
@app.route('/cancel_order', methods = ['GET', 'POST'])
def cancel_order_page():
global order_number_index
form = Cancel_Order()
if form.validate_on_submit():
order_number_index +=1
form_info = request.form
normalised_cancel(form_info)
return redirect(url_for('cancel_order_page'))
return render_template('cancel.html', form = form, num = order_number_index)
@app.route('/dashboard', methods= ['GET', 'POST'])
def dashboard():
print("hello")
return render_template('dashboard.html')
if __name__ == '__main__':
# a = threading.Thread(target = app.run, daemon=True)
# b = threading.Thread(target = testing, daemon=True)
# a.start()
# b.start()
app.run(debug=True)
print("Press enter to exit.")