Problem using COM server and Betfair API

Please post any questions regarding the program here.

Moderator: 2020vision

Problem using COM server and Betfair API

Postby Hovrin » Sat Apr 01, 2017 3:17 pm

Hi guys,

I'm wondering if anyone can help me with this please.
I have written many vba scripts to use with BA and Excel 2016 but this is my first time using the COM server.
The script below is designed to navigate through the BA market tree to find all the Over/Under 2.5 goal markets in various football leagues and it works well apart from one very weird (to me anyway) problem. It ALWAYS fails on the first run, at the point I have indicated, with an error which makes me suspect that the requested data has not been received. However, if I run the script again it works perfectly. It only fails when run for the first time after BA is started.
I have read and re read the BA help files and searched the forum but I can't find any info on this so can anyone help - please?

Thanks in advance

Hovrin


Code: Select all
Sub getmatches()

'Set variables
Dim TeamData As Worksheet, ResultsData As Worksheet, wb1 As Workbook
Set wb1 = ThisWorkbook
Set TeamData = wb1.Sheets("TeamData")
Set ResultsData = wb1.Sheets("ResultsData")

tdteamcol = 1
tdlosscol = 3
tdmatchnumcol = 4
matchfound = False
TeamData.Cells(2, 4) = ""

target = TeamData.Cells(1, 2)
stoploss = TeamData.Cells(2, 2)
lowodds = TeamData.Cells(3, 2)
highodds = TeamData.Cells(4, 2)
enablebets = TeamData.Cells(5, 2)
If enablebets = "Y" Then bettingenabled = True Else bettingenabled = False

Dim ba As BettingAssistantCom.ComClass
If ba Is Nothing Then
    Set ba = New BettingAssistantCom.ComClass
End If

countryarray = Array("English Soccer", "English Soccer", "Spanish Soccer", "German Soccer")
leaguearray = Array("English Premier League", "The Championship", "Primera Division", "Bundesliga 1")
tddatarowarray = Array(11, 33, 59, 81)

tdateday = "" & Day(Date)
If Len(tdateday) < 2 Then tdateday = "0" & tdateday
tdatemon = MonthName(Month(Date))
tdate = tdateday & " " & tdatemon

For j = 0 To 3
    ctrysoccer = countryarray(j)
    leaguename = leaguearray(j)

    'Work through markets tree to find the leagues and matches we want to bet on
    'Get all sports
    sports = ba.getSports()
    For Each sport In sports
        'Find Soccer
        If sport.sport = "Soccer" Then
            events = ba.getevents(sport.sportId)
            'Find the country
            For Each ctry In events
                If ctry.eventname = ctrysoccer Then
                    leagues = ba.getevents(ctry.eventid)
                    For Each league In leagues
                        'Find the league
                        If league.eventname = leaguename Then
                            fixtures = ba.getevents(league.eventid)
                            For Each fixture In fixtures
                                'Find the fixture date
                                If fixture.eventname = "Fixtures " & tdate Then
                                    matches = ba.getevents(fixture.eventid)
                                    'Work through the matches
                                    For Each mtch In matches
                                        'Check that it is a match
                                        If InStr(mtch.eventname, " v ") > 0 Then
                                            'Get the teams involved
                                            hometeam = Left(mtch.eventname, InStr(mtch.eventname, " v ") - 1)
                                            awayteam = Mid(mtch.eventname, InStr(mtch.eventname, " v ") + 3)
                                           
                                            'Start time is available if wanting to bet at ?sec to go
                                            overunders = ba.getevents(mtch.eventid)
                                            For Each overunder In overunders
                                               
                                                'Get the Over/Under 2.5 Goals market
                                                If overunder.eventname = "Over/Under 2.5 Goals" Then
                                                   
                                                    'Open market
                                                    mkt = ba.openMarket(overunder.eventid, 1)
                                                   
                                                    'Get odds
                                                    odds = ba.getPrices
                                                    For Each ods In odds
                                                        backodds = 0

                                                        'CODE ALWAYS FAILS AT THE NEXT LINE WITH THE ERROR
                                                        '   "Run-time error '424'  Object Required"

                                                        If ods.Selection = "Over 2.5 Goals" Then backodds = ods.backOdds1
                                                    Next ods


                                                    '}
                                                    '}
                                                    '}
                                                    '}
                                                    '}
                                                    '}
                                                    '}     Other code here to record odds, make bets, etc . .
                                                    '}
                                                    '}
                                                    '}
                                                    '}
                                                    '}

   
                                                End If
                                            Next overunder
                                        End If
                                    Next mtch
                                End If
                            Next fixture
                            Exit For
                        End If
                    Next league
                    Exit For
                End If
            Next ctry
            Exit For
        End If
    Next sport
   
Next j

End sub
Hovrin
 
Posts: 27
Joined: Sun Nov 11, 2007 5:48 pm

Return to Help

Who is online

Users browsing this forum: No registered users and 16 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.

cron