Skip to content

Commit d46a82d

Browse files
authored
Some other checks for empty response added
1 parent 02b7d72 commit d46a82d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

php-binance-api.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,10 @@ public function prices()
11581158
public function price(string $symbol)
11591159
{
11601160
$ticker = $this->httpRequest("v3/ticker/price", "GET", ["symbol" => $symbol]);
1161-
1161+
if (!isset($ticker['price'])) {
1162+
echo "Error: unable to fetch price for $symbol" . PHP_EOL;
1163+
return null;
1164+
}
11621165
return $ticker['price'];
11631166
}
11641167

@@ -1283,6 +1286,14 @@ public function depth(string $symbol, int $limit = 100)
12831286
"symbol" => $symbol,
12841287
"limit" => $limit,
12851288
]);
1289+
if (is_array($json) === false) {
1290+
echo "Error: unable to fetch depth" . PHP_EOL;
1291+
$json = [];
1292+
}
1293+
if (empty($json)) {
1294+
echo "Error: depth were empty" . PHP_EOL;
1295+
return $json;
1296+
}
12861297
if (isset($this->info[$symbol]) === false) {
12871298
$this->info[$symbol] = [];
12881299
}
@@ -3380,10 +3391,11 @@ public function futuresDepth(string $symbol, int $limit = null)
33803391
$json = $this->httpRequest("v1/depth", "GET", $params);
33813392
if (is_array($json) === false) {
33823393
echo "Error: unable to fetch futures depth" . PHP_EOL;
3394+
$json = [];
33833395
}
33843396
if (empty($json)) {
33853397
echo "Error: futures depth were empty" . PHP_EOL;
3386-
return [];
3398+
return $json;
33873399
}
33883400
if (isset($this->info[$symbol]) === false) {
33893401
$this->info[$symbol] = [];

0 commit comments

Comments
 (0)