Last active
September 10, 2015 07:46
-
-
Save dropmeaword/fbb543d2ed9180c51ecc to your computer and use it in GitHub Desktop.
Getting market data from barchart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# luis rodil-fernandez & hrvoje hirsl | |
import requests | |
import json | |
import urllib | |
from datetime import date | |
API_KEY = "93a7e50ea20390edd76b6f9a5de74570" | |
BASE_URL = "http://marketdata.websol.barchart.com/getHistory.json?" | |
def get_daily(ticker, params=None): | |
params['key']= API_KEY | |
params['symbol']= ticker | |
params['type'] = 'daily' | |
q = urllib.urlencode(params) | |
page = requests.get(BASE_URL+q) | |
# check if request was successful | |
if (page.status_code == 200): | |
response = page.text # get contents of page | |
return json.loads(response) | |
# sample fetch for APPL | |
daily = get_daily('APPL', {'startDate' : date(2014, 9, 21).strftime('%Y%m%d000000'), 'endDate' : date(2014, 9, 22).strftime('%Y%m%d000000')}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment