获取A股行情数据方法
做股票量化分析,獲取股票行情數(shù)據(jù)是第一步,結(jié)合網(wǎng)上的信息,和我用過的一些東西,做個(gè)總結(jié)。以后有新信息,逐步完善。
目錄
一、本地
3.baostock,
4.jqdatasdk、-聚寬的本地版
5.OpenDataTools
6、pandas-datareader庫(kù)
二、在線量化平臺(tái)
1.優(yōu)礦
2.聚寬
3.mindgo-同花順量化平臺(tái)
4、rqdatac-米筐,
5.其它
三、通達(dá)信等行情軟件
?
四、股票網(wǎng)站行情接口
1 雪球接口
2 網(wǎng)易接口
3 和訊接口
4 騰訊接口
5 新浪接口
6.從雅虎財(cái)經(jīng)上爬
7.愛搞搞
五、一些收費(fèi)的信息
六、其它
?
一、本地
1、tushare庫(kù)
網(wǎng)址:https://tushare.pro/
獲取上證指數(shù)1:ts-pro
import tushare as ts ts.set_token('********') pro = ts.pro_api() df = pro.index_daily(ts_code='000001.SH',start_date="20190101") df = df.sort_values(by='trade_date',ascending=True) df = df.reset_index(drop=True)?? df.rename(columns={'vol':'volume'},?inplace = True)pro.index_daily返回:ts_code、trade_date、close、open、high、low、pre_close、vol、amount等
獲取上證指數(shù)2:ts-ifeng
import tushare as ts dfi=ts.get_hist_data('sh') ? #獲取上證指數(shù)k線: dfi.sort_index(inplace=True) ? ? ?? dfi = dfi.reset_index(drop=False)? dfi.rename(columns={'date':'trade_date'}, inplace = True)ts.get_hist_data返回:'date', 'open', 'high', 'close', 'low', 'volume', 等,無(wú)amount
獲取上證指數(shù)3:ts-騰訊gtimg.cn
import tushare as ts def test_ts2():dfi=ts.get_k_data('sh') ? #獲取上證指數(shù)k線數(shù)據(jù),其它參數(shù)與個(gè)股一致,下同print(dfi)return dfits.get_k_data返回:1990年開市以來(lái)的所有'date', 'open', 'close', 'high', 'low', 'volume', 'code'等,無(wú)amount
獲取上證指數(shù)4:ts-vsf-sina
import tushare as ts def test_ts3():dfi=ts.get_h_data('sh') ? #獲取上證指數(shù)k線數(shù)據(jù),其它參數(shù)與個(gè)股一致,下同print(dfi)return dfi返回:此法已經(jīng)失效,原來(lái)應(yīng)該是獲取‘vsf': 'vip.stock.finance.sina.com.cn',不知道為何失效。
?
其它常用api
df1=pro.trade_cal(exchange=‘SSE’, start_date=sdate,end_date=edate,is_open=‘1’)
df = pro.daily(trade_date=‘20180810’) #獲取日線行情,里面有昨收
df = pro.top_inst(trade_date=idate) #獲取龍虎榜機(jī)構(gòu)機(jī)構(gòu)明細(xì)
?
2.AkShare-開源本地
https://akshare.readthedocs.io/
有一個(gè)dtshare,數(shù)據(jù)和調(diào)用方式都類似。
獲取股票指數(shù)歷史
1.股票指數(shù)數(shù)據(jù)是從新浪財(cái)經(jīng)獲取的數(shù)據(jù)
def test_sina(): ?import akshare as akstock_zh_index_daily_df = ak.stock_zh_index_daily(symbol="sh000001")print(stock_zh_index_daily_df)
返回:date\open\close\high\low\volume
zh_sina_index_stock_hist_url = "https://finance.sina.com.cn/realstock/company/{}/hisdata/klc_kl.js"
1.股票指數(shù)數(shù)據(jù)是從騰訊獲取的數(shù)據(jù)
def test_tx():import akshare as akstock_zh_index_daily_tx_df = ak.stock_zh_index_daily_tx(symbol="sh000001")print(stock_zh_index_daily_tx_df)返回:date\open\close\high\low\amount
url = "http://web.ifzq.gtimg.cn/appstock/app/fqkline/get"
測(cè)試的時(shí)候速度比sina慢不少。
3.baostock,
def test_bao():import baostock as bsimport pandas as pd# 登陸系統(tǒng)lg = bs.login()# 顯示登陸返回信息rs = bs.query_history_k_data_plus("sh.000001","date,code,open,high,low,close,preclose,volume,amount,pctChg",start_date='1990-01-01', frequency="d") ? ?# 打印結(jié)果集data_list = []while (rs.error_code == '0') & rs.next():# 獲取一條記錄,將記錄合并在一起data_list.append(rs.get_row_data())result = pd.DataFrame(data_list, columns=rs.fields)print(result)# 登出系統(tǒng)bs.logout()return result返回:1990-12-19開始的'date', 'code', 'open', 'high', 'low', 'close', 'preclose', 'volume','amount',等。
數(shù)據(jù)較快;close比對(duì)還行,兩位小數(shù),和三位的略有誤差;交叉調(diào)用時(shí)注意volume的單位
?
4.jqdatasdk、-聚寬的本地版
?
5.OpenDataTools
開源的數(shù)據(jù)提取工具,專注在各類網(wǎng)站上爬取數(shù)據(jù),并通過簡(jiǎn)單易用的API方式使用
- Home
- 01. 股票數(shù)據(jù)
- 02. 期貨數(shù)據(jù)
- 03. 匯率數(shù)據(jù)
| get_daily | 獲取日線數(shù)據(jù) | 雪球 |
https://github.com/PKUJohnson/OpenData/wiki
?
6、pandas-datareader庫(kù)
用fix_yahoo_finance庫(kù)修正雅虎源,用了一下,能用,但是據(jù)說在走下坡路,還是別太投入了。
def test_yahoo():#可以通過如下獲取上證指數(shù)的數(shù)據(jù),缺點(diǎn):from pandas_datareader import data, wbfrom datetime import datetimestart1=datetime(1990,1,1)end1=datetime(1993,1,1)df = data.DataReader("000001.SS", 'yahoo', start1, end1)print(df)return df速度很慢,上述代碼有一次是11秒運(yùn)行完,另一次2分鐘都沒返回結(jié)果,直接重啟內(nèi)核了。(20200419)
?
?
二、在線量化平臺(tái)
用了優(yōu)礦和聚寬,主要以優(yōu)礦為主,特別是里面的漲跌停信息,做漲跌停有關(guān)的分析很方便。之前還有米筐等。
1.優(yōu)礦
DataAPI.MktEqudGet # 取滬深A(yù)B股日行情信息,包含昨收價(jià)、開盤價(jià)、最高價(jià)、最低價(jià)、收盤價(jià)、成交量、成交金額等字段,每日16:00更新 DataAPI.MktLimitGet #獲取股票歷史漲跌停價(jià)格?
2.聚寬
?
3.mindgo-同花順量化平臺(tái)
http://quant.10jqka.com.cn/
?
4、rqdatac-米筐,
需申請(qǐng),可使用一個(gè)月
https://www.ricequant.com/welcome/
?
5.其它
另有:VNPY-tqsdk -看界面不錯(cuò)
?
三、通達(dá)信等行情軟件
比如通達(dá)信的高級(jí)導(dǎo)出功能,注意上證指數(shù)等指數(shù)需要單獨(dú)導(dǎo)出。
要注意下載數(shù)據(jù)可能不完整,逐步檢查,
優(yōu)缺點(diǎn):這個(gè)數(shù)據(jù)的好處是速度快。
?
四、股票網(wǎng)站行情接口
1 雪球接口
?
https://xueqiu.com/stock/forchartk/stocklist.json?symbol=<股票代碼>&period=<采樣頻率>&type=<復(fù)權(quán)類型>&begin=<起始時(shí)間戳>&end=<終止時(shí)間戳>2 網(wǎng)易接口
http://quotes.money.163.com/service/chddata.html?code=<股票代碼>&start=<起始時(shí)間>&end=<終止時(shí)間>&fields=<指標(biāo)用分號(hào)分隔>網(wǎng)易財(cái)經(jīng)可以下載股票和指數(shù)的歷史數(shù)據(jù)。通過在chrome的調(diào)試工具中觀察請(qǐng)求信息,發(fā)現(xiàn)網(wǎng)址為?
http://quotes.money.163.com/service/chddata.html?code=0000001&start=19901219&end=20200101&fields=TCLOSE;HIGH;LOW;TOPEN;LCLOSE;CHG;PCHG;VOTURNOVER;VATURNOVER?
這里0000001指的是上證指數(shù)。注意這串?dāng)?shù)字要分0和000001兩部分看。0代表sh,1代表sz。所以0000001其實(shí)是sh000001的意思。同理,0 000300也就是sh000300 滬深300的代碼。后面的start和end沒什么問題。fields選項(xiàng)中,TCLOSE,HIGH,LOW,TOPEN分別表示當(dāng)日的收盤,最高,最低,開盤價(jià);LCLOSE表示昨日收盤價(jià)。CHG,PCHG,VOTURNOVER,VAT分別表示漲跌額,漲跌幅,成交量,成交金額。如果你在瀏覽器中直接輸入網(wǎng)址的話,會(huì)下載一個(gè)csv文件。如果直接用urllib.request來(lái)打開的話,會(huì)得到一長(zhǎng)串字符串,里面包含了所有的數(shù)據(jù),如下所示。
?
以工商銀行為例的URL:
日內(nèi)實(shí)時(shí)盤口(JSON):
http://api.money.126.net/data/feed/1000002,1000001,1000881,0601398,money.api
歷史成交數(shù)據(jù)(CSV):
http://quotes.money.163.com/service/chddata.html?code=0601398&start=20000720&end=20150508
財(cái)務(wù)指標(biāo)(CSV):
http://quotes.money.163.com/service/zycwzb_601398.html?type=report
資產(chǎn)負(fù)債表(CSV):
http://quotes.money.163.com/service/zcfzb_601398.html
利潤(rùn)表(CSV):
http://quotes.money.163.com/service/lrb_601398.html
現(xiàn)金流表(CSV):
http://quotes.money.163.com/service/xjllb_601398.html
杜邦分析(HTML):
http://quotes.money.163.com/f10/dbfx_601398.html
?
3 和訊接口
和訊接口的特點(diǎn)是可以控制采樣的數(shù)量和方向。
http://webstock.quote.hermes.hexun.com/a/kline?code=<股票代碼>&start=<時(shí)間定位點(diǎn)>&number=<采樣數(shù)量和方向>&type=<采樣頻率代碼>和訊還提供了更簡(jiǎn)單的接口:
全部日線行情:
全部分時(shí)行情:
http://flashquote.stock.hexun.com/Quotejs/MA/<交易所標(biāo)記><股票代碼>_MA.html交易所標(biāo)記中的1表示滬市,2表示深市
接口差別在D和M,注意有兩處
4 騰訊接口
http://data.gtimg.cn/flashdata/hushen/latest/<采樣頻率>/<股票代碼>.js5 新浪接口
http://hq.sinajs.cn/list=<股票代碼>A股股票&基金
http://hq.sinajs.cn/list=sh601006
http://hq.sinajs.cn/list=sh502007
A股指數(shù)
http://hq.sinajs.cn/list=s_sz399001
港股股票
http://hq.sinajs.cn/list=hk02333
http://hq.sinajs.cn/list=rt_hkCSCSHQ?#滬港通資金流量
港股指數(shù)
http://hq.sinajs.cn/list=int_hangseng
http://hq.sinajs.cn/list=rt_hkHSI
http://hq.sinajs.cn/list=hkHSI,hkHSCEI,hkHSCCI?#恒生指數(shù),恒生國(guó)企指數(shù),恒生紅籌指數(shù)
美股股票&基金
http://hq.sinajs.cn/list=gb_amzn
http://hq.sinajs.cn/list=usr_amzn
http://hq.sinajs.cn/list=usr_russ
美股指數(shù)
http://hq.sinajs.cn/list=int_nasdaq
http://hq.sinajs.cn/list=gb_ixic?#納斯達(dá)克指數(shù)
http://hq.sinajs.cn/list=int_dji
http://hq.sinajs.cn/list=int_sp500
http://hq.sinajs.cn/list=int_ftse?#倫敦指數(shù)
http://hq.sinajs.cn/list=int_bloombergeuropean500?#彭博歐洲500指數(shù)
http://hq.sinajs.cn/list=int_dax30,int_djstoxx50
外匯行情
http://hq.sinajs.cn/list=XAUUSD
http://hq.sinajs.cn/list=DINIW?#美元指數(shù)
黃金&白銀
http://hq.sinajs.cn/list=hf_XAU
http://hq.sinajs.cn/list=hf_XAG
http://hq.sinajs.cn/list=hf_GC?#COMEX黃金
http://hq.sinajs.cn/list=hf_SI?#COMEX白銀
http://hq.sinajs.cn/list=hf_AUTD?#黃金TD
http://hq.sinajs.cn/list=hf_AGTD?#白銀TD
http://hq.sinajs.cn/list=AU0?#黃金期貨
http://hq.sinajs.cn/list=AG0?#白銀期貨
http://hq.sinajs.cn/list=hf_CL?#NYMEX原油
期貨
http://hq.sinajs.cn/list=CFF_LIST?#金融期貨合約
http://finance.sina.com.cn/iframe/futures_info_cff.js?#商品與金融期貨合約
http://hq.sinajs.cn/?list=CFF_RE_IF1705?#合約行情
期權(quán)合約的月份
http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getStockName
期權(quán)合約到期日
http://stock.finance.sina.com.cn/futures/api/openapi.php/StockOptionService.getRemainderDay?date=201705
看漲期權(quán)合約
http://hq.sinajs.cn/list=OP_UP_5100501705
看跌期權(quán)合約
http://hq.sinajs.cn/list=OP_DOWN_5100501705
期權(quán)行情
http://hq.sinajs.cn/list=CON_OP_10000869
http://hq.sinajs.cn/list=CON_ZL_10000869
http://hq.sinajs.cn/list=CON_SO_10000869
熱門股票
http://finance.sina.com.cn/realstock/company/hotstock_daily_a.js
新股日歷
http://vip.stock.finance.sina.com.cn/corp/view/iframe/vAK_NewStockIssueFrame_2015.php?num=10
定增列表
http://vip.stock.finance.sina.com.cn/corp/view/vAK_IncreaseStockIssueFrame_2015.php?num=10
基金公司
http://vip.stock.finance.sina.com.cn/fund_center/api/jsonp.php/var%20companyList=/NetValue_Service.getAllCompany
?
停更數(shù)據(jù):
http://biz.finance.sina.com.cn/stock/flash_hq/kline_data.php?symbol=sh000001&end_date=20120101
http://market.finance.sina.com.cn/downxls.php?date=2011-07-08&symbol=sh600900
內(nèi)容:該業(yè)務(wù)已經(jīng)下線。給您造成的不便,深表歉意。如果行情頁(yè)無(wú)法正常訪問,可反饋至:finproduct@staff.sina.com.cn?。如果是抓接口數(shù)據(jù),臣妾就木有辦法了。您趕緊找個(gè)其他的源抓吧,我們不再恢復(fù)這個(gè)接口了~
?
6.從雅虎財(cái)經(jīng)上爬
https://finance.yahoo.com/quote/<股票代碼.交易所>/history7.愛搞搞
http://www.aigaogao.com/tools/history.html?s=<股票代碼>五、一些收費(fèi)的信息
有錢了用收費(fèi)的吧,還沒用過,也沒體驗(yàn)過。
比如東財(cái)choice(單用戶5800元一年),wind等,有很多,有錢就用收費(fèi)的。
?
?
?
六、其它
有觀點(diǎn)認(rèn)為:
獲取股票數(shù)據(jù)的渠道有很多,而且基本上是免費(fèi)的。
目前股票端用的比較多的有通達(dá)信,tushare, Quantaxis等,
期貨端有CTP,CTPBEE,VNPY,TQSDK等,
?
下面介紹幾個(gè)~
- tushare?米哥的數(shù)據(jù)框架我就不用說了吧,采取積分制,高校學(xué)生免費(fèi)獲得積分。具體請(qǐng)自行百度
- tqsdk?期貨老牌廠商快期的開源計(jì)劃的核心, 他們有期貨數(shù)據(jù)轉(zhuǎn)發(fā)權(quán),所以在他們的tqsdk中可以很輕松的調(diào)用到歷史數(shù)據(jù)。當(dāng)然他的使用也是無(wú)腦的哈哈哈哈, 好像后續(xù)計(jì)劃對(duì)接股票數(shù)據(jù)
- QUANTAXIS, 作者我就不說了,?
@余天
一己之力可以通天的大佬,同樣使用QA你可以很輕松的使用到歷史數(shù)據(jù),注意,他是將數(shù)據(jù)寫入到本地mongodb數(shù)據(jù)庫(kù)。然后同時(shí)提供了取數(shù)據(jù)的代碼。當(dāng)然QA也支持股票數(shù)據(jù)。
https://zhuanlan.zhihu.com/p/100110280
?
其它:
數(shù)據(jù)接口-免費(fèi)版(股票數(shù)據(jù)API):
獲取股票數(shù)據(jù)的源頭主要有:數(shù)據(jù)超市、雅虎、新浪、Google、和訊、搜狐、ChinaStockWebService、東方財(cái)富客戶端、證券之星、網(wǎng)易財(cái)經(jīng)。
https://blog.csdn.net/Llingmiao/article/details/79941066?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242
?
?
?
End
?
?
總結(jié)
以上是生活随笔為你收集整理的获取A股行情数据方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网格计算——下一代分布式计算
- 下一篇: ashx需要everyone权限