<?php

/**
 * AccountApi
 * PHP version 8.1.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * 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: https://openapi-generator.tech
 * Generator version: 7.12.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace Binance\Client\MarginTrading\Api;

use Binance\Client\MarginTrading\Model\AdjustCrossMarginMaxLeverageRequest;
use Binance\Client\MarginTrading\Model\AdjustCrossMarginMaxLeverageResponse;
use Binance\Client\MarginTrading\Model\DisableIsolatedMarginAccountResponse;
use Binance\Client\MarginTrading\Model\EnableIsolatedMarginAccountRequest;
use Binance\Client\MarginTrading\Model\EnableIsolatedMarginAccountResponse;
use Binance\Client\MarginTrading\Model\GetBnbBurnStatusResponse;
use Binance\Client\MarginTrading\Model\GetSummaryOfMarginAccountResponse;
use Binance\Client\MarginTrading\Model\QueryCrossIsolatedMarginCapitalFlowResponse;
use Binance\Client\MarginTrading\Model\QueryCrossMarginAccountDetailsResponse;
use Binance\Client\MarginTrading\Model\QueryCrossMarginFeeDataResponse;
use Binance\Client\MarginTrading\Model\QueryEnabledIsolatedMarginAccountLimitResponse;
use Binance\Client\MarginTrading\Model\QueryIsolatedMarginAccountInfoResponse;
use Binance\Client\MarginTrading\Model\QueryIsolatedMarginFeeDataResponse;
use Binance\Common\ApiException;
use Binance\Common\Auth\SignerFactory;
use Binance\Common\Auth\SignerInterface;
use Binance\Common\CommonUtils;
use Binance\Common\Configuration\ClientConfiguration;
use Binance\Common\Dtos\ApiResponse;
use Binance\Common\HeaderSelector;
use Binance\Common\HttpClient;
use Binance\Common\ObjectSerializer;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ConnectException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\MultipartStream;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Utils;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * AccountApi Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */
class AccountApi
{
    /** @var string[] */
    public const contentTypes = [
        'adjustCrossMarginMaxLeverage' => ['application/x-www-form-urlencoded'],
        'disableIsolatedMarginAccount' => ['application/x-www-form-urlencoded'],
        'enableIsolatedMarginAccount' => ['application/x-www-form-urlencoded'],
        'getBnbBurnStatus' => ['application/x-www-form-urlencoded'],
        'getSummaryOfMarginAccount' => ['application/x-www-form-urlencoded'],
        'queryCrossIsolatedMarginCapitalFlow' => ['application/x-www-form-urlencoded'],
        'queryCrossMarginAccountDetails' => ['application/x-www-form-urlencoded'],
        'queryCrossMarginFeeData' => ['application/x-www-form-urlencoded'],
        'queryEnabledIsolatedMarginAccountLimit' => ['application/x-www-form-urlencoded'],
        'queryIsolatedMarginAccountInfo' => ['application/x-www-form-urlencoded'],
        'queryIsolatedMarginFeeData' => ['application/x-www-form-urlencoded'],
    ];
    private const HAS_TIME_UNIT = false;

    /**
     * @var ClientInterface
     */
    protected $client;

    /**
     * @var HeaderSelector
     */
    protected $headerSelector;

    /**
     * Summary of clientConfig.
     *
     * @var ClientConfiguration
     */
    protected $clientConfig;

    /**
     * Summary of signer.
     *
     * @var SignerInterface
     */
    protected $signer;

    /**
     * userAgent for HTTP requests.
     *
     * @var string
     */
    private $userAgent;

    public function __construct(
        ?ClientConfiguration $clientConfig = new ClientConfiguration(),
        ?ClientInterface $client = null,
        ?HeaderSelector $selector = null,
    ) {
        $this->clientConfig = $clientConfig;
        $this->client = $client ?: new HttpClient($clientConfig);
        $this->headerSelector = $selector ?: new HeaderSelector();
        if (!empty($clientConfig->getSignatureConfiguration())) {
            $this->signer = SignerFactory::getSigner($clientConfig->getSignatureConfiguration());
        }
        $this->userAgent = CommonUtils::getUserAgent('margin-trading');
    }

