question

Upvotes
Accepted
1 0 0 3

Cannot retrive data in VBA from AdxRtHistory

Hello,

I need help with AdxRtHistory.

I request data via VBA but does not wait for data to be retrieved.

With myAdxRtHist

While (.DataStatus = RT_DS_NULL_EMPTY Or .DataStatus = RT_DS_PARTIAL) And .RunStatus = RT_RS_BUSY

Wend

End With

Could you please help me make vba wait until it gets an answer from Reuters ?

Thanks a lot,

Hamza

eikoneikon-com-apivba
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

1 Answer

Upvotes
Accepted
39.2k 75 11 27

Hi @Hamza Guedira

VBA is single threaded. While your loop is running, it occupies the thread disallowing AdxRtHistory object to retrieve and process the data. AdfinX Real-Time API is asynchronous by design. Rather than trying to trick it into producing synchronous behavior, I would strongly advise that you follow the asynchronous pattern and split your code into the procedure that requests the data and immediately exits, and OnUpdate event callback, which will be raised once the object finished retrieving the data. See the tutorial following the link below for further details and an example.
https://developers.refinitiv.com/en/api-catalog/eikon/com-apis-for-use-in-microsoft-office/tutorials#tutorial-5-time-series-history-adx-rt-history

If however you must opt for synchronous data retrieval, then you need to make sure to include in the body of your loop the DoEvents statement to cede the execution thread and allow messages from Windows message queue to be processed. I would also strongly advise to implement a timeout to prevent an endless loop. Attached is a quick and dirty example. In production you will want to include a lot more error handling, as the synchronous retrieval pattern makes the example more error prone. I cannot help but wonder if the addition of timeout implementation based on an arbitrary timeout interval and extra error handling are worth whatever it is that you're trying to achieve by implementing synchronous retrieval.
adxrthistorysynchronous.zip


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea