Giter Club home page Giter Club logo

trading212api's People

Contributors

alex1443 avatar dowling-john avatar hellambro avatar phalanxguard avatar tbridel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

trading212api's Issues

Login issue

New issue when logging in:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="email"]"}
  (Session info: headless chrome=100.0.4896.88)

Script does not login automatically/ work at all

I don't know if this script (example.py) still works, but I am stuck right now at the login screen/allow cookies screen.
It shows the following page for about 2 seconds before then closing out and saying:
afbeelding

afbeelding

I am running a brand new Ubuntu 20.04.5 LTS
Using Python3.8.10

AttributeError: 'Trading212' object has no attribute 'cookie'

Downloaded the latest code from the repo, seems like it's having issues getting the session cookie, this had also happened in the previous revision occasionally, but now it seems to be persistent.

trading212 = Trading212(email, password, driver, mode=Mode.DEMO, trading=Trading.CFD)
File "C:\Python310\lib\site-packages\pytrading212\trading212.py", line 115, in init
"Cookie": self.cookie,
AttributeError: 'Trading212' object has no attribute 'cookie'

find_element removed

im getting this error: AttributeError: 'WebDriver' object has no attribute 'find_element_by_class_name'
apperently 'find_ellement' was removed in version 4,3
Selenium 4.3.0

  • Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
  • Deprecated Opera support has been removed (#10630)
  • Fully upgraded from python 2x to 3.7 syntax and features (#10647)
  • Added a devtools version fallback mechanism to look for an older version when mismatch occurs (#10749)
  • Better support for co-operative multi inheritance by utilising super() throughout
  • Improved type hints throughout

'Trading212' object has no attribute 'cookie'

I've fixed some issues in the last pull request, but there is still an issue somewhere with cookies that I can't resolve. The error displays the following message shortly after successful login:

trading212 = Trading212(email, password, driver, mode=Mode.DEMO, trading=Trading.CFD)
File "C:\Python310\lib\site-packages\pytrading212\trading212.py", line 113, in init
"Cookie": self.cookie,
AttributeError: 'Trading212' object has no attribute 'cookie'

[Feature request] Be able to put trough a CFD order.

Hi,

I am having issues finding out a way to do an order on CFD. I know it's not fully worked out, but I am trying to get it to work just for testing purposes.
Right now I have the following, which doesn't work:
afbeelding

Do you have any suggestions what to use for the 'trading212 = ' line and the 'buy_order = ' line?

Thanks!

Portfolio composition missing average price

Hi,

Please could you update the portfolio function to include the (weighted) average purchase price of the share?
Currently you can work out the average with the quantity of the shares purchased (y) and the total value invested (x), but x/y does not give you the weighted average purchase price. This data is provided by T212, so hopefully it can be incorporated into your scraping.

portfolio = trading212.get_portfolio_composition()

Thanks,
Adam

get portfolio not working

im getting this error. i dont know whats cousing it or how to fix it.
once in a blue moon it works though
Traceback (most recent call last):
File "c:\Users\flori\OneDrive\stock\playground.py", line 242, in
portfolio = trading212.get_portfolio_composition()
File "C:\Users\flori\AppData\Local\Programs\Python\Python310\lib\site-packages\pytrading212\trading212.py", line 190, in get_portfolio_composition
self.driver.find_element_by_class_name(right_sidepanel_portfolio_class).click()
File "C:\Users\flori\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 89, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\flori\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 773, in _execute
return self._parent.execute(command, params)
File "C:\Users\flori\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "C:\Users\flori\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element

...
is not clickable at point (29, 135). Other element would receive the click:
...

(Session info: chrome=104.0.5112.81)
Stacktrace:
Backtrace:
Ordinal0 [0x00A378B3+2193587]
Ordinal0 [0x009D0681+1771137]
Ordinal0 [0x008E41A8+803240]
Ordinal0 [0x00918C84+1019012]
Ordinal0 [0x00916C48+1010760]
Ordinal0 [0x0091493B+1001787]
Ordinal0 [0x00913699+997017]
Ordinal0 [0x00909223+954915]
Ordinal0 [0x0092D7AC+1103788]
Ordinal0 [0x00908C04+953348]
Ordinal0 [0x0092D9C4+1104324]
Ordinal0 [0x0093DAE2+1170146]
Ordinal0 [0x0092D5C6+1103302]
Ordinal0 [0x009077E0+948192]
Ordinal0 [0x009086E6+952038]
GetHandleVerifier [0x00CE0CB2+2738370]
GetHandleVerifier [0x00CD21B8+2678216]
GetHandleVerifier [0x00AC17AA+512954]
GetHandleVerifier [0x00AC0856+509030]
Ordinal0 [0x009D743B+1799227]
Ordinal0 [0x009DBB68+1817448]
Ordinal0 [0x009DBC55+1817685]
Ordinal0 [0x009E5230+1856048]
BaseThreadInitThunk [0x75F36739+25]
RtlGetFullPathName_UEx [0x77CD90AF+1215]
RtlGetFullPathName_UEx [0x77CD907D+1165]

CFDOrder class missing from __init__.py

An error is thrown when attempting to import CFDOrder from pytrading212
init.py is missing the CFDOrder class module from .order

Trialled locally adding the class into the init.py file with success:
from .order import EquityOrder, MarketOrder, LimitOrder, StopOrder, StopLimitOrder, ValueOrder, CFDMarketOrder, \ CFDLimitStopOrder, CFDOCOOrder, CFDOrder

Cannot run

Hello,

I'm with some dificulties to run the bot.

I've install trading212 and all the requirements but it keeps giving the below error:

Traceback (most recent call last):
File "trading_bot1.py", line 5, in
from pytrading212.trading212 import MarketOrder
ImportError: cannot import name 'MarketOrder' from 'pytrading212.trading212' (/home/ubuntu/.pyenv/versions/3.7.12/lib/python3.7/site-packages/pytrading212/trading212.py)

Here is my trading_bot.py code:

` import time
import yfinance as yf
from selenium import webdriver
from pytrading212.trading212 import Trading212
from pytrading212.trading212 import MarketOrder

email = 'xxxxxxxxxxxxxxxxxxxx'
password = 'xxxxxxxxxxxxxxx'
driver = webdriver.Chrome(executable_path='chromedriver.exe')

initialize Trading212 api

trading212 = Trading212(username=email, password=password, driver=driver)

iterate indefinitely

while True:
df = yf.Ticker('AMZN').history(period="1d", interval="1m").dropna() # drop NaN values

# get the last close price (1 minute candle)
last_price = df.iloc[-1]['Close']

# Write your trading logic here
# ...

if last_price < 3000:
    # BUY
    buy_order = trading212.execute_order(MarketOrder(instrument_code="AMZN_US_EQ", quantity=1))
    print(buy_order)
elif last_price > 4000:
    # SELL (note 'quantity=-1')
    sell_order = trading212.execute_order(MarketOrder(instrument_code="AMZN_US_EQ", quantity=-1))
    print(sell_order)

# wait 1 minute for the next candle
time.sleep(60)

`

Can you please help?

Stock split order correction

Hi,

I am trying to use the order extract to create a time series dataset of my portfolio, however I have come across an issue when stocks undergo a stock split. If I want to calculate the rolling weighted average of any stocks which I have purchased, it fails on any stocks which have had a stock split.

In the order dataframe, the values are not corrected retrospectively (e.g. Tesla stock went from ~$800 Aug 24 to ~$250 on Aug 25th, but the share/purchase price just jumps to the lower value from the stock split date). Is there any way to correct for this on your end when scraping the data? On the T212 portfolio, it is obviously corrected for, so I am wondering at what point this is done and why the output is not retrospectively corrected in the order sheet.

Thanks,
Adam

API calls seem to be broken.

Trading 212 is returning a 404 when sending a "Market Order". I'm going to assume that the API has changed in some way. Does anyone have any info on where the addresses/API code for the PUTs came from? I can see it in the site code, and there appears to be no API documents.

got multiple values for argument 'mode'

Hello,

I am trying to use your trading212 API on mac but I keep getting this error related to the mode argument. I am not sure what's going on here, because the Mode.DEMO argument seems to be returning the correct results.

Would really appreciate any help.

Regards

AttributeError: 'NoneType' object has no attribute 'isoformat'

Traceback (most recent call last):
File "Trading212.py", line 32, in
orders = trading212.get_orders()
^^^^^^^^^^^^^^^^^^^^^^^
File "pytrading212\trading212.py", line 149, in get_orders
params = {'olderThan': strftime(older_than.isoformat()),
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'isoformat'

not able to retrieve orders

Having error

Running the example I get the following error:

[01:17:50] Authenticating                                                                                                                                    console.py:12
Traceback (most recent call last):
  File "C:\Users\tachs\Desktop\trading212\trading212_v2.py", line 9, in <module>
    equity = Equity(email='[email protected]', password='xxxxxx',
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\pytrading212\trading212.py", line 239, in __init__
    super().__init__(email, password, driver, mode, constants.Trading.EQUITY)
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\pytrading212\trading212.py", line 50, in __init__
    self.driver.find_element(By.NAME, "email").send_keys(email)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 831, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "C:\Users\tachs\Desktop\trading212\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="email"]"}
  (Session info: chrome=111.0.5563.147)

Orders extract only shows latest orders

Hi,

Is there a way to extract all orders via the "trading212.get_orders()" function?
Currently in this format it only shows the most recent orders.

Thanks

Unable to log in

The driver only opens the login page and then prints the error message:

[23:25:22] Closing 'Cookies Popup' console.py:12
Authenticating console.py:12
[33960:2360:0519/232524.809:ERROR:device_event_log_impl.cc(239)] [23:25:24.809] USB: usb_service_win.cc:105 SetupDiGetDeviceProperty({{A45C254E-DF1C-4EFD-8020-67D146A850E0}, 6}) failed: Element not found. (0x490)

It gets stuck on this page:

image

Cannot change to live account

I'd like to use this API to extract the data in my live account and not my practice account - how can this be done?
I can see the 'Mode=Mode.DEMO' section of the Trading212 function but haven't been able to find what this should be for the live account instead.

Thanks

Maintenance / contributions

Hi @HellAmbro, thank you so much for publishing this... it helps a lot!
I was wondering if you are willing to take in some very easy PRs if I submit them,
mostly related to code styling (PEP8), the integration with Pandas and a simple
update to the README.

Thanks again

Orders does not include the 'Fill Price'

Hi,

The order extract is missing several details including the fill price, exchange rate and FX Fee. Would it be possible to include these in the dictionary you extract with trading212.get_orders(older_than=older_than, newer_than=newer_than please?

Thanks,
Adam

access denied in headless mode

when running your api in headless mode with chrome trading 212 will give me this screen
Image
when i dont use headless mode everything is fine. is this normal?

getting AttributeError when initialising Trading212

when i run my script i get this error messages:

ERROR: Couldn't read tbsCertificate as SEQUENCE
ERROR: Failed parsing Certificate

....\site-packages\pytrading212\trading212.py", line 113, in init
"Cookie": self.cookie,
AttributeError: 'Trading212' object has no attribute 'cookie'

edit: did some changes and in LIVE mode it does work, but DEMO still doesnt

Not able to trade

Logs in fine but then im slapped with this error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element

...
is not clickable at point (1329, 30). Other element would receive the click:
...

Driver issue?

When executing trading212.get_portfolio_composition() I get the following error:

selenium.common.exceptions.TimeoutException: Message: Stacktrace: #0 0x55bb3ede4ad3 <unknown> #1 0x55bb3eb44568 <unknown> #2 0x55bb3eb7ac46 <unknown> #3 0x55bb3eb7ae01 <unknown> #4 0x55bb3ebada64 <unknown> #5 0x55bb3eb9861d <unknown> #6 0x55bb3ebab824 <unknown> #7 0x55bb3eb984e3 <unknown> #8 0x55bb3eb6dd1a <unknown> #9 0x55bb3eb6ee75 <unknown> #10 0x55bb3ee12efd <unknown> #11 0x55bb3ee2c19b <unknown> #12 0x55bb3ee14c65 <unknown> #13 0x55bb3ee2cec8 <unknown> #14 0x55bb3ee08360 <unknown> #15 0x55bb3ee48a68 <unknown> #16 0x55bb3ee48be8 <unknown> #17 0x55bb3ee627fd <unknown> #18 0x7fcecebe9609 <unknown>

Any idea what is wrong? The driver is set up correctly and I can get into website and print the header etc, so I am guessing it's not related to driver setup. I can also login to my 212 account as I get the login notification.

cannot move past login

while it does show the login screen, moves past it and shows my main page with CFDs, I cannot move past the CFD object initialization. this is what I see on the screen

"""
config = configparser.ConfigParser()
config.read('./config.ini')
print (config['ACCOUNT']['email'])
driver = webdriver.Chrome(service=Service())
cfd = CFD(email=config['ACCOUNT']['email'], password=config['ACCOUNT']['password'], driver=driver, mode=Mode.LIVE)

15:13:44] Starting PyTrading212 v0.2.8 console.py:12
Trading: CFD
Mode: LIVE
[15:13:45] Closing 'Cookies Popup' console.py:12
Authenticating console.py:12
ERROR:main:An error occurred: Message:
Stacktrace:
#0 0x61ec2bcddc7a
#1 0x61ec2b9c0e2c
#2 0x61ec2ba0d661
#3 0x61ec2ba0d751
#4 0x61ec2ba51f64
#5 0x61ec2ba305ed
#6 0x61ec2ba4f303
#7 0x61ec2ba30363
#8 0x61ec2ba00247
#9 0x61ec2ba00b9e
#10 0x61ec2bca424b
#11 0x61ec2bca82f1
#12 0x61ec2bc8fafe
#13 0x61ec2bca8e52
#14 0x61ec2bc7479f
#15 0x61ec2bccd638
#16 0x61ec2bccd810
#17 0x61ec2bcdcdac
#18 0x7ed989c9ca94
#19 0x7ed989d29c3c

ERROR:main:Traceback:
Traceback (most recent call last):
File "debug-script.py", line 25, in
cfd = CFD(
File "/home/kalabharath/anaconda3/envs/mljar/lib/python3.8/site-packages/pytrading212/trading212.py", line 491, in init
super().init(email, password, driver, mode, constants.Trading.CFD)
File "/home/kalabharath/anaconda3/envs/mljar/lib/python3.8/site-packages/pytrading212/trading212.py", line 72, in init
WebDriverWait(self.driver, 120).until(EC.presence_of_element_located((By.CLASS_NAME, "company-logo")))
File "/home/kalabharath/anaconda3/envs/mljar/lib/python3.8/site-packages/selenium/webdriver/support/wait.py", line 105, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
#0 0x61ec2bcddc7a
#1 0x61ec2b9c0e2c
#2 0x61ec2ba0d661
#3 0x61ec2ba0d751
#4 0x61ec2ba51f64
#5 0x61ec2ba305ed
#6 0x61ec2ba4f303
#7 0x61ec2ba30363
#8 0x61ec2ba00247
#9 0x61ec2ba00b9e
#10 0x61ec2bca424b
#11 0x61ec2bca82f1
#12 0x61ec2bc8fafe
#13 0x61ec2bca8e52
#14 0x61ec2bc7479f
#15 0x61ec2bccd638
#16 0x61ec2bccd810
#17 0x61ec2bcdcdac
#18 0x7ed989c9ca94
#19 0x7ed989d29c3c

INFO:main:Current URL: https://app.trading212.com/

I am running ubuntu 24.04

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.