Skip to content

Commit 7888e5a

Browse files
committed
Merge branch 'dev' into 'master'
Dev See merge request server/openapi/openapi-python-sdk!144
2 parents a69c200 + 1fe617e commit 7888e5a

File tree

12 files changed

+418
-9
lines changed

12 files changed

+418
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.2.4 (2022-12-09)
2+
### new
3+
- 资金流接口 `QuoteClient.get_capital_flow`
4+
- 资金分布接口 `QuoteClient.get_capital_distribution`
5+
- 港股经纪商接口 `QuoteClient.get_stock_broker`
6+
7+
18
## 2.2.3 (2022-12-07)
29
### new
310
- 选股器 `QuoteClient.market_scanner`

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.2.3'
7+
__VERSION__ = '2.2.4'

tigeropen/common/consts/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ class BarPeriod(Enum):
107107
SIX_HOURS = '6hour' # 6小时
108108

109109

110+
class CapitalPeriod(Enum):
111+
INTRADAY = "intraday"
112+
DAY = "day"
113+
WEEK = "week"
114+
MONTH = "month"
115+
YEAR = "year"
116+
QUARTER = "quarter"
117+
HALFAYEAR = "6month"
118+
119+
110120
class OrderStatus(Enum):
111121
PENDING_NEW = 'PendingNew'
112122
NEW = 'Initial' # 订单初始状态

tigeropen/common/consts/service_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
MARKET_SCANNER = "market_scanner" # 选股器
5656
GET_QUOTE_PERMISSION = "get_quote_permission"
5757
TRADING_CALENDAR = "trading_calendar"
58+
STOCK_BROKER = "stock_broker" # 港股股票实时经纪队列
59+
CAPITAL_DISTRIBUTION = "capital_distribution" # 股票当日资金分布
60+
CAPITAL_FLOW = "capital_flow" # 股票资金流向
5861

5962
# 期权行情
6063
OPTION_EXPIRATION = "option_expiration"

tigeropen/examples/quote_client_demo.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pandas as pd
1111
from tigeropen.common.consts import Market, QuoteRight, FinancialReportPeriodType, Valuation, \
1212
Income, Balance, CashFlow, BalanceSheetRatio, Growth, Leverage, Profitability, IndustryLevel, BarPeriod, \
13-
SortDirection
13+
SortDirection, CapitalPeriod
1414
from tigeropen.common.consts.filter_fields import AccumulateField, StockField, FinancialField, MultiTagField, \
1515
AccumulatePeriod, FinancialPeriod
1616
from tigeropen.quote.domain.filter import OptionFilter, StockFilter, SortFilterData
@@ -187,7 +187,7 @@ def get_fundamental():
187187
print(stock_industry)
188188

189189

190-
def test_market_scanner(self):
190+
def test_market_scanner():
191191
# 股票基本数据过滤(is_no_filter为True时表示不启用该过滤器)
192192
base_filter1 = StockFilter(StockField.FloatShare, filter_min=1e7, filter_max=1e13, is_no_filter=True)
193193
base_filter2 = StockFilter(StockField.MarketValue, filter_min=1e8, filter_max=1e14, is_no_filter=False)
@@ -240,6 +240,49 @@ def test_market_scanner(self):
240240
print(f'scanned symbols:{scanner_result_symbols}')
241241

242242

