BenTimor / Trading212API

An unofficial API for Trading212
MIT License
51 stars 5 forks source link

Uses the old web app api & has no option to switch to the old app. #2

Closed peterferguson closed 3 years ago

peterferguson commented 3 years ago

setup method fails on a timeout after login since to account-menu-button is no longer a CSS element in the new app.

# Waiting and opening the user menu to avoid the 'You're using CFD' message.
        elem = WebDriverWait(self.driver, self.timeout).until(expected_conditions.element_to_be_clickable((By.CLASS_NAME, "account-menu-button")))
        force_click(elem)

A simple solution (as an intermediary to switching to new api) would be to use the Switch to the old app button as part of setup. The HTML for the button is

<div class="account-menu-item switch-to-old">
  <div class="svg-icon-holder advanced-mode-icon">
    <svg width="32" height="32" viewBox="0 0 32 32">
      <g fill="none" fill-rule="evenodd">
        <path
          fill="#6F6F7F"
          fill-rule="nonzero"
          d="M-0.396446563,2.89644657 C-0.591708707,2.70118442 -0.908291196,2.70118442 -1.10355334,2.89644656 C-1.29881549,3.09170871 -1.29881549,3.4082912 -1.10355335,3.60355334 L3.75000004,8.45710674 L8.60355335,3.60355335 C8.79881549,3.4082912 8.79881549,3.09170871 8.60355335,2.89644657 C8.4082912,2.70118442 8.09170871,2.70118442 7.89644657,2.89644657 L3.75000004,7.04289317 L-0.396446563,2.89644657 Z"
          transform="matrix(0 -1 -1 0 21.354 20.354)"
        ></path>
        <circle cx="16.5" cy="16.5" r="11" stroke="#6F6F7F"></circle>
      </g>
    </svg>
  </div>
  <div class="label">Switch to the old app</div>
</div>

or xpath

/html/body/div[1]/div[10]/div/div/div/div/div/div/div[9]

or css selector

div.account-menu-item:nth-child(9)

or css path

html body div#app.en div.css-cdrhz6.dropdown-animation-enter-done div div.css-p7lmf6.bottom.right.reverse.dropdown-items.account-menu div.dropdown-items-content div.css-1fbss72.scrollable-area-wrapper.bottom div.css-u0d0cr.scrollable-area div.scrollable-items div.account-menu-item.switch-to-old
Neugierdsnase commented 3 years ago

@peterferguson have you found a better solution than this package to automate tasks on Trading212?

peterferguson commented 3 years ago

@peterferguson have you found a better solution than this package to automate tasks on Trading212?

@Neugierdsnase

Nope I quite like this solution actually. If you just log into your trading212 and switch to the old app first in the drop down this library works like a charm.

The fix is fairly simple and the main class makes it easy to interact with the webdriver so any features that are missing are easy to add. I have added things like extraction of portfolio value, cash value and a list of stocks currently held.

BenTimor commented 3 years ago

Hey :) Sorry for answering late. I'm a little busy this days. I'm hoping to refactor all of this project to use requests instead of selenium so it'll be faster and it'll support design changes more easily.

I'll try to do it ASAP :)

BenTimor commented 3 years ago

Note: It's fixed for now thanks to @peterferguson , But I still want to make the library work with requests instead of selenium so we won't have bugs like this one. I've started a new job so it's gonna take some time.

If someone wants to contribute and develop it, he's welcome and I'll really appreciate it :)

peterferguson commented 3 years ago

Note: It's fixed for now thanks to @peterferguson , But I still want to make the library work with requests instead of selenium so we won't have bugs like this one. I've started a new job so it's gonna take some time.

If someone wants to contribute and develop it, he's welcome and I'll really appreciate it :)

Hey @BenTimor, I would like to get involved in this have you started working on the requests implementation yet?

BenTimor commented 3 years ago

Note: It's fixed for now thanks to @peterferguson , But I still want to make the library work with requests instead of selenium so we won't have bugs like this one. I've started a new job so it's gonna take some time. If someone wants to contribute and develop it, he's welcome and I'll really appreciate it :)

Hey @BenTimor, I would like to get involved in this have you started working on the requests implementation yet?

Thanks! :) I've just started investigating the requests Trading212's client sending to their server. Still couldn't reproduce any of them on Python requests, I guess they're looking for something like localStorage which I haven't trying to send yet.

When I (or you) have something ready, we should put it on a different branch and start working on it. :)