<?php

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

/**
 * Binance Sub Account REST API.
 *
 * OpenAPI Specification for the Binance Sub Account 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\SubAccount\Api;

use Binance\Client\SubAccount\Model\DepositAssetsIntoTheManagedSubAccountRequest;
use Binance\Client\SubAccount\Model\DepositAssetsIntoTheManagedSubAccountResponse;
use Binance\Client\SubAccount\Model\GetManagedSubAccountDepositAddressResponse;
use Binance\Client\SubAccount\Model\QueryManagedSubAccountAssetDetailsResponse;
use Binance\Client\SubAccount\Model\QueryManagedSubAccountFuturesAssetDetailsResponse;
use Binance\Client\SubAccount\Model\QueryManagedSubAccountListResponse;
use Binance\Client\SubAccount\Model\QueryManagedSubAccountMarginAssetDetailsResponse;
use Binance\Client\SubAccount\Model\QueryManagedSubAccountSnapshotResponse;
use Binance\Client\SubAccount\Model\QueryManagedSubAccountTransferLogMasterAccountInvestorResponse;
use Binance\Client\SubAccount\Model\QueryManagedSubAccountTransferLogMasterAccountTradingResponse;
use Binance\Client\SubAccount\Model\QueryManagedSubAccountTransferLogSubAccountTradingResponse;
use Binance\Client\SubAccount\Model\WithdrawlAssetsFromTheManagedSubAccountRequest;
use Binance\Client\SubAccount\Model\WithdrawlAssetsFromTheManagedSubAccountResponse;
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;

/**
 * ManagedSubAccountApi Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */
