wmshare-qlib
wmshare-qlib turns wmshare A-share market
data into Microsoft Qlib-native format — backtestable .bin panels,
ScoreFileModel score CSVs, and instrument universe files — so you can run Qlib's
research pipeline without writing the format bridge yourself.
The adapter is a translation layer, not a data source: it never computes factors and
never fabricates history. What upstream serves with dates becomes a .bin series;
what upstream only serves as a current value is emitted as a dated score snapshot,
never pasted across history.
Install
pip install wmshare-qlib # core
pip install 'wmshare-qlib[qlib]' # + pyqlib, for .bin read-back verification
Requires Python 3.11 — the only supported interpreter (3.12+ is refused at install time; pyqlib ships no wheels for it). From source:
git clone https://github.com/open-winmale/wmshare-qlib.git
cd wmshare-qlib && pip install -e '.[qlib]'
Quick start A — free trial, no credentials (start here)
Since wmshare 3.x there is one data mode (live) — and it works with no
credentials at all: the SDK's from_env() returns a public-pool free-trial
client (zero network at construction; requests carry no token). Configure
nothing and start pulling real data:
# 0) Preview the run scope — fires nothing
wmshare-qlib dump-history --symbols 600519 000858 --n 60 --dry-run
# 1) History panel -> Qlib .bin
wmshare-qlib dump-history --symbols 600519 000858 --n 60 --max-ec 30000 --out ./out/qlib_data
# 2) Read one value back with Qlib's own reader
# Without pyqlib this prints UNAVAILABLE (ok=None) — never a false PASS.
wmshare-qlib verify --qlib-dir ./out/qlib_data --check SH600519:close:<date>:<close>
# 3) Today's cross section -> score CSV (ScoreFileModel input)
wmshare-qlib dump-cross-section --via snapshot --symbols 600519 000858 601318 \
--max-ec 1000 --out ./out/score
Two things to know about the free trial:
- It is a shared pool — every unregistered caller of your network draws from the same quota, so a quota/rate refusal is terminal (retrying does not help). Real work wants real credentials (Quick start B).
--anonymousforces this mode even when credentials exist; setWMSHARE_DISABLE_ANON=1to forbid the fallback entirely (missing credentials then fail loud again).
The offline demo snapshot (
wmshare.demo_client()) was removed by the SDK in wmshare 3.0 and retired here in 0.7.0 — the free trial replaced it as the zero-credential path.
Quick start B — production (real data, your own account)
Credentials from https://open.winmale.com (我的 → 开放平台 → 我的应用 → 查看应用信息
— copy both client_id and api-key):
export WMSHARE_CLIENT_ID=your_client_id
export WMSHARE_CLIENT_SECRET=your_api_key
# or write them to ~/.wmshare/credentials.env (the SDK reads that file)
Then the same commands run against your own account:
# One-time bulk: builds the fragment store under hfq_factor
wmshare-qlib dump-history --symbols 600519 000858 \
--n 60 --max-ec 30000 --out ./out/qlib_data
# Daily incremental after that (fetches only NEW bars, then re-dumps)
wmshare-qlib update-history --max-ec 20000 --out ./out/qlib_data
Two rules worth knowing before you type them:
--max-ecis required on every live path. It is a budget ceiling, not a hint: the run stops submitting work once the ceiling is reached. If a run stops early with a ceiling message, raise the ceiling —--resumepicks up where it left off.- Incremental appends need the immutable hfq basis. Stores dumped under an
older convention (or predating the
adjustparam) are refused byupdate-history— rebuild once withdump-history. See docs/faq.md.
Want this to run itself? tools/daily_update.sh + a launchd template do the
daily update, PIT snapshot and an offline freshness verdict on a schedule —
see docs/getting-started.md.
--dry-run exists on dump-history, update-history, dump-cross-section and
accumulate — it prints the run scope and fires nothing:
wmshare-qlib dump-history --symbols 600519 --n 60 --dry-run --max-ec 30000
What it produces
out/qlib_data/
├── calendars/day.txt # ascending trading dates
├── instruments/all.txt # INST\tstart\tend (write-universe adds named ones)
├── features/sh600519/*.day.bin # Qlib float32: [start_index, values...] where
│ # values[0] is calendar[start_index]
│ # (includes $vwap, derived as amount/volume)
├── _resume/ # fragment store: manifest + per-symbol parquet
└── fetch_meta.json # params, metering, warnings
format.py is the single source of truth for the on-disk contract and is
Qlib-free (pure numpy). Only qlib_io.py imports Qlib, and only to read back — in a
child process, so importing this package never reconfigures your Qlib session.
The three-layer data model
Only the first layer is backtestable today:
- Real history — kline (OHLCV+amount), moneyflow,
pe/pb/ps/pr(10y window,config.VALUATION_WINDOW), plus the materializedvaluation.daily_basicfamily (pe_ttm/total_mv/circ_mv/turnover_rate/dv_ttm) via--daily-basic. Dumped straight into Qlib.bin.$vwapis derived at dump time (amount/volume; the stored volume is already factor-adjusted, so it is consistent with the adjusted prices) — Alpha158 can consume it unmodified. - Today only — the screener/indicator domain's ~2,750 precomputed metric
codes expose a current value, and their querying surface accepts no date
parameter at all — requesting their past values is inexpressible upstream.
This is a different upstream catalog from the valuation fields of layer 1
(which do carry dated series). Emitted as
score/<date>.csvfor online scoring, markedhistory=false. Never pasted across past dates. - Self-built PIT series —
accumulateappends one real snapshot per day; the series is available from its first captured day and grows one real day at a time, with--min-daysgating promotion to a backtestable panel.
Full detail, including why layer 2 cannot be fixed client-side: docs/data-model.md.
Commands
| Command | Purpose | Key flags |
|---|---|---|
dump-history |
fetch history → Qlib .bin |
--symbols --n/--years --workers --max-ec --resume --adjust --store --daily-basic --anonymous |
update-history |
incremental daily tails → reconcile → re-dump (hfq only) | --max-ec (required unless --dump-only) --tail-overlap --valuation-days --daily-basic --dump-only --anonymous |
dump-cross-section |
today's score CSV | --via screener/snapshot --idx --max-ec --anonymous |
accumulate |
append one daily PIT snapshot (prints availability + promotion status) | same dispatch + --as-of (default: today) --min-days |
accumulate-margin |
append one daily margin (两融) snapshot — Layer-3 forward-only PIT; --catchup K is the only sanctioned backfill (a real margin.query read) |
--symbols --catchup --max-ec --anonymous |
write-universe |
instruments/<name>.txt from index membership or a codes file; --index prefers PIT membership episodes when the SDK exposes index.members_history (one episode per membership run; dropped members keep their closed episode — survivorship-safe) |
--index/--codes-file --exclude-st --exclude-suspended --max-ec --anonymous |
verify |
read .bin back with Qlib's own reader |
--qlib-dir --check inst:field:date:value |
reconcile-daily-basic |
Gate B: accumulated PIT vs official daily_basic history (100% or fail) | --accumulated --upstream --tol, or --from-upstream --store --max-ec |
--dry-run is available on four of them: dump-history, update-history,
dump-cross-section, accumulate.
Budgets
Every live command takes a required --max-ec — a budget ceiling, not a
hint. The run stops submitting work once the ceiling is reached: per-symbol
paths stop between batches, one-shot paths (screener/snapshot cross-section,
margin) check post-hoc after the single request returns. If a run stops early
with a ceiling message, raise the ceiling and re-run — --resume picks up
where it left off. --dry-run prints the run scope before anything fires.
Two usage rules the ceiling exists to protect:
- Use
--nfor increments, never range (begin/end) queries — a range query is bounded by the server's anchor window, not by the rows you asked for (see docs/data-model.md). - Keep a daily cadence on a scoped universe —
--via snapshotover an explicit ~300-name list, or--idx index.hs300on the screener path. Full-market scans are a weekly/monthly cadence at most; full-market daily is not viable on any current endpoint.
Every fetch result carries a metering record (requests, note,
auth_mode) written to fetch_meta.json / *.meta.json.
Data-correctness gates
.binlayout —features/<inst>/<field>.day.binis[start_index, values…]wherevalues[0]is the value forcalendar[start_index]and the payload ends at the instrument's own last date — exactly what Qlib's reader resolves (seek(4*(i-start_index)+4)) and what Qlib'sdump_binwrites. Dumps made by ≤ 0.7.0 whose instruments did not all start on the calendar's first day were shifted; re-dump them locally, offline:wmshare-qlib update-history --dump-only --store <store> --out <out>.- Direction — every series is asserted ascending (2.x contract); a silently descending series would flip every rolling computation.
- Unit invariants — amounts in CNY, volumes in shares, ratios dimensionless; absurd magnitudes raise rather than flow into a backtest.
- Duplicate/conflict — duplicated dates with identical values are deduplicated with a warning; conflicting duplicates raise. Incremental tails are merged into the store, never overwritten, so a gap between updates cannot drop bars.
- Reconciliation gate — incremental tails must agree with stored history within float tolerance. An upstream revision fails loud; history is never silently rewritten.
- Gate B — accumulated PIT values are cross-checked against official
daily_basichistory, 100% agreement on a non-empty overlap or fail (an empty comparison, e.g. a budget-truncated pull, is reported as INCOMPLETE).
Qlib compatibility & low-intrusion design
The dumper targets Qlib's own on-disk layout, verified against
microsoft/qlib's data collector conventions:
factor = hfq/rawper date, with adjusted prices stored (live default); upstream volume is not adjusted, so it is divided by factor to keepclose × volume == amountinvariant across ex-dividend dates.qlib.init()runs only in a child process during read-back; the parent process'sqlib.config.Cis asserted untouched in the test suite.pyqlibis an optional extra; the dumper and its self-check need only numpy.
Module map
config.py— fields, units, metric-code selectionnormalize.py— anti-pitfall guards (direction, code mapping, unit, cold cache);merge_adjusted_klines(hfq+raw → factor)fetch.py— live acquisition (credentials or public-pool free trial) + metering + budget-ceiling executor + bounded transient retriespanel.py— integrity assertions (incl. the factor gate) + wide transformdump.py/format.py— Qlib-compatible.bindumper and its on-disk contract (Qlib-free)qlib_io.py— the only module that imports Qlib; child-process read-back + score readerresume.py— fragment store (bulk + incremental tails) + manifest with convention guard and reconciliation gatecross_section.py— score CSV + PIT accumulation/promotionreconcile.py— Gate B comparisoncli.py— the seven commands
Tests
# Tier 1 (mandatory in CI, offline, no credentials, no network)
pytest tests -q -m "not live"
# Tier 2 (optional) — adds the child-process Qlib read-back cross-check
pip install 'wmshare-qlib[qlib]'
pytest tests -q -m qlib
Offline tests run against synthetic SDK-shaped stubs, so they need no
credentials and never touch the network. Tier 1 verifies the dumped .bin with
pure numpy (format.read_bin_selfcheck); Tier 2 additionally reads it back
through Qlib itself. Live tests are opt-in (gated by WMSHARE_QLIB_LIVE=1) and
require REAL credentials — a public-pool free-trial client is skipped loudly.
See CONTRIBUTING.md.
What we deliberately do NOT do
- Fabricate history from today's snapshot (red line — see layer 2 above).
- Recompute upstream precomputed metrics client-side and present them as wmshare values.
- Per-symbol
indicator.getloops (slow and 429-prone). - Run a live metric-code
screener.querywithout an explicit--max-ecbudget. - Call
qlib.init()in the caller's process (global side effect). - Touch the wmshare main repo (separate repo, no version-bump churn).
See also
- Getting started — install to first
.bin, free trial then production credentials. - Data model — the three availability tiers and why layer 2 cannot be fixed client-side.
- FAQ — free-trial boundaries, hfq vs qfq, error reference.
- Contributing — tests, lint, and the red lines.
- Changelog
- wmshare — the data SDK this adapter translates.
- wmshare-vnpy — the same history panel injected into vnpy.alpha.
- Examples —
dump_to_qlib.py,online_score.py,alpha158_lgbm.py,benchmark/. - Design history and forward plans (engineering records, not user docs): docs/internal/.
Acknowledgements
Built on wmshare (BSD-3-Clause). Not affiliated with or endorsed by Microsoft; Qlib/pyqlib is used unmodified as an optional verification dependency only.
License
BSD-3-Clause — see LICENSE.
Metadata
Release files for wmshare-qlib 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wmshare_qlib-1.0.0.tar.gz | 127.5 kB | Without provenance | Details for wmshare_qlib-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wmshare_qlib-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for wmshare_qlib-1.0.0-py3-none-any.whl |
Total release size: 208.5 kB
Security for wmshare-qlib 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.