-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpattern_detector.py
70 lines (60 loc) · 2.32 KB
/
pattern_detector.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
import os
import sys
import asyncio
from tqdm import tqdm
from argparse import ArgumentParser
from datetime import datetime
from patterndetector.detector.engulfing_candle_detector import EngulfingCandleDetector
from patterndetector.detector.outside_day_detector import OutsideDayDetector
from patterndetector.result import Results
from patterndetector.data import Data
from patterndetector.email import EmailGenerator
class PatternDetector:
def __init__(self):
super().__init__()
self.results = Results()
self.data = Data()
self.detectors = [OutsideDayDetector(self.data)] # EngulfingCandleDetector(self.data)
parser = ArgumentParser()
parser.add_argument('from_email', help='email address to send from')
parser.add_argument('to_email', nargs='*', help='email address to send to')
parser.add_argument('--patterns', nargs='*', help='patterns to analyze')
args = parser.parse_args()
self.to_email = args.to_email
self.from_email = args.from_email
if args.patterns:
self.patterns = args.patterns
else:
self.patterns = ['outsideday']
def getDataDetectAndPrint(self):
num_analyzed = num_failed = 0
print("Analyzing all tickers")
num_failed = 0
for ticker in tqdm(self.data.getTickers()):
try:
self.detectPatterns(ticker)
num_analyzed += 1
except:
num_failed += 1
print(f"{num_analyzed} tickers analyzed with {num_failed} failures")
self.sendEmail()
def detectPatterns(self, ticker):
for Detector in self.detectors:
data = Detector.detect(ticker)
if data:
self.results.addResult(Detector.name, ticker, data)
def sendEmail(self):
email = EmailGenerator(self.results)
email.sendEmail(self.from_email, self.to_email)
async def main(self):
start = datetime.now()
await self.data.pullData()
self.getDataDetectAndPrint()
print(f'Runtime (HH:MM:SS.SSSSSS): {datetime.now()-start}')
if __name__ == "__main__":
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
loop = asyncio.get_event_loop()
loop.run_until_complete(PatternDetector().main())
loop.close()