From a2e1560eea28d5168e1713e4a80625f0c11d61ea Mon Sep 17 00:00:00 2001 From: Mohamed Ali Date: Fri, 27 Aug 2021 16:30:23 +0530 Subject: [PATCH 1/2] Added avgPrice, changed exchangeInfo and withdraw Added avgPrice function Changed exchangeInfo so it can get info for only one symbol Changed transactionFeeFlag, so it not to be sent when it is false --- php-binance-api.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index ac001c1d..4b492cb3 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -639,10 +639,14 @@ public function time() * @return array with error message or exchange info array * @throws \Exception */ - public function exchangeInfo() + public function exchangeInfo($symbol = null) { if (!$this->exchangeInfo) { - $arr = $this->httpRequest("v3/exchangeInfo"); + + $parameters = []; + if($symbol) $parameters["symbol"] = $symbol; + + $arr = $this->httpRequest("v3/exchangeInfo", "GET", $parameters); $this->exchangeInfo = $arr; $this->exchangeInfo['symbols'] = null; @@ -816,9 +820,11 @@ public function withdraw(string $asset, string $address, $amount, $addressTag = "coin" => $asset, "address" => $address, "amount" => $amount, - "transactionFeeFlag" => $transactionFeeFlag, "sapi" => true, ]; + + if($transactionFeeFlag) $options['transactionFeeFlag'] = true; + if (is_null($addressName) === false && empty($addressName) === false) { $options['name'] = str_replace(' ', '%20', $addressName); } @@ -2981,4 +2987,18 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp return $this->httpRequest("v3/order/oco", "POST", $opt, true); } + + /** + * avgPrice get the average price of a symbol + * + * $avgPrice = $api->avgPrice( "ETHBTC" ); + * + * @return array with error message or array with symbol price + * @throws \Exception + */ + public function avgPrice(string $symbol) + { + $ticker = $this->httpRequest("v3/avgPrice", "GET", ["symbol" => $symbol]); + return $ticker['price']; + } } From bba15f44a934806ad4ca77ad286d57180472435c Mon Sep 17 00:00:00 2001 From: ePascalC Date: Mon, 30 Aug 2021 18:36:36 +0200 Subject: [PATCH 2/2] exchangeInfo - added array as parameter --- php-binance-api.php | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/php-binance-api.php b/php-binance-api.php index 4b492cb3..f1c0ca93 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -632,21 +632,41 @@ public function time() } /** - * exchangeInfo Gets the complete exchange info, including limits, currency options etc. + * exchangeInfo - Gets the complete exchange info, including limits, currency options etc. + * + * @link https://binance-docs.github.io/apidocs/spot/en/#exchange-information * * $info = $api->exchangeInfo(); + * $info = $api->exchangeInfo('BTCUSDT'); + * + * $arr = array('ATABUSD','BTCUSDT'); + * $info = $api->exchangeInfo($arr); + * + * @property int $weight 10 + * + * @param string|array $symbols (optional) A symbol or an array of symbols, default is empty * - * @return array with error message or exchange info array + * @return array containing the response * @throws \Exception */ - public function exchangeInfo($symbol = null) + public function exchangeInfo($symbols = null) { if (!$this->exchangeInfo) { - + $arr = array(); + $arr['symbols'] = array(); $parameters = []; - if($symbol) $parameters["symbol"] = $symbol; - $arr = $this->httpRequest("v3/exchangeInfo", "GET", $parameters); + if ($symbols) { + if (gettype($symbols) == "string") { + $parameters["symbol"] = $symbols; + $arr = $this->httpRequest("v3/exchangeInfo", "GET", $parameters); + } + if (gettype($symbols) == "array") { + $arr = $this->httpRequest('v3/exchangeInfo?symbols=' . '["' . implode('","', $symbols) . '"]'); + } + } else { + $arr = $this->httpRequest("v3/exchangeInfo"); + } $this->exchangeInfo = $arr; $this->exchangeInfo['symbols'] = null; @@ -823,14 +843,14 @@ public function withdraw(string $asset, string $address, $amount, $addressTag = "sapi" => true, ]; - if($transactionFeeFlag) $options['transactionFeeFlag'] = true; - if (is_null($addressName) === false && empty($addressName) === false) { $options['name'] = str_replace(' ', '%20', $addressName); } if (is_null($addressTag) === false && empty($addressTag) === false) { $options['addressTag'] = $addressTag; } + if ($transactionFeeFlag) $options['transactionFeeFlag'] = true; + if (is_null($network) === false && empty($network) === false) { $options['network'] = $network; } @@ -2989,11 +3009,15 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp } /** - * avgPrice get the average price of a symbol + * avgPrice - get the average price of a symbol based on the last 5 minutes * * $avgPrice = $api->avgPrice( "ETHBTC" ); * - * @return array with error message or array with symbol price + * @property int $weight 1 + * + * @param string $symbol (mandatory) a symbol, e.g. ETHBTC + * + * @return string with symbol price * @throws \Exception */ public function avgPrice(string $symbol)