Skip to content

client_session: <aiohttp.client.ClientSession object at 0x000001B7CD7F9B70> #2173

Closed
@zhoujinhai

Description

I can get the ticker when I use the first code, but when I use async , the code run wrong, how to slove it ! can you help me? I am use python 3.6 on windows 10 .

the first code:

import ccxt
exchange = ccxt.binance()
symbol = 'BTC/USDT'
ticker = exchange.fetch_ticker(symbol)
print(ticker)

image

the sencond code:

import asyncio
import ccxt.async as ccxt

async def getticker():
    binance = ccxt.binance()
    print(await binance.fetch_ticker('BTC/USDT'))

asyncio.get_event_loop().run_until_complete(getticker())
Traceback (most recent call last):
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\base\exchange.py", line 124, in fetch
    proxy=self.aiohttp_proxy) as response:
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\aiohttp\client.py", line 690, in __aenter__
    self._resp = yield from self._coro
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\aiohttp\client.py", line 341, in _request
    break
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\aiohttp\helpers.py", line 727, in __exit__
    raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:/python3/test/test.py", line 10, in <module>
    asyncio.get_event_loop().run_until_complete(getticker())
  File "C:\Users\SXY004\Anaconda3\lib\asyncio\base_events.py", line 466, in run_until_complete
    return future.result()
  File "E:/python3/test/test.py", line 8, in getticker
    print(await binance.fetch_ticker('BTC/USDT'))
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\binance.py", line 492, in fetch_ticker
    await self.load_markets()
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\base\exchange.py", line 153, in load_markets
    markets = await self.fetch_markets()
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\binance.py", line 345, in fetch_markets
    response = await self.publicGetExchangeInfo()
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\base\exchange.py", line 102, in fetch2
    return await self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\async\base\exchange.py", line 139, in fetch
    self.raise_error(RequestTimeout, method, url, e, None)
  File "C:\Users\SXY004\Anaconda3\lib\site-packages\ccxt\base\exchange.py", line 274, in raise_error
    raise exception_type(output)
ccxt.base.errors.RequestTimeout: binance GET https://api.binance.com/api/v1/exchangeInfo 
binance requires to release all resources with an explicit call to the .close() coroutine.
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001AE4AB39B00>

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions