Skip to content

Commit a8b7a22

Browse files
authored
Another check for empty response added
1 parent d46a82d commit a8b7a22

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

php-binance-api.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,6 @@ public function exchangeInfo($symbols = null)
692692
{
693693
if (!$this->exchangeInfo) {
694694
$arr = array();
695-
$arr['symbols'] = array();
696-
$parameters = [];
697-
698695
if ($symbols) {
699696
if (gettype($symbols) == "string") {
700697
$parameters["symbol"] = $symbols;
@@ -706,7 +703,11 @@ public function exchangeInfo($symbols = null)
706703
} else {
707704
$arr = $this->httpRequest("v3/exchangeInfo");
708705
}
709-
706+
if ((is_array($arr) === false) || empty($arr)) {
707+
echo "Error: unable to fetch spot exchange info" . PHP_EOL;
708+
$arr = array();
709+
$arr['symbols'] = array();
710+
}
710711
$this->exchangeInfo = $arr;
711712
$this->exchangeInfo['symbols'] = null;
712713

@@ -921,13 +922,16 @@ public function depositAddress(string $asset, $network = null)
921922
$return = $this->httpRequest("v1/capital/deposit/address", "GET", $params, true);
922923

923924
// Adding for backwards compatibility with wapi
924-
$return['asset'] = $return['coin'];
925-
$return['addressTag'] = $return['tag'];
926-
927-
if (!empty($return['address'])) {
928-
$return['success'] = 1;
925+
if (is_array($return) && !empty($return)) {
926+
$return['asset'] = $return['coin'];
927+
$return['addressTag'] = $return['tag'];
928+
if (!empty($return['address'])) {
929+
$return['success'] = 1;
930+
} else {
931+
$return['success'] = 0;
932+
}
929933
} else {
930-
$return['success'] = 0;
934+
echo "Error: no deposit address found" . PHP_EOL;
931935
}
932936

933937
return $return;
@@ -955,8 +959,12 @@ public function depositHistory(string $asset = null, array $params = [])
955959
$return = $this->httpRequest("v1/capital/deposit/hisrec", "GET", $params, true);
956960

957961
// Adding for backwards compatibility with wapi
958-
foreach ($return as $key=>$item) {
959-
$return[$key]['asset'] = $item['coin'];
962+
if (is_array($return) && !empty($return)) {
963+
foreach ($return as $key=>$item) {
964+
$return[$key]['asset'] = $item['coin'];
965+
}
966+
} else {
967+
echo "Error: no deposit history found" . PHP_EOL;
960968
}
961969

962970
return $return;

0 commit comments

Comments
 (0)