<?php

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

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

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Please update the test case below to test the endpoint.
 */

namespace Binance\Client\MarginTrading\Test\Api;

use Binance\Client\MarginTrading\Api\TradeApi;
use Binance\Client\MarginTrading\Model\AssetNames;
use Binance\Client\MarginTrading\Model\CreateSpecialKeyRequest;
use Binance\Client\MarginTrading\Model\EditIpForSpecialKeyRequest;
use Binance\Client\MarginTrading\Model\MarginAccountNewOcoRequest;
use Binance\Client\MarginTrading\Model\MarginAccountNewOrderRequest;
use Binance\Client\MarginTrading\Model\MarginAccountNewOtocoRequest;
use Binance\Client\MarginTrading\Model\MarginAccountNewOtoRequest;
use Binance\Client\MarginTrading\Model\MarginManualLiquidationRequest;
use Binance\Client\MarginTrading\Model\Side;
use Binance\Client\MarginTrading\Model\SmallLiabilityExchangeRequest;
use Binance\Common\Configuration\ClientConfiguration;
use Binance\Common\Configuration\SignatureConfiguration;
use Binance\Common\HttpClient;
use GuzzleHttp\Psr7\Utils;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;

/**
 * TradeApiTest Class Doc Comment.
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @internal
 *
 * @coversNothing
 */
class TradeApiTest extends TestCase
{
    public function getApiMock(&$request)
    {
        $clientMock = $this->createMock(HttpClient::class);
        $signatureConfig = new SignatureConfiguration();
        $signatureConfig->setApiKey('apiKey');
        $signatureConfig->setSecretKey('secretKey');
        $clientConfig = new ClientConfiguration();
        $clientConfig->setUrl('http://localhost:8080');
        $clientConfig->setSignatureConfiguration($signatureConfig);
        $responseMock = $this->createMock(ResponseInterface::class);

        $responseMock->expects($this->any())
            ->method('getStatusCode')
            ->willReturn(200)
        ;

        $responseMock->expects($this->any())
            ->method('getBody')
            ->willReturn(Utils::streamFor('{}'))
        ;

        $clientMock->expects($this->once())
            ->method('send')
            ->will($this->returnCallback(function ($actualRequest) use (&$request, $responseMock) {
                $request = $actualRequest;

                return $responseMock;
            }))
        ;

        $apiMock = $this->getMockBuilder(TradeApi::class)
            ->setConstructorArgs([$clientConfig, $clientMock])
            ->onlyMethods(['getTimestamp'])
            ->getMock()
        ;

        $apiMock->method('getTimestamp')->willReturn('1736393892000');

        return $apiMock;
    }

