Skip to content

Instantly share code, notes, and snippets.

@dropmeaword
Last active September 10, 2015 07:46
Show Gist options
  • Save dropmeaword/fbb543d2ed9180c51ecc to your computer and use it in GitHub Desktop.
Save dropmeaword/fbb543d2ed9180c51ecc to your computer and use it in GitHub Desktop.
Getting market data from barchart
# 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