"""
Binance Margin Trading REST API

OpenAPI Specification for the Binance Margin Trading REST API
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

from typing import Union
from requests import Session
from binance_common.configuration import ConfigurationRestAPI
from binance_common.errors import RequiredError
from binance_common.models import ApiResponse
from binance_common.signature import Signers
from binance_common.utils import send_request


from ..models import StartUserDataStreamResponse


class RiskDataStreamApi:
    """API Client for RiskDataStreamApi endpoints."""

    def __init__(
        self,
        configuration: ConfigurationRestAPI = None,
        session: Session = None,
        signer: Signers = None,
    ) -> None:
        self._configuration = configuration
        self._session = session
        self._signer = signer

    def close_user_data_stream(
        self,
    ) -> ApiResponse[None]:
        """
                Close User Data Stream (USER_STREAM)
                DELETE /sapi/v1/margin/listen-key
                https://developers.binance.com/docs/margin_trading/risk-data-stream/Close-User-Data-Stream

                Close out a user data stream.

        Weight: 3000

                Args:

                Returns:
                    ApiResponse[None]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = None
        payload = None

        return send_request(
            self._session,
            self._configuration,
            method="DELETE",
            path="/sapi/v1/margin/listen-key",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
        )

    def keepalive_user_data_stream(
        self,
        listen_key: Union[str, None],
    ) -> ApiResponse[None]:
        """
                Keepalive User Data Stream (USER_STREAM)
                PUT /sapi/v1/margin/listen-key
                https://developers.binance.com/docs/margin_trading/risk-data-stream/Keepalive-User-Data-Stream

                Keepalive a user data stream to prevent a time out.

        Weight: 1

                Args:
                    listen_key (Union[str, None]):

                Returns:
                    ApiResponse[None]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        if listen_key is None:
            raise RequiredError(
                field="listen_key",
                error_message="Missing required parameter 'listen_key'",
            )

        body = {}
        payload = {"listen_key": listen_key}

        return send_request(
            self._session,
            self._configuration,
            method="PUT",
            path="/sapi/v1/margin/listen-key",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
        )

    def start_user_data_stream(
        self,
    ) -> ApiResponse[StartUserDataStreamResponse]:
        """
                Start User Data Stream (USER_STREAM)
                POST /sapi/v1/margin/listen-key
                https://developers.binance.com/docs/margin_trading/risk-data-stream/Start-User-Data-Stream

                Start a new user data stream.

        Weight: 1

                Args:

                Returns:
                    ApiResponse[StartUserDataStreamResponse]

                Raises:
                    RequiredError: If a required parameter is missing.

        """

        body = None
        payload = None

        return send_request(
            self._session,
            self._configuration,
            method="POST",
            path="/sapi/v1/margin/listen-key",
            payload=payload,
            body=body,
            time_unit=self._configuration.time_unit,
            response_model=StartUserDataStreamResponse,
        )
