雪球APP Python API (需要自取token)
安装
pip install pysnowball
示例
>>> import pysnowball as ball
>>> ball.set_token("xq_a_token=662745a236*****;u=909119****")
>>> ball.cash_flow('SH600000')
调用API前需要手动获取雪球网站的token,使用set_token设置token后才能访问雪球的API。s(xq_a_token & u)
传送门 === 如何获取雪球token
欢迎加入Users微信群,方便讨论使用方面的问题,新需求,以及量化交易相关的内容。 共同进步!


获取某支股票的行情数据
import pysnowball as ball
ball.quotec('SZ002027')
结果显示:
{
"data": [
{
"symbol": "SZ002027",
"current": 1.341,
"percent": -0.89,
"chg": -0.012,
"timestamp": 1541486940000,
"volume": 2695183,
"amount": 3605340,
"market_capital": 9835440347.54,
"float_market_capital": null,
"turnover_rate": null,
"amplitude": 1.4,
"open": 1.351,
"last_close": 1.353,
"high": 1.351,
"low": 1.332,
"avg_price": 1.338,
"trade_volume": 22100,
"side": 1,
"is_trade": true,
"level": 1,
"trade_session": null,
"trade_type": null,
"current_year_percent": -35.84
}
],
"error_code": 0,
"error_description": null
}
获取某支股票的行情数据-详细
import pysnowball as ball
ball.quote_detail("SH600104")
结果显示:
{
"data": {
"market": {
"status_id": 7,
"region": "CN",
"status": "已收盘",
"time_zone": "Asia/Shanghai",
"time_zone_desc": null,
"delay_tag": 0
},
"quote": {
"current_ext": null,
"symbol": "SH600104",
"volume_ext": null,
"high52w": 26.4319,
"delayed": 0,
"type": 11,
"tick_size": 0.01,
"float_shares": 11683461365,
"limit_down": 18.23,
"no_profit": null,
"high": 20.96,
"float_market_capital": 2.43717004074E11,
"timestamp_ext": null,
"lot_size": 100,
"lock_set": null,
"weighted_voting_rights": null,
"chg": 0.61,
"eps": 2.07,
"last_close": 20.25,
"profit_four": 2.413305412205E10,
"volume": 65949501,
"volume_ratio": 1.73,
"profit_forecast": 2.7133061018E10,
"turnover_rate": 0.56,
"low52w": 18.03,
"name": "上汽集团",
"exchange": "SH",
"pe_forecast": 8.982,
"total_shares": 11683461365,
"status": 1,
"is_vie_desc": null,
"security_status": null,
"code": "600104",
"goodwill_in_net_assets": 0.5219986746082667,
"avg_price": 20.698,
"percent": 3.01,
"weighted_voting_rights_desc": null,
"amplitude": 3.51,
"current": 20.86,
"is_vie": null,
"current_year_percent": -11.78,
"issue_date": 880387200000,
"sub_type": "ASH",
"low": 20.25,
"is_registration_desc": null,
"no_profit_desc": null,
"market_capital": 2.43717004074E11,
"dividend": 0.62,
"dividend_yield": 2.972,
"currency": "CNY",
"navps": 23.18,
"profit": 2.043103747976E10,
"timestamp": 1638860400000,
"pe_lyr": 11.929,
"amount": 1.365040096E9,
"pledge_ratio": null,
"traded_amount_ext": null,
"is_registration": null,
"pb": 0.9,
"limit_up": 22.28,
"pe_ttm": 10.099,
"time": 1638860400000,
"open": 20.33
},
"others": {
"pankou_ratio": -29.27,
"cyb_switch": true
},
"tags": [
{
"description": "沪股通",
"value": 1
},
{
"description": "融",
"value": 6
},
{
"description": "空",
"value": 7
}
]
},
"error_code": 0,
"error_description": ""
}
获取实时分笔数据,可以实时取得股票当前报价和成交信息
import pysnowball as ball
ball.pankou('SZ002027')
结果显示:
{
"symbol": "SZ002027",
"time": "Nov 6, 2018 2:59:15 PM",
"timestamp": 1541487555000,
"bp1": 6.56,
"bc1": 502,
"bp2": 0,
"bc2": 0,
"bp3": 0,
"bc3": 0,
"bp4": 0,
"bc4": 0,
"bp5": 0,
"bc5": 0,
"bp6": 0,
"bc6": 0,
"bp7": 0,
"bc7": 0,
"bp8": 0,
"bc8": 0,
"bp9": 0,
"bc9": 0,
"bp10": 0,
"bc10": 0,
"current": 6.55,
"sp1": 6.56,
"sc1": 502,
"sp2": 0,
"sc2": 2796,
"sp3": 0,
"sc3": 0,
"sp4": 0,
"sc4": 0,
"sp5": 0,
"sc5": 0,
"sp6": 0,
"sc6": 0,
"sp7": 0,
"sc7": 0,
"sp8": 0,
"sc8": 0,
"sp9": 0,
"sc9": 0,
"sp10": 0,
"sc10": 0,
"buypct": 13.21,
"sellpct": 86.79,
"diff": -2796,
"ratio": -73.58
}
获取K线数据。
第二参数可指定period,默认day;第三参数可指定count,默认284。
原K线接口中 https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=SH600219&begin=1747625277024&period=day&type=before&count=-284&indicator=kline,pe,pb,ps,pcf,market_capital,agt,ggt,balance 的 period 会根据不同的类型返回不同周期的K线
日K:day
周K:week
月K:month
60分K:60m
30分K:30m
1分K:1m
import pysnowball as ball
ball.kline('SZ002027')
ball.kline('SZ002027','day', 30)
按年度获取业绩预告数据
import pysnowball as ball
ball.earningforecast('SZ002027')
结果显示:
{
"list": [
{
"eps": 4.78,
"roe": null,
"pb": null,
"pe": 8.4,
"forecast_year": "2018"
},
{
"eps": 5.49,
"roe": null,
"pb": null,
"pe": 7.32,
"forecast_year": "2019"
},
{
"eps": 6.12,
"roe": null,
"pb": null,
"pe": 6.56,
"forecast_year": "2020"
}
]
}
获取机构评级数据
import pysnowball as ball
ball.report('SZ002027')
结果显示:
{
"list": [
{
"title": "2018年三季报点评:业绩确定性最强 新冷年预收款下降",
"rpt_comp": "申万宏源",
"rating_desc": "买入",
"target_price_min": null,
"target_price_max": null,
"pub_date": 1541088000000,
"status_id": 116200430,
"retweet_count": 0,
"reply_count": 4,
"like_count": 4,
"liked": false
},
{
"title": "2018年三季报点评:业绩表现优异 现金流增长亮眼(",
"rpt_comp": "海通证券",
"rating_desc": "增持",
"target_price_min": 50.3,
"target_price_max": 60.4,
"pub_date": 1541088000000,
"status_id": 116196608,
"retweet_count": 0,
"reply_count": 0,
"like_count": 0,
"liked": false
}...
]
}
获取当日资金流如流出数据,每分钟数据
import pysnowball as ball
ball.capital_flow('SZ002027')
结果显示:
{
"data": {
"symbol": "SZ002027",
"items": [
{
"timestamp": 1541467800000,
"amount": -12323447,
"type": null
},
{
"timestamp": 1541467860000,
"amount": -12940471,
"type": null
},
{
"timestamp": 1541467920000,
"amount": -18710425,
"type": null
},
...
]
}
获取历史资金流如流出数据,每日数据
import pysnowball as ball
ball.capital_history('SZ002027')
结果显示:
{
"data": {
"sum3": -152759438,
"sum5": -332530425,
"sum10": -362575240.15999997,
"sum20": -162580140.64,
"items": [
{
"amount": 1232691,
"timestamp": 1539100800000
},
{
"amount": -65392886,
"timestamp": 1539187200000
},
...
{
"amount": -4122992,
"timestamp": 1541433600000
}
]
},
"error_code": 0,
"error_description": ""
}
获取资金成交分布数据
import pysnowball as ball
ball.capital_assort('SZ002027')
结果显示:
{
"data": {
"sell_large": 21922533,
"sell_medium": 353650388,
"sell_small": 225596826,
"sell_total": 601169747,
"buy_large": 14298615,
"buy_medium": 317379444,
"buy_small": 265530036,
"buy_total": 597208095,
"timestamp": 1541433600000,
"created_at": null,
"updated_at": null
},
"error_code": 0,
"error_description": ""
}
大宗交易数据
import pysnowball as ball
ball.blocktrans('SZ002027')
结果显示:
{
"data": {
"items": [
{
"vol": 780200,
"sell_branch_org_name": "机构专用",
"premium_rat": 0,
"trans_amt": 30193700,
"td_date": 1541001600000,
"buy_branch_org_name": "机构专用",
"trans_price": 38.7
},
{
"vol": 774200,
"sell_branch_org_name": "机构专用",
"premium_rat": 0,
"trans_amt": 29961500,
"td_date": 1541001600000,
"buy_branch_org_name": "机构专用",
"trans_price": 38.7
},
...
]
},
"error_code": 0,
"error_description": ""
}
融资融券数据
import pysnowball as ball
ball.margin('SZ002027')
结果显示:
{
"data": {
"items": [
{
"margin_trading_amt_balance": 960745756,
"short_selling_amt_balance": 2888439,
"margin_trading_balance": 957857317,
"td_date": 1541347200000
},
{
"margin_trading_amt_balance": 948660728,
"short_selling_amt_balance": 2767982,
"margin_trading_balance": 945892746,
"td_date": 1541088000000
},
...
]
},
"error_code": 0,
"error_description": ""
}
按年度、季度获取业绩报表数据。
import pysnowball as ball
ball.indicator('SZ002027')
# or
ball.indicator(symbol='SZ002027',is_annals=1,count=10)
输入参数:
结果显示:
{
"data": {
"quote_name": "分众传媒",
"currency_name": "人民币",
"org_type": 1,
"last_report_name": "2018三季报",
"currency": "CNY",
"list": [
{
"report_date": 1538236800000,
"report_name": "2018三季报",
"avg_roe": [
40.2459,
-0.16318251756975927
],
"np_per_share": [
0.9217,
0.3588382721509656
],
"operate_cash_flow_ps": [
0.1063,
-0.45543032786885246
],
"basic_eps": [
0.3277,
0.024062499999999952
],
"capital_reserve": [
0.0127,
-0.15333333333333335
],
"undistri_profit_ps": [
0.9042,
0.4481101857783473
],
"net_interest_of_total_assets": [
28.1351,
-0.10744276201624894
],
"gross_selling_rate": [
69.2402,
-0.042102277836574074
]
},
{
"report_date": 1530288000000,
"report_name": "2018中报",
"avg_roe": [
29.2624,
-0.1387915228248617
],
"np_per_share": [
0.85,
0.07336784947594384
],
"operate_cash_flow_ps": [
0.085,
-0.5940783190066857
],
"basic_eps": [
0.23,
-0.20689655172413784
],
"capital_reserve": [
0.0127,
-0.3923444976076555
],
"undistri_profit_ps": [
0.8046,
0.12405699916177702
],
"net_interest_of_total_assets": [
20.1998,
0.06631263329039885
],
"gross_selling_rate": [
71.8153,
0.014222928982801345
]
},
...
]
},
"error_code": 0,
"error_description": ""
}
import pysnowball as ball
ball.income('SZ300251')
# or
ball.income(symbol='SZ300251',is_annals=1,count=10)
输入参数:
结果显示:
```json { "data": { "quote_name": "光线传媒", "currency_name": "人民币", "org_type": 1, "last_report_name": "2018三季报", "currency": "CNY",
$ claude mcp add pysnowball \
-- python -m otcore.mcp_server <graph>