degiro-connector icon indicating copy to clipboard operation
degiro-connector copied to clipboard

What is the best way to determine whether an order is executed and against which price?

Open funnel20 opened this issue 3 years ago • 16 comments

I'm able to create and confirm an order based on your documentation.

When trading on the DeGiro website, once an order is executed, a popup is shown briefly. Is there a way to subscribe to this event via the connector?

Or should we poll actively to see the changes. For example to retrieve pending orders, and when the id is not in, assume it's executed.

Or via OrdersHistory or TransactionsHistory?

funnel20 avatar Dec 07 '21 21:12 funnel20

Hello there,

Notification I think you are referring at this feature in the website :

  • after : creating an Order
  • is displayed : a notification pop-in

Notification which is letting you know that an Order as been created.

As magical as this notification looks like, it seems to be done by :

  • retrieving pending Orders
  • every 2 seconds or so

Improvement I think its possible to make this notifications more convenient to fetch. Feel free to join me on Discord if you want to contribute.

Thanks

Chavithra avatar Dec 08 '21 05:12 Chavithra

I was not referring to the confirmation popup that the order is created. I'm referring tot the 2nd popup, that informs that the order is executed against price X.

funnel20 avatar Dec 08 '21 08:12 funnel20

Do you have a capture of the location of this "2nd popup" ?

Chavithra avatar Dec 08 '21 09:12 Chavithra

Not for now, but the flow on the DeGiro website is quite self-explanatory:

  1. When creating an order, it will be shown in the left table Outstanding, while the confirmation popup "new order created" is shown briefly: Screenshot 2021-12-08 at 10 31 13

  2. When the target price is met and the order is executed, a confirmation popup "order executed against pice X" is shown briefly, while the order is moved to the right column, where it shows the execution price (since that can be different than the target price in the original order)

While you explained how to get event 1, I'm particularly interested in getting an event from the API for event 2.

funnel20 avatar Dec 08 '21 09:12 funnel20

Notification Just checked how the website is doing.

Looks like both sections (Outstanding and Latests transactions) use this endpoint :

  • trading/secure/v5/update

That you can consume with the method :

  • get_update

Example It is not in the example file but the feature to fetch TRANSACTIONS is available.

Here is how you can do :

# SETUP REQUEST
request_list = Update.RequestList()
request_list.values.extend(
    [
        Update.Request(option=Update.Option.ORDERS, last_updated=0),
        Update.Request(option=Update.Option.PORTFOLIO, last_updated=0),
        Update.Request(option=Update.Option.TOTALPORTFOLIO, last_updated=0),
        Update.Request(option=Update.Option.TRANSACTIONS, last_updated=0),
    ]
)

# FETCH DATA
update = trading_api.get_update(request_list=request_list, raw=True)

Hope that helps

Chavithra avatar Dec 08 '21 10:12 Chavithra

Awesome, I'll try this out. Just for my understanding, is the get_update() used as a single call with a single answer, or is it more similar to fetch_data() as a a data stream, which will send updates once they occur?

funnel20 avatar Dec 08 '21 10:12 funnel20

Not exactly : fetch_data uses long polling.

Here this is just refreshing : the website seems to reload the data every 2 secondes.

Note that you will have to update this parameter to get the exact same data then the website :

  • last_updated

Chavithra avatar Dec 08 '21 13:12 Chavithra

I have tried this, and I see the recent transactions. What is the meaning of the value for parameter last_updated? I.e. what if set to a value other dan 0?

funnel20 avatar Dec 08 '21 17:12 funnel20

You need to send back the last_updated you received.

I think this is how this endpoint avoids sending you the same data twice.

Chavithra avatar Dec 09 '21 02:12 Chavithra

This is how we've implemented it after placing an order:

# IMPORTANT
# The response doesn't show any details whether an order was executed, only that the order is accepted.
# To check whether the order is executed and for what price, 2 events should be started:
#
# 1) Request pending orders via `get_update()` with a list that contains `Update.Option.ORDERS`
#       This returns an array with pending orders, including the order ID. Keep polling while the order ID is present in the ID.
#       Once the order is not present (this can already be at the first request when the order was executed immediately), 
#       any of these 2 events have occured:
#           a) The order has been deleted
#           b) The order has been executed
#       To determine whether it's deleted or executed, the Transaction history should be requested:
#
# 2) Request the Transaction History for today via `get_transactions_history()`
#       Unfortunately this array doesn't contain the order ID. 
#       So we need to filter on the ticker (`productId`), amount and action for transactions that were created after the confirmation date of the order (as returned by `confirm_order()`). 

We even take into account that the order might be executed by multiple transactions.

funnel20 avatar Dec 17 '21 18:12 funnel20

This is how we've implemented it after placing an order:

# IMPORTANT
# The response doesn't show any details whether an order was executed, only that the order is accepted.
# To check whether the order is executed and for what price, 2 events should be started:
#
# 1) Request pending orders via `get_update()` with a list that contains `Update.Option.ORDERS`
#       This returns an array with pending orders, including the order ID. Keep polling while the order ID is present in the ID.
#       Once the order is not present (this can already be at the first request when the order was executed immediately), 
#       any of these 2 events have occured:
#           a) The order has been deleted
#           b) The order has been executed
#       To determine whether it's deleted or executed, the Transaction history should be requested:
#
# 2) Request the Transaction History for today via `get_transactions_history()`
#       Unfortunately this array doesn't contain the order ID. 
#       So we need to filter on the ticker (`productId`), amount and action for transactions that were created after the confirmation date of the order (as returned by `confirm_order()`). 

We even take into account that the order might be executed by multiple transactions.

Who is « we » ?

I think this can be more straightforward.

If I remember right « get_update » can let you know that the order was executed.

But you need to provide the « last_updated ».

Chavithra avatar Dec 17 '21 19:12 Chavithra

@Chavithra Well, "we" is a group of friends who are using your awesome connector into a project. I recently helped you with PR https://github.com/Chavithra/degiro-connector/pull/42 .

There were some issues processing trading_api.get_update(), hence this is what we came up with. It works for now, just wanted to inform other users about this, as it provides at least an answer to the question in the issue description (maybe not the best).

funnel20 avatar Dec 23 '21 10:12 funnel20

@funnel20 I think I know how to integrate this "order state detection feature".

But I don't have the time for this yet.

If you are up for the challenge we can brainstorm a specification for this together.

Chavithra avatar Dec 24 '21 11:12 Chavithra

@Chavithra I've finally found a way to link the order id and transaction id. Once I've finished my prototype, I'll post my findings here.

funnel20 avatar Feb 15 '22 10:02 funnel20

@funnel20 I'm very curious about the way you link order_id and transaction_id. Is there any followup?

richardbeumer avatar Jan 02 '23 10:01 richardbeumer

@funnel20 I'm very curious about the way you link order_id and transaction_id. Is there any followup?

Unfortunately not, since we have put our project on halt.

funnel20 avatar Jan 02 '23 12:01 funnel20