79357080

Date: 2025-01-15 04:42:35
Score: 0.5
Natty:
Report link

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
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Akshat Sharma