-
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?
Conversation
Added get_latest_price(symbol) function to fetch the latest price of a symbol and not the whole market. Returns an integer
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.
Please review
Co-authored-by: Precious <lilonaony@gmail.com>
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.
Looks clearer. Thank you
…tatement 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.
:raises: BinanceRequestException, BinanceAPIException | ||
|
||
""" | ||
val=0.0 |
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
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 comment
The 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
|
||
val = list_price[-1]['price'] | ||
|
||
return float(val) |
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.
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.
Added get_latest_price(symbol) function to fetch the latest price of a symbol and not the whole market. Returns a float value of the price at that moment. It is not an average price but the market price at that moment for a symbol.