行情推送引擎基类
| 6 | |
| 7 | |
| 8 | class BaseEngine: |
| 9 | """行情推送引擎基类""" |
| 10 | EventType = 'base' |
| 11 | PushInterval = 1 |
| 12 | |
| 13 | def __init__(self, event_engine, clock_engine): |
| 14 | self.event_engine = event_engine |
| 15 | self.clock_engine = clock_engine |
| 16 | self.is_active = True |
| 17 | self.quotation_thread = Thread(target=self.push_quotation, name="QuotationEngine.%s" % self.EventType) |
| 18 | self.quotation_thread.setDaemon(False) |
| 19 | self.init() |
| 20 | |
| 21 | def start(self): |
| 22 | self.quotation_thread.start() |
| 23 | |
| 24 | def stop(self): |
| 25 | self.is_active = False |
| 26 | |
| 27 | def push_quotation(self): |
| 28 | while self.is_active: |
| 29 | try: |
| 30 | response_data = self.fetch_quotation() |
| 31 | except: |
| 32 | self.wait() |
| 33 | continue |
| 34 | event = Event(event_type=self.EventType, data=response_data) |
| 35 | self.event_engine.put(event) |
| 36 | self.wait() |
| 37 | |
| 38 | def fetch_quotation(self): |
| 39 | # return your quotation |
| 40 | return None |
| 41 | |
| 42 | def init(self): |
| 43 | # do something init |
| 44 | pass |
| 45 | |
| 46 | def wait(self): |
| 47 | # for receive quit signal |
| 48 | for _ in range(int(self.PushInterval) + 1): |
| 49 | time.sleep(1) |
nothing calls this directly
no outgoing calls
no test coverage detected