
pywencai
同花顺问财数据查询:使用中文自然语言查询A股、指数、基金、港美股、可转债等市场数据;当用户需要通过自然语言从问财获取选股、财务、资金流、技术指标等数据时使用。
- Installs
- 300
- 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 pywencai- 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 pywencai 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.
PyWenCai(同花顺问财数据查询)
通过Python使用中文自然语言从同花顺问财查询A股及其他市场数据。
⚠️ 需要Cookie:必须提供问财网站的有效Cookie。获取方法见下文。
环境要求
- Python 3.7+
- Node.js v16+(pywencai 内部执行 JS 代码)
- pip package manager
安装
pip install pywencai --upgrade
如何获取Cookie
若存在环境变量 WENCAI_COOKIE,可直接使用;若调用失败,则按如下步骤重新获取:
- 在浏览器中打开 https://www.iwencai.com 并登录。
- 按F12打开开发者工具 → 切换到Network标签。
- 在问财页面执行任意查询。
- 找到发往
iwencai.com的请求,从请求头中复制Cookie值。 - 将该字符串作为
cookie参数使用。
Cookie管理
优先使用环境变量或文件管理Cookie,避免硬编码:
import os
import pywencai
# 方法1:从环境变量读取Cookie(推荐)
cookie = os.environ.get('WENCAI_COOKIE', '')
# 方法2:从文件读取Cookie
def load_cookie(path='~/.wencai_cookie'):
path = os.path.expanduser(path)
if os.path.exists(path):
with open(path) as f:
return f.read().strip()
return ''
# 方法3:封装查询函数,统一管理Cookie和错误处理
def query(q, **kwargs):
cookie = load_cookie()
try:
return pywencai.get(
query=q, cookie=cookie,
no_detail=True, retry=3, sleep=1,
**kwargs
)
except Exception as e:
print(f"查询失败: {e}")
return None
# 使用
df = query('今日涨停的股票')
基本用法
import pywencai
# 查询今日涨幅前10的股票,需要有效cookie
res = pywencai.get(query='今日涨幅前10', cookie='your_cookie_here')
print(res)
API参考:pywencai.get(**kwargs)
必选参数
- query — 中文自然语言查询字符串,如
'今日涨停股票'、'市盈率小于20的股票' - cookie — 从问财网站获取的Cookie字符串(必需)
可选参数
- sort_key — 排序字段名,如
'退市@退市日期' - sort_order — 排序方向:
'asc'(升序)或'desc'(降序) - page — 页码(默认:
1) - perpage — 每页结果数(默认和最大:
100) - loop — 设为
True获取所有页;或设为整数n获取前n页 - query_type — 查询类别(默认:
'stock'),可选值:
| 值 | 说明 |
|---|---|
stock | A股股票 |
zhishu | 指数 |
fund | 基金 |
hkstock | 港股 |
usstock | 美股 |
threeboard | 新三板 |
conbond | 可转债 |
insurance | 保险 |
futures | 期货 |
lccp | 理财产品 |
- retry — 失败重试次数(默认:
10) - sleep — 分页请求间延迟秒数(默认:
0) - log — 设为
True在控制台打印日志 - pro — 设为
True使用付费版(需要对应的cookie) - no_detail — 设为
True始终返回DataFrame或None(不返回dict) - find — 优先返回的股票代码列表,如
['600519', '000010'] - request_params — 传递给
requests的额外参数,如{'proxies': proxies}
返回值
- 列表类查询 → 返回
pandas.DataFrame - 详情类查询 → 返回
dict(可能包含文本和DataFrame)
使用示例
按市场类型查询
import pywencai
# A股股票(默认)
res = pywencai.get(query='今日涨停的股票', cookie=cookie)
# 指数数据
res = pywencai.get(query='上证指数近5日涨跌幅', query_type='zhishu', cookie=cookie)
# 基金数据
res = pywencai.get(query='近一年收益率最高的前20只基金', query_type='fund', cookie=cookie)
# 可转债数据
res = pywencai.get(query='可转债溢价率小于10%', query_type='conbond', cookie=cookie)
# 港股数据
res = pywencai.get(query='港股市值最大的前20只股票', query_type='hkstock', cookie=cookie)
基本面选股
# 估值筛选
res = pywencai.get(query='市盈率小于20的股票', cookie=cookie)
res = pywencai.get(query='市盈率小于10且市净率小于1的股票', cookie=cookie)
# 财务指标
res = pywencai.get(query='ROE大于15%且营收同比增长率大于20%的股票', cookie=cookie)
# 多条件综合筛选
res = pywencai.get(query='市盈率小于20且营收同比增长大于30%且机构持仓比例大于10%的股票', cookie=cookie)
res = pywencai.get(query='今日站上20日均线且市盈率小于30且ROE大于10%的股票', cookie=cookie)
技术面与资金流
# 技术信号
res = pywencai.get(query='今日MACD金叉的股票', cookie=cookie)
res = pywencai.get(query='KDJ的J值小于0的股票', cookie=cookie)
res = pywencai.get(query='今日成交量是5日均量2倍以上且涨幅大于5%的股票', cookie=cookie)
# 资金流向
res = pywencai.get(query='今日主力资金净流入前20的股票', cookie=cookie)
res = pywencai.get(query='北向资金持股比例最高的前20只股票', cookie=cookie)
排序、分页与代理
# 按指定字段排序
res = pywencai.get(
query='退市股票',
sort_key='退市@退市日期',
sort_order='asc',
cookie=cookie
)
# 自动分页获取全部数据(使用代理)
proxies = {'http': 'http://proxy:8080', 'https': 'http://proxy:8080'}
res = pywencai.get(
query='昨日涨幅',
loop=True,
log=True,
cookie=cookie,
request_params={'proxies': proxies}
)
历史数据查询
# 指定日期
res = pywencai.get(query='2024年1月2日涨幅前10的股票', cookie=cookie)
# 日期范围
res = pywencai.get(query='2024年上半年涨幅最大的前20只股票', cookie=cookie)
完整示例:多策略自动化选股并导出
import pywencai
import pandas as pd
import time
cookie = os.environ.get('WENCAI_COOKIE', '')
# 定义多个筛选策略
strategies = {
"低估值高分红": "市盈率小于15且股息率大于3%的股票",
"高成长": "营收同比增长大于30%且净利润同比增长大于30%的股票",
"技术突破": "今日放量突破20日均线且涨幅大于3%的股票",
"机构关注": "近一个月机构调研次数大于3次的股票",
"北向资金": "北向资金今日净买入前20的股票",
}
results = {}
for name, query in strategies.items():
try:
res = pywencai.get(query=query, cookie=cookie, no_detail=True)
if res is not None and not res.empty:
results[name] = res
print(f"策略 [{name}] 选出 {len(res)} 只股票")
else:
print(f"策略 [{name}] 无结果")
except Exception as e:
print(f"策略 [{name}] 查询失败: {e}")
time.sleep(2) # 每次查询间隔2秒,避免被封禁
# 保存结果到Excel(每个策略一个工作表)
if results:
with pd.ExcelWriter("选股结果.xlsx") as writer:
for name, df in results.items():
df.to_excel(writer, sheet_name=name, index=False)
print("筛选结果已保存到 选股结果.xlsx")
使用技巧
- 适度使用 — 高频调用可能被问财服务器封禁,建议每次查询间隔 ≥ 2秒。
- 始终使用最新版本:
pip install pywencai --upgrade - 查询字符串使用中文自然语言 — 像在问财网站搜索一样编写查询。
- 当
loop=True且设置了find时,loop被忽略,仅返回前100条结果。 - 使用付费数据时,设置
pro=True并提供有效cookie。
常见错误处理
| 错误 | 原因 | 解决方法 |
|---|---|---|
Cookie expired | Cookie过期 | 重新登录问财网站获取新Cookie |
返回None | 查询无结果或被限流 | 检查查询语句,降低调用频率 |
Node.js not found | 未安装Node.js | 安装Node.js v16+ |
JSONDecodeError | 服务端返回异常 | 增加retry参数,稍后重试 |
| 返回dict而非DataFrame | 查询为详情类 | 设置no_detail=True强制返回DataFrame |
规则
- 使用此 Skill 前,确认用户需要的是问财自然语言数据查询,而非纯行情 API(如 baostock)或回测框架(如 backtrader/rqalpha)。
- 示例中的
cookie参数应统一使用环境变量WENCAI_COOKIE或 Cookie 文件管理方式,不要硬编码 Cookie 字符串。 - 始终设置
no_detail=True以确保返回DataFrame(除非用户明确需要详情 dict)。 - 批量查询时必须设置
sleep参数(建议 ≥ 2秒),避免被服务器封禁。 - 查询字符串应使用中文自然语言,与问财网站搜索框的输入方式一致。
FAQ
What does the pywencai skill do?
同花顺问财数据查询:使用中文自然语言查询A股、指数、基金、港美股、可转债等市场数据;当用户需要通过自然语言从问财获取选股、财务、资金流、技术指标等数据时使用。
How do I install pywencai?
Run npx skills add https://github.com/lzwme/finance-quant-skills --skill pywencai 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/pywencai/ (personal) or .claude/skills/pywencai/ (project).
Which AI agents can use pywencai?
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 pywencai 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 pywencai?
It is published by lzwme in lzwme/finance-quant-skills. It has 300 recorded installs.
More from lzwme/finance-quant-skills
akshare
lzwme/finance-quant-skills
AKShare 开源金融数据接口库,提供股票、期货、期权、基金、外汇、债券、指数、加密货币等全品类金融数据;当用户需要获取各类金融市场数据时使用
baostock
lzwme/finance-quant-skills
BaoStock 免费开源 A 股数据平台,无需注册、无需 API Key,支持股票行情、K线、财务数据、行业分类、指数成分股查询。当用户提及 baostock、需要获取A股历史行情、财务报表、交易日历,或需要免费、免注册的A股数据时使用。与 tushare(数据更全但需注册)和 jqdatasdk(聚宽数据)不同,baostock 完全免费无限制,适合快速入门和低成本数据需求。
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 business & finance skills
website-builder
flowkit-labs/skills
Build and preview a hosted website for a business from a plain-language brief. Use for a new business homepage, landing page, service showcase, portfolio, online store, or customer portal, and for updates to sites hosted by this builder. Add bookings, checkout, or member accounts as needed and automate reminders, customer follow-ups, and reports after launch. Follow the user's choice when they specify another host or ask to edit an existing codebase.
sales-funnel-blueprint
autonnel/autonnel-skills
Turn an offer into a concrete multi-step sales funnel spec - page-by-page structure, price ladder, copy outline and the metrics each step must hit. Use when asked to build a sales funnel, marketing funnel, landing page flow, lead magnet funnel, webinar funnel, tripwire or VSL funnel, when planning a product launch page flow, or when someone asks "what pages do I need" for selling something online.
sales-enablement
coreyhaines31/marketingskills
When the user wants to create sales collateral, pitch decks, one-pagers, objection handling docs, or demo scripts. Also use when the user mentions 'sales deck,' 'pitch deck,' 'one-pager,' 'leave-behind,' 'objection handling,' 'deal-specific ROI analysis,' 'demo script,' 'talk track,' 'sales playbook,' 'proposal template,' 'buyer persona card,' 'battle card,' 'battlecard,' 'competitive one-pager,' 'win-loss analysis,' 'why are we losing deals,' 'loss reasons,' 'how do I respond to this objection,' 'prospect just said,' 'help my sales team,' 'sales materials,' or 'what should I give my sales reps,' 'cold call script,' or 'voicemail script.' Use this for any document or asset that helps a sales team close deals. For public competitor comparison pages, see competitors. For running buyer interviews or churn research, see customer-research. For marketing website copy, see copywriting. For cold outreach emails, see cold-email. For the offer being sold (bonuses, guarantees, pricing structure),
revops
coreyhaines31/marketingskills
When the user wants help with revenue operations, lead lifecycle management, or marketing-to-sales handoff processes. Also use when the user mentions 'RevOps,' 'revenue operations,' 'lead scoring,' 'outbound pipeline stages,' 'lead routing,' 'MQL,' 'SQL,' 'pipeline stages,' 'deal desk,' 'CRM automation,' 'marketing-to-sales handoff,' 'data hygiene,' 'leads aren't getting to sales,' 'pipeline management,' 'lead qualification,' or 'when should marketing hand off to sales.' Use this for anything involving the systems and processes that connect marketing to revenue. For cold outreach emails, see cold-email. For email drip campaigns, see emails. For pricing decisions, see pricing.
pricing
coreyhaines31/marketingskills
When the user wants help with pricing decisions, packaging, or monetization strategy. Also use when the user mentions 'pricing,' 'pricing tiers,' 'freemium,' 'free trial,' 'packaging,' 'price increase,' 'value metric,' 'Van Westendorp,' 'willingness to pay,' 'monetization,' 'how much should I charge,' 'my pricing is wrong,' 'pricing page,' 'annual vs monthly,' 'per seat pricing,' 'should I offer a free plan,' 'pricing page teardown,' 'pricing page audit,' 'is my pricing page AI-readable,' or 'can AI read my pricing.' Use this whenever someone is figuring out what to charge, how to structure their plans, or wants to audit a pricing page (for humans and for the AI agents that shortlist tools). For in-app upgrade screens, see paywalls. For offer construction (bonuses, guarantees, value framing, naming) on services/courses/coaching/high-ticket B2B, see offers.
offers
coreyhaines31/marketingskills
When the user wants to design, construct, or improve an offer — the thing they actually sell — including value framing, bonus stacking, guarantee design, scarcity/urgency, naming, and payment structure. Also use when the user mentions 'offer,' 'offer design,' 'build an offer,' 'grand slam offer,' 'irresistible offer,' 'value stack,' 'bonus stack,' 'guarantee,' 'risk reversal,' 'money-back guarantee,' 'scarcity,' 'urgency,' 'high-ticket offer,' 'productize a service,' 'naming an offer,' 'payment plan,' 'down-sell,' 'upsell offer,' or 'why isn't my offer converting.' Best for services, agencies, courses, coaching, info products, high-ticket B2B, and direct-response. If you run pure self-serve SaaS, read pricing first — tiers and packaging do more work there. For price level itself (tiers, freemium, value metric), see pricing. For the page that presents the offer, see copywriting. For the launch moment, see launch. For sales collateral, see sales-enablement.