"lastQtrEPS", "ttmEPS", "twelveMonthEPSChg", "peRatio", "recentEarnings", "recentDividends", "recentSplit", "beta" ] # getQuote with ONE symbol # ======================== print("{0} Quote".format(one_symbol)) print("=========") try: quote = getQuote(one_symbol, fields=quote_fields, session=session) for timestamp in QUOTE_TIMESTAMP_COLS: if timestamp in quote and quote[timestamp]: quote[timestamp] = quote[timestamp].isoformat() for datefield in QUOTE_DATE_COLS: if datefield in quote and quote[datefield]: quote[datefield] = quote[datefield].isoformat() print(pp.pprint(quote)) except NotImplementedError as err: print("getQuote failed: {}".format(err)) # getQuote with SEVERAL symbols # ============================= print("\n{0} Quotes".format(many_symbols)) print("=====================================") try:
if 'results' in results_dict: results_list = results_dict['results'] df = pd.DataFrame(results_list) df.index = [df['symbol'], df['tradeTimestamp']] del df['symbol'] del df['tradeTimestamp'] import requests_cache session = requests_cache.CachedSession(cache_name='cache', backend='sqlite', expire_after=dt.timedelta(days=1)) # getQuote with ONE symbol # ======================== symbol = "^EURUSD" quote = barchart.getQuote(symbol, apikey=barchart.API_KEY, session=session) print(quote) # quote is a dict ''' -------------------------------------------------------------------------------- PYMC -------------------------------------------------------------------------------- ''' lib.plot_invgamma(a=12, b=1) # Bayesian normal regression example
# requests_cache is optional # use it to have a cache mechanism # a session parameter can be pass to functions # ============================================= import datetime import requests_cache session = requests_cache.CachedSession(cache_name='cache', backend='sqlite', expire_after=datetime.timedelta(days=1)) #session = None # pass a None session to avoid caching queries # getQuote with ONE symbol # ======================== symbol = "^EURUSD" quote = getQuote(symbol, session=session) print(quote) # quote is a dict # getQuote with SEVERAL symbols # ============================= symbols = ["ZC*1", "IBM", "GOOGL" , "^EURUSD"] quotes = getQuote(symbols, session=session) print(quotes) # quotes is a Pandas DataFrame #print(quotes.dtypes) #print(type(quotes['serverTimestamp'][0])) # should be a pandas.tslib.Timestamp CONFIG.output_pandas = False quotes = getQuote(symbols, session=session) print(quotes) # quotes is a Pandas DataFrame CONFIG.output_pandas = True