Create a client like -
from pybit.unified_trading import HTTP as BybitHTTP
class ProxyHTTP(BybitHTTP):
def __init__(self, proxy_host=None, proxy_port=None, **kwargs):
super().__init__(**kwargs)
self.proxy_url = f'https://{proxy_host}:{proxy_port}' if proxy_host and proxy_port else None
def _send_http_request(self, req, **kwargs):
if self.proxy_url:
settings = self.client.merge_environment_settings(
req.url,
proxies={'https': self.proxy_url, 'https': self.proxy_url},
stream=None,
verify=True,
cert=None
)
return self.client.send(req, timeout=self.timeout, allow_redirects=False, **settings)
return self.client.send(req, timeout=self.timeout)
Use this in your main file -
from bybit_client import ProxyHTTP