Merge pull request #90 from jstultz/fixstock
Calculate change percentage correctly
This commit is contained in:
commit
980ebad385
|
@ -19,16 +19,18 @@ def stock(inp):
|
||||||
if quote['Change'] is None:
|
if quote['Change'] is None:
|
||||||
return "unknown ticker symbol %s" % inp
|
return "unknown ticker symbol %s" % inp
|
||||||
|
|
||||||
if quote['Change'][0] == '-':
|
change = float(quote['Change'])
|
||||||
|
price = float(quote['LastTradePriceOnly'])
|
||||||
|
|
||||||
|
if change < 0:
|
||||||
quote['color'] = "5"
|
quote['color'] = "5"
|
||||||
else:
|
else:
|
||||||
quote['color'] = "3"
|
quote['color'] = "3"
|
||||||
|
|
||||||
quote['Percent_Change'] = (100 * float(quote['Change']) /
|
quote['PercentChange'] = 100 * change / (price - change)
|
||||||
float(quote['LastTradePriceOnly']))
|
|
||||||
|
|
||||||
ret = "%(Name)s - %(LastTradePriceOnly)s " \
|
ret = "%(Name)s - %(LastTradePriceOnly)s " \
|
||||||
"\x03%(color)s%(Change)s (%(Percent_Change).2f%%)\x03 " \
|
"\x03%(color)s%(Change)s (%(PercentChange).2f%%)\x03 " \
|
||||||
"Day Range: %(DaysRange)s " \
|
"Day Range: %(DaysRange)s " \
|
||||||
"MCAP: %(MarketCapitalization)s" % quote
|
"MCAP: %(MarketCapitalization)s" % quote
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue