Binance async_support ccxt.base.errors.RequestTimeout
See original GitHub issue- OS: macOS 11.4
- Programming Language version:Python 3.7.1
- CCXT version: ccxt -v 1.51.3
import asyncio
import arrow
import ccxt.async_support as ccxt
class BinanceUsdtSwap: def init(self,api_key,api_secret,symbol): self.exchange = ccxt.binance({ ‘apiKey’ : api_key, ‘secret’: api_secret, }) async def get_balance(self): res = await self.exchange.fapiPrivateV2_get_balance() await self.exchange.close() return res if name == ‘main’: BUS = BinanceUsdtSwap(api_key,api_secret,‘BTCUSDT’) loop = asyncio.get_event_loop() loop.run_until_complete(BUS.get_balance())
I just want to get the future account balance in Binance, but when I use asyncio request, It's always timeout.
And it's ok when I import ccxt instead of ccxt.async_support .
show_data
Request: GET https://fapi.binance.com/fapi/v2/balance?timestamp=1623316737668&recvWindow=5000&signature=94028f5b6b19995d899086a3c97bde36744d740a22b18845e13b5e8e0a16a589 {‘X-MBX-APIKEY’: ‘YRA5WLdkXVJYORO4R8TQOujM8JcBU4mCq9pOXDoWGlE58DLtpganpHrNZ6xjGTBv’, ‘User-Agent’: ‘python-requests/2.25.1’, ‘Accept-Encoding’: ‘gzip, deflate’} None Traceback (most recent call last): File “/Users/yangjingsong/anaconda3/lib/python3.7/site-packages/ccxt/async_support/base/exchange.py”, line 121, in fetch proxy=self.aiohttp_proxy) as response: File “/Users/yangjingsong/anaconda3/lib/python3.7/site-packages/aiohttp/client.py”, line 1117, in aenter self._resp = await self._coro File “/Users/yangjingsong/anaconda3/lib/python3.7/site-packages/aiohttp/client.py”, line 619, in _request break File “/Users/yangjingsong/anaconda3/lib/python3.7/site-packages/aiohttp/helpers.py”, line 656, in exit raise asyncio.TimeoutError from None concurrent.futures._base.TimeoutError
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File “/Users/yangjingsong/anaconda3/lib/python3.7/runpy.py”, line 193, in _run_module_as_main “main”, mod_spec) File “/Users/yangjingsong/anaconda3/lib/python3.7/runpy.py”, line 85, in _run_code exec(code, run_globals) File “/Users/yangjingsong/.vscode/extensions/ms-python.python-2021.5.842923320/pythonFiles/lib/python/debugpy/main.py”, line 45, in <module> cli.main() File “/Users/yangjingsong/.vscode/extensions/ms-python.python-2021.5.842923320/pythonFiles/lib/python/debugpy/…/debugpy/server/cli.py”, line 444, in main run() File “/Users/yangjingsong/.vscode/extensions/ms-python.python-2021.5.842923320/pythonFiles/lib/python/debugpy/…/debugpy/server/cli.py”, line 285, in run_file runpy.run_path(target_as_str, run_name=compat.force_str(“main”)) File “/Users/yangjingsong/anaconda3/lib/python3.7/runpy.py”, line 263, in run_path pkg_name=pkg_name, script_name=fname) File “/Users/yangjingsong/anaconda3/lib/python3.7/runpy.py”, line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File “/Users/yangjingsong/anaconda3/lib/python3.7/runpy.py”, line 85, in _run_code exec(code, run_globals) File “/Users/yangjingsong/Desktop/JNHG/BinanceRestApiAysnc”, line 237, in <module> loop.run_until_complete(BUS.show_data()) File “/Users/yangjingsong/anaconda3/lib/python3.7/asyncio/base_events.py”, line 573, in run_until_complete return future.result() File “/Users/yangjingsong/Desktop/JNHG/BinanceRestApiAysnc”, line 228, in show_data res = await self.get_balance() File “/Users/yangjingsong/Desktop/JNHG/BinanceRestApiAysnc”, line 136, in get_balance res = await self.exchange.fapiPrivateV2_get_balance() File “/Users/yangjingsong/anaconda3/lib/python3.7/site-packages/ccxt/async_support/binance.py”, line 3570, in request response = await self.fetch2(path, api, method, params, headers, body) File “/Users/yangjingsong/anaconda3/lib/python3.7/site-packages/ccxt/async_support/base/exchange.py”, line 96, in fetch2 return await self.fetch(request[‘url’], request[‘method’], request[‘headers’], request[‘body’]) File “/Users/yangjingsong/anaconda3/lib/python3.7/site-packages/ccxt/async_support/base/exchange.py”, line 151, in fetch raise RequestTimeout(details) from e ccxt.base.errors.RequestTimeout: binance GET https://fapi.binance.com/fapi/v2/balance?timestamp=1623316737668&recvWindow=5000&signature=94028f5b6b19995d899086a3c97bde36744d740a22b18845e13b5e8e0a16a589 binance requires to release all resources with an explicit call to the .close() coroutine. If you are using the exchange instance with async coroutines, add exchange.close() to your code into a place when you’re done with the exchange and don’t need the exchange instance anymore (at the end of your async coroutine). Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7fd14019f240>
So, How can I solve this problem
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Related StackOverflow Question
added minor edits to the snippet above
@Joseph2Young you can configure the proxies as described here:
You can also find proxy examples here:
Hope that helps, let us know if not.