Author Topic: VBA code to refresh markets  (Read 2137 times)

Tags:
  • All members
  • Posts: 4
VBA code to refresh markets
« on: 10 Mar 2010, 19:25 »
I have written some VBA code that reads/writes data from/to the workbook opened by MF, and calculates what bets to place and well. I am having a problem with timing between my program and the automatic market refresh in MF. Can anyone suggest a block of code that I could insert into my VBA program to refresh all MF markets when it is called?

  • Élite
  • Posts: 81
  • Gender: Male
*
Re: VBA code to refresh markets
« Reply #1 on: 11 Mar 2010, 12:38 »
I’ve only just started using VBA in my workbook so I’m sure you know more about this. But the problem I had was filtering and extracting the list of bets by the market id and selection id.

Anyway managed to get it working by having a cell return “now_time” updating at every refresh (2 secs) then when that cell changes do an advanced filter. This is what I’m using

Code: [Select]
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$AD$2" Then
    'Ensure target is a number
    If IsNumeric(Target) Then
    'Stop any possible runtime errors and halting code
    On Error Resume Next
    'Turn off ALL events so the Target does not _
    put the code into a loop.
    Application.EnableEvents = False
    'for team1
    Range("$A$5:$I$1000").AdvancedFilter Action:=xlFilterCopy, _
    CriteriaRange:=Range("AE1:AF2"), CopyToRange:=Sheet4.Range("A100:I100"), Unique:=False
    'for team2
    Range("$A$5:$I$1000").AdvancedFilter Action:=xlFilterCopy, _
    CriteriaRange:=Range("AQ1:AR2"), CopyToRange:=Sheet5.Range("A100:I100"), Unique:=False
    'for team3
    Range("$A$5:$I$1000").AdvancedFilter Action:=xlFilterCopy, _
    CriteriaRange:=Range("BC1:BD2"), CopyToRange:=Sheet6.Range("A100:I100"), Unique:=False
    'Turn events back on
    Application.EnableEvents = True
    'Allow run time errors again
    On Error GoTo 0
    End If
    End If
End Sub
Or more simply if cell AD2 changes then run the rest of the code.

This may not answer your question, but it worked for me. I wasn’t aware you could refresh the market yourself from excel (could be wrong, it’s happened before)

  • All members
  • Posts: 4
Re: VBA code to refresh markets
« Reply #2 on: 12 Mar 2010, 08:10 »
Thanks for the tip. I think that you can communicate directly with MF from excel because I found this bit of code on the MF website under "FAQ & Support" -> "Tips for programmers". It uses DDE commands to pass data to/from MF. I am not familiar with using DDE, so wondered if there are a library of commands similar to the "bet" command used below, but to perform other functions such as refresh markets or run triggers etc..?

Sub Back(marketID As Long, selectionID As Long, price As Double, amount As Double)

Dim feed As Integer

Dim data As String

feed = Application.DDEInitiate("FEEDER5", "betting")

If feed > 0 Then

  data = "back/" & marketID & "/" & selectionID & "/" & price & "/" & amount

  Range("AA1000") = data

  Application.DDEPoke feed, "bet", Range("AA1000")

End If

End Sub


 

Please note, BetFair is seems to be currently OFFLINE