Closed funnel20 closed 2 years ago
30MIN TIMEOUT You can try by running some scripts with a timers. I have estimated 15sec and 30min were close enough timeouts last time I have checked : for the Quotecast and Trading.
RECONNECT Yes that is the purpose for which I have raised this exception. I am using it like that : to catch it on time and reconnect without generating errors on API side.
PRE-MARKET PRICES Which function from Trading API are you using to get pre-market prices ? How come it doesn’t refresh the timeout ? I am suprised.
Thanks
Hi @Chavithra Thanks, for the confirmation. Regarding Pre-market prices, we use Yahoo Finance as we did not found any frequent updates from DeGiro QuoteCast API.
I'll make a PR to update the docu to reflect:
TradingAPI()
init functionTimeoutError
exception @Chavithra PR is ready
Closed by PR #65
We build a simple script:
connect()
.check_order()
to the Trading API.So the first BUY order in step 4, starts at least 1 hour after connecting the Trading API. As expected, it did throw a
TimeoutError
exception.We're looking for a solution. The docu states:
Analysis
Where comes "around 30 minutes" from? Digging into the source code, I discovered that the Trading API uses a nested
timeout
property in theModelConnection
object. It's set to constanttimeouts.TRADING_TIMEOUT
which is defined at 1800 seconds. This is exactly 30 minutes, not "around".How to handle the timeout exception and restore the connection? Of course a not so robust/pretty work-around would be to schedule a recurring call to for instance
get_update()
, to keep the session alive. However, it would be more appropriate to detect theTimeoutError
exception and act upon it.Since I've discovered the
ModelConnection
object, I can prototype by changing the timeout to 2 seconds, and create an order 3 seconds later:This raises indeed a
TimeoutError
exception:It appears that a proper solution is to add an exception handler to each call to the Trader API. In case of an exception it will call
connect()
again, followed by a repeat of the original call. So the last row of the sample code:Is replaced by:
This shows the following in the log, while the order is checked successfully:
Can we adjust/extend the timeout? Why is
timeouts.TRADING_TIMEOUT
set to 1800? Is this a necessity for DeGiro, or can we increase it? To for example 36000 (10 hours) so we will not encounterTimeoutError
exceptions during a trading day.After we can come up with proper answers, I'm happy to update the docu.