From 0d80c03976cdbe880a4bbd0bcbeff22830fbb3e5 Mon Sep 17 00:00:00 2001 From: Arnab Mondal Date: Tue, 28 Dec 2021 01:07:22 +0530 Subject: [PATCH 1/3] Added get_latest_price(symbol) function Added get_latest_price(symbol) function to fetch the latest price of a symbol and not the whole market. Returns an integer --- binance/client.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/binance/client.py b/binance/client.py index 09b6652d6..a4e58335c 100755 --- a/binance/client.py +++ b/binance/client.py @@ -506,7 +506,28 @@ def get_symbol_info(self, symbol) -> Optional[Dict]: return item return None + + def get_latest_price(self,symbol) -> int: + """Latest price for One specific symbols. + Reference Document : https://binance-docs.github.io/apidocs/spot/en/#symbol-price-ticker + + :returns: Latest Price of a coin + + .. code-block:: python + + input : BNBUSDT + output : 600.2 + + :raises: BinanceRequestException, BinanceAPIException + + """ + val=0.0 + list_price= [x['price'] for x in self.get_all_tickers() if x['symbol']==symbol] + + for i in list_price: + val=float(i) + return val # General Endpoints def ping(self) -> Dict: From c47f8ce8474200f21db767d19e1e8695428fda38 Mon Sep 17 00:00:00 2001 From: Arnab Mondal Date: Wed, 23 Feb 2022 21:31:38 +0000 Subject: [PATCH 2/3] Changed Heading to Latest price by Symbol Co-authored-by: Precious --- binance/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binance/client.py b/binance/client.py index a4e58335c..de2594a0b 100755 --- a/binance/client.py +++ b/binance/client.py @@ -507,7 +507,7 @@ def get_symbol_info(self, symbol) -> Optional[Dict]: return None - def get_latest_price(self,symbol) -> int: + def get_latest_price_by_symbol(self,symbol) -> int: """Latest price for One specific symbols. Reference Document : https://binance-docs.github.io/apidocs/spot/en/#symbol-price-ticker From 8b6f95ab1060a911f4d9895d73079de99f5d886f Mon Sep 17 00:00:00 2001 From: Arnab Mondal Date: Wed, 30 Mar 2022 14:01:34 +0530 Subject: [PATCH 3/3] Updated the function description and changed the for loop to single statement Changed the function description to state that the return type is float. The function raises the same exception as other functions and hence the element not found is handled through that. Tha for loop is changed to a single statement which makes more sense and the price is extracted from that. --- binance/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/binance/client.py b/binance/client.py index de2594a0b..9ad0ab41f 100755 --- a/binance/client.py +++ b/binance/client.py @@ -507,7 +507,7 @@ def get_symbol_info(self, symbol) -> Optional[Dict]: return None - def get_latest_price_by_symbol(self,symbol) -> int: + def get_latest_price_by_symbol(self,symbol) -> float: """Latest price for One specific symbols. Reference Document : https://binance-docs.github.io/apidocs/spot/en/#symbol-price-ticker @@ -525,9 +525,9 @@ def get_latest_price_by_symbol(self,symbol) -> int: val=0.0 list_price= [x['price'] for x in self.get_all_tickers() if x['symbol']==symbol] - for i in list_price: - val=float(i) - return val + val = list_price[-1]['price'] + + return float(val) # General Endpoints def ping(self) -> Dict: