本文介绍了使用R和httr包对Tradier进行API调用的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试对传统API进行API调用,但出现401错误.以下是其API的链接: https://developer.tradier.com/documentation/markets/get-quotes
I'm trying to make an API call to tradier API, but get 401 error. Here's the link to their API: https://developer.tradier.com/documentation/markets/get-quotes
这是我的简单代码:
library(httr)
tradier <- "https://api.tradier.com/v1/markets/history?symbol=AAPL"
getdata<-GET(url=tradier, add_headers(Authorization="Bearer XXXXXXXXXXXXXXXXX"))
getdata
推荐答案
sandbox
API终结点对我有用.我猜想对于brokerage
API端点,您必须升级您的帐户.
The sandbox
API endpoint works for me. I guess for the brokerage
API endpoint you have to upgrade your account.
library(magrittr)
library(httr)
token <- keyring::key_get("tradier_token")
url <- "https://sandbox.tradier.com/v1/markets/quotes?symbols=AAPL,MSFT"
resp <- GET(url = url, add_headers(Authorization = paste("Bearer", token)))
content(resp)[[1]] %>%
data.table::rbindlist()
#> V1 V2
#> 1: AAPL MSFT
#> 2: Apple Inc Microsoft Corp
#> 3: Q Q
#> 4: stock stock
#> 5: 217.66 114.26
#> 6: -2.38 0.7
#> 7: -1.08 0.61
#> 8: 96246748 71229698
#> 9: 26803955 24017088
#> 10: 33973603 21492554
#> 11: 1.53756e+12 1.53756e+12
#> 12: 220.78 114
#> 13: 221.36 115.29
#> 14: 217.29 113.51
#> 15: 217.66 114.26
#> 16: 220.03 113.57
#> 17: 229.67 113.8
#> 18: 149.16 72.92
#> 19: 217.75 113.81
#> 20: 1 9
#> 21: K P
#> 22: 1.537574e+12 1.537574e+12
#> 23: 218.02 113.95
#> 24: 2 3
#> 25: P P
#> 26: 1.537574e+12 1.537574e+12
#> 27: AAPL MSFT
#> V1 V2
这篇关于使用R和httr包对Tradier进行API调用的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!