def _reconnect(self): self._subscribe_order_ok = False self._subscribe_position_ok = False self._subscribe_asset_ok = False self._assets = {} self._orders = {} self._position = Position(self._platform, self._account, self._strategy, self._symbol + '/' + self._contract_type) super(HuobiDeliveryTrade, self)._reconnect()
def __init__(self, **kwargs): """Initialize.""" e = None if not kwargs.get("account"): e = Error("param account miss") if not kwargs.get("strategy"): e = Error("param strategy miss") if not kwargs.get("symbol"): e = Error("param symbol miss") if not kwargs.get("contract_type"): e = Error("param contract_type miss") if not kwargs.get("host"): kwargs["host"] = "https://api.hbdm.com" if not kwargs.get("wss"): kwargs["wss"] = "wss://api.hbdm.com" if not kwargs.get("access_key"): e = Error("param access_key miss") if not kwargs.get("secret_key"): e = Error("param secret_key miss") if e: logger.error(e, caller=self) if kwargs.get("init_success_callback"): SingleTask.run(kwargs["init_success_callback"], False, e) return self._account = kwargs["account"] self._strategy = kwargs["strategy"] self._platform = HUOBI_FUTURE self._symbol = kwargs["symbol"].split('_')[0] self._contract_type = kwargs["contract_type"] self._host = kwargs["host"] self._wss = kwargs["wss"] self._access_key = kwargs["access_key"] self._secret_key = kwargs["secret_key"] self._asset_update_callback = kwargs.get("asset_update_callback") self._order_update_callback = kwargs.get("order_update_callback") self._position_update_callback = kwargs.get("position_update_callback") self._init_success_callback = kwargs.get("init_success_callback") url = self._wss + "/notification" super(HuobiFutureTrade, self).__init__(url, send_hb_interval=5) self._assets = {} # Asset detail, {"BTC": {"free": "1.1", "locked": "2.2", "total": "3.3"}, ... }. self._orders = {} # Order objects, {"order_id": order, ...}. self._position = Position(self._platform, self._account, self._strategy, self._symbol + '/' + self._contract_type) self._order_channel = "orders.{symbol}".format(symbol=self._symbol.lower()) self._position_channel = "positions.{symbol}".format(symbol=self._symbol.lower()) self._asset_channel = "accounts.{symbol}".format(symbol=self._symbol.lower()) self._subscribe_order_ok = False self._subscribe_position_ok = False self._subscribe_asset_ok = False self._rest_api = HuobiFutureRestAPI(self._host, self._access_key, self._secret_key) self.initialize()
async def on_event_position_update(self, position: Position): """ 仓位更新 """ print("on_event_position_update") print(position.__str__())