MCPcopy Create free account
hub / github.com/shidenggui/easyquant / FixedDataEngine

Class FixedDataEngine

custom/fixeddataengine.py:17–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17class FixedDataEngine(PushBaseEngine):
18 EventType = 'custom'
19 PushInterval = 15
20
21 def __init__(self, event_engine, clock_engine, watch_stocks=None, s='sina'):
22
23 self.watch_stocks = watch_stocks
24 self.s = s
25 self.source = None
26 self.__queue = mp.Queue(1000)
27 self.is_pause = not clock_engine.is_tradetime_now()
28 self._control_thread = Thread(target=self._process_control, name="FixedDataEngine._control_thread")
29 self._control_thread.start()
30 super(FixedDataEngine, self).__init__(event_engine, clock_engine)
31
32 def _process_control(self):
33
34 while True:
35 try:
36 msg = self.__queue.get(block=True)
37 if msg == "pause":
38 self.is_pause = True
39 else:
40 self.is_pause = False
41 except:
42 pass
43
44 def pause(self):
45 self.__queue.put("pause")
46
47 def work(self):
48 self.__queue.put("work")
49
50 def init(self):
51 # 进行相关的初始化操作
52 self.source = easyquotation.use(self.s)
53
54 def fetch_quotation(self):
55 # 返回行情
56 return self.source.stocks(self.watch_stocks)
57
58 def push_quotation(self):
59 while self.is_active:
60 if self.is_pause:
61 time.sleep(1)
62 continue
63 try:
64 response_data = self.fetch_quotation()
65 except aiohttp.errors.ServerDisconnectedError:
66 time.sleep(self.PushInterval)
67 continue
68 event = Event(event_type=self.EventType, data=response_data)
69 self.event_engine.put(event)
70 time.sleep(self.PushInterval)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected