def debug_pub(exchange, model, routing_key, user, password, host, port, content): if model == 'fanout': publisher(host=host, port=port, user=user, password=password, exchange=exchange).pub(content) elif model == 'direct': print(routing_key) publisher_routing(host=host, port=port, user=user, password=password, exchange=exchange, routing_key=routing_key).pub(content, routing_key=routing_key) elif model == 'topic': publisher_topic(host=host, port=port, user=user, password=password, exchange=exchange, routing_key=routing_key).pub(content, routing_key=routing_key)
def __init__(self, name, app=None, model='ctpx'): super().__init__(name, app) if model == 'ctpx': self.pub = publisher_routing(host=eventmq_ip, exchange='CTPX', routing_key='') else: self.pub = publisher_topic(host=eventmq_ip, exchange='CTPPRO', routing_key='')
def _debug_sim(self): self.running_mode = 'sim' if self.frequence.endswith('min'): self._old_data = QA.QA_fetch_get_future_min( 'tdx', self.code.upper(), QA.QA_util_get_last_day( QA.QA_util_get_real_date(str(datetime.date.today()))), str(datetime.datetime.now()), self.frequence)[:-1].set_index(['datetime', 'code']) self._old_data = self._old_data.assign( volume=self._old_data.trade ).loc[:, ['open', 'high', 'low', 'close', 'volume']] else: pass self.database = pymongo.MongoClient(mongo_ip).QAREALTIME self.client = self.database.account self.subscriber_client = self.database.subscribe self.acc = QIFI_Account(username=self.strategy_id, password=self.strategy_id, trade_host=mongo_ip, init_cash=self.init_cash) self.acc.initial() self.pub = publisher_routing(exchange='QAORDER_ROUTER', host=self.trade_host, port=self.trade_port, user=self.trade_user, password=self.trade_password) self.pubacc = publisher_topic(exchange='QAAccount', host=self.trade_host, port=self.trade_port, user=self.trade_user, password=self.trade_password) self.subscribe_data(self.code.lower(), self.frequence, self.data_host, self.data_port, self.data_user, self.data_password) self.database.strategy_schedule.job_control.update( {'strategy_id': self.strategy_id}, { 'strategy_id': self.strategy_id, 'taskid': self.taskid, 'filepath': os.path.abspath(__file__), 'status': 200 }, upsert=True)
def __init__(self, code_list: list, frequency='60min', strategy="HS300Enhance", init_data=None): """ :param code_list: :param indicator_fun: :param frequency: :param strategy: """ super().__init__() if isinstance(frequency, float): self.frequency = int(frequency) elif isinstance(frequency, str): _frequency = frequency.replace('min', '') if str.isnumeric(_frequency): self.frequency = int(_frequency) else: print("unknown frequency: %s" % frequency) return elif isinstance(frequency, int): self.frequency = frequency else: print("unknown frequency: %s" % frequency) return self.market_data = init_data self.stock_code_list = code_list self.strategy = strategy # 接收stock 重采样的数据 self.sub = subscriber(host=eventmq_ip, exchange='realtime_stock_{}_min'.format( self.frequency)) self.sub.callback = self.stock_min_callback # 发送stock indicator result self.pub = publisher_topic( host=eventmq_ip, exchange='realtime_stock_calculator_{}_{}_min'.format( self.strategy, self.frequency)) threading.Thread(target=self.sub.start).start() print("REALTIME_STOCK_CACULATOR INIT, strategy: %s frequency: %s" % (self.strategy, self.frequency))
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)
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') """ 在exchange为 xx的mq中
import sys import threading import uuid from datetime import timedelta import pymongo from celery import Celery, platforms from celery.schedules import crontab from qaenv import (eventmq_amqp, eventmq_ip, eventmq_password, eventmq_port, eventmq_username, mongo_ip, mongo_port) from QAPUBSUB.consumer import subscriber, subscriber_routing from QAPUBSUB.producer import publisher, publisher_routing, publisher_topic platforms.C_FORCE_ROOT = True # 加上这一行 publisher_R = publisher_topic(host=eventmq_ip, port=eventmq_port, exchange='QAEventTopic') class celeryconfig(): broker_url = eventmq_amqp RESULT_BACKEND = "rpc://" task_default_queue = 'default' task_serializer = 'json' result_serializer = 'json' accept_content = ['application/json'] task_compression = 'gzip' timezone = "Asia/Shanghai" #时区设置 result_backend = "rpc://" enable_utc = False worker_hijack_root_logger = False #celery默认开启自己的日志,可关闭自定义日志,不关闭自定义日志输出为空