-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
54 lines (42 loc) · 1.6 KB
/
app.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
import yfinance as yf
import os, csv
import pandas as pd
import talib
from flask import Flask, render_template, request
from patterns import patterns
app = Flask(__name__)
@app.route('/')
def home_page():
current_pattern = request.args.get('pattern', None)
stocks = {}
with open('datasets/companies.csv') as f:
for row in csv.reader(f):
stocks[row[0]] = {'company': row[1]}
print(stocks)
if current_pattern:
datafiles = os.listdir('datasets/daily')
for filename in datafiles:
df = pd.read_csv('datasets/daily/{}'.format(filename))
pattern_func = getattr(talib, current_pattern)
symbol = filename.split('.')[0]
try:
result = pattern_func(df['Open'], df['High'], df['Low'], df['Close'])
last = result.tail(1).values[0]
if last > 0:
stocks[symbol][current_pattern] = 'bullish'
elif last < 0:
stocks[symbol][current_pattern] = 'bearish'
else:
stocks[symbol][current_pattern] = None
except:
pass
return render_template('index.html', patterns=patterns, stocks=stocks ,current_pattern=current_pattern)
@app.route('/snapshot')
def snapshot():
with open('datasets/companies.csv') as f:
companies = f.read().splitlines()
for company in companies:
symbol = company.split(',')[0]
df = yf.download(symbol, start="2021-01-02")
df.to_csv('datasets/daily/{}.csv'.format(symbol))
return('Code Executed')