Open-source project
waditu/czsc avatar
waditu/czsc

czsc 1.0 moved Chan theory detection out of Python and into czsc._native

A technical-analysis toolkit for Chanlun (Chan Theory) trading methodology, covering stocks, futures and quantitative trading.

6,637 stars1,821 forksRustLicense varies

At a glance

What is it?
czsc rewrote its Chan theory core in Rust for the 1.0 line and shipped it to Python through a PyO3 extension, which moved the algorithm work out of interpreted code.
Who is it for?
czsc fits quants who already follow Chan theory and want fractal, bi and zhongshu recognition plus signal composition behind one import, and it fits them badly if they need documented connector credentials, a public API that stays put between releases, or a self contained route to a backtest report.
Can I use it commercially?
Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
Is it still maintained?
Yes. The repository last received commits 17 days ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • waditu/czsc6,637 ★ · +377
Star history
Repository2026-09-232026-11-25
waditu/czsc6.3k6.6k

377 Stars in the last 63 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Fractal, bi and zhongshu detection now happens inside czsc._native

Since the 1.0 line, czsc no longer finds fractals, bi or zhongshu in Python. Those core Chan theory structures moved into a Rust extension exposed to Python as czsc._native, and the objects you keep working with afterwards (CZSC, FX, BI, ZS, RawBar, NewBar, BarGenerator) all originate there. Readers who want to read the old algorithm path are sent to the 0.9.X tree, which the project links under the v0.9.69 tag.

The calling code stays plain Python. You build a list of RawBar objects and hand it to CZSC; recognition happens on the Rust side and comes back as two counters:

python
import czsc
from czsc import CZSC, Freq, format_standard_kline
from czsc.mock import generate_symbol_kines

# 生成模拟 K 线数据
df = generate_symbol_kines('000001', '30分钟', '20240101', '20240601')

# 转换为 RawBar 对象列表
bars = format_standard_kline(df, freq=Freq.F30)

czsc_obj = CZSC(bars)
print(f"笔数量:{len(czsc_obj.bi_list)}")
print(f"中枢数量:{len(czsc_obj.zs_list)}")

BarGenerator is the other half of the story, and it works the same way. Give it a base frequency and the frequencies you want, push raw bars into update(), and read the aggregated series back out of its bars mapping.

python
from czsc import BarGenerator, Freq

bg = BarGenerator(base_freq='1分钟', freqs=['5分钟', '30分钟', '日线'])
for bar in raw_bars:
    bg.update(bar)

bars_30m = bg.bars['30分钟']

from czsc import run_replay, run_research

run_replay(bars, signals_seq, pos_seq, res_path='./results/')

So the shape of a run is: bars in, structures and signals out, and the amount of Python you write shrinks to the plumbing around those calls.

Nine Cargo crates sit under the one Python package

The Rust side is a Cargo workspace declared with members = ["crates/*"], and the project names nine members: czsc, czsc-core, czsc-derive, czsc-signals, czsc-trader, czsc-utils, czsc-ta, czsc-signal-macros and czsc-python. The last one is the binding entry point. pyproject.toml points maturin at crates/czsc-python/Cargo.toml, sets module-name to czsc._native, and sets python-source to the repository root, so the pure Python czsc/ tree is copied into the wheel next to the compiled extension.

pyo3 appears in [workspace.dependencies] at version 0.29 with no features attached, deliberately, so unit tests inside the business crates link against a real libpython resolved through PYO3_PYTHON. Only the cdylib producer layers on extension-module plus abi3-py310, which is why a single wheel can claim support for Python 3.10 through 3.13, matching the classifiers, instead of one build per interpreter. The workspace itself runs edition 2024 with resolver 2, and the crates point their documentation field at docs.rs/czsc-core.

Signal functions are string paths, and events combine them

A signal is a named function you refer to by fully qualified string, not an object you construct. Two helpers parse what a list of those strings needs: get_signals_freqs returns the frequencies involved, get_signals_config returns the configuration, and generate_czsc_signals produces the series.

python
from czsc import generate_czsc_signals, get_signals_config, get_signals_freqs

signals_seq = [
    "czsc._native.signals.bar.bar_end_V230331",
    "czsc._native.signals.cxt.cxt_bi_status_V230101",
]

freqs = get_signals_freqs(signals_seq)
config = get_signals_config(signals_seq)

results = generate_czsc_signals(bars, signals_seq)

Two counts appear in the project documentation and they disagree: the architecture section says 220+ signal functions spread over seven Python side submodules under crates/czsc-signals/src/, while the walkthrough of the signal module says 246. Treat the number as approximate rather than as a contract.

Composition happens above the functions. Signals become events through signals_all, signals_any and signals_not, so the combination decides whether an Event exists, and Position objects derive from events rather than from raw signals. Anything counting on a specific signal name has to survive a rename.

cargo stops in build.rs when the default Python is older than 3.10

There are three ways in, and they cost different amounts. A prebuilt wheel is one command:

bash
pip install czsc -U

uv pip install czsc is the option the project points at for development environments. Building from source is the third path, and it needs a Rust toolchain plus maturin:

bash
git clone https://github.com/waditu/czsc.git
cd czsc
maturin develop --release

The Python floor is 3.10, and it is enforced inside the build rather than by the installer. pyo3 and pyo3-stub-gen 0.22 both require 3.10 or newer, so on a machine whose default interpreter is older, cargo build and cargo test panic early inside crates/czsc-python/build.rs and print a repair hint. Naming any 3.10+ interpreter gets you past it:

bash
export PYO3_PYTHON=$(which python3.12)   # 或任意 3.10+ 的解释器

The uv route avoids the trap, since uv sync --extra dev selects the interpreter the project declares. If you are on an older system Python and did not choose uv, expect that panic before you suspect your own code.

