feat(adapters): V6 Phase 4 — canonical adapter namespaces (re-exports)#30
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces the Phase-4 src.adapters.* canonical adapter namespace as an additive layer on top of the existing “V5” modules, plus a convergence test to ensure canonical imports resolve to the same underlying objects as legacy imports.
Changes:
- Add
src/adapters/{data,realtime,broker,storage,ml,messaging}/packages that (mostly) re-export legacy implementations. - Add
tests/test_adapters_convergence.pyto assert canonical imports converge to legacy objects. - Update architecture/changelog docs to reference the new adapter entry points.
Reviewed changes
Copilot reviewed 45 out of 45 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_adapters_convergence.py | Adds import convergence tests for canonical vs legacy adapter paths. |
| src/adapters/init.py | Defines the top-level canonical src.adapters namespace. |
| src/adapters/broker/init.py | Introduces canonical broker exports + a gateway factory/registry. |
| src/adapters/broker/base_live_gateway.py | Re-exports base live gateway types from legacy gateway layer. |
| src/adapters/broker/hundsun_uft_gateway.py | Re-exports HundsunUftGateway from legacy gateways. |
| src/adapters/broker/mappers.py | Re-exports broker symbol/order mapper types from legacy gateways. |
| src/adapters/broker/xtp_gateway.py | Re-exports XtpGateway from legacy gateways. |
| src/adapters/broker/xtquant_gateway.py | Re-exports XtQuantGateway from legacy gateways. |
| src/adapters/data/init.py | Aggregates canonical data adapter exports. |
| src/adapters/data/data_portal.py | Compatibility alias module for canonical data portal export. |
| src/adapters/data/level2.py | Re-exports Level2 models/providers from legacy data_sources. |
| src/adapters/data/portal.py | Re-exports DataPortal/create_portal from legacy data_sources. |
| src/adapters/data/providers.py | Re-exports provider types + get_provider from legacy data_sources. |
| src/adapters/data/quality.py | Re-exports data quality helpers from legacy data_sources. |
| src/adapters/data/trading_calendar.py | Re-exports trading calendar helpers from legacy data_sources. |
| src/adapters/realtime/init.py | Aggregates canonical realtime adapter exports. |
| src/adapters/realtime/feed.py | Re-exports realtime feed/data manager primitives from legacy core. |
| src/adapters/realtime/providers.py | Re-exports a narrower provider surface for canonical realtime providers. |
| src/adapters/storage/init.py | Aggregates canonical storage adapter exports. |
| src/adapters/storage/data_lake.py | Re-exports DataLake/DataLakeEntry from legacy platform module. |
| src/adapters/storage/db_manager.py | Compatibility alias module for canonical SQLite storage export. |
| src/adapters/storage/duckdb.py | Re-exports DuckDB store config/store from legacy data_sources. |
| src/adapters/storage/duckdb_store.py | Compatibility alias module for canonical DuckDB storage export. |
| src/adapters/storage/parquet_lake.py | Re-exports parquet data lake + quality gate types from legacy platform module. |
| src/adapters/storage/repository.py | Re-exports repository interfaces/constructors from legacy core. |
| src/adapters/storage/sqlite.py | Re-exports SQLite data manager from legacy data_sources. |
| src/adapters/ml/init.py | Aggregates canonical ML adapter exports. |
| src/adapters/ml/data.py | Re-exports ML data adapter utilities from legacy mlops. |
| src/adapters/ml/data_adapter.py | Compatibility alias module for canonical ML data adapter export. |
| src/adapters/ml/finrl.py | Re-exports FinRL frame builder from legacy mlops. |
| src/adapters/ml/finrl_adapter.py | Compatibility alias module for canonical FinRL adapter export. |
| src/adapters/ml/inference.py | Re-exports inference service/runner from legacy mlops. |
| src/adapters/ml/model_registry.py | Compatibility alias module for canonical model registry export. |
| src/adapters/ml/qlib.py | Re-exports Qlib frame builder from legacy mlops. |
| src/adapters/ml/qlib_adapter.py | Compatibility alias module for canonical Qlib adapter export. |
| src/adapters/ml/registry.py | Re-exports model registry types from legacy mlops. |
| src/adapters/ml/signals.py | Re-exports ML signal normalization/schema from legacy mlops. |
| src/adapters/ml/strategy.py | Re-exports AI signal strategy adapter from legacy mlops. |
| src/adapters/ml/strategy_adapter.py | Compatibility alias module for canonical strategy adapter export. |
| src/adapters/ml/training.py | Re-exports training adapters/artifacts from legacy mlops. |
| src/adapters/messaging/init.py | Aggregates canonical messaging adapter exports. |
| src/adapters/messaging/bus.py | Re-exports message bus types/backends from legacy core. |
| src/adapters/messaging/message_bus.py | Compatibility alias module for canonical message bus export. |
| docs/ARCHITECTURE_TARGET_STATE.md | Documents the canonical adapter entry points and legacy compatibility. |
| CHANGELOG.md | Adds changelog entry for adapter convergence + updates tests notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+23
to
+30
| _GATEWAY_IMPORTS: Dict[str, Tuple[str, str]] = { | ||
| "xtquant": ("src.adapters.broker.xtquant_gateway", "XtQuantGateway"), | ||
| "qmt": ("src.adapters.broker.xtquant_gateway", "XtQuantGateway"), | ||
| "miniqmt": ("src.adapters.broker.xtquant_gateway", "XtQuantGateway"), | ||
| "xtp": ("src.adapters.broker.xtp_gateway", "XtpGateway"), | ||
| "hundsun": ("src.adapters.broker.hundsun_uft_gateway", "HundsunUftGateway"), | ||
| "uft": ("src.adapters.broker.hundsun_uft_gateway", "HundsunUftGateway"), | ||
| } |
Comment on lines
+46
to
+53
| def test_broker_adapter_namespace_reexports_legacy_gateway_objects() -> None: | ||
| assert CanonicalGatewayConfig is GatewayConfig | ||
| assert CanonicalBaseLiveGateway is BaseLiveGateway | ||
| assert canonical_create_gateway is not create_gateway | ||
| assert canonical_create_gateway( | ||
| "xtquant", GatewayConfig(account_id="demo", broker="xtquant"), None | ||
| ).__class__.__name__ == ("XtQuantGateway") | ||
|
|
Comment on lines
+7
to
+15
| - V6 Phase 2 (open platform): freeze the open-platform contract surface in a new `src/core/contracts/` package. Adds `CONTRACT_VERSION = "0.1.0"` with a semver compatibility helper, immutable validated DTOs (`Instrument`, `Bar`, `Tick`, `OrderBookSnapshot`, `Order`, `Fill`, `Position`, `AccountSnapshot`, `Signal`, `RiskCheckResult`, `BacktestResult`), 18 `typing.Protocol` ports (Data / Execution / Risk / Observability / Messaging / Services) covering every entry-point group declared in Phase 0, and `PluginManifest` with known-capability and known-permission allow-lists. Purely additive — V5 modules (`src/core/interfaces.py`, `src/core/objects.py`, `src/core/plugin.py`) are untouched. | ||
| ### Added | ||
| - Architecture (V6 Phase 3 — Adapters convergence): add canonical adapter namespaces under `src/adapters/{data,realtime,broker,storage,ml,messaging}/` with compatibility re-exports for existing data source, realtime, broker gateway, storage, MLOps, and message bus implementations. | ||
| - V6 Phase 2 (open platform): freeze the open-platform contract surface in a new `src/core/contracts/` package. Adds `CONTRACT_VERSION = "0.1.0"` with a semver compatibility helper, immutable validated DTOs (`Instrument`, `Bar`, `Tick`, `OrderBookSnapshot`, `Order`, `Fill`, `Position`, `AccountSnapshot`, `Signal`, `RiskCheckResult`, `BacktestResult`), 18 `typing.Protocol` ports (Data / Execution / Risk / Observability / Messaging / Services) covering every entry-point group declared in Phase 0, and `PluginManifest` with known-capability and known-permission allow-lists. Purely additive — V5 modules (`src/core/interfaces.py`, `src/core/objects.py`, `src/core/plugin.py`) are untouched. |
Comment on lines
+13
to
+15
| ### Added | ||
| - Architecture (V6 Phase 3 — Adapters convergence): add canonical adapter namespaces under `src/adapters/{data,realtime,broker,storage,ml,messaging}/` with compatibility re-exports for existing data source, realtime, broker gateway, storage, MLOps, and message bus implementations. | ||
| - V6 Phase 2 (open platform): freeze the open-platform contract surface in a new `src/core/contracts/` package. Adds `CONTRACT_VERSION = "0.1.0"` with a semver compatibility helper, immutable validated DTOs (`Instrument`, `Bar`, `Tick`, `OrderBookSnapshot`, `Order`, `Fill`, `Position`, `AccountSnapshot`, `Signal`, `RiskCheckResult`, `BacktestResult`), 18 `typing.Protocol` ports (Data / Execution / Risk / Observability / Messaging / Services) covering every entry-point group declared in Phase 0, and `PluginManifest` with known-capability and known-permission allow-lists. Purely additive — V5 modules (`src/core/interfaces.py`, `src/core/objects.py`, `src/core/plugin.py`) are untouched. |
The bare 'report' pattern in .gitignore matched src/engines/report/, silently excluding the file from PR #28 (V6 Phase 3 engines layer). Local tests passed because the working tree has the file, but GitHub CI failed with 'ModuleNotFoundError: No module named src.engines.report'. - Replace bare 'report' with root-anchored '/report/' so only the top-level runtime output directory is ignored. - Track src/engines/report/__init__.py (the V6 ReportPort wrapper). Verified: tests/engines/test_engines_layer.py — 23 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
V6 Phase 4 of the open-platform reorg (per
docs/ROADMAP.md§8.5 anddocs/architecture/open-platform.md).Adds canonical adapter namespaces under
src/adapters/{data,realtime,broker,storage,ml,messaging}/that re-export the existing V5 implementations from their original locations. No code moved, no behavior change.src.adapters.datasrc.data_sources.providers / data_portal / trading_calendar / qualitysrc.adapters.realtimesrc.core.realtime_data,src.core.realtime_providerssrc.adapters.brokersrc.gateways.{base_live_gateway, xtp_gateway, xtquant_gateway, hundsun_uft_gateway, mappers}src.adapters.storagesrc.core.repository,src.core.duckdb_store,src.core.data_lake,src.platform.db_managersrc.adapters.mlsrc.mlops.{model_registry, training, inference, signals, data_adapter, strategy_adapter, finrl_adapter, qlib_adapter}src.adapters.messagingsrc.core.message_busPhase 5 (Plugin SPI + SDK) is intentionally not in this PR and will land in a follow-up branch.
Tests
powershell -ExecutionPolicy Bypass -File scripts/local_ci.ps1 -Jobs test -SkipInstall→ 1263 passed, 35 skipped, 0 failed.Includes
tests/test_adapters_convergence.pyverifying every canonical adapter import resolves to the same object as the legacy V5 import path (so behavior cannot diverge).Scope
Next
src/sdk/,PluginRegistry,quant-platformCLI, plugin template, example plugin) in a follow-up branch./api/v2/info contract_version.