Skip to content

Commit 222e9ec

Browse files
committed
add some live tests
1 parent 7e518a3 commit 222e9ec

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

php-binance-api.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class API
7474
protected $xMbxUsedWeight = 0;
7575
protected $xMbxUsedWeight1m = 0;
7676

77+
public $headers = [];
78+
7779
private $SPOT_ORDER_PREFIX = "x-HNA2TXFJ";
7880
private $CONTRACT_ORDER_PREFIX = "x-Cb7ytekJ";
7981

@@ -1521,6 +1523,13 @@ protected function httpRequest(string $url, string $method = "GET", array $param
15211523

15221524
$curl = curl_init();
15231525
curl_setopt($curl, CURLOPT_VERBOSE, $this->httpDebug);
1526+
1527+
//set custom headers if any
1528+
curl_setopt_array($curl, [
1529+
CURLOPT_HTTPHEADER => $this->headers,
1530+
// Optional: other cURL options
1531+
]);
1532+
15241533
$query = $this->binance_build_query($params);
15251534

15261535
// signed with params

tests/BinanceLiveTests.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,47 @@
99

1010
class BinanceLiveTests extends TestCase
1111
{
12-
private Binance\API $binance;
12+
private Binance\API $spotBinance;
13+
private Binance\API $futuresBinance;
1314

1415
public function setUp(): void {
15-
$this->binance = new API('api_key', 'api_secret');
16-
$this->binance->useTestnet = true;
16+
$this->spotBinance = new API('X4BHNSimXOK6RKs2FcKqExquJtHjMxz5hWqF0BBeVnfa5bKFMk7X0wtkfEz0cPrJ', 'x8gLihunpNq0d46F2q0TWJmeCDahX5LMXSlv3lSFNbMI3rujSOpTDKdhbcmPSf2i');
17+
$this->spotBinance->useTestnet = true;
18+
19+
$this->futuresBinance = new API('227719da8d8499e8d3461587d19f259c0b39c2b462a77c9b748a6119abd74401', 'b14b935f9cfacc5dec829008733c40da0588051f29a44625c34967b45c11d73c');
20+
$this->futuresBinance->useTestnet = true;
1721
}
1822
public function testPricesSpot()
1923
{
20-
$res = $this->binance->prices();
24+
$res = $this->spotBinance->prices();
2125
$this->assertIsArray($res);
2226
$this->assertArrayHasKey('BTCUSDT', $res);
2327
$this->assertIsString($res['BTCUSDT']);
2428
}
2529

2630
public function testPricesFutures()
2731
{
28-
$res = $this->binance->futuresPrices();
32+
$res = $this->futuresBinance->futuresPrices();
2933
$this->assertIsArray($res);
3034
$this->assertArrayHasKey('BTCUSDT', $res);
3135
$this->assertIsString($res['BTCUSDT']);
3236
}
37+
38+
public function testBalanceSpot()
39+
{
40+
$res = $this->spotBinance->balances();
41+
$this->assertIsArray($res);
42+
// $this->assertArrayHasKey('USDT', $res);
43+
// $this->assertIsString($res['USDT']['free']);
44+
}
45+
46+
public function testBalanceFutures()
47+
{
48+
$res = $this->futuresBinance->futuresAccount();
49+
$this->assertIsArray($res);
50+
$assets = $res['assets'];
51+
$first = $assets[0];
52+
$this->assertArrayHasKey('asset', $first);
53+
$this->assertArrayHasKey('walletBalance', $first);
54+
}
3355
}

0 commit comments

Comments
 (0)