async def _request_order_book_snapshot(
            self,
            trading_pair: str,
            limit: int = CONSTANTS.SNAPSHOT_LIMIT_SIZE) -> Dict[str, Any]:
        """
        Retrieves a copy of the full order book from the exchange, for a particular trading pair.

        :param trading_pair: the trading pair for which the order book will be retrieved
        :param limit: the depth of the order book to retrieve

        :return: the response from the exchange (JSON dictionary)
        """
        params = {}
        if limit != 0:
            params["limit"] = str(limit)

        symbol = await self._connector.exchange_symbol_associated_to_pair(
            trading_pair=trading_pair)

        rest_assistant = await self._api_factory.get_rest_assistant()
        data = await rest_assistant.execute_request(
            url=web_utils.public_rest_url(
                path_url=f"{CONSTANTS.SNAPSHOT_PATH_URL}/{symbol}",
                domain=self._domain),
            params=params,
            method=RESTMethod.GET,
            throttler_limit_id=CONSTANTS.SNAPSHOT_PATH_URL)

        return data
    async def _ping_listen_key(self) -> bool:
        rest_assistant = await self._api_factory.get_rest_assistant()
        try:
            data = await rest_assistant.execute_request(
                url=web_utils.public_rest_url(
                    path_url=CONSTANTS.USER_ID_PATH_URL, domain=self._domain),
                method=RESTMethod.GET,
                is_auth_required=True,
                return_err=True,
                throttler_limit_id=CONSTANTS.USER_ID_PATH_URL)

            if "id" not in data:
                self.logger().warning(
                    f"Failed to refresh the listen key {self._current_listen_key}: {data}"
                )
                return False

        except asyncio.CancelledError:
            raise
        except Exception as exception:
            self.logger().warning(
                f"Failed to refresh the listen key {self._current_listen_key}: {exception}"
            )
            return False

        return True
    async def _get_listen_key(self):
        rest_assistant = await self._api_factory.get_rest_assistant()
        data = await rest_assistant.execute_request(
            url=web_utils.public_rest_url(path_url=CONSTANTS.USER_ID_PATH_URL,
                                          domain=self._domain),
            method=RESTMethod.GET,
            is_auth_required=True,
            return_err=False,
            throttler_limit_id=CONSTANTS.USER_ID_PATH_URL)

        return data["id"]
Пример #4
0
 async def rest(self, path_url: str) -> Dict[Any, Any]:
     """REST public request"""
     url = web_utils.public_rest_url(path_url=path_url, domain=self.domain)
     headers = {"Content-Type": "application/x-www-form-urlencoded"}
     request = RESTRequest(method=RESTMethod.GET,
                           url=url,
                           headers=headers,
                           is_auth_required=False)
     client = await self.api_factory.get_rest_assistant()
     response: RESTResponse = await client.call(request)
     return await response.json()
 def test_public_rest_url(self):
     path_url = "/auth/account"
     expected_url = CONSTANTS.REST_URL.format(
         self.endpoint, self.domain) + CONSTANTS.REST_API_VERSION + path_url
     self.assertEqual(expected_url,
                      web_utils.public_rest_url(path_url, self.domain))