MATLAB obtains the number of real-time stock data function implementation code through the Sina Web interface

Source: Internet
Author: User

The code is as follows:

function Stockinfo = Queryprice (Stocktype, Stockid)%stocktype stock type: SH and sz%stockid stock code: URL = sprintf (' HTTP://HQ    . sinajs.cn/list=%s%d ', Stocktype, Stockid);    [SourceFile, status] = Urlread (URL);    if (~status) disp (' Cannot get data ');        Else% remove String str = javaobject (' java.lang.String ', sourcefile);        str = Str.replaceall (' var ', ');        STRs = str.split (' = ');        str = STRs (2);        str = Str.replacefirst (' "', ' {');        str = Str.replacefirst (' "', ' '}; ');        str = Str.replaceall (', ', ' ', ');        str = strcat (' stock= ', char (str));                eval (str);        Stockinfo = {};        Stockinfo.name = stock (1);        Stockinfo.today_start_price = str2double (Stock (2));        Stockinfo.yestoday_end_price = str2double (Stock (3));                Stockinfo.current_price = str2double (Stock (4));        Stockinfo.today_highest_price = str2double (Stock (5));        Stockinfo.today_lowest_price = str2double (stock (6)); Stockinfo.today_fIrst_buy_price = str2double (stock (7));        Stockinfo.today_first_sale_price = str2double (stock (8));       Stockinfo.today_success_stock_mount = str2double (stock (9))/100;                % Unit: Hand Stockinfo.today_success_money = str2double (stock (10));        % Unit: million Stockinfo.today_first_buy_price = Str2double (stock (11));                Stockinfo.today_first_sale_price = str2double (Stock (12));       Stockinfo.buy_stock_mount1 = str2double (stock (13))/100;             % Unit: Hand Stockinfo.buy_stock_price1 = str2double (Stock (14));        % Unit: million Stockinfo.buy_stock_mount2 = str2double (Stock (15));        Stockinfo.buy_stock_price2 = str2double (Stock (16));        Stockinfo.buy_stock_mount3 = str2double (Stock (17));        Stockinfo.buy_stock_price3 = str2double (Stock (18));        STOCKINFO.BUY_STOCK_MOUNT4 = str2double (stock (19));        Stockinfo.buy_stock_price4 = str2double (Stock (20));        STOCKINFO.BUY_STOCK_MOUNT5 = str2double (stock (21)); Stockinfo.buy_stock_Price5 = str2double (Stock (22));        Stockinfo.sale_stock_mount1 = str2double (stock (23));        Stockinfo.sale_stock_price1 = str2double (Stock (24));        Stockinfo.sale_stock_mount2 = str2double (stock (25));        Stockinfo.sale_stock_price2 = str2double (Stock (26));        Stockinfo.sale_stock_mount3 = str2double (Stock (27));        Stockinfo.sale_stock_price3 = str2double (Stock (28));        STOCKINFO.SALE_STOCK_MOUNT4 = str2double (stock (29));                Stockinfo.sale_stock_price4 = str2double (stock (30));        Stockinfo.date = Stock (31);    Stockinfo.time = Stock (32); End End

Examples use:

info = queryprice (' sh ', 601006)% Grand Qin Railway

The result is:

info =

Name: {' Tai Qin Railway '}
today_start_price:10.5800
yestoday_end_price:10.6300
current_price:10.8500
today_highest_price:10.9500
today_lowest_price:10.5000
today_first_buy_price:272852
today_first_sale_price:10.8500
today_success_stock_mount:1.1826e+06
today_success_money:1.2708e+09
buy_stock_mount1:410
buy_stock_price1:10.8400
buy_stock_mount2:43000
buy_stock_price2:10.8300
buy_stock_mount3:61300
buy_stock_price3:10.8200
buy_stock_mount4:67700
buy_stock_price4:10.8100
buy_stock_mount5:109038
buy_stock_price5:10.8600
sale_stock_mount1:86015
sale_stock_price1:10.8700
sale_stock_mount2:273900
sale_stock_price2:10.8800
sale_stock_mount3:180878
sale_stock_price3:10.8900
sale_stock_mount4:313838
sale_stock_price4:10.9000
Date: {' 2014-12-26 '}
Time: {' 15:03:06 '}

MATLAB obtains the number of real-time stock data function implementation code through the Sina Web interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.