Skip to content

Add session health check and reconnect support to Info and Exchange class #293

Open

Description

@4stah

The REST session in the Info and Exchange instances appears to expire after ~3 minutes of inactivity. It would be helpful to expose methods such as is_alive() and reconnect() (or similar) to handle this automatically.

BTW. WebSocket can be handled by:

def restart_WeSokects(): # Restart WebSockets if dead
global info
if not info.ws_manager or not info.ws_manager.is_alive():
# print("\n= WebSocket alive:",info.ws_manager.is_alive())
info.disconnect_websocket()
info.ws_manager = WebsocketManager(info.base_url)
info.ws_manager.start()
print("\n= Restart WebSocket:",info.ws_manager.is_alive())
return

Activity

  1. mifth commented on Apr 28, 2026

    @mifth

    I don;t know if you saw this comment #191 (comment)

    This will work forever.

  2. 4stah commented on Apr 28, 2026

    @4stah
    Author

    Well, thx. WebSocket reconnection it's only part of error handling. The other one is REST (calling eg. info.open_orders() will throw exception after 3+ min of inactivity). I can handle it by myself, but it will be nice to have it implemented in SDK.

  3. mifth commented on Apr 28, 2026

    @mifth

    That's weird that "info.open_orders() will throw exception after 3+ min of inactivity". The REST API has no any connection/reconnection stuff. Could you please provide the REST error message?

  4. 4stah commented on Apr 28, 2026

    @4stah
    Author

    Info class init has (from API): self.session = requests.Session()
    Here it is exception (without this opnords = info.open_orders(secret.WALLET_ADDRESS[1] there is no exception and it only occurs after 3+ minutes - if calls every 1 min it works):

    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
    conn,
    ...<10 lines>...
    **response_kw,
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 534, in _make_request
    response = conn.getresponse()
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connection.py", line 565, in getresponse
    httplib_response = super().getresponse()
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1430, in getresponse
    response.begin()
    ~~~~~~~~~~~~~~^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 331, in begin
    version, status, reason = self._read_status()
    ~~~~~~~~~~~~~~~~~^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 292, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/socket.py", line 719, in readinto
    return self._sock.recv_into(b)
    ~~~~~~~~~~~~~~~~~~~~^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1304, in recv_into
    return self.read(nbytes, buffer)
    ~~~~~~~~~^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1138, in read
    return self._sslobj.read(len, buffer)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
    ConnectionResetError: [Errno 54] Connection reset by peer

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/adapters.py", line 644, in send
    resp = conn.urlopen(
    method=request.method,
    ...<9 lines>...
    chunked=chunked,
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 841, in urlopen
    retries = retries.increment(
    method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/util/retry.py", line 474, in increment
    raise reraise(type(error), error, _stacktrace)
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
    conn,
    ...<10 lines>...
    **response_kw,
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 534, in _make_request
    response = conn.getresponse()
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connection.py", line 565, in getresponse
    httplib_response = super().getresponse()
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1430, in getresponse
    response.begin()
    ~~~~~~~~~~~~~~^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 331, in begin
    version, status, reason = self._read_status()
    ~~~~~~~~~~~~~~~~~^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 292, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/socket.py", line 719, in readinto
    return self._sock.recv_into(b)
    ~~~~~~~~~~~~~~~~~~~~^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1304, in recv_into
    return self.read(nbytes, buffer)
    ~~~~~~~~~^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1138, in read
    return self._sslobj.read(len, buffer)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
    urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/Volumes/Cryptovc/scripts/./h.py", line 359, in
    calcel_old_buy_orders()
    ~~~~~~~~~~~~~~~~~~~~~^^
    File "/Volumes/Cryptovc/scripts/./h.py", line 218, in calcel_old_buy_orders
    opnords = info.open_orders(secret.WALLET_ADDRESS[1])
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/hyperliquid/info.py", line 152, in open_orders
    return self.post("/info", {"type": "openOrders", "user": address, "dex": dex})
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/hyperliquid/api.py", line 23, in post
    response = self.session.post(url, json=payload, timeout=self.timeout)
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/adapters.py", line 659, in send
    raise ConnectionError(err, request=request)
    requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

  5. mifth commented on Apr 28, 2026

    @mifth

    Weird. It seems it's something with response = self.session.post().

    I took a test but it worked well. I didn't get the error above. I tested TESTNET_API_URL.

    from eth_account import Account
    from hyperliquid.exchange import Exchange, LocalAccount
    from hyperliquid.info import Info
    from hyperliquid.utils import signing
    from hyperliquid.utils import constants
    
    agent_account: LocalAccount = Account.from_key("0x13e9b3741b86d2eb0aa442b37362XXXXXXXXXXXXXXXZZZZZZZZZZZZZ")
    
    exchange: Exchange = Exchange(agent_account, 
                                  base_url=constants.TESTNET_API_URL, 
                                  account_address=agent_account.address,
                                  perp_dexs=["", "xyz"],)
    
    # sleep 3 mins
    time.sleep(180)
    
    open_orders = exchange.info.open_orders(agent_account.address)
    print(open_orders)
    
  6. 4stah commented on Apr 28, 2026

    @4stah
    Author

    Well, here is example that crashes (8/10 times on the second print):
    #---
    from hyperliquid.info import Info
    import time

    info = Info(constants.MAINNET_API_URL,skip_ws=False)

    def test():
    print(info.open_orders(secret.WALLET_ADDRESS[1]) )
    time.sleep (240)
    print(info.open_orders(secret.WALLET_ADDRESS[1]) )
    return

    test()
    #--- result:
    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
    conn,
    ...<10 lines>...
    **response_kw,
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 534, in _make_request
    response = conn.getresponse()
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connection.py", line 565, in getresponse
    httplib_response = super().getresponse()
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1430, in getresponse
    response.begin()
    ~~~~~~~~~~~~~~^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 331, in begin
    version, status, reason = self._read_status()
    ~~~~~~~~~~~~~~~~~^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 292, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/socket.py", line 719, in readinto
    return self._sock.recv_into(b)
    ~~~~~~~~~~~~~~~~~~~~^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1304, in recv_into
    return self.read(nbytes, buffer)
    ~~~~~~~~~^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1138, in read
    return self._sslobj.read(len, buffer)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
    ConnectionResetError: [Errno 54] Connection reset by peer

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/adapters.py", line 644, in send
    resp = conn.urlopen(
    method=request.method,
    ...<9 lines>...
    chunked=chunked,
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 841, in urlopen
    retries = retries.increment(
    method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/util/retry.py", line 474, in increment
    raise reraise(type(error), error, _stacktrace)
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/util/util.py", line 38, in reraise
    raise value.with_traceback(tb)
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    response = self._make_request(
    conn,
    ...<10 lines>...
    **response_kw,
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connectionpool.py", line 534, in _make_request
    response = conn.getresponse()
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/urllib3/connection.py", line 565, in getresponse
    httplib_response = super().getresponse()
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 1430, in getresponse
    response.begin()
    ~~~~~~~~~~~~~~^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 331, in begin
    version, status, reason = self._read_status()
    ~~~~~~~~~~~~~~~~~^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/http/client.py", line 292, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/socket.py", line 719, in readinto
    return self._sock.recv_into(b)
    ~~~~~~~~~~~~~~~~~~~~^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1304, in recv_into
    return self.read(nbytes, buffer)
    ~~~~~~~~~^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ssl.py", line 1138, in read
    return self._sslobj.read(len, buffer)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
    urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/Volumes/Cryptovc/scripts/./h.py", line 367, in
    test()
    ~~~~^^
    File "/Volumes/Cryptovc/scripts/./h.py", line 59, in test
    print(info.open_orders(secret.WALLET_ADDRESS[1]) )
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/hyperliquid/info.py", line 152, in open_orders
    return self.post("/info", {"type": "openOrders", "user": address, "dex": dex})
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/hyperliquid/api.py", line 23, in post
    response = self.session.post(url, json=payload, timeout=self.timeout)
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/requests/adapters.py", line 659, in send
    raise ConnectionError(err, request=request)
    requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer'))

  7. mifth commented on Apr 28, 2026

    @mifth

    @4stah will it be crashing if you set skip_ws=True?

  8. mifth commented on Apr 28, 2026

    @mifth

    I confirm that your code makes a crash on the info. Both with skip_ws=True and with skip_ws=False. I would set this issue as HIGH PRIORITY!

    Tested code:

    from hyperliquid.info import Info
    import time
    from hyperliquid.utils import constants
    
    info = Info(constants.MAINNET_API_URL,skip_ws=True)
    
    def test():
        print(info.open_orders("0x53A43e7764213870564409bAXXXXXXXX") )
        time.sleep (240)
        print(info.open_orders("0x53A43e7764213870564409XXXXXXXXXX") )
        return
    
    test()
    test()
    test()
    test()
    test()
    

    Log:

    []
    Traceback (most recent call last):
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
        response = self._make_request(
                   ^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\connectionpool.py", line 534, in _make_request
        response = conn.getresponse()
                   ^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\connection.py", line 571, in getresponse
        httplib_response = super().getresponse()
                           ^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\http\client.py", line 1430, in getresponse
        response.begin()
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\http\client.py", line 331, in begin
        version, status, reason = self._read_status()
                                  ^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\http\client.py", line 300, in _read_status
        raise RemoteDisconnected("Remote end closed connection without"
    http.client.RemoteDisconnected: Remote end closed connection without response
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\requests\adapters.py", line 644, in send
        resp = conn.urlopen(
               ^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\connectionpool.py", line 841, in urlopen
        retries = retries.increment(
                  ^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\util\retry.py", line 474, in increment
        raise reraise(type(error), error, _stacktrace)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\util\util.py", line 38, in reraise
        raise value.with_traceback(tb)
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
        response = self._make_request(
                   ^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\connectionpool.py", line 534, in _make_request
        response = conn.getresponse()
                   ^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\urllib3\connection.py", line 571, in getresponse
        httplib_response = super().getresponse()
                           ^^^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\http\client.py", line 1430, in getresponse
        response.begin()
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\http\client.py", line 331, in begin
        version, status, reason = self._read_status()
                                  ^^^^^^^^^^^^^^^^^^^
      File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\http\client.py", line 300, in _read_status
        raise RemoteDisconnected("Remote end closed connection without"
    urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "d:\Projects\Crpt\TBots\BotEngine2\BotEngine2\Test\test.py", line 13, in <module>
        test()
      File "d:\Projects\Crpt\TBots\BotEngine2\BotEngine2\Test\test.py", line 10, in test
        print(info.open_orders("0x53A43e7764213870564409bA3dfEE4996723Df43") )
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\hyperliquid\info.py", line 171, in open_orders
        return self.post("/info", {"type": "openOrders", "user": address, "dex": dex})
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\hyperliquid\api.py", line 23, in post
        response = self.session.post(url, json=payload, timeout=self.timeout)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\requests\sessions.py", line 637, in post
        return self.request("POST", url, data=data, json=json, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\requests\sessions.py", line 589, in request
        resp = self.send(prep, **send_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\requests\sessions.py", line 703, in send
        r = adapter.send(request, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "D:\Projects\Crpt\TBots\BotEngine2\.venv\Lib\site-packages\requests\adapters.py", line 659, in send
        raise ConnectionError(err, request=request)
    requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
    
  9. mifth commented on Apr 28, 2026

    @mifth

    A workaround fix. But it must be fixed by Hyperliquid devs properly!:

    Variant 1:

    from hyperliquid.info import Info
    from http.client import RemoteDisconnected
    import time
    from hyperliquid.utils import constants
    
    from requests.adapters import HTTPAdapter
    from urllib3.exceptions import ProtocolError
    from urllib3.util.retry import Retry
    
    
    def patch_hyperliquid_session(session):
        class HyperliquidSessionRetry(Retry):
            def _is_read_error(self, err: Exception) -> bool:
                if not isinstance(err, ProtocolError):
                    return False
    
                return any(isinstance(arg, RemoteDisconnected) for arg in err.args)
    
        retry = HyperliquidSessionRetry(
            total=1,
            connect=0,
            read=1,
            other=0,
            status=0,
            backoff_factor=0,
            status_forcelist=[],
            allowed_methods=["HEAD", "GET", "OPTIONS", "POST"],
        )
        adapter = HTTPAdapter(max_retries=retry)
        session.mount("http://", adapter)
        session.mount("https://", adapter)
    
    
    def test(info: Info):
        print(info.open_orders("0x53A43e776421387xxxxxxxxxxxxxxxxxxxxxx") )
        time.sleep (240)
        print(info.open_orders("0x53A43e776421387xxxxxxxxxxxxxxxxxxxxxxx") )
        return
    
    info: Info = Info(constants.MAINNET_API_URL,skip_ws=True)
    patch_hyperliquid_session(info.session)  # Apply retry logic to the session
    
    test(info)
    test(info)
    test(info)
    test(info)
    test(info)
    

    Variant 2:

    from hyperliquid.info import Info
    import time
    from hyperliquid.utils import constants
    
    
    from requests.adapters import HTTPAdapter
    from urllib3.util.retry import Retry
    
    
    def test(info: Info):
        print(info.open_orders("0x53A43e776421387056xxxxxxxxxxxxxxxxx") )
        time.sleep (240)
        print(info.open_orders("0x53A43e77642138705xxxxxxxxxxxxxxxxxxxxx") )
        return
    
    info: Info = Info(constants.MAINNET_API_URL,skip_ws=True)
    info.session.headers.update({'Connection': 'close'})  # Fix "Connection: keep-alive" issue
    
    test(info)
    test(info)
    test(info)
    test(info)
    test(info)
    
  10. 4stah commented on Apr 28, 2026

    @4stah
    Author

    thx for confirmation.
    for now, if you want avoid crash and you don't know if 200s idle passed away - the only resolution is to catch exception and create new instance. but it's a little dirty especially if parrallel you are using Websockets

  11. mifth commented on Apr 28, 2026

    @mifth

    That's pain making a new info instance every time. (((
    the Info object initializes so long (it gets some heavy data from api).

    It looks like the SDK is made by newbies. ))) It has many issues.

  12. 4stah commented on Apr 28, 2026

    @4stah
    Author

    session.headers.update({'Connection': 'close'}) - brilliant - thx. it's working! As I understand - every time new TCP connection but way faster than recreate Info object....

  13. mifth commented on May 8, 2026

    @mifth

    Just a heads up. I've updated the Variant 1. It was battle tested and worked well for me.
    #293 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions