API Support Forum
OEC API > API Support > COM sample code not working GF API
Author Topic: COM sample code not working GF API
(2 messages, Page 1 of 1)
Moderators: VPfau
ASykes4318
Posts: 18
Joined:


Posted: Oct 27, 2020 @ 04:55 AM             Msg. 1 of 2
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
JSmith5611
Posts: 187
Joined:


Posted: Oct 28, 2020 @ 02:18 PM             Msg. 2 of 2
Most of that code is commented out in the excel example. probably was a leftover from coverting from old api to the new one.

Here's a version of that function that does work:

Private Sub LookupRequest(ByVal Name As String)
If Len(Name) > 0 Then

Dim builder As SymbolLookupRequestBuilder
Set builder = New SymbolLookupRequestBuilder

Dim bc As BaseContract
If (Len(Name) > 3) Then
bcName = Mid(Name, 1, Len(Name) - 3)
Set bc = api.contracts.Base.Get_3(bcName)
Else
Set bc = Nothing
End If

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


The Mid() call stripping the last 3 characters off is to get, for example, 'ES' from 'ESZ20', as that is the base contract name.
Jason Smith

Edited by JSmith5611 on Oct 28, 2020 02:19 PM