    /**
     * Operation adjustCrossMarginMaxLeverage.
     *
     * Adjust cross margin max leverage (USER_DATA)
     *
     * @param AdjustCrossMarginMaxLeverageRequest $adjustCrossMarginMaxLeverageRequest adjustCrossMarginMaxLeverageRequest (required)
     *
     * @return ApiResponse<AdjustCrossMarginMaxLeverageResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function adjustCrossMarginMaxLeverage($adjustCrossMarginMaxLeverageRequest): ApiResponse
    {
        return $this->adjustCrossMarginMaxLeverageWithHttpInfo($adjustCrossMarginMaxLeverageRequest);
    }

    /**
     * Operation adjustCrossMarginMaxLeverageWithHttpInfo.
     *
     * Adjust cross margin max leverage (USER_DATA)
     *
     * @param AdjustCrossMarginMaxLeverageRequest $adjustCrossMarginMaxLeverageRequest (required)
     *
     * @return ApiResponse<AdjustCrossMarginMaxLeverageResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function adjustCrossMarginMaxLeverageWithHttpInfo($adjustCrossMarginMaxLeverageRequest): ApiResponse
    {
        $request = $this->adjustCrossMarginMaxLeverageRequest($adjustCrossMarginMaxLeverageRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\AdjustCrossMarginMaxLeverageResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\AdjustCrossMarginMaxLeverageResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\AdjustCrossMarginMaxLeverageResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'adjustCrossMarginMaxLeverage'.
     *
     * @param AdjustCrossMarginMaxLeverageRequest $adjustCrossMarginMaxLeverageRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function adjustCrossMarginMaxLeverageRequest($adjustCrossMarginMaxLeverageRequest)
    {
        $contentType = self::contentTypes['adjustCrossMarginMaxLeverage'][0];

        // verify the required parameter 'adjustCrossMarginMaxLeverageRequest' is set
        if (null === $adjustCrossMarginMaxLeverageRequest || (is_array($adjustCrossMarginMaxLeverageRequest) && 0 === count($adjustCrossMarginMaxLeverageRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $adjustCrossMarginMaxLeverageRequest when calling adjustCrossMarginMaxLeverage'
            );
        }

        $resourcePath = '/sapi/v1/margin/max-leverage';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $adjustCrossMarginMaxLeverageRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $adjustCrossMarginMaxLeverageRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $adjustCrossMarginMaxLeverageRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($adjustCrossMarginMaxLeverageRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($adjustCrossMarginMaxLeverageRequest));
            } else {
                $httpBody = $adjustCrossMarginMaxLeverageRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation disableIsolatedMarginAccount.
     *
     * Disable Isolated Margin Account (TRADE)
     *
     * @param string   $symbol     symbol (required)
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<DisableIsolatedMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function disableIsolatedMarginAccount($symbol, $recvWindow = null): ApiResponse
    {
        return $this->disableIsolatedMarginAccountWithHttpInfo($symbol, $recvWindow);
    }

    /**
     * Operation disableIsolatedMarginAccountWithHttpInfo.
     *
     * Disable Isolated Margin Account (TRADE)
     *
     * @param string   $symbol     (required)
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<DisableIsolatedMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function disableIsolatedMarginAccountWithHttpInfo($symbol, $recvWindow = null): ApiResponse
    {
        $request = $this->disableIsolatedMarginAccountRequest($symbol, $recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\DisableIsolatedMarginAccountResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\DisableIsolatedMarginAccountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\DisableIsolatedMarginAccountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'disableIsolatedMarginAccount'.
     *
     * @param string   $symbol     (required)
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function disableIsolatedMarginAccountRequest($symbol, $recvWindow = null)
    {
        $contentType = self::contentTypes['disableIsolatedMarginAccount'][0];

        // verify the required parameter 'symbol' is set
        if (null === $symbol || (is_array($symbol) && 0 === count($symbol))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $symbol when calling disableIsolatedMarginAccount'
            );
        }

        $resourcePath = '/sapi/v1/margin/isolated/account';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $symbol,
            'symbol', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'DELETE',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation enableIsolatedMarginAccount.
     *
     * Enable Isolated Margin Account (TRADE)
     *
     * @param EnableIsolatedMarginAccountRequest $enableIsolatedMarginAccountRequest enableIsolatedMarginAccountRequest (required)
     *
     * @return ApiResponse<EnableIsolatedMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function enableIsolatedMarginAccount($enableIsolatedMarginAccountRequest): ApiResponse
    {
        return $this->enableIsolatedMarginAccountWithHttpInfo($enableIsolatedMarginAccountRequest);
    }

    /**
     * Operation enableIsolatedMarginAccountWithHttpInfo.
     *
     * Enable Isolated Margin Account (TRADE)
     *
     * @param EnableIsolatedMarginAccountRequest $enableIsolatedMarginAccountRequest (required)
     *
     * @return ApiResponse<EnableIsolatedMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function enableIsolatedMarginAccountWithHttpInfo($enableIsolatedMarginAccountRequest): ApiResponse
    {
        $request = $this->enableIsolatedMarginAccountRequest($enableIsolatedMarginAccountRequest);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\EnableIsolatedMarginAccountResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\EnableIsolatedMarginAccountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\EnableIsolatedMarginAccountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'enableIsolatedMarginAccount'.
     *
     * @param EnableIsolatedMarginAccountRequest $enableIsolatedMarginAccountRequest (required)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function enableIsolatedMarginAccountRequest($enableIsolatedMarginAccountRequest)
    {
        $contentType = self::contentTypes['enableIsolatedMarginAccount'][0];

        // verify the required parameter 'enableIsolatedMarginAccountRequest' is set
        if (null === $enableIsolatedMarginAccountRequest || (is_array($enableIsolatedMarginAccountRequest) && 0 === count($enableIsolatedMarginAccountRequest))) {
            throw new \InvalidArgumentException(
                'Missing the required parameter $enableIsolatedMarginAccountRequest when calling enableIsolatedMarginAccount'
            );
        }

        $resourcePath = '/sapi/v1/margin/isolated/account';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $enableIsolatedMarginAccountRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $enableIsolatedMarginAccountRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $enableIsolatedMarginAccountRequest->{$getter}();
            }
        }

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        // for model (json/xml)
        if (count($formParams) > 0) {
            if ($multipart) {
                $multipartContents = [];
                foreach ($formParams as $formParamName => $formParamValue) {
                    $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue];
                    foreach ($formParamValueItems as $formParamValueItem) {
                        $multipartContents[] = [
                            'name' => $formParamName,
                            'contents' => $formParamValueItem,
                        ];
                    }
                }
                // for HTTP post (form)
                $httpBody = new MultipartStream($multipartContents);
            } elseif (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the form parameters
                $httpBody = Utils::jsonEncode($formParams);
            } else {
                // for HTTP post (form)
                $httpBody = ObjectSerializer::buildQuery($formParams);
            }
        } elseif (isset($enableIsolatedMarginAccountRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($enableIsolatedMarginAccountRequest));
            } else {
                $httpBody = $enableIsolatedMarginAccountRequest;
            }
        }

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'POST',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getBnbBurnStatus.
     *
     * Get BNB Burn Status (USER_DATA)
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<GetBnbBurnStatusResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getBnbBurnStatus($recvWindow = null): ApiResponse
    {
        return $this->getBnbBurnStatusWithHttpInfo($recvWindow);
    }

    /**
     * Operation getBnbBurnStatusWithHttpInfo.
     *
     * Get BNB Burn Status (USER_DATA)
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<GetBnbBurnStatusResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getBnbBurnStatusWithHttpInfo($recvWindow = null): ApiResponse
    {
        $request = $this->getBnbBurnStatusRequest($recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\GetBnbBurnStatusResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\GetBnbBurnStatusResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\GetBnbBurnStatusResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getBnbBurnStatus'.
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getBnbBurnStatusRequest($recvWindow = null)
    {
        $contentType = self::contentTypes['getBnbBurnStatus'][0];

        $resourcePath = '/sapi/v1/bnbBurn';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation getSummaryOfMarginAccount.
     *
     * Get Summary of Margin account (USER_DATA)
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<GetSummaryOfMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfMarginAccount($recvWindow = null): ApiResponse
    {
        return $this->getSummaryOfMarginAccountWithHttpInfo($recvWindow);
    }

    /**
     * Operation getSummaryOfMarginAccountWithHttpInfo.
     *
     * Get Summary of Margin account (USER_DATA)
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<GetSummaryOfMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfMarginAccountWithHttpInfo($recvWindow = null): ApiResponse
    {
        $request = $this->getSummaryOfMarginAccountRequest($recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\GetSummaryOfMarginAccountResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\GetSummaryOfMarginAccountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\GetSummaryOfMarginAccountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getSummaryOfMarginAccount'.
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfMarginAccountRequest($recvWindow = null)
    {
        $contentType = self::contentTypes['getSummaryOfMarginAccount'][0];

        $resourcePath = '/sapi/v1/margin/tradeCoeff';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation queryCrossIsolatedMarginCapitalFlow.
     *
     * Query Cross Isolated Margin Capital Flow (USER_DATA)
     *
     * @param null|string $asset      asset (optional)
     * @param null|string $symbol     isolated margin pair (optional)
     * @param null|string $type       Transfer Type: ROLL_IN, ROLL_OUT (optional)
     * @param null|int    $startTime  只支持查询最近90天的数据 (optional)
     * @param null|int    $endTime    endTime (optional)
     * @param null|int    $fromId     如设置fromId, 将返回id &gt; fromId的数据。否则将返回最新数据 (optional)
     * @param null|int    $limit      Default Value: 500; Max Value: 1000 (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryCrossIsolatedMarginCapitalFlowResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryCrossIsolatedMarginCapitalFlow($asset = null, $symbol = null, $type = null, $startTime = null, $endTime = null, $fromId = null, $limit = null, $recvWindow = null): ApiResponse
    {
        return $this->queryCrossIsolatedMarginCapitalFlowWithHttpInfo($asset, $symbol, $type, $startTime, $endTime, $fromId, $limit, $recvWindow);
    }

    /**
     * Operation queryCrossIsolatedMarginCapitalFlowWithHttpInfo.
     *
     * Query Cross Isolated Margin Capital Flow (USER_DATA)
     *
     * @param null|string $asset      (optional)
     * @param null|string $symbol     isolated margin pair (optional)
     * @param null|string $type       Transfer Type: ROLL_IN, ROLL_OUT (optional)
     * @param null|int    $startTime  只支持查询最近90天的数据 (optional)
     * @param null|int    $endTime    (optional)
     * @param null|int    $fromId     如设置fromId, 将返回id &gt; fromId的数据。否则将返回最新数据 (optional)
     * @param null|int    $limit      Default Value: 500; Max Value: 1000 (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryCrossIsolatedMarginCapitalFlowResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryCrossIsolatedMarginCapitalFlowWithHttpInfo($asset = null, $symbol = null, $type = null, $startTime = null, $endTime = null, $fromId = null, $limit = null, $recvWindow = null): ApiResponse
    {
        $request = $this->queryCrossIsolatedMarginCapitalFlowRequest($asset, $symbol, $type, $startTime, $endTime, $fromId, $limit, $recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\QueryCrossIsolatedMarginCapitalFlowResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\QueryCrossIsolatedMarginCapitalFlowResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\QueryCrossIsolatedMarginCapitalFlowResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryCrossIsolatedMarginCapitalFlow'.
     *
     * @param null|string $asset      (optional)
     * @param null|string $symbol     isolated margin pair (optional)
     * @param null|string $type       Transfer Type: ROLL_IN, ROLL_OUT (optional)
     * @param null|int    $startTime  只支持查询最近90天的数据 (optional)
     * @param null|int    $endTime    (optional)
     * @param null|int    $fromId     如设置fromId, 将返回id &gt; fromId的数据。否则将返回最新数据 (optional)
     * @param null|int    $limit      Default Value: 500; Max Value: 1000 (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryCrossIsolatedMarginCapitalFlowRequest($asset = null, $symbol = null, $type = null, $startTime = null, $endTime = null, $fromId = null, $limit = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryCrossIsolatedMarginCapitalFlow'][0];

        $resourcePath = '/sapi/v1/margin/capital-flow';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $asset,
            'asset', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $symbol,
            'symbol', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $type,
            'type', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $startTime,
            'startTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $endTime,
            'endTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fromId,
            'fromId', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $limit,
            'limit', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation queryCrossMarginAccountDetails.
     *
     * Query Cross Margin Account Details (USER_DATA)
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryCrossMarginAccountDetailsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryCrossMarginAccountDetails($recvWindow = null): ApiResponse
    {
        return $this->queryCrossMarginAccountDetailsWithHttpInfo($recvWindow);
    }

    /**
     * Operation queryCrossMarginAccountDetailsWithHttpInfo.
     *
     * Query Cross Margin Account Details (USER_DATA)
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryCrossMarginAccountDetailsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryCrossMarginAccountDetailsWithHttpInfo($recvWindow = null): ApiResponse
    {
        $request = $this->queryCrossMarginAccountDetailsRequest($recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\QueryCrossMarginAccountDetailsResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\QueryCrossMarginAccountDetailsResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\QueryCrossMarginAccountDetailsResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryCrossMarginAccountDetails'.
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryCrossMarginAccountDetailsRequest($recvWindow = null)
    {
        $contentType = self::contentTypes['queryCrossMarginAccountDetails'][0];

        $resourcePath = '/sapi/v1/margin/account';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation queryCrossMarginFeeData.
     *
     * Query Cross Margin Fee Data (USER_DATA)
     *
     * @param null|int    $vipLevel   User&#39;s current specific margin data will be returned if vipLevel is omitted (optional)
     * @param null|string $coin       coin (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryCrossMarginFeeDataResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryCrossMarginFeeData($vipLevel = null, $coin = null, $recvWindow = null): ApiResponse
    {
        return $this->queryCrossMarginFeeDataWithHttpInfo($vipLevel, $coin, $recvWindow);
    }

    /**
     * Operation queryCrossMarginFeeDataWithHttpInfo.
     *
     * Query Cross Margin Fee Data (USER_DATA)
     *
     * @param null|int    $vipLevel   User&#39;s current specific margin data will be returned if vipLevel is omitted (optional)
     * @param null|string $coin       (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryCrossMarginFeeDataResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryCrossMarginFeeDataWithHttpInfo($vipLevel = null, $coin = null, $recvWindow = null): ApiResponse
    {
        $request = $this->queryCrossMarginFeeDataRequest($vipLevel, $coin, $recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\QueryCrossMarginFeeDataResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\QueryCrossMarginFeeDataResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\QueryCrossMarginFeeDataResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryCrossMarginFeeData'.
     *
     * @param null|int    $vipLevel   User&#39;s current specific margin data will be returned if vipLevel is omitted (optional)
     * @param null|string $coin       (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryCrossMarginFeeDataRequest($vipLevel = null, $coin = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryCrossMarginFeeData'][0];

        $resourcePath = '/sapi/v1/margin/crossMarginData';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $vipLevel,
            'vipLevel', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $coin,
            'coin', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation queryEnabledIsolatedMarginAccountLimit.
     *
     * Query Enabled Isolated Margin Account Limit (USER_DATA)
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryEnabledIsolatedMarginAccountLimitResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryEnabledIsolatedMarginAccountLimit($recvWindow = null): ApiResponse
    {
        return $this->queryEnabledIsolatedMarginAccountLimitWithHttpInfo($recvWindow);
    }

    /**
     * Operation queryEnabledIsolatedMarginAccountLimitWithHttpInfo.
     *
     * Query Enabled Isolated Margin Account Limit (USER_DATA)
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryEnabledIsolatedMarginAccountLimitResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryEnabledIsolatedMarginAccountLimitWithHttpInfo($recvWindow = null): ApiResponse
    {
        $request = $this->queryEnabledIsolatedMarginAccountLimitRequest($recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\QueryEnabledIsolatedMarginAccountLimitResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\QueryEnabledIsolatedMarginAccountLimitResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\QueryEnabledIsolatedMarginAccountLimitResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryEnabledIsolatedMarginAccountLimit'.
     *
     * @param null|int $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryEnabledIsolatedMarginAccountLimitRequest($recvWindow = null)
    {
        $contentType = self::contentTypes['queryEnabledIsolatedMarginAccountLimit'][0];

        $resourcePath = '/sapi/v1/margin/isolated/accountLimit';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation queryIsolatedMarginAccountInfo.
     *
     * Query Isolated Margin Account Info (USER_DATA)
     *
     * @param null|string $symbols    Max 5 symbols can be sent; separated by \&quot;,\&quot;. e.g. \&quot;BTCUSDT,BNBUSDT,ADAUSDT\&quot; (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryIsolatedMarginAccountInfoResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryIsolatedMarginAccountInfo($symbols = null, $recvWindow = null): ApiResponse
    {
        return $this->queryIsolatedMarginAccountInfoWithHttpInfo($symbols, $recvWindow);
    }

    /**
     * Operation queryIsolatedMarginAccountInfoWithHttpInfo.
     *
     * Query Isolated Margin Account Info (USER_DATA)
     *
     * @param null|string $symbols    Max 5 symbols can be sent; separated by \&quot;,\&quot;. e.g. \&quot;BTCUSDT,BNBUSDT,ADAUSDT\&quot; (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryIsolatedMarginAccountInfoResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryIsolatedMarginAccountInfoWithHttpInfo($symbols = null, $recvWindow = null): ApiResponse
    {
        $request = $this->queryIsolatedMarginAccountInfoRequest($symbols, $recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\QueryIsolatedMarginAccountInfoResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\QueryIsolatedMarginAccountInfoResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\QueryIsolatedMarginAccountInfoResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryIsolatedMarginAccountInfo'.
     *
     * @param null|string $symbols    Max 5 symbols can be sent; separated by \&quot;,\&quot;. e.g. \&quot;BTCUSDT,BNBUSDT,ADAUSDT\&quot; (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryIsolatedMarginAccountInfoRequest($symbols = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryIsolatedMarginAccountInfo'][0];

        $resourcePath = '/sapi/v1/margin/isolated/account';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $symbols,
            'symbols', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation queryIsolatedMarginFeeData.
     *
     * Query Isolated Margin Fee Data (USER_DATA)
     *
     * @param null|int    $vipLevel   User&#39;s current specific margin data will be returned if vipLevel is omitted (optional)
     * @param null|string $symbol     isolated margin pair (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryIsolatedMarginFeeDataResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryIsolatedMarginFeeData($vipLevel = null, $symbol = null, $recvWindow = null): ApiResponse
    {
        return $this->queryIsolatedMarginFeeDataWithHttpInfo($vipLevel, $symbol, $recvWindow);
    }

    /**
     * Operation queryIsolatedMarginFeeDataWithHttpInfo.
     *
     * Query Isolated Margin Fee Data (USER_DATA)
     *
     * @param null|int    $vipLevel   User&#39;s current specific margin data will be returned if vipLevel is omitted (optional)
     * @param null|string $symbol     isolated margin pair (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return ApiResponse<QueryIsolatedMarginFeeDataResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryIsolatedMarginFeeDataWithHttpInfo($vipLevel = null, $symbol = null, $recvWindow = null): ApiResponse
    {
        $request = $this->queryIsolatedMarginFeeDataRequest($vipLevel, $symbol, $recvWindow);

        try {
            try {
                $response = $this->client->send($request, []);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }

            $statusCode = $response->getStatusCode();

            switch ($statusCode) {
                case 200:
                    return $this->handleResponseWithDataType(
                        '\Binance\Client\MarginTrading\Model\QueryIsolatedMarginFeeDataResponse',
                        $request,
                        $response,
                    );
            }

            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }

            return $this->handleResponseWithDataType(
                '\Binance\Client\MarginTrading\Model\QueryIsolatedMarginFeeDataResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\MarginTrading\Model\QueryIsolatedMarginFeeDataResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryIsolatedMarginFeeData'.
     *
     * @param null|int    $vipLevel   User&#39;s current specific margin data will be returned if vipLevel is omitted (optional)
     * @param null|string $symbol     isolated margin pair (optional)
     * @param null|int    $recvWindow No more than 60000 (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryIsolatedMarginFeeDataRequest($vipLevel = null, $symbol = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryIsolatedMarginFeeData'][0];

        $resourcePath = '/sapi/v1/margin/isolatedMarginData';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $vipLevel,
            'vipLevel', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $symbol,
            'symbol', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $recvWindow,
            'recvWindow', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);

        $headers = $this->headerSelector->selectHeaders(
            ['application/json'],
            $contentType,
            $multipart
        );

        $defaultHeaders = [];
        $defaultHeaders['User-Agent'] = $this->userAgent;

        if (self::HAS_TIME_UNIT && !empty($this->clientConfig->getTimeUnit())) {
            $defaultHeaders['X-MBX-TIME-UNIT'] = $this->clientConfig->getTimeUnit();
        }

        $headers = array_merge(
            $defaultHeaders,
            $headerParams,
            $headers
        );

        $operationHost = $this->clientConfig->getUrl();

        $queryParams['timestamp'] = $this->getTimestamp();
        $query = ObjectSerializer::buildQuery($queryParams);
        $queryParams['signature'] = $this->signer->sign($query.$httpBody);
        $headers['X-MBX-APIKEY'] = $this->clientConfig->getSignatureConfiguration()->getApiKey();
        $query = ObjectSerializer::buildQuery($queryParams);

        return new Request(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Summary of getTimestamp.
     */
    public function getTimestamp(): string
    {
        return date_create()->format('Uv');
    }

