VBA - regulate the UPDATE trigger to once every 30 seconds

Please post any questions regarding the program here.

Moderator: 2020vision

VBA - regulate the UPDATE trigger to once every 30 seconds

Postby technician » Sat Aug 15, 2020 9:22 am

Hello all

When there's a lot of meetings with large runner fields, I'm getting very close to exceeding the Transactions per Hour limit that Betfair impose. It's only a matter of time before I start incurring charges. I don't need my lay bets to update with every refresh, once every 30 seconds or so will do, which will reduce my transactions significantly and bring me way below the limit, but once again I'm struggling to implement this in VBA.

Here's a sample of my code, the lay bet is still updating with every refresh instead of once every 30 seconds. Please can someone show me the way?

Cheers

Code: Select all
Dim startTime As Single
Dim endTime As Single
Dim elapsedTime As Single
Dim currentMarket As String
Dim i As Integer

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Columns.Count = 16 Then
        'Upon new market, clear the trigger column, place new bets
        If [A1] <> currentMarket Then
            currentMarket = [A1]
            For i = 5 To 55
                Cells(i, 17).Value = ""
            Next i
            Application.EnableEvents = False
                    Cells(5, 17).Value = "LAY"
            Application.EnableEvents = True
        End If
       
        'Update lay bets after 30 second pause
        If stopWatch = False Then
            startTime = Timer()
            stopWatch = True
        End If

        If stopWatch = True Then
            endTime = Timer()
            elapsedTime = endTime - startTime
            If elapsedTime >= 30 Then
                stopWatch = False
                elapsedTime = 0
                endTime = 0
                startTime = 0
               
                ' Update bet
                Application.EnableEvents = False
                    Cells(5, 17).Value = "UPDATE"
                Application.EnableEvents = True
               
            End If
        Else
        Cells(5, 17).Value = "counting"
 
        End If
    End If
End Sub
technician
 
Posts: 5
Joined: Sun Aug 02, 2020 4:33 pm

Re: VBA - regulate the UPDATE trigger to once every 30 secon

Postby Captain Sensible » Sat Aug 15, 2020 3:27 pm

Depending on how much commission you earn for betfair in a day you may not even pay Transaction charges as they do get offset against comms.

But for your code you need to be declaring your variables as Public/Static variables otherwise they reset their value each time the code runs.
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Re: VBA - regulate the UPDATE trigger to once every 30 secon

Postby technician » Sat Aug 15, 2020 9:39 pm

I wasn't aware Transaction charges were offset against commission. Is this a new thing?

I'm still struggling to understand where and how I should declare my variables.

Like so?
Option Explicit

Public stopWatch As Boolean
Public startTime As Single
Public endTime As Single
Public elapsedTime As Single

And where does it go? I have everything on Sheet1 and those variables are on the General (Declarations) section and it still doesn't work for me..
technician
 
Posts: 5
Joined: Sun Aug 02, 2020 4:33 pm

Re: VBA - regulate the UPDATE trigger to once every 30 secon

Postby Captain Sensible » Sat Aug 15, 2020 11:27 pm

technician wrote:I wasn't aware Transaction charges were offset against commission. Is this a new thing?

I'm still struggling to understand where and how I should declare my variables.


It's been like that forever and in the betfair's t&c's

https://www.betfair.com/aboutUs/Betfair.Charges/#
Any remaining amount will be charged to your account on a daily basis. Should your (commission + implied commission) ÷ 2 exceed this amount, you will not be charged a transaction fee. Accounts that relate to one person, entity, API subscription or a Master account (Trading version only) with related Sub accounts are treated as one customer for the purposes of transaction charging. Note that no Betfair points will accrue for transaction fees.



I'm guessing you have other code running to clear the update etc but here's a quick edit of your code. You just need to wrap the code within the Application.EnableEvents as there's no point duplicating it. Also if you open an intermediate window in the VBA editor you can see the status of your variables with Debug.Print which is good for debugging when setting up code, obviously uncomment or delete them when things are fine thats the line Debug.Print "Start time " & startTime & " end time " & endTime & " elasped time " & elapsedTime

Code: Select all
Option Explicit

Public startTime As Single
Public endTime As Single
Public elapsedTime As Single
Public currentMarket As String
Public stopWatch As Boolean


Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim i As Integer
    If Target.Columns.Count = 16 Then
        'Upon new market, clear the trigger column, place new bets
        If [A1] <> currentMarket Then
            currentMarket = [A1]
            For i = 5 To 55
                Cells(i, 17).Value = ""
            Next i
           
                    Cells(5, 17).Value = "LAY"
           
        End If
       
        'Update lay bets after 30 second pause
        If stopWatch = False Then
            startTime = Timer()
            stopWatch = True
        End If

        If stopWatch = True Then
            endTime = Timer()
            elapsedTime = endTime - startTime
            If elapsedTime >= 30 Then
                stopWatch = False
                elapsedTime = 0
                endTime = 0
                startTime = 0
               
                ' Update bet
             
                    Cells(5, 17).Value = "UPDATE"
           
               
            End If
        Else
        Cells(5, 17).Value = "counting"
 
        End If
    End If
''''''''''''debugging
Debug.Print "Start time " & startTime & " end time " & endTime & " elasped time " & elapsedTime
''''''''''debugging

    Application.EnableEvents = True
End Sub
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Re: VBA - regulate the UPDATE trigger to once every 30 secon

Postby tradeaj71 » Mon Aug 17, 2020 9:57 am

Not sure of you are aware but the maximum transactions allowable in an hour will increase from 1000 to 5000 from Septermber 1st.
There are some small changes to what is considered a transaction but won't be a problem unless you are generating lots of error codes.

Your 'stopwatch' solution is likely to make your sheets quite 'clunky', have you considered just having increasing the refresh rate?
Just plugging away!
tradeaj71
 
Posts: 26
Joined: Tue Nov 12, 2013 6:16 pm
Location: United Kingdom

Re: VBA - regulate the UPDATE trigger to once every 30 secon

Postby technician » Sat Aug 22, 2020 11:56 am

Thank you for all the replies. I haven't had a chance to try these suggestions yet as my day job suddenly gone mental and kept me really busy, which is a good thing I suppose as I work in the Advertising industry so the fact that the big brands are spending millions again with the company I work for is a good sign that the economy is starting to recover.

The debug print feature is a very handy tip so thank you for pointing that out to me.

I was unaware that the maximum transactions allowable was going to increase 5 fold so that is probably the solution for me, to leave things as they are

In any event thank you for all the assistance, it's very much appreciated
technician
 
Posts: 5
Joined: Sun Aug 02, 2020 4:33 pm


Return to Help

Who is online

Users browsing this forum: Google [Bot] and 26 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.