Skip to content

Commit

Permalink
feat(AsyncClient): https_proxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiei committed Oct 21, 2024
1 parent 387aefd commit 89f48cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions binance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10028,8 +10028,9 @@ def __init__(
base_endpoint: str = BaseClient.BASE_ENDPOINT_DEFAULT,
testnet: bool = False, loop=None, session_params: Optional[Dict[str, Any]] = None,
private_key: Optional[Union[str, Path]] = None, private_key_pass: Optional[str] = None,
https_proxy: Optional[str] = None
):

self.https_proxy = https_proxy
self.loop = loop or get_loop()
self._session_params: Dict[str, Any] = session_params or {}
super().__init__(api_key, api_secret, requests_params, tld, base_endpoint, testnet, private_key, private_key_pass)
Expand Down Expand Up @@ -10076,7 +10077,7 @@ async def _request(self, method, uri: str, signed: bool, force_params: bool = Fa

kwargs = self._get_request_kwargs(method, signed, force_params, **kwargs)

async with getattr(self.session, method)(uri, **kwargs) as response:
async with getattr(self.session, method)(uri, proxy=self.https_proxy, **kwargs) as response:
self.response = response
return await self._handle_response(response)

Expand Down
15 changes: 12 additions & 3 deletions tests/test_papi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@

from binance.client import Client
from binance.client import Client, AsyncClient
import os
import pytest

proxies = {}
proxy = os.getenv("PROXY")
proxy = "http://51.83.140.52:16301"

if proxy:
proxies = {"http": proxy, 'https': proxy } # tmp: improve this in the future
Expand All @@ -12,6 +14,13 @@

client = Client("api_key", "api_secret", {'proxies': proxies})


def test_ping_sync():
pingResponse = client.papi_ping()
assert pingResponse != None
ping_response = client.papi_ping()
assert ping_response != None

@pytest.mark.asyncio()
async def test_ping_async():
clientAsync = AsyncClient(api_key="api_key", api_secret="api_secret", https_proxy=proxy)
ping_response = await clientAsync.papi_ping()
assert ping_response != None

0 comments on commit 89f48cc

Please sign in to comment.