### Get Financial Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves financial statements for a list of stocks. ```python get_financial_data(stock_list, table_list=[], start_time='', end_time='', report_type='report_time') ``` ```python 'Balance' #资产负债表 'Income' #利润表 'CashFlow' #现金流量表 'Capital' #股本表 'Holdernum' #股东数 'Top10holder' #十大股东 'Top10flowholder' #十大流通股东 'Pershareindex' #每股指标 ``` ```python 'report_time' #截止日期 'announce_time' #披露日期 ``` -------------------------------- ### Get IPO Subscription Information Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves new stock subscription details within a specified time range. ```python get_ipo_info(start_time, end_time) ``` ```python securityCode - string 证券代码 codeName - string 代码简称 market - string 所属市场 actIssueQty - int 发行总量,单位:股 onlineIssueQty - int 网上发行量, 单位:股 onlineSubCode - string 申购代码 onlineSubMaxQty - int 申购上限, 单位:股 publishPrice - float 发行价格 isProfit - int 是否已盈利 0:上市时尚未盈利 1:上市时已盈利 industryPe - float 行业市盈率 afterPE - float 发行后市盈率 ``` -------------------------------- ### Get Trading Calendar Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves the trading calendar for a specified market. ```python get_trading_calendar(market, start_time = '', end_time = '') ``` -------------------------------- ### GET /get_ipo_info Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves new stock subscription information for a specific date range. ```APIDOC ## GET /get_ipo_info ### Description Returns new stock subscription details including issue price, quantity, and market info. ### Method GET ### Parameters #### Query Parameters - **start_time** (string) - Required - Start date (e.g., '20230327') - **end_time** (string) - Required - End date (e.g., '20230327') ### Response #### Success Response (200) - **data** (list[dict]) - List of IPO information objects. ``` -------------------------------- ### GET /get_financial_data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves financial statement data for a list of stocks. ```APIDOC ## GET /get_financial_data ### Description Retrieves financial data tables (Balance, Income, CashFlow, etc.) for specified stocks. ### Method GET ### Parameters #### Query Parameters - **stock_list** (list) - Required - List of contract codes - **table_list** (list) - Optional - List of financial table names - **start_time** (string) - Optional - Start time - **end_time** (string) - Optional - End time - **report_type** (string) - Optional - 'report_time' or 'announce_time' ### Response #### Success Response (200) - **data** (dict) - Dictionary mapping stock codes to their respective financial dataframes. ``` -------------------------------- ### Get Trading Dates Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves a list of trading dates for a given market. ```python get_trading_dates(market, start_time='', end_time='', count=-1) ``` -------------------------------- ### Get Available Period List Source: https://dict.thinktrader.net/nativeApi/xtdata.html Returns the list of supported time periods for data retrieval. ```python get_period_list() ``` -------------------------------- ### Get Instrument Details Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves metadata for a specific stock code. Setting iscomplete to True returns additional fields like fee structures. ```python get_instrument_detail(stock_code, iscomplete) ``` ```text ExchangeID - string 合约市场代码 InstrumentID - string 合约代码 InstrumentName - string 合约名称 ProductID - string 合约的品种ID(期货) ProductName - string 合约的品种名称(期货) ExchangeCode - string 交易所代码 UniCode - string 统一规则代码 CreateDate - str 上市日期(期货) OpenDate - str IPO日期(股票) ExpireDate - int 退市日或者到期日 PreClose - float 前收盘价格 SettlementPrice - float 前结算价格 UpStopPrice - float 当日涨停价 DownStopPrice - float 当日跌停价 FloatVolume - float 流通股本 TotalVolume - float 总股本 LongMarginRatio - float 多头保证金率 ShortMarginRatio - float 空头保证金率 PriceTick - float 最小价格变动单位 VolumeMultiple - int 合约乘数(对期货以外的品种,默认是1) MainContract - int 主力合约标记,1、2、3分别表示第一主力合约,第二主力合约,第三主力合约 LastVolume - int 昨日持仓量 InstrumentStatus - int 合约停牌状态 IsTrading - bool 合约是否可交易 IsRecent - bool 是否是近月合约 OpenInterestMultiple - int 交割月持仓倍数 ``` ```text ChargeType - int 期货和期权手续费方式 0表示未知,1表示按元/手,2表示按费率,单位为万分比,‱ ChargeOpen - float 开仓手续费(率) 返回-1时该值无效,其余情况参考ChargeType ChargeClose - float 平仓手续费(率) 返回-1时该值无效,其余情况参考ChargeType ChargeTodayOpen - float 开今仓(日内开仓)手续费(率) 返回-1时该值无效,其余情况参考ChargeType ChargeTodayClose - float 平今仓(日内平仓)手续费(率) 返回-1时该值无效,其余情况参考ChargeType OptionType - int 期权类型 返回-1表示合约为非期权 返回0为期权认购 返回1为期权认沽 ...... ``` -------------------------------- ### Get Holiday Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves a list of holiday dates up to the current year. ```python get_holidays() ``` -------------------------------- ### Get Index Weight Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves the weight information for index components. Requires prior download of index weight data. ```python get_index_weight(index_code) ``` -------------------------------- ### Get Ex-Dividend Factors Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves ex-dividend data for a specific stock within a given time range. ```python get_divid_factors(stock_code, start_time='', end_time='') ``` -------------------------------- ### Get Instrument Type Source: https://dict.thinktrader.net/nativeApi/xtdata.html Returns a dictionary indicating the type of the specified instrument. ```python get_instrument_type(stock_code) ``` ```python 'index' #指数 'stock' #股票 'fund' #基金 'etf' #ETF ``` -------------------------------- ### Get Full Tick Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves full-push tick data for specified markets or individual contracts. ```python get_full_tick(code_list) ``` -------------------------------- ### GET /get_divid_factors Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves ex-dividend factors for a specific contract. ```APIDOC ## GET /get_divid_factors ### Description Retrieves ex-dividend factors for a given contract within a specified time range. ### Method GET ### Parameters #### Query Parameters - **stock_code** (string) - Required - Contract code - **start_time** (string) - Optional - Start time - **end_time** (string) - Optional - End time ### Response #### Success Response (200) - **data** (pd.DataFrame) - Ex-dividend dataset ``` -------------------------------- ### Get Latest Trading Day K-Line Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieves real-time K-line data for the current trading day. ```python get_full_kline(field_list = [], stock_list = [], period = '1m' , start_time = '', end_time = '', count = 1 , dividend_type = 'none', fill_data = True) ``` -------------------------------- ### Get Full Tick Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Acquire full tick data for specified instruments or markets. ```APIDOC ## GET /api/get_full_tick ### Description Retrieves full tick data for specified instruments or markets. ### Method GET ### Endpoint /api/get_full_tick ### Parameters #### Query Parameters - **code_list** (list) - Required - A list of codes. Can be market codes (e.g., `['SH', 'SZ']`) to subscribe to the entire market, or instrument codes (e.g., `['600000.SH', '000001.SZ']`) to subscribe to specific instruments. ### Response #### Success Response (200) - Returns a dictionary where keys are instrument codes (e.g., '600000.SH') and values are the corresponding tick data. #### Response Example ```json { "600000.SH": [ {"time": 1678886400, "price": 10.55, "volume": 100, "bid_price": [10.54, 10.53], "ask_price": [10.55, 10.56]}, {"time": 1678886406, "price": 10.56, "volume": 150, "bid_price": [10.55, 10.54], "ask_price": [10.56, 10.57]} ], "000001.SZ": [ {"time": 1678886400, "price": 3005.0, "volume": 500, "bid_price": [3004.0, 3003.0], "ask_price": [3005.0, 3006.0]}, {"time": 1678886406, "price": 3006.0, "volume": 600, "bid_price": [3005.0, 3004.0], "ask_price": [3006.0, 3007.0]} ] } ``` ### Remarks - None ``` -------------------------------- ### Get Local Market Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieve market data directly from local data files, useful for quick batch access to historical data. ```APIDOC ## GET /api/get_local_data ### Description Retrieves market data from local data files, designed for fast batch access to historical data. ### Method GET ### Endpoint /api/get_local_data ### Parameters #### Query Parameters - **field_list** (list) - Optional - A list of data fields to retrieve. If empty, all fields are returned. - **stock_list** (list) - Optional - A list of instrument codes. - **period** (str) - Optional - The data period. Examples: '1m', '5m', '1d'. Defaults to '1d'. - **start_time** (str) - Optional - The start time for the data retrieval. - **end_time** (str) - Optional - The end time for the data retrieval. - **count** (int) - Optional - The number of data points to retrieve. Defaults to -1 (all available data within the time range). - **dividend_type** (str) - Optional - The dividend adjustment type. Defaults to 'none'. - **fill_data** (bool) - Optional - Whether to fill missing data points forward. Defaults to `True`. - **data_dir** (str) - Optional - The path to the `userdata_mini` directory within the MiniQmt installation. By default, xtdata accesses this path via connection. Modifying this parameter or `xtdata.data_dir` changes the default data reading location. ### Response #### Success Response (200) - **For K-line periods ('1m', '5m', '1d'):** - Returns a dictionary where keys are field names (e.g., 'open', 'high', 'low', 'close', 'volume') and values are pandas DataFrames. Each DataFrame has `stock_list` as index and `time_list` as columns. All returned DataFrames share the same dimensions and index. - **For tick period ('tick'):** - Returns a dictionary where keys are instrument codes (e.g., '600000.SH') and values are NumPy ndarrays. Each ndarray contains data points sorted by timestamp. #### Response Example (K-line data) ```json { "open": { "600000.SH": [10.5, 10.6, 10.7], "000300.SH": [3000.0, 3010.0, 3020.0] }, "close": { "600000.SH": [10.6, 10.7, 10.8], "000300.SH": [3010.0, 3020.0, 3030.0] } } ``` #### Response Example (Tick data) ```json { "600000.SH": [ {"time": 1678886400, "price": 10.55, "volume": 100}, {"time": 1678886406, "price": 10.56, "volume": 150} ], "000300.SH": [ {"time": 1678886400, "price": 3005.0, "volume": 500}, {"time": 1678886406, "price": 3006.0, "volume": 600} ] } ``` ### Remarks - This function is only for retrieving Level 1 data. ``` -------------------------------- ### Get Market Data (Cached) Source: https://dict.thinktrader.net/nativeApi/xtdata.html Retrieve market data from the cache. This is the primary interface for actively fetching market data. ```APIDOC ## GET /api/get_market_data ### Description Retrieves market data from the cache. This is the main interface for actively fetching market data. ### Method GET ### Endpoint /api/get_market_data ### Parameters #### Query Parameters - **field_list** (list) - Optional - A list of data fields to retrieve. If empty, all fields are returned. - **stock_list** (list) - Optional - A list of instrument codes. - **period** (str) - Optional - The data period. Examples: '1m', '5m', '1d', 'tick'. Defaults to '1d'. - **start_time** (str) - Optional - The start time for the data retrieval. - **end_time** (str) - Optional - The end time for the data retrieval. - **count** (int) - Optional - The number of data points to retrieve. If >= 0 and `start_time` is specified, retrieves `count` bars ending at `end_time`. If `start_time` and `end_time` are omitted, retrieves the latest `count` data points. If `start_time`, `end_time`, and `count` are all omitted, retrieves all local data. - **dividend_type** (str) - Optional - The dividend adjustment type. Defaults to 'none'. - **fill_data** (bool) - Optional - Whether to fill missing data points forward. Defaults to `True`. ### Response #### Success Response (200) - **For K-line periods ('1m', '5m', '1d', etc.):** - Returns a dictionary where keys are field names (e.g., 'open', 'high', 'low', 'close', 'volume') and values are pandas DataFrames. Each DataFrame has `stock_list` as index and `time_list` as columns. All returned DataFrames share the same dimensions and index. - **For tick period ('tick'):** - Returns a dictionary where keys are instrument codes (e.g., '600000.SH') and values are NumPy ndarrays. Each ndarray contains data points sorted by timestamp. #### Response Example (K-line data) ```json { "open": { "600000.SH": [10.5, 10.6, 10.7], "000300.SH": [3000.0, 3010.0, 3020.0] }, "close": { "600000.SH": [10.6, 10.7, 10.8], "000300.SH": [3010.0, 3020.0, 3030.0] } } ``` #### Response Example (Tick data) ```json { "600000.SH": [ {"time": 1678886400, "price": 10.55, "volume": 100}, {"time": 1678886406, "price": 10.56, "volume": 150} ], "000300.SH": [ {"time": 1678886400, "price": 3005.0, "volume": 500}, {"time": 1678886406, "price": 3006.0, "volume": 600} ] } ``` ### Remarks - Accessing Level 2 data requires appropriate permissions. - The time range specified is inclusive. ``` -------------------------------- ### Download Index Weight Source: https://dict.thinktrader.net/nativeApi/xtdata.html Synchronously downloads index component weight information. ```python download_index_weight() ``` -------------------------------- ### download_index_weight Source: https://dict.thinktrader.net/nativeApi/xtdata.html Synchronously downloads the latest index component weight information. ```APIDOC ## download_index_weight ### Description Synchronously downloads index component weight data. The function returns once the download is complete. ### Parameters None ### Response None ``` -------------------------------- ### Download Holiday Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Downloads the latest holiday data. ```python download_holiday_data() ``` -------------------------------- ### Manage ETF Information Source: https://dict.thinktrader.net/nativeApi/xtdata.html Functions to download and retrieve ETF subscription and redemption list information. ```python download_etf_info() ``` ```python get_etf_info() ``` -------------------------------- ### Download Financial Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Functions to download financial data for specified stocks and tables. download_financial_data2 supports time range filtering and progress callbacks. ```python download_financial_data(stock_list, table_list=[]) ``` ```python download_financial_data2(stock_list, table_list=[], start_time='', end_time='', callback=None) ``` ```python def on_progress(data): print(data) # {'finished': 1, 'total': 50, 'stockcode': '000001.SZ', 'message': ''} ``` -------------------------------- ### Manage Market Sectors Source: https://dict.thinktrader.net/nativeApi/xtdata.html Functions for retrieving, creating, and modifying market sector data and custom sector folders. ```python get_sector_list() ``` ```python get_stock_list_in_sector(sector_name) ``` ```python download_sector_data() ``` ```python create_sector_folder(parent_node, folder_name, overwrite) ``` ```python create_sector(parent_node, sector_name, overwrite) ``` ```python add_sector(sector_name, stock_list) ``` ```python remove_stock_from_sector(sector_name, stock_list) ``` ```python remove_sector(sector_name) ``` -------------------------------- ### Manage Convertible Bond Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Functions to download and retrieve base information for convertible bonds. ```python download_cb_data() ``` ```python get_cb_info(stockcode) ``` -------------------------------- ### Financial Data Download Source: https://dict.thinktrader.net/nativeApi/xtdata.html Functions to download financial data for specified stocks and tables. ```APIDOC ## POST /api/download_financial_data ### Description Downloads financial data for a list of stocks and specified table types. ### Method POST ### Endpoint /api/download_financial_data ### Parameters #### Request Body - **stock_list** (list) - Required - List of stock codes. - **table_list** (list) - Optional - List of financial data table names. Defaults to an empty list. ### Request Example ```json { "stock_list": ["000001.SZ", "600000.SH"], "table_list": ["income_statement", "balance_sheet"] } ``` ### Response #### Success Response (200) - **None** - The function does not return any value upon successful completion. ### Notes Synchronous execution; returns after data fetching is complete. ``` ```APIDOC ## POST /api/download_financial_data2 ### Description Downloads financial data with options for time range and a callback function for progress updates. ### Method POST ### Endpoint /api/download_financial_data2 ### Parameters #### Request Body - **stock_list** (list) - Required - List of stock codes. - **table_list** (list) - Optional - List of financial data table names. Defaults to an empty list. - **start_time** (string) - Optional - Start time for filtering data (YYYY-MM-DD). - **end_time** (string) - Optional - End time for filtering data (YYYY-MM-DD). - **callback** (func) - Optional - Callback function to receive progress updates. - **data** (dict) - Progress information: - **total** (int) - Total number of items to download. - **finished** (int) - Number of items finished. - **stockcode** (string) - The stock code that just finished downloading. - **message** (string) - Additional message for the current update. ### Request Example ```json { "stock_list": ["000001.SZ"], "table_list": ["income_statement"], "start_time": "2023-01-01", "end_time": "2023-12-31" } ``` ### Callback Function Example ```python def on_progress(data): print(data) # Example: {'finished': 1, 'total': 50, 'stockcode': '000001.SZ', 'message': ''} ``` ### Response #### Success Response (200) - **None** - The function does not return any value upon successful completion. ### Notes Synchronous execution; returns after data fetching is complete. ``` -------------------------------- ### Retrieve Local Market Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Fetches historical level-1 market data directly from local files. Useful for batch processing. ```python get_local_data(field_list=[], stock_list=[], period='1d', start_time='', end_time='', count=-1, dividend_type='none', fill_data=True, data_dir=data_dir) ``` -------------------------------- ### Sector Management Source: https://dict.thinktrader.net/nativeApi/xtdata.html Functions for creating, managing, and removing sectors and their components. ```APIDOC ## POST /api/create_sector_folder ### Description Creates a new folder node within the sector directory structure. ### Method POST ### Endpoint /api/create_sector_folder ### Parameters #### Request Body - **parent_node** (string) - Required - The parent node name. Use ' ' for the root 'My' directory. - **folder_name** (string) - Required - The name of the folder to create. - **overwrite** (bool) - Optional - If True, skips creation if the folder exists. If False, appends a number to the name to ensure uniqueness. Defaults to True. ### Request Example ```json { "parent_node": "", "folder_name": "MyNewFolder", "overwrite": false } ``` ### Response #### Success Response (200) - **folder_name2** (string) - The actual name of the created folder. ### Notes None. ``` ```APIDOC ## POST /api/create_sector ### Description Creates a new sector. ### Method POST ### Endpoint /api/create_sector ### Parameters #### Request Body - **parent_node** (string) - Required - The parent node name. Use ' ' for the root 'My' directory. - **sector_name** (string) - Required - The name of the sector to create. - **overwrite** (bool) - Optional - If True, skips creation if the sector exists. If False, appends a number to the name to ensure uniqueness. Defaults to True. ### Request Example ```json { "parent_node": "", "sector_name": "MySector", "overwrite": false } ``` ### Response #### Success Response (200) - **sector_name2** (string) - The actual name of the created sector. ### Notes None. ``` ```APIDOC ## POST /api/add_sector ### Description Adds a custom sector with a list of component stocks. ### Method POST ### Endpoint /api/add_sector ### Parameters #### Request Body - **sector_name** (string) - Required - The name of the custom sector. - **stock_list** (list) - Required - A list of stock codes to include in the sector. ### Request Example ```json { "sector_name": "MyCustomSector", "stock_list": ["000001.SZ", "600000.SH"] } ``` ### Response #### Success Response (200) - **None** - The function does not return any value upon successful completion. ### Notes None. ``` ```APIDOC ## POST /api/remove_stock_from_sector ### Description Removes specified stocks from a sector. ### Method POST ### Endpoint /api/remove_stock_from_sector ### Parameters #### Request Body - **sector_name** (string) - Required - The name of the sector. - **stock_list** (list) - Required - A list of stock codes to remove from the sector. ### Request Example ```json { "sector_name": "MySector", "stock_list": ["000001.SZ"] } ``` ### Response #### Success Response (200) - **result** (bool) - True if the operation was successful, False otherwise. ### Notes None. ``` ```APIDOC ## POST /api/remove_sector ### Description Removes a custom sector. ### Method POST ### Endpoint /api/remove_sector ### Parameters #### Request Body - **sector_name** (string) - Required - The name of the sector to remove. ### Request Example ```json { "sector_name": "MyCustomSector" } ``` ### Response #### Success Response (200) - **None** - The function does not return any value upon successful completion. ### Notes None. ``` -------------------------------- ### Download Expired Contract Information Source: https://dict.thinktrader.net/nativeApi/xtdata.html Downloads information for delisted or expired contracts. ```python download_history_contracts() ``` -------------------------------- ### Download Historical Market Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Downloads historical market data for a single stock or a batch of stocks. Batch downloads support a callback function to track progress. ```python download_history_data(stock_code, period, start_time='', end_time='', incrementally = None) ``` ```python download_history_data2(stock_list, period, start_time='', end_time='', callback=None,incrementally = None) ``` ```python def on_progress(data): print(data) # {'finished': 1, 'total': 50, 'stockcode': '000001.SZ', 'message': ''} ``` -------------------------------- ### Generate Index Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Generate and save factor data files in feather format locally. Requires connection to the research terminal. ```APIDOC ## POST /api/generate_index_data ### Description Generates factor data files locally in feather format. This function requires a connection to the research terminal, and the `formula_name` must exist within it. ### Method POST ### Endpoint /api/generate_index_data ### Parameters #### Request Body - **formula_name** (str) - Required - The name of the model. - **formula_param** (dict) - Optional - Parameters for the model, e.g., `{"param1": 1.0, "param2": "sym"}`. - **stock_list** (list) - Optional - A list of stock codes. - **period** (str) - Optional - The data period. Options: '1m', '5m', '1d'. Defaults to '1d'. - **dividend_type** (str) - Optional - The dividend adjustment type. Options: 'none', 'front_ratio', 'back_ratio'. Defaults to 'none'. - **start_time** (str) - Optional - The start time in 'YYYYMMDD' or 'YYYYMMDDHHMMSS' format. - **end_time** (str) - Optional - The end time in 'YYYYMMDD' or 'YYYYMMDDHHMMSS' format. - **fill_mode** (str) - Optional - The method for filling missing data. Options: 'fixed', 'forward'. Defaults to 'fixed'. - **fill_value** (float) - Optional - The value used for filling missing data. Defaults to `float('nan')`. - **result_path** (str) - Optional - The path to save the resulting feather file. ### Request Example ```json { "formula_name": "MyFactorModel", "formula_param": {"lookback": 20}, "stock_list": ["600000.SH", "000300.SH"], "period": "1d", "start_time": "20230101", "end_time": "20231231", "result_path": "/path/to/save/factor_data.feather" } ``` ### Response #### Success Response (200) - **None** - This endpoint does not return any data upon successful execution. #### Response Example (No response body for success) ``` -------------------------------- ### Generate Factor Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Generates factor data files in feather format locally. Requires a connection to the research terminal. ```python generate_index_data(formula_name, formula_param = {}, stock_list = [], period = '1d', dividend_type = 'none', start_time = '', end_time = '', fill_mode = 'fixed', fill_value = float('nan'), result_path = None) ``` -------------------------------- ### POST /download_history_data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Downloads historical market data for a single contract or a list of contracts. ```APIDOC ## POST /download_history_data ### Description Synchronously downloads historical market data for a contract. Supports incremental downloads. ### Method POST ### Parameters #### Request Body - **stock_code** (string) - Required - Contract code - **period** (string) - Required - Data period - **start_time** (string) - Optional - Start time - **end_time** (string) - Optional - End time - **incrementally** (bool/None) - Optional - Whether to perform incremental download ``` -------------------------------- ### Subscribe to Single-Stock Market Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Subscribes to real-time data for a specific stock. The callback function receives data updates in a dictionary format. ```python subscribe_quote(stock_code, period='1d', start_time='', end_time='', count=0, callback=None) ``` ```python def on_data(datas): for stock_code in datas: print(stock_code, datas[stock_code]) ``` -------------------------------- ### Batch Model Execution Source: https://dict.thinktrader.net/nativeApi/xtdata.html Execute multiple VBA models in batch and retrieve their results. Ensure local K-line or tick data is available before use. ```APIDOC ## POST /api/call_formula_batch ### Description Batch execution of VBA models to retrieve results. It's recommended to supplement local K-line or tick data beforehand. ### Method POST ### Endpoint /api/call_formula_batch ### Parameters #### Request Body - **formula_names** (list) - Required - A list of model names to be executed in batch. - **stock_codes** (list) - Required - A list of main chart codes for the models, e.g., '000300.SH'. - **period** (str) - Required - The K-line period type. Options: 'tick', '1d', '1m', '3m', '5m', '15m', '30m', '1h', '1w', '1mon', '1q', '1hy', '1y'. - **start_time** (str) - Optional - The start time for model execution, format 'YYYYMMDD'. Defaults to the earliest available data. - **end_time** (str) - Optional - The end time for model execution, format 'YYYYMMDD'. Defaults to the latest available data. - **count** (int) - Optional - The number of bars to run the model backward from the end time. Defaults to -1 (all bars). - **dividend_type** (str) - Optional - The dividend adjustment type. Options: 'none', 'front', 'back', 'front_ratio', 'back_ratio'. Defaults to the main chart's dividend type. - **extend_params** (list) - Optional - A list of parameters for each model, e.g., [{'ModelName:ParamName': ParamValue}]. Can include '__basket' for stock pool weights or nested model parameter adjustments. ### Request Example ```json { "formula_names": ["MA"], "stock_codes": ["600000.SH"], "period": "1d", "start_time": "20200101", "end_time": "20201231", "extend_params": [{"MA:n1": 10}] } ``` ### Response #### Success Response (200) - **result** (list[dict]) - A list of dictionaries, where each dictionary contains: - **formula** (str): The model name. - **stock** (str): The instrument code. - **argument** (dict): The parameters used for the model run. - **result** (dict): The result of the model execution, similar to `call_formula` output. #### Response Example ```json [ { "formula": "MA", "stock": "600000.SH", "argument": {"MA:n1": 10}, "result": {"time": [20200101, 20200102], "MA": [10.5, 10.6]} } ] ``` ``` -------------------------------- ### Ex-Rights Data Fields Source: https://dict.thinktrader.net/nativeApi/xtdata.html Field definitions for ex-rights and ex-dividend data. ```text 'interest' #每股股利(税前,元) 'stockBonus' #每股红股(股) 'stockGift' #每股转增股本(股) 'allotNum' #每股配股数(股) 'allotPrice' #配股价格(元) 'gugai' #是否股改, 对于股改,在算复权系数时,系统有特殊算法 'dr' #除权系数 ``` -------------------------------- ### Subscribe to Full-Market Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Subscribes to tick data for an entire market or a list of specific contracts. The callback receives a dictionary mapping stock codes to their respective data. ```python subscribe_whole_quote(code_list, callback=None) ``` ```python def on_data(datas): for stock_code in datas: print(stock_code, datas[stock_code]) ``` -------------------------------- ### Retrieve Market Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Primary interface for fetching market data from cache. Time ranges are treated as closed intervals. ```python get_market_data(field_list=[], stock_list=[], period='1d', start_time='', end_time='', count=-1, dividend_type='none', fill_data=True) ``` -------------------------------- ### Batch Model Execution Source: https://dict.thinktrader.net/nativeApi/xtdata.html Executes multiple VBA models and retrieves results. Ensure local K-line or tick data is available before calling. ```python call_formula_batch(formula_names,stock_codes,period,start_time="",end_time="",count=-1,dividend_type="none",extend_params=[]) ``` -------------------------------- ### Level 2 Quote Fields Source: https://dict.thinktrader.net/nativeApi/xtdata.html Field definitions for Level 2 real-time market snapshots. ```text 'time' #时间戳 'lastPrice' #最新价 'open' #开盘价 'high' #最高价 'low' #最低价 'amount' #成交额 'volume' #成交总量 'pvolume' #原始成交总量 'openInt' #持仓量 'stockStatus' #证券状态 'transactionNum' #成交笔数 'lastClose' #前收盘价 'lastSettlementPrice' #前结算 'settlementPrice' #今结算 'pe' #市盈率 'askPrice' #多档委卖价 'bidPrice' #多档委买价 'askVol' #多档委卖量 'bidVol' #多档委买量 ``` -------------------------------- ### Trading Dates and Market Data Source: https://dict.thinktrader.net/nativeApi/xtdata.html Functions to retrieve trading dates, sector lists, and component stocks. ```APIDOC ## GET /api/get_trading_dates ### Description Retrieves a list of trading dates for a specified market within a given time range. ### Method GET ### Endpoint /api/get_trading_dates ### Parameters #### Query Parameters - **market** (string) - Required - The market code. - **start_time** (string) - Optional - Start date (YYYY-MM-DD). - **end_time** (string) - Optional - End date (YYYY-MM-DD). - **count** (int) - Optional - The number of trading dates to retrieve. Defaults to -1 (all). ### Response #### Success Response (200) - **list** - A list of timestamps representing trading dates. ### Notes None. ``` ```APIDOC ## GET /api/get_sector_list ### Description Retrieves a list of available sector names. ### Method GET ### Endpoint /api/get_sector_list ### Parameters #### Query Parameters None ### Response #### Success Response (200) - **list** - A list of sector names. ### Notes Requires sector classification information to be downloaded first. ``` ```APIDOC ## GET /api/get_stock_list_in_sector ### Description Retrieves a list of stock codes that belong to a specified sector. ### Method GET ### Endpoint /api/get_stock_list_in_sector ### Parameters #### Query Parameters - **sector_name** (string) - Required - The name of the sector. ### Response #### Success Response (200) - **list** - A list of stock codes belonging to the sector. ### Notes Requires sector classification information to be downloaded. ``` ```APIDOC ## POST /api/download_sector_data ### Description Downloads sector classification information. ### Method POST ### Endpoint /api/download_sector_data ### Parameters #### Request Body None ### Response #### Success Response (200) - **None** - The function does not return any value upon successful completion. ### Notes Synchronous execution; returns after sector data download is complete. ``` -------------------------------- ### Order Type Codes Source: https://dict.thinktrader.net/nativeApi/xtdata.html Codes for different order types. ```text 0 - 未知 1 - 正常交易业务 2 - 即时成交剩余撤销 3 - ETF基金申报 4 - 最优五档即时成交剩余撤销 5 - 全额成交或撤销 6 - 本方最优价格 7 - 对手方最优价格 ``` -------------------------------- ### Financial Statement Data Fields Source: https://dict.thinktrader.net/nativeApi/xtdata.html This documentation outlines the available fields for Balance Sheet and Income Statement data points. ```APIDOC ## Financial Statement Data Fields ### Description Provides a list of available fields for Balance Sheet and Income Statement reporting. ### Balance Sheet Fields - **grants_received** - 专项应付款 - **deferred_tax_liab** - 递延所得税负债 - **other_non_current_liabilities** - 其他非流动负债 - **non_current_liabilities** - 非流动负债合计 - **tot_liab** - 负债合计 - **cap_stk** - 实收资本(或股本) - **cap_rsrv** - 资本公积 - **specific_reserves** - 专项储备 - **surplus_rsrv** - 盈余公积 - **prov_nom_risks** - 一般风险准备 - **undistributed_profit** - 未分配利润 - **cnvd_diff_foreign_curr_stat** - 外币报表折算差额 - **tot_shrhldr_eqy_excl_min_int** - 归属于母公司股东权益合计 - **minority_int** - 少数股东权益 - **total_equity** - 所有者权益合计 - **tot_liab_shrhldr_eqy** - 负债和股东权益总计 ### Income Statement Fields - **m_anntime** - 披露日期 - **m_timetag** - 截止日期 - **revenue_inc** - 营业收入 - **earned_premium** - 已赚保费 - **real_estate_sales_income** - 房地产销售收入 - **total_operating_cost** - 营业总成本 - **real_estate_sales_cost** - 房地产销售成本 - **research_expenses** - 研发费用 - **surrender_value** - 退保金 - **net_payments** - 赔付支出净额 - **net_withdrawal_ins_con_res** - 提取保险合同准备金净额 - **policy_dividend_expenses** - 保单红利支出 - **reinsurance_cost** - 分保费用 - **change_income_fair_value** - 公允价值变动收益 - **futures_loss** - 期货损益 - **trust_income** - 托管收益 - **subsidize_revenue** - 补贴收入 - **other_business_profits** - 其他业务利润 - **net_profit_excl_merged_int_inc** - 被合并方在合并前实现净利润 - **int_inc** - 利息收入 - **handling_chrg_comm_inc** - 手续费及佣金收入 - **less_handling_chrg_comm_exp** - 手续费及佣金支出 - **other_bus_cost** - 其他业务成本 - **plus_net_gain_fx_trans** - 汇兑收益 - **il_net_loss_disp_noncur_asset** - 非流动资产处置收益 - **inc_tax** - 所得税费用 - **unconfirmed_invest_loss** - 未确认投资损失 - **net_profit_excl_min_int_inc** - 归属于母公司所有者的净利润 - **less_int_exp** - 利息支出 - **other_bus_inc** - 其他业务收入 - **revenue** - 营业总收入 - **total_expense** - 营业成本 - **less_taxes_surcharges_ops** - 营业税金及附加 - **sale_expense** - 销售费用 - **less_gerl_admin_exp** - 管理费用 - **financial_expense** - 财务费用 - **less_impair_loss_assets** - 资产减值损失 - **plus_net_invest_inc** - 投资收益 - **incl_inc_invest_assoc_jv_entp** - 联营企业和合营企业的投资收益 - **oper_profit** - 营业利润 - **plus_non_oper_rev** - 营业外收入 - **less_non_oper_exp** - 营业外支出 - **tot_profit** - 利润总额 - **net_profit_incl_min_int_inc** - 净利润 - **net_profit_incl_min_int_inc_after** - 净利润(扣除非经常性损益后) - **minority_int_inc** - 少数股东损益 - **s_fa_eps_basic** - 基本每股收益 - **s_fa_eps_diluted** - 稀释每股收益 - **total_income** - 综合收益总额 - **total_income_minority** - 归属于少数股东的综合收益总额 - **other_compreh_inc** - 其他收益 ``` -------------------------------- ### subscribe_whole_quote Source: https://dict.thinktrader.net/nativeApi/xtdata.html Subscribes to whole-market tick data. ```APIDOC ## subscribe_whole_quote ### Description Subscribes to whole-market tick data. Efficient for high-subscription scenarios. ### Parameters - **code_list** (list) - Required - List of market codes (e.g., ['SH', 'SZ']) or contract codes (e.g., ['600000.SH']) - **callback** (function) - Required - Callback function `on_data(datas)` where `datas` is `{ stock1 : data1, stock2 : data2, ... }` ### Response - **int** - Subscription ID (greater than 0 for success, -1 for failure) ``` -------------------------------- ### Capital Structure Source: https://dict.thinktrader.net/nativeApi/xtdata.html Definitions for equity capital and share distribution data. ```APIDOC ## Capital Data Fields ### Description Provides details regarding the company's total capital and circulating share structure. ### Fields - **total_capital** (string) - 总股本 - **circulating_capital** (string) - 已上市流通A股 - **restrict_circulating_capital** (string) - 限售流通股份 - **m_timetag** (string) - 报告截止日 - **m_anntime** (string) - 公告日 ``` -------------------------------- ### Level 2 Order Queue Fields Source: https://dict.thinktrader.net/nativeApi/xtdata.html Field definitions for Level 2 order queue data. ```text 'time' #时间戳 'bidLevelPrice' #委买价 'bidLevelVolume' #委买量 'offerLevelPrice' #委卖价 'offerLevelVolume' #委卖量 'bidLevelNumber' #委买数量 'offLevelNumber' #委卖数量 ```