1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\PublicTradingHistory\Tests; |
4
|
|
|
|
5
|
|
|
use Carpenstar\ByBitAPI\BybitAPI; |
6
|
|
|
use Carpenstar\ByBitAPI\Derivatives\MarketData\PublicTradingHistory\PublicTradingHistory; |
7
|
|
|
use Carpenstar\ByBitAPI\Derivatives\MarketData\PublicTradingHistory\Request\PublicTradingHistoryRequest; |
8
|
|
|
use Carpenstar\ByBitAPI\Derivatives\MarketData\PublicTradingHistory\Response\PublicTradingHistoryResponse; |
9
|
|
|
use Carpenstar\ByBitAPI\Derivatives\MarketData\PublicTradingHistory\Response\PublicTradingHistoryResponseItem; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class PublicTradingHistoryTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testPublicTradingHistoryEndpoint() |
15
|
|
|
{ |
16
|
|
|
echo "\n //// --- //// \n"; |
17
|
|
|
|
18
|
|
|
$bybit = (new BybitAPI())->setCredentials('https://api-testnet.bybit.com'); |
19
|
|
|
|
20
|
|
|
$response = $bybit->publicEndpoint( |
21
|
|
|
PublicTradingHistory::class, |
22
|
|
|
(new PublicTradingHistoryRequest()) |
23
|
|
|
->setSymbol('BTCUSDT') |
24
|
|
|
->setLimit(3) |
25
|
|
|
)->execute(); |
26
|
|
|
|
27
|
|
|
if ($response->getReturnCode() == 0) { |
28
|
|
|
echo "CODE: {$response->getReturnCode()}\n"; |
29
|
|
|
echo "MESSAGE: {$response->getReturnMessage()}\n"; |
30
|
|
|
|
31
|
|
|
/** @var PublicTradingHistoryResponse $tradeHistoryList */ |
32
|
|
|
$tradeHistoryList = $response->getResult(); |
33
|
|
|
|
34
|
|
|
echo "Trade history data: \n"; |
35
|
|
|
/** @var PublicTradingHistoryResponseItem $historyItem */ |
36
|
|
|
foreach ($tradeHistoryList->getTradingList() as $historyItem) { |
37
|
|
|
echo " --- \n"; |
38
|
|
|
echo "Time: {$historyItem->getTime()->format('Y-m-d H:i:s')}\n"; |
39
|
|
|
echo "Exec ID: {$historyItem->getExecId()}\n"; |
40
|
|
|
echo "Symbol: {$historyItem->getSymbol()}\n"; |
41
|
|
|
echo "Price: {$historyItem->getPrice()}\n"; |
42
|
|
|
echo "Size: {$historyItem->getSize()}\n"; |
43
|
|
|
echo "Side: {$historyItem->getSide()}\n"; |
44
|
|
|
echo "Is Block Trade: {$historyItem->isBlockTrade()}\n"; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$this->assertTrue(true); |
48
|
|
|
} else { |
49
|
|
|
echo "API ERORR: " . get_class($this) . "\n"; |
50
|
|
|
echo "CODE: {$response->getReturnCode()} \n"; |
51
|
|
|
echo "MESSAGE: {$response->getReturnMessage()} \n"; |
52
|
|
|
echo "EXTENDED:" . implode(";\n", $response->getExtendedInfo()) . "\n"; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|