Getting the Betfair Ladder into Excel: question

Discuss anything related to using the program (eg. triggered betting tactics)

Moderator: 2020vision

Getting the Betfair Ladder into Excel: question

Postby grimesy » Wed Sep 14, 2011 3:59 pm

Folks,

I use the following Private Sub to transpose the BF ladder into Excel columns for each runner in a race.

Only one problem - every time BA refreshes, the macro will fire. This takes my CPU usage to colse to 100%; as a result, I cannot compile, or indeed activate, any other subs/functions in the Worksheet.

Here is my code:-

===========================================

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count = 16 Then
Application.EnableEvents = False
If ba Is Nothing Then
Set ba = New BettingAssistantCom.ComClass
End If
Dim tradedVol As Variant, tradedVols As Variant
tradedVol = ba.getAllTradedVolume
If Not IsEmpty(tradedVol) Then
Dim i As Integer, c As Integer, k As Integer, selecName As String, j As Integer
c = 28
Cells(3, c).Select
Do
If ActiveCell.Value <> "" Then
For i = 0 To UBound(tradedVol)
If tradedVol(i).Selection = ActiveCell.Value Then
tradedVols = tradedVol(i).tradedVolumes
j = UBound(tradedVols)
ActiveCell.Select
ActiveCell.Offset(2, 0).Select
For k = 0 To j
Range("counter") = k
ActiveCell.Value = tradedVols(k).Odds
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = tradedVols(k).totalMatchedAmount
ActiveCell.Offset(1, -1).Select
Next k
Exit For
End If
Next
End If
If ActiveCell.Value < 1.01 Then
Cells(3, c).Select
c = c + 6
Cells(3, c).Select
End If
Loop Until ActiveCell.Value = ""
End If
Application.EnableEvents = True
End If
Range("jolly_LPM").Select
End Sub

===========================================

What I need the coding to do instead, is to only update the data that has changed, rather than looping the whole way through each BF ladder for each runner.

For example, consider the following code; this event is fired on each refresh which is an ideal time to call getPrices.

===========================================

Sub ba_pricesUpdated()
prices = ba.getPrices
i = 4
For Each priceItem In prices
i = i + 1
Cells(i, 1).Value = priceItem.Selection
Cells(i, 2).Value = priceItem.backOdds1
Cells(i, 3).Value = priceItem.layOdds1
Cells(i, 4).Value = priceItem.lastMatched
Cells(i, 5).Value = priceItem.totalMatched
Next
End Sub

===========================================

Only priceItems that change are updated in the Excel sheet.

I want my coding for the BF ladder to so the same.

i.e. 95% of the records in each ladder do not change from one refresh to the next; there is no need to loop endlessly through each ladder.

Thoughts/comments/suggestions/ideas/help all greatly appreciated.

Grimesy
grimesy
 
Posts: 53
Joined: Tue Sep 30, 2008 3:58 pm

Postby dgs2001 » Sat Sep 17, 2011 11:13 am

I would suggest doing all your calculation within the vba code, as its much quicker than reading/writing to the sheet.

To do this you would need to read the prices from the sheet into an array, (1 single read operation) and then get the current prices into a second array.

then compare the arrays, before writing the result back to your sheet in 1 single write operation.

There is some good info and code snippets about arrays here including code to compare two arrays :-
http://www.cpearson.com/Excel/VBAArrays.htm

Duncan
User avatar
dgs2001
 
Posts: 334
Joined: Thu Apr 05, 2007 4:53 pm
Location: The Home Of National Hunt


Return to Discussion

Who is online

Users browsing this forum: No registered users and 54 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.