Skip to content

feat: read-only Trading 212 broker connector#321

Merged
warren618 merged 1 commit into
HKUDS:mainfrom
mvanhorn:fix/309-trading212-readonly-connector
Jun 29, 2026
Merged

feat: read-only Trading 212 broker connector#321
warren618 merged 1 commit into
HKUDS:mainfrom
mvanhorn:fix/309-trading212-readonly-connector

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Add a new connector package agent/src/trading/connectors/trading212/ mirroring the structure of existing read-only/paper connectors such as dhan and shoonya: __init__.py (package docstring), sdk.py (read-only operations against Trading 212's REST API: account, positions, open orders, history, instrument metadata), profiles.py (TRADING212_PROFILES, capped at read-only since the public API has no runtime paper/live discriminator, following the same hard-refuse rule Dhan/Shoonya use for place_order/cancel_order), and classification.py (TRADING212_TOOL_CLASS mapping each operation to read/write ToolClass). Wire it into the three registries that every connector touches: add the SDK module to _SDK_CONNECTOR_MODULES in agent/src/trading/service.py, import and splice TRADING212_PROFILES into BUILTIN_PROFILES in agent/src/trading/profiles.py, and import and register TRADING212_TOOL_CLASS in the classification map in agent/src/live/registry.py. Add agent/tests/test_trading212_connector.py covering profile registration, read/write classification, and the paper/live hard-refuse on order placement.

Why

The reporter requested a broker connector for Trading 212 (UK/EU retail broker). The maintainer (warren618, COLLABORATOR) responded on 2026-06-27 that Trading 212 is a reasonable candidate and a focused community PR is welcome, with the explicit scoping that the first step stay read-only and avoid live order placement until the broker exposes a clear paper/demo or structural safety boundary. The cleanest first PR is read-only account/positions/orders/history/instrument-metadata support plus connector classification, mirroring the existing connector pattern.

Closes #309

Changes

  • Add a new connector package agent/src/trading/connectors/trading212/ mirroring the structure of existing read-only/paper connectors such as dhan and shoonya: __init__.py (package docstring), sdk.py (read-only operations against Trading 212's REST API: account, positions, open orders, history, instrument metadata), profiles.py (TRADING212_PROFILES, capped at read-only since the public API has no runtime paper/live discriminator, following the same hard-refuse rule Dhan/Shoonya use for place_order/cancel_order), and classification.py (TRADING212_TOOL_CLASS mapping each operation to read/write ToolClass). Wire it into the three registries that every connector touches: add the SDK module to _SDK_CONNECTOR_MODULES in agent/src/trading/service.py, import and splice TRADING212_PROFILES into BUILTIN_PROFILES in agent/src/trading/profiles.py, and import and register TRADING212_TOOL_CLASS in the classification map in agent/src/live/registry.py. Add agent/tests/test_trading212_connector.py covering profile registration, read/write classification, and the paper/live hard-refuse on order placement.

Test Plan

  • Existing tests pass (pytest --ignore=agent/tests/e2e_backtest --tb=short -q)
  • New tests added (if applicable)
  • Tested manually (describe below)
  • Happy path: the Trading 212 profile is discoverable via BUILTIN_PROFILES and read-only operations classify as read in the live registry. - Edge case: any place_order/cancel_order attempt with a non-paper config is hard-refused at the first line (no structural paper/live guard available), matching the Dhan/Shoonya rule. - Error path: a missing or invalid Trading 212 API key surfaces a clear connector error rather than an unhandled exception; classification falls back to deny for unknown operations.

Checklist

  • No changes to protected areas (src/agent/, src/session/, src/providers/) without prior discussion
  • No hardcoded values (API keys, file paths, magic numbers)
  • Code follows CONTRIBUTING.md guidelines
  • Documentation updated (if user-facing change)

AI was used for assistance.

@warren618
warren618 force-pushed the fix/309-trading212-readonly-connector branch from 2fcb744 to a83815d Compare June 29, 2026 08:48
@warren618
warren618 merged commit f6bd350 into HKUDS:main Jun 29, 2026
1 check passed
@warren618

Copy link
Copy Markdown
Collaborator

Thanks @mvanhorn, merged in f6bd350. I rebased the branch onto current main, resolved the additive registry conflicts, and kept the connector scoped to read-only / fail-closed behavior. I also aligned the Trading 212 host/auth handling with the current API docs while preserving your commit authorship on a83815d.

CI is green: https://github.com/HKUDS/Vibe-Trading/actions/runs/28359930953.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Broker connector support for Trading 212

2 participants