Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JayBee
    Junior Member
    • Oct 2010
    • 114

    #481
    Viewing horse races the night before...

    Mumbles0,

    On the Betfair website you can view tomorrow's races and any early betting.

    I would like to do this with the application you have been building in this thread.

    Currently, the night before, if I click the markets button then nothing is returned.

    How do I get a list of tomorrow's races in my Tree View?

    Thank you.

    Comment

    • Mumbles0
      Junior Member
      • Jan 2009
      • 240

      #482
      Tomorrow‘s markets

      JayBee,

      The TreeView example of Step 15 uses data obtained from the getAllMarkets call made in Step 5. Here the properties .fromDate and .toDate define the time window for the returned markets. In other words, getAllMarkets only returns markets whose start times lie between these limits.

      So to get tomorrow’s UK racing markets try this:

      Code:
      [COLOR="Gray"]  Dim oMarketsReq As New BFUK.GetAllMarketsReq
        Dim oMarketsResp As BFUK.GetAllMarketsResp
        With oMarketsReq
          .header = oHeaderUK()
          ReDim .eventTypeIds(0) : .eventTypeIds(0) = 7
          ReDim .countries(0) : .countries(0) = "GBR"
      [COLOR="Black"]    .fromDate = Today.AddDays(1)    'Midnight tonight
          .toDate = Today.AddDays(2)      'Midnight tomorrow night[/COLOR]
        End With
        oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)
        .........[/COLOR]
      Note that the Today method returns your local time.

      Comment

      • JayBee
        Junior Member
        • Oct 2010
        • 114

        #483
        Thank you Mumbles0, works perfectly.

        Originally posted by Mumbles0 View Post
        JayBee,

        The TreeView example of Step 15 uses data obtained from the getAllMarkets call made in Step 5. Here the properties .fromDate and .toDate define the time window for the returned markets. In other words, getAllMarkets only returns markets whose start times lie between these limits.

        So to get tomorrow’s UK racing markets try this...

        Comment

        • Tachikoma
          Junior Member
          • Nov 2010
          • 1

          #484
          cant find Async version of getM

          Hi Mumbles0, thanks for your great work.

          Referring to your Step 9. Making Async API Calls.

          BetFairUK.getMarketPricesAsync(MpricesReq)

          Why I can't find the Async version of getMarketPrices method?

          Comment

          • JayBee
            Junior Member
            • Oct 2010
            • 114

            #485
            Colouring cells dependent on value...

            Having started programming in 1981 on a Tandy TRS-80, I have yet to evolve the ability to perform object-oriented programming.

            I have a working program now and am certain it would give a younger programmer a heart attack.

            What I would like to do now is use the existing code in this excellent thread but colour code individual cells dependent on value range.

            Any ideas?

            I would prefer not to do a complete rewrite of all the excellent work already done in this thread.

            Thanks.

            Comment

            • JayBee
              Junior Member
              • Oct 2010
              • 114

              #486
              Found a solution after a day of hair pulling...

              Using the existing variable ref for currently selected grid...

              Public WithEvents SelectedGrid As RunnerGrid 'A variable to hold a reference to the currently-selected grid

              I added this event handler...

              Private Sub dataGridView1_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles SelectedGrid.CellFormatting
              If Me.SelectedGrid.Columns(e.ColumnIndex).Name = "F-B" ThenIf e.Value > 0 Then
              e.CellStyle.BackColor = Color.LightGreenEnd If
              End If

              End Sub


              Originally posted by JayBee View Post
              Having started programming in 1981 on a Tandy TRS-80, I have yet to evolve the ability to perform object-oriented programming.

              I have a working program now and am certain it would give a younger programmer a heart attack.

              What I would like to do now is use the existing code in this excellent thread but colour code individual cells dependent on value range.

              Any ideas?

              I would prefer not to do a complete rewrite of all the excellent work already done in this thread.

              Thanks.

              Comment

              • JayBee
                Junior Member
                • Oct 2010
                • 114

                #487
                New Problem...

                I want to add a new row to the bottom of my table, into which I can place totals.

                Any ideas?

                I've tried row.add() but it adds the row above the last runner.

                I have no idea why it does this.

                Comment

                • Mumbles0
                  Junior Member
                  • Jan 2009
                  • 240

                  #488
                  Reply to Tachikoma

                  Hi Mumbles0, thanks for your great work.
                  Referring to your Step 9. Making Async API Calls.
                  BetFairUK.getMarketPricesAsync(MpricesReq)
                  Why I can't find the Async version of getMarketPrices method?
                  It’s there.

                  If you have declared the service object BetFairUK as:

                  Private WithEvents BetFairUK As New BFUK.BFExchangeService 'The UK ExchangeService object
                  then when you type:

                  BetFairUK.
                  the getMarketPricesAsync method should appear on the Intellisense list.

                  Comment

                  • Mumbles0
                    Junior Member
                    • Jan 2009
                    • 240

                    #489
                    Reply to JayBee (using DataGridView)

                    Cell colouring

                    That’s the way to go. The CellFormating event fires whenever a cell’s value changes, allowing you to change the cell’s colour depending on its new value (as you’ve done).

                    Extra grid row

                    Try setting the RowCount property to one more than the number of runners.
                    Change these two lines in the RunnerGrid class:

                    Code:
                    [COLOR="Gray"][COLOR="Black"]  RowCount = Runners.Length + 1  'A row for each runner (plus extra row)
                      For i = 0 To Runners.Length - 1[/COLOR]
                        With Runners(i)
                          Item(colRunner, i).Value = .name  'Add the runner name
                          Item(colSelId, i).Value = .selectionId  'Add the selectionId
                        End With
                      Next[/COLOR]
                    (I don't know why the Rows.Add method inserts a new row before the last row)

                    Comment

                    • JayBee
                      Junior Member
                      • Oct 2010
                      • 114

                      #490
                      I used that method of adding a row and got the same problem as yourself, namely the row is in the wrong place.

                      That's not very helpful when it comes to totalling things up.

                      At the moment I am putting my totals into labels, elsewhere on the form.

                      Other ideas I have is to have label objects inside the tab or to declare a second grid view without headers and to pass data between the two or to sort the grid or to add a dummy runner.

                      Originally posted by Mumbles0 View Post

                      Extra grid row

                      Try setting the RowCount property to one more than the number of runners.
                      Change these two lines in the RunnerGrid class:

                      Code:
                      [COLOR="Gray"][COLOR="Black"]  RowCount = Runners.Length + 1  'A row for each runner (plus extra row)
                        For i = 0 To Runners.Length - 1[/COLOR]
                          With Runners(i)
                            Item(colRunner, i).Value = .name  'Add the runner name
                            Item(colSelId, i).Value = .selectionId  'Add the selectionId
                          End With
                        Next[/COLOR]
                      (I don't know why the Rows.Add method inserts a new row before the last row)

                      Comment

                      • Mumbles0
                        Junior Member
                        • Jan 2009
                        • 240

                        #491
                        JayBee,

                        There is no problem !!!

                        If you increase the RowCount property by one you get an extra row at the bottom of the grid. Isn't this what you want?

                        Comment

                        • JayBee
                          Junior Member
                          • Oct 2010
                          • 114

                          #492
                          Sorry, I hadn't noticed that you changed the For statement from

                          For i = 0 To RowCount

                          For i = 0 To Runners.Length - 1

                          Thanks for your help. I have no idea how it works but as I learned in functional maths in my comp. sci. degree, "Don't ask why, it just is."

                          PS... My first live run, today, made two trades on a race and the field was completely green. Thanks again!


                          Originally posted by Mumbles0 View Post
                          JayBee,

                          There is no problem !!!

                          If you increase the RowCount property by one you get an extra row at the bottom of the grid. Isn't this what you want?

                          Comment

                          • gunhero
                            Junior Member
                            • Aug 2010
                            • 6

                            #493
                            error: BET_IN_PROGRESS

                            Hi Mumbles0 and others,
                            I have some problem with an errorcode after the placeBetsReqest.
                            The errorcode is "BET_IN_PROGRESS". At betfair I read, that this means, that it's possible or not that the bet is placed. It's a very silly statement.

                            I will show you my Request:

                            Code:
                            'TestValues
                            handicap = 1
                            marketId = 101970857
                            selectionId = 285469
                            tempQuote = 5
                            tempStake = 100
                            betType = "B"
                            
                            Dim oPlaceBetResp As New BFUK.PlaceBetsResp
                            Dim oBets(0 To 0) As BFUK.PlaceBets
                            
                            oBets(0) = New BFUK.PlaceBets
                                    With oBets(0)
                                        .asianLineId = handicap
                                        .betCategoryType = BFUK.BetCategoryTypeEnum.E
                                        .betPersistenceType = BFUK.BetPersistenceTypeEnum.NONE
                                        If betType = "B" Then
                                            .betType = BFUK.BetTypeEnum.B
                                        ElseIf betType = "L" Then
                                            .betType = BFUK.BetTypeEnum.L
                                        End If
                            
                                        .bspLiability = 0
                                        .marketId = marketId
                                        .selectionId = selectionId
                                        .price = tempQuote
                                        .size = tempStake
                            
                                    End With
                            
                                    With oPlaceBetReq
                                        .header = oHeaderUK()
                                        .bets = oBets
                                    End With
                            
                            oPlaceBetResp = BetfairUK.placeBets(oPlaceBetReq)
                            
                            If oPlaceBetResp.errorCode = BFUK.PlaceBetsErrorEnum.OK Then
                            ' xxx
                            else
                            Print("Error: " & oPlaceBetResp.errorCode.ToString)
                            end if
                            I want to place a bet in the Total Goals market (Game: Aston Villa v Arsenal) at Back "1 goal or more".
                            I think the error is couse of the asian line ID. Can someone explain me the sense of this part? The error by handicap = -1 is "INCORRECT ASIAN_LINE_ID", by handicap = 1 is "BET_IN_PROGRESS".

                            How I have to change the code to place also bets at "Total Goals"?

                            Thanks for your help

                            gunhero

                            Comment

                            • gunhero
                              Junior Member
                              • Aug 2010
                              • 6

                              #494
                              The mistake was quiet simple
                              The Asian Line Id was wrong.

                              Greetings gunhero

                              Comment

                              • Mumbles0
                                Junior Member
                                • Jan 2009
                                • 240

                                #495
                                Gunhero,

                                The Total Goals market is treated as an Asian handcap, so the .asianLineId parameter in the placeBets request should be set to the corresponding value given in the .runners array returned by getMarket.

                                Comment

                                Working...
                                X