### Install Tushare from source Source: https://tushare.pro/document/1?doc_id=7 These methods involve downloading the Tushare project either from PyPI or GitHub and installing it locally using Python's setup script. ```bash python setup.py install ``` -------------------------------- ### Install Tushare Skills with Clawhub Source: https://tushare.pro/document/1?doc_id=450 Use the `clawhub install` command to install Tushare Skills. This command is used for initial installation. ```bash # 使用 clawhub 安装 clawhub install tushare-data ``` -------------------------------- ### Fetch Index Market Data with pro_bar Source: https://tushare.pro/document/2?doc_id=109 This example shows how to fetch market data for an index using the 'pro_bar' interface. It requires specifying the index code, setting the 'asset' parameter to 'I' for index, and defining the start and end dates. The result is a DataFrame with index trading data. ```python import tushare as ts # Fetch market data for Shanghai Stock Exchange Composite Index df = ts.pro_bar(ts_code='000001.SH', asset='I', start_date='20180101', end_date='20181011') ``` -------------------------------- ### Install Tushare Skills with Clawhub Source: https://tushare.pro/document/1 Use `clawhub install` to add Tushare Skills to your OpenClaw environment. Run `clawhub update` to get the latest version. ```bash # 使用 clawhub 安装 clawhub install tushare-data ``` ```bash # 升级更新tushare skills clawhub update tushare-data ``` -------------------------------- ### Install Tushare Library Source: https://tushare.pro/document/1 Install the Tushare Python library. It is recommended to use the Tsinghua mirror for faster downloads. ```bash # 安装 Tushare(推荐清华镜像加速) pip install tushare -i https://pypi.tuna.tsinghua.edu.cn/simple ``` -------------------------------- ### Install Python Package from Mirror within Script (Python) Source: https://tushare.pro/document/1?doc_id=65 A Python script that prompts the user for a package name and then installs it using pip, specifying a domestic mirror and trusting the host. This allows for dynamic package installation with mirror configuration from within a Python environment. ```python #!/usr/bin/python import os package = input("Input the package:\n") command = "pip install %s -i http://pypi.mirrors.ustc.edu.cn/simple --trusted-host pypi.mirrors.ustc.edu.cn" % package os.system(command) ``` -------------------------------- ### Install Tushare Skills via npx Source: https://tushare.pro/document/1 Install Tushare Skills in a large model programming environment using the `npx skills add` command with the GitHub repository URL. ```bash # 使用npx命令安装 npx skills add https://github.com/waditu-tushare/skills --skill tushare ``` -------------------------------- ### Install Tushare using pip Source: https://tushare.pro/document/1?doc_id=7 This command installs the Tushare library using pip. If you encounter network timeouts, you can try using a domestic pip mirror like Tsinghua's. ```bash pip install tushare ``` ```bash pip install tushare -i https://pypi.tuna.tsinghua.edu.cn/simple ``` -------------------------------- ### Initialize Tushare API and Authentication Source: https://tushare.pro/document/1?doc_id=131 Demonstrates how to import the Tushare library, set the user authentication token, and initialize the Pro API interface. The token can be set globally or passed directly during initialization. ```python import tushare as ts ts.set_token('your token here') pro = ts.pro_api() # Alternatively, initialize directly with token pro = ts.pro_api('your token') ``` -------------------------------- ### GET /fut_weekly_detail Source: https://tushare.pro/document/2?doc_id=216 Retrieves weekly trading statistics for major futures products starting from March 2010. ```APIDOC ## GET /fut_weekly_detail ### Description Retrieves weekly trading statistics for major futures products, including volume, turnover, and price changes. Data is available from March 2010 onwards. ### Method GET ### Endpoint /fut_weekly_detail ### Parameters #### Query Parameters - **week** (str) - Optional - Cycle (e.g., 202001 for the first week of 2020) - **prd** (str) - Optional - Futures product code (comma-separated for multiple) - **start_week** (str) - Optional - Start cycle - **end_week** (str) - Optional - End cycle - **exchange** (str) - Optional - Exchange code - **fields** (str) - Optional - Fields to extract (e.g., 'prd,name,vol') ### Request Example pro.fut_weekly_detail(prd='CU', start_week='202001', end_week='202003', fields='prd,name,vol,amount') ### Response #### Success Response (200) - **exchange** (str) - Exchange code - **prd** (str) - Futures product code - **name** (str) - Product name - **vol** (int) - Trading volume (lots) - **amount** (float) - Trading amount (100 million yuan) - **open_interest** (int) - Open interest (lots) - **mc_close** (float) - Main contract closing price - **week** (str) - Cycle #### Response Example { "exchange": "SHFE", "prd": "CU", "name": "铜", "vol": 1078970, "amount": 2363.84, "open_interest": 404849, "mc_close": 43520.0, "week": "202011" } ``` -------------------------------- ### GET btc_marketcap Source: https://tushare.pro/document/41?doc_id=76 Retrieves historical daily market capitalization data for Bitcoin based on a specified start and end date. ```APIDOC ## GET btc_marketcap ### Description Retrieves historical daily market capitalization data for Bitcoin from the Tushare Pro database. ### Method GET ### Endpoint btc_marketcap ### Parameters #### Query Parameters - **start_date** (str) - Required - The start date for the data range (format: YYYYMMDD) - **end_date** (str) - Required - The end date for the data range (format: YYYYMMDD) ### Request Example pro.btc_marketcap(start_date='20180101', end_date='20180801') ### Response #### Success Response (200) - **date** (str) - The date of the record - **marketcap** (float) - The total market capitalization on that date #### Response Example { "date": "20180801", "marketcap": 132376700000.0 } ``` -------------------------------- ### Fetch Real-time Daily K-lines for All A-shares (Caution Advised) Source: https://tushare.pro/document/2?doc_id=372 This example demonstrates fetching real-time daily K-line data and transaction counts for all A-shares across multiple exchanges. It is not recommended to extract the entire market at once due to potential performance issues; consider batch extraction for better performance. ```python #获取今日开盘以来全市场所有股票实时日线和成交笔数(不建议一次提取全市场,可分批提取性能更好) df = pro.rt_k(ts_code='3*.SZ,6*.SH,0*.SZ,9*.BJ') ``` -------------------------------- ### Tushare Pro Initialization and Data Retrieval Source: https://tushare.pro/document/1?doc_id=131 This section covers importing the Tushare library, setting your API token, initializing the pro interface, and retrieving data using the trade_cal example. ```APIDOC ## Tushare Pro Initialization and Data Retrieval ### Description This section covers importing the Tushare library, setting your API token, initializing the pro interface, and retrieving data using the trade_cal example. ### Setup 1. **Import Tushare** ```python import tushare as ts ``` *Note: Tushare version must be greater than 1.2.10.* 2. **Set Token** ```python ts.set_token('your token here') ``` This method only needs to be called once or when the token expires. Alternatively, you can initialize the pro API directly with the token. 3. **Initialize Pro API** *Method 1: Using set_token* ```python pro = ts.pro_api() ``` *Method 2: Initializing directly with token* ```python pro = ts.pro_api('your token') ``` ### Data Retrieval Example To retrieve trading calendar information: * **Using `pro.trade_cal`** ```python df = pro.trade_cal(exchange='', start_date='20180901', end_date='20181001', fields='exchange,cal_date,is_open,pretrade_date', is_open='0') ``` * **Using `pro.query`** ```python df = pro.query('trade_cal', exchange='', start_date='20180901', end_date='20181001', fields='exchange,cal_date,is_open,pretrade_date', is_open='0') ``` ### Sample Response ``` exchange cal_date is_open pretrade_date 0 SSE 20180901 0 20180831 1 SSE 20180902 0 20180831 2 SSE 20180908 0 20180907 3 SSE 20180909 0 20180907 4 SSE 20180915 0 20180914 5 SSE 20180916 0 20180914 6 SSE 20180922 0 20180921 7 SSE 20180923 0 20180921 8 SSE 20180924 0 20180921 9 SSE 20180929 0 20180928 10 SSE 20180930 0 20180928 11 SSE 20181001 0 20180928 ``` ``` -------------------------------- ### GET /api/limit_list_d Source: https://tushare.pro/document/2?doc_id=298 Retrieves daily A-share limit up/down and board-bouncing data. This API does not include statistics for ST stocks and provides data starting from 2020. ```APIDOC ## GET /api/limit_list_d ### Description Retrieves daily A-share limit up/down and board-bouncing data. Data is available from 2020 onwards and excludes ST stocks. The API has rate limits based on积分 (points). ### Method GET ### Endpoint /api/limit_list_d ### Parameters #### Query Parameters - **trade_date** (str) - Optional - Trading date (e.g., '20220615'). - **ts_code** (str) - Optional - Stock code (e.g., '000017.SZ'). - **limit_type** (str) - Optional - Limit type: 'U' for limit up, 'D' for limit down, 'Z' for board bounce. - **exchange** (str) - Optional - Exchange: 'SH' for Shanghai, 'SZ' for Shenzhen, 'BJ' for Beijing. - **start_date** (str) - Optional - Start date for data retrieval (e.g., '20200101'). - **end_date** (str) - Optional - End date for data retrieval (e.g., '20221231'). ### Request Example ```python import tushare as ts pro = ts.pro_api() df = pro.limit_list_d(trade_date='20220615', limit_type='U', fields='ts_code,trade_date,industry,name,close,pct_chg,open_times,up_stat,limit_times') ``` ### Response #### Success Response (200) - **trade_date** (str) - Trading date. - **ts_code** (str) - Stock code. - **industry** (str) - Industry the stock belongs to. - **name** (str) - Stock name. - **close** (float) - Closing price. - **pct_chg** (float) - Percentage change. - **amount** (float) - Transaction amount. - **limit_amount** (float) - Transaction amount at limit price (for limit down, sum of all transactions at the limit price; no data for limit up). - **float_mv** (float) - Circulating market value. - **total_mv** (float) - Total market value. - **turnover_ratio** (float) - Turnover ratio. - **fd_amount** (float) - Frozen order amount (total funds buying at the limit up price). - **first_time** (str) - First time hitting the limit (no data for limit down). - **last_time** (str) - Last time hitting the limit. - **open_times** (int) - Number of board bounces (number of times the limit was broken for limit down). - **up_stat** (str) - Limit up statistics (e.g., 'N/T' means N times in T days). - **limit_times** (int) - Consecutive limit up count. - **limit** (str) - Limit type: 'D' for limit down, 'U' for limit up, 'Z' for board bounce. #### Response Example ```json { "data": { "items": [ { "trade_date": "20220615", "ts_code": "000017.SZ", "industry": "交运设备", "name": "深中华A", "close": 3.65, "pct_chg": 9.94, "amount": 12345.67, "limit_amount": 0.0, "float_mv": 5.67e8, "total_mv": 8.9e8, "turnover_ratio": 0.05, "fd_amount": 1234567.89, "first_time": "09:30:00", "last_time": "14:50:00", "open_times": 0, "up_stat": "1/1", "limit_times": 1, "limit": "U" } ], "has_next": true }, "request_id": "abcdef123456" } ``` ``` -------------------------------- ### GET /twitter_kol Source: https://tushare.pro/document/41?doc_id=105 Retrieves data for cryptocurrency KOLs on Twitter. The data is updated every 5 minutes. This endpoint requires start and end dates and limits results to 200 items per request. ```APIDOC ## GET /twitter_kol ### Description Retrieves data for cryptocurrency KOLs on Twitter. The data is updated every 5 minutes. This endpoint requires start and end dates and limits results to 200 items per request. ### Method GET ### Endpoint /twitter_kol ### Parameters #### Query Parameters - **start_date** (datetime) - Required - Start time in 'YYYY-MM-DD HH:MM:SS' format. - **end_date** (datetime) - Required - End time in 'YYYY-MM-DD HH:MM:SS' format. - **fields** (str) - Optional - Comma-separated list of fields to retrieve. Example: "id,account,nickname,content,retweet_content,media,str_posted_at". ### Request Example ```python import tushare as ts pro = ts.pro_api() pro.twitter_kol(start_date='2018-09-26 14:15:41', end_date='2018-09-26 16:20:11', fields="id,account,nickname,content,retweet_content,media,str_posted_at") ``` ### Response #### Success Response (200) - **id** (int) - Record ID (from the collection site). - **account_id** (int) - Account ID (from the collection site). - **account** (str) - Twitter account handle. - **nickname** (str) - Account nickname. - **avatar** (str) - URL to the account's avatar. - **content_id** (int) - Content ID (from the collection site). - **content** (str) - Original tweet content. May contain HTML tags. - **is_retweet** (int) - Indicates if the post is a retweet (0 for no, 1 for yes). - **retweet_content** (json) - Content of the retweet, if applicable. Contains another Twitter structure. - **media** (json) - Attachments, if any. Contains resource type and URL. - **posted_at** (int) - Timestamp of when the tweet was posted. - **content_translation** (str) - Translated content of the tweet. - **str_posted_at** (str) - Formatted posting time. - **create_at** (str) - Timestamp of when the data was collected. #### Response Example ```json { "id": 1116360, "account": "Excellion", "nickname": "Samson Mow", "content": "RT ' with your actual Tushare token. ```python import tushare as ts ts.set_token('<--your-token-->') pro = ts.pro_api() df = pro.stk_shock(trade_date='20260416') ``` -------------------------------- ### GET /api/forecast - Get Earnings Forecast Data Source: https://tushare.pro/document/2?doc_id=45 Retrieves earnings forecast data for a specific stock or based on announcement dates. Requires 2000 points to access. ```APIDOC ## GET /api/forecast ### Description Retrieves earnings forecast data for a specific stock or based on announcement dates. This endpoint requires 2000 points to access. For fetching data for all listed companies in a quarter, use the `forecast_vip` interface. ### Method GET ### Endpoint /api/forecast ### Parameters #### Query Parameters - **ts_code** (str) - Optional - Stock code (one of ts_code or ann_date must be provided). - **ann_date** (str) - Optional - Announcement date (one of ts_code or ann_date must be provided). - **start_date** (str) - Optional - Announcement start date. - **end_date** (str) - Optional - Announcement end date. - **period** (str) - Optional - Reporting period (e.g., '20171231' for annual, '20170630' for semi-annual, '20170930' for Q3). - **type** (str) - Optional - Forecast type (e.g., '预增' for positive growth, '预减' for negative growth, '扭亏' for turnaround, '首亏' for first-time loss, '续亏' for continued loss, '续盈' for continued profit, '略增' for slight increase, '略减' for slight decrease). ### Request Example ```python import tushare as ts pro = ts.pro_api() # Example: Fetching forecast data for a specific announcement date pro.forecast(ann_date='20190131', fields='ts_code,ann_date,end_date,type,p_change_min,p_change_max,net_profit_min') ``` ### Response #### Success Response (200) - **ts_code** (str) - TS stock code. - **ann_date** (str) - Announcement date. - **end_date** (str) - Reporting period. - **type** (str) - Earnings forecast type. - **p_change_min** (float) - Minimum percentage change in net profit forecast. - **p_change_max** (float) - Maximum percentage change in net profit forecast. - **net_profit_min** (float) - Minimum net profit forecast (in ten thousand yuan). - **net_profit_max** (float) - Maximum net profit forecast (in ten thousand yuan). - **last_parent_net** (float) - Net profit of the parent company in the same period last year. - **first_ann_date** (str) - Date of the first announcement. - **summary** (str) - Summary of the earnings forecast. - **change_reason** (str) - Reason for the earnings change. #### Response Example ```json { "data": { "items": [ { "ts_code": "000005.SZ", "ann_date": "20190131", "end_date": "20181231", "type": "预增", "p_change_min": 618.56, "p_change_max": 945.18, "net_profit_min": null, "net_profit_max": null, "last_parent_net": null, "first_ann_date": null, "summary": null, "change_reason": null } ], "fields": "ts_code,ann_date,end_date,type,p_change_min,p_change_max,net_profit_min" } } ``` ```