Skip to main content

A Python client for the Trading212 public API.

Project description

Trading212py Module

This is an unofficial Python client for the Trading212 API

Installation

You can install the package using pip:

pip install trading212py

Configuration

Environment Variables

Create a directory and call it .env Create two separate files called .secret and .shared

.env/
|
|- .secret
|- .shared

Content of the .shared file

Add ACCOUNT_TYPE variable.

Options: ACCOUNT_TYPE="demo" or ACCOUNT_TYPE="live"

Content of the .secret file

Add T212_API_KEY and T212_DEMO_API_KEY variables.

Example: T212_API_KEY='1234.....abcd'

Note: If the app is pushed to Production or running inside a docker container, then these variables will be overwitten with the existing environment variables. For that reason, add those KEYS in your platform's environments variables.

Usage

from trading212py import T212

def main():

    t212 = T212()
    print(t212.account_metadata())

if __name__ == '__main__':
    main()

Orders

newLimitOrder: Order = Order(limitPrice=90.23, quantity=0.1, ticker='AAPL_US_EQ', timeValidity='DAY')
print(t212.place_limit_order(payload=newLimitOrder))

>>> creationTime='2024-09-07T03:05:32.603+03:00' filledQuantity=0.0 filledValue=None id=19150387579 status=<OrderStatus.NEW: 'NEW'> strategy='QUANTITY' type='LIMIT' value=None limitPrice=90.23 quantity=0.1 ticker='AAPL_US_EQ' timeValidity=None stopPrice=None

Alternatively you can pass the json payload to the relevant Class.

payload = {
    "limitPrice":90.23,
    "quantity":0.1,
    "ticker":'AAPL_US_EQ',
    "timeValidity"='DAY'
}
print(t212.place_limit_order(payload=Order(**payload)))
newMarketOrder: Order = Order(quantity=0.1, ticker='AAPL_US_EQ')
t212.place_market_order(payload=newMarketOrder)
from trading212py.base import ExportPayload
payload = {
    "dataIncluded": {
        "includeDividends": True,
        "includeInterest": True,
        "includeOrders": True,
        "includeTransactions": True
    },
    "timeFrom": "2019-08-24T14:15:22Z",
    "timeTo": "2024-09-07T14:15:22Z"
    }
print(t212.exports(payload=ExportPayload(**payload)))

Disclaimer

Nor me or Trading212 are responsible for the use of this API, first make sure that everything works well through the use of a DEMO account, then switch to REAL mode.

In addition, I don't take responsibility for the accuracy of the information reported here and the proper functioning of the API

All trademarks, logos and brand names are the property of their respective owners. All company, product and service names used in this website are for identification purposes only.

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

trading212py-0.1.3.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

trading212py-0.1.3-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file trading212py-0.1.3.tar.gz.

File metadata

  • Download URL: trading212py-0.1.3.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for trading212py-0.1.3.tar.gz
Algorithm Hash digest
SHA256 dafa7745f15bb48c9cce86bf84ec9e10712f50e9daec266dd422e08335682b44
MD5 351aeba0b6f6850e9273ba8f9075a32b
BLAKE2b-256 de9d88792d1400a6a8a2f831011b45778042fb25b9dd24bea6d164cc3b77228a

See more details on using hashes here.

Provenance

The following attestation bundles were made for trading212py-0.1.3.tar.gz:

Publisher: python-publish.yml on serdarbaran/trading212

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

File details

Details for the file trading212py-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: trading212py-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for trading212py-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1ebe0ff61ce7121ccda23f08f503d9bd09089cd3d8a6422dcf40d399b3baa6f6
MD5 b4f30a5cef512abf0307bca8c8647fdd
BLAKE2b-256 484c734bf6939c6b31cd2d38e8a08dfbe46b91fe90983da1f5911fa2b0708d8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for trading212py-0.1.3-py3-none-any.whl:

Publisher: python-publish.yml on serdarbaran/trading212

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