pyt212
Python wrapper for the Trading 212 REST API (Invest and Stocks ISA accounts).
- Install:
pip install pyt212(from PyPI) - Import:
import t212
To publish a new version, see PUBLISHING.md.
Requirements
- Python 3.10+
- Trading 212 API key and secret (from the Trading 212 app)
Quick start
import t212
# Use demo (paper) or live environment
client = t212.Trading212Client(
api_key="YOUR_API_KEY",
api_secret="YOUR_API_SECRET",
base_url=t212.DEFAULT_DEMO_URL, # or DEFAULT_LIVE_URL
)
# Account
summary = client.get_account_summary()
print(summary.currency, summary.total_value)
# Pending orders and positions
orders = client.get_pending_orders()
positions = client.get_positions()
# Place a limit buy order (positive quantity = buy)
from t212 import LimitOrderRequest, TimeValidity
order = client.place_limit_order(
LimitOrderRequest(ticker="AAPL_US_EQ", quantity=1.0, limit_price=150.0, time_validity=TimeValidity.DAY)
)
API coverage
- Accounts:
get_account_summary() - Instruments:
get_exchanges(),get_instruments() - Orders:
get_pending_orders(),get_order_by_id(),place_limit_order(),place_market_order(),place_stop_order(),place_stop_limit_order(),cancel_order() - Positions:
get_positions() - History:
get_dividends(),get_historical_orders(),get_transactions(),get_reports(),request_report()
All request and response payloads use Pydantic models. Paginated endpoints return objects with items and next_page_path; use get_all_dividends(), get_all_historical_orders(), and get_all_transactions() to fetch all pages in one call.
Rate limits: The client exposes the last response’s rate limit headers as client.last_rate_limit (t212.RateLimitInfo: limit, period, remaining, reset, used). Optional retry_on_429=True in the constructor will wait until the limit resets and retry once on 429.
Environments
- Demo (paper):
https://demo.trading212.com/api/v0—t212.DEFAULT_DEMO_URL - Live:
https://live.trading212.com/api/v0—t212.DEFAULT_LIVE_URL
Documentation
- API reference and behaviour: see
.agent/api-docs/trading212-api-reference.mdin this repo. - Trading 212 API Terms
License
MIT
Release files for pyt212 0.1.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 | |
|---|---|---|---|
| pyt212-0.1.0.tar.gz | 7.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyt212-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.1 kB
Release files / pyt212-0.1.0.tar.gz
| Download URL | pyt212-0.1.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a83e36e0d37adbfc8e4157f8c4483b13e4dbb91117c8b6052d09567fd48ce5a
|
|
BLAKE2b-256 checksum How to use checksums |
3f590533ba9cc13bae69fc075dd41d4734ddeb9905d192598c52fd0bc6f13724
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.8
|
Release files / pyt212-0.1.0-py3-none-any.whl
| Download URL | pyt212-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e2e4e18767d454a6640fe801cdaf2a58d90e7863abdde1040167771382e35e7
|
|
BLAKE2b-256 checksum How to use checksums |
10592c6b8e6a5b6242cea84e6cea6e4a45cf26f54366626d4f5c7a52410b3b87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.8
|