Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harrytwigg/viaduct-trading212-python-api
Viaduct is a Trading212 REST API wrapper for Python
https://github.com/harrytwigg/viaduct-trading212-python-api
api api-wrapper python rest trading212 trading212-api viaduct
Last synced: 7 days ago
JSON representation
Viaduct is a Trading212 REST API wrapper for Python
- Host: GitHub
- URL: https://github.com/harrytwigg/viaduct-trading212-python-api
- Owner: harrytwigg
- License: gpl-3.0
- Created: 2021-02-11T10:32:02.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-12T10:09:32.000Z (over 3 years ago)
- Last Synced: 2024-12-05T03:35:03.418Z (20 days ago)
- Topics: api, api-wrapper, python, rest, trading212, trading212-api, viaduct
- Language: Python
- Homepage:
- Size: 5.36 MB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Viaduct | A Trading212 Python REST API
Viaduct is a Python REST API wrapper that utilises Trading212's REST API that normally communciates exclusively with first party apps. This has not been offically released publicly but can be reverse-engineered.
Selenium is used to scrape required cookies and customer data from the web app but is no longer required after this point. REST network calls are used enabling greater functionallity and speed than pure web scraping.
The use of a wrapper ensures any API changes in the future will not impact pre-existing Trading212 dependeant programs as the wrapper itself can be updated instead of the underlying code.
## Prerequisites
- Firefox if not in default location, an error will be returned upon runtime.
- The Selenium Gecko driver will automatically install if not in system path, no manual installation is requried!## Installation
Pip install out now!
```console
pip install viaduct
```## Import and Usage
Viaduct is an API wrapper. API responses are returned python dictionaries, see the root tree images for more information. Selenium web scrapping modes extend the public class methods so it does not need to be recreated.
Examples are the payloads that the Rest API returns, these are returned as Python dictionaries for your convenience
Remember to disable 2-factor authentification and store passwords securely!
## Usage Key
See below for currently implemented API class methods, these are explained further below
| Method | Public | ISA | Equity | CFD |
| --- | --- | --- | --- | --- |
| 1 - getInstrument() | X | X | X | |
| 2 - getAllInstruments() | X | X | X | |
| 3 - getFundamentals() | X | X | X | |
| 4 - getMinMax() | | X | X | |
| 5 - getSettings() | | X | X | |
| 6 - getChartData() | X | X | X | X |
| 7 - getPortfolioPerformance() | | X | X | |## Public Mode
Retrieve publicly available information on companies and their financial information, utilises Trading212's unpublished private REST API no Selenium or web scrapping is required!
Symbols can be optionally loaded at startup, this will take approxuimately 30 seconds, this is requried for symbol reference conversion.
Symbol reference conversion refers to being able to use an instruments shortName, longName, ISIN (International Securities Identification Number), or ticker. These are referred to in the Trading212 API and can be converted to one another through the use of helper functions. Code refers to the ticker identifier, name is a shorthand of the pretty name.
```python
instance = Public(loadSymbols=False)
```## ISA Mode
Selenium powered wrapper for management of an ISA account, real mode only
If Firefox is not installed in default folder, make sure you pass the installed path upon initialisation:
```python
instance = ISA("email", "password", browserPath=r"C:\Program Files\Mozilla Firefox\firefox.exe", loadSymbols=False)
```## Equity Mode
Selenium powered wrapper for management of an Equity account, real or demo modes are supported
If Firefox is not installed in default folder, make sure you pass the installed path upon initialisation:
```python
instance = Equity("email", "password", reality=Reality.Real, browserPath=r"C:\Program Files\Mozilla Firefox\firefox.exe", loadSymbols=False)
```## CFD Mode
Selenium powered wrapper for management of CFD account, real or demo modes are supported
Custom methods for CFD are not yet supported and only return Public API calls
If Firefox is not installed in default folder, make sure you pass the installed path upon initialisation:
```python
instance = CFD("email", "password", reality=Reality.Real, browserPath=r"C:\Program Files\Mozilla Firefox\firefox.exe", loadSymbols=False)
```## API Class Methods
1 - getInstrument() has been removed, use instrument search instead
### 2 - getAllInstruments() - Get all securities on Trading212!
```python
instance.getAllInstruments()
```This returns all the securities on Trading212 Equity and ISA, some tickers are also reused by CFD but the lists have been seperated as of 01/04/2021
#### Example result [here](examples/2.json) this example has beenn truncated
### 3 - getFundamentals() - Get company fundamentals
```python
instance.getFundamentals(isin="US36467W1099")
```Takes an isin, returns a requested companies details
#### Example result [here](examples/3.json)
### 4 - getMinMax() - Get min and max position sizes
```python
instance.getMinMax(ticker="GYMl_EQ")
```Takes a company ticker. Gets minBuy, maxBuy, minSell, maxSell values in £, maxSellQuantity is number of shares. Not sure what sellThreshold is. The sell parameters only appear for UK stocks for some reason.
#### Example result [here](examples/4.json)
### 5 - getSettings() - Get position trade settings
```python
instance.getSettings(ticker="BOOHl_EQ")
```Takes instrument ticker, returns maxBuy and maxSell in shares for the account and max buy and sell that is technically possible on the exchange, also has minTrade and if the instrument is suspended.
#### Example result [here](examples/5.json)
### 6 - getChartData() - Get instrument chart data
```python
instance.getChartData(ticker="TSLA", chartPeriod=ChartPeriod.D1, number=5)
```Takes an instrument ticker, called 'name' when getInstrument() is called, returns a dictionary of data that is normally exclusively displayed on price charts. also takes period and number of most recent data points to return
#### Example result [here](examples/6.json)
### 7 - getPortfolioPerformance() - Gets the account performance graph data
```python
instance.getPortfolioPerformance(historyPeriod=HistoryTimeframe.Y1):
```This returns the account portfolio performance graph data that is displayed in the top left of the new app, takes a HistoryPeriod enumeration
#### Example result [here](examples/7.json)