Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions aster/rest_api/data_stream_listen_key.py
Original file line number Diff line number Diff line change
@@ -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})