"""
Binance Derivatives Trading USDS Futures REST API

OpenAPI Specification for the Binance Derivatives Trading USDS Futures 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.
"""

import json
import pytest
import requests

from unittest.mock import MagicMock, patch
from urllib.parse import parse_qs

from binance_common.configuration import ConfigurationRestAPI
from binance_common.errors import RequiredError
from binance_common.utils import normalize_query_values, is_one_of_model, snake_to_camel

from binance_sdk_derivatives_trading_usds_futures.rest_api.api import AccountApi
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    AccountInformationV2Response,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    AccountInformationV3Response,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    FuturesAccountBalanceV2Response,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    FuturesAccountBalanceV3Response,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    FuturesAccountConfigurationResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    FuturesTradingQuantitativeRulesIndicatorsResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetBnbBurnStatusResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetCurrentMultiAssetsModeResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetCurrentPositionModeResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetDownloadIdForFuturesOrderHistoryResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetDownloadIdForFuturesTradeHistoryResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetDownloadIdForFuturesTransactionHistoryResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetFuturesOrderHistoryDownloadLinkByIdResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetFuturesTradeDownloadLinkByIdResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetFuturesTransactionHistoryDownloadLinkByIdResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    GetIncomeHistoryResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    NotionalAndLeverageBracketsResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    QueryUserRateLimitResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    SymbolConfigurationResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    ToggleBnbBurnOnFuturesTradeResponse,
)
from binance_sdk_derivatives_trading_usds_futures.rest_api.models import (
    UserCommissionRateResponse,
)


