Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NFLMAN
    Junior Member
    • Jun 2010
    • 17

    #676
    Just wanted to ask the best way to track multiple bot actions:

    For example, I have 2 bots running on seperate timers placing bets at various time intervals on different markets and betting criteria.

    Bot 1 places async bets and writes the bet details to a log file. I then use this log file later to provide statistics. This works well as I know all the bets in this log file belong to bot1.

    When I start using bot 2, I want it to write to the same log file but I want to be able to distinguish which bot placed which bet.

    I'm thinking along the lines of passing a parameter containing a botID reference (generated by the timer tick event) through to the PlaceBet sub. I can then link the botID ref to the PlaceBet response's BetID and send this data to the log file.

    Am I going about this in the right manner or is there a smarter way to acheive what I need?

    Comment

    • BigSprout
      Junior Member
      • Feb 2011
      • 60

      #677
      Hi NFLMan,

      I had a similar problem and this is how I solved it:

      MyBotId represents the Bot number (Bot1, Bot2,...etc)

      Code:
      Public Sub PlaceMyBets(ByVal MyBotId As Integer)
      
      
      	' the code
      
      	StateCount += 1
      	BetfairExch.placeBetsAsync(oPlaceBetsReq, StateCount + (MyBotId * 10000))
      
      	'if MyBotId = 1 then the number sent is 10,000 + StateCount
      	'if MyBotId = 2 then the number sent is 20,000 + StateCount
      
      end sub
      
      
      
      Private Sub BetFairExCh_PlaceBetsCompleted(ByVal sender As Object, ByVal e As BFExService.placeBetsCompletedEventArgs) Handles BetfairExch.placeBetsCompleted
      
      	Dim MyBotId as Integer= e.UserState \ 10000
      
      	'MyBotId = 1 or 2, dependent on which Bot sent the bet
      	'this can then be used to differentiate between bots
      
      end sub
      I then added this line to "MyTimer", so that StateCount didn't exceed 10,000:

      If StateCount > 9950 then StateCount = 0

      hope this helps

      Comment

      • NFLMAN
        Junior Member
        • Jun 2010
        • 17

        #678
        Thanks BigSprout - that method worked and saved me a lot of extra coding :-)

        Comment

        • Geierkind
          Junior Member
          • May 2011
          • 10

          #679
          Changing format of Prices

          Hi,

          I need some help.

          You remember the Prices-Sub:

          Code:
          Sub ShowMprices(ByVal MpriceResp As BFUK.GetMarketPricesResp)
                  Dim Lay, Back As String
          
                  With MpriceResp
                      CheckHeader(.header)
                      Print("ErrorCode = " & .errorCode.ToString)
                      If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then
                          With .marketPrices
                              Print("MarketID = " & .marketId)
                              For i = 0 To .runnerPrices.Length - 1
                                  With .runnerPrices(i)
                                      Print("Runner " & i + 1 & "  LPM = " & .lastPriceMatched)
                                      Back = ""
                                      For j = 0 To .bestPricesToBack.Length - 1
                                          With .bestPricesToBack(j)
                                              Back = Back & "  " & .price & "/" & Int(.amountAvailable)
                                          End With
                                      Next
                                      Lay = ""
                                      For j = 0 To .bestPricesToLay.Length - 1
                                          With .bestPricesToLay(j)
                                              Lay = Lay & "  " & .price & "/" & Int(.amountAvailable)
                                          End With
                                      Next
                                      Print("Back = " & Back & "   Lay = " & Lay)
                                  End With
                              Next
                          End With
                      End If
                  End With
              End Sub
          This code gives Prices like this:

          MarketId = 4324232
          Runner 1 LPM=
          Back = Lay=
          Runner 2 LPM=
          Back = Lay=

          But I would like to see Prices in the following format:

          MarketID Runner 1 Runner 2 Runner 3 Runner 4 Runner 5
          4324232 [Backodds] [Backodds] [Backodds] [Backodds]

          All those loops are kind of too complicated for me, so I would like to hear some advice how to get this format of Data

          Thanks,

          Timo

          Comment

          • Camper
            Junior Member
            • Jul 2011
            • 30

            #680
            Hi everyone, first I have to say thanks for this thread, very helpful indeed!i

            I'm new to VB but I successfully completed all the steps in this tutorial and now I'm trying to make some changes. I would love to have a form to Login and after that a "main" form with the rest of the bot but for now I'm trying to add a textbox to input the password because i dont feel safe having a program with my password on it, the username i don't really care.

            I failed at doing this, does anyone have an idea to me?

            PS: Sorry for my english.
            Last edited by Camper; 28-07-2011, 07:09 PM.

            Comment

            • Camper
              Junior Member
              • Jul 2011
              • 30

              #681
              Hi again, another problem.

              I was able to open a new form and close the login form by adding this at the end of "Private Sub bLogin_Click":

              Code:
              With oLoginResp
                          CheckHeader(.header)
                          Print("ErrorCode = " & .errorCode.ToString)
                          If .errorCode.ToString = "OK" Then
                              Main.Show()
                              Me.Hide()
                          End If
                      End With
              The new form appears but when i click to see the events on the textbox i get this error:

              *** Events ***
              HeaderCode = NO_SESSION
              ErrorCode = API_ERROR
              I don't know what I did wrong here.

              Comment

              • Camper
                Junior Member
                • Jul 2011
                • 30

                #682
                I've already solved my problems. If anyone has the same problems feel free to ask.

                Comment

                • Geierkind
                  Junior Member
                  • May 2011
                  • 10

                  #683
                  Originally posted by Geierkind View Post
                  Hi,

                  This code gives Prices like this:

                  MarketId = 4324232
                  Runner 1 LPM=
                  Back = Lay=
                  Runner 2 LPM=
                  Back = Lay=

                  But I would like to see Prices in the following format:

                  MarketID Runner 1 Runner 2 Runner 3 Runner 4 Runner 5
                  4324232 [Backodds] [Backodds] [Backodds] [Backodds]

                  All those loops are kind of too complicated for me, so I would like to hear some advice how to get this format of Data

                  Thanks,

                  Timo
                  Originally posted by Geierkind View Post

                  First Question: How do I modify the code further, so that the Prices function "calls itself" until all Prices are read?

                  Second Question: How do I export that big array of all those Prices to Excel the most convenient way?

                  I have those problems solved If anyone needs assistance in doing the same thing, just write a PM.

                  What about starting another thread, referring to this one where we can publish our solutions for our little problems so if any other guy has the same problem later he doesn't have to scan through all the pages of this thread.

                  Regards,

                  Timo

                  Comment

                  • Camper
                    Junior Member
                    • Jul 2011
                    • 30

                    #684
                    Hi, i will only use my bot on tennis markets. I was able to do a treeview with only tennis markets and now I'm trying to put it like this:

                    Tournament
                    • Hour: Player 1 - Player 2: Match Odds


                    I read here in this topic about filtering the information but i was unable to do it

                    Any idea?

                    Comment

                    • NFLMAN
                      Junior Member
                      • Jun 2010
                      • 17

                      #685
                      Hi Camper,

                      I don't use a treeview but you can filter for specific market types like filtering for "match odds" like this:

                      Code:
                      Dim AllMarkets As New UnpackAllMarkets(oMarketsResp.marketData)
                            With AllMarkets
                                  For i = 0 To .marketData.Length - 1
                                       With .marketData(i)
                                             If .marketName = "Match Odds" Then
                                                    Code for Get Market Prices and placing bet etc.....
                                             End if
                                       End With
                                  Next i
                            End With
                      This will select all singles match odds markets and also any doubles match odds markets. You can filter out the doubles matches too with a bit more code but there are relatively few of these so I don't bother.

                      Comment

                      • Camper
                        Junior Member
                        • Jul 2011
                        • 30

                        #686
                        Hi, thanks for the help it worked just fine. I was able to Print only the match odds markets on a texbox by doing this like you said:
                        Code:
                        With AllMarkets
                                            For i = 0 To .marketData.Length - 1
                                                With .marketData(i)
                                                    If .marketName = "Match Odds" Then
                                                        Print(.marketId & " " & .marketStatus & "  " & .marketName & "  " & .menuPath)
                                                        PopulateTreeView(AllMarkets, tvMarkets)
                                                    End If
                                                End With
                                            Next
                                        End With
                        I want to do another thing, i want to Print only this information, for example:
                        I'm getting this:
                        103361258 ACTIVE Match Odds \Tennis\Group A\Mercury Insurance Open 2011\First Round Matches\Vesnina v Erakovic
                        And i want this:
                        103361258 ACTIVE Match Odds \Tennis\Mercury Insurance Open 2011\Vesnina v Erakovic

                        Is that possible? By doing this i will get to the match odds far more faster on the treeview, too many clicks the way i have it now.

                        Thanks for the help NFLMAN, I'm getting close to what i want
                        Last edited by Camper; 02-08-2011, 01:03 AM.

                        Comment

                        • Camper
                          Junior Member
                          • Jul 2011
                          • 30

                          #687
                          Suddently my code stoped to work.

                          Code:
                           Private Sub bMarkets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bMarkets.Click
                                  Print("*** Markets ***")
                                  Dim oMarketsReq As New BFUK.GetAllMarketsReq
                                  Dim oMarketsResp As BFUK.GetAllMarketsResp
                                  With oMarketsReq
                                      .header = oHeaderUK()
                                      ReDim .eventTypeIds(0) : .eventTypeIds(0) = 2 'For Tennis Matches
                                      .fromDate = Today
                                      .toDate = Today.AddDays(1)
                                  End With
                                  oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)
                                  With oMarketsResp
                                      CheckHeader(.header)
                                      Print("ErrorCode = " & .errorCode.ToString)
                                      If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
                                          Dim AllMarkets As New UnpackAllMarkets(.marketData)   
                                          PopulateTreeView(AllMarkets, tvMarkets)
                                          With AllMarkets
                                              For i = 0 To .marketData.Length - 1
                                                  With .marketData(i)
                                                      If .marketName = "match odds" Then
                                                          Print(.marketId & " " & .marketStatus & "  " & .marketName & "  " & .menuPath)
                                                      End If
                                                  End With
                                              Next
                                          End With
                                      End If
                                  End With
                              End Sub
                          I get this on the tLog:
                          *** Markets ***
                          HeaderCode = OK
                          ErrorCode = OK
                          It doesn't print .marketid, .marketStatus, .marketName or .menuPath
                          I dont recall doing anychange related to this

                          Comment

                          • Camper
                            Junior Member
                            • Jul 2011
                            • 30

                            #688
                            Solved, I feel idiot now, I logged in at betfair website and change the language to other than English so if .marketname = "Match Odds" couldnt work

                            Comment

                            • Camper
                              Junior Member
                              • Jul 2011
                              • 30

                              #689
                              I spoted a strange situation today. I have the best price to back and lay to both players displayed on textboxes.

                              The first player has the right values on both Back and Lay but I founded a mistake on the second. The Back and lay prices are not the best ones, they show the second best price i don't know why. The same for the avalable amount.

                              The code I use is this one:

                              Code:
                                  Sub ShowMprices(ByVal MpriceResp As BFUK.GetMarketPricesResp)
                                      With MpriceResp
                                          CheckHeader(.header)
                                          Print("ErrorCode = " & .errorCode.ToString)
                                          If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then
                                              With .marketPrices
                                                  bMstatus.Text = .marketStatus
                                                  bMarkid.Text = .marketId
                                                  With .runnerPrices(0)
                                                      bSelecid.Text = .selectionId
                                                      With .bestPricesToBack(0)
                                                          aBodd1.Text = .price
                                                          Dim y As Integer
                                                          Dim x As Double = .amountAvailable
                                                          y = Convert.ToInt32(x)
                                                          bBacka1.Text = y
                                                      End With
                                                      With .bestPricesToLay(0)
                                                          bLay1.Text = .price
                                                          Dim y As Integer
                                                          Dim x As Double = .amountAvailable
                                                          y = Convert.ToInt32(x)
                                                          bLaya1.Text = y
                                                      End With
                                                  End With
                                                  With .runnerPrices(1)
                                                      bSelectid1.Text = .selectionId
                                                      With .bestPricesToBack(1)
                                                          TextBox5.Text = .price
                                                          Dim y As Integer
                                                          Dim x As Double = .amountAvailable
                                                          y = Convert.ToInt32(x)
                                                          TextBox3.Text = y
                                                      End With
                                                      With .bestPricesToLay(1)
                                                          TextBox2.Text = .price
                                                          Dim y As Integer
                                                          Dim x As Double = .amountAvailable
                                                          y = Convert.ToInt32(x)
                                                          TextBox1.Text = y
                                                      End With
                                                  End With
                                              End With
                                          Else
                                              Print("ShowMprices Error")
                                          End If
                                      End With
                                  End Sub
                              I cant spot any error here

                              Comment

                              • BigSprout
                                Junior Member
                                • Feb 2011
                                • 60

                                #690
                                Camper,
                                I think the reason why you are getting 2nd best prices is because that is what you are asking for, try changing:

                                .bestPricesToBack(1) to .bestPricesToBack(0)
                                bestPricesToLay(1) to bestPricesToLay(0)

                                Code:
                                                    With .runnerPrices(1)
                                                        bSelectid1.Text = .selectionId
                                                        [B][COLOR="Red"]With .bestPricesToBack(0)[/COLOR][/B]
                                                            TextBox5.Text = .price
                                                            Dim y As Integer
                                                            Dim x As Double = .amountAvailable
                                                            y = Convert.ToInt32(x)
                                                            TextBox3.Text = y
                                                        End With
                                                        [COLOR="Red"][B]With .bestPricesToLay(0)[/B][/COLOR]
                                                            TextBox2.Text = .price
                                                            Dim y As Integer
                                                            Dim x As Double = .amountAvailable
                                                            y = Convert.ToInt32(x)
                                                            TextBox1.Text = y
                                                        End With
                                                    End With
                                                End With

                                Comment

                                Working...
                                X