Skip to content

Commit

Permalink
Fix auth
Browse files Browse the repository at this point in the history
  • Loading branch information
HellAmbro committed May 30, 2024
1 parent 9d34fb8 commit 2ec60ee
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
### v0.2.8
* fix auth
### v0.2.7
* fix candle stick
* adapt api with new T212 app
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytrading212"
version = "0.2.7"
version = "0.2.8"
description = "Unofficial Trading212 API"
authors = ["HellAmbro <[email protected]>"]
license = "MIT License"
Expand Down
18 changes: 5 additions & 13 deletions pytrading212/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@

URL_LOGIN = "https://www.trading212.com/en/login"
CLASS_COOKIES_NOTICE_BUTTON = "CookiesNotice_button__q5YaL"
CLASS_LOGIN_BUTTON = "SubmitButton_input__IV2dl"
XPATH_LOGIN_BUTTON = '//*[@id="root"]/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div[1]/div[2]/div[4]/div/div'
CLASS_EQUITY_ICON = "equity-icon"
CLASS_CFD_ICON = "cfd-icon"
PYTRADING212_VERSION = "0.2.6"
SELECTOR_NEW_APP = ("#root > div > div > div > div > div > div > div:nth-child(1) > "
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-105ug2t > "
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-105ug2t > div > div > div > div "
"> div > div > div > div.css-175oi2r.r-13awgt0 > div > "
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-12vffkv > div:nth-child(2) > div "
"> div.css-175oi2r.r-13awgt0.r-1udh08x > div > div.css-175oi2r.r-13awgt0 > div > div > div > div "
"> div > div > div.css-175oi2r.r-13awgt0 > div > "
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-12vffkv > div:nth-child(2) > div "
"> div.css-175oi2r.r-13awgt0.r-1udh08x > div > div.css-175oi2r.r-13awgt0 > div > div > "
"div.css-175oi2r.r-150rngu.r-eqz5dr.r-16y2uox.r-1wbh5a2.r-11yh6sk.r-1rnoaur.r-1sncvnh > div > "
"div.css-175oi2r.r-1loqt21.r-1otgn73 > div > div")
PYTRADING212_VERSION = "0.2.8"
XPATH_EMAIL = '//*[@id="root"]/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div[1]/div[2]/div[1]/div/div[1]/div[2]/input'
XPATH_PASSWORD = '//*[@id="root"]/div/div/div/div/div/div/div[1]/div/div[2]/div/div/div/div[1]/div/div[1]/div[2]/div[2]/div/div/div[1]/div[2]/input'
SELECTOR_MENU_BUTTON = ("#root > div > div > div > div > div > div > div:nth-child(1) > div > "
"div.css-175oi2r.r-1p0dtai.r-1d2f490.r-u8s1d.r-zchlnj.r-ipm5af.r-12vffkv > div > div > "
"div:nth-child(1) > div > div > div:nth-child(2) > div > div:nth-child(5) > div > span > div")
Expand Down Expand Up @@ -57,6 +48,7 @@

ONE_WEEK = "ONE_WEEK"


class Mode(Enum):
"""Mode Type"""
DEMO = "demo",
Expand Down
16 changes: 4 additions & 12 deletions pytrading212/trading212.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,14 @@ def __init__(

console.log("Authenticating")

WebDriverWait(self.driver, 120).until(expected_conditions.visibility_of_element_located((By.NAME, "email")))
WebDriverWait(self.driver, 120).until(expected_conditions.visibility_of_element_located((By.XPATH, constants.XPATH_EMAIL)))

# Authenticate
self.driver.find_element(By.NAME, "email").send_keys(email)
self.driver.find_element(By.NAME, "password").send_keys(password)
self.driver.find_element(By.XPATH, constants.XPATH_EMAIL).send_keys(email)
self.driver.find_element(By.XPATH, constants.XPATH_PASSWORD).send_keys(password)

# Click login button
self.driver.find_element(By.CLASS_NAME, constants.CLASS_LOGIN_BUTTON).click()

# Close new app button, should be removed later
try:
WebDriverWait(self.driver, 30).until(expected_conditions.visibility_of_element_located(
(By.CSS_SELECTOR, constants.SELECTOR_NEW_APP)))
self.driver.find_element(By.CSS_SELECTOR, constants.SELECTOR_NEW_APP).click()
except NoSuchElementException:
pass
self.driver.find_element(By.XPATH, constants.XPATH_LOGIN_BUTTON).click()

self.user_agent = self.driver.execute_script("return navigator.userAgent;")

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="pytrading212",
version="0.2.7",
version="0.2.8",
author="HellAmbro",
author_email="[email protected]",
description="Unofficial Trading212 API",
Expand Down

0 comments on commit 2ec60ee

Please sign in to comment.