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

    #181
    Step 19. Placing a Bet

    I have recently been asked about bet placement procedures, so I am posting some steps giving examples of calling the API’s bet placement and monitoring services, starting with placeBets.

    A typical application might monitor a market by calling getMarketPricesCompressed at regular intervals and, if conditions are right, place a bet by calling placeBets. With placeBets you can submit several bets at once and it can handle different types of bet in one call. To keep things simple the following example places a single standard exchange bet.

    Add this sub to the TestForm class:

    Code:
     
    Private Sub PlaceBet(ByVal YourMarket As Integer, ByVal YourSelection As Integer, ByVal YourBetType As BFUK.BetTypeEnum, ByVal BetPrice As Decimal, ByVal BetSize As Decimal)
    
      Dim oPlaceBetsReq As New BFUK.PlaceBetsReq      'Create the request object
      Dim oPlaceBetsResp As BFUK.PlaceBetsResp       'A variable to hold the response object
      Dim oBet As New BFUK.PlaceBets              'An object to specify the bet
      With oPlaceBetsReq
        .header = oHeaderUK()            'The standard header
        With oBet                        'Specify the bet details:
          .asianLineId = 0               'Non-asian handicap market 
          .betCategoryType = BFUK.BetCategoryTypeEnum.E    'Normal exchange bet
          .betPersistenceType = BFUK.BetPersistenceTypeEnum.NONE  'Standard bet (not SP or InPlay persistence)
          .betType = YourBetType         'Back or Lay
          .marketId = YourMarket         'The market of interest
          .price = BetPrice              'The desired price (odds)
          .selectionId = YourSelection   'Your selection of interest
          .size = BetSize                'The bet amount (stake)
          .bspLiability = 0              'Must be 0 for non-SP bet
        End With
        ReDim .bets(0)    'Array length = 1 to hold single bet
        .bets(0) = oBet   'Put the bet details object in element 0
      End With
    
      oPlaceBetsResp = BetFairUK.placeBets(oPlaceBetsReq)  'Call API to place the bet
    
      With oPlaceBetsResp    'The response
        CheckHeader(.header)
        Print("ErrorCode = " & .errorCode.ToString)
        If .errorCode = BFUK.PlaceBetsErrorEnum.OK Then  'The call succeeded
          For i = 0 To .betResults.Length - 1   'In this case there should only be 1 result.
            With .betResults(i)
              Print(.resultCode.ToString)   'Result of the bet placement
              If .success Then 
                Print("BetId = " & .betId)  'Print the betId if successful
                TheBetId = .betId           'Save this
               End If
            End With
          Next
        End If
      End With
    
    End Sub
    This is a sync call which follows the normal calling procedure. We create an object oBet to hold our bet parameters. This object is then assigned to the first element of the .bets array in the request object. The API Guide give details of each request parameter. In most cases, the purpose of each parameter is fairly obvious.

    This example has .betPersistenceType NONE. The other bet persistence types (SP, IP) can be used as described in the API guide. Note that not all markets have these other bet persistence types available. It’s a good idea to check the .bspMarket parameter returned by getMarket before placing a bet with SP persistence. Similarly check .turningInPlay from getAllMarkets before selecting IP.

    To place a bet you simply call Sub PlaceBet with your bet requirement as parameters. The calling syntax is:
    PlaceBet(marketId, selectionId, betType, price, size)

    To test this add a “PlaceBet” button to the TestForm. Name it bPlaceBet and add this code.

    Code:
    Dim Market As Integer = [I]YourMarketId[/I]     'The Id of your market
    Dim Selection As Integer = [I]YourSelectionId[/I]     'The Id of your selection
    Dim BetType As BFUK.BetTypeEnum = BFUK.BetTypeEnum.B   'For back bet
    Dim BetPrice As Decimal = 100            'Your desired odds
    Dim BetSize As Decimal = 10            'Your bet amount in currency units 
    Dim TheBetId As Long                  'The betId (returned from placeBets)
    
    Private Sub bPlaceBet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bPlaceBet.Click
      Print("*** PlaceBet ***")
      PlaceBet(Market, Selection, BetType, BetPrice, BetSize)    'The call to place the bet
    End Sub
    This sets up a test bet. Note that the values shown are for my example. You must plug in your own values. YourMarketId can be obtained from a previous call to getAllMarkets (refer Steps 5, 6, also 15), YourSelectionId can be obtained from a previous getMarket call for your market (refer Step 12). Change the BetType, BetPrice and BetSize to any values you like. This example specifies a Back bet, odds = 100, bet amount = 10 currency units. To test this, I suggest you choose a suitable market and set the bet parameters for a high odds back bet on a short-priced runner (this bet is unlikely to be matched).

    Now log onto the Betfair website and go to your market of interest. Observe the “My Bets” tab (which will probably be empty). Now run the project. When you click the “PlaceBet” button the bet should be placed. If successful, the bet appears on the “My Bets” tab. The Ref: number shown is the betId. You can change or cancel this bet on the website if you wish.

    That’s how to place a bet via the API. In the next step we will call getMUBets to monitor the status of the bet.

    Comment

    • genius1279
      Junior Member
      • Sep 2009
      • 4

      #182
      How to retrieve the information ball by ball?

      hi guys i amt trying to get the information on the Cricket market

      can any body tell me how can i get the information ball by ball basis and also how can i read the current score , and current ball etc.



      thanks in advace . any help regarding this would be great.

      Comment

      • genius1279
        Junior Member
        • Sep 2009
        • 4

        #183
        could'nt get this api call BetFairUK.getMarketPricesAsync

        i am using the Free APi and i could'nt find this BetFairUK.getMarketPricesAsync
        api call..

        help me please

        Comment

        • supunsilva.
          Junior Member
          • Aug 2009
          • 32

          #184
          Hii <REPLY TO genius1279>
          First of all insert following code to top of the testform class

          Dim WithEvents BetFairUK2 As New BFUK.BFExchangeService

          Please follow all by steps by step.. Please don't ignore any page.. You will never loss the cordings!!!!!

          Comment

          • genius1279
            Junior Member
            • Sep 2009
            • 4

            #185
            supunsilva.

            First of all thank you so much for the help.. its works for me .


            I asked one more question here.. that i am using the market "Cricket"

            and i am able to get all the information about the market.. i want to ask how can i retrieve the real time information about "Match score" "current run rate" "wickets fallen" "current ball"

            etc

            please help

            Comment

            • supunsilva.
              Junior Member
              • Aug 2009
              • 32

              #186
              Hi genius1279,

              I think Betfair API is a standed API for all events and markets. So.. therefore only we can retrieve standard informations. even we use soccar, baseball, basketball, hose racing, only we can retrieve specific odds for specific market.


              Hope you will understand this..!!!

              Thanks & Regards,
              Supun Silva

              Comment

              • supunsilva.
                Junior Member
                • Aug 2009
                • 32

                #187
                Placing bet problem

                Hi Mumbles, I have problem with placing bet. it's receiving error code=Invalid Size. I have placed odd 5.0 & Stake 0.01 for Lay bet.

                Other thing is when I press the place bet button, It is sticking the program. (Only If refresh odds timer enabled)

                If I press place bet button after stop refreshing odds, it is working fine and receiving error code=Invalid Size.

                Please find the following my odds refresh timer cording

                Print("*** MarketPricesCompressed ****")
                Dim oMPCreq As New BFUK.GetMarketPricesCompressedReq
                With oMPCreq
                .header = oHeaderUK()
                .marketId = TextBox3.Text 'an active market ID
                End With
                StateCount += 1
                BetFairUK2.getMarketPricesCompressedAsync(oMPCreq, StateCount)
                Please let me know what is the mistake I have made,,,
                Thanks & Regards,
                Supun Silva

                Comment

                • genius1279
                  Junior Member
                  • Sep 2009
                  • 4

                  #188
                  Live ScoreBoard

                  is there any way to get information on live score board for the cricket market ?

                  Comment

                  • Mumbles0
                    Junior Member
                    • Jan 2009
                    • 240

                    #189
                    Cricket info.

                    Watch TV.

                    I doubt if you will get real time data service for this.
                    You should ask the question in the General Betting section of the forum.

                    Comment

                    • supunsilva.
                      Junior Member
                      • Aug 2009
                      • 32

                      #190
                      Hiii

                      Hello Mumbles... What about my question????

                      Comment

                      • Mumbles0
                        Junior Member
                        • Jan 2009
                        • 240

                        #191
                        Reply to supunsilva (Re: Placebets problem)

                        A stake of 0.01 isn't much of a bet in any currency. Betfair have a minimum stake requirement (about the equivalant of UK£2.00). If you attempt below this you get the INVALID_SIZE error. For a lay bet I suggest you set BetPrice = 1.01, BetSize = your minumum bet amount. Don't worry - the bet won't get matched.

                        Your code looks OK. It would be more robust if you changed the line:
                        .marketId = TextBox3.Text 'an active market ID
                        to:
                        .marketId = Val(TextBox3.Text) 'an active market ID
                        This will prevent an "invalid cast" exception if the textbox does not contain a number. However, this may not be your problem.

                        I am not clairvoyant. When you say "It is sticking the project" what do you mean? Is an error message being printed? Does your computer freeze? Does the program stop running with the exception assistant shown? If so, what does it say?

                        What is the time interval of your refresh timer?
                        Last edited by Mumbles0; 15-09-2009, 02:58 PM.

                        Comment

                        • supunsilva.
                          Junior Member
                          • Aug 2009
                          • 32

                          #192
                          Reply to Mumbles (Re: Placebets problem)

                          Hi Friend.. thanks for your reply.
                          First of all sorry for my poor English.
                          If I press the place bet button when the odds refresh timers enabled, It will take long time (more than 10s - system freeze during this period) to place bet. my timer interval=100


                          Normally in BetTrader and Fairbot we can place UK£0.01 stake. Could you kindly tell me how to place a UK£0.01 stake when we have only UK£0.05 in account.

                          Thank you very much,
                          Supun Silva
                          Last edited by supunsilva.; 15-09-2009, 03:28 PM.

                          Comment

                          • supunsilva.
                            Junior Member
                            • Aug 2009
                            • 32

                            #193
                            I think it's working now. I have changed my timer interval=100 to 500. But still it's little bit slow.Do you have any solution for this...???

                            Please find the way to place lay bet 0.01 stake when i have 0.05 in account balance???

                            Comment

                            • Mumbles0
                              Junior Member
                              • Jan 2009
                              • 240

                              #194
                              Are you using the Free API ?

                              Comment

                              • supunsilva.
                                Junior Member
                                • Aug 2009
                                • 32

                                #195
                                Hi Mumbles,

                                Yes.. I am using Free API..
                                Is there any problem using Free API???

                                Comment

                                Working...
                                X