<?php

/**
 * AssetManagementApi
 * 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\FuturesTransferForSubAccountRequest;
use Binance\Client\SubAccount\Model\FuturesTransferForSubAccountResponse;
use Binance\Client\SubAccount\Model\GetDetailOnSubAccountsFuturesAccountResponse;
use Binance\Client\SubAccount\Model\GetDetailOnSubAccountsFuturesAccountV2Response;
use Binance\Client\SubAccount\Model\GetDetailOnSubAccountsMarginAccountResponse;
use Binance\Client\SubAccount\Model\GetMovePositionHistoryForSubAccountResponse;
use Binance\Client\SubAccount\Model\GetSubAccountDepositAddressResponse;
use Binance\Client\SubAccount\Model\GetSubAccountDepositHistoryResponse;
use Binance\Client\SubAccount\Model\GetSummaryOfSubAccountsFuturesAccountResponse;
use Binance\Client\SubAccount\Model\GetSummaryOfSubAccountsFuturesAccountV2Response;
use Binance\Client\SubAccount\Model\GetSummaryOfSubAccountsMarginAccountResponse;
use Binance\Client\SubAccount\Model\MarginTransferForSubAccountRequest;
use Binance\Client\SubAccount\Model\MarginTransferForSubAccountResponse;
use Binance\Client\SubAccount\Model\MovePositionForSubAccountRequest;
use Binance\Client\SubAccount\Model\MovePositionForSubAccountResponse;
use Binance\Client\SubAccount\Model\QuerySubAccountAssetsAssetManagementResponse;
use Binance\Client\SubAccount\Model\QuerySubAccountAssetsResponse;
use Binance\Client\SubAccount\Model\QuerySubAccountFuturesAssetTransferHistoryResponse;
use Binance\Client\SubAccount\Model\QuerySubAccountSpotAssetsSummaryResponse;
use Binance\Client\SubAccount\Model\QuerySubAccountSpotAssetTransferHistoryResponse;
use Binance\Client\SubAccount\Model\QueryUniversalTransferHistoryResponse;
use Binance\Client\SubAccount\Model\SubAccountFuturesAssetTransferRequest;
use Binance\Client\SubAccount\Model\SubAccountFuturesAssetTransferResponse;
use Binance\Client\SubAccount\Model\SubAccountTransferHistoryResponse;
use Binance\Client\SubAccount\Model\TransferToMasterRequest;
use Binance\Client\SubAccount\Model\TransferToMasterResponse;
use Binance\Client\SubAccount\Model\TransferToSubAccountOfSameMasterRequest;
use Binance\Client\SubAccount\Model\TransferToSubAccountOfSameMasterResponse;
use Binance\Client\SubAccount\Model\UniversalTransferRequest;
use Binance\Client\SubAccount\Model\UniversalTransferResponse;
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;

/**
 * AssetManagementApi Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */
