Test Failed
Pull Request — master (#13)
by Vladislav
09:26 queued 01:13
created

TradeHistoryTest::testBuildResponseData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 21
nc 2
nop 0
dl 0
loc 25
rs 9.584
c 0
b 0
f 0
1
<?php
2
namespace Carpenstar\ByBitAPI\Spot\Trade\TradeHistory\Tests;
3
4
use Carpenstar\ByBitAPI\BybitAPI;
5
use Carpenstar\ByBitAPI\Core\Exceptions\SDKException;
6
use Carpenstar\ByBitAPI\Core\Response\CurlResponseHandler;
7
use Carpenstar\ByBitAPI\Spot\Trade\TradeHistory\Request\TradeHistoryRequest;
8
use Carpenstar\ByBitAPI\Spot\Trade\TradeHistory\Response\TradeHistoryResponse;
9
use Carpenstar\ByBitAPI\Spot\Trade\TradeHistory\TradeHistory;
10
use PHPUnit\Framework\TestCase;
11
12
class TradeHistoryTest extends TestCase
13
{
14
    /**
15
     * Тестирование заполнения структуры ответа
16
     * @return void
17
     */
18
    public function testBuildResponseData()
19
    {
20
        $json = '{"retCode":0,"retMsg":"OK","result":{"list":[{"symbol":"BTCUSDT","id":"1210346127973428992","orderId":"1210073515485572864","tradeId":"2100000000001769786","orderPrice":"20500","orderQty":"0.02","execFee":"0.00002","feeTokenId":"BTC","creatTime":"1659020488738","isBuyer": "0","isMaker":"0", "matchOrderId":"1210346015893229312","makerRebate":"0","executionTime":"1659020502026","blockTradeId":""},{"symbol":"BTCUSDT","id":"1208702504949264128","orderId":"1208702504731160320","tradeId":"2100000000001753197","orderPrice":"20240","orderQty":"0.009881","execFee":"0.000009881","feeTokenId":"BTC","creatTime":"1658824566874","isBuyer":"0","isMaker":"1","matchOrderId":"1208677465155702529","makerRebate":"0","executionTime":"1658824566893","blockTradeId":""}]}, "retExtMap": {},"retExtInfo": {},"time":1659084254366}';
21
        $data = (new CurlResponseHandler())->build(json_decode($json, true), TradeHistoryResponse::class);
22
23
        $this->assertEquals(0, $data->getReturnCode());
24
        $this->assertEquals('OK', $data->getReturnMessage());
25
        $this->assertInstanceOf(TradeHistoryResponse::class, $data->getResult());
26
27
        $tradeHistory = $data->getResult();
28
        foreach ($tradeHistory->getTradeHistory() as $trade) {
0 ignored issues
show
Bug introduced by
The method getTradeHistory() does not exist on Carpenstar\ByBitAPI\Core\Objects\AbstractResponse. It seems like you code against a sub-type of Carpenstar\ByBitAPI\Core\Objects\AbstractResponse such as Carpenstar\ByBitAPI\Spot...se\TradeHistoryResponse. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        foreach ($tradeHistory->/** @scrutinizer ignore-call */ getTradeHistory() as $trade) {
Loading history...
29
            $this->assertIsString($trade->getSymbol());
30
            $this->assertIsInt($trade->getId());
31
            $this->assertIsInt($trade->getOrderId());
32
            $this->assertIsInt($trade->getTradeId());
33
            $this->assertIsFloat($trade->getOrderPrice());
34
            $this->assertIsFloat($trade->getOrderQty());
35
            $this->assertIsFloat($trade->getExecFee());
36
            $this->assertIsString($trade->getFeeTokenId());
37
            $this->assertInstanceOf(\DateTime::class, $trade->getCreatTime());
38
            $this->assertIsInt($trade->getIsBuyer());
39
            $this->assertIsInt($trade->getIsMaker());
40
            $this->assertIsInt($trade->getMatchOrderId());
41
            $this->assertIsInt($trade->getMakerRebate());
42
            $this->assertInstanceOf(\DateTime::class, $trade->getExecutionTime());
43
        }
44
    }
45
46
    /**
47
     * Тестирование эндпоинта на корректное исполнение
48
     * @return void
49
     * @throws SDKException
50
     */
51
    public function testTradeHistoryEndpoint()
52
    {
53
        $bybit = (new BybitAPI())
54
            ->setCredentials('https://api-testnet.bybit.com', 'fL02oi5qo8i2jDxlum', 'Ne1EE35XTprIWrId9vGEAc1ZYJTmodA4qFzZ');
55
56
        $orderHistoryResponse = $bybit->privateEndpoint(TradeHistory::class, (new TradeHistoryRequest())->setSymbol('ETHUSDT'))->execute();
57
58
        $this->assertEquals(0, $orderHistoryResponse->getReturnCode());
59
        $this->assertEquals('OK', $orderHistoryResponse->getReturnMessage());
60
        $this->assertInstanceOf(TradeHistoryResponse::class, $orderHistoryResponse->getResult());
61
62
        $tradeInfoList = $orderHistoryResponse->getResult()->getTradeHistory();
63
64
        foreach ($tradeInfoList as $trade) {
65
            $this->assertIsString($trade->getSymbol());
66
            $this->assertIsInt($trade->getId());
67
            $this->assertIsInt($trade->getOrderId());
68
            $this->assertIsInt($trade->getTradeId());
69
            $this->assertIsFloat($trade->getOrderPrice());
70
            $this->assertIsFloat($trade->getOrderQty());
71
            $this->assertIsFloat($trade->getExecFee());
72
            $this->assertIsString($trade->getFeeTokenId());
73
            $this->assertInstanceOf(\DateTime::class, $trade->getCreatTime());
74
            $this->assertIsInt($trade->getIsBuyer());
75
            $this->assertIsInt($trade->getIsMaker());
76
            $this->assertIsInt($trade->getMatchOrderId());
77
            $this->assertIsInt($trade->getMakerRebate());
78
            $this->assertInstanceOf(\DateTime::class, $trade->getExecutionTime());
79
        }
80
    }
81
}