【发布时间】:2019-04-10 19:40:02
【问题描述】:
我正在尝试创建一个与 api 交换信息的应用程序(确切地说是 Questrade API)。该 API 使用 oauth2 进行安全性和身份验证。
我已经成功1获取授权令牌、刷新令牌和查询基本信息(我的账户信息和股票行情)。
但是,我在尝试查询股票期权报价时遇到了问题(如 here 所述)。
我尝试了许多不同的排列,但无济于事。这是我到目前为止所做的:
1). 我采用了上面链接中提供的“示例请求”部分中显示的示例,并执行了jsondecode 以获得 MATLAB 等效项和“精确模板”参数结构必须编码:
>> eg_param = jsondecode('{"filters":{"optionType":"Call","underlyingId":27426,"expiryDate":"2017-01-20T00:00:00.000000-05:00","minstrikePrice":70,"maxstrikePrice":80},"optionIds":[9907637, 9907638]}')
eg_param =
struct with fields:
filters: [1×1 struct]
optionIds: [2×1 double]
>> eg_param.filters
ans =
struct with fields:
optionType: 'Call'
underlyingId: 27426
expiryDate: '2017-01-20T00:00:00.000000-05:00'
minstrikePrice: 70
maxstrikePrice: 80
>> eg_param.optionIds
ans =
9907637
9907638
2)。用我的实际值 (real_params) 代替示例中的值:
real_params.optionIds = 23255262;
real_params.filters.optionType = 'Call';
real_params.filters.expiryDate ='2018-11-09T00:00:00.000000-05:00';
real_params.filters.underlyingId = 40825;
real_params.filters.minstrikePrice = [];
real_params.filters.maxstrikePrice = [];
3).将weboptions'RequestMethod参数更改为post
web_opt.RequestMethod = 'Post';
4). 使用webwrite 函数,而不是'webread' 来发布和查询服务器:
new_data = webwrite(['https://api01.iq.questrade.com/',...
'v1/markets/quotes/options'], real_params, web_opt);
但是,当我这样做时,会收到错误消息:
*The server returned the status 400 with
message "Bad Request" in response to the
request to URL
https://api01.iq.questrade.com/v1/markets/quotes/options.*
我尝试了许多不同的排列方式,包括更改括号、[]、{}、{{}} 并为参数使用不同的值,但结果是相同的。此外,每当我进行测试时,我都会确保刷新访问令牌并使用“帐户信息”请求测试连接是否有效,因此此错误与任何授权、安全或连接问题无关。
1 例如,获取账户信息,website 指示为:
GET https://api01.iq.questrade.com/v1/accounts
我有 1)。使用了MATLAB的weboptions,并创建了一个对象来存储HeaderFields中的token信息:
web_opt = weboptions;
web_opt.RequestMethod = 'Get';
headerFields = {'Authorization', ['Bearer ', 'ZHHgMgh0up5UqJ9TSOIALpkoVpi0']};
web_opt.HeaderFields = headerFields;
和2)。使用以下方式查询服务器:
data = webread(['https://api01.iq.questrade.com/', 'v1/accounts'], web_opt);
这完成了与 API 服务器的通信,MATLAB 将我的帐户信息作为结构体数组存储在变量 data 中。
【问题讨论】:
-
不幸的是,我以为我添加了问题的超链接,但它们没有出现在原始消息中。链接是:[网站][1] - questrade.com/api/documentation/rest-operations/account-calls/…(如 [此处][2] 所述。 - questrade.com/api/documentation/rest-operations/market-calls/…
标签: json matlab api post oauth-2.0