stock: display after-hours stock data
This commit is contained in:
parent
e99867b2bc
commit
6b23fe36f4
|
@ -8,7 +8,7 @@ def stock(inp):
|
||||||
url = ('http://query.yahooapis.com/v1/public/yql?format=json&'
|
url = ('http://query.yahooapis.com/v1/public/yql?format=json&'
|
||||||
'env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys')
|
'env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys')
|
||||||
|
|
||||||
parsed = http.get_json(url, q='select * from yahoo.finance.quote '
|
parsed = http.get_json(url, q='select * from yahoo.finance.quotes '
|
||||||
'where symbol in ("%s")' % inp) # heh, SQLI
|
'where symbol in ("%s")' % inp) # heh, SQLI
|
||||||
|
|
||||||
quote = parsed['query']['results']['quote']
|
quote = parsed['query']['results']['quote']
|
||||||
|
@ -17,8 +17,19 @@ 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
|
||||||
|
|
||||||
change = float(quote['Change'])
|
|
||||||
price = float(quote['LastTradePriceOnly'])
|
price = float(quote['LastTradePriceOnly'])
|
||||||
|
change = float(quote['Change'])
|
||||||
|
if quote['Open'] and quote['Bid'] and quote['Ask']:
|
||||||
|
open_price = float(quote['Open'])
|
||||||
|
bid = float(quote['Bid'])
|
||||||
|
ask = float(quote['Ask'])
|
||||||
|
if price < bid:
|
||||||
|
price = bid
|
||||||
|
elif price > ask:
|
||||||
|
price = ask
|
||||||
|
change = price - open_price
|
||||||
|
quote['LastTradePriceOnly'] = price
|
||||||
|
quote['Change'] = ("+%.2f" % change) if change >= 0 else change
|
||||||
|
|
||||||
if change < 0:
|
if change < 0:
|
||||||
quote['color'] = "5"
|
quote['color'] = "5"
|
||||||
|
@ -27,7 +38,7 @@ def stock(inp):
|
||||||
|
|
||||||
quote['PercentChange'] = 100 * change / (price - change)
|
quote['PercentChange'] = 100 * change / (price - change)
|
||||||
|
|
||||||
ret = "%(Name)s - %(LastTradePriceOnly)s " \
|
ret = "%(Name)s - %(LastTradePriceOnly).2f " \
|
||||||
"\x03%(color)s%(Change)s (%(PercentChange).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