feat: 为出站请求统一接入 HTTP 代理

This commit is contained in:
2026-08-14 16:08:39 +08:00
parent 3dc2aeb3a2
commit fabca9510d
23 changed files with 213 additions and 14 deletions
+6 -1
View File
@@ -16,7 +16,9 @@ from typing import Any
import httpx
from app.shared.config import Settings
from app.shared.errors import AppError
from app.shared.proxy import httpx_client_options
from app.shared.task_state import OrderState, TaskStatus
from app.trading.worker.models import LeaseTask
@@ -29,13 +31,16 @@ class GatewayClient:
一份 AsyncClient 实例贯穿 worker 整个生命周期,连接池由 httpx 管理。
"""
def __init__(self, base_url: str, bearer_token: str, *, timeout: float = 60.0):
def __init__(
self, base_url: str, bearer_token: str, *, settings: Settings, timeout: float = 60.0
):
# 末尾去斜杠,避免 base + "/api/..." 拼出双斜杠
self._base_url = base_url.rstrip("/")
self._client = httpx.AsyncClient(
base_url=self._base_url,
headers={"Authorization": f"Bearer {bearer_token}"},
timeout=timeout,
**httpx_client_options(settings, target_url=self._base_url),
)
async def aclose(self) -> None: