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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
trading212api-0.1.1.tar.gz
(5.6 kB
view details)
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 trading212api-0.1.1.tar.gz.
File metadata
- Download URL: trading212api-0.1.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f24a8b439cd1502c0210aca1c786a5648af2395f682f51455f60a5a117e3f37
|
|
| MD5 |
ea83ac780719db9d60f071a068a3d5aa
|
|
| BLAKE2b-256 |
5206fbca92c832f3ff850179797775516d1a2d7c046832617227f3b91d43fc28
|
File details
Details for the file trading212api-0.1.1-py3-none-any.whl.
File metadata
- Download URL: trading212api-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f4e3e9c4ecddfb0a20bb30c575bfe9c91e9f169276e7699ff49aca5938f5ab9
|
|
| MD5 |
29b9e26cbb158ed7d873f227fb7da186
|
|
| BLAKE2b-256 |
8d413c823bf311d024ec123c27743c28491aa27ffc224aac532886e2e138536e
|