243+
def test_stock_broker():
244+
"""
245+
246+
:return:
247+
StockBroker({'symbol': '01810',
248+
'bid_broker': [
249+
LevelBroker({'level': 1, 'price': 11.46, 'broker_count': 5,
250+
'broker': [Broker({'id': '5999', 'name': '中国创盈'}), Broker({'id': '4374', 'name': '巴克莱亚洲'}),
251+
Broker({'id': '1438', 'name': 'Susquehanna'}), Broker({'id': '4821', 'name': '华盛'}),
252+
Broker({'id': '6998', 'name': '中国投资'})]})],
253+
'ask_broker': [
254+
LevelBroker({'level': 1, 'price': 11.48, 'broker_count': 5,
255+
'broker': [Broker({'id': '4374', 'name': '巴克莱亚洲'}), Broker({'id': '9056', 'name': '瑞银'}),
256+
Broker({'id': '2027', 'name': '东亚'}), Broker({'id': '4821', 'name': '华盛'}),
257+
Broker({'id': '4374', 'name': '巴克莱亚洲'})]})]})
258+
"""
259+
result = openapi_client.get_stock_broker('01810', limit=5)
260+
print(result)
261+
262+
263+
def test_capital_flow():
264+
"""
265+
time timestamp net_inflow symbol period
266+
0 2022-02-24 1645678800000 -5.889058e+08 AAPL day
267+
1 2022-02-25 1645765200000 -1.229127e+08 AAPL day
268+
2 2022-02-28 1646024400000 1.763644e+08 AAPL day
269+
"""
270+
result = openapi_client.get_capital_flow('AAPL', market=Market.US, period=CapitalPeriod.INTRADAY)
271+
print(result)
272+
273+
274+
def test_capital_distribution():
275+
"""
276+
277+
:return:
278+
CapitalDistribution({'symbol': 'JD', 'net_inflow': -14178801.76, 'in_all': 157357147.5,
279+
'in_big': 25577130.842900004, 'in_mid': 13664116.789999994, 'in_small': 118115899.86410056,
280+
'out_all': 171535949.25, 'out_big': 22642951.677099995, 'out_mid': 12733553.691200001,
281+
'out_small': 136159443.88620025})
282+
"""
283+
result = openapi_client.get_capital_distribution('JD', market=Market.US)
284+
print(result)
285+
243286

244287
if __name__ == '__main__':
245288
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2022/12/9
4+
# @Author : sukai
5+
class CapitalDistribution:
6+
def __init__(self):
7+
self.symbol = None
8+
self.net_inflow = None
9+
self.in_all = None
10+
self.in_big = None
11+
self.in_mid = None
12+
self.in_small = None
13+
self.out_all = None
14+
self.out_big = None
15+
self.out_mid = None
16+
self.out_small = None
17+
18+
def __repr__(self):
19+
return "CapitalDistribution(%s)" % self.__dict__
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2022/12/9
4+
# @Author : sukai
5+
6+
class Broker:
7+
def __init__(self):
8+
self.id = None
9+
self.name = None
10+
11+
def __repr__(self):
12+
return "Broker(%s)" % self.__dict__
13+
14+
15+
class LevelBroker:
16+
def __init__(self):
17+
self.level = None
18+
self.price = None
19+
self.broker_count = None
20+
self.broker = None
21+
22+
def __repr__(self):
23+
return "LevelBroker(%s)" % self.__dict__
24+
25+
26+
class StockBroker:
27+
def __init__(self):
28+
self.symbol = None
29+
self.bid_broker = None
30+
self.ask_broker = None
31+
32+
def __repr__(self):
33+
return "StockBroker(%s)" % self.__dict__

