API Support Forum
OEC API > API Support > Private Sub Connection_Disconnected DisconnectionReason_SocketError = 0
Author Topic: Private Sub Connection_Disconnected DisconnectionReason_SocketError = 0
(2 messages, Page 1 of 1)
Moderators: VPfau
ASykes4318
Posts: 18
Joined:


Posted: Dec 15, 2021 @ 12:02 PM             Msg. 1 of 2
Auto-Reconnect still not working does anyone know why??

Using GF API_COM the following code is returning an invalid password, then Already connecting over and over....requiring a killing of the application to get to stop. The same code works fine with OEC API.

The auto-reconnect has changed and is not working the same??

Please help!!

Private Sub Connection_Disconnected(ByVal reason As GF_Api_COM.DisconnectionReason, ByVal message As String)
Dim i As Integer
On Error GoTo Err_Connection_Disconnected

If Form_Login.chkAutoReconnect Then
Call NES.SaveTradeStates
Call Form_Login.cmdConnect_Click
Else
Set c = Nothing
End If
Debug.Print , "Connection_Disconnected failed.."; MilliTime() & " reason"
Form_Login.UpdateStatus

Exit_Connection_Disconnected:
On Error Resume Next
Exit Sub

Err_Connection_Disconnected:
gParms = CStr(message)
Call LogError(Err.Number, Err.Description, "GFClass", "Connection_Disconnected()", gParms)
Resume Exit_Connection_Disconnected
End Sub

Public Sub cmdConnect_Click()
On Error GoTo Err_cmdConnect_Click
Dim usr, pwd As String
'Stop
Me.chkAutoReconnect.value = True
' Me.chkAutoReconnect = True
Debug.Print "Connect button pressed."
DoCmd.Hourglass True

If Glob Is Nothing Then Set Glob = New GFClass

If Not Glob.Connected Then
usr = Username()
pwd = Password()
If usr = vbNullString Or pwd = vbNullString Then Exit Sub
Glob.Connect usr, pwd, AutoReconnect()

End If

Form_frmQuotes.Requery
Form_frmOrderEntry.Requery
Form_frmCompletedOrders.Requery
Form_frmActiveOrders.Requery
Form_frmAvgPos.Requery

Debug.Print "Connect button actions are completed."

Exit_cmdConnect_Click:
On Error Resume Next
DoCmd.Hourglass False
'MsgBox "cmdConnect_Click():OUT"
Exit Sub

Err_cmdConnect_Click:
DoCmd.Hourglass False
MsgBox Err.Description
Resume Exit_cmdConnect_Click
Resume Next


End Sub

Public Sub Connect(ByVal Name As String, ByVal Pass As String, Reconnect As Boolean)
On Error GoTo Err_Connect
'Do remove Reconnect parameter in this sub because the api reads it,
' so, no need to use .WithForceLogin_2 (Reconnect) in the builder.

'MsgBox "Connect():IN"
Debug.Print "Connect Sub executing.."

'Stop
If c Is Nothing Then
Set c = New GFComClient
c.Threading.CreateRunnerFor(c).Start
Set Connection = c.Connection.Aggregate
End If

If Len(gUUID) = 0 Or Len(gAPIServer) = 0 Or Len(gAPIPort) = 0 Then
RestartTradingApp
Exit Sub
End If

Dim builder As ConnectionContextBuilder
Set builder = New ConnectionContextBuilder
builder.WithUserName(Name) _
.WithPassword(Pass) _
.WithUUID(gUUID) _
.WithHost(gAPIServer) _
.WithForceLogin_2(True) _
.WithPort (gAPIPort)

Connection.Connect builder.Build

Debug.Print "Conn Builder built.."

Forms!Login!txtDebugMsg = "Connecting at " & Now()


Exit_Connect:
On Error Resume Next
Exit Sub

Err_Connect:
MsgBox Err.Description
gParms = Name & "-" & Pass
Call LogError(Err.Number, Err.Description, "GFClass", "Connect()", gParms)
If Err.Number = 0 Then
MsgBox Err.Description
' Call Form_Login.cmdDisconnect_Click
End If
Resume Exit_Connect
'MsgBox "Connect():OUT"

End Sub
Anthony Sykes

Edited by ASykes4318 on Jan 10, 2022 03:53 PM
ETrifonov
Posts: 63
Joined:


Posted: Feb 02, 2022 @ 08:12 PM             Msg. 2 of 2
Hello Anthony,

Same as for your previous request - GF API doesn;t provide auto reconnect feature out of the box.
Please see reconnect same here: https://gainfutures.com/GFAPI/?topic=html/da57e5d9-0be9-4b5c-a8c8-5e39e11b5c98.htm
Evgeny