trading212api
An unofficial API library for Trading212 based on Selenium
Description
This library allows you to interface with Trading212 through Selenium. Once you log in, the only operation requiring a human interation, you can buy and sell stocks, in both real and practice modes.
Installation
pip install trading212api
Install a Selenium web driver, e.g., the Chrome WebDriver
Available methods
enable_real_mode(): this method is used to enable real/live modeenable_practice_mode(): this method is used to enable practice/demo modeinitiate_connection(webdriverfile, loginusername=None, loginpassword=None, headless=False): initializes the connection to Trading212 through Selenium, optionally asking for username and password to login; in such case, an automatic login will be performed; otherwise, user interaction will be required, for a manual login to occur; ifheadlessisTrue, the browser will be executed in headless modeget_stocks_list(brw, navigationpath=None): returns all the list of stocks available, optionally selecting a specific>separated list identifying the navigation path, in terms of content, to followget_stock_info(brw, ticker, backtohome_begin=True, backtohome_end=True): starting from aselenium.webdriver.chrome.webdriver.WebDriverobjectbrw, this method retrieves information from a stock identified by a giventicker, optionally, returning home at the begin/end of the methodget_portfolio(brw): starting from aselenium.webdriver.chrome.webdriver.WebDriverobjectbrw, this method returns information on the current portfoliobuy(brw, ticker, amount, max_price=None): starting from aselenium.webdriver.chrome.webdriver.WebDriverobjectbrw, this method buys a stock identified by its ownticket, specifying theamountin terms of money to invest in the current valuta, plus an optional maximum pricemax_price; returns a boolean value indicating the success of the operationsell(brw, ticker, amount=None, min_price=None): starting from aselenium.webdriver.chrome.webdriver.WebDriverobjectbrw, this method sells a stock identified by its ownticket, specifying theamountin terms of number of stocks to sell and an optional minimum pricemin_price; returns a boolean value indicating the success of the operation
Sample usage
# import the library
import trading212api
# enable practice mode
trading212api.enable_practice_mode()
# initiate the connection
brw = trading212api.initiate_connection('./chromedriver')
# get and print portfolio information
portfolio = trading212api.get_portfolio(brw)
print(portfolio)
# get and print information on a given stock
stock_info = trading212api.get_stock_info(brw, 'AAPL')
print(stock_info)
# get all most popular stocks
popular_stocks = trading212api.get_stocks_list(brw, navigationpath='Stocks>Most Popular')
# get and print information on all most popular stocks
for s in popular_stocks:
stock_info = trading212api.get_stock_info(brw, s.get('ticker'))
print(stock_info)
# buy 10 USD of AAPL
trading212api.buy(brw, 'AAPL', 10)
# sell 1 stock of AAPL
trading212api.sell(brw, 'AAPL', 1)
TODO
- Improve code readability
Contacts
Metadata
Release files for trading212api 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trading212api-0.1.1.tar.gz | 5.6 kB | Without provenance | Details for trading212api-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trading212api-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for trading212api-0.1.1-py3-none-any.whl |
Total release size: 11.5 kB
Release files / trading212api-0.1.1.tar.gz
| Download URL | trading212api-0.1.1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f24a8b439cd1502c0210aca1c786a5648af2395f682f51455f60a5a117e3f37
|
|
BLAKE2b-256 checksum How to use checksums |
5206fbca92c832f3ff850179797775516d1a2d7c046832617227f3b91d43fc28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
|
Release files / trading212api-0.1.1-py3-none-any.whl
| Download URL | trading212api-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f4e3e9c4ecddfb0a20bb30c575bfe9c91e9f169276e7699ff49aca5938f5ab9
|
|
BLAKE2b-256 checksum How to use checksums |
8d413c823bf311d024ec123c27743c28491aa27ffc224aac532886e2e138536e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
|
Security for trading212api 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.