tigeropen/quote/quote_client.py

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from tigeropen.common.consts import THREAD_LOCAL, SecurityType, CorporateActionType, IndustryLevel
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, \
18-
HISTORY_TIMELINE, FUTURE_CONTRACT_BY_CONTRACT_CODE, TRADING_CALENDAR, FUTURE_CONTRACTS, MARKET_SCANNER
18+
HISTORY_TIMELINE, FUTURE_CONTRACT_BY_CONTRACT_CODE, TRADING_CALENDAR, FUTURE_CONTRACTS, MARKET_SCANNER, \
19+
STOCK_BROKER, CAPITAL_FLOW, CAPITAL_DISTRIBUTION
1920
from tigeropen.common.consts.service_types import MARKET_STATE, ALL_SYMBOLS, ALL_SYMBOL_NAMES, BRIEF, \
2021
TIMELINE, KLINE, TRADE_TICK, OPTION_EXPIRATION, OPTION_CHAIN, FUTURE_EXCHANGE, OPTION_BRIEF, \
2122
OPTION_KLINE, OPTION_TRADE_TICK, FUTURE_KLINE, FUTURE_TICK, FUTURE_CONTRACT_BY_EXCHANGE_CODE, \
@@ -38,7 +39,10 @@
3839
from tigeropen.quote.domain.filter import OptionFilter
3940
from tigeropen.quote.request.model import MarketParams, MultipleQuoteParams, MultipleContractParams, \
4041
FutureQuoteParams, FutureExchangeParams, FutureContractParams, FutureTradingTimeParams, SingleContractParams, \
41-
SingleOptionQuoteParams, DepthQuoteParams, OptionChainParams, TradingCalendarParams, MarketScannerParams
42+
SingleOptionQuoteParams, DepthQuoteParams, OptionChainParams, TradingCalendarParams, MarketScannerParams, \
43+
StockBrokerParams, CapitalParams
44+
from tigeropen.quote.response.capital_distribution_response import CapitalDistributionResponse
45+
from tigeropen.quote.response.capital_flow_response import CapitalFlowResponse
4246
from tigeropen.quote.response.future_briefs_response import FutureBriefsResponse
4347
from tigeropen.quote.response.future_contract_response import FutureContractResponse
4448
from tigeropen.quote.response.future_exchange_response import FutureExchangeResponse
@@ -61,6 +65,7 @@
6165
from tigeropen.quote.response.quote_timeline_response import QuoteTimelineResponse
6266
from tigeropen.quote.response.market_scanner_response import MarketScannerResponse
6367
from tigeropen.quote.response.stock_briefs_response import StockBriefsResponse
68+
from tigeropen.quote.response.stock_broker_response import StockBrokerResponse
6469
from tigeropen.quote.response.stock_details_response import StockDetailsResponse
6570
from tigeropen.quote.response.stock_short_interest_response import ShortInterestResponse
6671
from tigeropen.quote.response.stock_trade_meta_response import TradeMetaResponse
@@ -1409,7 +1414,6 @@ def grab_quote_permission(self):
14091414
return response.permissions
14101415
else:
14111416
raise ApiException(response.code, response.message)
1412-
return False
14131417

