Created
July 27, 2018 21:11
-
-
Save akhan118/98711cb13851e864c1bda3baae8beee3 to your computer and use it in GitHub Desktop.
Get Price History
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
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