|
MATLAB获取新浪实时股票数据:http://blog.sina.com.cn/s/blog_530e99a40102v01e.html
- function [CurrentStockData, CurrentStockInfo] = get_stock_data(StockCode)
- % StockCode = '000001'--字符类型
- if(str2num(StockCode)>=999999)
- symbol=strcat('sh000001');
- elseif(StockCode(1)=='6')
- symbol=strcat('sh',(StockCode)); % 上海
- elseif(StockCode(1)=='0')
- symbol=strcat('sz',(StockCode)); % 深圳
- end
- url2Read=['http://hq.sinajs.cn/list=',symbol];
- s=urlread(url2Read);
- result=textscan(s,'%s','delimiter', ',');
- result=result{1}; % 当前的结果,cell类型
- % 说明
- % 这个字符串由许多数据拼接在一起,不同含义的数据用逗号隔开了,按照程序员的思路,顺序号从0开始。
- % 0:”大秦铁路”,股票名字;
- % 1:”27.55″,今日开盘价;
- % 2:”27.25″,昨日收盘价;
- % 3:”26.91″,当前价格;
- % 4:”27.55″,今日最高价;
- % 5:”26.20″,今日最低价;
- % 6:”26.91″,竞买价,即“买一”报价;
- % 7:”26.92″,竞卖价,即“卖一”报价;
- % 8:”22114263″,成交的股票数,由于股票交易以一百股为基本单位,所以在使用时,通常把该值除以一百;
- % 9:”589824680″,成交金额,单位为“元”,为了一目了然,通常以“万元”为成交金额的单位,所以通常把该值除以一万;
- % 10:”4695″,“买一”申请4695股,即47手;
- % 11:”26.91″,“买一”报价;
- % 12:”57590″,“买二”
- % 13:”26.90″,“买二”
- % 14:”14700″,“买三”
- % 15:”26.89″,“买三”
- % 16:”14300″,“买四”
- % 17:”26.88″,“买四”
- % 18:”15100″,“买五”
- % 19:”26.87″,“买五”
- % 20:”3100″,“卖一”申报3100股,即31手;
- % 21:”26.92″,“卖一”报价
- % (22, 23), (24, 25), (26,27), (28, 29)分别为“卖二”至“卖四的情况”
- % 30:”2008-01-11″,日期;
- % 31:”15:05:32″,时间;
- StockName = result{1,1}(22:end); % 股票名称-char类型
- OpenPrice=str2double(result{2}); % 今日开盘价
- YesterdayPrice=str2double(result{3}); % 昨日收盘价
- CurrentPrice=str2double(result{4}); % 当前价格
- HighPrice=str2double(result{5}); % 今日最高价格
- LowPrice=str2double(result{6}); % 今日最低价格
- BidBuy1 = str2double(result{7}); % 竞买价,即“买一”报价;
- BidSell1 = str2double(result{8}); % 竞卖价,即“卖一”报价;
- TradeVolume = str2double(result{9}); % 今日成交量,成交的股票数,由于股票交易以一百股为基本单位,所以在使用时,通常把该值除以一百
- TradeMoney = str2double(result{10}); % 成交金额,单位为“元”,为了一目了然,通常以“万元”为成交金额的单位,所以通常把该值除以一万;
- BuyMount1 = str2double(result{11}); % “买一”申请股数
- BuyPrice1 = str2double(result{12}); % “买一”报价
- BuyMount2 = str2double(result{13}); % “买二”申请股数
- BuyPrice2 = str2double(result{14}); % “买二”报价
- BuyMount3 = str2double(result{15}); % “买三”申请股数
- BuyPrice3 = str2double(result{16}); % “买三”报价
- BuyMount4 = str2double(result{17}); % “买四”申请股数
- BuyPrice4 = str2double(result{18}); % “买四”报价
- BuyMount5 = str2double(result{19}); % “买五”申请股数
- BuyPrice5 = str2double(result{20}); % “买五”报价
- SellMount1 = str2double(result{21}); % “卖一”申请股数
- SellPrice1 = str2double(result{22}); % “卖一”报价
- SellMount2 = str2double(result{23}); % “卖二”申请股数
- SellPrice2 = str2double(result{24}); % “卖二”报价
- SellMount3 = str2double(result{25}); % “卖三”申请股数
- SellPrice3 = str2double(result{26}); % “卖三”报价
- SellMount4 = str2double(result{27}); % “卖四”申请股数
- SellPrice4 = str2double(result{28}); % “卖四”报价
- SellMount5 = str2double(result{29}); % “卖五”申请股数
- SellPrice5 = str2double(result{30}); % “卖五”报价
- date = result{31}; % ”2008-01-11″,日期;
- time = result{32}; % ”15:05:32″,时间;
- CurrentStockData=single([OpenPrice,YesterdayPrice,CurrentPrice,HighPrice,LowPrice,...
- BidBuy1,BidSell1,TradeVolume,TradeMoney,BuyMount1,BuyPrice1,BuyMount2,BuyPrice2,...
- BuyMount3,BuyPrice3,BuyMount4,BuyPrice4,BuyMount5,BuyPrice5,SellMount1,SellPrice1,...
- SellMount2,SellPrice2,SellMount3,SellPrice3,SellMount4,SellPrice4,SellMount5,SellPrice5 ]);
- CurrentStockInfo = {StockName;date;time};
复制代码
|
|