-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
52 lines (34 loc) · 1.18 KB
/
server.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
from flask import Flask, jsonify
from flask_cors import CORS
from openfx_api.openfx_api import OpenFxApi
from api.web_options import get_options
import http
from scraping.bloomberg_com import bloomberg_com
from scraping.investing_com import get_pair
app = Flask(__name__)
CORS(app)
def get_response(data):
if data is None:
return jsonify(dict(message='error getting data')), http.HTTPStatus.NOT_FOUND
else:
return jsonify(data)
@app.route("/api/test")
def test():
return jsonify(dict(message='hello'))
@app.route("/api/headlines")
def headlines():
return get_response(bloomberg_com())
@app.route("/api/account")
def account():
return get_response(OpenFxApi().get_account_summary())
@app.route("/api/options")
def options():
return get_response(get_options())
@app.route("/api/technicals/<pair>/<tf>")
def technicals(pair, tf):
return get_response(get_pair(pair, tf))
@app.route("/api/prices/<pair>/<granularity>/<count>")
def prices(pair, granularity, count):
return get_response(OpenFxApi().web_api_candles(pair, granularity, count))
if __name__ == "__main__":
app.run(debug=True)