Added get_latest_price_by_symbol(self,symbol) -> float#1112
Open
arnabm14 wants to merge 3 commits intosammchardy:masterfrom
Open
Added get_latest_price_by_symbol(self,symbol) -> float#1112arnabm14 wants to merge 3 commits intosammchardy:masterfrom
arnabm14 wants to merge 3 commits intosammchardy:masterfrom
Conversation
Added get_latest_price(symbol) function to fetch the latest price of a symbol and not the whole market. Returns an integer
0ex-d
suggested changes
Feb 19, 2022
Co-authored-by: Precious <lilonaony@gmail.com>
…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.
sammchardy
reviewed
Feb 19, 2023
| :raises: BinanceRequestException, BinanceAPIException | ||
|
|
||
| """ | ||
| val=0.0 |
Owner
There was a problem hiding this comment.
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'] |
Owner
There was a problem hiding this comment.
This will crash if symbol is not found in the list of tickers
|
|
||
| val = list_price[-1]['price'] | ||
|
|
||
| return float(val) |
Owner
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.