Skip to main content

AlphaFeed Python SDK

Project description

AlphaFeed Python SDK

AlphaFeed Python SDK 是 AlphaFeed 金融市场数据 API 的 Python 客户端,支持 A 股、ETF、美股、港股。

完整文档https://docs.alphafeed.org


安装

pip install alphafeed

SDK 支持 Python 3.9+,推荐 3.10 或更高版本。内置 pandas 和 tqdm 支持。


初始化

from alphafeed import AlphaFeed

af = AlphaFeed(api_key="your-api-key")

也支持环境变量:

export ALPHAFEED_API_KEY="your-api-key"
from alphafeed import AlphaFeed
af = AlphaFeed()  # 自动读取 ALPHAFEED_API_KEY

标的代码格式

示例 说明
600519.SH 上交所
000001.SZ 深交所
AAPL.US 美股
00700.HK 港股

基础用法

K 线获取

from alphafeed import AlphaFeed

af = AlphaFeed(api_key="your-api-key")

# 日 K 线,返回 DataFrame
df = af.klines.get("600519.SH", period="1d", count=5, to_dataframe=True)
print(df[["trade_date", "open", "high", "low", "close", "volume"]])
#    trade_date     open     high      low    close  volume
# 0  2026-06-02  1306.00  1326.36  1301.00  1307.22   36362
# 1  2026-06-03  1304.00  1304.00  1276.00  1281.91   52477
# 2  2026-06-04  1278.99  1288.99  1266.69  1268.00   33506
# 3  2026-06-05  1278.00  1283.00  1267.74  1272.86   31304
# 4  2026-06-08  1272.00  1278.00  1260.00  1262.98   30828

# 比例前复权(默认)/ 比例后复权 / 差值前复权 / 差值后复权 / 不复权
df = af.klines.get("600519.SH", adjust="forward", to_dataframe=True)
df = af.klines.get("600519.SH", adjust="backward", to_dataframe=True)
df = af.klines.get("600519.SH", adjust="forward_additive", to_dataframe=True)
df = af.klines.get("600519.SH", adjust="backward_additive", to_dataframe=True)
df = af.klines.get("600519.SH", adjust="none", to_dataframe=True)

批量获取:多只标的一次拉取:

symbols = ["600519.SH", "000001.SZ", "601318.SH"]
dfs = af.klines.batch(symbols, period="1d", count=5, to_dataframe=True, show_progress=True)
# dfs 是 dict: {"600519.SH": DataFrame, "000001.SZ": DataFrame, ...}
print(dfs["600519.SH"][["trade_date", "close"]])

日内分时

# 当日 1 分钟线
df = af.klines.intraday("600519.SH", to_dataframe=True)
print(df[["trade_time", "close", "volume"]].tail())
#               trade_time    close  volume
# 236  2026-06-08 14:56:00  1263.00     191
# 237  2026-06-08 14:57:00  1262.99     126
# 238  2026-06-08 14:58:00  1263.00       6
# 239  2026-06-08 14:59:00  1263.00       0
# 240  2026-06-08 15:00:00  1262.98     254

# 5 分钟线
df = af.klines.intraday("600519.SH", period="5m", to_dataframe=True)

# 批量日内分时
dfs = af.klines.intraday_batch(["600519.SH", "000001.SZ"], to_dataframe=True)

实时行情

按标的代码查询

df = af.quotes.get(symbols=["600519.SH", "000001.SZ"], to_dataframe=True)
print(df[["symbol", "last_price", "volume", "ext.name", "ext.change_pct"]])
#       symbol  last_price   volume ext.name  ext.change_pct
# 0  000001.SZ       11.03  1090926     平安银行        0.004554
# 1  600519.SH     1262.98    30828     贵州茅台       -0.007762

按标的池查询(全量行情)

# 全部 A 股实时行情
df = af.quotes.get(universes="CN_Stock", to_dataframe=True)
print(f"共 {len(df)} 只标的")

# 全部 ETF 行情
df = af.quotes.get(universes="CN_ETF", to_dataframe=True)

支持的标的池:CN_Stock(A股)、US_Stock(美股)、HK_Stock(港股)、CN_ETF(ETF)

五档盘口

depth = af.depth.get("600519.SH")
print(f"标的: {depth['symbol']}, 地区: {depth['region']}")
print(f"买盘价: {depth['bid_prices']}")   # [1262.98, 1262.65, ...]
print(f"买盘量: {depth['bid_volumes']}")  # [2, 1, ...]
print(f"卖盘价: {depth['ask_prices']}")   # [1262.99, 1263.0, ...]
print(f"卖盘量: {depth['ask_volumes']}")  # [7, 44, ...]

标的信息

# 单个标的
inst = af.instruments.get("600519.SH")
print(f"{inst['symbol']}: {inst['name']} ({inst['exchange']}, {inst['type']})")
# 600519.SH: 贵州茅台 (SH, stock)
print(f"上市日期: {inst['ext']['listing_date']}")
# 上市日期: 2001-08-27

# 批量查询
insts = af.instruments.batch(["600519.SH", "000001.SZ", "00700.HK"])
for i in insts:
    print(f"{i['symbol']}: {i['name']} ({i['region']})")
# 600519.SH: 贵州茅台 (CN)
# 000001.SZ: 平安银行 (CN)
# 00700.HK: 腾讯控股 (HK)

复权因子

df = af.klines.ex_factors(["600519.SH", "000001.SZ"], to_dataframe=True)
print(df[["symbol", "trade_date", "ex_factor"]].tail())
#        symbol  trade_date  ex_factor
# 52  000001.SZ  2023-06-14   1.024369
# 53  000001.SZ  2024-06-14   1.071428
# 54  000001.SZ  2024-10-10   1.021872
# 55  000001.SZ  2025-06-12   1.031331
# 56  000001.SZ  2025-10-15   1.021505

更多文档


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alphafeed-0.1.2.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alphafeed-0.1.2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file alphafeed-0.1.2.tar.gz.

File metadata

  • Download URL: alphafeed-0.1.2.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for alphafeed-0.1.2.tar.gz
Algorithm Hash digest
SHA256 77921532222efd7620b1aecbd1b0d85d987bc20b5abdda78a014a90bd6f42c57
MD5 be92c236773b5ef3d4400c35b4506235
BLAKE2b-256 b945ca155dfb2c917b5f6ceadea8dbafa4d919758b49120e4fc3eb57636e8340

See more details on using hashes here.

File details

Details for the file alphafeed-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: alphafeed-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for alphafeed-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f60eb531fe1dffaef47cbbe067629c1c595e0c45648712170a8f9d4224ace0d
MD5 2e42b6e159c5d429cfd0741562fa67a1
BLAKE2b-256 71d44f26c231acee24ab3f70e5ba143ceb94753f2c7b1d1be03d687d2d68fa70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page