
baostock
BaoStock 免费开源 A 股数据平台,无需注册、无需 API Key,支持股票行情、K线、财务数据、行业分类、指数成分股查询。当用户提及 baostock、需要获取A股历史行情、财务报表、交易日历,或需要免费、免注册的A股数据时使用。与 tushare(数据更全但需注册)和 jqdatasdk(聚宽数据)不同,baostock 完全免费无限制,适合快速入门和低成本数据需求。
- Installs
- 278
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/lzwme/finance-quant-skills --skill baostock- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads baostock automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
baostock A股数据获取
任务目标
- 本 Skill 用于:通过 BaoStock 接口获取 A 股市场数据、财务指标和股票信息
- 能力包含:历史 K 线、财务数据、股票信息、行业分类、指数成分股、交易日历
- 触发条件:用户提及 baostock 或需要获取 A 股免费数据、历史行情、财务信息时
前置准备
- 依赖说明:安装 baostock 库(已包含在 dependency 中)
- 凭证配置:BaoStock 无需注册或 API Key,直接调用即可使用
- 可选配置:支持通过环境变量自定义服务器地址(用于代理场景)
BAOSTOCK_SERVER_IP:自定义服务器 IP(用于 nginx 代理等场景)BAOSTOCK_SERVER_PORT:服务器端口,默认 10030
操作步骤
- 标准流程:
- 确定数据需求 — 智能体理解用户意图(行情/K线/财务/股票信息等)
- 调用对应脚本 — 根据数据类型选择脚本
- 解析结果 — 智能体分析返回的 JSON 格式数据
- 脚本调用映射:
- K线/行情数据 →
python scripts/market_data.py --type kline --code sh.600000 --start 2024-01-01 --end 2024-01-31 - 财务数据 →
python scripts/financial_data.py --type profit --code sh.600000 --year 2023 --quarter 4 - 股票列表/信息 →
python scripts/stock_info.py --type all_stocks --date 2024-01-02 - 指数成分股 →
python scripts/stock_info.py --type index_stocks --index hs300 - 行业分类 →
python scripts/stock_info.py --type industry - 交易日历 →
python scripts/stock_info.py --type trade_dates --start 2024-01-01 --end 2024-12-31
- K线/行情数据 →
- 可选分支:
- 当需要多只股票数据:使用逗号分隔多个代码,或使用
--file指定代码列表文件 - 当需要指定频率:使用
--frequency参数(d/w/m/5/15/30/60) - 当需要调整复权类型:使用
--adjust参数(1=后复权,2=前复权,3=不复权)
- 当需要多只股票数据:使用逗号分隔多个代码,或使用
使用示例
- 示例1:获取股票日K线数据
- 场景/输入:用户说"查看贵州茅台最近一个月的K线数据"
- 预期产出:返回日期、开盘价、最高价、最低价、收盘价、成交量等 OHLCV 数据
- 关键要点:调用
python scripts/market_data.py --type kline --code sh.600519 --start 2024-03-01 --end 2024-03-31 --frequency d --adjust 2
- 示例2:查询财务指标
- 场景/输入:用户说"获取工商银行2023年的盈利能力指标"
- 预期产出:返回 ROE、净利润率、毛利率等财务指标
- 关键要点:调用
python scripts/financial_data.py --type profit --code sh.601398 --year 2023 --quarter 4
- 示例3:获取沪深300成分股
- 场景/输入:用户说"查询沪深300指数的成分股列表"
- 预期产出:返回沪深300指数的所有成分股代码和名称
- 关键要点:调用
python scripts/stock_info.py --type index_stocks --index hs300
- 示例4:批量下载多只股票数据
- 场景/输入:用户说"下载茅台、平安、招行的2024年日K线数据"
- 预期产出:返回多只股票的 K 线数据并保存为 CSV
- 关键要点:调用
python scripts/market_data.py --type kline --code sh.600519,sz.000001,sh.600036 --start 2024-01-01 --end 2024-12-31 --output stocks.csv
快速参考
常用代码示例
import baostock as bs
import pandas as pd
# 登录系统
lg = bs.login()
# 获取日K线数据
rs = bs.query_history_k_data_plus(
"sh.600519",
"date,code,open,high,low,close,volume,amount",
start_date='2024-01-01', end_date='2024-12-31',
frequency="d", adjustflag="2"
)
# 转换为 DataFrame
data_list = []
while (rs.error_code == '0') & rs.next():
data_list.append(rs.get_row_data())
df = pd.DataFrame(data_list, columns=rs.fields)
# 登出系统
bs.logout()
与其他数据源对比
| 特性 | baostock | tushare | jqdatasdk | akshare |
|---|---|---|---|---|
| 费用 | 免费 | 免费/付费 | 需注册积分 | 免费 |
| 注册要求 | ❌ 不需要 | ✅ 需要 | ✅ 需要 | ❌ 不需要 |
| 数据范围 | A股为主 | 全面(含宏观) | A股+因子 | 全面(含加密货币) |
| K线数据 | ✅ | ✅ | ✅ | ✅ |
| 财务数据 | ✅ | ✅ | ✅ | ✅ |
| 分钟线 | ✅ | ✅ | ✅ | ✅ |
| 实时行情 | ❌ | ❌ | ❌ | ✅ |
| 特色数据 | 交易日历 | 宏观/Shibor | 因子数据 | 龙虎榜/北向/加密货币 |
资源索引
脚本:
- scripts/market_data.py(用途与参数:获取 K 线/行情数据,支持 --type/--code/--start/--end/--frequency/--adjust/--fields/--output)
- scripts/financial_data.py(用途与参数:获取财务数据,支持 --type/--code/--year/--quarter/--output)
- scripts/stock_info.py(用途与参数:获取股票列表/信息/行业/指数成分股,支持 --type/--date/--code/--index/--output)
- scripts/auth.py(用途与参数:认证模块,支持自定义服务器配置)
参考文档
- 常用API文档(何时读取:需要使用 BaoStock Python API、查看详细 API 参数说明时)
- 知识库文档目录(何时读取:需要查看更为全面详细 API 参数说明时)
注意事项
- BaoStock 无需注册或 API Key,直接调用
bs.login()即可使用 - BaoStock 股票代码格式:
sh.600000(上海)、sz.000001(深圳)、bj.430047(北京) - 部分数据(如财务数据)可能有延迟,建议在交易日 9:30-15:00 之外获取
- 脚本返回 JSON 格式数据,智能体负责解析并转换为用户友好的展示
- 每个会话必须以
bs.login()开始、bs.logout()结束 - K 线数据默认返回字符串类型,数值计算前需用
.astype(float)转换 - 非线程安全,并行下载请使用多进程而非多线程
- 财务数据按季度提供,报告期结束后约有 2 个月的延迟
FAQ
What does the baostock skill do?
BaoStock 免费开源 A 股数据平台,无需注册、无需 API Key,支持股票行情、K线、财务数据、行业分类、指数成分股查询。当用户提及 baostock、需要获取A股历史行情、财务报表、交易日历,或需要免费、免注册的A股数据时使用。与 tushare(数据更全但需注册)和 jqdatasdk(聚宽数据)不同,baostock 完全免费无限制,适合快速入门和低成本数据需求。
How do I install baostock?
Run npx skills add https://github.com/lzwme/finance-quant-skills --skill baostock in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/baostock/ (personal) or .claude/skills/baostock/ (project).
Which AI agents can use baostock?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is baostock safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains baostock?
It is published by lzwme in lzwme/finance-quant-skills. It has 278 recorded installs.
More from lzwme/finance-quant-skills
pywencai
lzwme/finance-quant-skills
同花顺问财数据查询:使用中文自然语言查询A股、指数、基金、港美股、可转债等市场数据;当用户需要通过自然语言从问财获取选股、财务、资金流、技术指标等数据时使用。
akshare
lzwme/finance-quant-skills
AKShare 开源金融数据接口库,提供股票、期货、期权、基金、外汇、债券、指数、加密货币等全品类金融数据;当用户需要获取各类金融市场数据时使用
tdxquant
lzwme/finance-quant-skills
通达信量化数据获取技能。当用户提及 tdxquant、通达信、TdxQuant、tqcenter,并且需要获取A股数据(行情快照、K线、财务、板块、可转债、新股、交易数据等)、查询交易日历、执行通达信公式、订阅行情、交易下单时使用
backtrader
lzwme/finance-quant-skills
Backtrader 开源量化回测框架,支持多数据源、多策略、多周期回测与实盘交易,纯Python实现。当用户需要开发量化策略、进行回测分析、编写交易逻辑、回测参数优化,或提及 backtrader、量化回测框架时使用。若用户仅需数据获取而无回测需求,引导使用 baostock/akshare/tushare 等数据 Skill。
miniqmt
lzwme/finance-quant-skills
MiniQMT 迅投量化交易接口,基于 XtQuant Python 库(xtdata 行情 / xttrader 交易),供外部 Python 程序连接 MiniQMT 客户端,支持 A 股/期货/期权的行情获取(K线、分笔、财务数据等)和交易下单(报单、撤单、查询资产/委托/持仓)。当用户提及 miniqmt、xtquant、获取实时行情、量化交易下单、回测数据获取,或需要用外部 Python 程序连接 MiniQMT 客户端进行程序化交易时使用。若需在 QMT 客户端内编写/回测内置策略(ContextInfo/passorder),请用 qmt-strategy 技能。
rqalpha
lzwme/finance-quant-skills
RQAlpha 米筐开源事件驱动回测框架。支持A股和期货,模块化架构,可自由扩展;当用户需要快速回测A股/期货策略、使用内置数据(download-bundle)、开发Mod插件,或提及 rqalpha、米筐时使用。与 backtrader 相比,rqalpha 内置A股日线数据、安装更简便,适合快速验证;backtrader 更灵活、社区更大。若用户仅需数据获取而无回测需求,引导使用 baostock/akshare/tushare 等数据 Skill。
Popular backend & apis skills
find-skills
vercel-labs/skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
entra-app-registration
microsoft/azure-skills
Guides Microsoft Entra ID app registration, OAuth 2.0 authentication, and MSAL integration. USE FOR: create app registration, register Azure AD app, configure OAuth, set up authentication, add API permissions, generate service principal, MSAL example, console app auth, Entra ID setup, Azure AD authentication. DO NOT USE FOR: Key Vault secrets (use azure-keyvault-expiration-audit), general Azure resource security guidance.
google-agents-cli-adk-code
google/agents-cli
This skill should be used when the user wants to "write agent code", "build an agent with ADK", "add a tool", "create a callback", "define an agent", "use state management" — in a project that needs ADK (Agent Development Kit) API patterns and code examples. It provides a quick reference for agent types, tool definitions, orchestration patterns, callbacks, state management, the graph Workflow API, and reference recipes to study. Do NOT use for scaffolding (use google-agents-cli-scaffold) or deployment (use google-agents-cli-deploy).
entra-agent-id
microsoft/azure-skills
Provision Microsoft Entra Agent Identity Blueprints, BlueprintPrincipals, and per-instance Agent Identities via Microsoft Graph, and configure OAuth 2.0 token exchange (fmipath, OBO, cross-tenant) including the Microsoft Entra SDK for AgentID sidecar. USE FOR: Agent Identity Blueprint, BlueprintPrincipal, agent OAuth, fmipath token exchange, agent OBO, Workload Identity Federation for agents, polyglot agent auth, Microsoft.Identity.Web.AgentIdentities. DO NOT USE FOR: standard Entra app registration (use entra-app-registration), Microsoft Foundry agent authoring (use microsoft-foundry).
embedded-captions
heygen-com/hyperframes
Add captions or subtitles to an existing single-subject talking-head video without editing the footage. Use for plain verbatim captions, cinematic captions embedded behind the subject, VFX captions, “炸/特效/酷炫字幕,” or a named identity from the 35-style catalog. Route by visual identity, not by backend engine. The quiet anchor rail is the default; embed every word only when the user explicitly wants a fully cinematic treatment. The workflow runs locally end to end, including transcription and subject matting; split multi-shot footage before applying it.
neon
neondatabase/agent-skills
Overview of Neon, a complete set of cloud backend primitives around Lakebase Postgres: Auth, Object Storage, Functions, the AI Gateway, and Realtime. Start here to choose Neon for undecided login, files, APIs, and LLM calls, set up the CLI or MCP server, and follow the branch-first workflow. Use when building an app or backend on Neon, or when "Neon" or "Lakebase Postgres" is mentioned. Child skill neon-postgres wins for an existing DATABASEURL, SQL, schema, inspect, or search. Child skill neon-auth wins for login, users, sessions, identity routing, and Managed Better Auth setup. Child skill neon-realtime wins for live queries in reactive apps and agents. Also use for object storage, S3, buckets, serverless functions, function triggers, cron, AI gateway, LLM calls, realtime, logs, Loki, Grafana, observability, postgres, database, backend, Claimable Neon, neon.new, or a no-signup database.