async def get_snapshot(
            trading_pair: str,
            limit: int = 1000,
            domain: str = "com",
            throttler: Optional[AsyncThrottler] = None) -> Dict[str, Any]:
        throttler = throttler or BinanceAPIOrderBookDataSource._get_throttler_instance(
        )
        params: Dict = {"limit": str(limit), "symbol": binance_utils.convert_to_exchange_trading_pair(trading_pair)} if limit != 0 \
            else {"symbol": binance_utils.convert_to_exchange_trading_pair(trading_pair)}
        async with aiohttp.ClientSession() as client:
            async with throttler.execute_task(
                    limit_id=CONSTANTS.SNAPSHOT_PATH_URL):
                url = binance_utils.public_rest_url(
                    path_url=CONSTANTS.SNAPSHOT_PATH_URL, domain=domain)
                async with client.get(url, params=params) as response:
                    response: aiohttp.ClientResponse = response
                    if response.status != 200:
                        raise IOError(
                            f"Error fetching market snapshot for {trading_pair}. "
                            f"Response: {response}.")
                    data: Dict[str, Any] = await response.json()

                    # Need to add the symbol into the snapshot message for the Kafka message queue.
                    # Because otherwise, there'd be no way for the receiver to know which market the
                    # snapshot belongs to.

                    return data
    async def get_snapshot(client: aiohttp.ClientSession, trading_pair: str, limit: int = 1000,
                           domain: str = "com") -> Dict[str, Any]:
        params: Dict = {"limit": str(limit), "symbol": convert_to_exchange_trading_pair(trading_pair)} if limit != 0 \
            else {"symbol": convert_to_exchange_trading_pair(trading_pair)}
        url = SNAPSHOT_REST_URL.format(domain)
        async with client.get(url, params=params) as response:
            response: aiohttp.ClientResponse = response
            if response.status != 200:
                raise IOError(f"Error fetching market snapshot for {trading_pair}. "
                              f"HTTP status is {response.status}.")
            data: Dict[str, Any] = await response.json()

            # Need to add the symbol into the snapshot message for the Kafka message queue.
            # Because otherwise, there'd be no way for the receiver to know which market the
            # snapshot belongs to.

            return data
Beispiel #3
0
 def test_convert_to_exchange_format_three_letters_base_and_three_letters_quote_matching_with_a_four_letters_quote_candidate(self):
     converted_pair = utils.convert_to_exchange_trading_pair("VET-USD")
     self.assertEqual(converted_pair, "VETUSD")
Beispiel #4
0
 def test_convert_to_exchange_format_three_letters_base_and_four_letters_quote(self):
     converted_pair = utils.convert_to_exchange_trading_pair("BTC-USDT")
     self.assertEqual(converted_pair, "BTCUSDT")
Beispiel #5
0
 def test_pair_conversion(self):
     if API_MOCK_ENABLED:
         return
     for pair in self.market.trading_rules:
         exchange_pair = convert_to_exchange_trading_pair(pair)
         self.assertTrue(exchange_pair in self.market.order_books)