-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.py
106 lines (93 loc) · 3.76 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
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
import talib
from flask import Flask, request, render_template
from zvt.api.data_type import Region, Provider
from zvt.contract.reader import DataReader
from zvt.domain import Stock1dKdata, Stock
candlestick_patterns = {
'CDL2CROWS': 'Two Crows',
'CDL3BLACKCROWS': 'Three Black Crows',
'CDL3INSIDE': 'Three Inside Up/Down',
'CDL3LINESTRIKE': 'Three-Line Strike',
'CDL3OUTSIDE': 'Three Outside Up/Down',
'CDL3STARSINSOUTH': 'Three Stars In The South',
'CDL3WHITESOLDIERS': 'Three Advancing White Soldiers',
'CDLABANDONEDBABY': 'Abandoned Baby',
'CDLADVANCEBLOCK': 'Advance Block',
'CDLBELTHOLD': 'Belt-hold',
'CDLBREAKAWAY': 'Breakaway',
'CDLCLOSINGMARUBOZU': 'Closing Marubozu',
'CDLCONCEALBABYSWALL': 'Concealing Baby Swallow',
'CDLCOUNTERATTACK': 'Counterattack',
'CDLDARKCLOUDCOVER': 'Dark Cloud Cover',
'CDLDOJI': 'Doji',
'CDLDOJISTAR': 'Doji Star',
'CDLDRAGONFLYDOJI': 'Dragonfly Doji',
'CDLENGULFING': 'Engulfing Pattern',
'CDLEVENINGDOJISTAR': 'Evening Doji Star',
'CDLEVENINGSTAR': 'Evening Star',
'CDLGAPSIDESIDEWHITE': 'Up/Down-gap side-by-side white lines',
'CDLGRAVESTONEDOJI': 'Gravestone Doji',
'CDLHAMMER': 'Hammer',
'CDLHANGINGMAN': 'Hanging Man',
'CDLHARAMI': 'Harami Pattern',
'CDLHARAMICROSS': 'Harami Cross Pattern',
'CDLHIGHWAVE': 'High-Wave Candle',
'CDLHIKKAKE': 'Hikkake Pattern',
'CDLHIKKAKEMOD': 'Modified Hikkake Pattern',
'CDLHOMINGPIGEON': 'Homing Pigeon',
'CDLIDENTICAL3CROWS': 'Identical Three Crows',
'CDLINNECK': 'In-Neck Pattern',
'CDLINVERTEDHAMMER': 'Inverted Hammer',
'CDLKICKING': 'Kicking',
'CDLKICKINGBYLENGTH': 'Kicking - bull/bear determined by the longer marubozu',
'CDLLADDERBOTTOM': 'Ladder Bottom',
'CDLLONGLEGGEDDOJI': 'Long Legged Doji',
'CDLLONGLINE': 'Long Line Candle',
'CDLMARUBOZU': 'Marubozu',
'CDLMATCHINGLOW': 'Matching Low',
'CDLMATHOLD': 'Mat Hold',
'CDLMORNINGDOJISTAR': 'Morning Doji Star',
'CDLMORNINGSTAR': 'Morning Star',
'CDLONNECK': 'On-Neck Pattern',
'CDLPIERCING': 'Piercing Pattern',
'CDLRICKSHAWMAN': 'Rickshaw Man',
'CDLRISEFALL3METHODS': 'Rising/Falling Three Methods',
'CDLSEPARATINGLINES': 'Separating Lines',
'CDLSHOOTINGSTAR': 'Shooting Star',
'CDLSHORTLINE': 'Short Line Candle',
'CDLSPINNINGTOP': 'Spinning Top',
'CDLSTALLEDPATTERN': 'Stalled Pattern',
'CDLSTICKSANDWICH': 'Stick Sandwich',
'CDLTAKURI': 'Takuri (Dragonfly Doji with very long lower shadow)',
'CDLTASUKIGAP': 'Tasuki Gap',
'CDLTHRUSTING': 'Thrusting Pattern',
'CDLTRISTAR': 'Tristar Pattern',
'CDLUNIQUE3RIVER': 'Unique 3 River',
'CDLUPSIDEGAP2CROWS': 'Upside Gap Two Crows',
'CDLXSIDEGAP3METHODS': 'Upside/Downside Gap Three Methods'
}
reader = DataReader(region=Region.US,
start_timestamp='2020-01-01',
data_schema=Stock1dKdata,
entity_schema=Stock,
provider=Provider.Yahoo)
gb = reader.data_df.groupby('code')
app = Flask(__name__)
@app.route('/')
def index():
pattern = request.args.get('pattern', False)
stocks = {}
if pattern:
pattern_function = getattr(talib, pattern)
for symbol in gb.groups:
stocks[symbol] = {'company': symbol}
df = gb.get_group(symbol)
results = pattern_function(df.open, df.high, df.low, df.close)
last = results.tail(1).values[0]
if last > 0:
stocks[symbol][pattern] = 'bullish'
elif last < 0:
stocks[symbol][pattern] = 'bearish'
else:
stocks[symbol][pattern] = None
return render_template('index.html', candlestick_patterns=candlestick_patterns, stocks=stocks, pattern=pattern)