-
Notifications
You must be signed in to change notification settings - Fork 21
/
strategy.py
37 lines (29 loc) · 1.1 KB
/
strategy.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
import logging
class Strategy(object):
"""Base class for strategies"""
def __init__(self):
"""Strategy constructor"""
def run(self) -> None:
"""Run the strategy"""
try:
while True:
self.before_loop()
self.loop()
self.after_loop()
except Exception as e:
logging.info("An error occurred when running strategy")
logging.info(e)
self.cleanup()
raise
def before_loop(self) -> None:
"""Method called before the loop"""
raise NotImplementedError("before_loop method must be override")
def loop(self) -> None:
"""Method in which is performed the strategy logic"""
raise NotImplementedError("loop method must be override")
def after_loop(self) -> None:
"""Method called after the loop"""
raise NotImplementedError("before_loop method must be override")
def cleanup(self) -> None:
"""Method called at the end of the strategy execution"""
raise NotImplementedError("cleanup method must be override")