class AssetManagementApi
{
    /** @var string[] */
    public const contentTypes = [
        'futuresTransferForSubAccount' => ['application/x-www-form-urlencoded'],
        'getDetailOnSubAccountsFuturesAccount' => ['application/x-www-form-urlencoded'],
        'getDetailOnSubAccountsFuturesAccountV2' => ['application/x-www-form-urlencoded'],
        'getDetailOnSubAccountsMarginAccount' => ['application/x-www-form-urlencoded'],
        'getMovePositionHistoryForSubAccount' => ['application/x-www-form-urlencoded'],
        'getSubAccountDepositAddress' => ['application/x-www-form-urlencoded'],
        'getSubAccountDepositHistory' => ['application/x-www-form-urlencoded'],
        'getSummaryOfSubAccountsFuturesAccount' => ['application/x-www-form-urlencoded'],
        'getSummaryOfSubAccountsFuturesAccountV2' => ['application/x-www-form-urlencoded'],
        'getSummaryOfSubAccountsMarginAccount' => ['application/x-www-form-urlencoded'],
        'marginTransferForSubAccount' => ['application/x-www-form-urlencoded'],
        'movePositionForSubAccount' => ['application/x-www-form-urlencoded'],
        'querySubAccountAssets' => ['application/x-www-form-urlencoded'],
        'querySubAccountAssetsAssetManagement' => ['application/x-www-form-urlencoded'],
        'querySubAccountFuturesAssetTransferHistory' => ['application/x-www-form-urlencoded'],
        'querySubAccountSpotAssetTransferHistory' => ['application/x-www-form-urlencoded'],
        'querySubAccountSpotAssetsSummary' => ['application/x-www-form-urlencoded'],
        'queryUniversalTransferHistory' => ['application/x-www-form-urlencoded'],
        'subAccountFuturesAssetTransfer' => ['application/x-www-form-urlencoded'],
        'subAccountTransferHistory' => ['application/x-www-form-urlencoded'],
        'transferToMaster' => ['application/x-www-form-urlencoded'],
        'transferToSubAccountOfSameMaster' => ['application/x-www-form-urlencoded'],
        'universalTransfer' => ['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 futuresTransferForSubAccount.
     *
     * Futures Transfer for Sub-account (For Master Account) (USER_DATA)
     *
     * @param FuturesTransferForSubAccountRequest $futuresTransferForSubAccountRequest futuresTransferForSubAccountRequest (required)
     *
     * @return ApiResponse<FuturesTransferForSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function futuresTransferForSubAccount($futuresTransferForSubAccountRequest): ApiResponse
    {
        return $this->futuresTransferForSubAccountWithHttpInfo($futuresTransferForSubAccountRequest);
    }

    /**
     * Operation futuresTransferForSubAccountWithHttpInfo.
     *
     * Futures Transfer for Sub-account (For Master Account) (USER_DATA)
     *
     * @param FuturesTransferForSubAccountRequest $futuresTransferForSubAccountRequest (required)
     *
     * @return ApiResponse<FuturesTransferForSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function futuresTransferForSubAccountWithHttpInfo($futuresTransferForSubAccountRequest): ApiResponse
    {
        $request = $this->futuresTransferForSubAccountRequest($futuresTransferForSubAccountRequest);

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

                    throw $e;
            }

            throw $e;
        }
    }

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

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

        $resourcePath = '/sapi/v1/sub-account/futures/transfer';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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

        $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 getDetailOnSubAccountsFuturesAccount.
     *
     * Get Detail on Sub-account&#39;s Futures Account (For Master Account) (USER_DATA)
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<GetDetailOnSubAccountsFuturesAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getDetailOnSubAccountsFuturesAccount($email, $recvWindow = null): ApiResponse
    {
        return $this->getDetailOnSubAccountsFuturesAccountWithHttpInfo($email, $recvWindow);
    }

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

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getDetailOnSubAccountsFuturesAccount'.
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getDetailOnSubAccountsFuturesAccountRequest($email, $recvWindow = null)
    {
        $contentType = self::contentTypes['getDetailOnSubAccountsFuturesAccount'][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 getDetailOnSubAccountsFuturesAccount'
            );
        }

        $resourcePath = '/sapi/v1/sub-account/futures/account';
        $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 getDetailOnSubAccountsFuturesAccountV2.
     *
     * Get Detail on Sub-account&#39;s Futures Account V2 (For Master Account) (USER_DATA)
     *
     * @param string   $email       [Sub-account email](#email-address) (required)
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @param null|int $recvWindow  recvWindow (optional)
     *
     * @return ApiResponse<GetDetailOnSubAccountsFuturesAccountV2Response>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getDetailOnSubAccountsFuturesAccountV2($email, $futuresType, $recvWindow = null): ApiResponse
    {
        return $this->getDetailOnSubAccountsFuturesAccountV2WithHttpInfo($email, $futuresType, $recvWindow);
    }

    /**
     * Operation getDetailOnSubAccountsFuturesAccountV2WithHttpInfo.
     *
     * Get Detail on Sub-account&#39;s Futures Account V2 (For Master Account) (USER_DATA)
     *
     * @param string   $email       [Sub-account email](#email-address) (required)
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @param null|int $recvWindow  (optional)
     *
     * @return ApiResponse<GetDetailOnSubAccountsFuturesAccountV2Response>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getDetailOnSubAccountsFuturesAccountV2WithHttpInfo($email, $futuresType, $recvWindow = null): ApiResponse
    {
        $request = $this->getDetailOnSubAccountsFuturesAccountV2Request($email, $futuresType, $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\GetDetailOnSubAccountsFuturesAccountV2Response',
                        $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\GetDetailOnSubAccountsFuturesAccountV2Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\GetDetailOnSubAccountsFuturesAccountV2Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getDetailOnSubAccountsFuturesAccountV2'.
     *
     * @param string   $email       [Sub-account email](#email-address) (required)
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @param null|int $recvWindow  (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getDetailOnSubAccountsFuturesAccountV2Request($email, $futuresType, $recvWindow = null)
    {
        $contentType = self::contentTypes['getDetailOnSubAccountsFuturesAccountV2'][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 getDetailOnSubAccountsFuturesAccountV2'
            );
        }

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

        $resourcePath = '/sapi/v2/sub-account/futures/account';
        $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(
            $futuresType,
            'futuresType', // param base name
            'integer', // 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 getDetailOnSubAccountsMarginAccount.
     *
     * Get Detail on Sub-account&#39;s Margin Account (For Master Account) (USER_DATA)
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<GetDetailOnSubAccountsMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getDetailOnSubAccountsMarginAccount($email, $recvWindow = null): ApiResponse
    {
        return $this->getDetailOnSubAccountsMarginAccountWithHttpInfo($email, $recvWindow);
    }

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

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getDetailOnSubAccountsMarginAccount'.
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getDetailOnSubAccountsMarginAccountRequest($email, $recvWindow = null)
    {
        $contentType = self::contentTypes['getDetailOnSubAccountsMarginAccount'][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 getDetailOnSubAccountsMarginAccount'
            );
        }

        $resourcePath = '/sapi/v1/sub-account/margin/account';
        $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 getMovePositionHistoryForSubAccount.
     *
     * Get Move Position History for Sub-account (For Master Account) (USER_DATA)
     *
     * @param string   $symbol     symbol (required)
     * @param int      $page       Page (required)
     * @param int      $row        row (required)
     * @param null|int $startTime  startTime (optional)
     * @param null|int $endTime    endTime (optional)
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<GetMovePositionHistoryForSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getMovePositionHistoryForSubAccount($symbol, $page, $row, $startTime = null, $endTime = null, $recvWindow = null): ApiResponse
    {
        return $this->getMovePositionHistoryForSubAccountWithHttpInfo($symbol, $page, $row, $startTime, $endTime, $recvWindow);
    }

    /**
     * Operation getMovePositionHistoryForSubAccountWithHttpInfo.
     *
     * Get Move Position History for Sub-account (For Master Account) (USER_DATA)
     *
     * @param string   $symbol     (required)
     * @param int      $page       Page (required)
     * @param int      $row        (required)
     * @param null|int $startTime  (optional)
     * @param null|int $endTime    (optional)
     * @param null|int $recvWindow (optional)
     *
     * @return ApiResponse<GetMovePositionHistoryForSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getMovePositionHistoryForSubAccountWithHttpInfo($symbol, $page, $row, $startTime = null, $endTime = null, $recvWindow = null): ApiResponse
    {
        $request = $this->getMovePositionHistoryForSubAccountRequest($symbol, $page, $row, $startTime, $endTime, $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\GetMovePositionHistoryForSubAccountResponse',
                        $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\GetMovePositionHistoryForSubAccountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\GetMovePositionHistoryForSubAccountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getMovePositionHistoryForSubAccount'.
     *
     * @param string   $symbol     (required)
     * @param int      $page       Page (required)
     * @param int      $row        (required)
     * @param null|int $startTime  (optional)
     * @param null|int $endTime    (optional)
     * @param null|int $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getMovePositionHistoryForSubAccountRequest($symbol, $page, $row, $startTime = null, $endTime = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['getMovePositionHistoryForSubAccount'][0];

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

        // 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 getMovePositionHistoryForSubAccount'
            );
        }

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

        $resourcePath = '/sapi/v1/sub-account/futures/move-position';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $symbol,
            'symbol', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $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(
            $page,
            'page', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            true // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $row,
            'row', // param base name
            'integer', // 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 getSubAccountDepositAddress.
     *
     * Get Sub-account Deposit Address (For 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<GetSubAccountDepositAddressResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSubAccountDepositAddress($email, $coin, $network = null, $amount = null, $recvWindow = null): ApiResponse
    {
        return $this->getSubAccountDepositAddressWithHttpInfo($email, $coin, $network, $amount, $recvWindow);
    }

    /**
     * Operation getSubAccountDepositAddressWithHttpInfo.
     *
     * Get Sub-account Deposit Address (For 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<GetSubAccountDepositAddressResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSubAccountDepositAddressWithHttpInfo($email, $coin, $network = null, $amount = null, $recvWindow = null): ApiResponse
    {
        $request = $this->getSubAccountDepositAddressRequest($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\GetSubAccountDepositAddressResponse',
                        $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\GetSubAccountDepositAddressResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\GetSubAccountDepositAddressResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getSubAccountDepositAddress'.
     *
     * @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 getSubAccountDepositAddressRequest($email, $coin, $network = null, $amount = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['getSubAccountDepositAddress'][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 getSubAccountDepositAddress'
            );
        }

        // 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 getSubAccountDepositAddress'
            );
        }

        $resourcePath = '/sapi/v1/capital/deposit/subAddress';
        $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 getSubAccountDepositHistory.
     *
     * Get Sub-account Deposit History (For Master Account) (USER_DATA)
     *
     * @param string      $email      [Sub-account email](#email-address) (required)
     * @param null|string $coin       coin (optional)
     * @param null|int    $status     0(0:pending,6: credited but cannot withdraw,7:Wrong Deposit,8:Waiting User confirm,1:success) (optional)
     * @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    $offset     default:0 (optional)
     * @param null|int    $recvWindow recvWindow (optional)
     * @param null|string $txId       txId (optional)
     *
     * @return ApiResponse<GetSubAccountDepositHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSubAccountDepositHistory($email, $coin = null, $status = null, $startTime = null, $endTime = null, $limit = null, $offset = null, $recvWindow = null, $txId = null): ApiResponse
    {
        return $this->getSubAccountDepositHistoryWithHttpInfo($email, $coin, $status, $startTime, $endTime, $limit, $offset, $recvWindow, $txId);
    }

    /**
     * Operation getSubAccountDepositHistoryWithHttpInfo.
     *
     * Get Sub-account Deposit History (For Master Account) (USER_DATA)
     *
     * @param string      $email      [Sub-account email](#email-address) (required)
     * @param null|string $coin       (optional)
     * @param null|int    $status     0(0:pending,6: credited but cannot withdraw,7:Wrong Deposit,8:Waiting User confirm,1:success) (optional)
     * @param null|int    $startTime  (optional)
     * @param null|int    $endTime    (optional)
     * @param null|int    $limit      Default value: 1, Max value: 200 (optional)
     * @param null|int    $offset     default:0 (optional)
     * @param null|int    $recvWindow (optional)
     * @param null|string $txId       (optional)
     *
     * @return ApiResponse<GetSubAccountDepositHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSubAccountDepositHistoryWithHttpInfo($email, $coin = null, $status = null, $startTime = null, $endTime = null, $limit = null, $offset = null, $recvWindow = null, $txId = null): ApiResponse
    {
        $request = $this->getSubAccountDepositHistoryRequest($email, $coin, $status, $startTime, $endTime, $limit, $offset, $recvWindow, $txId);

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

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getSubAccountDepositHistory'.
     *
     * @param string      $email      [Sub-account email](#email-address) (required)
     * @param null|string $coin       (optional)
     * @param null|int    $status     0(0:pending,6: credited but cannot withdraw,7:Wrong Deposit,8:Waiting User confirm,1:success) (optional)
     * @param null|int    $startTime  (optional)
     * @param null|int    $endTime    (optional)
     * @param null|int    $limit      Default value: 1, Max value: 200 (optional)
     * @param null|int    $offset     default:0 (optional)
     * @param null|int    $recvWindow (optional)
     * @param null|string $txId       (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function getSubAccountDepositHistoryRequest($email, $coin = null, $status = null, $startTime = null, $endTime = null, $limit = null, $offset = null, $recvWindow = null, $txId = null)
    {
        $contentType = self::contentTypes['getSubAccountDepositHistory'][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 getSubAccountDepositHistory'
            );
        }

        $resourcePath = '/sapi/v1/capital/deposit/subHisrec';
        $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
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $status,
            'status', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $startTime,
            'startTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $endTime,
            'endTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $limit,
            'limit', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $offset,
            'offset', // 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
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $txId,
            'txId', // 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 getSummaryOfSubAccountsFuturesAccount.
     *
     * Get Summary of Sub-account&#39;s Futures Account (For Master Account) (USER_DATA)
     *
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<GetSummaryOfSubAccountsFuturesAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfSubAccountsFuturesAccount($recvWindow = null): ApiResponse
    {
        return $this->getSummaryOfSubAccountsFuturesAccountWithHttpInfo($recvWindow);
    }

    /**
     * Operation getSummaryOfSubAccountsFuturesAccountWithHttpInfo.
     *
     * Get Summary of Sub-account&#39;s Futures Account (For Master Account) (USER_DATA)
     *
     * @param null|int $recvWindow (optional)
     *
     * @return ApiResponse<GetSummaryOfSubAccountsFuturesAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfSubAccountsFuturesAccountWithHttpInfo($recvWindow = null): ApiResponse
    {
        $request = $this->getSummaryOfSubAccountsFuturesAccountRequest($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\GetSummaryOfSubAccountsFuturesAccountResponse',
                        $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\GetSummaryOfSubAccountsFuturesAccountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\GetSummaryOfSubAccountsFuturesAccountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

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

        $resourcePath = '/sapi/v1/sub-account/futures/accountSummary';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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

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

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

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

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

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

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

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

    /**
     * Operation getSummaryOfSubAccountsFuturesAccountV2.
     *
     * Get Summary of Sub-account&#39;s Futures Account V2 (For Master Account) (USER_DATA)
     *
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @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<GetSummaryOfSubAccountsFuturesAccountV2Response>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfSubAccountsFuturesAccountV2($futuresType, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        return $this->getSummaryOfSubAccountsFuturesAccountV2WithHttpInfo($futuresType, $page, $limit, $recvWindow);
    }

    /**
     * Operation getSummaryOfSubAccountsFuturesAccountV2WithHttpInfo.
     *
     * Get Summary of Sub-account&#39;s Futures Account V2 (For Master Account) (USER_DATA)
     *
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @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<GetSummaryOfSubAccountsFuturesAccountV2Response>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfSubAccountsFuturesAccountV2WithHttpInfo($futuresType, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        $request = $this->getSummaryOfSubAccountsFuturesAccountV2Request($futuresType, $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\GetSummaryOfSubAccountsFuturesAccountV2Response',
                        $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\GetSummaryOfSubAccountsFuturesAccountV2Response',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\GetSummaryOfSubAccountsFuturesAccountV2Response',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'getSummaryOfSubAccountsFuturesAccountV2'.
     *
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @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 getSummaryOfSubAccountsFuturesAccountV2Request($futuresType, $page = null, $limit = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['getSummaryOfSubAccountsFuturesAccountV2'][0];

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

        $resourcePath = '/sapi/v2/sub-account/futures/accountSummary';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $futuresType,
            'futuresType', // 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
            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 getSummaryOfSubAccountsMarginAccount.
     *
     * Get Summary of Sub-account&#39;s Margin Account (For Master Account) (USER_DATA)
     *
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<GetSummaryOfSubAccountsMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfSubAccountsMarginAccount($recvWindow = null): ApiResponse
    {
        return $this->getSummaryOfSubAccountsMarginAccountWithHttpInfo($recvWindow);
    }

    /**
     * Operation getSummaryOfSubAccountsMarginAccountWithHttpInfo.
     *
     * Get Summary of Sub-account&#39;s Margin Account (For Master Account) (USER_DATA)
     *
     * @param null|int $recvWindow (optional)
     *
     * @return ApiResponse<GetSummaryOfSubAccountsMarginAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function getSummaryOfSubAccountsMarginAccountWithHttpInfo($recvWindow = null): ApiResponse
    {
        $request = $this->getSummaryOfSubAccountsMarginAccountRequest($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\GetSummaryOfSubAccountsMarginAccountResponse',
                        $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\GetSummaryOfSubAccountsMarginAccountResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\GetSummaryOfSubAccountsMarginAccountResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

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

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

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

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

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

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

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

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

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

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

    /**
     * Operation marginTransferForSubAccount.
     *
     * Margin Transfer for Sub-account (For Master Account) (USER_DATA)
     *
     * @param MarginTransferForSubAccountRequest $marginTransferForSubAccountRequest marginTransferForSubAccountRequest (required)
     *
     * @return ApiResponse<MarginTransferForSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function marginTransferForSubAccount($marginTransferForSubAccountRequest): ApiResponse
    {
        return $this->marginTransferForSubAccountWithHttpInfo($marginTransferForSubAccountRequest);
    }

    /**
     * Operation marginTransferForSubAccountWithHttpInfo.
     *
     * Margin Transfer for Sub-account (For Master Account) (USER_DATA)
     *
     * @param MarginTransferForSubAccountRequest $marginTransferForSubAccountRequest (required)
     *
     * @return ApiResponse<MarginTransferForSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function marginTransferForSubAccountWithHttpInfo($marginTransferForSubAccountRequest): ApiResponse
    {
        $request = $this->marginTransferForSubAccountRequest($marginTransferForSubAccountRequest);

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

                    throw $e;
            }

            throw $e;
        }
    }

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

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

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

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

        $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 movePositionForSubAccount.
     *
     * Move Position for Sub-account (For Master Account) (USER_DATA)
     *
     * @param MovePositionForSubAccountRequest $movePositionForSubAccountRequest movePositionForSubAccountRequest (required)
     *
     * @return ApiResponse<MovePositionForSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function movePositionForSubAccount($movePositionForSubAccountRequest): ApiResponse
    {
        return $this->movePositionForSubAccountWithHttpInfo($movePositionForSubAccountRequest);
    }

    /**
     * Operation movePositionForSubAccountWithHttpInfo.
     *
     * Move Position for Sub-account (For Master Account) (USER_DATA)
     *
     * @param MovePositionForSubAccountRequest $movePositionForSubAccountRequest (required)
     *
     * @return ApiResponse<MovePositionForSubAccountResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function movePositionForSubAccountWithHttpInfo($movePositionForSubAccountRequest): ApiResponse
    {
        $request = $this->movePositionForSubAccountRequest($movePositionForSubAccountRequest);

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

                    throw $e;
            }

            throw $e;
        }
    }

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

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

        $resourcePath = '/sapi/v1/sub-account/futures/move-position';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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

        $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 querySubAccountAssets.
     *
     * Query Sub-account Assets (For Master Account) (USER_DATA)
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<QuerySubAccountAssetsResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function querySubAccountAssets($email, $recvWindow = null): ApiResponse
    {
        return $this->querySubAccountAssetsWithHttpInfo($email, $recvWindow);
    }

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

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'querySubAccountAssets'.
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function querySubAccountAssetsRequest($email, $recvWindow = null)
    {
        $contentType = self::contentTypes['querySubAccountAssets'][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 querySubAccountAssets'
            );
        }

        $resourcePath = '/sapi/v3/sub-account/assets';
        $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 querySubAccountAssetsAssetManagement.
     *
     * Query Sub-account Assets (For Master Account) (USER_DATA)
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<QuerySubAccountAssetsAssetManagementResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function querySubAccountAssetsAssetManagement($email, $recvWindow = null): ApiResponse
    {
        return $this->querySubAccountAssetsAssetManagementWithHttpInfo($email, $recvWindow);
    }

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

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'querySubAccountAssetsAssetManagement'.
     *
     * @param string   $email      [Sub-account email](#email-address) (required)
     * @param null|int $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function querySubAccountAssetsAssetManagementRequest($email, $recvWindow = null)
    {
        $contentType = self::contentTypes['querySubAccountAssetsAssetManagement'][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 querySubAccountAssetsAssetManagement'
            );
        }

        $resourcePath = '/sapi/v4/sub-account/assets';
        $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 querySubAccountFuturesAssetTransferHistory.
     *
     * Query Sub-account Futures Asset Transfer History (For Master Account) (USER_DATA)
     *
     * @param string   $email       [Sub-account email](#email-address) (required)
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @param null|int $startTime   startTime (optional)
     * @param null|int $endTime     endTime (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<QuerySubAccountFuturesAssetTransferHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function querySubAccountFuturesAssetTransferHistory($email, $futuresType, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        return $this->querySubAccountFuturesAssetTransferHistoryWithHttpInfo($email, $futuresType, $startTime, $endTime, $page, $limit, $recvWindow);
    }

    /**
     * Operation querySubAccountFuturesAssetTransferHistoryWithHttpInfo.
     *
     * Query Sub-account Futures Asset Transfer History (For Master Account) (USER_DATA)
     *
     * @param string   $email       [Sub-account email](#email-address) (required)
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @param null|int $startTime   (optional)
     * @param null|int $endTime     (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<QuerySubAccountFuturesAssetTransferHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function querySubAccountFuturesAssetTransferHistoryWithHttpInfo($email, $futuresType, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        $request = $this->querySubAccountFuturesAssetTransferHistoryRequest($email, $futuresType, $startTime, $endTime, $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\QuerySubAccountFuturesAssetTransferHistoryResponse',
                        $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\QuerySubAccountFuturesAssetTransferHistoryResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QuerySubAccountFuturesAssetTransferHistoryResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'querySubAccountFuturesAssetTransferHistory'.
     *
     * @param string   $email       [Sub-account email](#email-address) (required)
     * @param int      $futuresType 1:USDT-margined Futures，2: Coin-margined Futures (required)
     * @param null|int $startTime   (optional)
     * @param null|int $endTime     (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 querySubAccountFuturesAssetTransferHistoryRequest($email, $futuresType, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['querySubAccountFuturesAssetTransferHistory'][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 querySubAccountFuturesAssetTransferHistory'
            );
        }

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

        $resourcePath = '/sapi/v1/sub-account/futures/internalTransfer';
        $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(
            $futuresType,
            'futuresType', // param base name
            'integer', // 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(
            $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 querySubAccountSpotAssetTransferHistory.
     *
     * Query Sub-account Spot Asset Transfer History (For Master Account) (USER_DATA)
     *
     * @param null|string $fromEmail  fromEmail (optional)
     * @param null|string $toEmail    toEmail (optional)
     * @param null|int    $startTime  startTime (optional)
     * @param null|int    $endTime    endTime (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<QuerySubAccountSpotAssetTransferHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function querySubAccountSpotAssetTransferHistory($fromEmail = null, $toEmail = null, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        return $this->querySubAccountSpotAssetTransferHistoryWithHttpInfo($fromEmail, $toEmail, $startTime, $endTime, $page, $limit, $recvWindow);
    }

    /**
     * Operation querySubAccountSpotAssetTransferHistoryWithHttpInfo.
     *
     * Query Sub-account Spot Asset Transfer History (For Master Account) (USER_DATA)
     *
     * @param null|string $fromEmail  (optional)
     * @param null|string $toEmail    (optional)
     * @param null|int    $startTime  (optional)
     * @param null|int    $endTime    (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<QuerySubAccountSpotAssetTransferHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function querySubAccountSpotAssetTransferHistoryWithHttpInfo($fromEmail = null, $toEmail = null, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        $request = $this->querySubAccountSpotAssetTransferHistoryRequest($fromEmail, $toEmail, $startTime, $endTime, $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\QuerySubAccountSpotAssetTransferHistoryResponse',
                        $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\QuerySubAccountSpotAssetTransferHistoryResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QuerySubAccountSpotAssetTransferHistoryResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'querySubAccountSpotAssetTransferHistory'.
     *
     * @param null|string $fromEmail  (optional)
     * @param null|string $toEmail    (optional)
     * @param null|int    $startTime  (optional)
     * @param null|int    $endTime    (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 querySubAccountSpotAssetTransferHistoryRequest($fromEmail = null, $toEmail = null, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['querySubAccountSpotAssetTransferHistory'][0];

        $resourcePath = '/sapi/v1/sub-account/sub/transfer/history';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fromEmail,
            'fromEmail', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $toEmail,
            'toEmail', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $startTime,
            'startTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $endTime,
            'endTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $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 querySubAccountSpotAssetsSummary.
     *
     * Query Sub-account Spot Assets Summary (For Master Account) (USER_DATA)
     *
     * @param null|string $email      Managed sub-account email (optional)
     * @param null|int    $page       Default value: 1 (optional)
     * @param null|int    $size       default 10, max 20 (optional)
     * @param null|int    $recvWindow recvWindow (optional)
     *
     * @return ApiResponse<QuerySubAccountSpotAssetsSummaryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function querySubAccountSpotAssetsSummary($email = null, $page = null, $size = null, $recvWindow = null): ApiResponse
    {
        return $this->querySubAccountSpotAssetsSummaryWithHttpInfo($email, $page, $size, $recvWindow);
    }

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

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'querySubAccountSpotAssetsSummary'.
     *
     * @param null|string $email      Managed sub-account email (optional)
     * @param null|int    $page       Default value: 1 (optional)
     * @param null|int    $size       default 10, max 20 (optional)
     * @param null|int    $recvWindow (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function querySubAccountSpotAssetsSummaryRequest($email = null, $page = null, $size = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['querySubAccountSpotAssetsSummary'][0];

        $resourcePath = '/sapi/v1/sub-account/spotSummary';
        $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(
            $size,
            'size', // 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 queryUniversalTransferHistory.
     *
     * Query Universal Transfer History (For Master Account) (USER_DATA)
     *
     * @param null|string $fromEmail    fromEmail (optional)
     * @param null|string $toEmail      toEmail (optional)
     * @param null|string $clientTranId clientTranId (optional)
     * @param null|int    $startTime    startTime (optional)
     * @param null|int    $endTime      endTime (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<QueryUniversalTransferHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryUniversalTransferHistory($fromEmail = null, $toEmail = null, $clientTranId = null, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        return $this->queryUniversalTransferHistoryWithHttpInfo($fromEmail, $toEmail, $clientTranId, $startTime, $endTime, $page, $limit, $recvWindow);
    }

    /**
     * Operation queryUniversalTransferHistoryWithHttpInfo.
     *
     * Query Universal Transfer History (For Master Account) (USER_DATA)
     *
     * @param null|string $fromEmail    (optional)
     * @param null|string $toEmail      (optional)
     * @param null|string $clientTranId (optional)
     * @param null|int    $startTime    (optional)
     * @param null|int    $endTime      (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<QueryUniversalTransferHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function queryUniversalTransferHistoryWithHttpInfo($fromEmail = null, $toEmail = null, $clientTranId = null, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null): ApiResponse
    {
        $request = $this->queryUniversalTransferHistoryRequest($fromEmail, $toEmail, $clientTranId, $startTime, $endTime, $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\QueryUniversalTransferHistoryResponse',
                        $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\QueryUniversalTransferHistoryResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\QueryUniversalTransferHistoryResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'queryUniversalTransferHistory'.
     *
     * @param null|string $fromEmail    (optional)
     * @param null|string $toEmail      (optional)
     * @param null|string $clientTranId (optional)
     * @param null|int    $startTime    (optional)
     * @param null|int    $endTime      (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 queryUniversalTransferHistoryRequest($fromEmail = null, $toEmail = null, $clientTranId = null, $startTime = null, $endTime = null, $page = null, $limit = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['queryUniversalTransferHistory'][0];

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

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $fromEmail,
            'fromEmail', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $toEmail,
            'toEmail', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $clientTranId,
            'clientTranId', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $startTime,
            'startTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $endTime,
            'endTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $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 subAccountFuturesAssetTransfer.
     *
     * Sub-account Futures Asset Transfer (For Master Account) (USER_DATA)
     *
     * @param SubAccountFuturesAssetTransferRequest $subAccountFuturesAssetTransferRequest subAccountFuturesAssetTransferRequest (required)
     *
     * @return ApiResponse<SubAccountFuturesAssetTransferResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function subAccountFuturesAssetTransfer($subAccountFuturesAssetTransferRequest): ApiResponse
    {
        return $this->subAccountFuturesAssetTransferWithHttpInfo($subAccountFuturesAssetTransferRequest);
    }

    /**
     * Operation subAccountFuturesAssetTransferWithHttpInfo.
     *
     * Sub-account Futures Asset Transfer (For Master Account) (USER_DATA)
     *
     * @param SubAccountFuturesAssetTransferRequest $subAccountFuturesAssetTransferRequest (required)
     *
     * @return ApiResponse<SubAccountFuturesAssetTransferResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function subAccountFuturesAssetTransferWithHttpInfo($subAccountFuturesAssetTransferRequest): ApiResponse
    {
        $request = $this->subAccountFuturesAssetTransferRequest($subAccountFuturesAssetTransferRequest);

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

                    throw $e;
            }

            throw $e;
        }
    }

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

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

        $resourcePath = '/sapi/v1/sub-account/futures/internalTransfer';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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

        $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 subAccountTransferHistory.
     *
     * Sub-account Transfer History (For Sub-account) (USER_DATA)
     *
     * @param null|string $asset             If not sent, result of all assets will be returned (optional)
     * @param null|int    $type              1: transfer in, 2: transfer out (optional)
     * @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|bool   $returnFailHistory Default &#x60;False&#x60;, return PROCESS and SUCCESS status history; If &#x60;True&#x60;,return PROCESS and SUCCESS and FAILURE status history (optional)
     * @param null|int    $recvWindow        recvWindow (optional)
     *
     * @return ApiResponse<SubAccountTransferHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function subAccountTransferHistory($asset = null, $type = null, $startTime = null, $endTime = null, $limit = null, $returnFailHistory = null, $recvWindow = null): ApiResponse
    {
        return $this->subAccountTransferHistoryWithHttpInfo($asset, $type, $startTime, $endTime, $limit, $returnFailHistory, $recvWindow);
    }

    /**
     * Operation subAccountTransferHistoryWithHttpInfo.
     *
     * Sub-account Transfer History (For Sub-account) (USER_DATA)
     *
     * @param null|string $asset             If not sent, result of all assets will be returned (optional)
     * @param null|int    $type              1: transfer in, 2: transfer out (optional)
     * @param null|int    $startTime         (optional)
     * @param null|int    $endTime           (optional)
     * @param null|int    $limit             Default value: 1, Max value: 200 (optional)
     * @param null|bool   $returnFailHistory Default &#x60;False&#x60;, return PROCESS and SUCCESS status history; If &#x60;True&#x60;,return PROCESS and SUCCESS and FAILURE status history (optional)
     * @param null|int    $recvWindow        (optional)
     *
     * @return ApiResponse<SubAccountTransferHistoryResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function subAccountTransferHistoryWithHttpInfo($asset = null, $type = null, $startTime = null, $endTime = null, $limit = null, $returnFailHistory = null, $recvWindow = null): ApiResponse
    {
        $request = $this->subAccountTransferHistoryRequest($asset, $type, $startTime, $endTime, $limit, $returnFailHistory, $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\SubAccountTransferHistoryResponse',
                        $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\SubAccountTransferHistoryResponse',
                $request,
                $response,
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        '\Binance\Client\SubAccount\Model\SubAccountTransferHistoryResponse',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);

                    throw $e;
            }

            throw $e;
        }
    }

    /**
     * Create request for operation 'subAccountTransferHistory'.
     *
     * @param null|string $asset             If not sent, result of all assets will be returned (optional)
     * @param null|int    $type              1: transfer in, 2: transfer out (optional)
     * @param null|int    $startTime         (optional)
     * @param null|int    $endTime           (optional)
     * @param null|int    $limit             Default value: 1, Max value: 200 (optional)
     * @param null|bool   $returnFailHistory Default &#x60;False&#x60;, return PROCESS and SUCCESS status history; If &#x60;True&#x60;,return PROCESS and SUCCESS and FAILURE status history (optional)
     * @param null|int    $recvWindow        (optional)
     *
     * @return Request
     *
     * @throws \InvalidArgumentException
     */
    public function subAccountTransferHistoryRequest($asset = null, $type = null, $startTime = null, $endTime = null, $limit = null, $returnFailHistory = null, $recvWindow = null)
    {
        $contentType = self::contentTypes['subAccountTransferHistory'][0];

        $resourcePath = '/sapi/v1/sub-account/transfer/subUserHistory';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $asset,
            'asset', // param base name
            'string', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $type,
            'type', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $startTime,
            'startTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $endTime,
            'endTime', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $limit,
            'limit', // param base name
            'integer', // openApiType
            'form', // style
            true, // explode
            false // required
        ) ?? []);
        // query params
        $queryParams = array_merge($queryParams, ObjectSerializer::toQueryValue(
            $returnFailHistory,
            'returnFailHistory', // param base name
            'boolean', // 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 transferToMaster.
     *
     * Transfer to Master (For Sub-account) (USER_DATA)
     *
     * @param TransferToMasterRequest $transferToMasterRequest transferToMasterRequest (required)
     *
     * @return ApiResponse<TransferToMasterResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function transferToMaster($transferToMasterRequest): ApiResponse
    {
        return $this->transferToMasterWithHttpInfo($transferToMasterRequest);
    }

    /**
     * Operation transferToMasterWithHttpInfo.
     *
     * Transfer to Master (For Sub-account) (USER_DATA)
     *
     * @param TransferToMasterRequest $transferToMasterRequest (required)
     *
     * @return ApiResponse<TransferToMasterResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function transferToMasterWithHttpInfo($transferToMasterRequest): ApiResponse
    {
        $request = $this->transferToMasterRequest($transferToMasterRequest);

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

                    throw $e;
            }

            throw $e;
        }
    }

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

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

        $resourcePath = '/sapi/v1/sub-account/transfer/subToMaster';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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

        $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 transferToSubAccountOfSameMaster.
     *
     * Transfer to Sub-account of Same Master (For Sub-account) (USER_DATA)
     *
     * @param TransferToSubAccountOfSameMasterRequest $transferToSubAccountOfSameMasterRequest transferToSubAccountOfSameMasterRequest (required)
     *
     * @return ApiResponse<TransferToSubAccountOfSameMasterResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function transferToSubAccountOfSameMaster($transferToSubAccountOfSameMasterRequest): ApiResponse
    {
        return $this->transferToSubAccountOfSameMasterWithHttpInfo($transferToSubAccountOfSameMasterRequest);
    }

    /**
     * Operation transferToSubAccountOfSameMasterWithHttpInfo.
     *
     * Transfer to Sub-account of Same Master (For Sub-account) (USER_DATA)
     *
     * @param TransferToSubAccountOfSameMasterRequest $transferToSubAccountOfSameMasterRequest (required)
     *
     * @return ApiResponse<TransferToSubAccountOfSameMasterResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function transferToSubAccountOfSameMasterWithHttpInfo($transferToSubAccountOfSameMasterRequest): ApiResponse
    {
        $request = $this->transferToSubAccountOfSameMasterRequest($transferToSubAccountOfSameMasterRequest);

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

                    throw $e;
            }

            throw $e;
        }
    }

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

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

        $resourcePath = '/sapi/v1/sub-account/transfer/subToSub';
        $formParams = [];
        $queryParams = [];
        $headerParams = [];
        $httpBody = '';
        $multipart = false;

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

        $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 universalTransfer.
     *
     * Universal Transfer (For Master Account) (USER_DATA)
     *
     * @param UniversalTransferRequest $universalTransferRequest universalTransferRequest (required)
     *
     * @return ApiResponse<UniversalTransferResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function universalTransfer($universalTransferRequest): ApiResponse
    {
        return $this->universalTransferWithHttpInfo($universalTransferRequest);
    }

    /**
     * Operation universalTransferWithHttpInfo.
     *
     * Universal Transfer (For Master Account) (USER_DATA)
     *
     * @param UniversalTransferRequest $universalTransferRequest (required)
     *
     * @return ApiResponse<UniversalTransferResponse>
     *
     * @throws ApiException              on non-2xx response or if the response body is not in the expected format
     * @throws \InvalidArgumentException
     */
    public function universalTransferWithHttpInfo($universalTransferRequest): ApiResponse
    {
        $request = $this->universalTransferRequest($universalTransferRequest);

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

                    throw $e;
            }

            throw $e;
        }
    }

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

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

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

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

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