Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

arnabm14
Copy link

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.

Added get_latest_price(symbol) function to fetch the latest price of a symbol and not the whole market. Returns an integer
Copy link
Owner

@sammchardy sammchardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review

binance/client.py Outdated Show resolved Hide resolved
binance/client.py Outdated Show resolved Hide resolved
binance/client.py Outdated Show resolved Hide resolved
Co-authored-by: Precious <lilonaony@gmail.com>
@arnabm14 arnabm14 changed the title Added get_latest_price(symbol) function Added get_latest_price_by_symbol(self,symbol) function Feb 23, 2022
@arnabm14 arnabm14 changed the title Added get_latest_price_by_symbol(self,symbol) function Added get_latest_price_by_symbol(self,symbol) -> float Feb 23, 2022
Copy link

@0ex-d 0ex-d left a 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
Copy link
Owner

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']
Copy link
Owner

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)
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants