Skip to content

Instantly share code, notes, and snippets.

@akhan118
Created July 27, 2018 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akhan118/98711cb13851e864c1bda3baae8beee3 to your computer and use it in GitHub Desktop.
Save akhan118/98711cb13851e864c1bda3baae8beee3 to your computer and use it in GitHub Desktop.
Get Price History
def get_price_history(self,symbol,startDate=None,endDate=None):
access_token = self.get_access_token().json()
access_token = access_token['access_token']
headers={'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer {}'.format(access_token)}
data = { 'periodType': 'year','frequencyType':'daily',
'startDate':startDate,'endDate':endDate}
authReply = requests.get('https://api.tdameritrade.com/v1/marketdata/'+symbol+'/pricehistory',
headers=headers, params=data)
# print(authReply.json())
candles = authReply.json()
df = json_normalize(authReply.json())
df = pd.DataFrame(candles['candles'])
return df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment