python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

How to set proxy in ThreadedWebsocketManager?

Open Vincent-299 opened this issue 2 years ago • 7 comments

Describe the bug There is no response when I set the proxy as following: twm = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret, requests_params={'proxy':proxies})

If I set testnet=True, I don't need set the proxy, and it works. twm = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret, testnet=True) To Reproduce proxies = 'http://127.0.0.1:xxxx' twm = ThreadedWebsocketManager(api_key=api_key, api_secret=api_secret, requests_params={'proxy':proxies})

Environment (please complete the following information):

  • Python version:3.7.13
  • Virtual Env: conda
  • OS: win10
  • python-binance version: 1.0.17

Logs or Additional context Add any other context about the problem here.

Vincent-299 avatar Apr 11 '23 16:04 Vincent-299

I looked into the code, there is no proxy support for websocket,

oliver-zehentleitner avatar Apr 14 '23 20:04 oliver-zehentleitner

Thx @oliver-zehentleitner . I think there is setting for websocket proxy. Here is the reason: For the following codes: twm = ThreadedWebsocketManager(requests_params={'proxy':proxies}, testnet=False) if I set testnet=False, I can't receive message for binance, but if i set testnet=True, I can receive data from testnet.

Vincent-299 avatar Apr 15 '23 06:04 Vincent-299

Testnet has nothing to do with proxy. For Testnet only another URI is used at the websocket start. A proxy connection works differently and is definitely not implemented in the code here.

Here you have an alternative, if you want it: https://medium.lucit.tech/how-to-connect-to-binance-com-websockets-using-python-via-a-socks5-proxy-3c5a3e063f12

oliver-zehentleitner avatar Apr 15 '23 09:04 oliver-zehentleitner

Thanks lot @oliver-zehentleitner . I'll look into it.

Vincent-299 avatar Apr 15 '23 14:04 Vincent-299

could it be enhanced to support proxy in python-binance.

quant2008 avatar Apr 28 '23 09:04 quant2008

Here you have an alternative, if you want it

Are you joking? In the article, you use "unicorn_binance_websocket_api", which requires a purchase to obtain a license. The most useless thing for developers.

canyone2015 avatar Dec 03 '24 11:12 canyone2015

@canyone2015 The latest version of python-binance supports proxies out of the box for both REST and WS

carlosmiei avatar Dec 03 '24 11:12 carlosmiei