In [1]:
import barchart
from barchart import getHistory, getQuote, CONFIG
In [2]:
#barchart.API_KEY = 'YOURAPIKEY'
You can also set an environment variable using Bash
export BARCHART_API_KEY="YOURAPIKEY"
In [3]:
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
In [4]:
symbol = "^EURUSD"
quote = getQuote(symbol, session=session)
quote # quote is a dict
Out[4]:
In [5]:
symbols = ["ZC*1", "IBM", "GOOGL" , "^EURUSD"]
quotes = getQuote(symbols, session=session)
quotes # quotes is a Pandas DataFrame
#print(quotes.dtypes)
#print(type(quotes['serverTimestamp'][0])) # should be a pandas.tslib.Timestamp
Out[5]:
In [6]:
CONFIG.output_pandas = False
quotes = getQuote(symbols, session=session)
print(quotes) # quotes is a Pandas DataFrame
CONFIG.output_pandas = True
In [7]:
symbol = 'IBM'
startDate = datetime.date(year=2014, month=9, day=28)
history = getHistory(symbol, typ='daily', startDate=startDate, session=session)
history
#print(history.dtypes)
#print(type(history['timestamp'][0])) # should be a pandas.tslib.Timestamp
#print(type(history.index[0])) # should be a pandas.tslib.Timestamp
#print(type(history['tradingDay'][0])) # should be a pandas.tslib.Timestamp
Out[7]:
In [8]:
symbols = ["ZC*1", "IBM", "GOOGL" , "^EURUSD"]
histories = getHistory(symbols, typ='daily', startDate=startDate, session=session)
histories
#print(histories.dtypes)
#print(type(histories.index[0])) # should be a pandas.tslib.Timestamp
#print(type(histories['timestamp'][0])) # should be a pandas.tslib.Timestamp
Out[8]:
In [9]:
#histories.loc[:, :, "IBM"] #??