ccxt / ccxt

A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
https://docs.ccxt.com
MIT License
32.51k stars 7.47k forks source link

CCXT proxy issue #20961

Closed BangyuanX closed 7 months ago

BangyuanX commented 7 months ago

Operating System

Win10

Programming Languages

Python

CCXT Version

4.2.21

Description

Context: I'm living in China and you may know we have the great fire wall. I usually use V2rayN on my PC to search content using Google or login to the website which are forbidden in China.

Basically, I can call the BInance API using its official connector binance-connector-python. However, when I tried to use cctx to pull the data, it's not working from my end. After that, I've searched and read a lot docs on the Internet and none of them solve my problem. Can you help me with that? Thanks!

Code

from binance.spot import Spot

client = Spot()
print(client.klines("BTCUSDT","1h",limit=10))
import ccxt

binance_exchange = ccxt.binance()
ticker_data = binance_exchange.fetch_ticker('BTC/USDT')
print(ticker_data)

Error

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\connectionpool.py", line 715, in urlopen
    httplib_response = self._make_request(
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\connectionpool.py", line 404, in _make_request
    self._validate_conn(conn)
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\connectionpool.py", line 1058, in _validate_conn
    conn.connect()
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\connection.py", line 179, in _new_conn
    raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x000001B92C7A3C40>, 'Connection to api.binance.com timed out. (connect timeout=10.0)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\requests\adapters.py", line 486, in send
    resp = conn.urlopen(
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\connectionpool.py", line 799, in urlopen
    retries = retries.increment(
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.binance.com', port=443): Max retries exceeded with url: /api/v3/exchangeInfo (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001B92C7A3C40>, 'Connection to api.binance.com timed out. (connect timeout=10.0)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\ccxt\base\exchange.py", line 596, in fetch
    response = self.session.request(
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\requests\adapters.py", line 507, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.binance.com', port=443): Max retries exceeded with url: /api/v3/exchangeInfo (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001B92C7A3C40>, 'Connection to api.binance.com timed out. (connect timeout=10.0)'))

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

Traceback (most recent call last):
  File "d:\Python\quant_learn\BinanceAPI\2.ccxt_quickstart.py", line 33, in <module>
    ticker_data = binance_exchange.fetch_ticker(symbol)
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\ccxt\binance.py", line 3007, in fetch_ticker
    self.load_markets()
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\ccxt\base\exchange.py", line 1464, in load_markets
    markets = self.fetch_markets(params)
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\ccxt\binance.py", line 2049, in fetch_markets
    promisesRaw.append(self.publicGetExchangeInfo(params))
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\ccxt\base\types.py", line 34, in unbound_method
    return _self.request(self.path, self.api, self.method, params, config=self.config)
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\ccxt\binance.py", line 8166, in request
    response = self.fetch2(path, api, method, params, headers, body, config)
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\ccxt\base\exchange.py", line 3350, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "C:\ProgramData\Anaconda3\envs\quant\lib\site-packages\ccxt\base\exchange.py", line 626, in fetch
    raise RequestTimeout(details) from e
ccxt.base.errors.RequestTimeout: binance GET https://api.binance.com/api/v3/exchangeInfo
ttodua commented 7 months ago

1) can you tell, do you access: https://api.binance.com/api/v3/exchangeInfo from browser directly? 2) do you have a chance to test out in other language (other than python, because I suspect it might be using OS's unproxied calls), so with nodejs you run i.e. this script: https://github.com/ccxt/ccxt/blob/master/examples/js/fetch-ohlcv.js

BangyuanX commented 7 months ago

Thanks for your reply.

  1. Yes, I tried and it's able to access the link and get the data from browser.
  2. No, I haven't tried.

Never mind, I migrate all the codes to an AWS servre. Everything works there. Thank you!

XXA222 commented 1 week ago

你好,我也遇到了同样的问题,使用了vpn,错误提示是RequestTimeout: binance GET https://api.binance.com/sapi/v1/capital/config/getall?timestamp=1725611533376&recvWindow=10000&signature=9f8f60ae68f12e2ad08ca78d5862dd3838889f5a358a8d9270c63de29117a6f0 ,以前vpn还能获取数据,现在获取不了了,这个问题你后面解决了吗

BangyuanX commented 1 week ago

没有解决,我用freqtrade了

ttodua commented 1 week ago

If you use proxies or VPN (like lantern) you might look in the answers: https://github.com/ccxt/ccxt/issues/9234