From 7d5f021717219e150579b8b249f5ff464a2718ce Mon Sep 17 00:00:00 2001 From: David Arena Date: Fri, 20 Dec 2024 23:47:18 +0100 Subject: [PATCH] feat: add timeout to FtRestClient --- ft_client/freqtrade_client/ft_rest_client.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ft_client/freqtrade_client/ft_rest_client.py b/ft_client/freqtrade_client/ft_rest_client.py index 851583ee0..0c6f71035 100755 --- a/ft_client/freqtrade_client/ft_rest_client.py +++ b/ft_client/freqtrade_client/ft_rest_client.py @@ -23,10 +23,11 @@ PostDataT = dict[str, Any] | list[dict[str, Any]] | None class FtRestClient: def __init__( - self, serverurl, username=None, password=None, *, pool_connections=10, pool_maxsize=10 + self, serverurl, username=None, password=None, *, pool_connections=10, pool_maxsize=10, timeout=10 ): self._serverurl = serverurl self._session = requests.Session() + self._timeout = timeout # allow configuration of pool adapter = HTTPAdapter(pool_connections=pool_connections, pool_maxsize=pool_maxsize) @@ -50,7 +51,7 @@ class FtRestClient: url = urlunparse((schema, netloc, path, par, query, fragment)) try: - resp = self._session.request(method, url, headers=hd, data=json.dumps(data)) + resp = self._session.request(method, url, headers=hd, timeout=self._timeout, data=json.dumps(data)) # return resp.text return resp.json() except RequestConnectionError: