Task Objective
- This Skill is used to: obtain all-category financial market data through the AKShare interface
- Capabilities include: data on stocks, futures, options, funds, forex, bonds, indices, cryptocurrencies, macroeconomics, etc.
- Trigger conditions: when the user mentions AKShare or needs to obtain various types of financial data
Prerequisites
- Dependency description: install the akshare library (already included in dependency)
- Credential configuration: AKShare requires no registration or API Key and can be used directly
- Environment requirements: Python 3.9+, it is recommended to update regularly
pip install akshare --upgrade
Operation Steps
- Standard process:
- Determine data requirements — the agent understands the user's intent (stocks/futures/funds/forex, etc.)
- Call the corresponding script — select the script according to the data type
- Parse the results — the agent analyzes the returned JSON-format data
- Script call mapping:
- Stock data →
python scripts/stock_data.py --type hist --symbol 000001 --start 20240101 --end 20240131 - Futures data →
python scripts/futures_data.py --type daily --exchange CFFEX --start 20240101 --end 20240131 - Fund data →
python scripts/fund_data.py --type etf --symbol 510300 - Forex data →
python scripts/forex_data.py --type spot --symbol usd - Macroeconomics →
python scripts/macro_data.py --type gdp - Cryptocurrencies →
python scripts/crypto_data.py --type price --symbol BTC/USDT
- Stock data →
- Optional branches:
- When multiple instruments are needed: separate multiple codes with commas
- When a period needs to be specified: use the
--periodparameter (daily/weekly/monthly) - When adjusted data is needed: use the
--adjustparameter (qfq/hfq/empty value)
Usage Examples
- Example 1: Obtain stock historical K-line data
- Scenario/Input: the user says "Obtain Guizhou Moutai's daily K-line data for 2024"
- Expected output: return OHLCV data such as date, opening price, highest price, lowest price, closing price, and trading volume
- Key points: call
python scripts/stock_data.py --type hist --symbol 600519 --start 20240101 --end 20241231 --period daily --adjust qfq
- Example 2: Obtain futures data
- Scenario/Input: the user says "View CSI 300 stock index futures data"
- Expected output: return information such as the futures contract's K-line data, open interest, and trading volume
- Key points: call
python scripts/futures_data.py --type daily --symbol IF2406 --start 20240101 --end 20240131
- Example 3: Obtain fund data
- Scenario/Input: the user says "Query the market performance of the CSI 300 ETF"
- Expected output: return the ETF's real-time market performance or historical net value data
- Key points: call
python scripts/fund_data.py --type etf --symbol 510300
- Example 4: Obtain macroeconomic data
- Scenario/Input: the user says "View China's GDP data"
- Expected output: return historical GDP data and the latest value
- Key points: call
python scripts/macro_data.py --type gdp
Detailed Data Classification
For the complete API function list (70+ interfaces, covering stocks/futures/funds/options/bonds/forex/indices/cryptocurrencies/macroeconomics/special data), see references/api-catalog.md。
Quick Index:
- Stocks →
ak.stock_zh_a_hist(),ak.stock_zh_a_spot_em() - Futures →
ak.futures_zh_spot(),ak.get_futures_daily() - Funds →
ak.fund_etf_spot_em(),ak.fund_etf_hist_em() - Macro →
ak.macro_china_gdp(),ak.macro_usa_cpi_monthly() - Special →
ak.stock_lhb_detail_em()(Dragon and Tiger List),ak.stock_hsgt_hist_em()(Northbound capital)
Resource Index
Scripts:
- scripts/stock_data.py(Purpose and parameters: retrieve stock K-line/market/financial data, supports --type/--symbol/--start/--end/--period/--adjust)
- scripts/futures_data.py(Purpose and parameters: retrieve futures data, supports --type/--symbol/--exchange/--start/--end)
- scripts/fund_data.py(Purpose and parameters: retrieve fund data, supports --type/--symbol/--start/--end)
- scripts/forex_data.py(Purpose and parameters: retrieve forex and precious metals data, supports --type/--symbol)
- scripts/macro_data.py(Purpose and parameters: retrieve macroeconomic data, supports --type)
- scripts/crypto_data.py(Purpose and parameters: retrieve cryptocurrency data, supports --type/--symbol/--period)
- scripts/index_data.py(Purpose and parameters: retrieve index data, supports --type/--symbol/--start/--end)
- scripts/option_data.py(Purpose and parameters: retrieve options data, supports --type/--symbol)
- scripts/bond_data.py(Purpose and parameters: retrieve bond data, supports --type/--symbol)
- scripts/special_data.py(Purpose and parameters: retrieve featured data such as the dragon-tiger list/margin trading/northbound capital, supports --type/--symbol/--start/--end)
Reference documentation:
- API Function Quick Reference(When to read: when you need to view the complete list of AKShare API functions)
- Stock Data Documentation(When to read: when you need to view parameter descriptions for stock-related APIs)
- Futures Data Documentation(When to read: when you need to view parameter descriptions for futures-related APIs)
- Fund Data Documentation(When to read: when you need to view parameter descriptions for fund-related APIs)
- Macroeconomic Documentation(When to read: when you need to view parameter descriptions for macroeconomic data APIs)
- AKShare Official Documentation(When to read: when you need to view the latest API documentation)
Notes
- AKShare requires no registration or API Key; it can be used by calling it directly
- A-share stock code format: pure numeric code (e.g., 000001, 600519), without a market prefix
- Hong Kong stock code format: pure numeric code (e.g., 00700)
- US stock code format: English code (e.g., AAPL, TSLA)
- Data column names: A-share data uses Chinese column names, US/Hong Kong stock data uses English column names
- It is recommended to update the AKShare version regularly:
pip install akshare --upgrade - Due to changes in upstream data sources, interfaces are updated frequently; when encountering errors, you can first try updating the version
- The script returns data in JSON format, and the agent is responsible for parsing and converting it into a user-friendly presentation
- Non-Python users can use the AKTools HTTP API wrapper
- The data is for academic research use only and does not constitute investment advice
Quick Reference
Function Naming Rules
{asset_type}_{market}_{data_type}_{data_source}
- Asset type:
stock(stocks),futures(futures),fund(funds),bond(bonds),forex(forex),option(options),macro(macro),index(indices) - Market:
zh(China),us(United States),hk(Hong Kong), or exchange code - Data type:
spot(real-time),hist(historical),daily(daily),minute(minute) - Data source:
em(East Money),sina(Sina Finance), exchange abbreviation
Adjustment Type
""- unadjusted"qfq"- forward-adjusted"hfq"- backward-adjusted
Period Type
"daily"- Daily"weekly"- Weekly"monthly"- Monthly"1","5","15","30","60"- Minute