Skip to content

Commit

Permalink
Better price formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MaticConradi committed Jun 18, 2022
1 parent 6118e68 commit 2ad2cf1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/components/coingecko.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ def _request_quote(cls, request, ticker):
volume = rawData["market_data"]["total_volume"][ticker.get("quote").lower()]
priceChange = rawData["market_data"]["price_change_percentage_24h_in_currency"][ticker.get("quote").lower()] if ticker.get("quote").lower() in rawData["market_data"]["price_change_percentage_24h_in_currency"] else 0

priceText = "{:,.8g}".format(price)
if price < 1 and "e-" in priceText:
number, exponent = priceText.split("e-")
priceText = ("{:,.%df}" % (len(number) + int(exponent) - 2)).format(price).rstrip('0')

payload = {
"quotePrice": "{:,.12f}".format(price).rstrip('0').rstrip('.') + " " + ticker.get("quote"),
"quotePrice": priceText + " " + ticker.get("quote"),
"quoteVolume": "{:,.4f}".format(volume).rstrip('0').rstrip('.') + " " + ticker.get("base"),
"title": ticker.get("name"),
"change": "{:+.2f} %".format(priceChange),
Expand Down

0 comments on commit 2ad2cf1

Please sign in to comment.