diff --git a/apps/indexticker/index_ticker.star b/apps/indexticker/index_ticker.star index fd4a41923..5ab84409d 100644 --- a/apps/indexticker/index_ticker.star +++ b/apps/indexticker/index_ticker.star @@ -12,6 +12,7 @@ v1.3 - Added NIKKEI, Europe 350, Global 100, Global 1200, NZX50 indices; support load("animation.star", "animation") load("encoding/json.star", "json") load("http.star", "http") +load("humanize.star", "humanize") load("math.star", "math") load("render.star", "render") load("schema.star", "schema") @@ -60,27 +61,9 @@ def main(config): Current = INDEX_JSON["chart"]["result"][0]["meta"]["regularMarketPrice"] PointsDiff = Current - LastClose - PercentDiff = PointsDiff / LastClose - StrPercentDiff = str(int(math.round(PercentDiff * 10000))) - - # if % greater than 0 - # elif % between 0 and -1 - # elif % less than 0 - - if PercentDiff > 0: - StrPercentDiff = (StrPercentDiff[0:-2] + "." + StrPercentDiff[-2:]) - elif PercentDiff > -0.01: - StrPercentDiff = StrPercentDiff.replace("-", "-0") - StrPercentDiff = (StrPercentDiff[0:-2] + "." + StrPercentDiff[-2:]) - elif PercentDiff < 0: - StrPercentDiff = (StrPercentDiff[0:-2] + "." + StrPercentDiff[-2:]) - - if StrPercentDiff.startswith("."): - StrPercentDiff = "0" + StrPercentDiff - DiffColor = "#00ff00" - elif StrPercentDiff.startswith("-"): - StrPercentDiff = StrPercentDiff[1:] - StrPercentDiff = "-" + StrPercentDiff + PercentDiff = PointsDiff / LastClose * 100.0 + + if PercentDiff < 0: DiffColor = "#f00" if RangeSelection == "5m&range=1d": @@ -97,8 +80,7 @@ def main(config): Interval = "YTD" if DisplaySelection == "true": - StrPercentDiff = StrPercentDiff + "%" - DisplayDiff = StrPercentDiff + DisplayDiff = humanize.float("#.##", PercentDiff) + "%" else: DisplayDiff = str(PointsDiff)[:6]