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:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kroitorcommented, Jun 10, 2021

added minor edits to the snippet above

0reactions
kroitorcommented, Jun 17, 2021

@Joseph2Young you can configure the proxies as described here:

You can also find proxy examples here:

Hope that helps, let us know if not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do I get this Python script execution error? - ccxt ...
An error occurs only when 'balance = exchange. fetch_balance()' is with the #main code part below. But on Windows it works just fine...
Read more >
ccxt-dev/ccxt - Gitter
i'd start applying/trying solutions mentioned in https://www.google.com/search?q=python+requests+max+retries+exceeded+with+url , as you can see, ...
Read more >
Exchanges — ccxt 2.4.71 documentation
All exchanges are derived from the base Exchange class and share a set of common ... Python exchange = ccxt.binance(config) exchange.set_sandbox_mode(True) ...
Read more >
Build #27848 - ccxt/ccxt
Travis CI enables your team to test and ship your apps with confidence. Easily sync your projects with Travis CI and you'll be...
Read more >
freqtrade.exceptions.operationalexception: could not load ...
HTTPError: 400 Client Error: for url: https://api.binance.com/sapi/v1/capital/ ... line 624, in fetch raise RequestTimeout(details) from e ccxt.base.errors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found