mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-08 11:16:58 +08:00
test.py is successfully relaying all datasource events.
This commit is contained in:
+14
-14
@@ -6,6 +6,7 @@ import json
|
||||
import pytz
|
||||
import copy
|
||||
import multiprocessing
|
||||
import logging
|
||||
from pymongo import ASCENDING, DESCENDING
|
||||
|
||||
from backtest.util import *
|
||||
@@ -13,13 +14,13 @@ from backtest.util import *
|
||||
|
||||
class EquityMinuteTrades(object):
|
||||
|
||||
def __init__(self, sid, db, data_address, sync_address, source_id, logger):
|
||||
def __init__(self, sid, db, data_address, sync_address, source_id):
|
||||
self.sid = sid
|
||||
self.db = db
|
||||
self.source_id = source_id
|
||||
self.logger = logger
|
||||
self.data_address = data_address
|
||||
self.logger = logging.getLogger()
|
||||
self.sync_address = sync_address
|
||||
self.data_address = data_address
|
||||
self.logger.info("data address is {ds}".format(ds=data_address))
|
||||
|
||||
self.cur_event = None
|
||||
@@ -29,9 +30,18 @@ class EquityMinuteTrades(object):
|
||||
self.proc.start()
|
||||
|
||||
def run(self):
|
||||
self.logger.info("starting data source:{sid}".format(sid=self.sid))
|
||||
self.logger.info("starting data source:{sid} on {addr}".format(sid=self.sid, addr=self.data_address))
|
||||
self.context = zmq.Context()
|
||||
|
||||
#synchronize with feed
|
||||
sync_socket = self.context.socket(zmq.REQ)
|
||||
sync_socket.connect(self.sync_address)
|
||||
# send a synchronization request to the feed
|
||||
sync_socket.send('')
|
||||
# wait for synchronization reply from the feed
|
||||
sync_socket.recv()
|
||||
sync_socket.close()
|
||||
|
||||
#create the data sink. Based on http://zguide.zeromq.org/py:tasksink2
|
||||
self.data_socket = self.context.socket(zmq.PUSH)
|
||||
self.data_socket.connect(self.data_address)
|
||||
@@ -42,16 +52,6 @@ class EquityMinuteTrades(object):
|
||||
slave_ok=True)
|
||||
self.logger.info("found {count} events".format(count=eventQS.count()))
|
||||
|
||||
#synchronize with feed
|
||||
syncclient = self.context.socket(zmq.REQ)
|
||||
syncclient.connect(self.sync_address)
|
||||
|
||||
# send a synchronization request
|
||||
syncclient.send('')
|
||||
# wait for synchronization reply
|
||||
syncclient.recv()
|
||||
|
||||
syncclient.close()
|
||||
|
||||
for doc in eventQS:
|
||||
doc_dt = doc['dt'].replace(tzinfo = pytz.utc)
|
||||
|
||||
Reference in New Issue
Block a user