python 港股交易数据_GitHub - 116pythonZS/futuquant: 富途量化平台 API
FutuQuant - 富途量化投資平臺 (Futu Quant Trading API)
簡介
?FutuQuant開源項(xiàng)目可以滿足使用富途牛牛軟件進(jìn)行量化投資的需求, 提供包括Python接口、Json接口的行情及交易的API。
安裝
pip install futuquant
注: 本API同時(shí)兼容Python2和Python3, 推薦安裝anaconda環(huán)境,方便快捷。
快速上手
# 導(dǎo)入futuquant api
import futuquant as ft
# 實(shí)例化行情上下文對象
quote_ctx = ft.OpenQuoteContext(host="127.0.0.1", port=11111)
# 上下文控制
quote_ctx.start() # 開啟異步數(shù)據(jù)接收
quote_ctx.stop() # 停止異步數(shù)據(jù)接收
quote_ctx.set_handler(handler) # 設(shè)置用于異步處理數(shù)據(jù)的回調(diào)對象
# 低頻數(shù)據(jù)接口
quote_ctx.get_trading_days(market, start_date=None, end_date=None) # 獲取交易日
quote_ctx.get_stock_basicinfo(market, stock_type='STOCK') # 獲取股票信息
quote_ctx.get_history_kline(code, start=None, end=None, ktype='K_DAY', autype='qfq') # 獲取歷史K線
quote_ctx.get_autype_list(code_list) # 獲取復(fù)權(quán)因子
quote_ctx.get_market_snapshot(code_list) # 獲取市場快照
quote_ctx.get_plate_list(market, plate_class) # 獲取板塊集合下的子板塊列表
quote_ctx.get_plate_stock(market, stock_code) # 獲取板塊下的股票列表
# 高頻數(shù)據(jù)接口
quote_ctx.get_stock_quote(code_list) # 獲取報(bào)價(jià)
quote_ctx.get_rt_ticker(code, num) # 獲取逐筆
quote_ctx.get_cur_kline(code, num, ktype=' K_DAY', autype='qfq') # 獲取當(dāng)前K線
quote_ctx.get_order_book(code) # 獲取擺盤
quote_ctx.get_rt_data(code) # 獲取分時(shí)數(shù)據(jù)
quote_ctx.get_broker_queue(code) # 獲取經(jīng)紀(jì)隊(duì)列
# 實(shí)例化港股交易上下文對象
trade_hk_ctx = ft.OpenHKTradeContext(host="127.0.0.1", port=11111)
# 實(shí)例化美股交易上下文對象
trade_us_ctx = ft.OpenUSTradeContext(host="127.0.0.1", port=11111)
# 交易接口列表
ret_code, ret_data = trade_hk_ctx.unlock_trade(password='123456') # 解鎖接口
ret_code, ret_data = trade_hk_ctx.place_order(price, qty, strcode, orderside, ordertype=0, envtype=0) # 下單接口
ret_code, ret_data = trade_hk_ctx.set_order_status(status, orderid=0, envtype=0) # 設(shè)置訂單狀態(tài)
ret_code, ret_data = trade_hk_ctx.change_order(price, qty, orderid=0, envtype=0) # 修改訂單
ret_code, ret_data = trade_hk_ctx.accinfo_query(envtype=0) # 查詢賬戶信息
ret_code, ret_data = trade_hk_ctx.order_list_query(statusfilter="", envtype=0) # 查詢訂單列表
ret_code, ret_data = trade_hk_ctx.position_list_query(envtype=0) # 查詢持倉列表
ret_code, ret_data = trade_hk_ctx.deal_list_query(envtype=0) # 查詢成交列表
示例策略
示例策略文件位于目錄: (futuquant包安裝目錄)/futuquant/examples 下,用戶可參考實(shí)例策略來學(xué)習(xí)API的使用。
另外,可參考API相對應(yīng)的視頻課程學(xué)習(xí)API的使用。
組織結(jié)構(gòu)
?最新版本在master分支。之前各版本在其他分支上。
API與富途牛牛客戶端架構(gòu)
使用須知
限定使用有API后綴的安裝包。不要去掉勾選“安裝量化交易插件API”選項(xiàng)。
無需拷貝對應(yīng)的dll插件。
安裝成功后直接使用接口進(jìn)行行情獲取或者交易操作。
歷史數(shù)據(jù)及除權(quán)除息下載問題
在富途牛牛安裝目錄的plugin文件夾內(nèi)有歷史數(shù)據(jù)下載配置文件(ftplugin.ini),請先詳細(xì)閱讀再進(jìn)行操作。
如果不想下載新數(shù)據(jù)、可以將開始時(shí)間和暫停下載時(shí)間設(shè)置為相同時(shí)間。
如果選擇下載的數(shù)據(jù)越大,下載所需時(shí)間越長。如果中途退出,下次開啟時(shí)將重新下載。請勿在下載過程中關(guān)閉牛牛客戶端。
客戶端下載及交流方式
富途開放API群(108534288) 群文件 >富途牛牛客戶端(API接口專用版本)
使用說明
有任何問題可以到 issues 處提出,我們會及時(shí)進(jìn)行解答。
使用新版本時(shí)請先仔細(xì)閱讀接口文檔,大部分問題都可以在接口文檔中找到你想要的答案。
歡迎大家提出建議、也可以提出各種需求,我們一定會盡量滿足大家的需求。
總結(jié)
以上是生活随笔為你收集整理的python 港股交易数据_GitHub - 116pythonZS/futuquant: 富途量化平台 API的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 九九乘法表代码口述_利用随机函数实现座次
- 下一篇: python判断奇偶数字符串的拼接_Py