Skip to main content

A-share quote source router with pytdx failover, easyquotation fallback and audit trail

Project description

aquote-router

aquote-router is a lightweight A-share quote source router for research tooling. It routes provider calls, records source attempts, and returns normalized Python dataclasses. It is infrastructure only: it does not provide investment advice, order execution, account login, screening, timing signals, or performance claims.

Features

  • realtime_quotes, full_realtime_quotes, and index_realtime route through pytdx -> easyquotation_sina -> easyquotation_tencent.
  • minute_kline, daily_kline, and unified kline are pytdx-only.
  • pytdx servers are ordered by primary -> hot_backup -> backup, then by latency_ms.
  • probe-pytdx can generate a local active pytdx server pool for diagnostics.
  • Return models include source, source_level, is_fallback, fallback_from, and trace_id.
  • JSONL and SQLite audit logs record attempts, fallback_chain, selected_source, duration, record count, and final error details.
  • The default test suite is offline. Live smoke checks require explicit opt-in.

Install

python -X utf8 -m pip install aquote-router

Local development:

python -X utf8 -m pip install -e ".[dev,test]"

Quick Start

from aquote_router import QuoteRouter

router = QuoteRouter.from_config(
    pytdx_servers_path="config/pytdx_servers.example.json",
    source_policy_path="config/source_policy.example.yaml",
    audit_jsonl_path="logs/aquote_router_audit.jsonl",
    audit_sqlite_path="logs/aquote_router_audit.sqlite3",
)

records = router.realtime_quotes(["000001", "600000"])
for record in records:
    print(record.to_dict())

K-line examples:

router.minute_kline("000001", period="15m", count=120)
router.daily_kline("000001", count=120)
router.kline("000001", period="1d", count=120)

Public API

router.realtime_quotes(["000001", "600000"])
router.full_realtime_quotes(["000001", "600000"])
router.index_realtime(["000001", "399001"])
router.minute_kline("000001", period="15m", count=120)
router.daily_kline("000001", count=120)
router.kline("000001", period="1d", count=120)
router.diagnose()

CLI

aquote-router realtime 000001 600000
aquote-router full 000001 600000
aquote-router full-realtime 000001 600000
aquote-router index 000001 399001
aquote-router minute 000001 --period 15m --count 120
aquote-router daily 000001 --count 120
aquote-router kline 000001 --period 15m --count 120
aquote-router kline 000001 --period 1d --count 120
aquote-router probe-pytdx --json --output config/pytdx_servers.active.local.json
aquote-router diagnose --json

Use --json for complete output, especially when table columns are too wide. CLI failures return a non-zero exit code and a structured project error code.

When K-line calls time out, first refresh a local pytdx pool:

aquote-router probe-pytdx --json --output config/pytdx_servers.active.local.json

Then pass the active local pool explicitly:

aquote-router kline 000001 --period 15m --count 10 \
  --pytdx-servers config/pytdx_servers.active.local.json --json

config/pytdx_servers.active.local.json is an observed local diagnostic result and should not be committed. Free pytdx server availability changes by network, region, and time; this project does not promise that every environment can connect at every time.

Source Policy

Default realtime routing:

realtime_quotes: pytdx -> easyquotation_sina -> easyquotation_tencent
full_realtime_quotes: pytdx -> easyquotation_sina -> easyquotation_tencent
index_realtime: pytdx -> easyquotation_sina -> easyquotation_tencent

Default K-line routing:

minute_kline: pytdx only
daily_kline: pytdx only
kline: pytdx only

K-line APIs never fall back to easyquotation and never fabricate bars. Realtime APIs may fall back to easyquotation_sina or easyquotation_tencent after pytdx failures, but K-line APIs do not use easyquotation fallback.

Core Docs

Audit Trail

Each routed call receives a trace_id. Audit records include:

  • api_name
  • symbols
  • started_at, finished_at, duration_ms
  • selected_source, selected_source_level
  • attempts
  • fallback_chain
  • success
  • error_type, error_message
  • record_count

See docs/AUDIT_TRAIL.md.

Risk Notice

This package does not produce market data. It calls upstream public Python libraries and their public interfaces. Upstream data may be delayed, unavailable, incomplete, or structurally changed. Users are responsible for validating data quality and following the terms of each upstream project.

License

MIT License. See LICENSE.

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

aquote_router-0.2.1.tar.gz (55.8 kB view details)

Uploaded Source

Built Distribution

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

aquote_router-0.2.1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file aquote_router-0.2.1.tar.gz.

File metadata

  • Download URL: aquote_router-0.2.1.tar.gz
  • Upload date:
  • Size: 55.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aquote_router-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3c5447ae6bd5940526c8aec26034f38b382f162e2db53d536422c8fc58f667d3
MD5 094c59e8eb964adad410bfde132fa24e
BLAKE2b-256 e6bf870a4e805af435d8ae58d8714ad5a6ff49ccf600d4ebc2fed4552807f10d

See more details on using hashes here.

Provenance

The following attestation bundles were made for aquote_router-0.2.1.tar.gz:

Publisher: publish.yml on tabman2026/aquote-router

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aquote_router-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: aquote_router-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 29.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aquote_router-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e837d3f0d552702796f201fabe444ae46c3d15b5bb0fb9986f3948aee7f23ca3
MD5 3425cbd6bd9dcb50531c727a3217d4c2
BLAKE2b-256 71df11111f2da88ff6a8427045f218f230a97a53773d6aeb10e682a231f3d776

See more details on using hashes here.

Provenance

The following attestation bundles were made for aquote_router-0.2.1-py3-none-any.whl:

Publisher: publish.yml on tabman2026/aquote-router

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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