|
9 | 9 | import delorean |
10 | 10 | import six |
11 | 11 |
|
12 | | -from tigeropen.common.consts import THREAD_LOCAL, SecurityType, CorporateActionType |
| 12 | +from tigeropen.common.consts import THREAD_LOCAL, SecurityType, CorporateActionType, IndustryLevel |
13 | 13 | from tigeropen.common.exceptions import ApiException |
14 | | -from tigeropen.fundamental.request.model import FinancialDailyParams, FinancialReportParams, CorporateActionParams |
| 14 | +from tigeropen.fundamental.request.model import FinancialDailyParams, FinancialReportParams, CorporateActionParams, \ |
| 15 | + IndustryParams |
15 | 16 | from tigeropen.fundamental.response.corporate_dividend_response import CorporateDividendResponse |
16 | 17 | from tigeropen.fundamental.response.corporate_earnings_calendar_response import EarningsCalendarResponse |
17 | 18 | from tigeropen.fundamental.response.corporate_split_response import CorporateSplitResponse |
18 | 19 | from tigeropen.fundamental.response.financial_report_response import FinancialReportResponse |
19 | 20 | from tigeropen.fundamental.response.financial_daily_response import FinancialDailyResponse |
| 21 | +from tigeropen.fundamental.response.industry_response import IndustryListResponse, IndustryStocksResponse, \ |
| 22 | + StockIndustryResponse |
20 | 23 | from tigeropen.quote.response.future_briefs_response import FutureBriefsResponse |
21 | 24 | from tigeropen.quote.response.future_exchange_response import FutureExchangeResponse |
22 | 25 | from tigeropen.quote.response.future_contract_response import FutureContractResponse |
|
47 | 50 | TIMELINE, KLINE, TRADE_TICK, OPTION_EXPIRATION, OPTION_CHAIN, FUTURE_EXCHANGE, OPTION_BRIEF, \ |
48 | 51 | OPTION_KLINE, OPTION_TRADE_TICK, FUTURE_KLINE, FUTURE_TICK, FUTURE_CONTRACT_BY_EXCHANGE_CODE, \ |
49 | 52 | FUTURE_TRADING_DATE, QUOTE_SHORTABLE_STOCKS, FUTURE_REAL_TIME_QUOTE, \ |
50 | | - FUTURE_CURRENT_CONTRACT, QUOTE_REAL_TIME, QUOTE_STOCK_TRADE, FINANCIAL_DAILY, FINANCIAL_REPORT, CORPORATE_ACTION |
| 53 | + FUTURE_CURRENT_CONTRACT, QUOTE_REAL_TIME, QUOTE_STOCK_TRADE, FINANCIAL_DAILY, FINANCIAL_REPORT, CORPORATE_ACTION, \ |
| 54 | + INDUSTRY_LIST, INDUSTRY_STOCKS, STOCK_INDUSTRY |
51 | 55 | from tigeropen.common.consts import Market, Language, QuoteRight, BarPeriod |
52 | 56 | from tigeropen.common.util.contract_utils import extract_option_info |
53 | 57 | from tigeropen.common.util.common_utils import eastern |
@@ -954,3 +958,71 @@ def get_financial_report(self, symbols, market, fields, period_type): |
954 | 958 | return response.financial_report |
955 | 959 | else: |
956 | 960 | raise ApiException(response.code, response.message) |
| 961 | + |
| 962 | + def get_industry_list(self, industry_level=IndustryLevel.GGROUP): |
| 963 | + """ |
| 964 | + 获取行业列表 |
| 965 | + :param industry_level: 行业级别. 可选值为 common.consts.IndustryLevel 枚举类型. 默认一级行业 |
| 966 | + :return: 由行业信息 dict 构成的列表. industry_level 为行业级别, id 为行业 id |
| 967 | + 如 [{'industry_level': 'GGROUP', 'id': '5020', 'name_cn': '媒体与娱乐', 'name_en': 'Media & Entertainment'}, |
| 968 | + {'industry_level': 'GGROUP', 'id': '2550', 'name_cn': '零售业', 'name_en': 'Retailing'}, |
| 969 | + ...] |
| 970 | + """ |
| 971 | + params = IndustryParams() |
| 972 | + params.industry_level = industry_level.value |
| 973 | + request = OpenApiRequest(INDUSTRY_LIST, biz_model=params) |
| 974 | + response_content = self.__fetch_data(request) |
| 975 | + if response_content: |
| 976 | + response = IndustryListResponse() |
| 977 | + response.parse_response_content(response_content) |
| 978 | + if response.is_success(): |
| 979 | + return response.industry_list |
| 980 | + else: |
| 981 | + raise ApiException(response.code, response.message) |
| 982 | + |
| 983 | + def get_industry_stocks(self, industry, market=Market.US): |
| 984 | + """ |
| 985 | + 获取某行业下的股票列表 |
| 986 | + :param industry: 行业 id |
| 987 | + :param market: 市场枚举类型 |
| 988 | + :return: 公司信息列表. |
| 989 | + 如 [{'symbol': 'A', 'company_name': 'A', 'market': 'US', 'industry_list': [{...}, {...},..]}, |
| 990 | + {'symbol': 'B', 'company_name': 'B', 'market': 'US', 'industry_list': [{...}, {...},..]}, |
| 991 | + ...] |
| 992 | + """ |
| 993 | + params = IndustryParams() |
| 994 | + params.market = market.value |
| 995 | + params.industry_id = industry |
| 996 | + request = OpenApiRequest(INDUSTRY_STOCKS, biz_model=params) |
| 997 | + response_content = self.__fetch_data(request) |
| 998 | + if response_content: |
| 999 | + response = IndustryStocksResponse() |
| 1000 | + response.parse_response_content(response_content) |
| 1001 | + if response.is_success(): |
| 1002 | + return response.industry_stocks |
| 1003 | + else: |
| 1004 | + raise ApiException(response.code, response.message) |
| 1005 | + |
| 1006 | + def get_stock_industry(self, symbol, market=Market.US): |
| 1007 | + """ |
| 1008 | + 获取股票的行业 |
| 1009 | + :param symbol: 股票 symbol |
| 1010 | + :param market: 市场枚举类型 |
| 1011 | + :return: 所属多级行业的列表 |
| 1012 | + 如 [{'industry_level': 'GSECTOR', 'id': '45', 'name_cn': '信息技术', 'name_en': 'Information Technology'}, |
| 1013 | + {'industry_level': 'GGROUP', 'id': '4520', 'name_cn': '技术硬件与设备', 'name_en': 'Technology Hardware & Equipment'}, |
| 1014 | + {'industry_level': 'GIND', 'id': '452020', 'name_cn': '电脑与外围设备', 'name_en': 'Technology Hardware, Storage & Peripherals'}, |
| 1015 | + {'industry_level': 'GSUBIND', 'id': '45202030', 'name_cn': '电脑硬件、储存设备及电脑周边', 'name_en': 'Technology Hardware, Storage & Peripherals'}] |
| 1016 | + """ |
| 1017 | + params = IndustryParams() |
| 1018 | + params.symbol = symbol |
| 1019 | + params.market = market.value |
| 1020 | + request = OpenApiRequest(STOCK_INDUSTRY, biz_model=params) |
| 1021 | + response_content = self.__fetch_data(request) |
| 1022 | + if response_content: |
| 1023 | + response = StockIndustryResponse() |
| 1024 | + response.parse_response_content(response_content) |
| 1025 | + if response.is_success(): |
| 1026 | + return response.stock_industry |
| 1027 | + else: |
| 1028 | + raise ApiException(response.code, response.message) |
0 commit comments