From 62ed182d12b8a8344a87f6ee5a528628434cf826 Mon Sep 17 00:00:00 2001 From: hail100 Date: Wed, 6 Aug 2025 18:01:34 +0800 Subject: [PATCH] feat: Api support timeout setting --- hyperliquid/api.py | 5 +++-- hyperliquid/exchange.py | 5 +++-- hyperliquid/info.py | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hyperliquid/api.py b/hyperliquid/api.py index 876244bf..d808f2ce 100644 --- a/hyperliquid/api.py +++ b/hyperliquid/api.py @@ -10,16 +10,17 @@ class API: - def __init__(self, base_url=None): + def __init__(self, base_url=None, timeout=None): self.base_url = base_url or MAINNET_API_URL self.session = requests.Session() self.session.headers.update({"Content-Type": "application/json"}) self._logger = logging.getLogger(__name__) + self.timeout = timeout def post(self, url_path: str, payload: Any = None) -> Any: payload = payload or {} url = self.base_url + url_path - response = self.session.post(url, json=payload) + response = self.session.post(url, json=payload, timeout=self.timeout) self._handle_exception(response) try: return response.json() diff --git a/hyperliquid/exchange.py b/hyperliquid/exchange.py index 828bb175..72f1a9bd 100644 --- a/hyperliquid/exchange.py +++ b/hyperliquid/exchange.py @@ -60,12 +60,13 @@ def __init__( account_address: Optional[str] = None, spot_meta: Optional[SpotMeta] = None, perp_dexs: Optional[List[str]] = None, + timeout: Optional[float] = None, ): - super().__init__(base_url) + super().__init__(base_url, timeout) self.wallet = wallet self.vault_address = vault_address self.account_address = account_address - self.info = Info(base_url, True, meta, spot_meta, perp_dexs) + self.info = Info(base_url, True, meta, spot_meta, perp_dexs, timeout) self.expires_after: Optional[int] = None def _post_action(self, action, signature, nonce): diff --git a/hyperliquid/info.py b/hyperliquid/info.py index cc831c93..d3245e15 100644 --- a/hyperliquid/info.py +++ b/hyperliquid/info.py @@ -24,8 +24,9 @@ def __init__( # Note that when perp_dexs is None, then "" is used as the perp dex. "" represents # the original dex. perp_dexs: Optional[List[str]] = None, + timeout: Optional[float] = None, ): # pylint: disable=too-many-locals - super().__init__(base_url) + super().__init__(base_url, timeout) self.ws_manager: Optional[WebsocketManager] = None if not skip_ws: self.ws_manager = WebsocketManager(self.base_url)