Skip to content

Commit cc8f70c

Browse files
committed
Merge branch 'dev' of git.tigerbrokers.net:server/openapi/openapi-python-sdk into dev
2 parents 5c8f36a + b8a0ded commit cc8f70c

9 files changed

Lines changed: 112 additions & 55 deletions

File tree

tigeropen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
55
@author: gaoan
66
"""
7-
__VERSION__ = '2.3.7'
7+
__VERSION__ = '2.3.8'

tigeropen/common/consts/filter_fields.py

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,32 @@ class StockField(FilterField):
7272
EarningDate = 23, "earningDate"
7373
# 市盈率* TTM(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
7474
PeTTM = 24, "peRate"
75-
# 市净率*(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
76-
PbRate = 25, "pbRate"
7775
# 股息 hermes $
78-
DividePrice = 26, "dividePrice"
76+
DividePrice = 26, "dividePriceVal"
7977
# 股息收益率 选股服务自身计算
80-
DivideRate = 27, "divideRate"
78+
DivideRate = 27, "divideRateVal"
8179
# 股票交易市场
8280
Exchange = 29, "exchange"
8381
# 换手率*(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
8482
TurnoverRate = 30, "turnoverRate"
8583
# 上市时间
8684
ListingDate = 31, "listingDate"
87-
# 市盈率LYR* TTM(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
88-
LyrPeRate = 32, "LyrPeRate"
8985
# 总股本*
9086
Share = 33, "shares"
9187
# 上市价格*
9288
ListingPrice = 34, "listingPrice"
93-
# 交易币种*
94-
TradeCurrency = 35, "tradeCurrency"
9589
# 最新价-发行价*
9690
DiffBetweenLastPriceAndListPrice = 36, "DiffBetweenLastPriceAndListPrice"
9791
# 每股收益 lyr=Last Year Ratio 静态市盈率
9892
lyr_Eps = 37, "lyrEps"
9993
# 未平仓做空量
100-
Open_Short_Interest = 38, "OpenShortInterest"
94+
Open_Short_Interest = 38, "OpenShortInterestVal"
10195
# 未平仓做空比例 = 未平仓做空量/总股本
10296
Open_Short_Interest_Ratio = 39, "OpenShortInterestRatio"
10397
# 产权比率 = Liability/Equity 总负债/股东
104-
Equity_Ratio = 40, "EquityRatio"
98+
Equity_Ratio = 40, "totalDebtToEquity"
10599
# 权益乘数 = Asset/Equity
106-
Equity_Multiplier = 41, "EquityMultiplier"
100+
Equity_Multiplier = 41, "totalLiabilitiesToTotalAssets"
107101
# 最新股东数
108102
Holder_Nums = 42, "holderNums"
109103
# 最新股东户数增长率
@@ -128,21 +122,30 @@ class StockField(FilterField):
128122
Top20_Composition_Rate = 52, "Top20CompoRate"
129123
# 溢价率(折扣率) - ETF
130124
DiscountPremium = 53, "discountPremium"
131-
# 股息率 - ETF
132-
dividend_Rate = 54, "dividendRate"
133125
# 资产规模-净值 - ETF
134126
Net_Worth_Aum = 55, "aum"
135127
# 资产规模-现价 - ETF
136128
assetSize = 56, "assetSize"
137129
# 振幅
138130
Amplitude = 57, "Amplitude"
139-
131+
# 盘前涨跌幅
132+
Pre_ChangeRate = 58, "preChangeRate"
133+
# 盘中涨跌幅 */
134+
current_ChangeRate = 59, "curChangeRate"
135+
# 盘后涨跌幅 */
136+
Post_ChangeRate = 60, "postChangeRate"
137+
# 成分变动 - etf */
138+
ETF_LastHoldingChangeDay = 61, "LastHoldingChangeDay"
139+
# 持仓数量 - etf */
140+
ETF_HoldingCount = 62, "etfHoldingCount"
141+
# 净利润 不带周期 */
142+
Net_Income = 63, "netIncomeVal"
140143

141144
class AccumulateField(FilterField):
142145
# 涨跌幅*(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
143146
ChangeRate = 1, "changeRate"
144147
# 涨跌额*(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
145-
ChangeValue = 2, "change"
148+
ChangeValue = 2, "changeVal"
146149
# 总负债增长率
147150
TotalLiabilities_Ratio_Annual = 3, "totalLiabilitiesRatio"
148151
# 净资产增长率
@@ -167,10 +170,6 @@ class AccumulateField(FilterField):
167170
ROE = 13, "ROE"
168171
# ROA = 净资产收益率
169172
ROA = 14, "ROA"
170-
# 股息 hermes $
171-
DividePrice = 15, "dividePrice"
172-
# 股息收益率 选股服务自身计算
173-
DivideRate = 16, "divideRate"
174173
# 毛利率
175174
GrossProfitRate = 17, "grossMargin"
176175
# 净利率*
@@ -181,8 +180,8 @@ class AccumulateField(FilterField):
181180
CurrentRatio = 20, "currentRatio"
182181
# 速动比率
183182
QuickRatio = 21, "quickRatio"
184-
# 经营现金流
185-
CashFromOps = 22, "cash4Ops"
183+
# 经营现金流比率
184+
CashFromOpsRatio = 22, "cash4OpsRatio"
186185
# 投资现金流
187186
CashFromInvesting = 23, "cash4Invest"
188187
# 筹资现金流
@@ -193,31 +192,30 @@ class AccumulateField(FilterField):
193192
CashFromOps_yearOnYear_Ratio = 26, "cash4OpsYearOnYearRatio"
194193
# 净资产收益率ROE同比增长率 (T期ROE-T-1期ROE)/T-1期ROE *100%
195194
ROE_yearOnYear_Ratio = 27, "netIncomeYearOnYearRatio"
196-
195+
# 营业利润占比
196+
Operating_Profits_Ratio = 28, "OperatingProfitsRatio"
197+
# 经营现金流
198+
CashFromOpsVal = 29, "cash4OpsVal"
197199

198200
class FinancialField(FilterField):
199201
# 毛利率(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
200-
GrossProfitRate = 1, "grossMargin"
202+
GrossProfitRate = 1, "grossMarginVal"
201203
# 净利率(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
202-
NetProfitRate = 2, "netIncomeMargin"
204+
NetProfitRate = 2, "netIncomeMarginVal"
203205
# 扣非净利润率(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
204206
EarningsFromContOpsMargin = 3, "earningsFromContOpsMargin"
205-
# 总负债/股东权益 (单位:元)
206-
TotalDebtToEquity = 4, "totalDebtToEquity"
207207
# 长期负债/股东权益
208208
LongTermDebtToEquity = 5, "ltDebtToEquity"
209209
# EBIT/利息支出
210210
EbitToInterestExp = 6, "ebitToInterestExp"
211-
# 总负债/总资产
212-
TotalLiabilitiesToTotalAssets = 7, "totalLiabilitiesToTotalAssets"
213211
# 总资产周转率(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
214212
TotalAssetTurnover = 8, "totalAssetTurnover"
215213
# 应收帐款周转率
216214
AccountsReceivableTurnover = 9, "accountsReceivableTurnover"
217215
# 存货周转率(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
218216
InventoryTurnover = 10, "inventoryTurnover"
219217
# 流动比率(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
220-
CurrentRatio = 11, "currentRatio"
218+
CurrentRatio = 11, "currentRatioVal"
221219
# 速动比率(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
222220
QuickRatio = 12, "quickRatio"
223221
# 资产回报率 总资产收益率 *$ TTM(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
@@ -238,7 +236,7 @@ class FinancialField(FilterField):
238236
TotalAssets1YrGrowth = 20, "totalAssets1YrGrowth"
239237
# 有形资产一年增长率
240238
TangibleBookValue1YrGrowth = 21, "tangibleBookValue1YrGrowth"
241-
# 经营现金流一年增长率
239+
# 经营现金流一年增长率 = 经营现金流同比增长率
242240
CashFromOperations1YrGrowth = 22, "cashFromOperations1YrGrowth"
243241
# 资本开支一年增长率
244242
CapitalExpenditures1YrGrowth = 23, "capitalExpenditures1YrGrowth"
@@ -269,19 +267,19 @@ class FinancialField(FilterField):
269267
# 筹资现金流
270268
CashFromFinancing = 36, "cashFromFinancing"
271269
# 净利润2年复合增长率
272-
NormalizedNetIncome2YrCagr = 37, "normalizedNetIncome2YrCagr"
270+
NormalizedNetIncome2YrCagr = 37, "netIncome2YrCagr"
273271
# 营收2年复合增长率
274272
TotalRevenues2YrCagr = 38, "totalRevenues2YrCagr"
275273
# 净利润5年复合增长率
276274
NetIncome5YrCagr = 39, "netIncome5YrCagr"
277275
# 营收5年复合增长率
278276
TotalRevenues5YrCagr = 40, "totalRevenues5YrCagr"
279277
# 总资产
280-
TotalAssets = 41, "totalAssets"
278+
TotalAssets = 41, "totalAssetsVal"
281279
# 固定资产周转率(精确到小数点后 3 位,超出部分会被舍弃)例如填写 [0.005,0.01] 值区间
282280
FixedAssetTurnover = 42, "fixedAssetTurnover"
283281
# 营业利润
284-
OperatingIncome = 43, "operatingIncome"
282+
OperatingIncome = 43, "operatingIncomeVal"
285283
# 营业总收入
286284
TotalRevenue = 44, "totalRevenue"
287285
# 市盈率LYR PE =price-to-earnings ratio
@@ -292,10 +290,6 @@ class FinancialField(FilterField):
292290
LYR_PS = 47, "LyrPS"
293291
# 市销率TTM PS =Price-to-sales Ratio
294292
TTM_PS = 48, "ttmPS"
295-
# 市净率LYR PB =price/book value ratio
296-
LYR_PB = 47, "LyrPB"
297-
# 市净率TTM PB =price/book value ratio
298-
TTM_PB = 48, "ttmPB"
299293
# 当日主力净流入额
300294
LargeInflowAmountToday = 49, "largeInflowAmountToday"
301295
# 当日主力增仓占比
@@ -336,7 +330,10 @@ class FinancialField(FilterField):
336330
Lst2YearAnnualVolatility = 67, "lst2YearAnnualVolatility"
337331
# 近5年年化波动率 ETF
338332
Lst5YearAnnualVolatility = 68, "lst5YearAnnualVolatility"
339-
333+
# 市净率LYR PB =price/book value ratio
334+
LYR_PB = 69, "LyrPB"
335+
# 市净率TTM PB =price/book value ratio
336+
TTM_PB = 70, "ttmPB"
340337

341338
class MultiTagField(FilterField):
342339
# 所属行业
@@ -374,7 +371,14 @@ class MultiTagField(FilterField):
374371
Week52HighFlag = 17, "week52HighFlag"
375372
# 52周最低 0 否 1是
376373
Week52LowFlag = 18, "week52LowFlag"
377-
374+
# 交易币种, 需要具体币种
375+
TradeCurrency = 19, "tradeCurrency"
376+
# ETF类型,需要具体类型
377+
ETF_TYPE = 20, "etfType"
378+
# 股票市场,支持多个市场
379+
Market_Name = 21, "marketName"
380+
# 一级行业级别, 需要传递具体sectorId
381+
One_Sectors_Level = 22, "oneSectorsLevel"
378382

379383
class FieldBelongType(Enum):
380384
"""选股排序字段对应的filter类别

