跳转到主要内容

获取日K线并计算均线

from quantdash import QuantDash

qd = QuantDash(api_key="your-api-key")

df = qd.klines.get("600519.SH", period="1d", count=120, to_dataframe=True)
df["ma5"] = df["close"].rolling(5).mean()
df["ma20"] = df["close"].rolling(20).mean()
print(df[["trade_date", "close", "ma5", "ma20"]].tail(5))

批量获取日K线(带进度条)

symbols = ["600519.SH", "000001.SZ", "601318.SH", "600036.SH", "000858.SZ"]
dfs = qd.klines.batch(symbols, period="1d", count=60, to_dataframe=True, show_progress=True)

# 汇总最新收盘价
import pandas as pd
latest = {sym: df["close"].iloc[-1] for sym, df in dfs.items()}
print(pd.Series(latest, name="close").sort_values(ascending=False))
600519.SH    1215.00
000858.SZ      75.85
601318.SH      49.38
600036.SH      37.26
000001.SZ      10.52
Name: close, dtype: float64

获取分钟K线

df = qd.klines.get("600519.SH", period="5m", count=5, to_dataframe=True)
print(df[["trade_time", "open", "high", "low", "close", "volume"]])
          trade_time    open    high     low   close  volume
2026-06-18 14:40:00 1214.44 1215.82 1212.26 1215.82    1151
2026-06-18 14:45:00 1215.02 1217.00 1215.00 1216.99     997
2026-06-18 14:50:00 1216.52 1217.39 1215.99 1217.38     827
2026-06-18 14:55:00 1217.40 1228.37 1217.40 1222.55    2355
2026-06-18 15:00:00 1223.02 1223.99 1215.00 1215.00    2324

全 A 股实时行情

# 支持标的池:CN_Stock / CN_ETF / US_Stock / HK_Stock
df = qd.quotes.get(universes=["CN_Stock"], to_dataframe=True)
print(df)
         symbol region  ...  ext.amplitude  ext.turnover_rate
0     920985.BJ     CN  ...       0.043893           0.015161
1     002414.SZ     CN  ...       0.027106           0.015167
2     600589.SH     CN  ...       0.047852           0.076141
3     688543.SH     CN  ...       0.043046           0.052545
4     300988.SZ     CN  ...       0.044633           0.043186
...         ...    ...  ...            ...                ...
5496  002546.SZ     CN  ...       0.022026           0.014857
5497  920363.BJ     CN  ...       0.038917           0.027170
5498  688590.SH     CN  ...       0.033557           0.051160
5499  001317.SZ     CN  ...       0.053210           0.043987
5500  300731.SZ     CN  ...       0.080393           0.090136

[5501 rows x 18 columns]

按标的查询实时行情

df = qd.quotes.get(symbols=["600519.SH", "000001.SZ"], to_dataframe=True)
print(df[["symbol", "last_price", "prev_close", "volume", "ext.name", "ext.change_pct"]])
   symbol  last_price  prev_close  volume ext.name  ext.change_pct
000001.SZ       10.52       10.78 1426893     平安银行       -0.024119
600519.SH     1215.00     1240.00   57472     贵州茅台       -0.020161

获取日内分时

df = qd.klines.intraday("600519.SH", count=5, to_dataframe=True)
print(df[["symbol", "name", "trade_time", "close", "volume"]])
   symbol name          trade_time   close  volume
600519.SH 贵州茅台 2026-06-18 14:56:00 1223.50     273
600519.SH 贵州茅台 2026-06-18 14:57:00 1223.88     261
600519.SH 贵州茅台 2026-06-18 14:58:00 1223.26       2
600519.SH 贵州茅台 2026-06-18 14:59:00 1223.26       0
600519.SH 贵州茅台 2026-06-18 15:00:00 1215.00    1788

批量日内分时

dfs = qd.klines.intraday_batch(["600519.SH", "000001.SZ"], to_dataframe=True)
for sym, df in dfs.items():
    print(f"{sym} ({df['name'].iloc[0]}): {len(df)} 条分钟线")
600519.SH (贵州茅台): 241 条分钟线
000001.SZ (平安银行): 241 条分钟线

获取标的信息

# 单个标的
inst = qd.instruments.get("600519.SH")
print(f"{inst['symbol']}: {inst['name']}")
print(f"  交易所: {inst['exchange']}, 类型: {inst['type']}")
print(f"  上市日期: {inst['ext']['listing_date']}")
print(f"  总股本: {inst['ext']['total_shares']:,.0f}")
600519.SH: 贵州茅台
  交易所: SH, 类型: stock
  上市日期: 2001-08-27
  总股本: 1,250,081,601

批量查询

insts = qd.instruments.get(["600519.SH", "000001.SZ", "00700.HK"])
for i in insts:
    print(f"{i['symbol']:>10s}  {i['name']:<6s}  交易所={i['exchange']}  类型={i['type']}  上市={i['ext'].get('listing_date','')}")
 600519.SH  贵州茅台    交易所=SH  类型=stock  上市=2001-08-27
 000001.SZ  平安银行    交易所=SZ  类型=stock  上市=1991-04-03
  00700.HK  腾讯控股    交易所=HK  类型=stock  上市=2004-06-16

获取除权因子

df = qd.klines.ex_factors(["600519.SH"], to_dataframe=True)
print(df[["symbol", "trade_date", "ex_factor"]].tail(5))
   symbol trade_date  ex_factor
600519.SH 2023-12-20   1.011540
600519.SH 2024-06-19   1.020716
600519.SH 2024-12-20   1.015637
600519.SH 2025-06-26   1.019649
600519.SH 2025-12-19   1.017003

五档盘口

depth = qd.depth.get("600519.SH")
print(f"标的: {depth['symbol']}  地区: {depth['region']}")
for i in range(5):
    bid = f"买{i+1}: {depth['bid_prices'][i]:>10.2f} x {depth['bid_volumes'][i]}"
    ask = f"卖{i+1}: {depth['ask_prices'][i]:>10.2f} x {depth['ask_volumes'][i]}"
    print(f"  {bid}  |  {ask}")
标的: 600519.SH  地区: CN
  买1:    1215.00 x 123  |  卖1:    1215.28 x 1
  买2:    1214.95 x 2  |  卖2:    1215.96 x 1
  买3:    1214.88 x 1  |  卖3:    1216.00 x 2
  买4:    1214.48 x 1  |  卖4:    1218.00 x 1
  买5:    1214.40 x 1  |  卖5:    1218.89 x 1