diff --git a/php-binance-api.php b/php-binance-api.php index ac001c1d..f1c0ca93 100755 --- a/php-binance-api.php +++ b/php-binance-api.php @@ -632,17 +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() + public function exchangeInfo($symbols = null) { if (!$this->exchangeInfo) { - $arr = $this->httpRequest("v3/exchangeInfo"); + $arr = array(); + $arr['symbols'] = array(); + $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; @@ -816,15 +840,17 @@ public function withdraw(string $asset, string $address, $amount, $addressTag = "coin" => $asset, "address" => $address, "amount" => $amount, - "transactionFeeFlag" => $transactionFeeFlag, "sapi" => 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; } @@ -2981,4 +3007,22 @@ 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 based on the last 5 minutes + * + * $avgPrice = $api->avgPrice( "ETHBTC" ); + * + * @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) + { + $ticker = $this->httpRequest("v3/avgPrice", "GET", ["symbol" => $symbol]); + return $ticker['price']; + } }