    private function handleResponseWithDataType(
        string $dataType,
        RequestInterface $request,
        ResponseInterface $response
    ): ApiResponse {
        if ('\SplFileObject' === $dataType) {
            $content = $response->getBody(); // stream goes to serializer
        } else {
            $content = (string) $response->getBody();
            if ('string' !== $dataType) {
                try {
                    $content = json_decode($content, false, 512, JSON_THROW_ON_ERROR);
                } catch (\JsonException $exception) {
                    throw new ApiException(
                        sprintf(
                            'Error JSON decoding server response (%s)',
                            $request->getUri()
                        ),
                        $response->getStatusCode(),
                        $response->getHeaders(),
                        $content
                    );
                }
            }
        }

        $rateLimits = CommonUtils::getRateLimits($response->getStatusCode(), $response->getHeaders());

        return new ApiResponse(
            $response->getStatusCode(),
            $response->getHeaders(),
            ObjectSerializer::deserialize($content, $dataType, []),
            $rateLimits
        );
    }

    private function responseWithinRangeCode(
        string $rangeCode,
        int $statusCode
    ): bool {
        $left = (int) ($rangeCode[0].'00');
        $right = (int) ($rangeCode[0].'99');

        return $statusCode >= $left && $statusCode <= $right;
    }
}
