[R-SIG-Finance] CUSIP Numbers

G See gsee000 at gmail.com
Wed Jan 21 23:25:05 CET 2015


Since this is an R mailing list, I'll try to bring this thread back on
topic.  Unless you are willing to pay, the only free source that I am
aware of to get CUSIPs via R is TradeKing.
https://developers.tradeking.com/documentation/market-ext-quotes-get-post

You must have an account, but you can create an account for free and
you don't have to fund it in order to do this.


library(ROAuth) #importFrom(ROAuth, OAuthFactory)
library(RJSONIO) #importFrom(RJSONIO, fromJSON)

#' ## This part could go in your .Rprofile
#' # Set your application keys # https://developers.tradeking.com/applications
#' cKey <- '################'
#' cSecret <- '#################'
#' oKey <- '################'
#' oSecret <- '################'

# Set the API endpoint
tkURL <- "https://api.tradeking.com/v1/market/ext/quotes.json"

# Create the OAuth connection - this is straight from the ROAuth
documentation on CRAN
credentials <- OAuthFactory$new(consumerKey=cKey,
                                consumerSecret=cSecret,
                                oauthKey = oKey,
                                oauthSecret = oSecret,
                                needsVerifier=FALSE,
                                signMethod='HMAC')
# Update the connection so the handshake is TRUE
credentials$handshakeComplete <- TRUE

Symbols <- tolower(c("AAPL", "MSFT")) ## Whatever symbols you want
symbols <- paste(Symbols, collapse=",")

#what <- "datetime,bidsz,bid,ask,asksz,last,chg,pchg,opn,hi,lo,vl"
what <- "cusip"
what <- gsub(" ", "", tolower(paste(unlist(strsplit(what, ",")),
                                      collapse=",")))
tkURL <- "https://api.tradeking.com/v1/market/ext/quotes.json"
query <- list(symbols=symbols, fids=what)
response <- credentials$OAuthRequest(tkURL, query)
res <- fromJSON(response)
qt <- res$response$quotes$quote
qt

#[[1]]
#     cusip       exch     symbol
#"59491810"     "NASD"     "MSFT"
#
#[[2]]
#     cusip       exch     symbol
#"03783310"     "NASD"     "AAPL"

HTH,
Garrett



More information about the R-SIG-Finance mailing list