-
Notifications
You must be signed in to change notification settings - Fork 1
/
stockList.py
78 lines (67 loc) · 2.2 KB
/
stockList.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
from pytickersymbols import PyTickerSymbols
from flask import Flask, Blueprint
stockList = Blueprint('stockList', __name__)
stock_data = PyTickerSymbols()
ftse = stock_data.get_stocks_by_index('FTSE 100')
sp500 = stock_data.get_stocks_by_index('S&P 500')
sp100 = stock_data.get_stocks_by_index('S&P 100')
nasdaq100 = stock_data.get_stocks_by_index('NASDAQ 100')
dow = stock_data.get_stocks_by_index('DOW JONES')
cac40 = stock_data.get_stocks_by_index('CAC 40')
allStocks = []
allStocks.extend(ftse)
allStocks.extend(sp500)
allStocks.extend(sp100)
allStocks.extend(nasdaq100)
allStocks.extend(dow)
allStocks.extend(cac40)
allStocksSet = set()
removeDuplicates = []
for stock in allStocks:
if stock['symbol'] not in allStocksSet:
allStocksSet.add(stock['symbol'])
removeDuplicates.append(stock)
allStocks = removeDuplicates
@stockList.route(f'api/stocklist', methods=["GET"])
def stockListByExchange():
filteredData = []
for stock in list(allStocks):
filteredStock = {
'companyName': stock['name'],
'symbol': stock['symbol']
}
filteredData.append(filteredStock)
return filteredData
@stockList.route(f'api/stocklist/ftse', methods=["GET"])
def ftseStockList():
ftse = stock_data.get_stocks_by_index('FTSE 100')
filteredData = []
for stock in list(ftse):
filteredStock = {
'companyName': stock['name'],
'symbol': stock['symbol']
}
filteredData.append(filteredStock)
return filteredData
@stockList.route(f'api/stocklist/nasdaq', methods=["GET"])
def nasdaqStockList():
nasdaq100 = stock_data.get_stocks_by_index('NASDAQ 100')
filteredData = []
for stock in list(nasdaq100):
filteredStock = {
'companyName': stock['name'],
'symbol': stock['symbol']
}
filteredData.append(filteredStock)
return filteredData
@stockList.route(f'api/stocklist/sp100', methods=["GET"])
def spStockList():
sp100 = stock_data.get_stocks_by_index('S&P 100')
filteredData = []
for stock in list(sp100):
filteredStock = {
'companyName': stock['name'],
'symbol': stock['symbol']
}
filteredData.append(filteredStock)
return filteredData