tigeropen/common/consts/service_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
QUOTE_DEPTH = "quote_depth" # level2 深度行情
6262
GRAB_QUOTE_PERMISSION = "grab_quote_permission" # 抢占行情
6363
MARKET_SCANNER = "market_scanner" # 选股器
64+
MARKET_SCANNER_TAGS = "market_scanner_tags"
6465
GET_QUOTE_PERMISSION = "get_quote_permission"
6566
TRADING_CALENDAR = "trading_calendar"
6667
STOCK_BROKER = "stock_broker" # 港股股票实时经纪队列

tigeropen/push/pb/util.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class ProtoMessageUtil:
2222
increment_count = 0
2323

2424
@classmethod
25-
@property
2625
def increment(cls):
2726
cls.increment_count += 1
2827
return cls.increment_count
@@ -51,7 +50,7 @@ def build_connect_message(cls, tiger_id, sign, version='3', send_interval=0, rec
5150
raise ValueError("sendInterval < 0 or receiveInterval < 0")
5251
request = Request_pb2.Request()
5352
request.command = SocketCommon_pb2.SocketCommon.CONNECT
54-
request.id = cls.increment
53+
request.id = cls.increment()
5554

5655
con = Request_pb2.Request.Connect()
5756
con.acceptVersion = version
@@ -67,21 +66,21 @@ def build_connect_message(cls, tiger_id, sign, version='3', send_interval=0, rec
6766
def build_disconnect_message(cls):
6867
request = Request_pb2.Request()
6968
request.command = SocketCommon_pb2.SocketCommon.DISCONNECT
70-
request.id = cls.increment
69+
request.id = cls.increment()
7170
return request
7271

7372
@classmethod
7473
def build_send_message(cls):
7574
request = Request_pb2.Request()
7675
request.command = SocketCommon_pb2.SocketCommon.SEND
77-
request.id = cls.increment
76+
request.id = cls.increment()
7877
return request
7978

8079
@classmethod
8180
def build_heart_beat_message(cls):
8281
request = Request_pb2.Request()
8382
request.command = SocketCommon_pb2.SocketCommon.HEARTBEAT
84-
request.id = cls.increment
83+
request.id = cls.increment()
8584
return request
8685

8786
@classmethod
@@ -96,7 +95,7 @@ def build_unsubscribe_trade_message(cls, data_type, account):
9695
def build_subscribe_query_message(cls):
9796
request = Request_pb2.Request()
9897
request.command = SocketCommon_pb2.SocketCommon.SEND
99-
request.id = cls.increment
98+
request.id = cls.increment()
10099
return request
101100

102101
@classmethod
@@ -135,7 +134,7 @@ def build_unsubscribe_market_message(cls, market):
135134
def build_quote_message(cls, data_type, symbols, command):
136135
request = Request_pb2.Request()
137136
request.command = command
138-
request.id = cls.increment
137+
request.id = cls.increment()
139138

140139
sub = Request_pb2.Request.Subscribe()
141140
sub.dataType = data_type
@@ -148,7 +147,7 @@ def build_quote_message(cls, data_type, symbols, command):
148147
def build_market_quote_message(cls, market, command):
149148
request = Request_pb2.Request()
150149
request.command = command
151-
request.id = cls.increment
150+
request.id = cls.increment()
152151

153152
sub = Request_pb2.Request.Subscribe()
154153
sub.dataType = SocketCommon_pb2.SocketCommon.Quote
@@ -160,7 +159,7 @@ def build_market_quote_message(cls, market, command):
160159
def build_trade_message(cls, data_type, account, command):
161160
request = Request_pb2.Request()
162161
request.command = command
163-
request.id = cls.increment
162+
request.id = cls.increment()
164163

165164
sub = Request_pb2.Request.Subscribe()
166165
sub.dataType = data_type

tigeropen/quote/domain/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def to_dict(self):
7979
'field_name': self.field.index,
8080
'field_type': self.field.field_type_request_name,
8181
'sort_dir': self.sort_dir.value,
82-
'period': self.period.value
82+
'period': self.period.value if self.period else None
8383
}
8484

8585

tigeropen/quote/quote_client.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from tigeropen.common.consts.filter_fields import FieldBelongType
1717
from tigeropen.common.consts.service_types import GRAB_QUOTE_PERMISSION, QUOTE_DELAY, GET_QUOTE_PERMISSION, \
1818
HISTORY_TIMELINE, FUTURE_CONTRACT_BY_CONTRACT_CODE, TRADING_CALENDAR, FUTURE_CONTRACTS, MARKET_SCANNER, \
19-
STOCK_BROKER, CAPITAL_FLOW, CAPITAL_DISTRIBUTION, WARRANT_REAL_TIME_QUOTE, WARRANT_FILTER
19+
STOCK_BROKER, CAPITAL_FLOW, CAPITAL_DISTRIBUTION, WARRANT_REAL_TIME_QUOTE, WARRANT_FILTER, MARKET_SCANNER_TAGS
2020
from tigeropen.common.consts.service_types import MARKET_STATE, ALL_SYMBOLS, ALL_SYMBOL_NAMES, BRIEF, \
2121
TIMELINE, KLINE, TRADE_TICK, OPTION_EXPIRATION, OPTION_CHAIN, FUTURE_EXCHANGE, OPTION_BRIEF, \
2222
OPTION_KLINE, OPTION_TRADE_TICK, FUTURE_KLINE, FUTURE_TICK, FUTURE_CONTRACT_BY_EXCHANGE_CODE, \
@@ -63,7 +63,7 @@
6363
from tigeropen.quote.response.quote_ticks_response import TradeTickResponse
6464
from tigeropen.quote.response.quote_timeline_history_response import QuoteTimelineHistoryResponse
6565
from tigeropen.quote.response.quote_timeline_response import QuoteTimelineResponse
66-
from tigeropen.quote.response.market_scanner_response import MarketScannerResponse
66+
from tigeropen.quote.response.market_scanner_response import MarketScannerResponse, MarketScannerTagsResponse
6767
from tigeropen.quote.response.stock_briefs_response import StockBriefsResponse
6868
from tigeropen.quote.response.stock_broker_response import StockBrokerResponse
6969
from tigeropen.quote.response.stock_details_response import StockDetailsResponse
@@ -1373,7 +1373,7 @@ def market_scanner(self, market=Market.US, filters=None, sort_field_data=None, p
13731373
"""
13741374
params = MarketScannerParams()
13751375
params.version = OPEN_API_SERVICE_VERSION_V1
1376-
params.market = market.value
1376+
params.market = get_enum_value(market)
13771377
if filters is not None:
13781378
params.base_filter_list = list()
13791379
params.accumulate_filter_list = list()
@@ -1402,6 +1402,23 @@ def market_scanner(self, market=Market.US, filters=None, sort_field_data=None, p
14021402
else:
14031403
raise ApiException(response.code, response.message)
14041404

1405+
def get_market_scanner_tags(self, market=Market.US, tag_fields=None):
1406+
"""
1407+
:param market: tigeropen.common.consts.Market
1408+
:param tag_fields: tigeropen.common.consts.filter_fields.MultiTagField
1409+
"""
1410+
params = MarketScannerParams()
1411+
params.market = get_enum_value(market)
1412+
params.multi_tags_fields = tag_fields
1413+
request = OpenApiRequest(MARKET_SCANNER_TAGS, biz_model=params)
1414+
response_content = self.__fetch_data(request)
1415+
if response_content:
1416+
response = MarketScannerTagsResponse()
1417+
response.parse_response_content(response_content)
1418+
if response.is_success():
1419+
return response.result
1420+
else:
1421+
raise ApiException(response.code, response.message)
14051422
def grab_quote_permission(self):
14061423
"""
14071424
抢占行情权限

tigeropen/quote/request/model.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ def __init__(self):
850850
self._sort_field_data = None
851851
self._page = None
852852
self._page_size = None
853-
853+
self._multi_tags_fields = None
854854
@property
855855
def market(self):
856856
return self._market
@@ -915,6 +915,14 @@ def page_size(self):
915915
def page_size(self, value):
916916
self._page_size = value
917917

918+
@property
919+
def multi_tags_fields(self):
920+
return self._multi_tags_fields
921+
922+
@multi_tags_fields.setter
923+
def multi_tags_fields(self, value):
924+
self._multi_tags_fields = value
925+
918926
def to_openapi_dict(self):
919927
"""
920928
example
@@ -950,6 +958,8 @@ def to_openapi_dict(self):
950958
params['page'] = self.page
951959
if self.page_size is not None:
952960
params['page_size'] = self.page_size
961+
if self.multi_tags_fields:
962+
params['multi_tag_field_list'] = [f.index for f in self.multi_tags_fields]
953963
return params
954964

955965

0 commit comments

Comments
 (0)