API Support Forum
User Profile

Viewing User Profile for: ASykes4318


About

N/A

Oct 03, 2022 09:16 AM

Jun 26, 2023 01:42 PM



Post Statistics
ASykes4318 has contributed to 18 posts out of 5593 total posts

20 most recent posts:

API Support » Latest GAIN GFAPI COM x64 version Oct 03, 2022 @ 09:16 AM (Total replies: 1)

What is the latest GAIN GFAPI COM x64 version and where do I go download it?
Anthony Sykes


API Support » VBA Sample COM Book Feb 03, 2022 @ 06:15 AM (Total replies: 3)

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


API Support » VBA Sample COM Book Jan 29, 2022 @ 08:11 AM (Total replies: 3)

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


API Support » Private Sub Connection_Disconnected DisconnectionReason_SocketError = 0 Dec 15, 2021 @ 12:02 PM (Total replies: 1)

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

API Support » Excel DOM example not working Dec 29, 2020 @ 09:25 PM (Total replies: 1)

The following statement is giving us the following error from the excel DOM Code:
• Object doesn't support this property or method
Is there an update code procedure that works with the new GF API??
We would like to also send maindraft and draftTP only also is this possible??

orders.SendLinkedOrders mainDraft, OSOGroupingMethod_ByPrice, linked

Sub SendOrder(side As OrderSide, row As Integer, qty As Integer)
On Error GoTo Err
'Stop
Dim account As account
Set account = CurrentAccount
If account Is Nothing Then
MsgBox "Invalid account"
Else
Dim Price As Double
Price = CurrentTop - (row - TopRow) * CurrentContract.tickSize
If qty < 0 Then
DecreaseQty side, Price, -qty, account
Else
Dim Builder As OrderDraftBuilder
Set Builder = New OrderDraftBuilder
Builder.WithSide side
Builder.WithPrice Price
Builder.WithQuantity qty
Builder.WithContractID CurrentContract.ID
Builder.WithComments "DOM"
Builder.WithAccountID account.ID

If (side = OrderSide_Buy) And (Price CurrentContract.CurrentPrice.LastPrice) Then
Builder.WithOrderType (OrderType_Limit)
Else
Builder.WithOrderType (OrderType_Stop)
End If
Dim sl As Integer, tp As Integer
sl = Range("K6")
tp = Range("K7")
Dim mainDraft As OrderDraft
Dim draftSL As OrderDraft
Dim draftTP As OrderDraft
Set mainDraft = Builder.Build
If (sl = 0) And (tp = 0) Then
Stop
orders.SendOrder mainDraft
Else
If sl 0 Then
If mainDraft.side = OrderSide_Buy Then
Builder.WithSide OrderSide_Sell
Builder.WithPrice mainDraft.Price - sl * CurrentContract.tickSize
Else
Builder.WithSide OrderSide_Buy
Builder.WithPrice mainDraft.Price + sl * CurrentContract.tickSize
End If
Builder.WithOrderType OrderType_Stop
Set draftSL = Builder.Build
End If
If tp 0 Then
If mainDraft.side = OrderSide_Buy Then
Builder.WithSide OrderSide_Sell
Builder.WithPrice mainDraft.Price + tp * CurrentContract.tickSize
Else
Builder.WithSide OrderSide_Buy
Builder.WithPrice mainDraft.Price - tp * CurrentContract.tickSize
End If
Builder.WithOrderType OrderType_Limit
Set draftTP = Builder.Build
End If
Dim linked As OrderDraftList
Set linked = New OrderDraftList
If (tp 0) Then
linked.Add draftTP
End If
If sl 0 Then
linked.Add draftSL
End If
orders.SendLinkedOrders mainDraft, OSOGroupingMethod_ByPrice, linked
End If
End If
End If
Exit Sub
Err:
MsgBox Err.Description
End Sub
Anthony Sykes


API Support » Runtime 13 Type Mismatch error - cancel All Dec 20, 2020 @ 09:59 AM (Total replies: 1)

We use VBA in MS Access and would like to cancel all orders for a single contact Based on the Orders' state. After it meets the criteria within the If statement, we used a DAO.recordset to retrieve the OderID, from our local table, which the table was filled with the orders data previously including their OrderID.

Problem is; the OrdersApi.CancelOrder fails with Runtime 13 Type Mismatch error. Our parameters have the correct data type for the criteria required. They are; Long for the OrderID and 0 (as "Manual") for the type, we left the "Location" blank since it's optional.



'Created MSansa 2020-1214
On Error GoTo Err_CancelWorkingOrders
Dim i As Integer
Dim Order As GF_Api_COM.Order
Dim cd As DAO.Database, rsc As Recordset
Dim cSQL As String

'refresh the list of active orders
Form_frmActiveOrders.UpdateStatus
'Set APIs
If (api Is Nothing) Then Set api = Glob.c
If (apiOrders Is Nothing) Then Set apiOrders = api.orders

'Stop 'Stops when "Suspend Trading" is checked on the Login window.
If Not apiOrders Is Nothing Then
For i = 0 To apiOrders.Get().Count - 1
Set Order = apiOrders.Get().GetAt(i)

If Order.Contract = aryCommodities(lPointer).Base_Contract Then
If Order.CurrentState = OrderState_Working _
Or Order.CurrentState = OrderState_Sent _
Or Order.CurrentState = OrderState_Held Then
'the Old API command that cancels an order,search for ActiveOrder
' Glob.c.CancelOrder Order
' or Glob.c.CancelOrder ActiveOrder

'Cancel all orders for the same Contract
cSQL = "Select clng([Order]) From tblActiveOrders_temp " _
& "Where Symbol='" & aryCommodities(lPointer).Base_Contract & "';"
Set cd = CurrentDb: Set rsc = cd.OpenRecordset(cSQL)
If rsc.EOF Then Exit Function
Do Until rsc.EOF
apiOrders.CancelOrder rsc(0), SubmissionType_Manual
Loop
End If 'Order state
End If 'Order contracts
Next
End If 'Order Api'


Exit_CancelWorkingOrders:
On Error Resume Next
Set rsc = Nothing: Set cd = Nothing
Set Order = Nothing: Set apiOrders = Nothing
Exit Function

Err_CancelWorkingOrders:
gParms = CStr(lPointer)
Call LogError(Err.Number, Err.Description, "NESClass", "CancelALLWorkingOrders()", gParms)
Resume Exit_CancelWorkingOrders
Resume Next

End Function
Anthony Sykes


API Support » Procedure written using OEC API Dec 15, 2020 @ 07:39 AM (Total replies: 1)

Trying to figure out how to write the following procedure using the GF API COM???

Public Sub CancelActiveOrder(ByVal lPointer As Long)

Dim ActiveOrder As GF_Api_COM.ordersApi

On Error GoTo Err_CancelActiveOrder

' Find the Order that is still Active, then Cancel It
Set ActiveOrder = Glob.c.orders.Item(aryCommodities(lPointer).Trade_ModifyId)
If Not ActiveOrder Is Nothing Then
If Form_Login.GetAccount().ID = ActiveOrder.Account.ID Then
Glob.c.CancelOrder ActiveOrder
End If
End If

Exit_CancelActiveOrder:
On Error Resume Next
Exit Sub

Err_CancelActiveOrder:
gParms = CStr(lPointer)
Call LogError(Err.Number, Err.Description, "NESClass", "CancelActiveOrder()", gParms)
Resume Exit_CancelActiveOrder
Anthony Sykes


API Support » Auto-cenceled on trade sent using "Sample COM Book.xls" Nov 20, 2020 @ 02:50 PM (Total replies: 1)

I'm testing the new GFAPI using the COM and Excel spreadsheet from Gain Futures...but when I send a "Marker if Touched" it is Auto-cancelled (All trade types are being Auto-canceled) . What are we doing wrong??

Completed Orders information:

Account,Order #,State,Avg.Price,Side,Qty,Filled Qty,Symbol,Price,Last.Cmd,Comments,Time,Post-Allocation,Fill Time,Completed Time
API010024,209453134,Cancelled,,Buy,1,0,GCLF21,MOC,Auto-cancelled,,13:41:47.889,,,13:41:50.036


Please advise

Anthony Sykes
User Name ASykes4318
Account API010024
Anthony Sykes


API Support » Trying to get contract Id Nov 05, 2020 @ 09:10 PM (Total replies: 1)

The following code is not returning Contract or Contract Id:


'---------------------------------------------------
'decleration
Private api As GF_Api_COM.IGFComClient

Dim Contract As GF_Api_COM.iContract
Dim myContract As Contract
Dim name As String
Dim ConID, requestID As Long

Dim builder As SymbolLookupRequestBuilder
Set builder = New SymbolLookupRequestBuilder

name = "GCLZ20"
Set myContract = api.Contracts.Get_2(name)

Debug.Print , ".builder.WithSymbol " & name & " My Contract ID:" & ConID
'builder.WithSymbol Name, TextSearchMode_StartsWith
If Not (myContract Is Nothing) Then
builder.WithSymbol name, TextSearchMode_Exact
ConID = Contract.ID
Set requestID = api.Contracts.lookup.BySymbol(name)

builder.WithResultCount 1
api.Contracts.lookup.ByCriteria builder.Build

End If

If Not (Contract Is Nothing) Then
'>>> Contract is nothing here !!!
'Stop
ConID = Contract.ID
End If
'---------------------------------------------------
Anthony Sykes


API Support » Error: -2146233079 Descr: Price server not connected Nov 02, 2020 @ 12:26 PM (Total replies: 3)

When using your example I'm not getting that error. Any thoughts as to why the remote host (GF server??) is forcibly closing??

Our application is saying that we are still connected
Anthony Sykes


API Support » Error: -2146233079 Descr: Price server not connected Nov 02, 2020 @ 09:21 AM (Total replies: 3)

We are connecting to the “Aggregate” server, however in the Public Sub SubscribeAll we are getting “Price server not connected” error.
What should we be doing different???

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("5549126e-9866-488f-b7c8-156683f8eacc") _
.WithHost(Server) _
.WithPort (9210)

connection.Connect builder.Build
Anthony Sykes


API Support » COM sample code not working GF API Oct 27, 2020 @ 04:55 AM (Total replies: 1)

The following is a sample code from the Excel COM spreadsheet provided by GF. The Set bc not working, what should be done differently??
bc.Symbol is showing a runtime error

Is there some updated sample code that works??


Private Sub LookupRequest(ByVal Name As String)
If Len(Name) > 0 Then
api.contracts.lookup.BySymbol Name

Dim builder As SymbolLookupRequestBuilder
Set builder = New SymbolLookupRequestBuilder

Dim bc As BaseContract
Set bc = api.contracts.Base.Get_3(Name)

If Not (bc Is Nothing) Then
builder.WithBaseSymbol bc.Symbol, TextSearchMode_StartsWith
Else
builder.WithSymbol Name, TextSearchMode_StartsWith
End If

builder.WithResultCount 1
api.contracts.lookup.ByCriteria builder.Build
End If
End Sub
Anthony Sykes


API Support » Contracts.Lookup.BySymbol() - We are having a problem Oct 26, 2020 @ 08:53 PM (Total replies: 1)

Our applicaton (developed in Microsoft Access), which connects to the API successfully, but we are having difficulties in setting the contract portion. Ou r main goal is to retrieve Contract details such as ContractSize, PriceFomat etc once we can connect.
?? We also have the Excel, that uses the same API and works successfully.
Our function initilized the GF_Api_COM.GFComClient , but following lines does not help to reacing the Contract
'WaitSeconds is a function that waits timer to loop x seconds.
'api = GF_Api_COM.GFComClient ' was already set

'(a)
Set Contract = api.Contracts.Get_2(Name)
WaitSeconds 5

'(b)'If fails, try by .Contracts.Base.Get_3
If Contract Is Nothing Then
Set Contract = api.Contracts.Base.Get_3(Name)
End If

'(c)'If fails: .Contracts.Lookup.BySymbol()
If Contract Is Nothing Then
If lookup Then
Set requestID = api.Contracts.lookup.BySymbol(Name)
' we have told to wait for system to return requestID, meaning contract is set
WaitSeconds 3
Set Contract = api.Contracts.Base.Get_3(Name)
End If
End If
'Contract is NOT set !!!

'Contract spossed to be set at this point, but it never works
If Not Contract Is Nothing Then
'Step (3) set the bc now
'GF_API_COM.GFComClient.Contracts.Base.Get_3()

'(3-a)
Set bc = api.Contracts.Base.Get_3(Name)
'(3-b)
If (bc Is Nothing) Then
Set bc = api.Contracts.Get_2(Name)
End If

If Not (bc Is Nothing) Then
'bc is set Subscribe now
Dim conID As String
conID = Contract.ID
'api.Subscribe Contract
'Set SubscribedContracts(i) = Contract
Dim subscription As PriceSubscription
end if
Anthony Sykes


API Support » = api.BaseContracts.FindBySymbol(Name) in OECAPICOM Sep 07, 2020 @ 05:31 AM (Total replies: 4)

I'm trying to find a way in GF API COM to find the base symbol when the contract name is provided???

Public Sub SubscribeAll(oecApi As OECAPICOM.IOECClient)
Dim Contract As OECAPICOM.iContract, bc As OECAPICOM.IBaseContract
Dim i As Integer, Name As String, t As Integer

On Error GoTo Err_SubscribeAll

Set api = oecApi
t = UBound(aryCommodities()) + 1
For i = 1 To t
With aryCommodities(i - 1)
Name = .Base_Contract
Set Contract = api.Contracts.Item(Name)
If Contract Is Nothing Then
'Set Contract = Glob.FindNearest(Name)
If Not (Contract Is Nothing) Then
ElseIf Len(Name) > 3 Then
Set bc = api.BaseContracts.FindBySymbol(Name)
If Not (bc Is Nothing) Then
.Base_ContractSize = bc.ContractSize
.Base_Margin = Round(bc.InitialMargin / 2, 2)
.Base_PriceFormat = bc.PriceFormat
.Base_PriceMultiplier = bc.PriceMultiplier
.Base_TickSize = bc.TickSize
api.RequestContracts bc
Set Contract = api.Contracts.Item(Name)
End If
End If
Else
Set bc = api.BaseContracts.FindBySymbol(Name)
If Not (bc Is Nothing) Then
.Base_ContractSize = bc.ContractSize
.Base_Margin = Round(bc.InitialMargin / 2, 2)
.Base_PriceFormat = bc.PriceFormat
.Base_PriceMultiplier = bc.PriceMultiplier
.Base_TickSize = bc.TickSize
End If
End If
End With

If Not (Contract Is Nothing) Then
api.Subscribe Contract
Set SubscribedContracts(i) = Contract
Else
Set SubscribedContracts(i) = Nothing
End If

Next i

Exit_SubscribeAll:
On Error Resume Next
Exit Sub

Err_SubscribeAll:
gParms = "OECAPICOM.IOECClient"
Call LogError(Err.Number, Err.Description, "Quotes", "SubscribeAll()", gParms)
Resume Exit_SubscribeAll
Resume Next

End Sub
Anthony Sykes


API Support » api.gainfutures.com Sep 19, 2019 @ 09:52 AM (Total replies: 4)

The issue was with our application...thanks for your response.
Anthony Sykes


API Support » api.gainfutures.com Sep 19, 2019 @ 08:37 AM (Total replies: 4)

Contract
GCLX9
Anthony Sykes


API Support » api.gainfutures.com Sep 19, 2019 @ 08:23 AM (Total replies: 4)

API appear to be not sending prices since yesterday. Is api.gainfutures.com offline as of 09-18-19??
Anthony Sykes


API Support » Excel DDE Add-in not found Aug 27, 2019 @ 03:27 PM (Total replies: 1)

When trying to run OEC Trader Developer Setup Wizard I'm getting the following error:
Cannot find the file Excel DDE Add-in.exe

under select components the Others - Excel DDE Add-in was selected.

What can I do different?
Anthony Sykes