sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.91k stars 2.19k forks source link

How to set proxy in ThreadedWebsocketManager? #1312

Open Vincent-299 opened 1 year ago

Vincent-299 commented 1 year ago

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):

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

oliver-zehentleitner commented 1 year ago

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

Vincent-299 commented 1 year ago

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.

oliver-zehentleitner commented 1 year ago

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

Vincent-299 commented 1 year ago

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

quant2008 commented 1 year ago

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