class ManagedSubAccountApi
{
    /** @var string[] */
    public const contentTypes = [
        'depositAssetsIntoTheManagedSubAccount' => ['application/x-www-form-urlencoded'],
        'getManagedSubAccountDepositAddress' => ['application/x-www-form-urlencoded'],
        'queryManagedSubAccountAssetDetails' => ['application/x-www-form-urlencoded'],
        'queryManagedSubAccountFuturesAssetDetails' => ['application/x-www-form-urlencoded'],
        'queryManagedSubAccountList' => ['application/x-www-form-urlencoded'],
        'queryManagedSubAccountMarginAssetDetails' => ['application/x-www-form-urlencoded'],
        'queryManagedSubAccountSnapshot' => ['application/x-www-form-urlencoded'],
        'queryManagedSubAccountTransferLogMasterAccountInvestor' => ['application/x-www-form-urlencoded'],
        'queryManagedSubAccountTransferLogMasterAccountTrading' => ['application/x-www-form-urlencoded'],
        'queryManagedSubAccountTransferLogSubAccountTrading' => ['application/x-www-form-urlencoded'],
        'withdrawlAssetsFromTheManagedSubAccount' => ['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('sub-account');
    }

    /**
     * Operation depositAssetsIntoTheManagedSubAccount.
     *
     * Deposit Assets Into The Managed Sub-account (For Investor Master Account) (USER_DATA)
     *
     * @param DepositAssetsIntoTheManagedSubAccountRequest $depositAssetsIntoTheManagedSubAccountRequest depositAssetsIntoTheManagedSubAccountRequest (required)
     *
     * @return ApiResponse<DepositAssetsIntoTheManagedSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function depositAssetsIntoTheManagedSubAccount($depositAssetsIntoTheManagedSubAccountRequest): ApiResponse
    {
        return $this->depositAssetsIntoTheManagedSubAccountWithHttpInfo($depositAssetsIntoTheManagedSubAccountRequest);
    }

    /**
     * Operation depositAssetsIntoTheManagedSubAccountWithHttpInfo.
     *
     * Deposit Assets Into The Managed Sub-account (For Investor Master Account) (USER_DATA)
     *
     * @param DepositAssetsIntoTheManagedSubAccountRequest $depositAssetsIntoTheManagedSubAccountRequest (required)
     *
     * @return ApiResponse<DepositAssetsIntoTheManagedSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function depositAssetsIntoTheManagedSubAccountWithHttpInfo($depositAssetsIntoTheManagedSubAccountRequest): ApiResponse
    {
        $request = $this->depositAssetsIntoTheManagedSubAccountRequest($depositAssetsIntoTheManagedSubAccountRequest);

        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\SubAccount\Model\DepositAssetsIntoTheManagedSubAccountResponse',
                        $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\SubAccount\Model\DepositAssetsIntoTheManagedSubAccountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\DepositAssetsIntoTheManagedSubAccountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

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

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

        $resourcePath = '/sapi/v1/managed-subaccount/deposit';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $depositAssetsIntoTheManagedSubAccountRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $depositAssetsIntoTheManagedSubAccountRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $depositAssetsIntoTheManagedSubAccountRequest->{$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($depositAssetsIntoTheManagedSubAccountRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($depositAssetsIntoTheManagedSubAccountRequest));
            } else {
                $httpBody = $depositAssetsIntoTheManagedSubAccountRequest;
            }
        }

        $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 getManagedSubAccountDepositAddress.
     *
     * Get Managed Sub-account Deposit Address (For Investor Master Account) (USER_DATA)
     *
     * @param string      $email      [Sub-account email](#email-address) (required)
     * @param string      $coin       coin (required)
     * @param null|string $network    networks can be found in &#x60;GET /sapi/v1/capital/deposit/address&#x60; (optional)
     * @param null|float  $amount     amount (optional)
     * @param null|int    $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<GetManagedSubAccountDepositAddressResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getManagedSubAccountDepositAddress($email, $coin, $network = null, $amount = null, $recvWindow = null): ApiResponse
    {
        return $this->getManagedSubAccountDepositAddressWithHttpInfo($email, $coin, $network, $amount, $recvWindow);
    }

    /**
     * Operation getManagedSubAccountDepositAddressWithHttpInfo.
     *
     * Get Managed Sub-account Deposit Address (For Investor Master Account) (USER_DATA)
     *
     * @param string      $email      [Sub-account email](#email-address) (required)
     * @param string      $coin       (required)
     * @param null|string $network    networks can be found in &#x60;GET /sapi/v1/capital/deposit/address&#x60; (optional)
     * @param null|float  $amount     (optional)
     * @param null|int    $recvWindow (optional)
     *
     * @return ApiResponse<GetManagedSubAccountDepositAddressResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getManagedSubAccountDepositAddressWithHttpInfo($email, $coin, $network = null, $amount = null, $recvWindow = null): ApiResponse
    {
        $request = $this->getManagedSubAccountDepositAddressRequest($email, $coin, $network, $amount, $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\SubAccount\Model\GetManagedSubAccountDepositAddressResponse',
                        $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\SubAccount\Model\GetManagedSubAccountDepositAddressResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\GetManagedSubAccountDepositAddressResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getManagedSubAccountDepositAddress'.
     *
     * @param string      $email      [Sub-account email](#email-address) (required)
     * @param string      $coin       (required)
     * @param null|string $network    networks can be found in &#x60;GET /sapi/v1/capital/deposit/address&#x60; (optional)
     * @param null|float  $amount     (optional)
     * @param null|int    $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getManagedSubAccountDepositAddressRequest($email, $coin, $network = null, $amount = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['getManagedSubAccountDepositAddress'][0];

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

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

        $resourcePath = '/sapi/v1/managed-subaccount/deposit/address';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $coin,
            'coin', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $network,
            'network', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $amount,
            'amount', // param base name
            'number', // 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 queryManagedSubAccountAssetDetails.
     *
     * Query Managed Sub-account Asset Details (For Investor Master Account) (USER_DATA)
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountAssetDetailsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountAssetDetails($email, $recvWindow = null): ApiResponse
    {
        return $this->queryManagedSubAccountAssetDetailsWithHttpInfo($email, $recvWindow);
    }

    /**
     * Operation queryManagedSubAccountAssetDetailsWithHttpInfo.
     *
     * Query Managed Sub-account Asset Details (For Investor Master Account) (USER_DATA)
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountAssetDetailsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountAssetDetailsWithHttpInfo($email, $recvWindow = null): ApiResponse
    {
        $request = $this->queryManagedSubAccountAssetDetailsRequest($email, $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\SubAccount\Model\QueryManagedSubAccountAssetDetailsResponse',
                        $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\SubAccount\Model\QueryManagedSubAccountAssetDetailsResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryManagedSubAccountAssetDetailsResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryManagedSubAccountAssetDetails'.
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountAssetDetailsRequest($email, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryManagedSubAccountAssetDetails'][0];

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

        $resourcePath = '/sapi/v1/managed-subaccount/asset';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // 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(
            'GET',
            $operationHost.$resourcePath.($query ? "?{$query}" : ''),
            $headers,
            $httpBody
        );
    }

    /**
     * Operation queryManagedSubAccountFuturesAssetDetails.
     *
     * Query Managed Sub-account Futures Asset Details (For Investor Master Account) (USER_DATA)
     *
     * @param string      $email       [Sub-account email](#email-address) (required)
     * @param null|string $accountType No input or input \&quot;MARGIN\&quot; to get Cross Margin account details. Input \&quot;ISOLATED_MARGIN\&quot; to get Isolated Margin account details. (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountFuturesAssetDetailsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountFuturesAssetDetails($email, $accountType = null): ApiResponse
    {
        return $this->queryManagedSubAccountFuturesAssetDetailsWithHttpInfo($email, $accountType);
    }

    /**
     * Operation queryManagedSubAccountFuturesAssetDetailsWithHttpInfo.
     *
     * Query Managed Sub-account Futures Asset Details (For Investor Master Account) (USER_DATA)
     *
     * @param string      $email       [Sub-account email](#email-address) (required)
     * @param null|string $accountType No input or input \&quot;MARGIN\&quot; to get Cross Margin account details. Input \&quot;ISOLATED_MARGIN\&quot; to get Isolated Margin account details. (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountFuturesAssetDetailsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountFuturesAssetDetailsWithHttpInfo($email, $accountType = null): ApiResponse
    {
        $request = $this->queryManagedSubAccountFuturesAssetDetailsRequest($email, $accountType);

        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\SubAccount\Model\QueryManagedSubAccountFuturesAssetDetailsResponse',
                        $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\SubAccount\Model\QueryManagedSubAccountFuturesAssetDetailsResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryManagedSubAccountFuturesAssetDetailsResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryManagedSubAccountFuturesAssetDetails'.
     *
     * @param string      $email       [Sub-account email](#email-address) (required)
     * @param null|string $accountType No input or input \&quot;MARGIN\&quot; to get Cross Margin account details. Input \&quot;ISOLATED_MARGIN\&quot; to get Isolated Margin account details. (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountFuturesAssetDetailsRequest($email, $accountType = null)
    {
        $contentType = self::contentTypes['queryManagedSubAccountFuturesAssetDetails'][0];

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

        $resourcePath = '/sapi/v1/managed-subaccount/fetch-future-asset';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $accountType,
            'accountType', // param base name
            'string', // 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 queryManagedSubAccountList.
     *
     * Query Managed Sub-account List (For Investor) (USER_DATA)
     *
     * @param null|string $email      Managed sub-account email (optional)
     * @param null|int    $page       Default value: 1 (optional)
     * @param null|int    $limit      Default value: 1, Max value: 200 (optional)
     * @param null|int    $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountListResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountList($email = null, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        return $this->queryManagedSubAccountListWithHttpInfo($email, $page, $limit, $recvWindow);
    }

    /**
     * Operation queryManagedSubAccountListWithHttpInfo.
     *
     * Query Managed Sub-account List (For Investor) (USER_DATA)
     *
     * @param null|string $email      Managed sub-account email (optional)
     * @param null|int    $page       Default value: 1 (optional)
     * @param null|int    $limit      Default value: 1, Max value: 200 (optional)
     * @param null|int    $recvWindow (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountListResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountListWithHttpInfo($email = null, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        $request = $this->queryManagedSubAccountListRequest($email, $page, $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\SubAccount\Model\QueryManagedSubAccountListResponse',
                        $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\SubAccount\Model\QueryManagedSubAccountListResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryManagedSubAccountListResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryManagedSubAccountList'.
     *
     * @param null|string $email      Managed sub-account email (optional)
     * @param null|int    $page       Default value: 1 (optional)
     * @param null|int    $limit      Default value: 1, Max value: 200 (optional)
     * @param null|int    $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountListRequest($email = null, $page = null, $limit = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryManagedSubAccountList'][0];

        $resourcePath = '/sapi/v1/managed-subaccount/info';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page,
            'page', // 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 queryManagedSubAccountMarginAssetDetails.
     *
     * Query Managed Sub-account Margin Asset Details (For Investor Master Account) (USER_DATA)
     *
     * @param string      $email       [Sub-account email](#email-address) (required)
     * @param null|string $accountType No input or input \&quot;MARGIN\&quot; to get Cross Margin account details. Input \&quot;ISOLATED_MARGIN\&quot; to get Isolated Margin account details. (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountMarginAssetDetailsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountMarginAssetDetails($email, $accountType = null): ApiResponse
    {
        return $this->queryManagedSubAccountMarginAssetDetailsWithHttpInfo($email, $accountType);
    }

    /**
     * Operation queryManagedSubAccountMarginAssetDetailsWithHttpInfo.
     *
     * Query Managed Sub-account Margin Asset Details (For Investor Master Account) (USER_DATA)
     *
     * @param string      $email       [Sub-account email](#email-address) (required)
     * @param null|string $accountType No input or input \&quot;MARGIN\&quot; to get Cross Margin account details. Input \&quot;ISOLATED_MARGIN\&quot; to get Isolated Margin account details. (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountMarginAssetDetailsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountMarginAssetDetailsWithHttpInfo($email, $accountType = null): ApiResponse
    {
        $request = $this->queryManagedSubAccountMarginAssetDetailsRequest($email, $accountType);

        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\SubAccount\Model\QueryManagedSubAccountMarginAssetDetailsResponse',
                        $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\SubAccount\Model\QueryManagedSubAccountMarginAssetDetailsResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryManagedSubAccountMarginAssetDetailsResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryManagedSubAccountMarginAssetDetails'.
     *
     * @param string      $email       [Sub-account email](#email-address) (required)
     * @param null|string $accountType No input or input \&quot;MARGIN\&quot; to get Cross Margin account details. Input \&quot;ISOLATED_MARGIN\&quot; to get Isolated Margin account details. (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountMarginAssetDetailsRequest($email, $accountType = null)
    {
        $contentType = self::contentTypes['queryManagedSubAccountMarginAssetDetails'][0];

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

        $resourcePath = '/sapi/v1/managed-subaccount/marginAsset';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $accountType,
            'accountType', // param base name
            'string', // 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 queryManagedSubAccountSnapshot.
     *
     * Query Managed Sub-account Snapshot (For Investor Master Account) (USER_DATA)
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param string   $type       \&quot;SPOT\&quot;, \&quot;MARGIN\&quot;（cross）, \&quot;FUTURES\&quot;（UM） (required)
     * @param null|int $startTime  startTime (optional)
     * @param null|int $endTime    endTime (optional)
     * @param null|int $limit      Default value: 1, Max value: 200 (optional)
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountSnapshotResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountSnapshot($email, $type, $startTime = null, $endTime = null, $limit = null, $recvWindow = null): ApiResponse
    {
        return $this->queryManagedSubAccountSnapshotWithHttpInfo($email, $type, $startTime, $endTime, $limit, $recvWindow);
    }

    /**
     * Operation queryManagedSubAccountSnapshotWithHttpInfo.
     *
     * Query Managed Sub-account Snapshot (For Investor Master Account) (USER_DATA)
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param string   $type       \&quot;SPOT\&quot;, \&quot;MARGIN\&quot;（cross）, \&quot;FUTURES\&quot;（UM） (required)
     * @param null|int $startTime  (optional)
     * @param null|int $endTime    (optional)
     * @param null|int $limit      Default value: 1, Max value: 200 (optional)
     * @param null|int $recvWindow (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountSnapshotResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountSnapshotWithHttpInfo($email, $type, $startTime = null, $endTime = null, $limit = null, $recvWindow = null): ApiResponse
    {
        $request = $this->queryManagedSubAccountSnapshotRequest($email, $type, $startTime, $endTime, $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\SubAccount\Model\QueryManagedSubAccountSnapshotResponse',
                        $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\SubAccount\Model\QueryManagedSubAccountSnapshotResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryManagedSubAccountSnapshotResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryManagedSubAccountSnapshot'.
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param string   $type       \&quot;SPOT\&quot;, \&quot;MARGIN\&quot;（cross）, \&quot;FUTURES\&quot;（UM） (required)
     * @param null|int $startTime  (optional)
     * @param null|int $endTime    (optional)
     * @param null|int $limit      Default value: 1, Max value: 200 (optional)
     * @param null|int $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountSnapshotRequest($email, $type, $startTime = null, $endTime = null, $limit = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryManagedSubAccountSnapshot'][0];

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

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

        $resourcePath = '/sapi/v1/managed-subaccount/accountSnapshot';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $type,
            'type', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // 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(
            $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 queryManagedSubAccountTransferLogMasterAccountInvestor.
     *
     * Query Managed Sub Account Transfer Log (For Investor Master Account) (USER_DATA)
     *
     * @param string      $email                       [Sub-account email](#email-address) (required)
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountTransferLogMasterAccountInvestorResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogMasterAccountInvestor($email, $startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null): ApiResponse
    {
        return $this->queryManagedSubAccountTransferLogMasterAccountInvestorWithHttpInfo($email, $startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType);
    }

    /**
     * Operation queryManagedSubAccountTransferLogMasterAccountInvestorWithHttpInfo.
     *
     * Query Managed Sub Account Transfer Log (For Investor Master Account) (USER_DATA)
     *
     * @param string      $email                       [Sub-account email](#email-address) (required)
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountTransferLogMasterAccountInvestorResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogMasterAccountInvestorWithHttpInfo($email, $startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null): ApiResponse
    {
        $request = $this->queryManagedSubAccountTransferLogMasterAccountInvestorRequest($email, $startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType);

        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\SubAccount\Model\QueryManagedSubAccountTransferLogMasterAccountInvestorResponse',
                        $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\SubAccount\Model\QueryManagedSubAccountTransferLogMasterAccountInvestorResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryManagedSubAccountTransferLogMasterAccountInvestorResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryManagedSubAccountTransferLogMasterAccountInvestor'.
     *
     * @param string      $email                       [Sub-account email](#email-address) (required)
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogMasterAccountInvestorRequest($email, $startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null)
    {
        $contentType = self::contentTypes['queryManagedSubAccountTransferLogMasterAccountInvestor'][0];

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

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

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

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

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

        $resourcePath = '/sapi/v1/managed-subaccount/queryTransLogForInvestor';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $startTime,
            'startTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $endTime,
            'endTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page,
            'page', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $limit,
            'limit', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transfers,
            'transfers', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transferFunctionAccountType,
            'transferFunctionAccountType', // param base name
            'string', // 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 queryManagedSubAccountTransferLogMasterAccountTrading.
     *
     * Query Managed Sub Account Transfer Log (For Trading Team Master Account) (USER_DATA)
     *
     * @param string      $email                       [Sub-account email](#email-address) (required)
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountTransferLogMasterAccountTradingResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogMasterAccountTrading($email, $startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null): ApiResponse
    {
        return $this->queryManagedSubAccountTransferLogMasterAccountTradingWithHttpInfo($email, $startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType);
    }

    /**
     * Operation queryManagedSubAccountTransferLogMasterAccountTradingWithHttpInfo.
     *
     * Query Managed Sub Account Transfer Log (For Trading Team Master Account) (USER_DATA)
     *
     * @param string      $email                       [Sub-account email](#email-address) (required)
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountTransferLogMasterAccountTradingResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogMasterAccountTradingWithHttpInfo($email, $startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null): ApiResponse
    {
        $request = $this->queryManagedSubAccountTransferLogMasterAccountTradingRequest($email, $startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType);

        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\SubAccount\Model\QueryManagedSubAccountTransferLogMasterAccountTradingResponse',
                        $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\SubAccount\Model\QueryManagedSubAccountTransferLogMasterAccountTradingResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryManagedSubAccountTransferLogMasterAccountTradingResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryManagedSubAccountTransferLogMasterAccountTrading'.
     *
     * @param string      $email                       [Sub-account email](#email-address) (required)
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogMasterAccountTradingRequest($email, $startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null)
    {
        $contentType = self::contentTypes['queryManagedSubAccountTransferLogMasterAccountTrading'][0];

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

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

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

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

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

        $resourcePath = '/sapi/v1/managed-subaccount/queryTransLogForTradeParent';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $email,
            'email', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $startTime,
            'startTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $endTime,
            'endTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page,
            'page', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $limit,
            'limit', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transfers,
            'transfers', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transferFunctionAccountType,
            'transferFunctionAccountType', // param base name
            'string', // 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 queryManagedSubAccountTransferLogSubAccountTrading.
     *
     * Query Managed Sub Account Transfer Log (For Trading Team Sub Account) (USER_DATA)
     *
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     * @param null|int    $recvWindow                  recvWindow (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountTransferLogSubAccountTradingResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogSubAccountTrading($startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null, $recvWindow = null): ApiResponse
    {
        return $this->queryManagedSubAccountTransferLogSubAccountTradingWithHttpInfo($startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType, $recvWindow);
    }

    /**
     * Operation queryManagedSubAccountTransferLogSubAccountTradingWithHttpInfo.
     *
     * Query Managed Sub Account Transfer Log (For Trading Team Sub Account) (USER_DATA)
     *
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     * @param null|int    $recvWindow                  (optional)
     *
     * @return ApiResponse<QueryManagedSubAccountTransferLogSubAccountTradingResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogSubAccountTradingWithHttpInfo($startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null, $recvWindow = null): ApiResponse
    {
        $request = $this->queryManagedSubAccountTransferLogSubAccountTradingRequest($startTime, $endTime, $page, $limit, $transfers, $transferFunctionAccountType, $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\SubAccount\Model\QueryManagedSubAccountTransferLogSubAccountTradingResponse',
                        $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\SubAccount\Model\QueryManagedSubAccountTransferLogSubAccountTradingResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryManagedSubAccountTransferLogSubAccountTradingResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryManagedSubAccountTransferLogSubAccountTrading'.
     *
     * @param int         $startTime                   Start Time (required)
     * @param int         $endTime                     End Time (The start time and end time interval cannot exceed half a year) (required)
     * @param int         $page                        Page (required)
     * @param int         $limit                       Limit (Max: 500) (required)
     * @param null|string $transfers                   Transfer Direction (FROM/TO) (optional)
     * @param null|string $transferFunctionAccountType Transfer function account type (SPOT/MARGIN/ISOLATED_MARGIN/USDT_FUTURE/COIN_FUTURE) (optional)
     * @param null|int    $recvWindow                  (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function queryManagedSubAccountTransferLogSubAccountTradingRequest($startTime, $endTime, $page, $limit, $transfers = null, $transferFunctionAccountType = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryManagedSubAccountTransferLogSubAccountTrading'][0];

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

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

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

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

        $resourcePath = '/sapi/v1/managed-subaccount/query-trans-log';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $startTime,
            'startTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $endTime,
            'endTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $page,
            'page', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $limit,
            'limit', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transfers,
            'transfers', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $transferFunctionAccountType,
            'transferFunctionAccountType', // 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 withdrawlAssetsFromTheManagedSubAccount.
     *
     * Withdrawl Assets From The Managed Sub-account (For Investor Master Account) (USER_DATA)
     *
     * @param WithdrawlAssetsFromTheManagedSubAccountRequest $withdrawlAssetsFromTheManagedSubAccountRequest withdrawlAssetsFromTheManagedSubAccountRequest (required)
     *
     * @return ApiResponse<WithdrawlAssetsFromTheManagedSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function withdrawlAssetsFromTheManagedSubAccount($withdrawlAssetsFromTheManagedSubAccountRequest): ApiResponse
    {
        return $this->withdrawlAssetsFromTheManagedSubAccountWithHttpInfo($withdrawlAssetsFromTheManagedSubAccountRequest);
    }

    /**
     * Operation withdrawlAssetsFromTheManagedSubAccountWithHttpInfo.
     *
     * Withdrawl Assets From The Managed Sub-account (For Investor Master Account) (USER_DATA)
     *
     * @param WithdrawlAssetsFromTheManagedSubAccountRequest $withdrawlAssetsFromTheManagedSubAccountRequest (required)
     *
     * @return ApiResponse<WithdrawlAssetsFromTheManagedSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function withdrawlAssetsFromTheManagedSubAccountWithHttpInfo($withdrawlAssetsFromTheManagedSubAccountRequest): ApiResponse
    {
        $request = $this->withdrawlAssetsFromTheManagedSubAccountRequest($withdrawlAssetsFromTheManagedSubAccountRequest);

        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\SubAccount\Model\WithdrawlAssetsFromTheManagedSubAccountResponse',
                        $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\SubAccount\Model\WithdrawlAssetsFromTheManagedSubAccountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\WithdrawlAssetsFromTheManagedSubAccountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

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

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

        $resourcePath = '/sapi/v1/managed-subaccount/withdraw';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        $getters = $withdrawlAssetsFromTheManagedSubAccountRequest::getters();
        $formParams = [];
        foreach ($getters as $property => $getter) {
            $value = $withdrawlAssetsFromTheManagedSubAccountRequest->{$getter}();
            if (!empty($value)) {
                $formParams[$property] = $withdrawlAssetsFromTheManagedSubAccountRequest->{$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($withdrawlAssetsFromTheManagedSubAccountRequest)) {
            if (false !== stripos($headers['Content-Type'], 'application/json')) {
                // if Content-Type contains "application/json", json_encode the body
                $httpBody = Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($withdrawlAssetsFromTheManagedSubAccountRequest));
            } else {
                $httpBody = $withdrawlAssetsFromTheManagedSubAccountRequest;
            }
        }

        $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
        );
    }

    /**
     * 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;
    }
}
