本文整理汇总了Python中ystockquote.get_all函数的典型用法代码示例。如果您正苦于以下问题:Python get_all函数的具体用法?Python get_all怎么用?Python get_all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_all函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
def handle(text, mic, profile):
"""
Responds to user-input, typically speech text, with a summary of
the day's top news headlines, sending them to the user over email
if desired.
Arguments:
text -- user-input, typically transcribed speech
mic -- used to interact with the user (for both input and output)
profile -- contains information related to the user (e.g., phone
number)
"""
mic.say("Getting Stock Info")
try:
output = ''
for symbol in profile['stocks']:
print symbol
stock_info = ys.get_all(symbol)
print stock_info
current_out = symbol + " Current Price is " + stock_info['price'] + \
" with a daily change of " + stock_info['change'] + " ... "
print current_out
output = output + current_out
mic.say(output)
except:
mic.say("Error retrieving stocks")
示例2: percent_change
def percent_change(self):
tick_data = []
repull_all = raw_input("Would you like to pull ticker data? (Y/N): ")
ask_print = raw_input("Show after pull? (Y/N): ")
if "y" in repull_all:
pbar = ProgressBar()
for ticker in pbar(self.ticker_list):
# print str(ticker_list.index(ticker) + 1) + ' / ' + str(len(ticker_list)) + ' ' + str((float(ticker_list.index(ticker) + 1) / len(ticker_list))) + '%'
try:
tick_data = ysq.get_all(ticker)
percentage = (
float(tick_data["change"]) / (float(tick_data["price"]) - float(tick_data["change"]))
) * 100
if percentage > 0:
self.rising.append([ticker, tick_data["price"]])
if percentage > 3:
self.rising_three.append([ticker, tick_data["price"]])
if percentage < 0:
self.dipping.append([ticker, tick_data["price"]])
if percentage < -3:
self.dipping_three.append([ticker, tick_data["price"]])
except Exception, e:
# print "Data Pull Error For: " + str(ticker)
self.error_list.append(ticker)
pass
self.write_cache()
示例3: fetchQuotes
def fetchQuotes(sym, start=FROM_DATE, end=CURRENT_DATE):
his = None
data = None
try:
# print start, end
data = ystockquote.get_historical_prices(sym, start, end)
except Exception:
print "Please check the dates. Data might not be available. 404 returned"
# 404 due to data yet not available
if data:
his = DataFrame(collections.OrderedDict(sorted(data.items()))).T
his = his.convert_objects(convert_numeric=True)
his.index = pd.to_datetime(his.index)
his.insert(0, 'symbol', sym, allow_duplicates=True)
# insert the date as dataframe too
his.insert(1, 'date', his.index)
# his.columns = getColumns('stock_quote_historical') # Removing as db dependency is removed
his.columns = getColumnsNoSql('stock_quote_historical')
daily = ystockquote.get_all(sym)
# print daily
# persist(his, daily, sym, end)
return his, daily
示例4: stock
def stock(bot, trigger):
if not trigger.group(2):
bot.reply("Please enter a stock ticker. Ex. TWTR")
else:
ticker = trigger.group(2).upper()
s = ystockquote.get_all(ticker)
bot.reply("%s %s, Price: $%s, Change: %s, Volume: %s, 52 Week High: $%s. " % (ticker, s['stock_exchange'], s['price'], s['change'], s['volume'], s['52_week_high']))
示例5: main
def main():
# ticker_file = "input/tickers.txt"
# bucket_name = "edgarsentimentbucket"
# conn = S3Connection(argv[1], argv[2])
# path_bucket = conn.get_bucket(bucket_name)
# k = Key(path_bucket)
# k.key = ticker_file
# pathfile = k.get_contents_as_string()
# try:
# lines = pathfile.split('\n')
# except AttributeError:
# lines = pathfile
try:
print "started"
# for linie in open(ticker_file, "r"):
for linie in sys.stdin:
try:
print linie
ticker_arr = linie.split('\t')
curr_ticker = ticker_arr[1]
curr_cik = ticker_arr[2]
curr_date = ticker_arr[3]
if not '-' in curr_date:
curr_date = curr_date[0:4] + '-' + curr_date[4:6] + '-' + curr_date[6:8]
curr_date = curr_date.strip()
curr_date_obj = crteDateObj(curr_date)
yest_date_obj = curr_date_obj - timedelta(days=1)
yest_date = crteDateStr(yest_date_obj)
try:
price_dict = ystockquote.get_historical_prices(curr_ticker, yest_date, curr_date)
curr_close = price_dict[curr_date]['Close']
curr_adj_close = price_dict[curr_date]['Adj Close']
curr_open = price_dict[curr_date]['Open']
yest_close = price_dict[yest_date]['Close']
yest_adj_close = price_dict[yest_date]['Adj Close']
yest_open = price_dict[yest_date]['Close']
except:
curr_close = "NA"
curr_adj_close = "NA"
curr_open = "NA"
yest_close = "NA"
yest_adj_close = "NA"
yest_open = "NA"
try:
all_dict = ystockquote.get_all(curr_ticker)
curr_mkt_cap = all_dict['market_cap']
except:
curr_mkt_cap = "NA"
print curr_ticker + '\t' + curr_cik + '\t' + curr_date + '\t' + curr_open + '\t' + \
curr_close + '\t' + curr_adj_close + '\t' + yest_open + '\t' + yest_close + '\t' + \
yest_adj_close + '\t' + curr_mkt_cap
except:
print "bad"
except:
print "didn't start"
示例6: test_get_all_alignment
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))
示例7: get
def get(self):
stock_name = self.request.path[7:]
# Checking if request is from valid user
if 'HMAC' not in self.request.headers:
self.request.headers['HMAC'] = None
hmac_sign = self.request.headers['HMAC']
if 'PKEY' not in self.request.headers:
self.request.headers['PKEY'] = None
public_key = self.request.headers['PKEY']
data_dict = {'stock': stock_name}
response = {}
if not is_valid_user_request(hmac_sign,
public_key,
data_dict):
response['status'] = False
response['unathorized'] = True
self.response.out.write(json.dumps(response))
return
response["name"] = stock_name
try:
if len(stock_name) < 1:
raise Exception()
details = ystockquote.get_all(stock_name)
response["status"] = True
response["details"] = details
except:
response["status"] = False
self.response.out.write(json.dumps(response))
示例8: getStockLine
def getStockLine (self, stocks):
stock_list = stocks.split()
stockLine = ""
for stock in stock_list:
stockData = ystockquote.get_all(stock)
stockLine += stock + '[' + stockData['price'] + '/' + stockData['change'] + "] "
return stockLine
示例9: get_quote
def get_quote(self):
if self.quote is None:
try:
self.quote = ystockquote.get_all(self.symbol)
except:
self.quote = None
return self.quote
示例10: compact_quote
def compact_quote(symbol):
a = y.get_all(symbol)
try:
L52 = int(round(float(a['fifty_two_week_low']), 0))
except ValueError:
L52 = '_'
try:
P = round(float(a['price']), 1)
except ValueError:
P = '_'
try:
C = a['change']
except ValueError:
C = '_'
try:
H52 = int(round(float(a['fifty_two_week_high']), 0))
except ValueError:
H52 = '_'
try:
PE = round(float(a['price_earnings_ratio']), 1)
except ValueError:
PE = '_'
try:
Cp = int(round(float(C) / float(P) * 100))
except ValueError:
Cp = '_'
return '{} {} {}% [{} {}] PE {}'.format(symbol, P, Cp, L52, H52, PE)[0:31]
示例11: test_get_all
def test_get_all(self):
symbol = 'GOOG'
all_info = ystockquote.get_all(symbol)
self.assertIsInstance(all_info, dict)
pc = all_info['previous_close']
self.assertNotEqual(pc, 'N/A')
self.assertGreater(float(pc), 0)
示例12: get_fundamental_data
def get_fundamental_data(stock: str) -> dict:
"""
Gets fundamental Data from yahoo finance. Some fundamentals and a lot af real-live prices.
Enter a starting point and an endpoint as args after entering the symbol of a stock or an index.
The result will look like this:
avg_daily_volume: 17735800,
book_value: 9.33,
change: -0.13,
dividend_per_share: 0.12,
dividend_yield: 1.23,
earnings_per_share: -0.44,
ebitda: 2.63B,
fifty_day_moving_avg: 10.28,
fifty_two_week_high: 11.50,
fifty_two_week_low: 6.14,
market_cap: 12.35B,
price: 9.39,
price_book_ratio: 1.02,
price_earnings_growth_ratio: 2.50,
price_earnings_ratio: N/A,
price_sales_ratio: 0.59,
short_ratio: 8.07,
stock_exchange: "NYQ",
two_hundred_day_moving_avg: 9.91,
volume: 15300774},
"""
try:
return ystockquote.get_all(stock)
except:
print("Something went wrong!")
示例13: addRow
def addRow(self, stockSym):
self.sysmTextIn.delete(0, END)
searchterms = [('Symbol', stockSym.upper(), '=', 'AND')]
symbolCol = self.model.getColumnData(columnIndex=self.model.getColumnIndex(columnName="Symbol"),
columnName="Symbol", filters=searchterms)
if stockSym.upper() in symbolCol:
return
result = ystockquote.get_all(stockSym.upper())
row = Rows(result, stockSym.upper())
dictrow = row.getRow()
colIndex = self.model.getColumnIndex(columnName="Symbol")
stockSym = self.model.getValueAt(rowIndex=0, columnIndex=colIndex)
if stockSym == " ":
row0 = self.table.getSelectedRow()
self.model.deleteRow(row0)
self.table.setSelectedRow(row0-1)
self.table.clearSelected()
else:
self.currentRow = self.currentRow + 1
self.model.importDict({ "%s%d" % ("rec", self.currentRow) : dictrow})
change = float(dictrow['Change'])
if change > 0:
self.model.setColorAt(rowIndex=self.model.getRecordIndex("%s%d" % ("rec", self.currentRow)),
columnIndex=self.model.getColumnIndex(columnName="Change"),color="green", key="fg")
self.model.setColorAt(rowIndex=self.model.getRecordIndex("%s%d" % ("rec", self.currentRow)),
columnIndex=self.model.getColumnIndex(columnName="%Change"),color="green", key="fg")
if change < 0:
self.model.setColorAt(rowIndex=self.model.getRecordIndex("%s%d" % ("rec", self.currentRow)),
columnIndex=self.model.getColumnIndex(columnName="Change"),color="red", key="fg")
self.model.setColorAt(rowIndex=self.model.getRecordIndex("%s%d" % ("rec", self.currentRow)),
columnIndex=self.model.getColumnIndex(columnName="%Change"),color="red", key="fg")
self.table.redrawTable()
self.after(5000, self.updateTableValue, "%s%d" % ("rec", self.currentRow))
示例14: test_get_all_multiple
def test_get_all_multiple(self):
symbols = ['GOOG', 'TSLA']
all_info = ystockquote.get_all(symbols)
self.assertIsInstance(all_info, list)
for row in all_info:
self.assertIsInstance(row, dict)
pc = row['previous_close']
self.assertNotEqual(pc, 'N/A')
self.assertGreater(float(pc), 0)
示例15: main
def main():
args = parse_args()
if args.startDate and args.endDate:
values = get_historical_prices(
args.symbol, args.startDate, args.endDate).items()
else:
values = get_all(args.symbol).items()
for val in sorted(values):
print val