### Get Tencent Holdings Revenue Data (Python) Source: https://tushare.pro/document/2?doc_id=389 This example shows how to fetch historical revenue data for a specific Hong Kong stock by specifying the indicator name. The API can return up to 10000 rows per request. ```python #获取腾讯控股00700.HK股票利润表历年营业额数据 df = pro.hk_income(ts_code='00700.HK', ind_name='营业额') ``` -------------------------------- ### Get Index Basic Information Source: https://tushare.pro/document/2?doc_id=94 Use this snippet to fetch basic information for indices, specifying the market. Ensure you have initialized the Tushare API client. ```python pro = ts.pro_api() df = pro.index_basic(market='SW') ``` -------------------------------- ### Fetch Real-time Daily K-line Data for All A-shares Source: https://tushare.pro/document/2?doc_id=372 This example demonstrates fetching real-time daily K-line data for all A-shares across different exchanges. It is not recommended to fetch the entire market at once due to performance considerations; consider batch retrieval for better performance. ```python df = pro.rt_k(ts_code='3*.SZ,6*.SH,0*.SZ,9*.BJ') ``` -------------------------------- ### Get Index Daily Data by Date Range Source: https://tushare.pro/document/2?doc_id=95 Retrieve daily market data for an index within a specified start and end date. This is useful for historical analysis. ```python pro = ts.pro_api() df = pro.index_daily(ts_code='399300.SZ', start_date='20180101', end_date='20181010') ``` -------------------------------- ### Get Hong Kong Stock Connect Turnover for a Date Range Source: https://tushare.pro/document/2?doc_id=196 Retrieves turnover statistics for a specified period between a start and end date. Requires the `ts` library. ```python pro = ts.pro_api() #获取时间段统计信息 df = pro.ggt_daily(start_date='20180925', end_date='20190925') ``` -------------------------------- ### 获取上证e互动问答文本 Source: https://tushare.pro/document/2?doc_id=366 使用 `pro.irm_qa_sh` 接口获取指定日期的上证e互动问答文本数据。需要先初始化 `ts.pro_api()`。 ```python pro = ts.pro_api() #获取2025年2月12日上证e互动的问答文本 df = pro.irm_qa_sh(ann_date='20250212') ``` -------------------------------- ### Get All SGE Spot Contract Basic Info Source: https://tushare.pro/document/2?doc_id=284 Initializes the Tushare API and retrieves all available spot contract basic information. No specific input parameters are required. ```python pro = ts.pro_api() df = pro.sge_basic() ``` -------------------------------- ### Get CCTV News Transcript Source: https://tushare.pro/document/2?doc_id=154 Fetches the text transcript of the CCTV News broadcast for a specific date. The data starts from 2017. The API allows for continuous extraction by date and has no overall limit, but requires a separate permission. ```APIDOC ## GET cctv_news ### Description Retrieves the text transcript of the CCTV News broadcast for a given date. ### Method GET ### Endpoint /cctv_news ### Parameters #### Query Parameters - **date** (str) - Required - The date for which to retrieve the transcript. Format: YYYYMMDD (e.g., 20181211). ### Response #### Success Response (200) - **date** (str) - The date of the broadcast. - **title** (str) - The title of the news segment. - **content** (str) - The full text content of the news segment. ### Request Example ```python import tushare as ts pro = ts.pro_api() # Get the news transcript for December 11, 2018 df = pro.cctv_news(date='20181211') print(df) ``` ### Response Example ```json { "data": [ { "date": "20181211", "title": "中共中央党史和文献研究院编辑的《习近平谈“一带一路”》一书,已由中央文献出版社出版,即日起在...", "content": "中共中央党史和文献研究院编辑的《习近平谈“一带一路”》一书,已由中央文献出版社出版,即日起在..." }, { "date": "20181211", "title": "习近平总书记视察北京时强调,要坚持人民城市为人民,以北京市民最关心的问题为导向,对大气污染、...", "content": "习近平总书记视察北京时强调,要坚持人民城市为人民,以北京市民最关心的问题为导向,对大气污染、..." } ] } ``` ``` -------------------------------- ### Fetch Index Announcements with Date Range and Specific Fields Source: https://tushare.pro/document/2?doc_id=460 This example shows how to fetch announcements from a specific source within a date range and select only desired output fields. ```python #示例:获取国证指数公司2026年1月以来发布的指数公告,并指定输出字段 df = pro.idx_anns(src='国证指数', start_date='20260101', fields='ann_date,title,type') ``` -------------------------------- ### Initialize and Use pledge_detail API Source: https://tushare.pro/document/2?doc_id=111 Initializes the TuShare API client and calls the `pledge_detail` function to fetch stock pledge data. Ensure you have a valid token if not using the default. ```python pro = ts.pro_api() #or #pro = ts.pro_api('your token') df = pro.pledge_detail(ts_code='000014.SZ') ``` -------------------------------- ### Get Abnormal Volatility Data for a Specific Stock Over a Date Range Source: https://tushare.pro/document/2?doc_id=451 Retrieves abnormal volatility information for a particular stock code within a specified start and end date. This is useful for historical analysis of a single stock's volatility. ```python df = pro.stk_shock(ts_code='002015.SZ', start_date='20250101', end_date='20261231') ``` -------------------------------- ### Get Hong Kong Stock Connect Fund Flows by Date Range Source: https://tushare.pro/document/2?doc_id=47 Use this method to fetch daily fund flow data for Hong Kong Stock Connect by specifying a start and end date. Requires initialization of the Tushare Pro API. ```python pro = ts.pro_api() pro.moneyflow_hsgt(start_date='20180125', end_date='20180808') ``` -------------------------------- ### 查询当前所有正常上市交易的股票列表 Source: https://tushare.pro/document/2?doc_id=25 使用 `stock_basic` 方法查询所有正常上市交易的股票,并指定返回的字段。此方法适用于获取股票的基本信息。 ```python pro = ts.pro_api() #查询当前所有正常上市交易的股票列表 data = pro.stock_basic(exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date') ``` -------------------------------- ### Initialize Tushare Pro API and Fetch Single ETF Data Source: https://tushare.pro/document/2?doc_id=454 Configure your API token and then fetch real-time reference data for a specific ETF using its ts_code. Ensure the token is set globally or passed during initialization. ```python # 导入sdk包 import tushare as ts # 配置凭据,如果已全局配置了,可以忽略。 ts.set_token('<--your-token-->') # 获取接口实例 pro = ts.pro_api() # 示例: 获取单个ETF(159103.SZ)的最新参考 df = pro.rt_etf_sz_iopv(ts_code="159103.SZ") print(df) ``` -------------------------------- ### Get Hibor Interest Rates Source: https://tushare.pro/document/2?doc_id=153 Retrieves Hibor interest rate data for a specified period. The API supports fetching data by date, start date, and end date. It has a limit of 4000 rows per request and can be accessed using accumulated points. ```APIDOC ## Get Hibor Interest Rates ### Description Retrieves Hibor interest rate data for a specified period. The API supports fetching data by date, start date, and end date. It has a limit of 4000 rows per request and can be accessed using accumulated points. ### Method GET ### Endpoint /hibor ### Parameters #### Query Parameters - **date** (str) - Optional - The specific date for which to retrieve Hibor rates (format: YYYYMMDD). - **start_date** (str) - Optional - The start date for the data retrieval period (format: YYYYMMDD). - **end_date** (str) - Optional - The end date for the data retrieval period (format: YYYYMMDD). ### Response #### Success Response (200) - **date** (str) - The date of the rate. - **on** (float) - Overnight rate. - **1w** (float) - 1-week rate. - **2w** (float) - 2-week rate. - **1m** (float) - 1-month rate. - **2m** (float) - 2-month rate. - **3m** (float) - 3-month rate. - **6m** (float) - 6-month rate. - **12m** (float) - 12-month rate. ### Request Example ```python import tushare as ts pro = ts.pro_api() df = pro.hibor(start_date='20180101', end_date='20181130') ``` ### Response Example ```json { "data": [ { "date": "20181130", "on": 1.52500, "1w": 1.10125, "2w": 1.08000, "1m": 1.20286, "2m": 1.83030, "3m": 2.03786, "6m": 2.32821, "12m": 2.65929 } // ... more data ] } ``` ``` -------------------------------- ### Get Futures Copper Weekly Trading Statistics with Specific Fields and Date Range Source: https://tushare.pro/document/2?doc_id=216 Retrieves specific trading statistics (product code, name, volume, amount) for copper futures within a defined week range. This example demonstrates filtering by `start_week`, `end_week`, and `fields` parameters. ```python df = pro.fut_weekly_detail(prd='CU', start_week='202001', end_week='202003', fields='prd,name,vol,amount') ``` -------------------------------- ### 查询当前所有正常上市交易的股票列表 (使用 query) Source: https://tushare.pro/document/2?doc_id=25 使用 `query` 方法查询所有正常上市交易的股票,并指定返回的字段。此方法是 `stock_basic` 的另一种调用方式,功能相同。 ```python #查询当前所有正常上市交易的股票列表 data = pro.query('stock_basic', exchange='', list_status='L', fields='ts_code,symbol,name,area,industry,list_date') ``` -------------------------------- ### Initialize TuShare API and Fetch Pledge Statistics Source: https://tushare.pro/document/2?doc_id=110 Initialize the TuShare API client, optionally with a token, and then call the `pledge_stat` function to retrieve stock pledge statistics for a given stock code. ```python pro = ts.pro_api() #或者 #pro = ts.pro_api('your token') df = pro.pledge_stat(ts_code='000014.SZ') ``` -------------------------------- ### Calculate Moving Averages Source: https://tushare.pro/document/2?doc_id=109 Calculates moving averages for a given stock. The `start_date` must be set sufficiently in advance of the desired end date to allow for the calculation of the longest moving average requested. For example, to get a 5-day moving average, the date range must span more than 5 days. ```python df = ts.pro_bar(ts_code='000001.SZ', start_date='20180101', end_date='20181011', ma=[5, 20, 50]) ``` -------------------------------- ### Get Daily Auction Data Source: https://tushare.pro/document/2?doc_id=369 Retrieve the opening auction trading results for a specific date. Specify the trade_date and desired fields to get the data. ```python df = pro.stk_auction(trade_date='20250218',fields='ts_code, trade_date,vol,price,amount,turnover_rate,volume_ratio') ``` -------------------------------- ### 获取可转债基本信息列表 Source: https://tushare.pro/document/2?doc_id=185 使用此接口获取可转债的基本信息列表。需要先初始化Pro API并传入您的token。可指定fields参数来选择需要返回的字段。 ```python pro = ts.pro_api(your token) #获取可转债基础信息列表 df = pro.cb_basic(fields="ts_code,bond_short_name,stk_code,stk_short_name,list_date,delist_date") ``` -------------------------------- ### Query pledge_detail using query method Source: https://tushare.pro/document/2?doc_id=111 Fetches stock pledge details using the generic `query` method with the 'pledge_detail' interface. This is an alternative way to access the same data. ```python df = pro.query('pledge_detail', ts_code='000014.SZ') ``` -------------------------------- ### Get Industry Classification for a Stock Code Source: https://tushare.pro/document/2?doc_id=335 Use this snippet to find the industry classifications a specific stock belongs to. Provide the `ts_code` of the stock to get its hierarchical industry information. ```python #获取000001.SZ所属行业 df = pro.index_member_all(ts_code='000001.SZ') ``` -------------------------------- ### Initialize Tushare Pro API and Fetch Financial Indicators Source: https://tushare.pro/document/2?doc_id=79 Initializes the Tushare Pro API client and fetches financial indicator data for a specific stock code. Ensure you have authenticated your API client before use. ```python pro = ts.pro_api() df = pro.fina_indicator(ts_code='600000.SH') ``` -------------------------------- ### Get CCASS Shareholding Details Source: https://tushare.pro/document/2?doc_id=274 Use this function to retrieve the shareholding details from the Central Clearing System. Specify the stock code and trade date to get the desired information. You can also select specific fields to return. ```python pro = ts.pro_api() df = pro.ccass_hold_detail(ts_code='00960.HK', trade_date='20211101', fields='trade_date,ts_code,col_participant_id,col_participant_name,col_shareholding') ``` -------------------------------- ### Get Daily Top Sectors - Python Source: https://tushare.pro/document/2?doc_id=357 Use this function to retrieve a list of the top-performing sectors based on daily limit-up stocks. Specify the trade date to get relevant data. Ensure you have initialized the Tushare Pro API client. ```python pro = ts.pro_api() df = pro.limit_cpt_list(trade_date='20241127') ``` -------------------------------- ### 获取申万行业指数实时行情 Source: https://tushare.pro/document/2?doc_id=417 使用 `rt_sw_k` 接口获取申万行业指数的最新截面数据。该接口需要单独的权限。可以一次性提取全部指数数据,或按指定的指数代码提取。 ```APIDOC ## 获取申万行业指数实时行情 ### Description 获取申万行业指数的最新截面数据。该接口是单独开权限的数据。 ### Method `rt_sw_k` ### Parameters #### Query Parameters - **ts_code** (str) - Optional - 指数代码,如: 801005.SI;可以是逗号隔开的多个,如: 801005.SI,801001.SI ### Request Example ```python import tushare as ts pro = ts.pro_api() # 一次性提取全部申万指数实时数据 df = pro.rt_sw_k() # 按ts_code提取行情数据,例如提取801053.SI(贵金属) 实时行情 df = pro.rt_sw_k(ts_code='801053.SI') ``` ### Response #### Success Response (200) - **ts_code** (str) - 指数代码 - **name** (str) - 指数名称 - **trade_time** (str) - 交易时间 - **close** (float) - 现价 - **pre_close** (float) - 昨收 - **high** (float) - 最高价 - **open** (float) - 开盘价 - **low** (float) - 最低价 - **vol** (float) - 成交量(股) - **amount** (float) - 成交金额(元) - **pct_change** (float) - 增长率 #### Response Example ```json [ { "ts_code": "801001.SI", "name": "申万50", "trade_time": "2026-01-29 11:20:15", "close": 3787.9120, "pre_close": 3798.2100, "high": 3813.4650, "open": 3813.4650, "low": 3774.6250, "vol": 3705199982.0, "amount": 222824326266.0, "pct_change": -0.27 } ] ``` ``` -------------------------------- ### Get Hong Kong Stock Adjusted Daily Data Source: https://tushare.pro/document/2?doc_id=339 Use this function to retrieve adjusted daily market data for Hong Kong stocks. Specify `ts_code` and date range for a single stock, or `trade_date` to get data for all stocks on a specific day. Ensure you have the necessary API access and积分. ```python pro = ts.pro_api() #获取单一股票行情 df = pro.hk_daily_adj(ts_code='00001.HK', start_date='20240101', end_date='20240722') ``` ```python #获取某一日某个交易所的全部股票 df = pro.hk_daily_adj(trade_date='20240722') ``` -------------------------------- ### 获取A股当日1分钟实时行情 Source: https://tushare.pro/document/2?doc_id=457 配置TuShare SDK凭据,然后获取实时分钟数据。适用于需要获取单只股票当日分时行情数据的场景。 ```python # 导入sdk包 import tushare as ts # 配置凭据,如果已全局配置了,可以忽略。 ts.set_token('<--your-token-->') # 获取接口实例 pro = ts.pro_api() # 拉取接口(rt_min_daily)数据 # 获取浦发银行股票(600000.SH)当日1分钟实时行情 df = pro.rt_min_daily(freq="1MIN", ts_code="600000.SH") print(df) ``` -------------------------------- ### Get Convertible Bond Rating History Source: https://tushare.pro/document/2?doc_id=458 Retrieves the historical rating records for a given convertible bond. ```APIDOC ## GET cb_rating ### Description Fetches the historical rating records for convertible bonds. This API has a rate limit of 3000 records per request and requires 2000 points to call. ### Method GET ### Endpoint /api/v1/market/cb_rating ### Parameters #### Query Parameters - **ts_code** (str) - Required - Convertible bond code. Supports multiple values. ### Response #### Success Response (200) - **ts_code** (str) - Convertible bond code. - **ann_date** (str) - Rating announcement date. - **rating_date** (str) - Rating date. - **rating_com_name** (str) - Rating agency name. - **rating_way** (str) - Rating method. - **rating_type** (str) - Rating category. - **rating** (str) - Credit rating. - **rating_outlook** (str) - Rating outlook. ### Request Example ```python # Example usage (Python SDK) import tushare as ts pro = ts.pro_api() # Fetch rating history for a specific bond df = pro.cb_rating(ts_code='128119.SZ', fields='ts_code,ann_date,rating_date,rating_com_name,rating,rating_outlook') print(df) ``` ### Response Example ```json { "ts_code": "128119.SZ", "ann_date": "20260402", "rating_date": "20260330", "rating_com_name": "联合资信评估股份有限公司", "rating_way": "评级", "rating_type": "主体", "rating": "BB+", "rating_outlook": null } ``` ``` -------------------------------- ### 获取期权分钟行情数据 Source: https://tushare.pro/document/2?doc_id=341 使用Python SDK获取指定期权合约的分钟行情数据。需要提供合约代码、分钟频度以及开始和结束日期。 ```python pro = ts.pro_api() df = pro.df = pro.opt_mins(ts_code='10007976.SH', freq='1min', start_date='2024-09-27 09:00:00', end_date='2024-09-27 19:00:00') ``` -------------------------------- ### Get Futures Weekly/Monthly Market Data Source: https://tushare.pro/document/2?doc_id=337 Retrieves weekly or monthly market data for futures contracts. This endpoint is updated daily. ```APIDOC ## GET /api/v1/fut_weekly_monthly ### Description Retrieves weekly or monthly market data for futures contracts. This endpoint is updated daily. ### Method GET ### Endpoint /api/v1/fut_weekly_monthly ### Parameters #### Query Parameters - **ts_code** (str) - Optional - TS code for the futures contract. - **trade_date** (str) - Optional - Specific trading date (YYYYMMDD). - **start_date** (str) - Optional - Start trading date (YYYYMMDD). - **end_date** (str) - Optional - End trading date (YYYYMMDD). - **freq** (str) - Required - Frequency of the data. Use 'week' for weekly and 'month' for monthly. - **exchange** (str) - Optional - Exchange code. ### Response #### Success Response (200) - **ts_code** (str) - Futures contract code. - **trade_date** (str) - Trading date (typically Friday for weekly, end of month for monthly). - **end_date** (str) - Calculation end date. - **freq** (str) - Frequency of the data (week or month). - **open** (float) - Opening price for the period. - **high** (float) - Highest price for the period. - **low** (float) - Lowest price for the period. - **close** (float) - Closing price for the period. - **pre_close** (float) - Previous period's closing price. - **settle** (float) - Settlement price for the period. - **pre_settle** (float) - Previous period's settlement price. - **vol** (float) - Trading volume for the period (lots). - **amount** (float) - Trading amount for the period (ten thousand yuan). - **oi** (float) - Open interest for the period (lots). - **oi_chg** (float) - Change in open interest for the period. - **exchange** (str) - Exchange code. - **change1** (float) - Price change (Close - Previous Settle). - **change2** (float) - Price change (Settle - Previous Settle). ### Request Example ```json { "ts_code": "SR88.DCE", "trade_date": "20231027", "freq": "week" } ``` ### Response Example ```json { "data": [ { "ts_code": "SR88.DCE", "trade_date": "20231027", "end_date": "20231027", "freq": "week", "open": 7500.0, "high": 7600.0, "low": 7400.0, "close": 7550.0, "pre_close": 7450.0, "settle": 7555.0, "pre_settle": 7455.0, "vol": 100000.0, "amount": 755500000.0, "oi": 200000.0, "oi_chg": 5000.0, "exchange": "DCE", "change1": 100.0, "change2": 100.0 } ] } ``` ```