def test_get_all_alignment(self): """ Compare bulk 'all_info' values to individual values. Currently broken due to misalignment from invalid CSV in fields: f6, k3, and maybe j2, a5, b6. """ symbol = 'GOOG' all_info = ystockquote.get_all(symbol) self.assertIsInstance(all_info, dict) self.assertEquals( all_info['previous_close'], ystockquote.get_previous_close(symbol)) self.assertEquals( all_info['volume'], ystockquote.get_volume(symbol)) self.assertEquals( all_info['bid_realtime'], ystockquote.get_bid_realtime(symbol)) self.assertEquals( all_info['ask_realtime'], ystockquote.get_ask_realtime(symbol)) self.assertEquals( all_info['last_trade_price'], ystockquote.get_last_trade_price(symbol)) self.assertEquals( all_info['today_open'], ystockquote.get_today_open(symbol)) self.assertEquals( all_info['todays_high'], ystockquote.get_todays_high(symbol)) self.assertEquals( all_info['last_trade_date'], ystockquote.get_last_trade_date(symbol))
def test_get_all_alignment_new(self): """ Compare bulk 'all_info' values to individual values. Currently broken due to misalignment from invalid CSV in fields: f6, k3, and maybe j2, a5, b6. """ symbol = 'GOOG' all_info = quote_properties.get_all(symbol) self.assertIsInstance(all_info, dict) self.assertEquals( all_info['PreviousClose'], ystockquote.get_previous_close(symbol)) self.assertEquals( all_info['Volume'], ystockquote.get_volume(symbol)) self.assertEquals( all_info['BidRealtime'], ystockquote.get_bid_realtime(symbol)) self.assertEquals( all_info['AskRealtime'], ystockquote.get_ask_realtime(symbol)) self.assertEquals( all_info['LastTradePriceOnly'], ystockquote.get_last_trade_price(symbol)) self.assertEquals( all_info['Open'], ystockquote.get_today_open(symbol)) self.assertEquals( all_info['DaysHigh'], ystockquote.get_todays_high(symbol)) self.assertEquals( all_info['LastTradeDate'], ystockquote.get_last_trade_date(symbol))
def stock_properties(stock): """ Retrieves properties for a given stock and returns a dictionary containing it. """ stock_dict = {} stock_dict["stock_name"] = stock.name stock_dict["stock_ask_realtime"] = ystockquote.get_ask_realtime(stock.symbol) stock_dict["stock_today_open"] = ystockquote.get_today_open(stock.symbol) stock_dict["stock_volume"] = ystockquote.get_volume(stock.symbol) stock_dict["stock_change"] = ystockquote.get_change(stock.symbol) stock_dict["stock_change_percent"] = ystockquote.get_change_percent(stock.symbol)[1:-1] stock_dict["stock_todays_range"] = ystockquote.get_todays_range(stock.symbol)[1:-1] # Gets past dates stock_dict["historical_prices_dict"] = collections.OrderedDict( sorted(eval(stock.historical_prices).items(), key=lambda t: t[0]) ) return stock_dict
#!/usr/bin/python #coding=utf8 import ystockquote #获取该股票所有信息 print ystockquote.get_all('GOOG') #获取当前股价 print ystockquote.get_ask_realtime('GOOG') #获取2012.11.22到2013.10.1历史报价 print ystockquote.get_historical_prices("GOOG", '2012.11.22', '2013.10.1')