class TestAccountApi:
    @pytest.fixture(autouse=True)
    def setup_client(self):
        """Setup a client instance with mocked session before each test method."""
        self.mock_session = MagicMock(spec=requests.Session)
        config = ConfigurationRestAPI(
            api_key="test-api-key",
            api_secret="test-api-secret",
        )
        self.client = AccountApi(configuration=config, session=self.mock_session)

    def set_mock_response(self, data: dict = {}, status_code=200, headers=None):
        """Helper method to setup mock response for the client's session request."""
        if headers is None:
            headers = {}

        mock_response = MagicMock()
        mock_response.status_code = status_code
        mock_response.json.return_value = data
        mock_response.text = json.dumps(data)
        mock_response.headers = headers

        self.mock_session.request.return_value = mock_response

    @patch("binance_common.utils.get_signature")
    def test_account_information_v2_success(self, mock_get_signature):
        """Test account_information_v2() successfully with required parameters only."""

        expected_response = {
            "feeTier": 0,
            "feeBurn": True,
            "canDeposit": True,
            "canWithdraw": True,
            "updateTime": 0,
            "multiAssetsMargin": True,
            "tradeGroupId": -1,
            "totalInitialMargin": "0.00000000",
            "totalMaintMargin": "0.00000000",
            "totalWalletBalance": "126.72469206",
            "totalUnrealizedProfit": "0.00000000",
            "totalMarginBalance": "126.72469206",
            "totalPositionInitialMargin": "0.00000000",
            "totalOpenOrderInitialMargin": "0.00000000",
            "totalCrossWalletBalance": "126.72469206",
            "totalCrossUnPnl": "0.00000000",
            "availableBalance": "126.72469206",
            "maxWithdrawAmount": "126.72469206",
            "assets": [
                {
                    "asset": "USDT",
                    "walletBalance": "23.72469206",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "23.72469206",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "23.72469206",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "23.72469206",
                    "maxWithdrawAmount": "23.72469206",
                    "marginAvailable": True,
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "BUSD",
                    "walletBalance": "103.12345678",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "103.12345678",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "103.12345678",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "103.12345678",
                    "maxWithdrawAmount": "103.12345678",
                    "marginAvailable": True,
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "USDT",
                    "walletBalance": "23.72469206",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "23.72469206",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "23.72469206",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "23.72469206",
                    "marginAvailable": True,
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "BUSD",
                    "walletBalance": "103.12345678",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "103.12345678",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "103.12345678",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "103.12345678",
                    "marginAvailable": True,
                    "updateTime": 1625474304765,
                },
            ],
            "positions": [
                {
                    "symbol": "BTCUSDT",
                    "initialMargin": "0",
                    "maintMargin": "0",
                    "unrealizedProfit": "0.00000000",
                    "positionInitialMargin": "0",
                    "openOrderInitialMargin": "0",
                    "leverage": "100",
                    "isolated": True,
                    "entryPrice": "0.00000",
                    "maxNotional": "250000",
                    "bidNotional": "0",
                    "askNotional": "0",
                    "positionSide": "BOTH",
                    "positionAmt": "0",
                    "updateTime": 0,
                },
                {
                    "symbol": "BTCUSDT",
                    "initialMargin": "0",
                    "maintMargin": "0",
                    "unrealizedProfit": "0.00000000",
                    "positionInitialMargin": "0",
                    "openOrderInitialMargin": "0",
                    "leverage": "100",
                    "isolated": True,
                    "entryPrice": "0.00000",
                    "maxNotional": "250000",
                    "bidNotional": "0",
                    "askNotional": "0",
                    "positionSide": "BOTH",
                    "positionAmt": "0",
                    "updateTime": 0,
                },
            ],
            "canTrade": True,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.account_information_v2()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/fapi/v2/account" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(AccountInformationV2Response)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(AccountInformationV2Response, "from_dict"):
            expected = AccountInformationV2Response.from_dict(expected_response)
        else:
            expected = AccountInformationV2Response.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_account_information_v2_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test account_information_v2() successfully with optional parameters."""

        params = {"recv_window": 5000}

        expected_response = {
            "feeTier": 0,
            "feeBurn": True,
            "canDeposit": True,
            "canWithdraw": True,
            "updateTime": 0,
            "multiAssetsMargin": True,
            "tradeGroupId": -1,
            "totalInitialMargin": "0.00000000",
            "totalMaintMargin": "0.00000000",
            "totalWalletBalance": "126.72469206",
            "totalUnrealizedProfit": "0.00000000",
            "totalMarginBalance": "126.72469206",
            "totalPositionInitialMargin": "0.00000000",
            "totalOpenOrderInitialMargin": "0.00000000",
            "totalCrossWalletBalance": "126.72469206",
            "totalCrossUnPnl": "0.00000000",
            "availableBalance": "126.72469206",
            "maxWithdrawAmount": "126.72469206",
            "assets": [
                {
                    "asset": "USDT",
                    "walletBalance": "23.72469206",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "23.72469206",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "23.72469206",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "23.72469206",
                    "maxWithdrawAmount": "23.72469206",
                    "marginAvailable": True,
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "BUSD",
                    "walletBalance": "103.12345678",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "103.12345678",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "103.12345678",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "103.12345678",
                    "maxWithdrawAmount": "103.12345678",
                    "marginAvailable": True,
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "USDT",
                    "walletBalance": "23.72469206",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "23.72469206",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "23.72469206",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "23.72469206",
                    "marginAvailable": True,
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "BUSD",
                    "walletBalance": "103.12345678",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "103.12345678",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "103.12345678",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "103.12345678",
                    "marginAvailable": True,
                    "updateTime": 1625474304765,
                },
            ],
            "positions": [
                {
                    "symbol": "BTCUSDT",
                    "initialMargin": "0",
                    "maintMargin": "0",
                    "unrealizedProfit": "0.00000000",
                    "positionInitialMargin": "0",
                    "openOrderInitialMargin": "0",
                    "leverage": "100",
                    "isolated": True,
                    "entryPrice": "0.00000",
                    "maxNotional": "250000",
                    "bidNotional": "0",
                    "askNotional": "0",
                    "positionSide": "BOTH",
                    "positionAmt": "0",
                    "updateTime": 0,
                },
                {
                    "symbol": "BTCUSDT",
                    "initialMargin": "0",
                    "maintMargin": "0",
                    "unrealizedProfit": "0.00000000",
                    "positionInitialMargin": "0",
                    "openOrderInitialMargin": "0",
                    "leverage": "100",
                    "isolated": True,
                    "entryPrice": "0.00000",
                    "maxNotional": "250000",
                    "bidNotional": "0",
                    "askNotional": "0",
                    "positionSide": "BOTH",
                    "positionAmt": "0",
                    "updateTime": 0,
                },
            ],
            "canTrade": True,
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.account_information_v2(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/fapi/v2/account" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(AccountInformationV2Response)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(AccountInformationV2Response, "from_dict"):
            expected = AccountInformationV2Response.from_dict(expected_response)
        else:
            expected = AccountInformationV2Response.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_account_information_v2_server_error(self):
        """Test that account_information_v2() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.account_information_v2 = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.account_information_v2()

    @patch("binance_common.utils.get_signature")
    def test_account_information_v3_success(self, mock_get_signature):
        """Test account_information_v3() successfully with required parameters only."""

        expected_response = {
            "totalInitialMargin": "0.00000000",
            "totalMaintMargin": "0.00000000",
            "totalWalletBalance": "126.72469206",
            "totalUnrealizedProfit": "0.00000000",
            "totalMarginBalance": "126.72469206",
            "totalPositionInitialMargin": "0.00000000",
            "totalOpenOrderInitialMargin": "0.00000000",
            "totalCrossWalletBalance": "126.72469206",
            "totalCrossUnPnl": "0.00000000",
            "availableBalance": "126.72469206",
            "maxWithdrawAmount": "126.72469206",
            "assets": [
                {
                    "asset": "USDT",
                    "walletBalance": "23.72469206",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "23.72469206",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "23.72469206",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "23.72469206",
                    "maxWithdrawAmount": "23.72469206",
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "USDC",
                    "walletBalance": "103.12345678",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "103.12345678",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "103.12345678",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "103.12345678",
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "USDT",
                    "walletBalance": "23.72469206",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "23.72469206",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "23.72469206",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "23.72469206",
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "BUSD",
                    "walletBalance": "103.12345678",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "103.12345678",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "103.12345678",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "103.12345678",
                    "updateTime": 1625474304765,
                },
            ],
            "positions": [
                {
                    "symbol": "BTCUSDT",
                    "positionSide": "BOTH",
                    "positionAmt": "1.000",
                    "unrealizedProfit": "0.00000000",
                    "isolatedMargin": "0.00000000",
                    "notional": "0",
                    "isolatedWallet": "0",
                    "initialMargin": "0",
                    "maintMargin": "0",
                    "updateTime": 0,
                },
                {
                    "symbol": "BTCUSDT",
                    "positionSide": "BOTH",
                    "positionAmt": "1.000",
                    "unrealizedProfit": "0.00000000",
                    "isolatedMargin": "0.00000000",
                    "notional": "0",
                    "isolatedWallet": "0",
                    "initialMargin": "0",
                    "maintMargin": "0",
                    "updateTime": 0,
                },
            ],
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.account_information_v3()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/fapi/v3/account" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(AccountInformationV3Response)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(AccountInformationV3Response, "from_dict"):
            expected = AccountInformationV3Response.from_dict(expected_response)
        else:
            expected = AccountInformationV3Response.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    @patch("binance_common.utils.get_signature")
    def test_account_information_v3_success_with_optional_params(
        self, mock_get_signature
    ):
        """Test account_information_v3() successfully with optional parameters."""

        params = {"recv_window": 5000}

        expected_response = {
            "totalInitialMargin": "0.00000000",
            "totalMaintMargin": "0.00000000",
            "totalWalletBalance": "126.72469206",
            "totalUnrealizedProfit": "0.00000000",
            "totalMarginBalance": "126.72469206",
            "totalPositionInitialMargin": "0.00000000",
            "totalOpenOrderInitialMargin": "0.00000000",
            "totalCrossWalletBalance": "126.72469206",
            "totalCrossUnPnl": "0.00000000",
            "availableBalance": "126.72469206",
            "maxWithdrawAmount": "126.72469206",
            "assets": [
                {
                    "asset": "USDT",
                    "walletBalance": "23.72469206",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "23.72469206",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "23.72469206",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "23.72469206",
                    "maxWithdrawAmount": "23.72469206",
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "USDC",
                    "walletBalance": "103.12345678",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "103.12345678",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "103.12345678",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "103.12345678",
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "USDT",
                    "walletBalance": "23.72469206",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "23.72469206",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "23.72469206",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "23.72469206",
                    "updateTime": 1625474304765,
                },
                {
                    "asset": "BUSD",
                    "walletBalance": "103.12345678",
                    "unrealizedProfit": "0.00000000",
                    "marginBalance": "103.12345678",
                    "maintMargin": "0.00000000",
                    "initialMargin": "0.00000000",
                    "positionInitialMargin": "0.00000000",
                    "openOrderInitialMargin": "0.00000000",
                    "crossWalletBalance": "103.12345678",
                    "crossUnPnl": "0.00000000",
                    "availableBalance": "126.72469206",
                    "maxWithdrawAmount": "103.12345678",
                    "updateTime": 1625474304765,
                },
            ],
            "positions": [
                {
                    "symbol": "BTCUSDT",
                    "positionSide": "BOTH",
                    "positionAmt": "1.000",
                    "unrealizedProfit": "0.00000000",
                    "isolatedMargin": "0.00000000",
                    "notional": "0",
                    "isolatedWallet": "0",
                    "initialMargin": "0",
                    "maintMargin": "0",
                    "updateTime": 0,
                },
                {
                    "symbol": "BTCUSDT",
                    "positionSide": "BOTH",
                    "positionAmt": "1.000",
                    "unrealizedProfit": "0.00000000",
                    "isolatedMargin": "0.00000000",
                    "notional": "0",
                    "isolatedWallet": "0",
                    "initialMargin": "0",
                    "maintMargin": "0",
                    "updateTime": 0,
                },
            ],
        }
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.account_information_v3(**params)

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/fapi/v3/account" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        self.mock_session.request.assert_called_once()
        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(AccountInformationV3Response)

        if is_list and not is_flat_list:
            expected = expected_response
        elif is_oneof or is_list or hasattr(AccountInformationV3Response, "from_dict"):
            expected = AccountInformationV3Response.from_dict(expected_response)
        else:
            expected = AccountInformationV3Response.model_validate_json(
                json.dumps(expected_response)
            )

        assert response.data() == expected

    def test_account_information_v3_server_error(self):
        """Test that account_information_v3() raises an error when the server returns an error."""

        mock_error = Exception("ResponseError")
        self.client.account_information_v3 = MagicMock(side_effect=mock_error)

        with pytest.raises(Exception, match="ResponseError"):
            self.client.account_information_v3()

    @patch("binance_common.utils.get_signature")
    def test_futures_account_balance_v2_success(self, mock_get_signature):
        """Test futures_account_balance_v2() successfully with required parameters only."""

        expected_response = [
            {
                "accountAlias": "SgsR",
                "asset": "USDT",
                "balance": "122607.35137903",
                "crossWalletBalance": "23.72469206",
                "crossUnPnl": "0.00000000",
                "availableBalance": "23.72469206",
                "maxWithdrawAmount": "23.72469206",
                "marginAvailable": True,
                "updateTime": 1617939110373,
            }
        ]
        mock_get_signature.return_value = "mocked_signature"
        self.set_mock_response(expected_response)

        response = self.client.futures_account_balance_v2()

        actual_call_args = self.mock_session.request.call_args
        request_kwargs = actual_call_args.kwargs

        self.mock_session.request.assert_called_once()
        mock_get_signature.assert_called_once()

        assert "url" in request_kwargs
        assert "signature" in parse_qs(request_kwargs["params"])
        assert "/fapi/v2/balance" in request_kwargs["url"]
        assert request_kwargs["method"] == "GET"

        assert response is not None
        is_list = isinstance(expected_response, list)
        is_flat_list = (
            is_list and not isinstance(expected_response[0], list) if is_list else False
        )
        is_oneof = is_one_of_model(FuturesAccountBalanceV2Response)

        if is_list and not is_flat_list:
            expected = expected_response
        elif (
            is_oneof or is_list or hasattr(FuturesAccountBalanceV2Response, "from_dict")
        ):
            expected = FuturesAccountBalanceV2Response.from_dict(expected_response)
        else:
            expected = FuturesAccountBalanceV2Response.model_validate_json(
                json.dumps(expected_response)
            )