The weight backtest and its HTML report come from wbt, not from czsc

The package boundary gets blurry at the backtesting examples. WeightBacktest appears in the API table with the note that it comes from wbt, and it consumes a weighted frame plus a fee rate:

python
from czsc import WeightBacktest
from czsc.mock import generate_klines_with_weights

dfw = generate_klines_with_weights(seed=42)

wb = WeightBacktest(dfw, fee_rate=0.0002)
print(wb.stats)

The report generator is imported from wbt as well, not from czsc:

python
from wbt import generate_backtest_report

generate_backtest_report(df=dfw, output_path="report.html", weight_type="ts")

So the division of labour is: czsc supplies bars and signals, wbt supplies the weight series, the fee arithmetic and the HTML output. The example data comes from czsc.mock rather than from a connector. The same split shows up in the plotting entry points: plot_czsc and plot_czsc_trader live under czsc.utils.plotting.lightweight and emit self contained HTML, while wbt.generate_backtest_report handles the report.

Three licence declarations, and two of them disagree

Read both manifests before you vendor anything. pyproject.toml declares license = "Apache-2.0" for the Python distribution, while the Cargo workspace declares its own licence and its repository, documentation and homepage fields:

toml
license       = "MIT"
repository    = "https://github.com/waditu/czsc"
homepage      = "https://github.com/waditu/czsc"
documentation = "https://docs.rs/czsc-core"

The repository metadata itself asserts no licence at all, so a package index looking at the API response sees nothing to report. The visible files do not explain the split between an Apache 2.0 Python distribution and a workspace of MIT licensed crates, and this is not legal advice, it is a reading of three files that do not match.

There is a second licence related detail worth knowing if you package rather than consume. pyproject sets license-files = ["LICENSE"], and its own comments record that v1.0.0-rc.5 published a wheel successfully while the sdist upload came back 400 because that field was missing. That fix is now in place, but it is the kind of packaging detail that only shows up at upload time.

The connectors are named, their configuration is not

czsc.connectors is described as the data source layer, with Tianqin, Tushare, CCXT and a local cache listed as its members. None of the README's quick-start examples uses one. That is what makes the mock route the only fully specified path: every runnable snippet starts from generate_symbol_kines or generate_klines_with_weights, both in czsc.mock, and format_standard_kline turns the frame into RawBar objects at a chosen frequency.

The research helpers sit on top of that same bar input. run_replay walks one symbol, run_research walks a list of symbols, and both take signals_seq, pos_seq and a res_path directory that you name. The README's quick-start examples do not show what happens when a connector fails, whether a partial bar from an unfinished interval reaches BarGenerator, or how pos_seq is supposed to be built, so those three points are where you will be writing glue rather than calling the library.

The written documentation lives on a wiki that is not versioned

Very little prose documentation sits in the repository. The project links out to a Feishu wiki for the main docs, a second page for shared research data, a third for the rules on writing signal functions, and a generated overview on DeepWiki. End to end cases get their own page, including one for reproducing CZSC and CzscTrader throughput locally with a metrics quick reference, one for exporting Chan theory structures as offline HTML through lightweight charts, and one for overlaying signal trigger points on the candlestick main chart.

Tutorials are video, on Bilibili, and there is a Feishu group for people already doing quant research with the library. A separate product, an LLM assisted research platform with an invite code, is advertised in the same table and is described as an internal test focused on time series price and volume timing strategies.

None of that is pinned to a tag. The repository does carry CHANGELOG.md, CLAUDE.md, docs/, tests/, scripts/, rust-toolchain.toml and uv.lock at the top level, so the questions a new user most needs answered, such as what changed between 0.9 and 1.0 and which signal names moved, are split between a changelog that does not move and a wiki that can change under you. The Rust side also carries one dependency pin you will notice: polars is held at 0.52.0 because polars-arrow 0.53.x constrains chrono to <=0.4.41, which collides with the chrono ^0.4.44 that pyo3-stub-gen 0.21 and later require.

Editorial conclusion

czsc fits quants who already follow Chan theory and want fractal, bi and zhongshu recognition plus signal composition behind one import, and it fits them badly if they need documented connector credentials, a public API that stays put between releases, or a self contained route to a backtest report. Before adopting it, read both manifests for the licence question, diff CHANGELOG.md against the signal names your strategy already calls, and pin an exact version, since 0.9 to 1.0 relocated those functions into czsc._native and renamed nothing politely.

Frequently asked questions

What Python version does czsc 1.0 require?

Python 3.10 or newer, with classifiers covering 3.10, 3.11, 3.12 and 3.13. On an older default interpreter the Rust build panics inside crates/czsc-python/build.rs, so PYO3_PYTHON has to point at a 3.10+ interpreter.

How do I install czsc and run a first Chan theory analysis?

pip install czsc -U pulls the prebuilt wheel and uv pip install czsc is the development option. The first run generates mock klines with generate_symbol_kines, converts them with format_standard_kline, passes the bars to CZSC, and prints how many bi and zhongshu were found.

Can I keep the old Python signal logic on czsc 1.0?

No. Fractal and bi recognition runs in Rust behind czsc._native from 1.0 onward, and the project points readers who need the previous implementation at the 0.9.X tree under the v0.9.69 tag.

Where does the weight backtest in the czsc examples come from?

WeightBacktest and generate_backtest_report are documented as coming from wbt, a separate distribution. The bars and signals fed into it do come from czsc.

Official sources

  1. Issues
  2. README
  3. Releases
  4. waditu/czsc on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/waditu-czsc.svg)](https://hysenlabs.com/projects/waditu-czsc)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/waditu-czsc.svg)](https://hysenlabs.com/projects/waditu-czsc)

Was this useful?