Skip to content

Commit 02b7d72

Browse files
authored
A few warnings for empty response added
1 parent 726e266 commit 02b7d72

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

php-binance-api.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3249,6 +3249,14 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp
32493249
public function avgPrice(string $symbol)
32503250
{
32513251
$ticker = $this->httpRequest("v3/avgPrice", "GET", ["symbol" => $symbol]);
3252+
if (is_array($ticker) === false) {
3253+
echo "Error: unable to fetch avg price" . PHP_EOL;
3254+
$ticker = [];
3255+
}
3256+
if (empty($ticker)) {
3257+
echo "Error: avg price was empty" . PHP_EOL;
3258+
return null;
3259+
}
32523260
return $ticker['price'];
32533261
}
32543262

@@ -3320,11 +3328,12 @@ public function futuresTime()
33203328
public function futuresExchangeInfo()
33213329
{
33223330
if (!$this->futuresExchangeInfo) {
3323-
$arr = array();
3324-
$arr['symbols'] = array();
3325-
33263331
$arr = $this->httpRequest("v1/exchangeInfo", "GET", [ 'fapi' => true ]);
3327-
3332+
if ((is_array($arr) === false) || empty($arr)) {
3333+
echo "Error: unable to fetch futures exchange info" . PHP_EOL;
3334+
$arr = array();
3335+
$arr['symbols'] = array();
3336+
}
33283337
$this->futuresExchangeInfo = $arr;
33293338
$this->futuresExchangeInfo['symbols'] = null;
33303339

@@ -3369,6 +3378,13 @@ public function futuresDepth(string $symbol, int $limit = null)
33693378
$params['limit'] = $limit;
33703379
}
33713380
$json = $this->httpRequest("v1/depth", "GET", $params);
3381+
if (is_array($json) === false) {
3382+
echo "Error: unable to fetch futures depth" . PHP_EOL;
3383+
}
3384+
if (empty($json)) {
3385+
echo "Error: futures depth were empty" . PHP_EOL;
3386+
return [];
3387+
}
33723388
if (isset($this->info[$symbol]) === false) {
33733389
$this->info[$symbol] = [];
33743390
$this->info[$symbol]['futures'] = [];
@@ -3801,7 +3817,8 @@ public function futuresPrice(string $symbol)
38013817
];
38023818
$ticker = $this->httpRequest("v1/ticker/price", "GET", $parameters);
38033819
if (!isset($ticker['price'])) {
3804-
throw new \Exception("No price found for symbol $symbol");
3820+
echo "Error: unable to fetch futures price for $symbol" . PHP_EOL;
3821+
return null;
38053822
}
38063823
return $ticker['price'];
38073824
}
@@ -3848,7 +3865,8 @@ public function futuresPriceV2(string $symbol)
38483865
];
38493866
$ticker = $this->httpRequest("v2/ticker/price", "GET", $parameters);
38503867
if (!isset($ticker['price'])) {
3851-
throw new \Exception("No price found for symbol $symbol");
3868+
echo "Error: unable to fetch futures price for $symbol" . PHP_EOL;
3869+
return null;
38523870
}
38533871
return $ticker['price'];
38543872
}

0 commit comments

Comments
 (0)