-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added get_latest_price_by_symbol(self,symbol) -> float #1112
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -506,7 +506,28 @@ def get_symbol_info(self, symbol) -> Optional[Dict]: | |
return item | ||
|
||
return None | ||
|
||
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 | ||
|
||
: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] | ||
|
||
val = list_price[-1]['price'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will crash if symbol is not found in the list of tickers |
||
|
||
return float(val) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Float can cause precision issues and may not be what is wanted by other users. Passing in a formatter to allow for float or Decimal may be a better option here. |
||
# General Endpoints | ||
|
||
def ping(self) -> Dict: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is defined here for now reason