diff --git a/README.md b/README.md
index d056429e..f2d053ba 100755
--- a/README.md
+++ b/README.md
@@ -74,11 +74,10 @@ $api = new Binance\API( "somefile.json" );
$api->caOverride = true;
```
-#### Get latest price of a symbol
+#### Get latest price of all symbols
```php
$ticker = $api->prices();
-print_r($ticker); // List prices of all symbols
-echo "Price of BNB: {$ticker['BNBBTC']} BTC.".PHP_EOL;
+print_r($ticker);
```
@@ -172,7 +171,13 @@ Price of BNB: 0.00021479 BTC.
```
-### Get miniTicker for all symbols
+#### Get latest price of a symbol
+```php
+$price = $api->price("BNBBTC");
+echo "Price of BNB: {$price} BTC.".PHP_EOL;
+```
+
+#### Get miniTicker for all symbols
```php
$api->miniTicker(function($api, $ticker) {
print_r($ticker);
diff --git a/examples/0.example.php b/examples/0.example.php
index ec4b0334..bdcb4bc2 100755
--- a/examples/0.example.php
+++ b/examples/0.example.php
@@ -2,13 +2,16 @@
require '../vendor/autoload.php';
$api = new Binance\API("","");
+// Get latest price of all symbols
+$tickers = $api->prices();
+print_r($tickers); // List prices of all symbols
+
// Get latest price of a symbol
-$ticker = $api->prices();
-print_r($ticker); // List prices of all symbols
-echo "Price of BNB: {$ticker['BNBBTC']} BTC.\n";
+$price = $api->price('BNBBTC');
+echo "Price of BNB: {$price} BTC.\n";
// Get all of your positions, including estimated BTC value
-$balances = $api->balances($ticker);
+$balances = $api->balances($tickers);
print_r($balances);
// Get all bid/ask prices
diff --git a/examples/get_prices.php b/examples/get_prices.php
index 976902ac..7cd09ec8 100755
--- a/examples/get_prices.php
+++ b/examples/get_prices.php
@@ -6,7 +6,10 @@
// use config from ~/.confg/jaggedsoft/php-binance-api.json
$api = new Binance\API();
+// Get latest price of all symbols
+$tickers = $api->prices();
+print_r($tickers); // List prices of all symbols
+
// Get latest price of a symbol
-$ticker = $api->prices();
-print_r($ticker); // List prices of all symbols
-echo "Price of BNB: {$ticker['BNBBTC']} BTC.\n";
+$price = $api->price('BNBBTC');
+echo "Price of BNB: {$price} BTC.\n";
diff --git a/examples/home_directory_config.php b/examples/home_directory_config.php
index 45605ead..77baa3d8 100755
--- a/examples/home_directory_config.php
+++ b/examples/home_directory_config.php
@@ -13,6 +13,5 @@
$api = new Binance\API();
-$ticker = $api->prices();
-print_r($ticker); // List prices of all symbols
-echo "Price of BNB: {$ticker['BNBBTC']} BTC.".PHP_EOL;
+$tickers = $api->prices();
+print_r($tickers); // List prices of all symbols
diff --git a/examples/proxy_config.php b/examples/proxy_config.php
index 0cb3af36..50adb544 100755
--- a/examples/proxy_config.php
+++ b/examples/proxy_config.php
@@ -14,12 +14,11 @@
// use config from ~/.confg/jaggedsoft/php-binance-api.json
$api = new Binance\API("","",["useServerTime"=>false],$proxyConf);
-$ticker = $api->prices();
-print_r($ticker); // List prices of all symbols
-echo "Price of BNB: {$ticker['BNBBTC']} BTC.".PHP_EOL;
+$tickers = $api->prices();
+print_r($tickers); // List prices of all symbols
// Get balances for all of your positions, including estimated BTC value
-$balances = $api->balances($ticker);
+$balances = $api->balances($tickers);
print_r($balances);
echo "BTC owned: ".$balances['BTC']['available'].PHP_EOL;
echo "ETH owned: ".$balances['ETH']['available'].PHP_EOL;
diff --git a/examples/ratelimiter.php b/examples/ratelimiter.php
index fa6be11b..b8d18758 100755
--- a/examples/ratelimiter.php
+++ b/examples/ratelimiter.php
@@ -8,8 +8,8 @@
$api = new Binance\RateLimiter($api);
// Get latest price of a symbol
-$ticker = $api->prices();
-echo "Price of BNB: {$ticker['BNBBTC']} BTC.\n";
+$price = $api->price("BNBBTC");
+echo "Price of BNB: {$price} BTC.\n";
while(true)
{
diff --git a/examples/single/single.php b/examples/single/single.php
index ac70825a..14ed58e1 100755
--- a/examples/single/single.php
+++ b/examples/single/single.php
@@ -3,12 +3,16 @@
require 'binance-api-single.php';
$api = new Binance("","");
-$ticker = $api->prices();
-print_r($ticker); // List prices of all symbols
-echo "Price of BNB: {$ticker['BNBBTC']} BTC.".PHP_EOL;
+// Get latest price of all symbols
+$tickers = $api->prices();
+print_r($tickers); // List prices of all symbols
+
+// Get latest price of a symbol
+$price = $api->price("BNBBTC");
+echo "Price of BNB: {$price} BTC.".PHP_EOL;
// Get balances for all of your positions, including estimated BTC value
-$balances = $api->balances($ticker);
+$balances = $api->balances($tickers);
print_r($balances);
echo "BTC owned: ".$balances['BTC']['available'].PHP_EOL;
echo "ETH owned: ".$balances['ETH']['available'].PHP_EOL;
diff --git a/php-binance-api.php b/php-binance-api.php
index 1ac1a9ac..c012a54f 100755
--- a/php-binance-api.php
+++ b/php-binance-api.php
@@ -629,6 +629,21 @@ public function prices()
return $this->priceData($this->httpRequest("v3/ticker/price"));
}
+ /**
+ * price get the latest price of a symbol
+ *
+ * $price = $api->price( "ETHBTC" );
+ *
+ * @return array with error message or array with symbol price
+ * @throws \Exception
+ */
+ public function price(string $symbol)
+ {
+ $ticker = $this->httpRequest("v3/ticker/price", "GET", ["symbol" => $symbol]);
+
+ return $ticker['price'];
+ }
+
/**
* bookPrices get all bid/asks prices
*
@@ -1481,6 +1496,18 @@ private function depthData(string $symbol, array $json)
"asks" => $asks,
];
}
+
+ /**
+ * roundStep rounds number with given step
+ * @param $value price
+ * @param $stepSize parameter from exchangeInfo
+ * @return rounded value. example: roundStep(1.2345, 0.1) = 1.2
+ *
+ */
+ public function roundStep($value, $stepSize = 0.1) {
+ $precision = strlen(substr(strrchr(rtrim($value,'0'), '.'), 1));
+ return round((($value / $stepSize) | 0) * $stepSize, $precision);
+ }
/**
* getTransfered gets the total transfered in b,Kb,Mb,Gb