Skip to content

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

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