Traded Volume VBA code

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

Moderator: 2020vision

Traded Volume VBA code

Postby negapo » Tue Oct 20, 2009 8:20 pm

Hi all,
I'm trying to adapt a VBA code that uses the COM function getAllTradedVolume. I have use the above code in excel when i have a tab opened with one market and it works fine. I wanted to adapt it to a Coupon View Tab where there are lots of markets in the same spreadsheet. I can see that the code loops from Cell.(5,1) until it gets to a empty cell (Loop Until selecName = ""). I have tried to put something like: Loop Until selecName = "Stop" and put in Cell.(300,1) the word Stop so it stops there but i still just shows for the first market. Can some Guru help me out? My ultimate objective is just to have the weighted average odd next to every selection.

This is the code:

Code: Select all
If ba Is Nothing Then
            Set ba = New BettingAssistantCom.ComClass
        End If
        Dim tradedVol As Variant, tradedVols As Variant
        Dim totalTraded As Double, totalProfit As Double
        tradedVol = ba.getAllTradedVolume
        If Not IsEmpty(tradedVol) Then
            Dim i As Integer, r As Integer, selecName As String, j As Integer
            r = 5
            Do
                selecName = Cells(r, 1).Value
                If selecName <> "" Then
                    For i = 0 To UBound(tradedVol)
                        If tradedVol(i).Selection = selecName Then
                            Cells(r, 28).Value = tradedVol(i).actualBsp
                            Cells(r, 29).Value = tradedVol(i).totalBspBackMatchedAmount
                            Cells(r, 30).Value = tradedVol(i).totalBspLiabilityMatchedAmount
                            tradedVols = tradedVol(i).tradedVolumes
                            totalTraded = 0
                            totalProfit = 0
                            For j = 0 To UBound(tradedVols)
                                 If tradedVols(j).totalMatchedAmount <> 0 Then
                                    totalTraded = totalTraded + tradedVols(j).totalMatchedAmount
                                    totalProfit = totalProfit + (tradedVols(j).odds - 1) * tradedVols(j).totalMatchedAmount
                                 End If
                                 If tradedVols(j).odds = Cells(r, 15).Value Then
                                    Cells(r, 27).Value = tradedVols(j).totalMatchedAmount
                                 End If
                            Next
                            Cells(r, 31).Value = Round((totalProfit / totalTraded) + 1, 2)
                            Exit For
                        End If
                    Next
                End If
                r = r + 1
            Loop Until selecName = ""
        End If
       
Application.EnableEvents = True
negapo
 
Posts: 179
Joined: Thu Mar 19, 2009 1:17 pm
Location: Porto, Portugal

Postby osknows » Tue Oct 20, 2009 10:06 pm

I haven't used the COM functions and can't access them right now; so this is only me speculating...

Possibly the it could be the function ba.getAllTradedVolume is setting up the array 'tradedVol' for only the first market? (eg the first few rows in excel)

Once you move beyond this market in your worksheet you're not finding a match to the market in the array.
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby negapo » Tue Oct 20, 2009 11:48 pm

Thanks for the reply osknows.
I don't understand much of how the functions store the values but i think it might be that, that it only stores the values for the first market. Can someone else confirm this? Thanks in advanced
negapo
 
Posts: 179
Joined: Thu Mar 19, 2009 1:17 pm
Location: Porto, Portugal

Postby GaryRussell » Wed Oct 21, 2009 5:53 am

The COM calls only work with one market at a time currently so this cannot be done with the coupon view. I am working on adding multi market capability. Sorry if you wasted your time.
User avatar
GaryRussell
Site Admin
 
Posts: 9872
Joined: Fri Nov 18, 2005 8:09 pm
Location: Birmingham, UK

Postby negapo » Wed Oct 21, 2009 5:56 pm

Thanks for the reply Gary.
Not at all, i have the worksheet already done when the functions are available :D
negapo
 
Posts: 179
Joined: Thu Mar 19, 2009 1:17 pm
Location: Porto, Portugal

Postby negapo » Fri Oct 23, 2009 12:46 pm

In a related question, can anyone help me out with this code please:

Code: Select all
If ba Is Nothing Then
            Set ba = New BettingAssistantCom.ComClass
        End If
        Dim tradedVol As Variant, tradedVols As Variant
        Dim totalTraded As Double, totalProfit As Double
        tradedVol = ba.getAllTradedVolume
                If Not IsEmpty(tradedVol) Then
            Dim i As Integer, r As Integer, selecName As String, j As Integer
            r = 5
            Do
                selecName = Cells(r, 1).Value
                If selecName <> "" Then
                    For i = 0 To UBound(tradedVol)
                        If tradedVol(i).Selection = selecName Then
                            tradedVols = tradedVol(i).tradedVolumes
                            totalTraded = 0
                            totalProfit = 0
                            For j = 0 To UBound(tradedVols)
                                 If tradedVols(j).totalMatchedAmount <> 0 Then
                                    totalTraded = totalTraded + tradedVols(j).totalMatchedAmount
                                    totalProfit = totalProfit + (tradedVols(j).odds - 1) * tradedVols(j).totalMatchedAmount
                                 End If
                            Next
                            Cells(r, 27).Value = Round((totalProfit / totalTraded) + 1, 2)
                            Exit For
                        End If
                    Next
                End If
                r = r + 1
            Loop Until selecName = ""
        End If