14141418
def get_quote_permission(self):
14151419
"""
@@ -1429,7 +1433,6 @@ def get_quote_permission(self):
14291433
return response.permissions
14301434
else:
14311435
raise ApiException(response.code, response.message)
1432-
return False
14331436

14341437
def get_trading_calendar(self, market, begin_date=None, end_date=None):
14351438
"""
@@ -1453,4 +1456,91 @@ def get_trading_calendar(self, market, begin_date=None, end_date=None):
14531456
return response.calendar
14541457
else:
14551458
raise ApiException(response.code, response.message)
1456-
return False
1459+
1460+
def get_stock_broker(self, symbol, limit=40, lang=None):
1461+
"""Get stock broker information
1462+
:param symbol:
1463+
:param limit: The maximum number of items returned. Default value is 40.
1464+
:param lang: tigeropen.common.consts.Language
1465+
return: tigeropen.quote.domain.stock_broker.StockBroker
1466+
example:
1467+
StockBroker({'symbol': '01810',
1468+
'bid_broker': [
1469+
LevelBroker({'level': 1, 'price': 11.46, 'broker_count': 5,
1470+
'broker': [Broker({'id': '5999', 'name': '中国创盈'}), Broker({'id': '4374', 'name': '巴克莱亚洲'}),
1471+
Broker({'id': '1438', 'name': 'Susquehanna'}), Broker({'id': '4821', 'name': '华盛'}),
1472+
Broker({'id': '6998', 'name': '中国投资'})]})],
1473+
'ask_broker': [
1474+
LevelBroker({'level': 1, 'price': 11.48, 'broker_count': 5,
1475+
'broker': [Broker({'id': '4374', 'name': '巴克莱亚洲'}), Broker({'id': '9056', 'name': '瑞银'}),
1476+
Broker({'id': '2027', 'name': '东亚'}), Broker({'id': '4821', 'name': '华盛'}),
1477+
Broker({'id': '4374', 'name': '巴克莱亚洲'})]})]})
1478+
"""
1479+
params = StockBrokerParams()
1480+
params.symbol = symbol
1481+
params.limit = limit
1482+
params.lang = get_enum_value(lang) if lang else get_enum_value(self._lang)
1483+
request = OpenApiRequest(STOCK_BROKER, biz_model=params)
1484+
response_content = self.__fetch_data(request)
1485+
if response_content:
1486+
response = StockBrokerResponse()
1487+
response.parse_response_content(response_content)
1488+
if response.is_success():
1489+
return response.result
1490+
else:
1491+
raise ApiException(response.code, response.message)
1492+
1493+
def get_capital_flow(self, symbol, market, period, begin_time=-1, end_time=-1, limit=200, lang=None):
1494+
"""Get capital net inflow Data, including different time periods, such as daily, weekly, monthly, etc.
1495+
:param symbol: 股票代号
1496+
:param market: tigeropen.common.consts.Market
1497+
:param period: period, possible values are: intraday, day, week, month, year, quarter, 6month
1498+
:param begin_time: 开始时间. 若是时间戳需要精确到毫秒, 为13位整数;
1499+
或是日期时间格式的字符串, 如 "2019-01-01" 或 "2019-01-01 12:00:00"
1500+
:param end_time: 结束时间. 格式同 begin_time
1501+
:param limit: 数量限制
1502+
:param lang: 语言支持: zh_CN,zh_TW,en_US
1503+
:return pandas.DataFrame, example:
1504+
time timestamp net_inflow symbol period
1505+
0 2022-02-24 1645678800000 -5.889058e+08 AAPL day
1506+
1 2022-02-25 1645765200000 -1.229127e+08 AAPL day
1507+
2 2022-02-28 1646024400000 1.763644e+08 AAPL day
1508+
"""
1509+
params = CapitalParams()
1510+
params.symbol = symbol
1511+
params.market = get_enum_value(market)
1512+
params.period = get_enum_value(period)
1513+
params.begin_time = begin_time
1514+
params.end_time = end_time
1515+
params.limit = limit
1516+
params.lang = get_enum_value(lang) if lang else get_enum_value(self._lang)
1517+
request = OpenApiRequest(CAPITAL_FLOW, biz_model=params)
1518+
response_content = self.__fetch_data(request)
1519+
if response_content:
1520+
response = CapitalFlowResponse()
1521+
response.parse_response_content(response_content)
1522+
if response.is_success():
1523+
return response.result
1524+
else:
1525+
raise ApiException(response.code, response.message)
1526+
1527+
def get_capital_distribution(self, symbol, market, lang=None):
1528+
"""Get capital distribution.
1529+
:param symbol: 股票代号
1530+
:param market: tigeropen.common.consts.Market
1531+
:param lang: 语言支持: zh_CN,zh_TW,en_US
1532+
return: tigeropen.quote.domain.capital_distribution.CapitalDistribution
1533+
"""
1534+
params = CapitalParams()
1535+
params.symbol = symbol
1536+
params.market = get_enum_value(market)
1537+
params.lang = get_enum_value(lang) if lang else get_enum_value(self._lang)
1538+
request = OpenApiRequest(CAPITAL_DISTRIBUTION, biz_model=params)
1539+
response_content = self.__fetch_data(request)
1540+
if response_content:
1541+
response = CapitalDistributionResponse()
1542+
response.parse_response_content(response_content)
1543+
if response.is_success():
1544+
return response.result
1545+
else:
1546+
raise ApiException(response.code, response.message)

0 commit comments

Comments
 (0)