Skip to content

Commit fde7cdf

Browse files
committed
0.1.0
1 parent a8abd95 commit fde7cdf

File tree

8 files changed

+93
-56
lines changed

8 files changed

+93
-56
lines changed

README.md

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Viaduct | A Trading212 Python REST API
66

7-
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.
7+
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.
88

99
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.
1010

@@ -15,17 +15,17 @@ The use of a wrapper ensures any API changes in the future will not impact pre-e
1515
- Firefox if not in default location, an error will be returned upon runtime.
1616
- The Selenium Gecko driver will automatically install if not in system path, no manual installation is requried!
1717

18-
Pip install coming soon!
18+
## Installation
1919

20-
## Import and Usage
21-
22-
If Firefox is not installed in default folder, make sure you pass it upon initialisation for example:
20+
Pip install out now!
2321

24-
```python
25-
instance = viaduct.ISA(email, password, Reality.Real, browserPath=r"C:\Program Files\Mozilla Firefox\firefox.exe")
22+
```console
23+
pip install viaduct
2624
```
2725

28-
Currently only ISA and public modes are supported, more are coming soon. Responses are returned python dictionaries, see the root tree images for more information. Selenium web scrapping modes extend the public class so it does not need to be recreated.
26+
## Import and Usage
27+
28+
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 so it does not need to be recreated.
2929

3030
Examples are the payloads that the Rest API returns, these are returned as Python dictionaries for your convenience
3131

@@ -37,13 +37,13 @@ See below for currently implemented API class methods, these are explained furth
3737

3838
| Method | Public | ISA | Equity | CFD |
3939
| --- | --- | --- | --- | --- |
40-
| 1 - getInstrument() | X | X | | |
41-
| 2 - getAllInstruments() | X | X | | |
42-
| 3 - getFundamentals() | X | X | | |
43-
| 4 - getMinMax() | | X | | |
44-
| 5 - getSettings() | | X | | |
45-
| 6 - getChartData() | X | X | | |
46-
| 7 - getPortfolioPerformance() | | X | | |
40+
| 1 - getInstrument() | X | X | X | X |
41+
| 2 - getAllInstruments() | X | X | X | X |
42+
| 3 - getFundamentals() | X | X | X | X |
43+
| 4 - getMinMax() | | X | X | |
44+
| 5 - getSettings() | | X | X | |
45+
| 6 - getChartData() | X | X | X | X |
46+
| 7 - getPortfolioPerformance() | | X | X | |
4747

4848
## Public Mode
4949

@@ -61,19 +61,33 @@ instance = Public(loadSymbols=False)
6161

6262
Selenium powered wrapper for management of an ISA account, real mode only
6363

64-
Browser path may need to be manually specified
64+
If Firefox is not installed in default folder, make sure you pass the installed path upon initialisation:
6565

6666
```python
67-
instance = ISA("email", "password", Reality.Real, browserPath=r"C:\Program Files\Mozilla Firefox\firefox.exe")
67+
instance = ISA("email", "password", browserPath=r"C:\Program Files\Mozilla Firefox\firefox.exe")
6868
```
6969

7070
## Equity Mode
7171

72-
Coming soon!
72+
Selenium powered wrapper for management of an Equity account, real or demo modes are supported
73+
74+
If Firefox is not installed in default folder, make sure you pass the installed path upon initialisation:
75+
76+
```python
77+
instance = Equity("email", "password", reality=Reality.Real, browserPath=r"C:\Program Files\Mozilla Firefox\firefox.exe")
78+
```
7379

7480
## CFD Mode
7581

76-
Coming soon!
82+
Selenium powered wrapper for management of CFD account, real or demo modes are supported
83+
84+
Custom methods for CFD are not yet supported and only return Public API calls
85+
86+
If Firefox is not installed in default folder, make sure you pass the installed path upon initialisation:
87+
88+
```python
89+
instance = CFD("email", "password", reality=Reality.Real, browserPath=r"C:\Program Files\Mozilla Firefox\firefox.exe")
90+
```
7791

7892
## API Class Methods
7993

dist/viaduct-0.0.12.tar.gz

-7 Bytes
Binary file not shown.

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setup(
44
name='viaduct', # How you named your package folder (MyLib)
55
packages=['viaduct'], # Chose the same as "name"
6-
version='0.0.12', # Start with a small number and increase it with every change you make
6+
version='0.1.0', # Start with a small number and increase it with every change you make
77
# Chose a license from here: https://help.github.com/articles/licensing-a-repository
88
license='gpl-3.0',
99
# Give a short description about your library
@@ -14,7 +14,7 @@
1414
# Provide either the link to your github or to your website
1515
url='https://github.com/harrytwigg/Viaduct-Trading212-Python-API',
1616
# I explain this later on
17-
download_url='https://github.com/harrytwigg/Viaduct-Trading212-Python-API/archive/0.0.12.tar.gz',
17+
download_url='https://github.com/harrytwigg/Viaduct-Trading212-Python-API/archive/0.1.0.tar.gz',
1818
keywords=['python', 'api', 'rest', 'api-wrapper', 'viaduct', 'trading212',
1919
'trading212-api'], # Keywords that define your package best
2020
install_requires=[ # I get to this in a second

tests.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

viaduct/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from viaduct.isa import *
2+
from viaduct.equity import *
3+
from viaduct.cfd import *
4+
5+
from viaduct.public import *
6+
from viaduct.utils import *

viaduct/cfd.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from viaduct.core import *
2+
from viaduct.utils import *
3+
4+
5+
class CFD(CoreModule):
6+
def __init__(self, email, password, reality, browserPath, headless=False, timeout=2):
7+
super().__init__(email, password, TradingType.CFD,
8+
reality, headless, browserPath, timeout)
9+
self.reality = reality
10+
11+
# Format url on whether is live
12+
def urlf(self, url):
13+
if (self.reality == Reality.Real):
14+
return ("https://live.trading212.com" + url)
15+
elif (self.reality == Reality.Practice):
16+
return ("https://demo.trading212.com" + url)
17+
else:
18+
raise Exception("Invalid reality " + self.reality)

viaduct/equity.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from viaduct.core import *
2+
from viaduct.utils import *
3+
4+
5+
class Equity(CoreModule):
6+
def __init__(self, email, password, reality, browserPath, headless=False, timeout=2):
7+
super().__init__(email, password, TradingType.Equity,
8+
reality, headless, browserPath, timeout)
9+
self.reality = reality
10+
11+
# Format url on whether is live
12+
def urlf(self, url):
13+
if (self.reality == Reality.Real):
14+
return ("https://live.trading212.com" + url)
15+
elif (self.reality == Reality.Practice):
16+
return ("https://demo.trading212.com" + url)
17+
else:
18+
raise Exception("Invalid reality " + self.reality)
19+
20+
# Gets min and max buy and sell value in £, max sell quantity is number of shares
21+
# Not sure what sellThreshold is
22+
# The sell parameters only appear for UK stocks for some reason
23+
def getMinMax(self, code):
24+
return super().get(self.urlf("/rest/v1/equity/value-order/min-max?instrumentCode=" + code), cookies=self.cookiePayload)
25+
26+
# Takes instrument code, returns maxBuy and maxSell in shares for the account and max buy and sell that is technically
27+
# possible on the exchange, also has minTrade and if suspended
28+
def getSettings(self, code):
29+
return super().post(self.urlf("/rest/v2/account/instruments/settings"), cookies=self.cookiePayload, payload=[code])
30+
31+
# Gets the account performance graph data
32+
def getPortfolioPerformance(self, historyPeriod):
33+
return super().get(self.urlf("/rest/v2/portfolio?period=" + historyPeriod), cookies=self.cookiePayload)

viaduct/public.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def getChartData(self, code, chartPeriod, size, includeFake=False):
129129
"candles": [
130130
{
131131
"ticker": code,
132-
"period": "ONE_DAY",
132+
"period": chartPeriod,
133133
"size": size,
134134
"includeFake": includeFake
135135
}

0 commit comments

Comments
 (0)