End If


If the totalTraded for a selection is 0 it will divide by zero the totalProfit and will crash. I wanted to put a condition if totalTraded = 0 then nothing else run the code (the ideal was to ignore individual zero and have the calculations for the selections that have traded volume). I just don't know how to impose the condition because totalTraded is an array of values and I'm not used to work with arrays and don't know how.
Any help would be great. Thanks in advanced.
negapo
 
Posts: 179
Joined: Thu Mar 19, 2009 1:17 pm
Location: Porto, Portugal

Postby osknows » Fri Oct 23, 2009 1:12 pm

Try this
Code: Select all
If ba Is Nothing Then
            Set ba = New BettingAssistantCom.ComClass
        End If
        Dim tradedVol As Variant, tradedVols As Variant
        Dim totalTraded As Double, totalProfit As Double
        tradedVol = ba.getAllTradedVolume
                If Not IsEmpty(tradedVol) Then
            Dim i As Integer, r As Integer, selecName As String, j As Integer
            r = 5
            Do
                selecName = Cells(r, 1).Value
                If selecName <> "" Then
                    For i = 0 To UBound(tradedVol)
                        If tradedVol(i).Selection = selecName Then
                            tradedVols = tradedVol(i).tradedVolumes
                            totalTraded = 0
                            totalProfit = 0
                            traded_over_profit = 0
                            For j = 0 To UBound(tradedVols)
                                 If tradedVols(j).totalMatchedAmount <> 0 Then
                                    totalTraded = totalTraded + tradedVols(j).totalMatchedAmount
                                    totalProfit = totalProfit + (tradedVols(j).odds - 1) * tradedVols(j).totalMatchedAmount
                                    traded_over_profit = Round((totalProfit / totalTraded) + 1, 2)
                                 End If
                            Next
                         
                            Cells(r, 27).Value = traded_over_profit
                            Exit For
                        End If
                    Next
                End If
                r = r + 1
            Loop Until selecName = ""
        End If
End If


If that doesn't work this definitely will
Code: Select all
If ba Is Nothing Then
            Set ba = New BettingAssistantCom.ComClass
        End If
        Dim tradedVol As Variant, tradedVols As Variant
        Dim totalTraded As Double, totalProfit As Double
        tradedVol = ba.getAllTradedVolume
        If Not IsEmpty(tradedVol) Then
            Dim i As Integer, r As Integer, selecName As String, j As Integer
            r = 5
            Do
                selecName = Cells(r, 1).Value
                If selecName <> "" Then
                    For i = 0 To UBound(tradedVol)
                        If tradedVol(i).Selection = selecName Then
                            Cells(r, 28).Value = tradedVol(i).actualBsp
                            Cells(r, 29).Value = tradedVol(i).totalBspBackMatchedAmount
                            Cells(r, 30).Value = tradedVol(i).totalBspLiabilityMatchedAmount
                            tradedVols = tradedVol(i).tradedVolumes
                            totalTraded = 0
                            totalProfit = 0
                            For j = 0 To UBound(tradedVols)
                                 If tradedVols(j).totalMatchedAmount <> 0 Then
                                    totalTraded = totalTraded + tradedVols(j).totalMatchedAmount
                                    totalProfit = totalProfit + (tradedVols(j).odds - 1) * tradedVols(j).totalMatchedAmount
                                 End If
                                 If tradedVols(j).odds = Cells(r, 15).Value Then
                                    Cells(r, 27).Value = tradedVols(j).totalMatchedAmount
                                 End If
                            Next
                            If totalTraded <> 0 Then
                            Cells(r, 31).Value = Round((totalProfit / totalTraded) + 1, 2)
                            Else
                            Cells(r, 31).Value = 0
                            End If
                            Exit For
                        End If
                    Next
                End If
                r = r + 1
            Loop Until selecName = ""
        End If
       
Application.EnableEvents = True

User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby negapo » Fri Oct 23, 2009 1:48 pm

osknows

Thank you for your help.
It definitely worked the second one with the if totaltraded <> 0.
negapo
 
Posts: 179
Joined: Thu Mar 19, 2009 1:17 pm
Location: Porto, Portugal


Return to Discussion

Who is online

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