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
Best Answer
-
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.html0
Answers
-
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.0 -
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 StringActiveSheet.Range("A1").Select
Do
ActiveCell.Offset(1, 0).Select
IndexRIC = ActiveCell.ValueCall myRHistoryAPIExample(myRIC)
Application.Wait Now + #12:00:05 AM#
Loop Until myRIC = ""
End SubThe 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 StringActiveSheet.Range("A1").Select
' Do
ActiveCell.Offset(1, 0).Select
IndexRIC = ActiveCell.ValueCall myRHistoryAPIExample(myRIC)
' Application.Wait Now + #12:00:05 AM#
' Loop Until myRIC = ""
End SubAny idea why OnImage is not triggered once the above code is wrapped in a loop?
Many thanks in advance,
Best regards
Richard
0 -
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
0 -
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.
0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