def debug_sub(exchange, model, routing_key, user, password, host, durable): if model == 'fanout': subscriber(host=host, user=user, password=password, exchange=exchange).start() elif model == 'direct': subscriber_routing(host=host, user=user, password=password, exchange=exchange, routing_key=routing_key, durable=durable).start() elif model == 'topic': subscriber_topic(host=host, user=user, password=password, exchange=exchange, routing_key=routing_key, durable=durable).start()
def __init__(self, code=['000001'], frequence='1min', strategy_id='QA_STRATEGY', risk_check_gap=1, portfolio='default', start='2019-01-01', end='2019-10-21', send_wx=False, market_type='stock_cn', data_host=eventmq_ip, data_port=eventmq_port, data_user=eventmq_username, data_password=eventmq_password, trade_host=eventmq_ip, trade_port=eventmq_port, trade_user=eventmq_username, trade_password=eventmq_password, taskid=None, mongo_ip=mongo_ip): super().__init__(code=code, frequence=frequence, strategy_id=strategy_id, risk_check_gap=risk_check_gap, portfolio=portfolio, start=start, end=end, send_wx=send_wx, data_host=eventmq_ip, data_port=eventmq_port, data_user=eventmq_username, data_password=eventmq_password, trade_host=eventmq_ip, trade_port=eventmq_port, trade_user=eventmq_username, trade_password=eventmq_password, taskid=taskid, mongo_ip=mongo_ip) self.code = code self.send_wx = send_wx self.dtcode = {} stock_pool_pd = pd.read_csv( "/root/qa_strategy/stock_strategy/stock_pool.csv", encoding='utf-8', converters={'code': str}) self.stock_pool_list = stock_pool_pd['code'].tolist() ''' ''' print('订阅远程行情开始:') self.subscriber = subscriber_topic(host='www.yutiansut.com', port='5678', exchange='QARealtimePro_FIX', durable=False, vhost='/', routing_key='*') #pymongo.MongoClient(mongo_ip).qa.drop_collection('REALTIMEPRO_FIX') self.db = pymongo.MongoClient(mongo_ip).qa.REALTIMEPRO_FIX
def subscribe_multi(self, codelist, frequence, data_host, data_port, data_user, data_password): self.sub = subscriber_topic(exchange='realtime_{}'.format( frequence), host=data_host, port=data_port, user=data_user, password=data_password) for item in codelist: self.sub.add_sub(exchange='realtime_{}'.format( frequence), routing_key=item) self.sub.callback = self.callback
def __init__(self, host, port): super().__init__() self.subscriber = subscriber_topic(host=host, port=port, exchange='QARealtimePro_FIX', durable=False, vhost='/', routing_key='*') self.initdb()
def subscribe_data(self, code, frequence, data_host, data_port, data_user, data_password): """[summary] Arguments: code {[type]} -- [description] frequence {[type]} -- [description] """ self.sub = subscriber_topic(exchange='realtime_stock_{}'.format( frequence), host=data_host, port=data_port, user=data_user, password=data_password, routing_key='') for item in code: self.sub.add_sub(exchange='realtime_stock_{}'.format( frequence), routing_key=item) self.sub.callback = self.callback
def __init__(self, username, password, model="SIM", broker_name="QAPaperTrading", trade_host=mongo_ip, init_cash=1000000, eventmq_ip=eventmq_ip, eventmq_port=eventmq_port): super().__init__(username, password, model, broker_name, trade_host, init_cash) self.pub = producer.publisher_routing( exchange='qamdgateway', host=eventmq_ip, port=eventmq_port, durable=True) self.subrealtime = subscriber_topic( host=eventmq_ip, port=eventmq_port, exchange='QASMG', routing_key=username) self.ordersub = subscriber_routing( host=eventmq_ip, port=eventmq_port, exchange='QAORDER_ROUTER', routing_key=username) self.subrealtime.callback = self.realtime_data_callback self.ordersub.callback = self.listen_order_callback threading.Thread(target=self.subrealtime.start).start() threading.Thread(target=self.ordersub.start).start() self.pub_acc = producer.publisher_topic( exchange='qaStandardAcc', host=eventmq_ip, port=eventmq_port, durable=True)
def __init__(self, host, port): super().__init__() self.subscriber = subscriber_topic(host=host, port=port, exchange='QARealtimePro_FIX', durable=False, vhost='/', routing_key='*') #pymongo.MongoClient(mongo_ip).qa.drop_collection('REALTIMEPRO_FIX') self.db = pymongo.MongoClient(mongo_ip).qa.REALTIMEPRO_FIX ''' import pandas as pd stock_pool_pd = pd.read_csv("/root/qa_strategy/stock_strategy/stock_pool.csv", encoding='utf-8', converters={'code': str}); self.stock_pool_list = stock_pool_pd['code'].tolist() ''' self.db.create_index([ ('code', pymongo.ASCENDING), ('datetime', pymongo.ASCENDING), ('frequence', pymongo.ASCENDING), ])
#!/usr/bin/env python import QAPUBSUB import threading from QAPUBSUB.consumer import subscriber_topic from QAPUBSUB.producer import publisher_topic z1 = subscriber_topic(exchange='testTopic', routing_key='000001.#') z2 = subscriber_topic(exchange='testTopic', routing_key='#.000300.#') z2.add_sub(exchange='testTopic', routing_key='#.000050.#') z3 = subscriber_topic(exchange='testTopic', routing_key='#.SZ.#') z1.callback = lambda a, b, c, x: print('FROM 个股订阅 000001 {}'.format(x)) z2.callback = lambda a, b, c, x: print('FROM 板块订阅/ 沪深300/ 上证50 {}'.format(x)) z3.callback = lambda a, b, c, x: print('FROM 市场订阅/深圳市场 {}'.format(x)) p = publisher_topic(exchange='testTopic', ) threading.Thread(target=z1.start).start() threading.Thread(target=z2.start).start() threading.Thread(target=z3.start).start() p.pub('000001', routing_key='000001.SZ.000300.000050') p.pub('000002', routing_key='000002.SZ.000300.000050') p.pub('601318', routing_key='601318.SH.000300.000050')
#!/usr/bin/env python import QAPUBSUB import threading from QAPUBSUB.consumer import subscriber_topic from QAPUBSUB.producer import publisher_topic z1 = subscriber_topic(exchange='testTopic', routing_key='#') z2 = subscriber_topic(exchange='testTopic', routing_key='#.SZ') z3 = subscriber_topic(exchange='testTopic', routing_key='#.SH') z1.callback = lambda a, b, c, x: print('FROM X1 {}'.format(x)) z2.callback = lambda a, b, c, x: print('FROM X2 {}'.format(x)) z2.add_sub(exchange='testTopic', routing_key='000001.SZ') z3.callback = lambda a, b, c, x: print('FROM X3 {}'.format(x)) p = publisher_topic(exchange='testTopic', ) threading.Thread(target=z1.start).start() threading.Thread(target=z2.start).start() threading.Thread(target=z3.start).start() p.pub('000001', routing_key='000001.SZ') p.pub('000002', routing_key='000002.SZ') p.pub('601318', routing_key='601318.SH') """ 在exchange为 xx的mq中