Skip to main content

Local ClickHouse replica of JoinQuant jqdatasdk APIs (get_fundamentals / get_price / finance.run_query / 交易日历 / 证券列表)

Project description

kedu

本项目在本地 ClickHouse 上复刻聚宽 jqdatasdk 的常用 API。查询全部走本地库 jqdata,不依赖在线接口;数据由回补脚本从聚宽拉取后落库。

当前包名是 kedu,不是 jqdata

from kedu import auth, query, valuation, get_price, get_fundamentals

auth("default", "<password>")
df = get_fundamentals(query(valuation).limit(5), date="2024-05-10")

已经复刻可用的 API

认证与查询表面

from kedu import (
    auth,
    auth_from_env,
    get_client,
    query,
    income,
    balance,
    cash_flow,
    indicator,
    valuation,
)

基本面

from kedu import (
    get_fundamentals,
    get_fundamentals_continuously,
    get_history_fundamentals,
)

行情

from kedu import get_price

已支持:

  • frequency='daily'
  • frequency='1m',前提是本地已回补 bar_1m
  • fq=Nonefq='post'fq='pre'
  • 股票、指数、场内基金日线;分钟线按已入库标的可查

交易日历与证券列表

from kedu import get_trade_days, get_all_trade_days, get_all_securities

get_all_securities 已覆盖:

  • stock
  • index
  • fund
  • etf
  • lof
  • fja

其中 fund 会展开到场内基金细分类型。

finance 模块

from kedu import finance, get_table_info

已支持:

  • finance.run_query
  • finance.run_offset_query
  • finance.get_table_info
  • 顶层别名 get_table_info

已复刻的 finance 表:

  • 股票报告期/公告类: STK_INCOME_STATEMENT, STK_BALANCE_SHEET, STK_CASHFLOW_STATEMENT, STK_CASH_FLOW_STATEMENT, STK_FIN_FORCAST, STK_AUDIT_OPINION, STK_REPORT_DISCLOSURE, STK_STATUS_CHANGE, STK_EXCHANGE_TRADE_INFO, STK_MT_TOTAL
  • 上市公司基本信息类: STK_COMPANY_INFO, STK_LIST, STK_NAME_HISTORY, STK_EMPLOYEE_INFO, STK_HOLDER_NUM, STK_LIMITED_SHARES_LIST, STK_LIMITED_SHARES_UNLIMIT, STK_SHAREHOLDERS_SHARE_CHANGE, STK_CAPITAL_CHANGE, STK_SHARES_FROZEN, STK_SHAREHOLDER_TOP10, STK_SHAREHOLDER_FLOATING_TOP10
  • 基金类: FUND_MAIN_INFO, FUND_NET_VALUE, FUND_FIN_INDICATOR, FUND_PORTFOLIO, FUND_PORTFOLIO_BOND, FUND_PORTFOLIO_STOCK, FUND_INVEST_TARGET, FUND_DIVIDEND, FUND_SHARE_DAILY, FUND_MF_DAILY_PROFIT

行业、概念、指数

from kedu import (
    get_industries,
    get_industry_stocks,
    get_history_industry,
    get_industry,
    get_concepts,
    get_concept_stocks,
    get_concept,
    get_index_stocks,
    get_index_weights,
    get_index_valuation,
)

融资融券、解禁、额外字段

from kedu import (
    get_mtss,
    get_margincash_stocks,
    get_marginsec_stocks,
    get_locked_shares,
    get_extras,
)

get_extras 当前只支持这些 info

  • is_st
  • unit_net_value
  • acc_net_value
  • adj_net_value

安装

uv sync

认证

交互式使用:

from kedu import auth

auth("default", "<clickhouse_password>")

脚本使用环境变量:

export CLICKHOUSE_USER=default
export CLICKHOUSE_PASSWORD=your_password
export CLICKHOUSE_HOST=localhost
export CLICKHOUSE_PORT=8123
export CLICKHOUSE_DATABASE=jqdata

然后在脚本里:

from kedu import auth_from_env

auth_from_env()

get_client() 在未认证时会直接报错,不会静默读取环境变量。

常用命令

UV_CACHE_DIR=/tmp/uv uv run pytest
UV_CACHE_DIR=/tmp/uv uv run ruff check .
UV_CACHE_DIR=/tmp/uv uv run ruff format .

单测示例:

UV_CACHE_DIR=/tmp/uv uv run pytest tests/test_fundamentals.py -xvs
UV_CACHE_DIR=/tmp/uv uv run pytest tests/test_index.py -xvs

数据回补脚本

仓库内常用脚本:

  • scripts/rebuild_from_jq.py:全量回补基本面、日线、可选分钟线
  • scripts/backfill_stk.py:回补 finance 的股票类表
  • scripts/backfill_fund.py:回补基金类表、基金日线
  • scripts/backfill_index.py:回补指数成分、权重、估值
  • scripts/backfill_industry.py:回补行业、概念及其历史成分
  • scripts/backfill_margin.py:回补融资融券数据
  • scripts/backfill_locked_shares.py:回补限售解禁数据
  • scripts/backfill_jq.py:回补交易日历、估值、is_st
  • scripts/update_jqdata.py:盘后增量更新入口
  • scripts/status.py:检查各表新鲜度

校验

测试会把本地结果和线上 jqdatasdk 逐字段比对。已覆盖的模块包括:

  • 基本面三组接口
  • finance.run_query / run_offset_query
  • get_price 日线、基金日线、可选分钟线
  • 交易日历、证券列表
  • 行业、概念、指数
  • 融资融券
  • get_locked_shares
  • get_extras

运行全部测试:

UV_CACHE_DIR=/tmp/uv uv run pytest

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

kedu-0.1.2.tar.gz (54.3 kB view details)

Uploaded Source

Built Distribution

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

kedu-0.1.2-py3-none-any.whl (71.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kedu-0.1.2.tar.gz
  • Upload date:
  • Size: 54.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kedu-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a5d17ebcb4d4281a20825a28aa30b72b0756616ecbbc158e7299addea690eada
MD5 4ea818763e25126bee5bee16bca05f28
BLAKE2b-256 de7dedfd3368188cc08ae267cdc6d23012d8aadc0c57794e60e8256611315faa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kedu-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 71.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kedu-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a49df7e41d83a7c7e96a1e683bfc107daefe90956faf9f92b08232101a516480
MD5 3b2aeb89c978cc884b181afb285a8294
BLAKE2b-256 cccc6cd662a32a5e5bf712fc379370ee2acdf25ffeddaefb12ee586fb91b31a1

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