akshare

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

AKShare 金融数据获取

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

  • 标准流程:
    1. 确定数据需求 — 智能体理解用户意图(股票/期货/基金/外汇等)
    2. 调用对应脚本 — 根据数据类型选择脚本
    3. 解析结果 — 智能体分析返回的 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
  • 可选分支:
    • 当需要多只标的:使用逗号分隔多个代码
    • 当需要指定周期:使用
      --period
      参数(daily/weekly/monthly)
    • 当需要复权数据:使用
      --adjust
      参数(qfq/hfq/空值)
  • Standard Process:
    1. Confirm Data Requirements — Agent understands user intent (stocks/futures/funds/foreign exchange, etc.)
    2. Call Corresponding Script — Select the script according to data type
    3. 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
  • Optional Branches:
    • When multiple targets are needed: Use commas to separate multiple codes
    • When specifying a period: Use the
      --period
      parameter (daily/weekly/monthly)
    • When needing adjusted data: Use the
      --adjust
      parameter (qfq/hfq/empty value)

使用示例

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)

  • 实时行情
    ak.stock_zh_a_spot_em()
    - 全部A股实时行情
  • 历史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)
    - 基本面数据
  • 估值指标
    ak.stock_valuation(symbol)
    - PE、PB等
  • 港股数据
    ak.stock_hk_spot_em()
    ,
    ak.stock_hk_hist()
  • 美股数据
    ak.stock_us_daily(symbol)
    ,
    ak.stock_us_spot_em()
  • Real-time Market:
    ak.stock_zh_a_spot_em()
    - Real-time market of all A-shares
  • 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:
    ak.stock_individual_info_em(symbol)
    - Basic information, market value, industry, etc.
  • Financial Data:
    ak.stock_fundamental(symbol)
    - Fundamental data
  • Valuation Indicators:
    ak.stock_valuation(symbol)
    - PE, PB, etc.
  • 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:
    ak.futures_zh_spot()
    - Real-time market
  • Futures K-line:
    get_futures_daily(start_date, end_date, market)
    - By exchange
  • Inventory Data:
    ak.futures_inventory_99(symbol)
    - Futures inventory

基金数据

Fund Data

  • ETF行情
    ak.fund_etf_spot_em()
    - ETF实时行情
  • 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:
    ak.fund_etf_spot_em()
    - Real-time ETF market
  • ETF History:
    ak.fund_etf_hist_em(symbol, period, start_date, end_date, adjust)
  • Open-end Funds:
    ak.fund_open_fund_daily_em(symbol)
    - Daily net value
  • Fund Ratings:
    ak.fund_rating_all()
    - Fund rating information

期权数据

Options Data

  • 期权历史
    ak.option_hist_dce(symbol)
    - 交易所期权数据
  • ETF期权
    ak.option_sse_spot_price(symbol)
    - 上证50ETF期权
  • Options History:
    ak.option_hist_dce(symbol)
    - Exchange options data
  • ETF Options:
    ak.option_sse_spot_price(symbol)
    - SSE 50 ETF options

债券数据

Bond Data

  • 可转债
    ak.bond_zh_cov()
    - 可转债列表
  • 可转债K线
    ak.bond_zh_hs_cov_daily(symbol)
    - 可转债历史数据
  • 债券报价
    ak.bond_spot_quote()
    - 中国债券现货报价
  • Convertible Bonds:
    ak.bond_zh_cov()
    - List of convertible bonds
  • Convertible Bond K-line:
    ak.bond_zh_hs_cov_daily(symbol)
    - Historical data of convertible bonds
  • Bond Quotes:
    ak.bond_spot_quote()
    - Spot quotes of Chinese bonds

外汇贵金属

Foreign Exchange and Precious Metals

  • 外汇行情
    ak.forex_spot_em()
    - 外汇实时行情
  • 汇率数据
    ak.forex_usd_cny()
    - 美元兑人民币
  • 贵金属
    ak.metals_gold()
    - 国际金价
  • Foreign Exchange Market:
    ak.forex_spot_em()
    - Real-time foreign exchange market
  • Exchange Rate Data:
    ak.forex_usd_cny()
    - USD/CNY exchange rate
  • Precious Metals:
    ak.metals_gold()
    - International gold price

指数数据

Index Data

  • A股指数
    ak.stock_zh_index_daily_em(symbol)
    - 指数历史数据
  • 指数成分
    ak.index_stock_cons_csindex(symbol)
    - 指数成分股
  • A-share Indices:
    ak.stock_zh_index_daily_em(symbol)
    - Historical index data
  • Index Components:
    ak.index_stock_cons_csindex(symbol)
    - Index constituent stocks

加密货币

Cryptocurrencies

  • 币种列表
    ak.crypto_binance_symbols()
    - 币安交易对
  • 实时价格
    ak.crypto_binance_btc_usdt_spot()
    - BTC/USDT价格
  • K线数据
    ak.crypto_binance_btc_usdt_kline(period)
    - 加密货币K线
  • Currency List:
    ak.crypto_binance_symbols()
    - Binance trading pairs
  • Real-time Price:
    ak.crypto_binance_btc_usdt_spot()
    - BTC/USDT price
  • K-line Data:
    ak.crypto_binance_btc_usdt_kline(period)
    - Cryptocurrency K-line

宏观经济

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:
    ak.stock_lhb_detail_em(start_date, end_date)
    - Details of Dragon and Tiger List
  • Margin Trading:
    ak.stock_margin_sse(start_date, end_date)
    - Margin trading data
  • Northbound Capital:
    ak.stock_hsgt_hist_em(symbol)
    - Stock Connect data
  • Shareholder Data:
    ak.stock_gdfx_top_10_em(symbol, date)
    - Top 10 shareholders
  • Sector Market:
    ak.stock_board_industry_name_em()
    - Industry sectors
  • Restricted Stock Unlocking:
    ak.stock_restricted_release_queue_em(symbol)
    - Restricted stock unlocking queue
  • Capital Flow:
    ak.stock_market_fund_flow()
    - Market capital 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:
    stock
    (stocks),
    futures
    (futures),
    fund
    (funds),
    bond
    (bonds),
    forex
    (foreign exchange),
    option
    (options),
    macro
    (macroeconomics),
    index
    (indices)
  • Market:
    zh
    (China),
    us
    (US),
    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 Types

  • ""
    - 不复权
  • "qfq"
    - 前复权
  • "hfq"
    - 后复权
  • ""
    - No adjustment
  • "qfq"
    - Forward adjustment
  • "hfq"
    - Backward adjustment

周期类型

Period Types

  • "daily"
    - 日线
  • "weekly"
    - 周线
  • "monthly"
    - 月线
  • "1"
    ,
    "5"
    ,
    "15"
    ,
    "30"
    ,
    "60"
    - 分钟线
  • "daily"
    - Daily
  • "weekly"
    - Weekly
  • "monthly"
    - Monthly
  • "1"
    ,
    "5"
    ,
    "15"
    ,
    "30"
    ,
    "60"
    - Minute ",