Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mumbles0
    Junior Member
    • Jan 2009
    • 240

    #436
    Peter,

    I’m surprised you haven’t got DataGridView. It’s been included as a replacement for DataGrid since VB2005. Try this:

    Right-click on the Toolbox and select "Choose Items..." to show the "Choose Toolbox Items" form. You should find DataGridView on the list (on the ".NET Framework Components" tab) Ensure this is checked this and click OK. The DataGridView control should now appear in the Toolbox.

    Comment

    • Peter Simple
      Junior Member
      • Aug 2009
      • 32

      #437
      I know the DataGridView and have used it many times. But the DataGridView is part of Windows Form and not WPF (Windows Presentations Foundation). WPF shall be the successor of Windows Forms. Earlier versions (before VS 2010) WPF had nothing like a DataGridView and only WPF 3.5 introduced a similar tool and it was called "DataGrid" but is not so handy like the DataGridView (perhaps it is only a matter of convenience).

      I have now decided that i use WPF for all my new applications because soon or later you have to learn it.

      The basic way to display datas in WPF is so:

      1. You need a class

      Public Class Example

      Private _Item01 As String
      Private _ Item02 As String

      Public Property Item01/Item02 As String

      Get ... / Set ...

      ...

      End Class

      2. WPF XAML

      We have a DataGrid called "DataGrid1) in the Window

      <DataGrid AutoGenerateColumns="False" Height="271" HorizontalAlignment="Left" Margin="12,28,0,0" Name="DataGrid1" VerticalAlignment="Top" ItemsSource="{Binding}" Width="261" >
      <DataGrid.Columns>
      <DataGridTextColumn Header="Item" Width="90" Binding="{Binding Path=Item01}"></DataGridTextColumn>
      <DataGridTextColumn Header="Next Item" Width="90" Binding="{Binding Path=Item02}"></DataGridTextColumn>
      </DataGrid.Columns>
      </DataGrid>
      3. MainWindow.xaml.vb

      Class MainWindow

      Dim table As New List(Of Exampel)

      ...

      Private Sub X_Response_Process ( ...)

      Dim response As New Exampel

      ...
      response.Item01 = "x"
      response.Item02 = "y"

      table.Add(response)

      ...
      End Sub

      Private Sub ShowAllInDataGrid ()

      DataGrid1.ItemsSource = table
      DataGrid1.IsReadOnly = True

      End Sub

      When you modify items of the table and try to update the DataGrid you have to add:

      DataGrid1.Items.Refresh()

      This is the basic structure and should help for a start but things can become very quickly complex.

      Comment

      • ribogio7
        Junior Member
        • Apr 2010
        • 4

        #438
        Hi Mumbles0,

        I have upload an image.And i would like to ask a simple question.How can i take these numbers (100.7% and 99.3%) with betfair api...? (Which method must be use and which property must be use in this method)

        Thank you.
        Attached Files

        Comment

        • Mumbles0
          Junior Member
          • Jan 2009
          • 240

          #439
          ribogio7,

          These numbers are the "Book %" or "overround" values for the market.

          ribogio7-1.bmp

          I don't think you can get them directly from the API but they are quite easy to calculate. Their value is the sum of the reciprocals of the best prices, expressed as a percentage:
          For the Back = (1/2.08 + 1/4.4 + 1/3.35) * 100 = 100.7
          For the Lay = (1/2.1 + 1/4.5 + 1/3.45) * 100 = 98.8

          Comment

          • Mumbles0
            Junior Member
            • Jan 2009
            • 240

            #440
            Wpf

            Peter,

            Obviously I don't know much about WPF.

            Comment

            • John10
              Junior Member
              • Sep 2010
              • 4

              #441
              Munbles0 I didn't know that you can load the DataGridView directly. thanks for the Tip.
              It Works Great.

              Comment

              • Monairda
                Junior Member
                • Jan 2009
                • 32

                #442
                GetBetHistory

                Hello

                Thanks to everyone and especially to Mumbles0

                One question that I can not solve. I'm using the call to Get Bet History (exchange) and I ask the ProfitAndloss and he returns the amount without applying the commission. However, in support of the API says that returns "Net result of bet"

                I'm using the code ribogio7

                Code:
                        Dim oGBHReq As New BFExchange.GetBetHistoryReq
                        Dim oGBHResp As New BFExchange.GetBetHistoryResp
                
                        With oGBHReq
                            .header = oHeaderUK
                            .placedDateFrom = Now.AddDays(-7)
                            .placedDateTo = Now
                            .startRecord = 0
                            .recordCount = 30
                            .betTypesIncluded = BFExchange.BetStatusEnum.S 
                            ReDim .eventTypeIds(0) : .eventTypeIds(0) = 1 'For soccer
                            ReDim .marketTypesIncluded(0) : .marketTypesIncluded(0) = BFExchange.MarketTypeEnum.O
                            .sortBetsBy = BFExchange.BetsOrderByEnum.PLACED_DATE
                        End With
                
                        oGBHResp = BetfairUK.getBetHistory(oGBHReq)
                
                        With oGBHResp
                            CheckHeader(.header)
                            MsgBox("ErrorCode = " & .errorCode.ToString)
                            If .errorCode = BFExchange.GetBetHistoryErrorEnum.OK Then
                                For i = 0 To .betHistoryItems().Length - 1
                                    RichTextBox1.Text = .betHistoryItems(i).betId & .betHistoryItems(i).betType & .betHistoryItems(i).placedDate & .betHistoryItems(i).profitAndloss & vbNewLine
                                Next
                            End If
                        End With
                http://bdphelp.betfair.com/API6/6.0/...tml/wwhelp.htm

                Any suggestions, thanks
                Last edited by Monairda; 19-09-2010, 06:46 PM.

                Comment

                • labus
                  Junior Member
                  • Apr 2010
                  • 1

                  #443
                  Hi i made list of all steps for better orientation this great tutorial

                  Step 1. Build a Test Form

                  Step 2. Connecting to the Global service

                  Step 3. Saving the Session Token

                  Step 4. Typical API call: getActiveEventTypes

                  Step 5. Accessing an Exchange API

                  Step 6. Unpacking Response Strings

                  Step 7. Restrictions of the Free API

                  Step 8. Using a Call Timer

                  Step 9. Making Async API Calls

                  Step 10. Calling getCompleteMarketPricesCompressed

                  Step 11. A Look at Multithreading

                  Step 12. Getting a List of Runners

                  Step 13. Enabling gzip Compression

                  Step 14. Calling getMarketPricesCompressed

                  Step 15. Using TreeView to show events and markets

                  Step 16. Unpacking Removed Runners

                  Step 17. Sorting Runner Info Arrays

                  Step 18. Horse Racing - Today’s Card

                  Step 19. Placing a Bet

                  Step 20. Monitoring Bet Status

                  Step 21. Cancelling a Bet

                  Step 22. Changing the bet size and price

                  Step 23. Changing a Bet

                  Step 24. Calling getMarketTradedVolumeCompressed

                  Step 25. Accessing Australian Markets

                  Step 26. Array fundamentals

                  Step 27. Understanding Object References

                  Step 28. Placing Multiple Bets with placeBets

                  Step 29. Adding controls to a form at run time

                  Step 30. Saving your project’s settings

                  Comment

                  • Mumbles0
                    Junior Member
                    • Jan 2009
                    • 240

                    #444
                    Thanks labus. The tutorial has gown quite large (mainly unplanned). That ties it down nicely.

                    Comment

                    • John10
                      Junior Member
                      • Sep 2010
                      • 4

                      #445
                      Market return differance

                      Mumbles0

                      image of my treeview created as per this tutorial
                      Attachment MyTree.jpg

                      image of BfExplorer
                      Attachment Bfexplorer.jpg

                      My question is, What changes are required to the following code to get the special bet under horse racing

                      Code:
                      Private Sub bMarkets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bAUMarkets.Click
                              Print("*** AU Markets ***")
                              Dim oMarketsReq As New BFAU.GetAllMarketsReq
                              Dim oMarketsResp As BFAU.GetAllMarketsResp
                              With oMarketsReq
                                  .header = oHeaderAU()
                                  ReDim .eventTypeIds(1) : .eventTypeIds(0) = 7 : .eventTypeIds(1) = 4339  'For horse , greyhound
                                  ReDim .countries(1) : .countries(0) = "AUS" : .countries(1) = "NZL"
                                  .fromDate = Today
                                  .toDate = Today.AddDays(1)
                              End With
                              oMarketsResp = BetFairAU.getAllMarkets(oMarketsReq)  'Call the AU API
                              With oMarketsResp
                                  CheckHeader(.header)
                                  Print("ErrorCode = " & .errorCode.ToString)
                                  If .errorCode = BFAU.GetAllMarketsErrorEnum.OK Then
                                      'Print(.marketData)
                                      Dim AllMarkets As New UnpackAllMarkets(.marketData)   'Create an object and unpack the string
                                      PopulateTreeView(AllMarkets, tvMarkets)
                                      'With AllMarkets
                                      '    For i = 0 To .marketData.Length - 1
                                      '        With .marketData(i)
                                      '            Print(.eventHeirachy & " " & .marketId & "  " & .marketStatus & "  " & .marketName & "  " & .menuPath & "  " & .countryCode)
                                      '        End With
                                      '    Next
                                      'End With
                                  End If
                              End With
                          End Sub
                      Attached Files
                      Last edited by John10; 20-09-2010, 02:44 AM. Reason: No Image Showing

                      Comment

                      • Mumbles0
                        Junior Member
                        • Jan 2009
                        • 240

                        #446
                        John10,

                        The special bet pertains to the Melbourne Cup, event date 2 November 2010, but your date limits are set for today only. So put
                        .fromDate = Today
                        .toDate = #11/3/2010#
                        to return this market.

                        Comment

                        • granted
                          Junior Member
                          • Jun 2009
                          • 14

                          #447
                          cancel all unmatched bets

                          does anyone know how i can cancel all unmatched bets for a market id?

                          Comment

                          • Baby Jesus
                            Junior Member
                            • Apr 2009
                            • 7

                            #448
                            Originally posted by granted View Post
                            does anyone know how i can cancel all unmatched bets for a market id?
                            Depends if you're using the free api or full api.

                            The full API has a call CancelBetsByMarket which only requires the header and marketId (or array of marketIds) - downside is you don't get a full breakdown to the bets in the market i'e. if some of the bets have been matched between sending the request and it hitting the exhange and may still have to call up getMUBets to monitor any positions you have in the market.

                            With the free api you're only option is to call getMUBets and request a list of unmatched bets then send the array of betIds to cancelBets - cancelBets will then give you a fuller picture confirming the status of your outstanding bets including if any have been matched whilst the request was sent.

                            Comment

                            • ribogio7
                              Junior Member
                              • Apr 2010
                              • 4

                              #449
                              Hello Mumbles0,

                              First of all,i am grateful for all your help.

                              I have one more question about profit and loss in particular market.

                              How can i get the profit or loss in every selection before place the bet...?

                              Which method can i use to display these values...?

                              ps:I have upload an image to help you about this issue.
                              Attached Files

                              Comment

                              • Tony Logun
                                Junior Member
                                • Feb 2009
                                • 5

                                #450
                                Hi, can anyone give some pointers on how to automatically select the next market once the market timer reaches zero.

                                Thanks

                                Tony

                                Comment

                                Working...
                                X