Skip to content
This repository was archived by the owner on May 25, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
delete,
get,
post,
set_proxy,
drop_notifications_query_params,
add_balance_allowance_params_to_url,
add_order_scoring_params_to_url,
Expand Down Expand Up @@ -124,6 +125,7 @@ def __init__(
funder: str = None,
builder_config: BuilderConfig = None,
tick_size_ttl: float = 300.0,
proxy: Optional[str] = None,
):
"""
Initializes the clob client
Expand Down Expand Up @@ -159,6 +161,10 @@ def __init__(
self.__neg_risk = {}
self.__fee_rates = {}

# proxy
if proxy:
set_proxy(proxy)
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

# RFQ client
self.rfq = RfqClient(self)

Expand Down
12 changes: 12 additions & 0 deletions py_clob_client/http_helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@
_http_client = httpx.Client(http2=True)


def set_proxy(proxy: str = None):
"""
Reconfigures the shared HTTP client to use the given proxy.
Pass None or empty string to disable proxy.
"""
global _http_client
kwargs = {"http2": True}
if proxy:
kwargs["proxy"] = proxy
_http_client = httpx.Client(**kwargs)
Comment thread
cursor[bot] marked this conversation as resolved.


def overloadHeaders(method: str, headers: dict) -> dict:
if headers is None:
headers = dict()
Expand Down
24 changes: 24 additions & 0 deletions tests/http_helpers/test_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from unittest import TestCase
from unittest.mock import patch, MagicMock

from py_clob_client.http_helpers.helpers import set_proxy


class TestProxy(TestCase):
@patch("py_clob_client.http_helpers.helpers.httpx.Client")
def test_set_proxy_creates_client_with_proxy(self, mock_client_cls):
"""set_proxy should create a new httpx.Client with the proxy param."""
set_proxy("http://localhost:8080")
mock_client_cls.assert_called_once_with(http2=True, proxy="http://localhost:8080")

@patch("py_clob_client.http_helpers.helpers.httpx.Client")
def test_set_proxy_none_creates_client_without_proxy(self, mock_client_cls):
"""set_proxy(None) should create a client without the proxy param."""
set_proxy(None)
mock_client_cls.assert_called_once_with(http2=True)

@patch("py_clob_client.http_helpers.helpers.httpx.Client")
def test_set_proxy_empty_string_creates_client_without_proxy(self, mock_client_cls):
"""set_proxy('') should create a client without the proxy param."""
set_proxy("")
mock_client_cls.assert_called_once_with(http2=True)