degiro-connector
degiro-connector copied to clipboard
What is the best way to determine whether an order is executed and against which price?
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?
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
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.
Do you have a capture of the location of this "2nd popup" ?
Not for now, but the flow on the DeGiro website is quite self-explanatory:
-
When creating an order, it will be shown in the left table Outstanding, while the confirmation popup "new order created" is shown briefly:
-
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.
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
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?
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
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
?
You need to send back the last_updated
you received.
I think this is how this endpoint
avoids sending you the same data twice.
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.
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 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 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 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 I'm very curious about the way you link order_id and transaction_id. Is there any followup?
@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.