Matlab获取新浪财经实时行情
生活随笔
收集整理的這篇文章主要介紹了
Matlab获取新浪财经实时行情
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SinaData.m
function [Data, DataCell] = SinaData(Code) %參數說明: code股票代碼,上交所輸入sh+證券代碼,深交所輸入sz+證券代碼 %返回值說明:Data只是行情數據,DataCell包含數據描述信息 %調用說明:SinaData('sh600000')%調用新浪接口獲取數據url = ['http://hq.sinajs.cn/list=', Code]; %字符串拼接s = webread(url);%按分隔符','解析字符串并返回cellresult = textscan(s, '%s', 'delimiter', ',');result = result{1, 1};DataCell = result;%分離出行情數據,并轉換為double類型Data = cellfun(@str2double, DataCell(2:30));%設置第1行為StockName_StockIDtemp = cell2mat(DataCell(1));StockName = temp(22:end);StockID = temp(12:19);DataCell{1, 1} = [StockName, '_', StockID];%設置第2行為行情日期StockDate = cell2mat( DataCell(31) );DataCell{2, 1} = StockDate;%設置第3行為行情時間StockTime = cell2mat( DataCell(32) );DataCell{3, 1} = StockTime;%從第4行開始,把Data的數據拷貝到DataCellDataCell(4:end-1) = mat2cell( Data, ones(length(Data), 1) );%因為cell一共有33行,相當于去掉最后一項數據temp = DataCell(1:32);DataCell = temp;%在第2列添加中文標題ind = 1;DataCell{ind, 2} = '股票名稱代碼';ind = ind + 1;DataCell{ind, 2} = '日期';ind = ind + 1;DataCell{ind, 2} = '時間';ind = ind + 1;DataCell{ind, 2} = '今開盤';ind = ind + 1;DataCell{ind, 2} = '昨收盤';ind = ind + 1;DataCell{ind, 2} = '當前價';ind = ind + 1;DataCell{ind, 2} = '今最高';ind = ind + 1;DataCell{ind, 2} = '今最低';ind = ind + 1;DataCell{ind, 2} = '競買價,即“買一”報價';ind = ind + 1;DataCell{ind, 2} = '競賣價,即“賣一”報價';ind = ind + 1;DataCell{ind, 2} = '成交量,單位“股”'; %不同的證券品種有不同的單位,比如債券是張ind = ind + 1;DataCell{ind, 2} = '成交額,單位“元”';ind = ind + 1;DataCell{ind, 2} = '買一量';ind = ind + 1;DataCell{ind, 2} = '買一價';ind = ind + 1;DataCell{ind, 2} = '買二量';ind = ind + 1;DataCell{ind, 2} = '買二價';ind = ind + 1;DataCell{ind, 2} = '買三量';ind = ind + 1;DataCell{ind, 2} = '買三價';ind = ind + 1;DataCell{ind, 2} = '買四量';ind = ind + 1;DataCell{ind, 2} = '買四價';ind = ind + 1;DataCell{ind, 2} = '買五量';ind = ind + 1;DataCell{ind, 2} = '買五價';ind = ind + 1;DataCell{ind, 2} = '賣一量';ind = ind + 1;DataCell{ind, 2} = '賣一價';ind = ind + 1;DataCell{ind, 2} = '賣二量';ind = ind + 1;DataCell{ind, 2} = '賣二價';ind = ind + 1;DataCell{ind, 2} = '賣三量';ind = ind + 1;DataCell{ind, 2} = '賣三價';ind = ind + 1;DataCell{ind, 2} = '賣四量';ind = ind + 1;DataCell{ind, 2} = '賣四價';ind = ind + 1;DataCell{ind, 2} = '賣五量';ind = ind + 1;DataCell{ind, 2} = '賣五價'; end
總結
以上是生活随笔為你收集整理的Matlab获取新浪财经实时行情的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MIP、PWA、WebGL、HTTPS,
- 下一篇: 中国金融体系(金融机构,金融市场,金融基