Subscribe for Events (O2GO, VBA)
From FxCodeBaseWiki
To subscribe for the events in VBA you must use an instance of the FXCore.TradeDeskEventsSink
interface. You must declare it using WithEvents
keyword. When such declaration is made, the variable keeping the FXCore.TradeDeskEventsSink
appears in the list of event sources and all related events appears in the list:
So, all you need is to create an instance of FXCore.TradeDeskEventsSink
object and then use Subscribe
method to start received the events.
In the example below use StartCore()
to start receiving the events and StopCore()
to log off and stop.
Option Explicit
Const USR = "username"
Const PWD = "password"
Const CONN = "Demo"
Const URL = "http://www.fxcorporate.com"
Dim core As FXCore.CoreAut
Dim desk As FXCore.TradeDeskAut
Dim WithEvents desk_events As FXCore.TradeDeskEventsSink
Dim subscribtion As Long
Sub StartCore()
Set core = New FXCore.CoreAut
Set desk = core.CreateTradeDesk("trader")
Set desk_events = New FXCore.TradeDeskEventsSink
subscribtion = desk.Subscribe(desk_events)
Call desk.Login(USR, PWD, URL, CONN)
End Sub
Sub StopCore()
Call desk.Unsubscribe(subscribtion)
desk.Logout
End Sub
Private Sub desk_events_OnRowChanged(ByVal pTableDisp As Object, ByVal sRowID As String)
Dim table As FXCore.TableAut
Dim row As FXCore.RowAut
Dim sheet As Excel.Worksheet
Set table = pTableDisp
If LCase(table.Type) = "offers" Then
Set row = table.FindRow("OfferID", sRowID, 0)
Set sheet = ActiveWorkbook.Worksheets.Item(1)
sheet.Cells(2, 1) = row.CellValue("Instrument")
sheet.Cells(2, 2) = row.CellValue("Bid")
sheet.Cells(2, 3) = row.CellValue("Ask")
End If
End Sub
Private Sub desk_events_OnSessionStatusChanged(ByVal sStatus As String)
Dim sheet As Excel.Worksheet
Set sheet = ActiveWorkbook.Worksheets.Item(1)
sheet.Cells(1, 1) = sStatus
End Sub
See also: Visual Basic For Application (O2GO)
This Article in Other Languages
Language: | English • español |
---|