Skip to content

Instantly share code, notes, and snippets.

@jgilmour
Created January 30, 2013 14:51
Show Gist options
  • Save jgilmour/4673785 to your computer and use it in GitHub Desktop.
Save jgilmour/4673785 to your computer and use it in GitHub Desktop.
Pulls stock quotes from tradeking's api into json format
#!/usr/bin/python
# Python script to pull a stock symbol using TradeKings API
# The 'stock' variable can be multiple stocks ie: "AAPL,CRM,CARB"
# The response output's in json, but can be other formats as well depending
# upon the apiurl request
import oauth2 as oauth
apiurl = "https://api.tradeking.com/v1/market/ext/quotes.json?symbols="
stock = "AAPL"
oAuthConsumer = oauth.Consumer(
key="<oauthConsumerKey>",
secret="<oauthConsumerSecret>")
oAuthToken = oauth.Token(
key="<oAuthTokenKey>",
secret="<oauthTokenSecret>")
oAuthRequest = oauth.Client(oAuthConsumer, oAuthToken)
response, content = oAuthRequest.request(apiurl+stock)
print "Response: ", response
print "Content: ", content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment