asynchronous ccxt cannot connect to exchanges

I am trying to asynchronous ccxt (from ccxt.async_support), but every time I run any asynchronous functions that, for example, fetches ticker data from an exchange, it causes an error like this in the Python console:

poloniex requires to release all resources with an explicit call to the .close() coroutine. If you are using the exchange instance with async coroutines, add `await exchange.close()` to your code into a place when you're done with the exchange and don't need the exchange instance anymore (at th
e end of your async coroutine).
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f27e8d7d0f0>
Traceback (most recent call last):
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/aiohttp/", line 1025, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)
  File "/usr/local/lib/python3.10/asyncio/", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('', 443)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/base/", line 199, in fetch
    async with session_method(yarl.URL(url, encoded=True),
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/aiohttp/", line 1197, in __aenter__
    self._resp = await self._coro
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/aiohttp/", line 581, in _request
    conn = await self._connector.connect(
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/aiohttp/", line 544, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/aiohttp/", line 944, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/aiohttp/", line 1257, in _create_direct_connection
    raise last_exc
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/aiohttp/", line 1226, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/aiohttp/", line 1033, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host ssl:default [Connect call failed ('', 443)]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/asyncio/", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/lib/python3.10/asyncio/", line 646, in run_until_complete
    return future.result()
  File "<stdin>", line 3, in print_poloniex_ethbtc_ticker
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/", line 813, in fetch_ticker
    await self.load_markets()
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/", line 478, in load_markets
    markets = await super(poloniex, self).load_markets(reload, params)
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/base/", line 276, in load_markets
    raise e
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/base/", line 272, in load_markets
    result = await self.markets_loading
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/base/", line 261, in load_markets_helper
    currencies = await self.fetch_currencies()
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/", line 682, in fetch_currencies
    response = await self.publicGetCurrencies(self.extend(params, {'includeMultiChainCurrencies': True}))
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/base/", line 816, in request
    return await self.fetch2(path, api, method, params, headers, body, config)
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/base/", line 813, in fetch2
    return await self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "/home/gsembwdvqjjrsqkhdosya/.local/lib/python3.10/site-packages/ccxt/async_support/base/", line 237, in fetch
    raise ExchangeNotAvailable(details) from e
ccxt.base.errors.ExchangeNotAvailable: poloniex GET

However, running a similar function using normal ccxt does not return an error, and works normally. I am using the proxy from for both asynchronous and normal ccxt, and the proxy configurations are the same for both of them. I used ccxt.poloniex({"proxies":{"http":"proxy.server:3128","https":"proxy.server:3128"}}) to test them.

Also, using the requests library or curl on the exchange works fine as well. Running the same function on my computer without proxy settings works fine.

Is the reason why asynchronous ccxt is unable to connect to the exchanges because of the proxy? If so, how do I fix that?

That "connect call failed" means that it's not using the proxy for some reason. Perhaps you could check with the developers. of the ccxt library to see if there's some difference in the way you need to configure the proxy when in async mode?

Ok, I checked the ccxt documentation and it was because I didn't configure it properly.

Instead of exchange = ccxt.poloniex({"proxies":{"http":"proxy.server:3128","https":"proxy.server:3128"}}) I was supposed to just modify the httpProxy attribute of the exchange. Now it works, thank you for your help!

Thanks for letting us know!