Git Product home page Git Product logo

Comments (8)

b-aeby avatar b-aeby commented on July 28, 2024 1

Hi Chavithra,
Thank you for all, now error content is fully available and unnecessary lines have been removed.
I don't have a Discord account yet, I'll create one soon.
Regards

from degiro-connector.

Chavithra avatar Chavithra commented on July 28, 2024

Hello Ben,

to see the error messages : one solution is to use the logs.

Here is how to setup logging level :

import logging
logging.basicConfig(level=logging.DEBUG)

from degiro-connector.

b-aeby avatar b-aeby commented on July 28, 2024

Hello Chavithra,

Thank you, logging was already in DEBUG level, but the log doesn't return the confirmation error details.
Here is a way to reproduce:
Open an order for a price too low on stock : SOON | CH0012549785 limit 1.00CHF, size 1. (Displayed price at 12h48 is 350.10CHF with 15 minutes delay.)
Validate order, then confirm.
A popup shows this error message:

Le prix renseigné 1.0000 est trop bas par rapport au dernier prix 347.7000. Le prix minimum est de 278.1600.

Doing this by degiro_connector with:

order = Order(
    action=Order.Action.BUY,
    order_type=Order.OrderType.LIMIT,
    price=1,
    product_id=353484,
    size=1,
    time_type=Order.TimeType.GOOD_TILL_DAY,
)


checking_response = self.trading_api.check_order(order=order, raw=False)
# SEND CONFIRMATION
confirmation_response = self.trading_api.confirm_order(
        confirmation_id=checking_response.confirmation_id,
        order=order,
        raw=True
    )

All we got is a None response without content:

type(confirmation_response)
Out[21]: NoneType

In the log :

CRITICAL:degiro_connector.trading.actions.action_confirm_order:<Response [400]>
CRITICAL:degiro_connector.trading.actions.action_confirm_order:400 Client Error: Bad Request for url: https://trader.degiro.nl/trading/secure/v5/order/[...]

It seams to fail in confirmation response treatment.
Using another degiro python api from lolokraus : degiro), I can retrieve the error message and get the useful datas from the error text. The error returned has this content :

{"errors":[{"text":"Le prix renseigné 1.0000 est trop bas par rapport au dernier prix 347.7000. Le prix minimum est de 278.1600."}]}

If the error content could be returned instead of None, that would be useful for realtime price or tick size.
Thank you
Ben

from degiro-connector.

Chavithra avatar Chavithra commented on July 28, 2024

Le prix renseigné 1.0000 est trop bas par rapport au dernier prix 347.7000. Le prix minimum est de 278.1600.

You are French ?

Ok got your issue.

Released a new version with better error logging.

Does that fit your need ?

from degiro-connector.

b-aeby avatar b-aeby commented on July 28, 2024

Thank you for your quick reaction!
I am Swiss, in the french speaking part.

I can now read the error in the log, but an error occurs:

UnboundLocalError: local variable 'response_dict' referenced before assignment

One objective is to use error content to get the tick size and correct the failing orders. Error logging is interesting, but won't help for automated orders correction.

I think these modifications in "action_confirm_order.py" may do the job (not sure it respects your coding style). The error content is retrieved if raw is set to True:

    @classmethod
    def confirm_order(
        cls,
        confirmation_id: str,
        credentials: Credentials,
        order: Order,
        session_id: str,
        logger: logging.Logger = None,
        raw: bool = False,
        session: requests.Session = None,
    ) -> Union[Order.ConfirmationResponse, Dict, None]:
        if logger is None:
            logger = cls.build_logger()
        if session is None:
            session = cls.build_session()

        int_account = credentials.int_account
        url = urls.ORDER_CONFIRM
        url = f"{url}/{confirmation_id};jsessionid={session_id}"

        params = {
            "intAccount": int_account,
            "sessionId": session_id,
        }

        order_dict = cls.order_to_api(order=order)

        request = requests.Request(
            method="POST",
            url=url,
            json=order_dict,
            params=params,
        )
        prepped = session.prepare_request(request)
        response_raw = None

        try:
            response_raw = session.send(prepped, verify=False)
            response_raw.raise_for_status()
            response_dict = response_raw.json()
        except requests.HTTPError as e:
            logger.fatal(response_raw.status_code)
            logger.fatal(response_raw.text)
            response_dict = response_raw.json()
        except Exception as e:
            logger.fatal(e)
            response_dict = response_raw.json()
            if raw is True:
                return response_dict
            else:
                return None

        if (
            isinstance(response_dict, dict)
            and "data" in response_dict
            and "orderId" in response_dict["data"]
        ):
            order.id = response_dict["data"]["orderId"]

            if raw is True:
                return response_dict
            else:
                return cls.confirmation_response_to_grpc(
                    payload=response_dict,
                )
        else:
            if raw is True:
                return response_dict
            else:
                return None

from degiro-connector.

Chavithra avatar Chavithra commented on July 28, 2024

So you are not only using this for debugging : you want to returned error to do some automation with it ?

Maybe we can reach each other on Discord so we can find a solution which fit.

from degiro-connector.

funnel20 avatar funnel20 commented on July 28, 2024

@b-aeby Please see my ongoing issue #54 to return the fault data.

from degiro-connector.

b-aeby avatar b-aeby commented on July 28, 2024

from degiro-connector.

Related Issues (20)

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.