Skip to content

Instantly share code, notes, and snippets.

@tonoriesco
Last active July 17, 2020 13:38
Show Gist options
  • Save tonoriesco/156bca09c993f95fa02c90389157e0af to your computer and use it in GitHub Desktop.
Save tonoriesco/156bca09c993f95fa02c90389157e0af to your computer and use it in GitHub Desktop.
Get the timestamp of a quote from TDameritrade
# Remember to set the next enviroment variables, otherwise doesn't work!
# export TDAMERITRADE_ACCESS_TOKEN="your_key"
# export TDAMERITRADE_CLIENT_ID="your_key"
# export TDAMERITRADE_REFRESH_TOKEN="your_key"
# Install tdameritrade module: https://pypi.org/project/tdameritrade/
from datetime import datetime
import tdameritrade as td
c = td.TDClient()
stock = 'KO'
time_to_get = 'quoteTimeInLong'
value_to_get = 'lastPrice'
df = c.quote(stock)
time_item = df[stock][time_to_get]/1000
value_item = df[stock][value_to_get]
date_item = datetime.fromtimestamp(time_item).strftime('%Y-%m-%d %H:%M:%S.%f')
print(f'\n\n{stock}: \nValue Now: {value_item} \nTimestamp: {date_item}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment