Skip to content

Commit 0f31514

Browse files
committed
feat: Api support timeout setting
1 parent 782b688 commit 0f31514

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

hyperliquid/api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010

1111

1212
class API:
13-
def __init__(self, base_url=None):
13+
def __init__(self, base_url=None, timeout=None):
1414
self.base_url = base_url or MAINNET_API_URL
1515
self.session = requests.Session()
1616
self.session.headers.update({"Content-Type": "application/json"})
1717
self._logger = logging.getLogger(__name__)
18+
self.timeout = timeout
1819

1920
def post(self, url_path: str, payload: Any = None) -> Any:
2021
payload = payload or {}
2122
url = self.base_url + url_path
22-
response = self.session.post(url, json=payload)
23+
response = self.session.post(url, json=payload, timeout=self.timeout)
2324
self._handle_exception(response)
2425
try:
2526
return response.json()

hyperliquid/exchange.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ def __init__(
6060
account_address: Optional[str] = None,
6161
spot_meta: Optional[SpotMeta] = None,
6262
perp_dexs: Optional[List[str]] = None,
63+
timeout: Optional[float] = None,
6364
):
64-
super().__init__(base_url)
65+
super().__init__(base_url, timeout)
6566
self.wallet = wallet
6667
self.vault_address = vault_address
6768
self.account_address = account_address

hyperliquid/info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def __init__(
2424
# Note that when perp_dexs is None, then "" is used as the perp dex. "" represents
2525
# the original dex.
2626
perp_dexs: Optional[List[str]] = None,
27+
timeout: Optional[float] = None,
2728
): # pylint: disable=too-many-locals
28-
super().__init__(base_url)
29+
super().__init__(base_url, timeout)
2930
self.ws_manager: Optional[WebsocketManager] = None
3031
if not skip_ws:
3132
self.ws_manager = WebsocketManager(self.base_url)

0 commit comments

Comments
 (0)