同花顺问财数据查询:使用中文自然语言查询A股、指数、基金、港美股、可转债等市场数据;当用户需要通过自然语言从问财获取选股、财务、资金流、技术指标等数据时使用。
npx skills add https://github.com/lzwme/finance-quant-skills --skill pywencai
通过Python使用中文自然语言从同花顺问财查询A股及其他市场数据。
> ⚠️ 需要Cookie:必须提供问财网站的有效Cookie。获取方法见下文。
pip install pywencai --upgrade
若存在环境变量 WENCAI_COOKIE,可直接使用;若调用失败,则按如下步骤重新获取:
iwencai.com的请求,从请求头中复制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)
pywencai.get(**kwargs)'今日涨停股票'、'市盈率小于20的股票''退市@退市日期''asc'(升序)或 'desc'(降序)1)100)True获取所有页;或设为整数n获取前n页'stock'),可选值:| 值 | 说明 |
|---|---|
| stock | A股股票 |
| zhishu | 指数 |
| fund | 基金 |
| hkstock | 港股 |
| usstock | 美股 |
| threeboard | 新三板 |
| conbond | 可转债 |
| insurance | 保险 |
| futures | 期货 |
| lccp | 理财产品 |
10)0)True在控制台打印日志True使用付费版(需要对应的cookie)True始终返回DataFrame或None(不返回dict)['600519', '000010']requests的额外参数,如 {'proxies': proxies}pandas.DataFramedict(可能包含文本和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")
pip install pywencai --upgradeloop=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 |
cookie 参数应统一使用环境变量 WENCAI_COOKIE 或 Cookie 文件管理方式,不要硬编码 Cookie 字符串。no_detail=True 以确保返回 DataFrame(除非用户明确需要详情 dict)。sleep 参数(建议 ≥ 2秒),避免被服务器封禁。Automatically organizes invoices and receipts for tax preparation by reading messy files, extracting key information, renaming them consistently, and sorting them into logical folders. Turns hours of manual bookkeeping into minutes of automated organization.
Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.
This skill calculates key financial ratios and metrics from financial statement data for investment analysis
This skill provides an advanced financial modeling suite with DCF analysis, sensitivity testing, Monte Carlo simulations, and scenario planning for investment decisions
This skill retrieves upcoming earnings announcements for US stocks using the Financial Modeling Prep (FMP) API. Use this when the user requests earnings calendar data, wants to know which companies are reporting earnings in the upcoming week, or needs a weekly earnings review. The skill focuses on mid-cap and above companies (over $2B market cap) that have significant market impact, organizing the data by date and timing in a clean markdown table format. Supports multiple environments (CLI, Desktop, Web) with flexible API key management.
Crypto wallet operations via the awal CLI — sign in, check balances, send USDC/ETH/POL/SOL, trade tokens, fund the wallet, and use the x402 payment protocol to discover paid services, pay for API calls, monetize an API, or query onchain data. Use whenever the user mentions signing in, login, authentication, wallet status, balance, address, sending money, paying someone, transferring tokens, ENS names, swapping/trading/converting tokens, funding/topping up/onramp, USDC, ETH, POL, SOL, the x402 bazaar, paid APIs, monetizing an endpoint, or querying onchain data on Base.
Access real-time and historical stock market data, forex rates, cryptocurrency prices, commodities, economic indicators, and 50+ technical indicators via the Alpha Vantage API. Use when fetching stock prices (OHLCV), company fundamentals (income statement, balance sheet, cash flow), earnings, options data, market news/sentiment, insider transactions, GDP, CPI, treasury yields, gold/silver/oil prices, Bitcoin/crypto prices, forex exchange rates, or calculating technical indicators (SMA, EMA, MACD, RSI, Bollinger Bands). Requires a free API key from alphavantage.co.
Braintree Automation: manage payment processing via Stripe-compatible tools for customers, subscriptions, payment methods, and transactions
Take lzwme/pywencai from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference pip.
Without those the skill loads but fails at the first command.