Author |
Topic: VBA Sample COM Book (4 messages, Page 1 of 1) |
||||
---|---|---|---|---|---|
Moderators: VPfau | |||||
ASykes4318 Posts: 18 Joined: |
The Auto-Reconnect does not appear to be passed on login and does not work. What changes have to be made to the sample code provided by StoneX to get the reconnect to work properly?
Public WithEvents connection As ServerConnectionApi Public client As GF_Api_COM.IGFComClient Private Server As String Public Sub Disconnect() If Not connection Is Nothing Then connection.Disconnect Rem Set c = Nothing End If End Sub Public Sub Connect(Name As String, Pass As String, Reconnect As Boolean) On Error GoTo Err If client Is Nothing Then Set client = New GFComClient client.Threading.CreateRunnerFor(client).Start Set connection = client.connection.Aggregate Server = "api.gainfutures.com" End If Dim Builder As ConnectionContextBuilder Set Builder = New ConnectionContextBuilder Builder.WithUserName(Name) _ .WithPassword(Pass) _ .WithUUID("9e61a8bc-0a31-4542-ad85-33ebab0e4e86") _ .WithHost(Server) _ .WithPort (9210) connection.Connect Builder.Build Exit Sub Err: MsgBox Err.Description End Sub Public Function Connected() If connection Is Nothing Then Connected = False Else Connected = connection.IsConnected End If End Function Private Sub connection_LoginComplete() On Error GoTo Err Config.UpdateStatus AvgPositions.Initialize client Quotes.Initialize client Quotes.SubscribeAll True DOM.Initialize client Balances.Initialize client Bars.Initialize client CompleteOrders.Initialize client WorkingOrders.Initialize client Abbreviated.Initialize client Exit Sub Err: MsgBox Err.Description End Sub Private Sub connection_LoginFailed(ByVal reason As FailReason) On Error GoTo Err Config.LoginFailed reason Exit Sub Err: MsgBox Err.Description End Sub Private Sub connection_Disconnected(ByVal reason As DisconnectionReason, ByVal message As String) On Error GoTo Err Config.UpdateStatus AvgPositions.Reset Balances.Reset Bars.Reset CompleteOrders.Reset WorkingOrders.Reset Abbreviated.Reset Exit Sub Err: MsgBox Err.Description End Sub Public Function FindNearest(Symbol As String) As Contract Dim bcName As String If (Len(Contract) <= 3) Or (client Is Nothing) Then Set FindNearest = Nothing Else bcName = Mid(Contract, 1, Len(Contract) - 3) Dim bc As BaseContract Set bc = client.contracts.Base.Get_3(bcName) If Not bc Is Nothing And bc.contracts.Count > 0 Then Set FindNearest = bc.contracts.GetAt(0) Else Set FindNearest = Nothing End If End If End Function Anthony Sykes
|
||||
ETrifonov Posts: 63 Joined: |
Hello Anthony,
GF API doesn't provide auto reconnect feature out of the box and should be implemented on client side. Please see documentation sample here: https://gainfutures.com/GFAPI/?topic=html/da57e5d9-0be9-4b5c-a8c8-5e39e11b5c98.htm Evgeny
|
||||
ASykes4318 Posts: 18 Joined: |
Thanks for your reply...we are using the GF_API_COM and the following are not available:
1) GF.Api.Utils.GFApiEventHandler 2) CancellationTokenSource Can you help me with useful code snippets that work for "GF_API_COM"?? Anthony Sykes
|
||||
ETrifonov Posts: 63 Joined: |
Hello Anthony.
1) You can simply not use GFApiEventHandler - it is not mandatory there. 2) It's in System.Threading namespace. Below is some snippet you can try. Also, you can check our COM API samples here: https://bitbucket.org/GainFuturesDev/comapisamples
Evgeny Edited by ETrifonov on Feb 06, 2022 10:00 PM |
||||