1. 程式人生 > >【原創】免費股票行情介面

【原創】免費股票行情介面

免費股票行情介面:

1 sina 新浪js介面

http://hq.sinajs.cn/list=sh600001

返回

var hq_str_sh600011="華能國際,7.390,7.420,7.230,7.500,7.110,7.210,7.230,24257738,174459225.000,6200,7.210,9900,7.200,16000,7.190,24400,7.180,18506,7.170,23900,7.230,53100,7.240,50400,7.250,17000,7.260,2000,7.270,2018-12-17,15:00:00,00";

 

http://hq.sinajs.cn/list=sh600011,sh600012

返回

var hq_str_sh600011="華能國際,7.390,7.420,7.230,7.500,7.110,7.210,7.230,24257738,174459225.000,6200,7.210,9900,7.200,16000,7.190,24400,7.180,18506,7.170,23900,7.230,53100,7.240,50400,7.250,17000,7.260,2000,7.270,2018-12-17,15:00:00,00";
var hq_str_sh600012="皖通高速,5.590,5.590,5.620,5.650,5.550,5.610,5.620,2157530,12066336.000,16500,5.610,45971,5.600,11600,5.590,44300,5.580,19600,5.570,1200,5.620,19500,5.630,21300,5.640,57700,5.650,38100,5.660,2018-12-17,15:00:00,00";

返回格式如下:

股票名字,今日開盤價,昨日收盤價,當前價格,今日最高價,今日最低價,買一量,買一價,買二量,買二價,買三量,買三價,買四量,買四價,買五量,買五價,賣一量,賣一價,賣二量,賣二價,賣三量,賣三價,賣四量,賣四價,賣五量,賣五價,日期,時間

優點:實時資料,可以一次獲取多個股票的當天實時資料,而且資料指標很全;

缺點:不能指定日期;

 

2 netease 網易csv下載介面

http://quotes.money.163.com/service/chddata.html?code=0600011&start=19940809&end=20181214&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;TURNOVER;VOTURNOVER;VATURNOVER;TCAP;MCAP

返回

優點:可以指定起始和結束日期以及哪些資料指標,適合下載歷史資料;

缺點:不實時;

程式碼如下:

    val url = new URL(urlStr)
    val conn = url.openConnection
    val is = conn.getInputStream
    val bos = new ByteArrayOutputStream()
    val b = new Array[Byte](1024)
    var len = 0
    do {
      len = is.read(b)
      if (len > 0) bos.write(b, 0, len)
    } 
while (len != -1) println(new String(bos.toByteArray, "GBK"))