def __init__(self, hitbtc_api_key: str, hitbtc_secret_key: str, trading_pairs: Optional[List[str]] = None, trading_required: bool = True ): """ :param hitbtc_api_key: The API key to connect to private HitBTC APIs. :param hitbtc_secret_key: The API secret. :param trading_pairs: The market trading pairs which to track order book data. :param trading_required: Whether actual trading is needed. """ super().__init__() self._trading_required = trading_required self._trading_pairs = trading_pairs self._hitbtc_auth = HitbtcAuth(hitbtc_api_key, hitbtc_secret_key) self._order_book_tracker = HitbtcOrderBookTracker(trading_pairs=trading_pairs) self._user_stream_tracker = HitbtcUserStreamTracker(self._hitbtc_auth, trading_pairs) self._ev_loop = asyncio.get_event_loop() self._shared_client = None self._poll_notifier = asyncio.Event() self._last_timestamp = 0 self._in_flight_orders = {} # Dict[client_order_id:str, HitbtcInFlightOrder] self._order_not_found_records = {} # Dict[client_order_id:str, count:int] self._trading_rules = {} # Dict[trading_pair:str, TradingRule] self._status_polling_task = None self._user_stream_event_listener_task = None self._trading_rules_polling_task = None self._last_poll_timestamp = 0
def setUpClass(cls): cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() cls.trading_pairs = ["BTC-USDT"] cls.user_stream_tracker: HitbtcUserStreamTracker = HitbtcUserStreamTracker( hitbtc_auth=HitbtcAuth(cls.api_key, cls.api_secret), trading_pairs=cls.trading_pairs) cls.user_stream_tracker_task: asyncio.Task = safe_ensure_future( cls.user_stream_tracker.start())