akshare
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAKShare 金融数据获取
AKShare Financial Data Retrieval
任务目标
Task Objectives
- 本 Skill 用于:通过 AKShare 接口获取全品类金融市场数据
- 能力包含:股票、期货、期权、基金、外汇、债券、指数、加密货币、宏观经济等数据
- 触发条件:用户提及 AKShare 或需要获取各类金融数据时
- This Skill is used to: Retrieve full-category financial market data via AKShare interfaces
- Capabilities include: Data of stocks, futures, options, funds, foreign exchange, bonds, indices, cryptocurrencies, macroeconomics, etc.
- Trigger conditions: When users mention AKShare or need to obtain various financial data
前置准备
Preparations
- 依赖说明:安装 akshare 库(已包含在 dependency 中)
- 凭证配置:AKShare 无需注册或 API Key,直接调用即可使用
- 环境要求:Python 3.9+,建议定期更新
pip install akshare --upgrade
- Dependency Description: Install the akshare library (included in dependencies)
- Credential Configuration: AKShare requires no registration or API Key, it can be used directly by calling
- Environment Requirements: Python 3.9+, it is recommended to update regularly with
pip install akshare --upgrade
操作步骤
Operation Steps
- 标准流程:
- 确定数据需求 — 智能体理解用户意图(股票/期货/基金/外汇等)
- 调用对应脚本 — 根据数据类型选择脚本
- 解析结果 — 智能体分析返回的 JSON 格式数据
- 脚本调用映射:
- 股票数据 →
python scripts/stock_data.py --type hist --symbol 000001 --start 20240101 --end 20240131 - 期货数据 →
python scripts/futures_data.py --type daily --exchange CFFEX --start 20240101 --end 20240131 - 基金数据 →
python scripts/fund_data.py --type etf --symbol 510300 - 外汇数据 →
python scripts/forex_data.py --type spot --symbol usd - 宏观经济 →
python scripts/macro_data.py --type gdp - 加密货币 →
python scripts/crypto_data.py --type price --symbol BTC/USDT
- 股票数据 →
- 可选分支:
- 当需要多只标的:使用逗号分隔多个代码
- 当需要指定周期:使用 参数(daily/weekly/monthly)
--period - 当需要复权数据:使用 参数(qfq/hfq/空值)
--adjust
- Standard Process:
- Confirm Data Requirements — Agent understands user intent (stocks/futures/funds/foreign exchange, etc.)
- Call Corresponding Script — Select the script according to data type
- Parse Results — 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 - Foreign Exchange Data →
python scripts/forex_data.py --type spot --symbol usd - Macroeconomic Data →
python scripts/macro_data.py --type gdp - Cryptocurrency Data →
python scripts/crypto_data.py --type price --symbol BTC/USDT
- Stock Data →
- Optional Branches:
- When multiple targets are needed: Use commas to separate multiple codes
- When specifying a period: Use the parameter (daily/weekly/monthly)
--period - When needing adjusted data: Use the parameter (qfq/hfq/empty value)
--adjust
使用示例
Usage Examples
- 示例1:获取股票历史K线
- 场景/输入:用户说"获取贵州茅台2024年的日K线数据"
- 预期产出:返回日期、开盘价、最高价、最低价、收盘价、成交量等OHLCV数据
- 关键要点:调用
python scripts/stock_data.py --type hist --symbol 600519 --start 20240101 --end 20241231 --period daily --adjust qfq
- 示例2:获取期货数据
- 场景/输入:用户说"查看沪深300股指期货数据"
- 预期产出:返回期货合约的K线数据、持仓量、成交量等信息
- 关键要点:调用
python scripts/futures_data.py --type daily --symbol IF2406 --start 20240101 --end 20240131
- 示例3:获取基金数据
- 场景/输入:用户说"查询沪深300ETF的行情"
- 预期产出:返回ETF的实时行情或历史净值数据
- 关键要点:调用
python scripts/fund_data.py --type etf --symbol 510300
- 示例4:获取宏观经济数据
- 场景/输入:用户说"查看中国GDP数据"
- 预期产出:返回GDP历史数据和最新值
- 关键要点:调用
python scripts/macro_data.py --type gdp
- Example 1: Retrieve Stock Historical K-line
- Scenario/Input: User says: "Get the daily K-line data of Kweichow Moutai in 2024"
- Expected Output: Returns OHLCV data such as date, opening price, highest price, lowest price, closing price, trading volume, etc.
- Key Points: Call
python scripts/stock_data.py --type hist --symbol 600519 --start 20240101 --end 20241231 --period daily --adjust qfq
- Example 2: Retrieve Futures Data
- Scenario/Input: User says: "Check the CSI 300 stock index futures data"
- Expected Output: Returns K-line data, open interest, trading volume and other information of futures contracts
- Key Points: Call
python scripts/futures_data.py --type daily --symbol IF2406 --start 20240101 --end 20240131
- Example 3: Retrieve Fund Data
- Scenario/Input: User says: "Query the market of CSI 300 ETF"
- Expected Output: Returns real-time market or historical net value data of the ETF
- Key Points: Call
python scripts/fund_data.py --type etf --symbol 510300
- Example 4: Retrieve Macroeconomic Data
- Scenario/Input: User says: "Check China's GDP data"
- Expected Output: Returns historical GDP data and the latest value
- Key Points: Call
python scripts/macro_data.py --type gdp
数据分类详解
Detailed Data Classification
股票数据(A股/港股/美股)
Stock Data (A-shares/Hong Kong Stocks/US Stocks)
- 实时行情:- 全部A股实时行情
ak.stock_zh_a_spot_em() - 历史K线:
ak.stock_zh_a_hist(symbol, period, start_date, end_date, adjust) - 分钟K线:
ak.stock_zh_a_hist_min_em(symbol, period, start_date, end_date) - 个股信息:- 基本信息、市值、行业等
ak.stock_individual_info_em(symbol) - 财务数据:- 基本面数据
ak.stock_fundamental(symbol) - 估值指标:- PE、PB等
ak.stock_valuation(symbol) - 港股数据:,
ak.stock_hk_spot_em()ak.stock_hk_hist() - 美股数据:,
ak.stock_us_daily(symbol)ak.stock_us_spot_em()
- Real-time Market: - Real-time market of all A-shares
ak.stock_zh_a_spot_em() - Historical K-line:
ak.stock_zh_a_hist(symbol, period, start_date, end_date, adjust) - Minute K-line:
ak.stock_zh_a_hist_min_em(symbol, period, start_date, end_date) - Individual Stock Information: - Basic information, market value, industry, etc.
ak.stock_individual_info_em(symbol) - Financial Data: - Fundamental data
ak.stock_fundamental(symbol) - Valuation Indicators: - PE, PB, etc.
ak.stock_valuation(symbol) - Hong Kong Stocks Data: ,
ak.stock_hk_spot_em()ak.stock_hk_hist() - US Stocks Data: ,
ak.stock_us_daily(symbol)ak.stock_us_spot_em()
期货数据
Futures Data
- 期货行情:- 实时行情
ak.futures_zh_spot() - 期货K线:- 按交易所
get_futures_daily(start_date, end_date, market) - 库存数据:- 期货库存
ak.futures_inventory_99(symbol)
- Futures Market: - Real-time market
ak.futures_zh_spot() - Futures K-line: - By exchange
get_futures_daily(start_date, end_date, market) - Inventory Data: - Futures inventory
ak.futures_inventory_99(symbol)
基金数据
Fund Data
- ETF行情:- ETF实时行情
ak.fund_etf_spot_em() - ETF历史:
ak.fund_etf_hist_em(symbol, period, start_date, end_date, adjust) - 开放式基金:- 每日净值
ak.fund_open_fund_daily_em(symbol) - 基金评级:- 基金评级信息
ak.fund_rating_all()
- ETF Market: - Real-time ETF market
ak.fund_etf_spot_em() - ETF History:
ak.fund_etf_hist_em(symbol, period, start_date, end_date, adjust) - Open-end Funds: - Daily net value
ak.fund_open_fund_daily_em(symbol) - Fund Ratings: - Fund rating information
ak.fund_rating_all()
期权数据
Options Data
- 期权历史:- 交易所期权数据
ak.option_hist_dce(symbol) - ETF期权:- 上证50ETF期权
ak.option_sse_spot_price(symbol)
- Options History: - Exchange options data
ak.option_hist_dce(symbol) - ETF Options: - SSE 50 ETF options
ak.option_sse_spot_price(symbol)
债券数据
Bond Data
- 可转债:- 可转债列表
ak.bond_zh_cov() - 可转债K线:- 可转债历史数据
ak.bond_zh_hs_cov_daily(symbol) - 债券报价:- 中国债券现货报价
ak.bond_spot_quote()
- Convertible Bonds: - List of convertible bonds
ak.bond_zh_cov() - Convertible Bond K-line: - Historical data of convertible bonds
ak.bond_zh_hs_cov_daily(symbol) - Bond Quotes: - Spot quotes of Chinese bonds
ak.bond_spot_quote()
外汇贵金属
Foreign Exchange and Precious Metals
- 外汇行情:- 外汇实时行情
ak.forex_spot_em() - 汇率数据:- 美元兑人民币
ak.forex_usd_cny() - 贵金属:- 国际金价
ak.metals_gold()
- Foreign Exchange Market: - Real-time foreign exchange market
ak.forex_spot_em() - Exchange Rate Data: - USD/CNY exchange rate
ak.forex_usd_cny() - Precious Metals: - International gold price
ak.metals_gold()
指数数据
Index Data
- A股指数:- 指数历史数据
ak.stock_zh_index_daily_em(symbol) - 指数成分:- 指数成分股
ak.index_stock_cons_csindex(symbol)
- A-share Indices: - Historical index data
ak.stock_zh_index_daily_em(symbol) - Index Components: - Index constituent stocks
ak.index_stock_cons_csindex(symbol)
加密货币
Cryptocurrencies
- 币种列表:- 币安交易对
ak.crypto_binance_symbols() - 实时价格:- BTC/USDT价格
ak.crypto_binance_btc_usdt_spot() - K线数据:- 加密货币K线
ak.crypto_binance_btc_usdt_kline(period)
- Currency List: - Binance trading pairs
ak.crypto_binance_symbols() - Real-time Price: - BTC/USDT price
ak.crypto_binance_btc_usdt_spot() - K-line Data: - Cryptocurrency K-line
ak.crypto_binance_btc_usdt_kline(period)
宏观经济
Macroeconomics
- 中国GDP:,
ak.macro_china_gdp()ak.macro_china_gdp_yearly() - CPI数据:,
ak.macro_china_cpi_yearly()ak.macro_china_cpi() - PMI数据:
ak.macro_china_pmi() - 美国数据:,
ak.macro_usa_non_farm()ak.macro_usa_cpi_monthly()
- China's GDP: ,
ak.macro_china_gdp()ak.macro_china_gdp_yearly() - CPI Data: ,
ak.macro_china_cpi_yearly()ak.macro_china_cpi() - PMI Data:
ak.macro_china_pmi() - US Data: ,
ak.macro_usa_non_farm()ak.macro_usa_cpi_monthly()
特色数据
Featured Data
- 龙虎榜:- 龙虎榜详情
ak.stock_lhb_detail_em(start_date, end_date) - 融资融券:- 融资融券数据
ak.stock_margin_sse(start_date, end_date) - 北向资金:- 陆港通数据
ak.stock_hsgt_hist_em(symbol) - 股东数据:- 前十大股东
ak.stock_gdfx_top_10_em(symbol, date) - 板块行情:- 行业板块
ak.stock_board_industry_name_em() - 限售解禁:- 限售解禁
ak.stock_restricted_release_queue_em(symbol) - 资金流向:- 市场资金流向
ak.stock_market_fund_flow()
- Dragon and Tiger List: - Details of Dragon and Tiger List
ak.stock_lhb_detail_em(start_date, end_date) - Margin Trading: - Margin trading data
ak.stock_margin_sse(start_date, end_date) - Northbound Capital: - Stock Connect data
ak.stock_hsgt_hist_em(symbol) - Shareholder Data: - Top 10 shareholders
ak.stock_gdfx_top_10_em(symbol, date) - Sector Market: - Industry sectors
ak.stock_board_industry_name_em() - Restricted Stock Unlocking: - Restricted stock unlocking queue
ak.stock_restricted_release_queue_em(symbol) - Capital Flow: - Market capital flow
ak.stock_market_fund_flow()
资源索引
Resource Index
脚本:
Scripts:
- scripts/stock_data.py(用途与参数:获取股票K线/行情/财务数据,支持 --type/--symbol/--start/--end/--period/--adjust)
- scripts/futures_data.py(用途与参数:获取期货数据,支持 --type/--symbol/--exchange/--start/--end)
- scripts/fund_data.py(用途与参数:获取基金数据,支持 --type/--symbol/--start/--end)
- scripts/forex_data.py(用途与参数:获取外汇贵金属数据,支持 --type/--symbol)
- scripts/macro_data.py(用途与参数:获取宏观经济数据,支持 --type)
- scripts/crypto_data.py(用途与参数:获取加密货币数据,支持 --type/--symbol/--period)
- scripts/index_data.py(用途与参数:获取指数数据,支持 --type/--symbol/--start/--end)
- scripts/option_data.py(用途与参数:获取期权数据,支持 --type/--symbol)
- scripts/bond_data.py(用途与参数:获取债券数据,支持 --type/--symbol)
- scripts/special_data.py(用途与参数:获取龙虎榜/融资融券/北向资金等特色数据,支持 --type/--symbol/--start/--end)
- scripts/stock_data.py (Purpose & Parameters: Retrieve stock K-line/market/financial data, supports --type/--symbol/--start/--end/--period/--adjust)
- scripts/futures_data.py (Purpose & Parameters: Retrieve futures data, supports --type/--symbol/--exchange/--start/--end)
- scripts/fund_data.py (Purpose & Parameters: Retrieve fund data, supports --type/--symbol/--start/--end)
- scripts/forex_data.py (Purpose & Parameters: Retrieve foreign exchange and precious metals data, supports --type/--symbol)
- scripts/macro_data.py (Purpose & Parameters: Retrieve macroeconomic data, supports --type)
- scripts/crypto_data.py (Purpose & Parameters: Retrieve cryptocurrency data, supports --type/--symbol/--period)
- scripts/index_data.py (Purpose & Parameters: Retrieve index data, supports --type/--symbol/--start/--end)
- scripts/option_data.py (Purpose & Parameters: Retrieve options data, supports --type/--symbol)
- scripts/bond_data.py (Purpose & Parameters: Retrieve bond data, supports --type/--symbol)
- scripts/special_data.py (Purpose & Parameters: Retrieve featured data such as Dragon and Tiger List/margin trading/northbound capital, supports --type/--symbol/--start/--end)
参考文档:
Reference Documents:
- 股票数据文档(何时读取:需要查看股票相关API参数说明时)
- 期货数据文档(何时读取:需要查看期货相关API参数说明时)
- 基金数据文档(何时读取:需要查看基金相关API参数说明时)
- 宏观经济文档(何时读取:需要查看宏观数据API参数说明时)
- AKShare官方文档(何时读取:需要查看最新API文档时)
- Stock Data Documentation (When to read: Need to check parameter descriptions of stock-related APIs)
- Futures Data Documentation (When to read: Need to check parameter descriptions of futures-related APIs)
- Fund Data Documentation (When to read: Need to check parameter descriptions of fund-related APIs)
- Macroeconomic Documentation (When to read: Need to check parameter descriptions of macro data APIs)
- AKShare Official Documentation (When to read: Need to check the latest API documentation)
注意事项
Notes
- AKShare 无需注册或 API Key,直接调用即可使用
- A股股票代码格式:纯数字代码(如 000001、600519),不带市场前缀
- 港股股票代码格式:纯数字代码(如 00700)
- 美股股票代码格式:英文代码(如 AAPL、TSLA)
- 数据列名:A股数据为中文列名,美股/港股数据为英文列名
- 建议定期更新AKShare版本:
pip install akshare --upgrade - 由于上游数据源变化,接口更新频繁,遇到错误时可先尝试更新版本
- 脚本返回 JSON 格式数据,智能体负责解析并转换为用户友好的展示
- 非Python用户可使用 AKTools HTTP API封装
- 数据仅供学术研究使用,不构成投资建议
- AKShare requires no registration or API Key, it can be used directly by calling
- A-share stock code format: Pure numeric code (e.g., 000001, 600519), without 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 AKShare regularly:
pip install akshare --upgrade - Due to changes in upstream data sources, interfaces are updated frequently; try updating the version first when encountering errors
- Scripts return JSON format data, and the Agent is responsible for parsing and converting it into user-friendly display
- Non-Python users can use AKTools HTTP API encapsulation
- The data is for academic research only and does not constitute investment advice
快速参考
Quick Reference
函数命名规则
Function Naming Rules
{asset_type}_{market}_{data_type}_{data_source}- Asset type: (股票),
stock(期货),futures(基金),fund(债券),bond(外汇),forex(期权),option(宏观),macro(指数)index - Market: (中国),
zh(美国),us(香港), 或交易所代码hk - Data type: (实时),
spot(历史),hist(日线),daily(分钟)minute - Data source: (东方财富),
em(新浪财经), 交易所缩写sina
{asset_type}_{market}_{data_type}_{data_source}- Asset type: (stocks),
stock(futures),futures(funds),fund(bonds),bond(foreign exchange),forex(options),option(macroeconomics),macro(indices)index - Market: (China),
zh(US),us(Hong Kong), or exchange codehk - Data type: (real-time),
spot(historical),hist(daily),daily(minute)minute - Data source: (East Money),
em(Sina Finance), exchange abbreviationsina
复权类型
Adjustment Types
- - 不复权
"" - - 前复权
"qfq" - - 后复权
"hfq"
- - No adjustment
"" - - Forward adjustment
"qfq" - - Backward adjustment
"hfq"
周期类型
Period Types
- - 日线
"daily" - - 周线
"weekly" - - 月线
"monthly" - ,
"1","5","15","30"- 分钟线"60"
- - Daily
"daily" - - Weekly
"weekly" - - Monthly
"monthly" - ,
"1","5","15","30"- Minute ","60"