def init_tasks(self): loop = asyncio.get_event_loop() # init task_exchanges task_exchanges = TaskExchanges(self.exchange_data, self.config["magicwalletkey"]) task_exchanges.set_period(int(self.config["timer_minute"]) * 60) # init task_pusher if self.config["pusher"]["enable"]: topic = "bts.exchanges" login_info = None if self.config["pusher"]["user"]: login_info = self.config["pusher"] task_pusher = TaskPusher(self.exchange_data) task_pusher.topic = topic task_pusher.set_expired(self.config["timer_minute"] * 60 + 30) if "publish" in self.config["pusher"]: def publish_data(_type, _name, _data): # print("publish: %s %s" % (_type, _name)) task_pusher.pusher.publish(topic, _type, _name, _data) task_exchanges.handler = publish_data task_pusher.run_tasks(loop, login_info) task_exchanges.run_tasks(loop)
def init_tasks(self): loop = asyncio.get_event_loop() # init task_exchanges task_exchanges = TaskExchanges(self.exchange_data) task_exchanges.set_period(int(self.config["timer_minute"])*60) # init task_pusher if self.config["pusher"]["enable"]: topic = "bts.exchanges" login_info = None if self.config["pusher"]["user"]: login_info = self.config["pusher"] task_pusher = TaskPusher(self.exchange_data) task_pusher.topic = topic task_pusher.set_expired(self.config["timer_minute"]*60+30) if "publish" in self.config["pusher"]: def publish_data(_type, _name, _data): # print("publish: %s %s" % (_type, _name)) task_pusher.pusher.publish(topic, _type, _name, _data) task_exchanges.handler = publish_data task_pusher.run_tasks(loop, login_info) task_exchanges.run_tasks(loop)
self.pusher = Pusher(loop, login_info) self.pusher.sync_subscribe(onData, self.topic) def set_expired(self, sec): self.expired = sec if __name__ == "__main__": exchange_data = {} task_pusher = TaskPusher(exchange_data) topic = "public.exchanges" def publish_data(_type, _name, _data): print("publish: %s %s" % (_type, _name)) task_pusher.pusher.publish(topic, _type, _name, _data) from btsprice.task_exchanges import TaskExchanges task_exchanges = TaskExchanges(exchange_data) task_exchanges.handler = publish_data task_exchanges.set_period(20) loop = asyncio.get_event_loop() task_pusher.topic = topic task_pusher.run_tasks(loop) task_exchanges.run_tasks(loop) loop.run_forever() loop.close()