forked from shidenggui/easytrader
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhttpserver.py
More file actions
Latest commit
40 lines (29 loc) · 870 Bytes
/
Copy pathhttpserver.py
File metadata and controls
40 lines (29 loc) · 870 Bytes
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
from __future__ importprint_function
importjson
fromflaskimportFlask, request, jsonify
importeasytrader
app=Flask(__name__)
user=None
@app.route('/login')
deflogin():
globaluser
args=request.args
user=easytrader.use(args['use'])
user.prepare(args['prepare'])
returnjsonify({'message': 'login ok'})
@app.route('/call')
defdo():
globaluser
target=request.args.get('func')
params_str=request.args.get('params', None)
ifparams_str:
params=params_str.split(',')
iftargetin ['buy', 'sell']:
params[-1] =int(params[-1])
params[-2] =float(params[-2])
result=getattr(user, target)(*params)
else:
result=getattr(user, target)
returnjson.dumps({'return': result}, ensure_ascii=False)
if__name__=='__main__':
app.run(debug=True)