From 646060da79249f9ef213c09d188284c7fbcd265c Mon Sep 17 00:00:00 2001 From: Tyyare <65265263+codeform670@users.noreply.github.com> Date: Tue, 25 Nov 2025 02:22:26 +0300 Subject: [PATCH] Update data_stream_listen_key.py --- aster/rest_api/data_stream_listen_key.py | 32 ++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/aster/rest_api/data_stream_listen_key.py b/aster/rest_api/data_stream_listen_key.py index 3cbfed2..31ddec2 100644 --- a/aster/rest_api/data_stream_listen_key.py +++ b/aster/rest_api/data_stream_listen_key.py @@ -1,46 +1,52 @@ +import aster.lib.utils from aster.lib.utils import check_required_parameter def new_listen_key(self): """ - | - | **Create a ListenKey (USER_STREAM)** + Creates a new ListenKey (USER_STREAM). :API endpoint: ``POST /fapi/v1/listenKey`` :API doc: https://github.com/asterdex/api-docs/blob/master/aster-finance-api.md#start-user-data-stream-user_stream - | + :returns: API response containing the new listenKey. """ url_path = "/fapi/v1/listenKey" + # The POST request is typically empty for creating a new key. return self.send_request("POST", url_path) def renew_listen_key(self, listenKey: str): """ - | - | **Ping/Keep-alive a ListenKey (USER_STREAM)** + Pings the server to keep a ListenKey alive (USER_STREAM). :API endpoint: ``PUT /fapi/v1/listenKey`` :API doc: https://github.com/asterdex/api-docs/blob/master/-finance-api.md#keepalive-user-data-stream-user_stream - | + :param listenKey: The ListenKey to renew. + :returns: API response indicating success. """ + # Ensure the key is provided before making the request check_required_parameter(listenKey, "listenKey") + url_path = "/fapi/v1/listenKey" + # The PUT request requires the listenKey as a parameter. return self.send_request("PUT", url_path, {"listenKey": listenKey}) def close_listen_key(self, listenKey: str): """ - | - | **Close a ListenKey (USER_STREAM)** + Closes and invalidates a ListenKey (USER_STREAM). :API endpoint: ``DELETE /fapi/v1/listenKey`` :API doc: https://github.com/asterdex/api-docs/blob/master/aster-finance-api.md#close-user-data-stream-user_stream - | + :param listenKey: The ListenKey to close. + :returns: API response indicating success. """ - + + # [FIX] Added parameter check for consistency and robustness + check_required_parameter(listenKey, "listenKey") + url_path = "/fapi/v1/listenKey" - return self.send_request("DELETE", url_path) - - + # [FIX] The DELETE request requires the listenKey to specify which stream to close. + return self.send_request("DELETE", url_path, {"listenKey": listenKey})