Skip to main content

Python wrapper for the Trading 212 REST API (Invest and Stocks ISA)

Project description

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

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/v0t212.DEFAULT_DEMO_URL
  • Live: https://live.trading212.com/api/v0t212.DEFAULT_LIVE_URL

Documentation

  • API reference and behaviour: see .agent/api-docs/trading212-api-reference.md in this repo.
  • Trading 212 API Terms

License

MIT

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

pyt212-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

pyt212-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file pyt212-0.1.0.tar.gz.

File metadata

  • Download URL: pyt212-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.8

File hashes

Hashes for pyt212-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0a83e36e0d37adbfc8e4157f8c4483b13e4dbb91117c8b6052d09567fd48ce5a
MD5 52eaff9631332092624acaacd5d1253d
BLAKE2b-256 3f590533ba9cc13bae69fc075dd41d4734ddeb9905d192598c52fd0bc6f13724

See more details on using hashes here.

File details

Details for the file pyt212-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyt212-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.8

File hashes

Hashes for pyt212-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e2e4e18767d454a6640fe801cdaf2a58d90e7863abdde1040167771382e35e7
MD5 8f00140a7fd778eba1e692670b56f922
BLAKE2b-256 10592c6b8e6a5b6242cea84e6cea6e4a45cf26f54366626d4f5c7a52410b3b87

See more details on using hashes here.

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