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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trading212py-0.1.1.tar.gz.
File metadata
- Download URL: trading212py-0.1.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
362f5f2dded25299ff9fbcc73ee065ca1cc1868386faaa920f949cad39c62f3f
|
|
| MD5 |
1e4c5c8a63f1ddd362ed6ed88691de71
|
|
| BLAKE2b-256 |
90928b03e4f6762cb8507d15453f86f7c8cf3171e93ce76763d5628f531aa6bc
|
File details
Details for the file trading212py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: trading212py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93db6b91aac7adcd6bb84a593ebfb95c6a5bcc474e58a9bc0e4f8d1a878dd7d3
|
|
| MD5 |
311af962baa13d61e94fe6c5375f6ef5
|
|
| BLAKE2b-256 |
e88bd90586b18dee780e09debac37b9da988c2d7561496e146eb936126f5c55c
|