question

Upvotes
Accepted
3 1 1 4

When are Historyueery OnImage/OnUpdate triggered? What is the difference between running F8 and F5?

Dear all,

I tried to follow the Tutorial 9 - Time Series History - RHistoryAPI and got stuck at the point when the vba code is supposed to jump from the Sub myRHistoryAPIExample to Sub

myRHistoryAPIExample_OnUpdate.

In my case the code was simply running through Sub myRHistoryAPIExample and never got to the OnUpdate sub.

I resolved the problem by using OnImage instead of OnUpdate and could then use a_historyTable in order to perform some checks in my code. However my code is only jumping from myRHistoryAPIExample to myRHistoryAPIExample_OnImage when I press F5 to run the code. In case I rund the code via F8 the macro will never jump out of myRHistoryAPIExample and never perform the code in the OnImage Sub.

Could please somebody help and explain how and when OnUpdate and OnImage are triggered?

Many thanks in advance,

Richard

Private Sub myRHistoryAPIExample()

Dim strFldList As String
Dim myResult As String
Dim a_historyTable As Variant
Dim rw As Integer, col As Integer

On Error GoTo ErrorHandler

Set myRHistoryManager = CreateRHistoryManager
myRHistoryCookie = myRHistoryManager.Initialize("MY BOOK")
Set myRHistoryQuery = myRHistoryManager.CreateHistoryQuery(myRHistoryCookie)

With myRHistoryQuery
.InstrumentIDList = .BKXU
.FieldList = "TRDPRC_1.TIMESTAMP;TRDPRC_1.CLOSE"
.RequestParams = "INTERVAL:1D START:20-DEC-1999 END:05-JAN-2000"
.DisplayParams = "Sort:A CH:Fd"
.RefreshParams = ""
.Subscribe


End With
Exit Sub
ErrorHandler:
Debug.Print Err.Number & ": " & Err.Description

End Sub

Private Sub myRHistoryQuery_OnImage(ByVal a_historyTable As Variant)
Dim rw As Integer, col As Integer

For rw = LBound(a_historyTable, 1) To UBound(a_historyTable, 1)
For col = LBound(a_historyTable, 2) To UBound(a_historyTable, 2)
Range("C1").Offset(rw, col).Value = a_historyTable(rw, col)
Next col
Next rw

End Sub

eikoneikon-com-api
icon clock
10 |1500

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

Upvotes
Accepted
39.4k 77 11 27

Hi Richard,

The code snippet you provided can never produce any result because myRIC variable is never initialized. But I assume it's just a typo and in your actual example you assign a value to myRIC variable rather than to IndexRIC. In this case the behavior you experienced is normal and expected. OnImage or any other event for that matter cannot be raised while your RunLoop procedure is being executed. Any events can only be raised once your RunLoop procedure exits. Application.Wait method does not yield execution thread to events. It suspends the thread, which in single threaded VBA means there's no code being executed at all. COM objects cannot raise events while the thread is suspended because these objects live on the same thread. To achieve what you're looking to do see a similar question that's been previously asked and answered on this forum.
https://community.developers.refinitiv.com/questions/11472/how-can-i-run-rhistory-in-a-loop.html

icon clock
10 |1500

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

Upvotes
39.4k 77 11 27

Hi Richard,
The behavior you experienced is normal and expected. As stated in RHistory API Reference Guide, OnImage event is raised when the timeseries requested are received. OnUpdate event is raised after OnImage event if and when the updates are received from the real-time stream. The real-time stream is only opened when you request data from intraday intervals. If you request daily timeseries, OnUpdate event will never be raised.
When you execute the code step by step in break mode COM events are not raised. In order for COM events to be raised you have to run the code by hitting F5 rather than F8. More accurately you can step through the code in break mode up until you reach the Subscribe method of RHistoryQuery object. For RHistoryQuery object to raise any events it implements the Subscribe method has to be executed not in break mode. This is not specific to RHistory API. VBA code triggering the event must not be executed in break mode for any COM object to be able to raise events.
I hope this helps.

icon clock
10 |1500

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

Upvotes
3 1 1 4

Hi Alex,

Many thanks for your helpful answer.

I have a range of RICs in column A for which I want to run the above mentioned code in a loop like below.

Private Sub RunLoop()
Dim myRIC As String

ActiveSheet.Range("A1").Select

Do
ActiveCell.Offset(1, 0).Select
IndexRIC = ActiveCell.Value

Call myRHistoryAPIExample(myRIC)

Application.Wait Now + #12:00:05 AM#

Loop Until myRIC = ""
End Sub

The result is that the code is running through all RICs, but I never receive the output as OnImage is never trigerred.

In case I run the code without any loop as below, the OnImage event is triggered and I receive the result for one RIC.

Private Sub RunLoop()
Dim myRIC As String

ActiveSheet.Range("A1").Select

' Do
ActiveCell.Offset(1, 0).Select
IndexRIC = ActiveCell.Value

Call myRHistoryAPIExample(myRIC)

' Application.Wait Now + #12:00:05 AM#

' Loop Until myRIC = ""
End Sub

Any idea why OnImage is not triggered once the above code is wrapped in a loop?

Many thanks in advance,

Best regards

Richard

icon clock
10 |1500

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

Upvotes
3 1 1 4

Hi Alex,

Many thanks for your answer.

Unfortunately I can't access you link receiving the below error message:

Access Denied

We're sorry, but you do not have permission to do the activity you attempted. If you believe this to be in error, please contact the site administrator(s).

I would be very grateful for an example how to use loops with RHIsotry API.

Many thanks in advance,

Best regards

RIchard Sponda

icon clock
10 |1500

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

Upvotes
39.4k 77 11 27

Hi Richard,

Can you try the link again? For some reason that discussion was marked as private, although there's no private content in it. I just made it public. You should be able to view it now.

icon clock
10 |1500

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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