An unofficial API library for Trading212 based on Selenium
Project description
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 modeget_stock_info(brw, ticker, backtohome_begin=True, backtohome_end=True)
: starting from aselenium.webdriver.chrome.webdriver.WebDriver
objectbrw
, 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.WebDriver
objectbrw
, this method returns information on the current portfoliobuy(brw, ticker, amount, max_price=None)
: starting from aselenium.webdriver.chrome.webdriver.WebDriver
objectbrw
, this method buys a stock identified by its ownticket
, specifying theamount
in 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.WebDriver
objectbrw
, this method sells a stock identified by its ownticket
, specifying theamount
in 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)
# 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
Project details
Release history Release notifications | RSS feed
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.0.3.tar.gz
(4.1 kB
view hashes)
Built Distribution
Close
Hashes for trading212api-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6253cfee8be712e83125f78f2c8b6424febc6d5426a25a956c2bdfa23ea756f8 |
|
MD5 | 9445b07b5f4d0d016f9e5af430e098cf |
|
BLAKE2b-256 | 0f62b0b547db203e822318678cacebccb5d5f18d63a9ea947aa7cb1ec7e9cf27 |