Connecting to websocket using

import websocket
import json
import time

# Connection settings
binance_base_endpoint = "wss://"
raw_stream = "/ws"
combined_stream = "/stream?streams="
symbol = "btcusdt"

# Subscriptions
agg_trade_stream = f"{symbol}@aggTrade"
depth_stream = f"{symbol}@depth"

# Proxy settings
http_proxy_host = "host"
http_proxy_port = port

# Proxy authentication
proxy_username = "user"
proxy_password = "pass"

# Connect to Binance websocket
ws = websocket.WebSocket(http_proxy_host=http_proxy_host, http_proxy_port=http_proxy_port, http_proxy_auth=(proxy_username, proxy_password))
ws.connect(binance_base_endpoint + raw_stream + "/" + agg_trade_stream)

# Subscribe to a stream
subscribe_request = {
    "method": "SUBSCRIBE",
    "params": [
    "id": 1

# Listen for messages
    while True:
        response = json.loads(ws.recv())
        if "result" in response and response["result"] is None:
            print(f'Subscription successful: {response["id"]}')
            print(f'Received message: {response}')
except KeyboardInterrupt:
    print("Closing websocket connection...")

# Unsubscribe from a stream
unsubscribe_request = {
    "method": "UNSUBSCRIBE",
    "params": [
    "id": 312
unsubscribe_response = json.loads(ws.recv())
if "result" in unsubscribe_response and unsubscribe_response["result"] is None:
    print(f'Unsubscription successful: {unsubscribe_response["id"]}')

# Close the websocket connection

I’m trying to connect to websocket through HTTP, HTTPS and SOCKS5 proxies and I can’t seem to connect to it, what should I do? Can I use any proxy to connect? What would be a better solution?

P.S: I’m developing a bot for a client and I should develop the code with proxy.

Please consult with the websocket library for how to use proxy.