# 條件選股
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_stock_filter(market, filter_list, plate_code=None, begin=0, num=200)
介紹
條件選股
參數
參數 類型 説明 market Market 市場標識 不區分滬股和深股,傳入滬股或者深股都會返回滬深市場的股票filter_list list 篩選條件的列表 參考下面的表格,列表中元素類型為 SimpleFilter 或 AccumulateFilter 或 FinancialFilterplate_code str 板塊代碼 begin int 數據起始點 num int 請求數據個數 SimpleFilter 對象相關參數如下:
欄位 類型 説明 stock_field StockField 簡單屬性 filter_min float 區間下限 閉區間
不傳預設為 -∞filter_max float 區間上限 閉區間
不傳預設為 +∞is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選sort SortDir 排序方向 不傳預設為不排序AccumulateFilter 對象相關參數如下:
欄位 類型 説明 stock_field StockField 累積屬性 filter_min float 區間下限 閉區間
不傳預設為 -∞filter_max float 區間上限 閉區間
不傳預設為 +∞is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選sort SortDir 排序方向 不傳預設為不排序days int 所篩選的數據的累計天數 FinancialFilter 對象相關參數如下:
欄位 類型 説明 stock_field StockField 財務屬性 filter_min float 區間下限 閉區間
不傳預設為 -∞filter_max float 區間上限 閉區間
不傳預設為 +∞is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選sort SortDir 排序方向 不傳預設為不排序quarter FinancialQuarter 財報累積時間 CustomIndicatorFilter 對象相關參數如下:
欄位 類型 説明 stock_field1 StockField 自定義技術指標屬性 stock_field1_para list 自定義技術指標屬性參數 根據指標類型進行傳參:
1. MA:[平均移動週期]
2.EMA:[指數移動平均週期]
3.RSI:[RSI 指標週期]
4.MACD:[快速平均線值, 慢速平均線值, DIF值]
5.BOLL:[均線週期, 偏移值]
6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]relative_position RelativePosition 相對位置 stock_field2 StockField 自定義技術指標屬性 stock_field2_para list 自定義技術指標屬性參數 根據指標類型進行傳參:
1. MA:[平均移動週期]
2.EMA:[指數移動平均週期]
3.RSI:[RSI 指標週期]
4.MACD:[快速平均線值, 慢速平均線值, DIF值]
5.BOLL:[均線週期, 偏移值]
6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]value float 自定義數值 當 stock_field2 在 StockField 中選擇自定義數值時,value 為必傳參數ktype KLType K線類型 KLType 僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期consecutive_period int 篩選連續週期(consecutive_period)都符合條件的數據 填寫範圍為[1,12]is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選PatternFilter 對象相關參數如下:
欄位 類型 説明 stock_field StockField 形態技術指標屬性 ktype KLType K線類型 KLType (僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期) consecutive_period int 篩選連續週期(consecutive_period)都符合條件的數據 填寫範圍為[1,12]is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選
返回
參數 類型 説明 ret RET_CODE 介面呼叫結果 data tuple 當 ret == RET_OK,返回選股數據 str 當 ret != RET_OK,返回錯誤描述 選股數據元組組成如下:
欄位 類型 説明 last_page bool 是否是最後一頁 all_count int 列表總數量 stock_list list 選股數據 list 中元素類型是 FilterStockDataFilterStockData 類型的欄位格式:
欄位 類型 説明 stock_code str 股票代碼 stock_name str 股票名字 cur_price float 最新價 cur_price_to_highest_52weeks_ratio float (現價 - 52周最高)/52周最高 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%cur_price_to_lowest_52weeks_ratio float (現價 - 52周最低)/52周最低 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%high_price_to_highest_52weeks_ratio float (今日最高 - 52周最高)/52周最高 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%low_price_to_lowest_52weeks_ratio float (今日最低 - 52周最低)/52周最低 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%volume_ratio float 量比 bid_ask_ratio float 委比 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%lot_price float 每手價格 market_val float 市值 pe_annual float 市盈率 pe_ttm float 市盈率 TTM pb_rate float 市淨率 change_rate_5min float 五分鐘價格漲跌幅 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%change_rate_begin_year float 年初至今價格漲跌幅 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%ps_ttm float 市銷率 TTM 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%pcf_ttm float 市現率 TTM 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%total_share float 總股數 單位:股float_share float 流通股數 單位:股float_market_val float 流通市值 單位:元change_rate float 漲跌幅 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%amplitude float 振幅 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%volume float 日均成交量 turnover float 日均成交額 turnover_rate float 換手率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%net_profit float 淨利潤 net_profix_growth float 淨利潤增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%sum_of_business float 營業收入 sum_of_business_growth float 營業同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%net_profit_rate float 淨利率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%gross_profit_rate float 毛利率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%debt_asset_rate float 資產負債率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%return_on_equity_rate float 淨資產收益率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%roic float 投入資本回報率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%roa_ttm float 資產回報率 TTM 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%。僅適用於年報ebit_ttm float 息税前利潤 TTM 單位:元。僅適用於年報ebitda float 税息折舊及攤銷前利潤 單位:元operating_margin_ttm float 營業利潤率 TTM 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%。僅適用於年報ebit_margin float EBIT 利潤率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%ebitda_margin float EBITDA 利潤率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%financial_cost_rate float 財務成本率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_profit_ttm float 營業利潤 TTM 單位:元。僅適用於年報shareholder_net_profit_ttm float 歸屬於母公司的淨利潤 單位:元。僅適用於年報net_profit_cash_cover_ttm float 盈利中的現金收入比例 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%。僅適用於年報current_ratio float 流動比率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%quick_ratio float 速動比率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%current_asset_ratio float 流動資產率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%current_debt_ratio float 流動負債率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%equity_multiplier float 權益乘數 property_ratio float 產權比率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%cash_and_cash_equivalents float 現金和現金等價 單位:元total_asset_turnover float 總資產週轉率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%fixed_asset_turnover float 固定資產週轉率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%inventory_turnover float 存貨週轉率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_cash_flow_ttm float 經營活動現金流 TTM 單位:元。僅適用於年報accounts_receivable float 應收賬款淨額 單位:元ebit_growth_rate float EBIT 同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_profit_growth_rate float 營業利潤同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%total_assets_growth_rate float 總資產同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%profit_to_shareholders_growth_rate float 歸母淨利潤同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%profit_before_tax_growth_rate float 總利潤同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%eps_growth_rate float EPS 同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%roe_growth_rate float ROE 同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%roic_growth_rate float ROIC 同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%nocf_growth_rate float 經營現金流同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%nocf_per_share_growth_rate float 每股經營現金流同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_revenue_cash_cover float 經營現金收入比 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_profit_to_total_profit float 營業利潤佔比 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%basic_eps float 基本每股收益 單位:元diluted_eps float 稀釋每股收益 單位:元nocf_per_share float 每股經營現金淨流量 單位:元price float 最新價格 ma float 簡單均線 根據 MA 參數返回具體的數值ma5 float 5日簡單均線 ma10 float 10日簡單均線 ma20 float 20日簡單均線 ma30 float 30日簡單均線 ma60 float 60日簡單均線 ma120 float 120日簡單均線 ma250 float 250日簡單均線 rsi float RSI的值 根據 RSI 參數返回具體的數值,RSI 預設參數為12ema float 指數移動均線 根據 EMA 參數返回具體的數值ema5 float 5日指數移動均線 ema10 float 10日指數移動均線 ema20 float 20日指數移動均線 ema30 float 30日指數移動均線 ema60 float 60日指數移動均線 ema120 float 120日指數移動均線 ema250 float 250日指數移動均線 kdj_k float KDJ 指標的 K 值 根據 KDJ 參數返回具體的數值,KDJ 預設參數為[9,3,3]kdj_d float KDJ 指標的 D 值 根據 KDJ 參數返回具體的數值,KDJ 預設參數為[9,3,3]kdj_j float KDJ 指標的 J 值 根據 KDJ 參數返回具體的數值,KDJ 預設參數為[9,3,3]macd_diff float MACD 指標的 DIFF 值 根據 MACD 參數返回具體的數值,MACD 預設參數為[12,26,9]macd_dea float MACD 指標的 DEA 值 根據 MACD 參數返回具體的數值,MACD 預設參數為[12,26,9]macd float MACD 指標的 MACD 值 根據 MACD 參數返回具體的數值,MACD 預設參數為[12,26,9]boll_upper float BOLL 指標的 UPPER 值 根據 BOLL 參數返回具體的數值,BOLL 預設參數為[20.2]boll_middler float BOLL 指標的 MIDDLER 值 根據 BOLL 參數返回具體的數值,BOLL 預設參數為[20.2]boll_lower float BOLL 指標的 LOWER 值 根據 BOLL 參數返回具體的數值,BOLL 預設參數為[20.2]
Example
from futu import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
simple_filter = SimpleFilter()
simple_filter.filter_min = 2
simple_filter.filter_max = 1000
simple_filter.stock_field = StockField.CUR_PRICE
simple_filter.is_no_filter = False
# simple_filter.sort = SortDir.ASCEND
financial_filter = FinancialFilter()
financial_filter.filter_min = 0.5
financial_filter.filter_max = 50
financial_filter.stock_field = StockField.CURRENT_RATIO
financial_filter.is_no_filter = False
financial_filter.sort = SortDir.ASCEND
financial_filter.quarter = FinancialQuarter.ANNUAL
custom_filter = CustomIndicatorFilter()
custom_filter.ktype = KLType.K_DAY
custom_filter.stock_field1 = StockField.KDJ_K
custom_filter.stock_field1_para = [10,4,4]
custom_filter.stock_field2 = StockField.KDJ_K
custom_filter.stock_field2_para = [9,3,3]
custom_filter.relative_position = RelativePosition.MORE
custom_filter.is_no_filter = False
nBegin = 0
last_page = False
ret_list = list()
while not last_page:
nBegin += len(ret_list)
ret, ls = quote_ctx.get_stock_filter(market=Market.HK, filter_list=[simple_filter, financial_filter, custom_filter], begin=nBegin) # 對香港市場的股票做簡單、財務和指標篩選
if ret == RET_OK:
last_page, all_count, ret_list = ls
print('all count = ', all_count)
for item in ret_list:
print(item.stock_code) # 取股票代碼
print(item.stock_name) # 取股票名稱
print(item[simple_filter]) # 取 simple_filter 對應的變量值
print(item[financial_filter]) # 取 financial_filter 對應的變量值
print(item[custom_filter]) # 獲取 custom_filter 的數值
else:
print('error: ', ls)
time.sleep(3) # 加入時間間隔,避免觸發限頻
quote_ctx.close() # 結束後記得關閉當條連線,防止連線條數用盡
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
- Output
39 39 [ stock_code:HK.08103 stock_name:HMVOD視頻 cur_price:2.69 current_ratio(annual):4.413 , stock_code:HK.00376 stock_name:雲鋒金融 cur_price:2.96 current_ratio(annual):12.585 , stock_code:HK.09995 stock_name:榮昌生物-B cur_price:92.65 current_ratio(annual):16.054 , stock_code:HK.80737 stock_name:灣區發展-R cur_price:2.8 current_ratio(annual):17.249 , stock_code:HK.00737 stock_name:灣區發展 cur_price:3.25 current_ratio(annual):17.249 , stock_code:HK.03939 stock_name:萬國國際礦業 cur_price:2.22 current_ratio(annual):17.323 , stock_code:HK.01055 stock_name:中國南方航空股份 cur_price:5.17 current_ratio(annual):17.529 , stock_code:HK.02638 stock_name:港燈-SS cur_price:7.68 current_ratio(annual):21.255 , stock_code:HK.00670 stock_name:中國東方航空股份 cur_price:3.53 current_ratio(annual):25.194 , stock_code:HK.01952 stock_name:雲頂新耀-B cur_price:69.5 current_ratio(annual):26.029 , stock_code:HK.00089 stock_name:大生地產 cur_price:4.22 current_ratio(annual):26.914 , stock_code:HK.00728 stock_name:中國電信 cur_price:2.81 current_ratio(annual):27.651 , stock_code:HK.01372 stock_name:比速科技 cur_price:5.1 current_ratio(annual):28.303 , stock_code:HK.00753 stock_name:中國國航 cur_price:6.38 current_ratio(annual):31.828 , stock_code:HK.01997 stock_name:九龍倉置業 cur_price:43.75 current_ratio(annual):33.239 , stock_code:HK.02158 stock_name:醫渡科技 cur_price:39.0 current_ratio(annual):34.046 , stock_code:HK.02588 stock_name:中銀航空租賃 cur_price:77.0 current_ratio(annual):34.531 , stock_code:HK.01330 stock_name:綠色動力環保 cur_price:3.36 current_ratio(annual):35.028 , stock_code:HK.01525 stock_name:建橋教育 cur_price:6.28 current_ratio(annual):36.989 , stock_code:HK.09908 stock_name:嘉興燃氣 cur_price:10.02 current_ratio(annual):37.848 , stock_code:HK.06078 stock_name:海吉亞醫療 cur_price:49.8 current_ratio(annual):39.0 , stock_code:HK.01071 stock_name:華電國際電力股份 cur_price:2.16 current_ratio(annual):39.507 , stock_code:HK.00357 stock_name:美蘭空港 cur_price:34.15 current_ratio(annual):39.514 , stock_code:HK.00762 stock_name:中國聯通 cur_price:5.15 current_ratio(annual):40.74 , stock_code:HK.01787 stock_name:山東黃金 cur_price:15.56 current_ratio(annual):41.604 , stock_code:HK.00902 stock_name:華能國際電力股份 cur_price:2.66 current_ratio(annual):42.919 , stock_code:HK.00934 stock_name:中石化冠德 cur_price:2.96 current_ratio(annual):43.361 , stock_code:HK.01117 stock_name:現代牧業 cur_price:2.3 current_ratio(annual):45.037 , stock_code:HK.00177 stock_name:江蘇寧滬高速公路 cur_price:8.78 current_ratio(annual):45.93 , stock_code:HK.01379 stock_name:温嶺工量刃具 cur_price:5.71 current_ratio(annual):46.774 , stock_code:HK.01876 stock_name:百威亞太 cur_price:22.5 current_ratio(annual):46.917 , stock_code:HK.01907 stock_name:中國旭陽集團 cur_price:4.38 current_ratio(annual):47.129 , stock_code:HK.02160 stock_name:心通醫療-B cur_price:15.54 current_ratio(annual):47.384 , stock_code:HK.00293 stock_name:國泰航空 cur_price:7.1 current_ratio(annual):47.983 , stock_code:HK.00694 stock_name:北京首都機場股份 cur_price:6.34 current_ratio(annual):47.985 , stock_code:HK.09922 stock_name:九毛九 cur_price:26.65 current_ratio(annual):48.278 , stock_code:HK.01083 stock_name:港華燃氣 cur_price:3.39 current_ratio(annual):49.2 , stock_code:HK.00291 stock_name:華潤啤酒 cur_price:58.0 current_ratio(annual):49.229 , stock_code:HK.00306 stock_name:冠忠巴士集團 cur_price:2.29 current_ratio(annual):49.769 ]
HK.08103
HMVOD視頻
2.69
2.69
4.413
...
HK.00306
冠忠巴士集團
2.29
2.29
49.769
2
3
4
5
6
7
8
9
10
11
12
# Qot_StockFilter.proto
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性欄位名“field”與C#protocol buf保留的函數名衝突,Futu API將從3.18版本開始將該欄位重命名為“fieldName”。請注意修改相應介面中使用的欄位名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
協議 ID
3215
uint StockFilter(QotStockFilter.Request req);
virtual void OnReply_StockFilter(FTAPI_Conn client, uint nSerialNo, QotStockFilter.Response rsp);
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性欄位名“field”與C#protocol buf保留的函數名衝突,Futu API將從3.18版本開始將該欄位重命名為“fieldName”。請注意修改相應介面中使用的欄位名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
- Example
public class Program : FTSPI_Qot, FTSPI_Conn {
FTAPI_Qot qot = new FTAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //設定用戶端資訊
qot.SetConnCallback(this); //設定連線回呼
qot.SetQotCallback(this); //設定交易回呼
}
public void Start() {
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(FTAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotStockFilter.BaseFilter filter = QotStockFilter.BaseFilter.CreateBuilder()
.SetFieldName(QotStockFilter.StockField.StockField_CurPrice)
.SetFilterMax(100)
.SetFilterMax(200)
.Build();
QotStockFilter.C2S c2s = QotStockFilter.C2S.CreateBuilder()
.SetBegin(0)
.SetNum(10)
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.AddBaseFilterList(filter)
.Build();
QotStockFilter.Request req = QotStockFilter.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.StockFilter(req);
Console.Write("Send QotStockFilter: {0}\n", seqNo);
}
public void OnDisconnect(FTAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_StockFilter(FTAPI_Conn client, uint nSerialNo, QotStockFilter.Response rsp)
{
Console.Write("Reply: QotStockFilter: {0}\n", nSerialNo, rsp.ToString());
Console.Write("code: {0}, name: {1} \n", rsp.S2C.DataListList[0].Security.Code,
rsp.S2C.DataListList[0].Name);
}
public static void Main(String[] args) {
FTAPI.Init();
Program qot = new Program();
qot.Start();
while (true)
Thread.Sleep(1000 * 600);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- Output
Qot onInitConnect: ret=0 desc= connID=6825721743616225277
Send QotStockFilter: 3
Reply: QotStockFilter: 3
code: 00376, name: 雲鋒金融
2
3
4
int stockFilter(QotStockFilter.Request req);
void onReply_StockFilter(FTAPI_Conn client, int nSerialNo, QotStockFilter.Response rsp);
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性欄位名“field”與C#protocol buf保留的函數名衝突,Futu API將從3.18版本開始將該欄位重命名為“fieldName”。請注意修改相應介面中使用的欄位名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
- Example
public class QotDemo implements FTSPI_Qot, FTSPI_Conn {
FTAPI_Conn_Qot qot = new FTAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //設定用戶端資訊
qot.setConnSpi(this); //設定連線回呼
qot.setQotSpi(this); //設定交易回呼
}
public void start() {
qot.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(FTAPI_Conn client, long errCode, String desc)
{
System.out.printf("Qot onInitConnect: ret=%b desc=%s connID=%d\n", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
QotStockFilter.BaseFilter filter = QotStockFilter.BaseFilter.newBuilder()
.setFieldName(QotStockFilter.StockField.StockField_CurPrice_VALUE)
.setFilterMax(100)
.setFilterMax(200)
.build();
QotStockFilter.C2S c2s = QotStockFilter.C2S.newBuilder()
.setBegin(0)
.setNum(10)
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.addBaseFilterList(filter)
.build();
QotStockFilter.Request req = QotStockFilter.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.stockFilter(req);
System.out.printf("Send QotStockFilter: %d\n", seqNo);
}
@Override
public void onDisconnect(FTAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_StockFilter(FTAPI_Conn client, int nSerialNo, QotStockFilter.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotStockFilter failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotStockFilter: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
FTAPI.init();
QotDemo qot = new QotDemo();
qot.start();
while (true) {
try {
Thread.sleep(1000 * 600);
} catch (InterruptedException exc) {
}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
- Output
Send QotStockFilter: 2
Receive QotStockFilter: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"lastPage": false,
"allCount": 2431,
"dataList": [{
"security": {
"market": 1,
"code": "08560"
},
"name": "世大控股"
}, ... {
"security": {
"market": 1,
"code": "02171"
},
"name": "科濟藥業-B"
}]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Futu::u32_t StockFilter(const Qot_StockFilter::Request &stReq);
virtual void OnReply_StockFilter(Futu::u32_t nSerialNo, const Qot_StockFilter::Response &stRsp) = 0;
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性欄位名“field”與C#protocol buf保留的函數名衝突,Futu API將從3.18版本開始將該欄位重命名為“fieldName”。請注意修改相應介面中使用的欄位名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
- Example
class Program : public FTSPI_Qot, public FTSPI_Trd, public FTSPI_Conn
{
public:
Program() {
m_pQotApi = FTAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr)
{
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
FTAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(FTAPI_Conn* pConn, Futu::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// 組包
Qot_StockFilter::Request req;
Qot_StockFilter::C2S *c2s = req.mutable_c2s();
c2s->set_begin(0);
c2s->set_num(50);
c2s->set_market(1);
m_StockFilterSerialNo = m_pQotApi->StockFilter(req);
cout << "Request StockFilter SerialNo: " << m_StockFilterSerialNo << endl;
}
virtual void OnReply_StockFilter(Futu::u32_t nSerialNo, const Qot_StockFilter::Response &stRsp){
if(nSerialNo == m_StockFilterSerialNo)
{
cout << "OnReply_StockFilter SerialNo: " << nSerialNo << endl;
// 解析內部結構列印出來
// ProtoBufToBodyData和UTF8ToLocal函數的定義參見Sample中的tool.h檔案
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
FTAPI_Qot *m_pQotApi;
Futu::u32_t m_StockFilterSerialNo;
};
int32_t main(int32_t argc, char** argv)
{
FTAPI::Init();
{
Program program;
program.Start();
getchar();
}
protobuf::ShutdownProtobufLibrary();
FTAPI::UnInit();
return 0;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
- Output
connect
Request StockFilter SerialNo: 4
OnReply_StockFilter SerialNo: 4
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"lastPage": false,
"allCount": 2426,
"dataList": [
{
"security": {
"market": 1,
"code": "02930"
},
"name": "絲路物流控股"
},
...
{
"security": {
"market": 1,
"code": "01440"
},
"name": "DEYUN HOLDING"
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
StockFilter(req);
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性欄位名“field”與C#protocol buf保留的函數名衝突,Futu API將從3.18版本開始將該欄位重命名為“fieldName”。請注意修改相應介面中使用的欄位名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
- Example
import ftWebsocket from "futu-api";
import { ftCmdID } from "futu-api";
import { Common, Qot_Common } from "futu-api/proto";
import beautify from "js-beautify";
function QotStockFilter(){
const { RetType } = Common
const { QotMarket } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new ftWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) { // 登入成功
const req = {
c2s: {
begin: 0,
num: 2,
market: QotMarket.QotMarket_HK_Security,
},
};
websocket.StockFilter(req)
.then((res) => {
let { errCode, retMsg, retType,s2c } = res
console.log("StockFilter: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(data);
}
})
.catch((error) => {
console.log("error:", error);
});
} else {
console.log("error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
//關閉行情連線,連線不再使用之後,要關閉,否則佔用不必要資源
//同時OpenD也限制了最多128條連線
//也可以一個頁面或者一個專案維護一條連線,這裡範例請求一次建立一條連線
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // 5秒後斷開
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
- Output
StockFilter: errCode 0, retMsg , retType 0
{
"lastPage": false,
"allCount": 2436,
"dataList": [{
"security": {
"market": 1,
"code": "08579"
},
"name": "萬亞企業控股"
}, {
"security": {
"market": 1,
"code": "09869"
},
"name": "海倫司"
}]
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
提示
- 利用獲取子板塊列表函數 獲取子板塊代碼,條件選股支援的板塊分別為
- 港股的行業板塊和概念板塊。
- 美股的行業板塊
- 滬深的行業板塊,概念板塊和地域板塊
- 支援的板塊指數代碼
代碼 説明 HK.Motherboard 港股主板 HK.GEM 港股創業板 HK.BK1911 H 股主板 HK.BK1912 H 股創業板 US.NYSE 紐交所 US.AMEX 美交所 US.NASDAQ 納斯達克 SH.3000000 上海主板 SZ.3000001 深證主板 SZ.3000004 深證創業板
介面限制
- 港股 BMP 權限不支援條件選股功能
- 每 30 秒內最多請求 10 次條件選股介面
- 每頁返回的篩選結果最多 200 個
- 建議篩選條件不超過 250 個,否則可能會出現“業務處理超時沒返回”
- 累積屬性的同一篩選條件數量上限 10 個
- 如果使用“最新價”等動態數據作為排序字段,在多頁獲取的間隙,數據的排序有可能發生變化
- 非同類指標不支援比較,僅限於同類指標之間建立比較關係,跨不同類型的指標比較會報錯。例如:MA5 和 MA10 可以建立關係。MA5和EMA10不能建立關係。
- 自定義指標屬性的同一類篩選條件超出數量上限10個
- 簡單屬性,財務屬性,形態屬性不支援對同一字段重複指定篩選條件
- 條件選股暫不支援美股盤前盤後、夜盤,篩選結果均按照盤中數據返回
- Python
- Proto
- C#
- Java
- C++
- JavaScript
get_stock_filter(market, filter_list, plate_code=None, begin=0, num=200)
介紹
條件選股
參數
參數 類型 説明 market Market 市場標識 不區分滬股和深股,傳入滬股或者深股都會返回滬深市場的股票filter_list list 篩選條件的列表 參考下面的表格,列表中元素類型為 SimpleFilter 或 AccumulateFilter 或 FinancialFilterplate_code str 板塊代碼 begin int 數據起始點 num int 請求數據個數 SimpleFilter 對象相關參數如下:
欄位 類型 説明 stock_field StockField 簡單屬性 filter_min float 區間下限 閉區間
不傳預設為 -∞filter_max float 區間上限 閉區間
不傳預設為 +∞is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選sort SortDir 排序方向 不傳預設為不排序AccumulateFilter 對象相關參數如下:
欄位 類型 説明 stock_field StockField 累積屬性 filter_min float 區間下限 閉區間
不傳預設為 -∞filter_max float 區間上限 閉區間
不傳預設為 +∞is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選sort SortDir 排序方向 不傳預設為不排序days int 所篩選的數據的累計天數 FinancialFilter 對象相關參數如下:
欄位 類型 説明 stock_field StockField 財務屬性 filter_min float 區間下限 閉區間
不傳預設為 -∞filter_max float 區間上限 閉區間
不傳預設為 +∞is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選sort SortDir 排序方向 不傳預設為不排序quarter FinancialQuarter 財報累積時間 CustomIndicatorFilter 對象相關參數如下:
欄位 類型 説明 stock_field1 StockField 自定義技術指標屬性 stock_field1_para list 自定義技術指標屬性參數 根據指標類型進行傳參:
1. MA:[平均移動週期]
2.EMA:[指數移動平均週期]
3.RSI:[RSI 指標週期]
4.MACD:[快速平均線值, 慢速平均線值, DIF值]
5.BOLL:[均線週期, 偏移值]
6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]relative_position RelativePosition 相對位置 stock_field2 StockField 自定義技術指標屬性 stock_field2_para list 自定義技術指標屬性參數 根據指標類型進行傳參:
1. MA:[平均移動週期]
2.EMA:[指數移動平均週期]
3.RSI:[RSI 指標週期]
4.MACD:[快速平均線值, 慢速平均線值, DIF值]
5.BOLL:[均線週期, 偏移值]
6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]value float 自定義數值 當 stock_field2 在 StockField 中選擇自定義數值時,value 為必傳參數ktype KLType K線類型 KLType 僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期consecutive_period int 篩選連續週期(consecutive_period)都符合條件的數據 填寫範圍為[1,12]is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選PatternFilter 對象相關參數如下:
欄位 類型 説明 stock_field StockField 形態技術指標屬性 ktype KLType K線類型 KLType (僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期) consecutive_period int 篩選連續週期(consecutive_period)都符合條件的數據 填寫範圍為[1,12]is_no_filter bool 該欄位是否不需要篩選 True:不篩選
False:篩選
不傳預設不篩選
返回
參數 類型 説明 ret RET_CODE 介面呼叫結果 data tuple 當 ret == RET_OK,返回選股數據 str 當 ret != RET_OK,返回錯誤描述 選股數據元組組成如下:
欄位 類型 説明 last_page bool 是否是最後一頁 all_count int 列表總數量 stock_list list 選股數據 list 中元素類型是 FilterStockDataFilterStockData 類型的欄位格式:
欄位 類型 説明 stock_code str 股票代碼 stock_name str 股票名字 cur_price float 最新價 cur_price_to_highest_52weeks_ratio float (現價 - 52周最高)/52周最高 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%cur_price_to_lowest_52weeks_ratio float (現價 - 52周最低)/52周最低 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%high_price_to_highest_52weeks_ratio float (今日最高 - 52周最高)/52周最高 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%low_price_to_lowest_52weeks_ratio float (今日最低 - 52周最低)/52周最低 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%volume_ratio float 量比 bid_ask_ratio float 委比 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%lot_price float 每手價格 market_val float 市值 pe_annual float 市盈率 pe_ttm float 市盈率 TTM pb_rate float 市淨率 change_rate_5min float 五分鐘價格漲跌幅 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%change_rate_begin_year float 年初至今價格漲跌幅 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%ps_ttm float 市銷率 TTM 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%pcf_ttm float 市現率 TTM 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%total_share float 總股數 單位:股float_share float 流通股數 單位:股float_market_val float 流通市值 單位:元change_rate float 漲跌幅 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%amplitude float 振幅 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%volume float 日均成交量 turnover float 日均成交額 turnover_rate float 換手率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%net_profit float 淨利潤 net_profix_growth float 淨利潤增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%sum_of_business float 營業收入 sum_of_business_growth float 營業同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%net_profit_rate float 淨利率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%gross_profit_rate float 毛利率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%debt_asset_rate float 資產負債率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%return_on_equity_rate float 淨資產收益率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%roic float 投入資本回報率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%roa_ttm float 資產回報率 TTM 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%。僅適用於年報ebit_ttm float 息税前利潤 TTM 單位:元。僅適用於年報ebitda float 税息折舊及攤銷前利潤 單位:元operating_margin_ttm float 營業利潤率 TTM 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%。僅適用於年報ebit_margin float EBIT 利潤率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%ebitda_margin float EBITDA 利潤率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%financial_cost_rate float 財務成本率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_profit_ttm float 營業利潤 TTM 單位:元。僅適用於年報shareholder_net_profit_ttm float 歸屬於母公司的淨利潤 單位:元。僅適用於年報net_profit_cash_cover_ttm float 盈利中的現金收入比例 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%。僅適用於年報current_ratio float 流動比率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%quick_ratio float 速動比率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%current_asset_ratio float 流動資產率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%current_debt_ratio float 流動負債率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%equity_multiplier float 權益乘數 property_ratio float 產權比率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%cash_and_cash_equivalents float 現金和現金等價 單位:元total_asset_turnover float 總資產週轉率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%fixed_asset_turnover float 固定資產週轉率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%inventory_turnover float 存貨週轉率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_cash_flow_ttm float 經營活動現金流 TTM 單位:元。僅適用於年報accounts_receivable float 應收賬款淨額 單位:元ebit_growth_rate float EBIT 同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_profit_growth_rate float 營業利潤同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%total_assets_growth_rate float 總資產同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%profit_to_shareholders_growth_rate float 歸母淨利潤同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%profit_before_tax_growth_rate float 總利潤同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%eps_growth_rate float EPS 同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%roe_growth_rate float ROE 同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%roic_growth_rate float ROIC 同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%nocf_growth_rate float 經營現金流同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%nocf_per_share_growth_rate float 每股經營現金流同比增長率 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_revenue_cash_cover float 經營現金收入比 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%operating_profit_to_total_profit float 營業利潤佔比 該欄位為百分比欄位,預設不展示 %,如 20 實際對應 20%basic_eps float 基本每股收益 單位:元diluted_eps float 稀釋每股收益 單位:元nocf_per_share float 每股經營現金淨流量 單位:元price float 最新價格 ma float 簡單均線 根據 MA 參數返回具體的數值ma5 float 5日簡單均線 ma10 float 10日簡單均線 ma20 float 20日簡單均線 ma30 float 30日簡單均線 ma60 float 60日簡單均線 ma120 float 120日簡單均線 ma250 float 250日簡單均線 rsi float RSI的值 根據 RSI 參數返回具體的數值,RSI 預設參數為12ema float 指數移動均線 根據 EMA 參數返回具體的數值ema5 float 5日指數移動均線 ema10 float 10日指數移動均線 ema20 float 20日指數移動均線 ema30 float 30日指數移動均線 ema60 float 60日指數移動均線 ema120 float 120日指數移動均線 ema250 float 250日指數移動均線 kdj_k float KDJ 指標的 K 值 根據 KDJ 參數返回具體的數值,KDJ 預設參數為[9,3,3]kdj_d float KDJ 指標的 D 值 根據 KDJ 參數返回具體的數值,KDJ 預設參數為[9,3,3]kdj_j float KDJ 指標的 J 值 根據 KDJ 參數返回具體的數值,KDJ 預設參數為[9,3,3]macd_diff float MACD 指標的 DIFF 值 根據 MACD 參數返回具體的數值,MACD 預設參數為[12,26,9]macd_dea float MACD 指標的 DEA 值 根據 MACD 參數返回具體的數值,MACD 預設參數為[12,26,9]macd float MACD 指標的 MACD 值 根據 MACD 參數返回具體的數值,MACD 預設參數為[12,26,9]boll_upper float BOLL 指標的 UPPER 值 根據 BOLL 參數返回具體的數值,BOLL 預設參數為[20.2]boll_middler float BOLL 指標的 MIDDLER 值 根據 BOLL 參數返回具體的數值,BOLL 預設參數為[20.2]boll_lower float BOLL 指標的 LOWER 值 根據 BOLL 參數返回具體的數值,BOLL 預設參數為[20.2]
Example
from moomoo import *
import time
quote_ctx = OpenQuoteContext(host='127.0.0.1', port=11111)
simple_filter = SimpleFilter()
simple_filter.filter_min = 2
simple_filter.filter_max = 1000
simple_filter.stock_field = StockField.CUR_PRICE
simple_filter.is_no_filter = False
# simple_filter.sort = SortDir.ASCEND
financial_filter = FinancialFilter()
financial_filter.filter_min = 0.5
financial_filter.filter_max = 50
financial_filter.stock_field = StockField.CURRENT_RATIO
financial_filter.is_no_filter = False
financial_filter.sort = SortDir.ASCEND
financial_filter.quarter = FinancialQuarter.ANNUAL
custom_filter = CustomIndicatorFilter()
custom_filter.ktype = KLType.K_DAY
custom_filter.stock_field1 = StockField.KDJ_K
custom_filter.stock_field1_para = [10,4,4]
custom_filter.stock_field2 = StockField.KDJ_K
custom_filter.stock_field2_para = [9,3,3]
custom_filter.relative_position = RelativePosition.MORE
custom_filter.is_no_filter = False
nBegin = 0
last_page = False
ret_list = list()
while not last_page:
nBegin += len(ret_list)
ret, ls = quote_ctx.get_stock_filter(market=Market.HK, filter_list=[simple_filter, financial_filter, custom_filter], begin=nBegin) # 對香港市場的股票做簡單、財務和指標篩選
if ret == RET_OK:
last_page, all_count, ret_list = ls
print('all count = ', all_count)
for item in ret_list:
print(item.stock_code) # 取股票代碼
print(item.stock_name) # 取股票名稱
print(item[simple_filter]) # 取 simple_filter 對應的變量值
print(item[financial_filter]) # 取 financial_filter 對應的變量值
print(item[custom_filter]) # 獲取 custom_filter 的數值
else:
print('error: ', ls)
time.sleep(3) # 加入時間間隔,避免觸發限頻
quote_ctx.close() # 結束後記得關閉當條連線,防止連線條數用盡
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
- Output
39 39 [ stock_code:HK.08103 stock_name:HMVOD視頻 cur_price:2.69 current_ratio(annual):4.413 , stock_code:HK.00376 stock_name:雲鋒金融 cur_price:2.96 current_ratio(annual):12.585 , stock_code:HK.09995 stock_name:榮昌生物-B cur_price:92.65 current_ratio(annual):16.054 , stock_code:HK.80737 stock_name:灣區發展-R cur_price:2.8 current_ratio(annual):17.249 , stock_code:HK.00737 stock_name:灣區發展 cur_price:3.25 current_ratio(annual):17.249 , stock_code:HK.03939 stock_name:萬國國際礦業 cur_price:2.22 current_ratio(annual):17.323 , stock_code:HK.01055 stock_name:中國南方航空股份 cur_price:5.17 current_ratio(annual):17.529 , stock_code:HK.02638 stock_name:港燈-SS cur_price:7.68 current_ratio(annual):21.255 , stock_code:HK.00670 stock_name:中國東方航空股份 cur_price:3.53 current_ratio(annual):25.194 , stock_code:HK.01952 stock_name:雲頂新耀-B cur_price:69.5 current_ratio(annual):26.029 , stock_code:HK.00089 stock_name:大生地產 cur_price:4.22 current_ratio(annual):26.914 , stock_code:HK.00728 stock_name:中國電信 cur_price:2.81 current_ratio(annual):27.651 , stock_code:HK.01372 stock_name:比速科技 cur_price:5.1 current_ratio(annual):28.303 , stock_code:HK.00753 stock_name:中國國航 cur_price:6.38 current_ratio(annual):31.828 , stock_code:HK.01997 stock_name:九龍倉置業 cur_price:43.75 current_ratio(annual):33.239 , stock_code:HK.02158 stock_name:醫渡科技 cur_price:39.0 current_ratio(annual):34.046 , stock_code:HK.02588 stock_name:中銀航空租賃 cur_price:77.0 current_ratio(annual):34.531 , stock_code:HK.01330 stock_name:綠色動力環保 cur_price:3.36 current_ratio(annual):35.028 , stock_code:HK.01525 stock_name:建橋教育 cur_price:6.28 current_ratio(annual):36.989 , stock_code:HK.09908 stock_name:嘉興燃氣 cur_price:10.02 current_ratio(annual):37.848 , stock_code:HK.06078 stock_name:海吉亞醫療 cur_price:49.8 current_ratio(annual):39.0 , stock_code:HK.01071 stock_name:華電國際電力股份 cur_price:2.16 current_ratio(annual):39.507 , stock_code:HK.00357 stock_name:美蘭空港 cur_price:34.15 current_ratio(annual):39.514 , stock_code:HK.00762 stock_name:中國聯通 cur_price:5.15 current_ratio(annual):40.74 , stock_code:HK.01787 stock_name:山東黃金 cur_price:15.56 current_ratio(annual):41.604 , stock_code:HK.00902 stock_name:華能國際電力股份 cur_price:2.66 current_ratio(annual):42.919 , stock_code:HK.00934 stock_name:中石化冠德 cur_price:2.96 current_ratio(annual):43.361 , stock_code:HK.01117 stock_name:現代牧業 cur_price:2.3 current_ratio(annual):45.037 , stock_code:HK.00177 stock_name:江蘇寧滬高速公路 cur_price:8.78 current_ratio(annual):45.93 , stock_code:HK.01379 stock_name:温嶺工量刃具 cur_price:5.71 current_ratio(annual):46.774 , stock_code:HK.01876 stock_name:百威亞太 cur_price:22.5 current_ratio(annual):46.917 , stock_code:HK.01907 stock_name:中國旭陽集團 cur_price:4.38 current_ratio(annual):47.129 , stock_code:HK.02160 stock_name:心通醫療-B cur_price:15.54 current_ratio(annual):47.384 , stock_code:HK.00293 stock_name:國泰航空 cur_price:7.1 current_ratio(annual):47.983 , stock_code:HK.00694 stock_name:北京首都機場股份 cur_price:6.34 current_ratio(annual):47.985 , stock_code:HK.09922 stock_name:九毛九 cur_price:26.65 current_ratio(annual):48.278 , stock_code:HK.01083 stock_name:港華燃氣 cur_price:3.39 current_ratio(annual):49.2 , stock_code:HK.00291 stock_name:華潤啤酒 cur_price:58.0 current_ratio(annual):49.229 , stock_code:HK.00306 stock_name:冠忠巴士集團 cur_price:2.29 current_ratio(annual):49.769 ]
HK.08103
HMVOD視頻
2.69
2.69
4.413
...
HK.00306
冠忠巴士集團
2.29
2.29
49.769
2
3
4
5
6
7
8
9
10
11
12
# Qot_StockFilter.proto
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性字段名“field”與C#protocol buf保留的函數名衝突,moomoo API將從3.18版本開始將該字段重命名為“fieldName”。請注意修改相應介面中使用的字段名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
協議 ID
3215
uint StockFilter(QotStockFilter.Request req);
virtual void OnReply_StockFilter(MMAPI_Conn client, uint nSerialNo, QotStockFilter.Response rsp);
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性字段名“field”與C#protocol buf保留的函數名衝突,moomoo API將從3.18版本開始將該字段重命名為“fieldName”。請注意修改相應介面中使用的字段名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
- Example
public class Program : MMSPI_Qot, MMSPI_Conn {
MMAPI_Qot qot = new MMAPI_Qot();
public Program() {
qot.SetClientInfo("csharp", 1); //設定用戶端資訊
qot.SetConnCallback(this); //設定連線回呼
qot.SetQotCallback(this); //設定交易回呼
}
public void Start() {
qot.InitConnect("127.0.0.1", (ushort)11111, false);
}
public void OnInitConnect(MMAPI_Conn client, long errCode, String desc)
{
Console.Write("Qot onInitConnect: ret={0} desc={1} connID={2}\n", errCode, desc, client.GetConnectID());
if (errCode != 0)
return;
QotStockFilter.BaseFilter filter = QotStockFilter.BaseFilter.CreateBuilder()
.SetFieldName(QotStockFilter.StockField.StockField_CurPrice)
.SetFilterMax(100)
.SetFilterMax(200)
.Build();
QotStockFilter.C2S c2s = QotStockFilter.C2S.CreateBuilder()
.SetBegin(0)
.SetNum(10)
.SetMarket((int)QotCommon.QotMarket.QotMarket_HK_Security)
.AddBaseFilterList(filter)
.Build();
QotStockFilter.Request req = QotStockFilter.Request.CreateBuilder().SetC2S(c2s).Build();
uint seqNo = qot.StockFilter(req);
Console.Write("Send QotStockFilter: {0}\n", seqNo);
}
public void OnDisconnect(MMAPI_Conn client, long errCode) {
Console.Write("Qot onDisConnect: {0}\n", errCode);
}
public void OnReply_StockFilter(MMAPI_Conn client, uint nSerialNo, QotStockFilter.Response rsp)
{
Console.Write("Reply: QotStockFilter: {0}\n", nSerialNo, rsp.ToString());
Console.Write("code: {0}, name: {1} \n", rsp.S2C.DataListList[0].Security.Code,
rsp.S2C.DataListList[0].Name);
}
public static void Main(String[] args) {
MMAPI.Init();
Program qot = new Program();
qot.Start();
while (true)
Thread.Sleep(1000 * 600);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- Output
Qot onInitConnect: ret=0 desc= connID=6825721743616225277
Send QotStockFilter: 3
Reply: QotStockFilter: 3
code: 00376, name: 雲鋒金融
2
3
4
int stockFilter(QotStockFilter.Request req);
void onReply_StockFilter(MMAPI_Conn client, int nSerialNo, QotStockFilter.Response rsp);
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性字段名“field”與C#protocol buf保留的函數名衝突,moomoo API將從3.18版本開始將該字段重命名為“fieldName”。請注意修改相應介面中使用的字段名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
- Example
public class QotDemo implements MMSPI_Qot, MMSPI_Conn {
MMAPI_Conn_Qot qot = new MMAPI_Conn_Qot();
public QotDemo() {
qot.setClientInfo("javaclient", 1); //設定用戶端資訊
qot.setConnSpi(this); //設定連線回呼
qot.setQotSpi(this); //設定交易回呼
}
public void start() {
qot.initConnect("127.0.0.1", (short)11111, false);
}
@Override
public void onInitConnect(MMAPI_Conn client, long errCode, String desc)
{
System.out.printf("Qot onInitConnect: ret=%b desc=%s connID=%d\n", errCode, desc, client.getConnectID());
if (errCode != 0)
return;
QotStockFilter.BaseFilter filter = QotStockFilter.BaseFilter.newBuilder()
.setFieldName(QotStockFilter.StockField.StockField_CurPrice_VALUE)
.setFilterMax(100)
.setFilterMax(200)
.build();
QotStockFilter.C2S c2s = QotStockFilter.C2S.newBuilder()
.setBegin(0)
.setNum(10)
.setMarket(QotCommon.QotMarket.QotMarket_HK_Security_VALUE)
.addBaseFilterList(filter)
.build();
QotStockFilter.Request req = QotStockFilter.Request.newBuilder().setC2S(c2s).build();
int seqNo = qot.stockFilter(req);
System.out.printf("Send QotStockFilter: %d\n", seqNo);
}
@Override
public void onDisconnect(MMAPI_Conn client, long errCode) {
System.out.printf("Qot onDisConnect: %d\n", errCode);
}
@Override
public void onReply_StockFilter(MMAPI_Conn client, int nSerialNo, QotStockFilter.Response rsp) {
if (rsp.getRetType() != 0) {
System.out.printf("QotStockFilter failed: %s\n", rsp.getRetMsg());
}
else {
try {
String json = JsonFormat.printer().print(rsp);
System.out.printf("Receive QotStockFilter: %s\n", json);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
MMAPI.init();
QotDemo qot = new QotDemo();
qot.start();
while (true) {
try {
Thread.sleep(1000 * 600);
} catch (InterruptedException exc) {
}
}
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
- Output
Send QotStockFilter: 2
Receive QotStockFilter: {
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"lastPage": false,
"allCount": 2431,
"dataList": [{
"security": {
"market": 1,
"code": "08560"
},
"name": "世大控股"
}, ... {
"security": {
"market": 1,
"code": "02171"
},
"name": "科濟藥業-B"
}]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
moomoo::u32_t StockFilter(const Qot_StockFilter::Request &stReq);
virtual void OnReply_StockFilter(moomoo::u32_t nSerialNo, const Qot_StockFilter::Response &stRsp) = 0;
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性字段名“field”與C#protocol buf保留的函數名衝突,moomoo API將從3.18版本開始將該字段重命名為“fieldName”。請注意修改相應介面中使用的字段名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
- Example
class Program : public MMSPI_Qot, public MMSPI_Trd, public MMSPI_Conn
{
public:
Program() {
m_pQotApi = MMAPI::CreateQotApi();
m_pQotApi->RegisterQotSpi(this);
m_pQotApi->RegisterConnSpi(this);
}
~Program() {
if (m_pQotApi != nullptr)
{
m_pQotApi->UnregisterQotSpi();
m_pQotApi->UnregisterConnSpi();
MMAPI::ReleaseQotApi(m_pQotApi);
m_pQotApi = nullptr;
}
}
void Start() {
m_pQotApi->InitConnect("127.0.0.1", 11111, false);
}
virtual void OnInitConnect(MMAPI_Conn* pConn, moomoo::i64_t nErrCode, const char* strDesc) {
cout << "connect" << endl;
// 組包
Qot_StockFilter::Request req;
Qot_StockFilter::C2S *c2s = req.mutable_c2s();
c2s->set_begin(0);
c2s->set_num(50);
c2s->set_market(1);
m_StockFilterSerialNo = m_pQotApi->StockFilter(req);
cout << "Request StockFilter SerialNo: " << m_StockFilterSerialNo << endl;
}
virtual void OnReply_StockFilter(moomoo::u32_t nSerialNo, const Qot_StockFilter::Response &stRsp){
if(nSerialNo == m_StockFilterSerialNo)
{
cout << "OnReply_StockFilter SerialNo: " << nSerialNo << endl;
// 解析內部結構列印出來
// ProtoBufToBodyData和UTF8ToLocal函數的定義參見Sample中的tool.h檔案
string resp_str;
ProtoBufToBodyData(stRsp, resp_str);
cout << UTF8ToLocal(resp_str) << endl;
}
}
protected:
MMAPI_Qot *m_pQotApi;
moomoo::u32_t m_StockFilterSerialNo;
};
int32_t main(int32_t argc, char** argv)
{
MMAPI::Init();
{
Program program;
program.Start();
getchar();
}
protobuf::ShutdownProtobufLibrary();
MMAPI::UnInit();
return 0;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
- Output
connect
Request StockFilter SerialNo: 4
OnReply_StockFilter SerialNo: 4
{
"retType": 0,
"retMsg": "",
"errCode": 0,
"s2c": {
"lastPage": false,
"allCount": 2426,
"dataList": [
{
"security": {
"market": 1,
"code": "02930"
},
"name": "絲路物流控股"
},
...
{
"security": {
"market": 1,
"code": "01440"
},
"name": "DEYUN HOLDING"
}
]
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
StockFilter(req);
介紹
條件選股
參數
// 使用以下6種結構(BaseFilter、AcumulateFilter、FinancialFilter、BaseData、AcumulateData、FinancialData)的用戶請注意,由於屬性字段名“field”與C#protocol buf保留的函數名衝突,moomoo API將從3.18版本開始將該字段重命名為“fieldName”。請注意修改相應介面中使用的字段名稱。
// 簡單屬性篩選
message BaseFilter
{
required int32 fieldName = 1; // StockField 簡單屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
}
// 累積屬性篩選
message AccumulateFilter
{
required int32 fieldName = 1; // AccumulateField 累積屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 days = 6; // 近幾日,累積時間
}
// 財務屬性篩選
message FinancialFilter
{
required int32 fieldName = 1; // FinancialField 財務屬性
optional double filterMin = 2; // 區間下限(閉區間),不傳代表下限為 -∞
optional double filterMax = 3; // 區間上限(閉區間),不傳代表上限為 +∞
optional bool isNoFilter = 4; // 該欄位是否不需要篩選,True:不篩選,False:篩選。不傳預設不篩選
optional int32 sortDir = 5; // SortDir 排序方向,預設不排序。
required int32 quarter = 6; // FinancialQuarter 財報累積時間
}
// 形態技術指標屬性篩選
message PatternFilter
{
required int32 fieldName = 1; // PatternField 形態技術指標屬性
required int32 klType = 2; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 3; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
optional int32 consecutivePeriod = 4; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
// 自定義技術指標屬性篩選
message CustomIndicatorFilter
{
required int32 firstFieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required int32 secondFieldName = 2; // CustomIndicatorField 自定義技術指標屬性
required int32 relativePosition = 3; // RelativePosition 相對位置
optional double fieldValue = 4; // 自定義數值
required int32 klType = 5; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
optional bool isNoFilter = 6; // 該欄位是否不需要篩選,True代表不篩選,False代表篩選。不傳預設為不篩選
repeated int32 firstFieldParaList = 7; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
repeated int32 secondFieldParaList = 8; // 自定義指標參數。根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
optional int32 consecutivePeriod = 9; // 篩選連續週期(consecutivePeriod)都符合條件的數據,填寫範圍為[1,12]
}
message C2S
{
required int32 begin = 1; // 數據起始點
required int32 num = 2; // 請求數據個數,最大200
required int32 market= 3; // Qot_Common::QotMarket 股票市場,支援滬股和深股,且滬股和深股不做區分都代表 A 股市場。
// 以下為篩選條件,可選欄位,不填表示不過濾
optional Qot_Common.Security plate = 4; // 板塊
repeated BaseFilter baseFilterList = 5; // 簡單指標過濾器
repeated AccumulateFilter accumulateFilterList = 6; // 累積指標過濾器 累積屬性的同一篩選條件數量上限 10 個
repeated FinancialFilter financialFilterList = 7; // 財務指標過濾器
repeated PatternFilter patternFilterList = 8; // 形態技術指標過濾器
repeated CustomIndicatorFilter customIndicatorFilterList = 9; // 自定義技術指標過濾器
}
message Request
{
required C2S c2s = 1;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
- 股票結構參見 Security
- 市場類型參見 QotMarket
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- 形態技術指標屬性篩選條件參見 PatternField
- 財報時間週期參見 FinancialQuarter
- 排序方向參見 SortDir
- 相對位置參見 RelativePosition
- K線類型參見 KLType
- 返回
// 簡單屬性數據
message BaseData
{
required int32 fieldName = 1; // StockField 簡單屬性
required double value = 2;
}
// 累積屬性數據
message AccumulateData
{
required int32 fieldName = 1; // AccumulateField 累積屬性
required double value = 2;
required int32 days = 3; // 近幾日,累積時間
}
// 財務屬性數據
message FinancialData
{
required int32 fieldName = 1; // FinancialField 財務屬性
required double value = 2;
required int32 quarter = 3; // FinancialQuarter 財報累積時間
}
// 自定義技術指標屬性數據
message CustomIndicatorData
{
required int32 fieldName = 1; // CustomIndicatorField 自定義技術指標屬性
required double value = 2;
required int32 klType = 3; // Qot_Common.KLType,K線類型,僅支援K_60M,K_DAY,K_WEEK,K_MON 四種時間週期
repeated int32 fieldParaList = 4; // 自定義指標參數 根據指標類型進行傳參:1. MA:[平均移動週期] 2.EMA:[指數移動平均週期] 3.RSI:[RSI 指標週期] 4.MACD:[快速平均線值, 慢速平均線值, DIF值] 5.BOLL:[均線週期, 偏移值] 6.KDJ:[RSV 週期, K 值計算週期, D 值計算週期]
}
// 返回的股票數據
message StockData
{
required Qot_Common.Security security = 1; // 股票
required string name = 2; // 股票名稱
repeated BaseData baseDataList = 3; // 篩選後的簡單指標屬性數據
repeated AccumulateData accumulateDataList = 4; // 篩選後的累積指標屬性數據
repeated FinancialData financialDataList = 5; // 篩選後的財務指標屬性數據
repeated CustomIndicatorData customIndicatorDataList = 6; // 自定義技術指標屬性數據
// CustomIndicatorFilter 中的 firstFieldName 和 secondFieldName 的數值會在這個列表中分開返回
}
message S2C
{
required bool lastPage = 1; // 是否最後一頁了,false:非最後一頁,還有窩輪記錄未返回; true:已是最後一頁
required int32 allCount = 2; // 該條件請求所有數據的個數
repeated StockData dataList = 3; // 返回的股票數據列表
}
message Response
{
required int32 retType = 1 [default = -400]; // RetType,返回結果
optional string retMsg = 2;
optional int32 errCode = 3;
optional S2C s2c = 4;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
- 股票結構參見 Security
- 簡單屬性篩選條件參見 StockField
- 累積屬性篩選條件參見 AccumulateField
- 財務屬性篩選條件參見 FinancialField
- 財報時間週期參見 FinancialQuarter
- 自定義技術指標屬性篩選條件參見 CustomIndicatorField
- K線類型參見 KLType
- 介面呼叫結果,結構參見 RetType
- Example
import mmWebsocket from "moomoo-api";
import { mmCmdID } from "moomoo-api";
import { Common, Qot_Common } from "moomoo-api/proto";
import beautify from "js-beautify";
function QotStockFilter(){
const { RetType } = Common
const { QotMarket } = Qot_Common
let [addr, port, enable_ssl, key] = ["127.0.0.1", 33333, false, '7522027ccf5a06b1'];
let websocket = new mmWebsocket();
websocket.onlogin = (ret, msg)=>{
if (ret) { // 登入成功
const req = {
c2s: {
begin: 0,
num: 2,
market: QotMarket.QotMarket_HK_Security,
},
};
websocket.StockFilter(req)
.then((res) => {
let { errCode, retMsg, retType,s2c } = res
console.log("StockFilter: errCode %d, retMsg %s, retType %d", errCode, retMsg, retType);
if(retType == RetType.RetType_Succeed){
let data = beautify(JSON.stringify(s2c), {
indent_size: 2,
space_in_empty_paren: true,
});
console.log(data);
}
})
.catch((error) => {
console.log("error:", error);
});
} else {
console.log("error", msg);
}
};
websocket.start(addr, port, enable_ssl, key);
//關閉行情連線,連線不再使用之後,要關閉,否則佔用不必要資源
//同時OpenD也限制了最多128條連線
//也可以一個頁面或者一個專案維護一條連線,這裡範例請求一次建立一條連線
setTimeout(()=>{
websocket.stop();
console.log("stop");
}, 5000); // 5秒後斷開
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
- Output
StockFilter: errCode 0, retMsg , retType 0
{
"lastPage": false,
"allCount": 2436,
"dataList": [{
"security": {
"market": 1,
"code": "08579"
},
"name": "萬亞企業控股"
}, {
"security": {
"market": 1,
"code": "09869"
},
"name": "海倫司"
}]
}
stop
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
提示
- 利用獲取子板塊列表函數 獲取子板塊代碼,條件選股支援的板塊分別為
- 港股的行業板塊和概念板塊。
- 美股的行業板塊
- 滬深的行業板塊,概念板塊和地域板塊
- 支援的板塊指數代碼
代碼 説明 HK.Motherboard 港股主板 HK.GEM 港股創業板 HK.BK1911 H 股主板 HK.BK1912 H 股創業板 US.NYSE 紐交所 US.AMEX 美交所 US.NASDAQ 納斯達克 SH.3000000 上海主板 SZ.3000001 深證主板 SZ.3000004 深證創業板
介面限制
- 每 30 秒內最多請求 10 次條件選股介面
- 每頁返回的篩選結果最多 200 個
- 建議篩選條件不超過 250 個,否則可能會出現“業務處理超時沒返回”
- 累積屬性的同一篩選條件數量上限 10 個
- 如果使用“最新價”等動態數據作為排序字段,在多頁獲取的間隙,數據的排序有可能發生變化
- 非同類指標不支援比較,僅限於同類指標之間建立比較關係,跨不同類型的指標比較會報錯。例如:MA5 和 MA10 可以建立關係。MA5和EMA10不能建立關係。
- 自定義指標屬性的同一類篩選條件超出數量上限10個
- 簡單屬性,財務屬性,形態屬性不支援對同一字段重複指定篩選條件
- 條件選股暫不支援美股盤前盤後、夜盤,篩選結果均按照盤中數據返回