25 lines
662 B
Python
25 lines
662 B
Python
"""Shared HTTP client options (optional SOCKS5 proxy)."""
|
|
|
|
from .config import settings
|
|
|
|
|
|
def proxy_for(target: str) -> str | None:
|
|
"""
|
|
target: 'binance' | 'wecom'
|
|
Returns proxy URL when enabled and scope matches.
|
|
"""
|
|
if not settings.proxy_enabled or not settings.proxy_url.strip():
|
|
return None
|
|
scope = settings.proxy_for.lower()
|
|
if scope == "all" or scope == target:
|
|
return settings.proxy_url.strip()
|
|
return None
|
|
|
|
|
|
def httpx_client_kwargs(target: str, **extra) -> dict:
|
|
kwargs = dict(extra)
|
|
proxy = proxy_for(target)
|
|
if proxy:
|
|
kwargs["proxy"] = proxy
|
|
return kwargs
|