Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions php-binance-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ protected function httpRequest(string $url, string $method = "GET", array $param

$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, $this->httpDebug);
$query = http_build_query($params, '', '&');
$query = $this->binance_build_query($params);

// signed with params
if ($signed === true) {
Expand Down Expand Up @@ -1253,13 +1253,13 @@ protected function httpRequest(string $url, string $method = "GET", array $param
$base = $this->sapi;
}

$query = http_build_query($params, '', '&');
$query = $this->binance_build_query($params);
$query = str_replace([ '%40' ], [ '@' ], $query);//if send data type "e-mail" then binance return: [Signature for this request is not valid.]
$signature = hash_hmac('sha256', $query, $this->api_secret);
if ($method === "POST") {
$endpoint = $base . $url;
$params['signature'] = $signature; // signature needs to be inside BODY
$query = http_build_query($params, '', '&'); // rebuilding query
$query = $this->binance_build_query($params); // rebuilding query
} else {
$endpoint = $base . $url . '?' . $query . '&signature=' . $signature;
}
Expand Down Expand Up @@ -1363,6 +1363,35 @@ protected function httpRequest(string $url, string $method = "GET", array $param
return $json;
}

/**
* binance_build_query - Wrapper for http_build_query to allow arrays as parameters
*
* sapi v1/asset/dust can have an array, so it needs a conversion
*
* @param array $params (mandatory) Parameters to convert to http query
*
* @return array containing the response
* @throws \Exception
*/
protected function binance_build_query($params = [])
{
$new_arr = array();
$query_add = '';
foreach ($params as $label=>$item) {
if ( gettype($item) == 'array' ) {
foreach ($item as $arritem) {
$query_add = $label . '=' . $arritem . '&' . $query_add;
}
} else {
$new_arr[$label] = $item;
}
}
$query = http_build_query($new_arr, '', '&');
$query = $query_add . $query;

return $query;
}

/**
* Converts the output of the CURL header to an array
*
Expand Down