Skip to content

Commit ebf43e6

Browse files
committed
getInstruments() - API url updated, codes are now referred to as tickers
1 parent 2e2a047 commit ebf43e6

File tree

9 files changed

+262
-338
lines changed

9 files changed

+262
-338
lines changed

README.md

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ 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 | X | X |
41-
| 2 - getAllInstruments() | X | X | X | X |
42-
| 3 - getFundamentals() | X | X | X | X |
40+
| 1 - getInstrument() | X | X | X | |
41+
| 2 - getAllInstruments() | X | X | X | |
42+
| 3 - getFundamentals() | X | X | X | |
4343
| 4 - getMinMax() | | X | X | |
4444
| 5 - getSettings() | | X | X | |
4545
| 6 - getChartData() | X | X | X | X |
@@ -51,7 +51,7 @@ Retrieve publicly available information on companies and their financial informa
5151

5252
Symbols can be optionally loaded at startup, this will take approxuimately 30 seconds, this is requried for symbol reference conversion.
5353

54-
Symbol reference conversion refers to being able to use an isntruments name short hand, pretty name, code, ISIN (International Securities Identification Number), or ID. 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.
54+
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.
5555

5656
```python
5757
instance = Public(loadSymbols=False)
@@ -91,27 +91,17 @@ instance = CFD("email", "password", reality=Reality.Real, browserPath=r"C:\Progr
9191

9292
## API Class Methods
9393

94-
### 1 - getInstrument() - Get specific instrument details instead of all of them
95-
96-
```python
97-
instance.getAllInstruments(code="TSLA")
98-
```
99-
100-
Get instrument details using position code from the secret API, note this is not the shorthand name, ISIN or stock ticker. Ideal for updating existing data on a stock of interest. This is far faster than loading all instruments so if you know the isntrument code, then use this!
101-
102-
#### Example result [here](examples/1.json)
94+
1 - getInstrument() has been removed, use instrument search instead
10395

10496
### 2 - getAllInstruments() - Get all securities on Trading212!
10597

10698
```python
10799
instance.getAllInstruments()
108100
```
109101

110-
This returns all the securities on Trading212 Equity and ISA, be warned it's over 9,000 and constantly growing
111-
112-
Result format is the same as a single instrument but returns a list of dictionaries
102+
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
113103

114-
#### Example result [here](examples/2.json)
104+
#### Example result [here](examples/2.json) this example has beenn truncated
115105

116106
### 3 - getFundamentals() - Get company fundamentals
117107

@@ -126,20 +116,20 @@ Takes an isin, returns a requested companies details
126116
### 4 - getMinMax() - Get min and max position sizes
127117

128118
```python
129-
instance.getMinMax(code="GYMl_EQ")
119+
instance.getMinMax(ticker="GYMl_EQ")
130120
```
131121

132-
Takes a company code. 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.
122+
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.
133123

134124
#### Example result [here](examples/4.json)
135125

136126
### 5 - getSettings() - Get position trade settings
137127

138128
```python
139-
instance.getSettings(code="BOOHl_EQ")
129+
instance.getSettings(ticker="BOOHl_EQ")
140130
```
141131

142-
Takes instrument code, 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.
132+
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.
143133

144134
#### Example result [here](examples/5.json)
145135

dist/viaduct-0.1.1.tar.gz

8.17 KB
Binary file not shown.

examples/1.json

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

examples/2.json

Lines changed: 92 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,98 @@
1-
[
2-
{
3-
"id": 4374,
4-
"name": "SIG",
5-
"prettyName": "Signature Aviation",
6-
"code": "BBA",
7-
"type": "STOCK",
8-
"currency": "GBP",
9-
"group": "UK STOCKS",
10-
"isin": "GB00BKDM7X41",
11-
"price": {
12-
"buy": 4.084,
13-
"sell": 4.169
1+
{
2+
"items": [
3+
{
4+
"ticker": "1COVd_EQ",
5+
"type": "STOCK",
6+
"isin": "DE0006062144",
7+
"currency": "EUR",
8+
"shortName": "1COV",
9+
"fullName": "Covestro",
10+
"description": "Covestro AG",
11+
"countryOfOrigin": "DE",
12+
"minTrade": 0.0100000000,
13+
"digitsPrecision": 2,
14+
"quantityPrecision": 8,
15+
"exchangeId": 54
1416
},
15-
"realPrice": {
16-
"buy": 4.084,
17-
"sell": 4.169
17+
{
18+
"ticker": "1GISl_EQ",
19+
"type": "ETF",
20+
"isin": "IE00BF4TW560",
21+
"currency": "GBX",
22+
"shortName": "1GIS",
23+
"fullName": "WisdomTree Gilts 10Y -1x",
24+
"description": "WisdomTree Gilts 10Y 1x Daily Short",
25+
"countryOfOrigin": "GB",
26+
"minTrade": 1.0000000000,
27+
"digitsPrecision": 2,
28+
"exchangeId": 70
1829
},
19-
"minTrade": 1.0000000000,
20-
"precision": 3,
21-
"minTradeSizeCoefficient": 10,
22-
"insignificantDigits": 0,
23-
"description": "Signature Aviation PLC",
24-
"enabled": true,
25-
"suspended": false,
26-
"marketId": 35,
27-
"shortPercent": 0,
28-
"baseCode": "BBA",
29-
"maxPendingDist": 1.38400,
30-
"priorityIndex": 50.00,
31-
"margin": 0.0500,
32-
"quantity": 5.0000000000,
33-
"quantityPrecision": 0,
34-
"countryOfOrigin": "GB"
35-
},
36-
{
37-
"id": 116954,
38-
"name": "SIGT",
39-
"prettyName": "Seneca Global Income & Growth Trust",
40-
"code": "SIGTl_EQ",
41-
"type": "STOCK",
42-
"currency": "GBX",
43-
"group": "XLON",
44-
"isin": "GB0008769993",
45-
"price": {
46-
"buy": 166.62,
47-
"sell": 171.38
30+
{
31+
"ticker": "1MCSl_EQ",
32+
"type": "ETF",
33+
"isin": "IE00BBGBF313",
34+
"currency": "GBX",
35+
"shortName": "1MCS",
36+
"fullName": "WisdomTree FTSE 250 1x Daily Short",
37+
"description": "WisdomTree FTSE 250 1x Daily Short",
38+
"countryOfOrigin": "GB",
39+
"minTrade": 1.0000000000,
40+
"digitsPrecision": 2,
41+
"exchangeId": 70
4842
},
49-
"realPrice": {
50-
"buy": 166.62,
51-
"sell": 171.38
43+
{
44+
"ticker": "1PASl_EQ",
45+
"type": "ETF",
46+
"isin": "IE00B94QLR02",
47+
"currency": "USD",
48+
"shortName": "1PAS",
49+
"fullName": "WisdomTree Palladium -1x",
50+
"description": "WisdomTree Palladium 1x Daily Short",
51+
"countryOfOrigin": "US",
52+
"minTrade": 1.0000000000,
53+
"digitsPrecision": 2,
54+
"exchangeId": 70
5255
},
53-
"minTrade": 1.0000000000,
54-
"precision": 2,
55-
"minTradeSizeCoefficient": 0,
56-
"insignificantDigits": 0,
57-
"description": "Seneca Global Income & Growth Trust PLC",
58-
"enabled": true,
59-
"suspended": false,
60-
"marketId": 55,
61-
"shortPercent": 0,
62-
"baseCode": "SIGTl_EQ",
63-
"maxPendingDist": 216.37500,
64-
"margin": 1.0000,
65-
"quantity": 0.0000000000,
66-
"quantityPrecision": 0,
67-
"countryOfOrigin": "GB"
68-
},
69-
{
70-
"id": 86890,
71-
"name": "PDYPY",
72-
"prettyName": "Flutter Entertainment",
73-
"code": "PDYPY_US_EQ",
74-
"type": "STOCK",
75-
"currency": "USD",
76-
"group": "US EQ",
77-
"isin": "US3440441026",
78-
"price": {
79-
"buy": 97.59,
80-
"sell": 98.31
56+
{
57+
"ticker": "1SId_EQ",
58+
"type": "STOCK",
59+
"isin": "US83304A1060",
60+
"currency": "EUR",
61+
"shortName": "1SI",
62+
"fullName": "Snap",
63+
"description": "Snap Inc.",
64+
"countryOfOrigin": "US",
65+
"minTrade": 0.0500000000,
66+
"digitsPrecision": 2,
67+
"quantityPrecision": 8,
68+
"exchangeId": 54
8169
},
82-
"realPrice": {
83-
"buy": 97.59,
84-
"sell": 98.31
70+
{
71+
"ticker": "2AAPl_EQ",
72+
"type": "ETF",
73+
"isin": "IE00BF03XJ35",
74+
"currency": "GBX",
75+
"shortName": "2AAP",
76+
"fullName": "2x Apple",
77+
"description": "Leverage Shares 2x Apple ETP",
78+
"countryOfOrigin": "IE",
79+
"minTrade": 0.0100000000,
80+
"quantityPrecision": 8,
81+
"exchangeId": 59
8582
},
86-
"minTrade": 1.0000000000,
87-
"precision": 2,
88-
"minTradeSizeCoefficient": 0,
89-
"insignificantDigits": 0,
90-
"description": "Flutter Entertainment PLC",
91-
"enabled": true,
92-
"suspended": false,
93-
"marketId": 85,
94-
"shortPercent": 0,
95-
"baseCode": "PDYPY_US_EQ",
96-
"maxPendingDist": 123.18000,
97-
"priorityIndex": 50.00,
98-
"margin": 1.0000,
99-
"quantity": 0.0000000000,
100-
"quantityPrecision": 0,
101-
"countryOfOrigin": "US"
102-
}
103-
]
83+
{
84+
"ticker": "2AMDl_EQ",
85+
"type": "ETF",
86+
"isin": "IE00BKT6ZG93",
87+
"currency": "GBX",
88+
"shortName": "2AMD",
89+
"fullName": "2x AMD",
90+
"description": "Leverage Shares 2x Advanced Micro Devices ETP",
91+
"countryOfOrigin": "IE",
92+
"minTrade": 0.0100000000,
93+
"quantityPrecision": 8,
94+
"exchangeId": 59
95+
}
96+
],
97+
"version": 1033719421
98+
}

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.1.1', # Start with a small number and increase it with every change you make
6+
version='0.1.2', # 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.1.1.tar.gz',
17+
download_url='https://github.com/harrytwigg/Viaduct-Trading212-Python-API/archive/0.1.2.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

viaduct/cfd.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,18 @@ def urlf(self, url):
1616
return ("https://demo.trading212.com" + url)
1717
else:
1818
raise Exception("Invalid reality " + self.reality)
19+
20+
# Gets chart data for a particular ticker
21+
# When getting chart data, the ticker returned is the ticker not what is on the stock exchange!
22+
def getChartData(self, ticker, chartPeriod, size, includeFake=False):
23+
payload = {
24+
"candles": [
25+
{
26+
"ticker": ticker,
27+
"period": chartPeriod,
28+
"size": size,
29+
"includeFake": includeFake
30+
}
31+
]
32+
}
33+
return post(url=self.urlf("/charting/v2/batch"), payload=payload)

0 commit comments

Comments
 (0)