① 股票數據介面怎麼獲取一般是怎麼收費的
② 用java定義一個股票類Stock,該類包括如右圖所示
public class Stock {
private String store;// 股票類屬性
private String symbol;// 股票代號
private String name;// 股票名稱
private BigDecimal currentPrice;// 當前時間的股票價格
private BigDecimal previouClosingPrice;// 前一天的股票值
/**
* 返回前一天變到當前時間的百分比
* @return 百分比
*/
public double getChangePercent() {
return this.currentPrice.subtract(this.previouClosingPrice).abs()
.divide(this.currentPrice, 2, BigDecimal.ROUND_HALF_EVEN)
.doubleValue();
}
/**
* 返回前一天變到當前時間的百分比
* @param currentPrice 當前時間的股票價格
* @param previouClosingPrice 前一天的股票值
* @return 百分比
*/
public double getChangePercent(BigDecimal currentPrice,
BigDecimal previouClosingPrice) {
return currentPrice.subtract(previouClosingPrice).abs()
.divide(currentPrice, 2, BigDecimal.ROUND_HALF_EVEN)
.doubleValue();
}
public String getStore() {
return store;
}
public void setStore(String store) {
this.store = store;
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public BigDecimal getCurrentPrice() {
return currentPrice;
}
public void setCurrentPrice(BigDecimal currentPrice) {
this.currentPrice = currentPrice;
}
public BigDecimal getPreviouClosingPrice() {
return previouClosingPrice;
}
public void setPreviouClosingPrice(BigDecimal previouClosingPrice) {
this.previouClosingPrice = previouClosingPrice;
}
}
③ 股票數據介面怎麼找
股票數據介面用免費的股票行情軟體就行,真正有用的數據只有與交易所有協議的機構才能得到,其他人是弄不到的,而且收費昂貴非專業機構也用不起的。
④ 如何獲取實時的股票行情信息,有相關的公用介面或者數據源嗎
實時股票數據介面
股票數據的獲取目前有如下兩種方法可以獲取:
1.
http/javascript介面取數據
2.
web-service介面
1.http/javascript介面取數據
1.1Sina股票數據介面
以大秦鐵路(股票代碼:601006)為例,如果要獲取它的最新行情,只需訪問新浪的股票數據
介面:
http://hq.sinajs.cn/list=sh601006
這個url會返回一串文本,例如:
var
hq_str_sh601006="大秦鐵路, 27.55, 27.25, 26.91, 27.55, 26.20, 26.91,
26.92,
22114263, 589824680, 4695, 26.91, 57590, 26.90, 14700,
26.89, 14300,
26.88, 15100, 26.87, 3100, 26.92, 8900, 26.93,
14230, 26.94, 25150, 26.95, 15220, 26.96, 2008-01-11,
15:05:32";
這個字元串由許多數據拼接在一起,不同含義的數據用逗號隔開了,按照程序員的思路,順序號從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″,時間;
一個簡單的JavaScript應用例子:
script
type="text/javascript" src="http://hq.sinajs.cn/list=sh601006"
charset="gb2312">/script>
/javascript">
var
elements=hq_str_sh601006.split(",");
document.write("current
price:"+elements[3]);
這段代碼輸出大秦鐵路(股票代碼:601006)的當前股價
current
price:14.20
如果你要同時查詢多個股票,那麼在URL最後加上一個逗號,再加上股票代碼就可以了;比如你要一次查詢大秦鐵路(601006)和大同煤業(601001)的行情,就這樣使用URL:
http://hq.sinajs.cn/list=sh601003,sh601001
查詢大盤指數,比如查詢上證綜合指數(000001):
http://hq.sinajs.cn/list=s_sh000001
伺服器返回的數據為:
var
hq_str_s_sh000001="上證指數,3094.668,-128.073,-3.97,436653,5458126";
數據含義分別為:指數名稱,當前點數,當前價格,漲跌率,成交量(手),成交額(萬元);
查詢深圳成指數:
http://hq.sinajs.cn/list=s_sz399001
對於股票的K線圖,日線圖等的獲取可以通過請求http://image.sinajs.cn/…./…/*.gif此URL獲取,其中*代表股票代碼,詳見如下:
查看日K線圖:
http://image.sinajs.cn/newchart/daily/n/sh601006.gif
分時線的查詢:
http://image.sinajs.cn/newchart/min/n/sh000001.gif
日K線查詢:
http://image.sinajs.cn/newchart/daily/n/sh000001.gif
周K線查詢:
http://image.sinajs.cn/newchart/weekly/n/sh000001.gif
月K線查詢:
http://image.sinajs.cn/newchart/monthly/n/sh000001.gif
1.2
Bai&Google的財經數據
在,
google中搜索某隻股票代碼時,將會在頭條顯示此股票的相關信息,例如在google搜索601006時,
第一條搜索結果如下圖:
通過點擊左邊的圖片我們發現會將此圖片鏈接到sina財經頻道上,也就是說google股票數據的獲取也是從sina獲取。後經抓包分析,發現google也是採用1.1中介紹的介面。
Bai的股票數據來自的財經頻道
http://stock..com/
1.3
其他方式
除了sina,等網站提供股票信息外,其他網站也有類似的介面。我們分析了一款論壇上採用的股票插件,
其中有關於實時股票數據獲取的介紹,詳見如下代碼,其中可以看到有些數據來自sina。
以下是ASP示例:
=5
then
stockdata=gethttp("http://hq.sinajs.cn/list=sh"&code&"")
if
not len(stockdata)=0 then
stockdata=split(stockdata,chr(34))(1)
end if
if
len(stockdata)=0
then
stockdata="0,0,0,0,0,0,0,0,0,0,0,0"
else
stockdatasplit=split(stockdata,",")
stockdata=""&exstock.checkstr(stockdatasplit(0))&","&stockdatasplit(1)&","&stockdatasplit(2)&","&stockdatasplit(3)&","&stockdatasplit(4)&","&stockdatasplit(5)&","&formatdatetime(""&stockdatasplit(30)&"
"&stockdatasplit(31)&"",0)&""
end
if
『0=股票名稱,1=開盤價格,2=昨收盤價格,3=當前價格,4=最高價,5=最低價,6=更新時間
getstockdata=stockdata
end
function
function getstockimg(code)
dim
rndnum,addnum,checkcode,imgsource
if len(code)=5
then
getstockimg="http://image.sinajs.cn/newchart/daily/n/sh"&code&".gif"
end
if
imgsource="http://finance.sina.com.cn"
case
3
getstockimg="http://hq.gazxfe.com/stockchart/realline.chart?"&code&"&1003&SZ
500 330"
imgsource="http://hq.gazxfe.com"
case
4
getstockimg="http://chartse.stockstar.com/chartserver?code="&code&""
imgsource="http://www.stockstar.com/"
end
select
getstockimg=split(""&getstockimg&"||"&imgsource&"","||")
end
function
function getastockimg()
dim
rndnum,addnum,checkcode
dim
getastockimgb,imgsource
addnum=6
randomize:rndnum=cint(rnd*addnum)
select
case rndnum
case
0
getastockimg="http://202.109.106.1/gifchartse/gif/000001.gif"
getastockimgb="http://202.109.106.1/gifchartse/gif/399001.gif"
imgsource="http://www.stockstar.com/"
case
1
getastockimg="http://money.163.com/special/100.gif?C39"
getastockimgb="http://money.163.com/special/101.gif?HrS"
imgsource="http://www.163.com"
case
2
getastockimg="http://www.10jqka.com.cn/curve/realtime/index2.php?code=1a0001&w=180&h=140"
getastockimgb="http://www.10jqka.com.cn/curve/realtime/index2.php?code=399001&w=180&h=140"
imgsource="http://www.10jqka.com.cn"
case
3
getastockimg="http://chart.cnlist.com/stockchart/realline.chart?1a0001&1002&SZ
180
140"
getastockimgb="http://chart.cnlist.com/stockchart/realline.chart?399001&1002&SZ
180
140"
imgsource="http://chart.cnlist.com/"
case
4
getastockimg="http://image.sinajs.cn/newchart/small/ish000001.gif?1189176558328"
getastockimgb="http://image.sinajs.cn/newchart/small/isz399001.gif?1189176558328"
imgsource="http://www.sinajs.cn"
case
5
getastockimg="http://218.1.72.66/cgi/pic/sh/realtime/JA000001164143.png"
getastockimgb="http://218.1.72.66/cgi/pic/sz/realtime/JA399001164143.png"
imgsource="http://www.cnstock.com/"
case
6
getastockimg="http://222.73.29.85/img/000001.png"
getastockimgb="http://222.73.29.85/img/399001.png"
imgsource="http://www.eastmoney.com/"
end
select
getastockimg=split(""&getastockimg&"||"&getastockimgb&"||"&imgsource&"","||")
end
function
%>
2.
web-service介面
2.1 CHINAstock的web-service:
http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx
中國股票行情數據
WEB 服務(支持深圳和上海股市的全部基金、債券和股票),數據即時更新。輸出GIF分時走勢圖、日/周/月 K
線圖、及時行情數據(股票名稱、行情時間、最新價、昨收盤、今開盤、漲跌額、最低、最高、漲跌幅、成交量、成交額、競買價、競賣價、委比、買一 - 買五、賣一 -
賣五)。此WEB服務提供了如下幾個介面:
2.1.1
getStockImageByCode
GET
股票GIF分時走勢圖
INput:theStockCode =
股票代號,如:sh000001
POST /WebServices/ChinaStockWebService.asmx
HTTP/1.1
Host: www.webxml.com.cn
Content-Type:
text/xml; charset=utf-8
Content-Length:
length
SOAPAction:
"http://WebXml.com.cn/getStockImageByCode"
string
Output:
2.1.2
getStockImageByteByCode
獲得中國股票GIF分時走勢圖位元組數組
INput:theStockCode
= 股票代號,如:sh000001
POST /WebServices/ChinaStockWebService.asmx
HTTP/1.1Host: www.webxml.com.cnContent-Type: text/xml;
charset=utf-8Content-Length: lengthSOAPAction:
"http://WebXml.com.cn/getStockImageByteByCode"
string
返回的數據如下:
hkMyt4m4VkJtstbv8A
2.1.3
getStockImage_kByCode
直接獲得中國股票GIF日/周/月 K
線圖(545*300pixel/72dpi)
INPUT: theStockCode =
股票代號
theType = K 線圖類型(D:日[默認]、W:周、M:月),
POST
/WebServices/ChinaStockWebService.asmx HTTP/1.1Host:
www.webxml.com.cnContent-Type: text/xml; charset=utf-8Content-Length:
lengthSOAPAction: "http://WebXml.com.cn/getStockImage_kByCode" string
string
比如按照下圖所示輸入:
返回的結果就是周K線圖:
2.1.4
getStockImage_kByteByCode
獲得中國股票GIF日/周/月 K
線圖位元組數組
Input:theStockCode = 股票代號,如:sh000001
POST
/WebServices/ChinaStockWebService.asmx HTTP/1.1Host:
www.webxml.com.cnContent-Type: text/xml; charset=utf-8Content-Length:
lengthSOAPAction: "http://WebXml.com.cn/getStockImage_kByteByCode" string string
HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Content-Length: length
base64Binary
比如按照下圖輸入:
返回的結果就是周K線圖位元組數組
hkMyt4m4VkJtstbv8A
2.1.5
getStockInfoByCode
獲得中國股票及時行情
input:theStockCode
= 股票代號
POST /WebServices/ChinaStockWebService.asmx HTTP/1.1Host:
www.webxml.com.cnContent-Type: text/xml; charset=utf-8Content-Length:
lengthSOAPAction: "http://WebXml.com.cn/getStockInfoByCode"
string
返回的值一個一維字元串數組
String(24),結構為:String(0)股票代號、String(1)股票名稱、String(2)行情時間、String(3)最新價(元)、String(4)昨收盤(元)、String(5)今開盤(元)、String(6)漲跌額(元)、String(7)最低(元)、String(8)最高(元)、String(9)漲跌幅(%)、String(10)成交量(手)、String(11)成交額(萬元)、String(12)競買價(元)、String(13)競賣價(元)、String(14)委比(%)、String(15)-String(19)買一
- 買五(元)/手、String(20)-String(24)賣一 - 賣五(元)/手。
Web
service的方法類似於現在concurrent項目的DBWS數據的獲取,都是通過SOAP協議向DBWS伺服器獲取相關的數據。
利用雅虎查中國股票
http://quote.yahoo.com/d/quotes.csv?s=MSFT&f=slc1wop
返回微軟的股票價格
"MSFT","4:00pm
- 30.70",+1.04,"21.46 -
30.75",29.77,29.66
http://quote.yahoo.com/d/quotes.csv?s=000969.SZ&f=slc1wop
這個返回安泰科技的,一般有半個小時的延遲。
但是s=000969.sz
這個後面的sz是深圳的意思, 滬市是SS後綴
⑤ java 如何實現 獲取實時股票數據
一般有三種方式:
網頁爬蟲。採用爬蟲去爬取目標網頁的股票數據,去GitHub或技術論壇(如CSDN、51CTO)上找一下別人寫的爬蟲集成到項目中。
請求第三方API。會有專門的公司(例如網路API市場)提供股票數據,你只需要去購買他們的服務,使用他們提供的SDK,仿照demo開發實現即可。如下圖所示:
⑥ 如何用java實現用股票名稱查詢實時股票信息
1、首先如果用中文名稱查詢可能出現中文亂碼的錯誤,雖然能夠解決,但是步驟上比較麻煩
2、如果你想實現,可以設置超鏈接也就是
<a href="http://hq.sinajs.cn/list="+名稱>實現一下
比如:<a href="http://hq.sinajs.cn/list="+中國人壽>中國人壽</a>
可能在格式上也就是+後面的東西是寫在引號內還是引號外,我有點記不起來了
不過這個好解決,你可以嘗試一下
⑦ 求助大神 有沒有股票實時行情的API介面
對於個人投資者,一般的看盤軟體中,通過自定義公式介面,可以獲取到股票實時行情的。例如 通達信、同花順、大智慧都支持。這個就相當於股票實時行情的API介面。這種方式採用的就是股票軟體中的公式介面,一般都是這些軟體中自帶的公式語言,編程比較簡單,普通用戶一般也可很快上手,使用也比較方便。
如果是企業用戶,有專門的金融實時行情API介面的提供方,例如微盛的金融實時行情API介面。這種方式需要軟體開發人員才能開發,使用的就是真正的計算機語言,C、C#、java、php等等,更專業些,不太適合普通用戶使用。
⑧ 請問怎樣用Java獲取股票行情歷史數據新浪、搜狐、百度財經都可以......
publicclassStockConnection{
publicstaticvoidmain(String[]args){
URLur=null;
try{
//搜狐股票行情歷史介面
// ur=newURL("http://q.stock.sohu.com/hisHq?code=cn_300228&start=20130930&end=20131231&stat=1&order=D&period=d&callback=historySearchHandler&rt=jsonp");
//新浪股票行情歷史介面
ur=newURL("http://biz.finance.sina.com.cn/stock/flash_hq/kline_data.php?&rand=random(10000)&symbol=sh600000&end_date=20150809&begin_date=20000101&type=plain");
HttpURLConnectionuc=(HttpURLConnection)ur.openConnection();
BufferedReaderreader=newBufferedReader(newInputStreamReader(ur.openStream(),"GBK"));
Stringline;
while((line=reader.readLine())!=null){
System.out.println(line);
}
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
⑨ 如何用java讀取股票數據
股票實時行情,可以通過兩個方法來進行查看: 第一種,在網路搜索頁面直接輸入股票代碼,如:000717,網路輸入後,即可在搜索結果中看到,其中分時,就是該股票在當天的實時走向。 第二種,通過炒股軟體,如東財,同花順等,在開啟後,直接輸入
⑩ 股票軟體如何開發的用什麼語言數據的獲得方式
K-JAVA功能可以做移動商務、移動辦公、信息點播、股票、外匯、地址簿、日歷、文件管理、天氣預報等;
股票軟體戚枝使用的是JAVA語言,該可以跨平台運行,軟體開發商可以很容易的開發應用程序;股票行情軟體是基於Java計算機編程語言上的,也就是K-JAVA即J2ME軟體平台,專門用於嵌入式設備的JAVA軟體。
Java包含了一種計算機編程語言和一個平台,隨著K-Java技術的不斷完善與發展,發展商們將對具有K-Java功能的手機用戶提供更還更全面的絕仔輪服務。如:互動游戲、互動新聞、增強手機連接到無線網路後進行數據交換的安全性、載以Java語言寫成的內容、遙控家用電器。
軟體開發商以K-Java編程語言為手機開發應用程序,可以提供,游並信戲,個人信息處理,股票,電子地圖等服務程序。Java有許多值得稱道的優點,如簡單、面向對象、分布式、解釋性、可靠、安全、結構中立性、可移植性、高性能、多線程、動態性等。