    /**
     * Test case for createSpecialKey.
     *
     * Create Special Key(Low-Latency Trading)(TRADE).
     */
    public function testCreateSpecialKey()
    {
        $createSpecialKeyRequest = new CreateSpecialKeyRequest();
        $createSpecialKeyRequest->setApiName('');

        $response = $this->getApiMock($request)->createSpecialKey($createSpecialKeyRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/apiKey', $request->getUri()->getPath());
        self::assertEquals('5b6da8754f9a162890073c441b4fb686c6c01e6e124d5c181285ab1061b0406b', $queryMap['signature']);
    }

    /**
     * Test case for deleteSpecialKey.
     *
     * Delete Special Key(Low-Latency Trading)(TRADE).
     */
    public function testDeleteSpecialKey()
    {
        $apiName = '';
        $symbol = '';
        $recvWindow = 5000;
        $this->getApiMock($request)->deleteSpecialKey($apiName, $symbol, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals('/sapi/v1/margin/apiKey', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for editIpForSpecialKey.
     *
     * Edit ip for Special Key(Low-Latency Trading)(TRADE).
     */
    public function testEditIpForSpecialKey()
    {
        $editIpForSpecialKeyRequest = new EditIpForSpecialKeyRequest();
        $editIpForSpecialKeyRequest->setIp('');

        $this->getApiMock($request)->editIpForSpecialKey($editIpForSpecialKeyRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals('/sapi/v1/margin/apiKey/ip', $request->getUri()->getPath());
        self::assertEquals('7093fecfa62ee85cc50f4d669abdd401d22f3fd6d54ace4ec570339639cc519a', $queryMap['signature']);
    }

    /**
     * Test case for getForceLiquidationRecord.
     *
     * Get Force Liquidation Record (USER_DATA).
     */
    public function testGetForceLiquidationRecord()
    {
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $isolatedSymbol = '';
        $current = 1;
        $size = 10;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getForceLiquidationRecord($startTime, $endTime, $isolatedSymbol, $current, $size, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/forceLiquidationRec', $request->getUri()->getPath());
        self::assertEquals('2ecc0415a3bdb2963e8030cdf6cf00de6f49d21b71ff939dda42e5756eb8ba66', $queryMap['signature']);
    }

    /**
     * Test case for getSmallLiabilityExchangeCoinList.
     *
     * Get Small Liability Exchange Coin List (USER_DATA).
     */
    public function testGetSmallLiabilityExchangeCoinList()
    {
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSmallLiabilityExchangeCoinList($recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/exchange-small-liability', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for getSmallLiabilityExchangeHistory.
     *
     * Get Small Liability Exchange History (USER_DATA).
     */
    public function testGetSmallLiabilityExchangeHistory()
    {
        $current = 1;
        $size = 10;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->getSmallLiabilityExchangeHistory($current, $size, $startTime, $endTime, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/exchange-small-liability-history', $request->getUri()->getPath());
        self::assertEquals('cf3665c6ad1ae7c4af54fc90d8cae844164449f5f850748c21373dd86013616b', $queryMap['signature']);
    }

    /**
     * Test case for marginAccountCancelAllOpenOrdersOnASymbol.
     *
     * Margin Account Cancel all Open Orders on a Symbol (TRADE).
     */
    public function testMarginAccountCancelAllOpenOrdersOnASymbol()
    {
        $symbol = '';
        $isIsolated = 'false';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->marginAccountCancelAllOpenOrdersOnASymbol($symbol, $isIsolated, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/openOrders', $request->getUri()->getPath());
        self::assertEquals('add65e05865fdd18a5031b8cd03b817c53044ab47bc775e023898c5f451f9fab', $queryMap['signature']);
    }

    /**
     * Test case for marginAccountCancelOco.
     *
     * Margin Account Cancel OCO (TRADE).
     */
    public function testMarginAccountCancelOco()
    {
        $symbol = '';
        $isIsolated = 'false';
        $orderListId = 1;
        $listClientOrderId = '1';
        $newClientOrderId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->marginAccountCancelOco($symbol, $isIsolated, $orderListId, $listClientOrderId, $newClientOrderId, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/orderList', $request->getUri()->getPath());
        self::assertEquals('b9b55143daefd9ab6b09b85bfeb910d085e7558d9dc486af9975f9815ca1f72a', $queryMap['signature']);
    }

    /**
     * Test case for marginAccountCancelOrder.
     *
     * Margin Account Cancel Order (TRADE).
     */
    public function testMarginAccountCancelOrder()
    {
        $symbol = '';
        $isIsolated = 'false';
        $orderId = 1;
        $origClientOrderId = '1';
        $newClientOrderId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->marginAccountCancelOrder($symbol, $isIsolated, $orderId, $origClientOrderId, $newClientOrderId, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/order', $request->getUri()->getPath());
        self::assertEquals('524eb7d8ebb73bd66897f739ec254947072e8149af95053fd246d59bc6cff1f3', $queryMap['signature']);
    }

    /**
     * Test case for marginAccountNewOco.
     *
     * Margin Account New OCO (TRADE).
     */
    public function testMarginAccountNewOco()
    {
        $marginAccountNewOcoRequest = new MarginAccountNewOcoRequest();
        $marginAccountNewOcoRequest->setSymbol('');
        $marginAccountNewOcoRequest->setSide(Side::BUY);
        $marginAccountNewOcoRequest->setQuantity(1.0);
        $marginAccountNewOcoRequest->setPrice(1.0);
        $marginAccountNewOcoRequest->setStopPrice(1.0);

        $response = $this->getApiMock($request)->marginAccountNewOco($marginAccountNewOcoRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/order/oco', $request->getUri()->getPath());
        self::assertEquals('8cf51e6addee22c6a5feaec76a56050bd7b7834d13c90b3a075fdcc0ecccedcc', $queryMap['signature']);
    }

    /**
     * Test case for marginAccountNewOrder.
     *
     * Margin Account New Order (TRADE).
     */
    public function testMarginAccountNewOrder()
    {
        $marginAccountNewOrderRequest = new MarginAccountNewOrderRequest();
        $marginAccountNewOrderRequest->setSymbol('');
        $marginAccountNewOrderRequest->setSide(Side::BUY);
        $marginAccountNewOrderRequest->setType('');

        $response = $this->getApiMock($request)->marginAccountNewOrder($marginAccountNewOrderRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/order', $request->getUri()->getPath());
        self::assertEquals('2cb0badbb7aa9dcc202c9eb7a490346d9b1444ead428cc697587340c4ffefff0', $queryMap['signature']);
    }

    /**
     * Test case for marginAccountNewOto.
     *
     * Margin Account New OTO (TRADE).
     */
    public function testMarginAccountNewOto()
    {
        $marginAccountNewOtoRequest = new MarginAccountNewOtoRequest();
        $marginAccountNewOtoRequest->setSymbol('');
        $marginAccountNewOtoRequest->setWorkingType('');
        $marginAccountNewOtoRequest->setWorkingSide('');
        $marginAccountNewOtoRequest->setWorkingPrice(1.0);
        $marginAccountNewOtoRequest->setWorkingQuantity(1.0);
        $marginAccountNewOtoRequest->setWorkingIcebergQty(1.0);
        $marginAccountNewOtoRequest->setPendingType('Order Types');
        $marginAccountNewOtoRequest->setPendingSide('');
        $marginAccountNewOtoRequest->setPendingQuantity(1.0);

        $response = $this->getApiMock($request)->marginAccountNewOto($marginAccountNewOtoRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/order/oto', $request->getUri()->getPath());
        self::assertEquals('211a091089033ee4cacfa689c3d17b496d85551156eb34f1706d21f4a5be3206', $queryMap['signature']);
    }

    /**
     * Test case for marginAccountNewOtoco.
     *
     * Margin Account New OTOCO (TRADE).
     */
    public function testMarginAccountNewOtoco()
    {
        $marginAccountNewOtocoRequest = new MarginAccountNewOtocoRequest();
        $marginAccountNewOtocoRequest->setSymbol('');
        $marginAccountNewOtocoRequest->setWorkingType('');
        $marginAccountNewOtocoRequest->setWorkingSide('');
        $marginAccountNewOtocoRequest->setWorkingPrice(1.0);
        $marginAccountNewOtocoRequest->setWorkingQuantity(1.0);
        $marginAccountNewOtocoRequest->setPendingSide('');
        $marginAccountNewOtocoRequest->setPendingQuantity(1.0);
        $marginAccountNewOtocoRequest->setPendingAboveType('');

        $response = $this->getApiMock($request)->marginAccountNewOtoco($marginAccountNewOtocoRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/order/otoco', $request->getUri()->getPath());
        self::assertEquals('40b54a18785bfe9afa1a95470e06a42a3323605f3ea4cf873313cc3e9cfcea79', $queryMap['signature']);
    }

    /**
     * Test case for marginManualLiquidation.
     *
     * Margin Manual Liquidation(MARGIN).
     */
    public function testMarginManualLiquidation()
    {
        $marginManualLiquidationRequest = new MarginManualLiquidationRequest();
        $marginManualLiquidationRequest->setType('');

        $response = $this->getApiMock($request)->marginManualLiquidation($marginManualLiquidationRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/manual-liquidation', $request->getUri()->getPath());
        self::assertEquals('c3cb51190a7d7b0749bdf4789709d2715f7e7649fdcaa5bdb8da0b1337b5065c', $queryMap['signature']);
    }

    /**
     * Test case for queryCurrentMarginOrderCountUsage.
     *
     * Query Current Margin Order Count Usage (TRADE).
     */
    public function testQueryCurrentMarginOrderCountUsage()
    {
        $isIsolated = 'false';
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryCurrentMarginOrderCountUsage($isIsolated, $symbol, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/rateLimit/order', $request->getUri()->getPath());
        self::assertEquals('75d217e43fee29be5553782b49783dcd4725af0d24595ebf4c02097f8173a0c5', $queryMap['signature']);
    }

    /**
     * Test case for queryMarginAccountsAllOco.
     *
     * Query Margin Account's all OCO (USER_DATA).
     */
    public function testQueryMarginAccountsAllOco()
    {
        $isIsolated = 'false';
        $symbol = '';
        $fromId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMarginAccountsAllOco($isIsolated, $symbol, $fromId, $startTime, $endTime, $limit, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/allOrderList', $request->getUri()->getPath());
        self::assertEquals('d3c4ac9ae9e87fc4a0e0d0acce0754c1b722a66bec1300211ce26e9fe0a1c27a', $queryMap['signature']);
    }

    /**
     * Test case for queryMarginAccountsAllOrders.
     *
     * Query Margin Account's All Orders (USER_DATA).
     */
    public function testQueryMarginAccountsAllOrders()
    {
        $symbol = '';
        $isIsolated = 'false';
        $orderId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMarginAccountsAllOrders($symbol, $isIsolated, $orderId, $startTime, $endTime, $limit, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/allOrders', $request->getUri()->getPath());
        self::assertEquals('b19144d8ecaee65d9a44334e0bff7233225b2e742455de322f7d6cee6585236d', $queryMap['signature']);
    }

    /**
     * Test case for queryMarginAccountsOco.
     *
     * Query Margin Account's OCO (USER_DATA).
     */
    public function testQueryMarginAccountsOco()
    {
        $isIsolated = 'false';
        $symbol = '';
        $orderListId = 1;
        $origClientOrderId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMarginAccountsOco($isIsolated, $symbol, $orderListId, $origClientOrderId, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/orderList', $request->getUri()->getPath());
        self::assertEquals('f1a87feba8b7af2ae2788e3c860bdf69a9b2e9419cbbeeb8b6e63848db437bf9', $queryMap['signature']);
    }

    /**
     * Test case for queryMarginAccountsOpenOco.
     *
     * Query Margin Account's Open OCO (USER_DATA).
     */
    public function testQueryMarginAccountsOpenOco()
    {
        $isIsolated = 'false';
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMarginAccountsOpenOco($isIsolated, $symbol, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/openOrderList', $request->getUri()->getPath());
        self::assertEquals('75d217e43fee29be5553782b49783dcd4725af0d24595ebf4c02097f8173a0c5', $queryMap['signature']);
    }

    /**
     * Test case for queryMarginAccountsOpenOrders.
     *
     * Query Margin Account's Open Orders (USER_DATA).
     */
    public function testQueryMarginAccountsOpenOrders()
    {
        $symbol = '';
        $isIsolated = 'false';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMarginAccountsOpenOrders($symbol, $isIsolated, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/openOrders', $request->getUri()->getPath());
        self::assertEquals('75d217e43fee29be5553782b49783dcd4725af0d24595ebf4c02097f8173a0c5', $queryMap['signature']);
    }

    /**
     * Test case for queryMarginAccountsOrder.
     *
     * Query Margin Account's Order (USER_DATA).
     */
    public function testQueryMarginAccountsOrder()
    {
        $symbol = '';
        $isIsolated = 'false';
        $orderId = 1;
        $origClientOrderId = '1';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMarginAccountsOrder($symbol, $isIsolated, $orderId, $origClientOrderId, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/order', $request->getUri()->getPath());
        self::assertEquals('28c77d755a10d018e01fcdf7982e25569fd38c91bd89e0dea2a98c986cebd842', $queryMap['signature']);
    }

    /**
     * Test case for queryMarginAccountsTradeList.
     *
     * Query Margin Account's Trade List (USER_DATA).
     */
    public function testQueryMarginAccountsTradeList()
    {
        $symbol = '';
        $isIsolated = 'false';
        $orderId = 1;
        $startTime = 1623319461670;
        $endTime = 1641782889000;
        $fromId = 1;
        $limit = 500;
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->queryMarginAccountsTradeList($symbol, $isIsolated, $orderId, $startTime, $endTime, $fromId, $limit, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/myTrades', $request->getUri()->getPath());
        self::assertEquals('54ee52c6763e418b1d66b1520323fe3d0b3ace00a4e5fe68bd2fa0513d8d93e7', $queryMap['signature']);
    }

    /**
     * Test case for querySpecialKey.
     *
     * Query Special key(Low Latency Trading)(TRADE).
     */
    public function testQuerySpecialKey()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySpecialKey($symbol, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/apiKey', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for querySpecialKeyList.
     *
     * Query Special key List(Low Latency Trading)(TRADE).
     */
    public function testQuerySpecialKeyList()
    {
        $symbol = '';
        $recvWindow = 5000;
        $response = $this->getApiMock($request)->querySpecialKeyList($symbol, $recvWindow);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals(200, $response->getStatusCode());
        self::assertEquals('/sapi/v1/margin/api-key-list', $request->getUri()->getPath());
        self::assertEquals('2cdd1e484bce80021437bee6b762e6a276b1954c3a0c011a16f6f2f6a47aba75', $queryMap['signature']);
    }

    /**
     * Test case for smallLiabilityExchange.
     *
     * Small Liability Exchange (MARGIN).
     */
    public function testSmallLiabilityExchange()
    {
        $smallLiabilityExchangeRequest = new SmallLiabilityExchangeRequest();
        $smallLiabilityExchangeRequest->setAssetNames(new AssetNames());

        $this->getApiMock($request)->smallLiabilityExchange($smallLiabilityExchangeRequest);

        parse_str($request->getUri(), $queryMap);

        self::assertEquals('/sapi/v1/margin/exchange-small-liability', $request->getUri()->getPath());
        self::assertEquals('53668e00dc92eb93de0b253c301e9fc0c20042b13db384a0ad94b38688a5a84c', $queryMap['signature']);
    }
}
