From 77b7fbb0021947abe355ea7dbf4686d95d8913bd Mon Sep 17 00:00:00 2001 From: yutiansut Date: Fri, 30 Aug 2019 03:00:12 +0800 Subject: [PATCH] #update for realtime_stock --- QARealtimeCollector/__init__.py | 4 ++++ QARealtimeCollector/collectors/stockcollector.py | 2 +- QARealtimeCollector/webserver.py | 7 ++++++- setup.py | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/QARealtimeCollector/__init__.py b/QARealtimeCollector/__init__.py index 84546e1..b9f8eda 100644 --- a/QARealtimeCollector/__init__.py +++ b/QARealtimeCollector/__init__.py @@ -42,3 +42,7 @@ def resample(code, freq, model): def random(code, date, price, interval): r = QARTC_RandomTick(code, date, price, interval) r.start() + + +def stock_collector(): + QARTC_Stock().start() \ No newline at end of file diff --git a/QARealtimeCollector/collectors/stockcollector.py b/QARealtimeCollector/collectors/stockcollector.py index 811ff9d..1264bac 100644 --- a/QARealtimeCollector/collectors/stockcollector.py +++ b/QARealtimeCollector/collectors/stockcollector.py @@ -69,7 +69,7 @@ def run(self): if __name__ == "__main__": - r = QARTC_Stock('yutiansut', '940809') + r = QARTC_Stock() r.subscribe('000001') r.subscribe('000002') r.start() diff --git a/QARealtimeCollector/webserver.py b/QARealtimeCollector/webserver.py index c8382c0..c4a9d62 100644 --- a/QARealtimeCollector/webserver.py +++ b/QARealtimeCollector/webserver.py @@ -9,6 +9,7 @@ from tornado.web import Application, RequestHandler, authenticated import QUANTAXIS as QA +from QAPUBSUB.producer import publisher, publisher_routing from QARealtimeCollector.collectors import (QARTC_CtpBeeCollector, QARTC_CTPTickCollector, QARTC_RandomTick, QARTC_Stock, @@ -47,7 +48,11 @@ def post(self): self.handler[market_type][code].start() self.write({'result': 'success'}) else: - pass + publisher_routing(exchange='QARealtime_Market', routing_key='stock').pub(json.dumps({ + 'topic': 'subscribe', + 'code': code + }), routing_key='stock') + self.handler[market_type][code] = True else: self.write({'result': 'already exist'}) diff --git a/setup.py b/setup.py index 94a88ec..de1b927 100644 --- a/setup.py +++ b/setup.py @@ -70,6 +70,7 @@ def read(fname): 'QARC_Resample = QARealtimeCollector.__init__:resample', 'QARC_Random = QARealtimeCollector.__init__:random', 'QARC_CTP = QARealtimeCollector.__init__:start_ctp', + 'QARC_Stock = QARealtimeCollector.__init__:stock_collector', 'QARC_WEBSERVER = QARealtimeCollector.webserver:main' ] },