def initialize(self): """ 初始化 """ # 注册服务 检查连接是否正常 heartbeat.register(self._check_connection, self._check_conn_interval) # 注册服务 发送心跳 heartbeat.register(self._send_heartbeat_msg, self._send_hb_interval) # 建立websocket连接 asyncio.get_event_loop().create_task(self._connect())
def initialize(self): """ 初始化 """ self.order_manager = OrderManager(self.platfrom, self.account, self.access_key, self.secret_key, self.symbol, self.name) # 注册订单状态更新回调 self.order_manager.register_callback(self.on_event_order_update) # 注册定时任务 heartbeat.register(self.do_task)
def __init__(self): self._host = config.rabbitmq.get('host', 'localhost') self._port = config.rabbitmq.get('port', 5672) self._username = config.rabbitmq.get('username', 'guest') self._password = config.rabbitmq.get('password', 'guest') self._protocol = None self._channel = None # 连接通道 self._connected = False # 是否连接成功 self._subscribers = [] # 订阅者 [(event, callback, multi), ...] self._event_handler = { } # 事件对应的处理函数 {"exchange:routing_key": [callback_function, ...]} heartbeat.register(self._check_connection, 10) # 检查连接是否正常
def register(cls, func, interval=1, *args, **kwargs): """ 注册一个任务,在每次心跳的时候执行调用 @param func 心跳的时候执行的函数,必须的async异步函数 @param interval 执行回调的时间间隔(秒),必须是整秒 @return task_id 任务id """ task_id = heartbeat.register(func, interval, *args, **kwargs) return task_id
def __init__(self, platform, account, access_key, secret_key, symbol, strategy, order_update_interval=2): """ 初始化 @param platform 交易平台 @param account 交易账户 @param access_key 公钥 @param secret_key 私钥 @param symbol 交易对 @param strategy 策略名称 @param order_update_interval 检查订单更新时间间隔(秒) """ self._platform = platform self._account = account self._access_key = access_key self._secret_key = secret_key self._symbol = symbol self._strategy = strategy self._order_update_interval = order_update_interval # 将标准交易对转换成原始交易对 self._raw_symbol = SYMBOL_MAP.get(symbol, {}).get(self._platform, symbol) # 订单对象 self._orders = {} # 订单列表 key:order_no, value:order_object # 回调函数列表 self._callback_funcs = [] # 请求对象 self._request = Request(platform, account, access_key, secret_key) # 初始化订单数据库对象 # self._order_db = OrderData() # 订阅回调 定时查询订单状态 heartbeat.register(self.check_order_update, self._order_update_interval)
def _initialize(self): """ Initialize.""" for channel in self._channels: if channel == "orderbook": heartbeat.register(self.do_orderbook_update, self._orderbook_interval) elif channel == const.MARKET_TYPE_KLINE_5M: heartbeat.register(self.create_kline_tasks, 60 * 5, const.MARKET_TYPE_KLINE_5M) elif channel == const.MARKET_TYPE_KLINE_15M: heartbeat.register(self.create_kline_tasks, 60 * 15, const.MARKET_TYPE_KLINE_15M) elif channel == "trade": heartbeat.register(self.do_trade_update, self._trade_interval) else: logger.error("channel error! channel:", channel, caller=self)
def register(cls, func, interval=1, *args, **kwargs): """ Register a loop run. Args: func: Asynchronous callback function. interval: execute interval time(seconds), default is 1s. Returns: task_id: Task id. """ task_id = heartbeat.register(func, interval, *args, **kwargs) return task_id
def _initialize(self): """ Initialize.""" for channel in self._channels: if channel == const.MARKET_TYPE_KLINE_5M: heartbeat.register(self.create_kline_tasks, 1, const.MARKET_TYPE_KLINE_5M) elif channel == const.MARKET_TYPE_KLINE_15M: heartbeat.register(self.create_kline_tasks, 1, const.MARKET_TYPE_KLINE_15M) elif channel == const.MARKET_TYPE_KLINE_1H: heartbeat.register(self.create_kline_tasks, 1, const.MARKET_TYPE_KLINE_1H)