フィルターのクリア

Run a code multiple times and save variables

1 回表示 (過去 30 日間)
Stuart
Stuart 2014 年 7 月 11 日
コメント済み: dpb 2014 年 7 月 12 日
Hi,
I would like to run the following code every 20 seconds for 5 minutes in order to get the latest bitcoin price.
rawdata = urlread('https://www.bitstamp.net/api/ticker/');
j = strfind(rawdata, 'high');
k = strfind(rawdata, 'last');
m = strfind(rawdata, 'vwap');
o = strfind(rawdata, 'volume');
p = strfind(rawdata, 'low');
High=rawdata(j+8:j+13);
Last=rawdata(k+8:k+13)
vwap=rawdata(m+8:m+13);
volume=rawdata(o+10:o+22);
low=rawdata(p+7:p+12);
I would like the value of high/last/vwap etc for each of the time periods. I am having trouble using a vector as I don't know if urlread can be used in this format.
Any help would be much appreciated.
Thanks,
Stu

採用された回答

dpb
dpb 2014 年 7 月 11 日
編集済み: dpb 2014 年 7 月 12 日
M=5; % number of minutes
P=20; % period between readings
N=60/P*M; % readings expected
% format string for the data line returned...
fmt=['{"high": "%f", "last": "%f",' repmat('%*s ',1,4) '"vwap": "%f", "volume": "%f", "low": "%f"']
data=zeros(N,5); % preallocate
for i=1:N
rawdata=urlread('https://www.bitstamp.net/api/ticker/');
data(i,:)=sscanf(rawdata,fmt).';
pause(P)
end
Your values will be
High Last VWAP Vol Low
by column for each period.
  4 件のコメント
Stuart
Stuart 2014 年 7 月 12 日
Thanks dpb.
Much appreciated.
dpb
dpb 2014 年 7 月 12 日
No problem...you'll undoubtedly want to add some error handling and all...the pause is klunky; not sure whether there's a way to schedule it as a callback or not--never investigated that in Matlab.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by