def setUp(self) -> None:
     super().setUp()
     self.base = "COINALHPA"
     self.quote = "HBOT"
     self.trading_pair = f"{self.base}-{self.quote}"
     self.wallet_key = "someWalletKey"
     self.gateway_host = "gtw_host"
     self.gateway_port = 123
     global_config_map["gateway_api_host"].value = self.gateway_host
     global_config_map["gateway_api_port"].value = self.gateway_port
     self.connector = UniswapConnector(
         trading_pairs=[self.trading_pair],
         wallet_private_key=self.wallet_key,
         ethereum_rpc_url="https://<network>.infura.io/v3/YOUR-PROJECT-ID",
     )
     self.ev_loop = asyncio.get_event_loop()
class UniswapConnectorTest(unittest.TestCase):
    def setUp(self) -> None:
        super().setUp()
        self.base = "COINALHPA"
        self.quote = "HBOT"
        self.trading_pair = f"{self.base}-{self.quote}"
        self.wallet_key = "someWalletKey"
        self.gateway_host = "gtw_host"
        self.gateway_port = 123
        global_config_map["gateway_api_host"].value = self.gateway_host
        global_config_map["gateway_api_port"].value = self.gateway_port
        self.connector = UniswapConnector(
            trading_pairs=[self.trading_pair],
            wallet_private_key=self.wallet_key,
            ethereum_rpc_url="https://<network>.infura.io/v3/YOUR-PROJECT-ID",
        )
        self.ev_loop = asyncio.get_event_loop()

    def async_run_with_timeout(self, coroutine: Awaitable, timeout: float = 1):
        ret = self.ev_loop.run_until_complete(
            asyncio.wait_for(coroutine, timeout))
        return ret

    @aioresponses()
    @patch(
        "hummingbot.connector.connector.uniswap.uniswap_connector.UniswapConnector._http_client",
        new_callable=AsyncMock)
    def test_get_quote_price_updates_fee_overrides_config_map(
            self, mocked_api, mocked_http_client):
        mocked_http_client.return_value = aiohttp.ClientSession()
        url = f"https://{self.gateway_host}:{self.gateway_port}/eth/uniswap/price"
        mock_response = {
            "price": 10,
            "gasLimit": 30000,
            "gasPrice": 1,
            "gasCost": 2,
            "swaps": [],
        }
        mocked_api.post(url, body=json.dumps(mock_response))

        self.connector._account_balances = {"ETH": Decimal("10000")}
        self.connector._allowances = {self.quote: Decimal("10000")}

        self.async_run_with_timeout(
            self.connector.get_quote_price(self.trading_pair,
                                           is_buy=True,
                                           amount=Decimal("2")))

        self.assertEqual(
            fee_overrides_config_map["uniswap_maker_fixed_fees"].value,
            [TokenAmount("ETH", Decimal(str("2")))])
        self.assertEqual(
            fee_overrides_config_map["uniswap_taker_fixed_fees"].value,
            [TokenAmount("ETH", Decimal(str("2")))])
Ejemplo n.º 3
0
 def setUpClass(cls):
     cls._gas_price_patcher = unittest.mock.patch(
         "hummingbot.connector.connector.uniswap.uniswap_connector.get_gas_price"
     )
     cls._gas_price_mock = cls._gas_price_patcher.start()
     cls._gas_price_mock.return_value = 50
     cls.ev_loop = asyncio.get_event_loop()
     cls.clock: Clock = Clock(ClockMode.REALTIME)
     cls.connector: UniswapConnector = UniswapConnector([
         trading_pair
     ], "0xdc393a78a366ac53ffbd5283e71785fd2097807fef1bc5b73b8ec84da47fb8de",
                                                        "")
     print(
         "Initializing CryptoCom market... this will take about a minute.")
     cls.clock.add_iterator(cls.connector)
     cls.stack: contextlib.ExitStack = contextlib.ExitStack()
     cls._clock = cls.stack.enter_context(cls.clock)
     cls.ev_loop.run_until_complete(cls.wait_til_ready())
     print("Ready.")
Ejemplo n.º 4
0
 async def request_rate_in_eth(self, quote: str) -> int:
     if self._uniswap is None:
         self._uniswap = UniswapConnector([f"{quote}-WETH"], "", None)
     return await self._uniswap.get_quote_price(f"{quote}-WETH", True, 1)