Using VB2008 to acccess the Betfair API: A tutorial

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • thewhistler
    replied
    A little stuck

    I have build the basics of table build and all seems well and good.

    My main problem with the program still remains with the market id.

    Once I double click the market I am wanting to look at it prints the market id

    Code:
         Private Sub lbMarkets_DoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbmarkets.DoubleClick
            Dim s As String, Part As String(), marketId As Integer
    
            s = lbmarkets.SelectedItem    'The selected item
            Part = s.Split(" ")           'Get the parts of the item separated by spaces
            marketId = Val(Part(1))       'The marketId is the second part
            Print("marketId = " & marketId)
    
    
    
    
            Dim oCMPCreq As New BFUK.GetCompleteMarketPricesCompressedReq
            With oCMPCreq
                .header = oHeaderUK()
                .marketId = marketId
            End With
            StateCount += 1
            BetFairUK.getCompleteMarketPricesCompressedAsync(oCMPCreq, StateCount) 'Call the APi
    Which is marketID

    Is there a way to set this as the current market ID for a public string that can be used throughout all other requests, such as pressing buttons runners or prices?

    I have been trying to reference the marketID as it currently stands but keeps producing the error INVALID_MARKET.

    Perhaps I am missing a trick here

    Leave a comment:


  • thewhistler
    replied
    Ahhhh, so by declaring friend it basically allows reference from any form.

    Fantastic, works perfectly added in me.close at the end of the login so the window closes.

    Now have a fully functioning little login window


    I have since created a grid view form and plan to pull a table of runners for a specific market into the grid view.


    The table fields are as follows

    Checkbox (this will be used as my horse selection box)
    market Id text field
    Runner Name
    Back Odds
    Lay Odds
    Start Time
    Market Name
    Date


    I currently click through my list box menu and it provides today's racing market which double clicking on whatever market will return the market ID in Tlog

    At this point I am not sure how to reference the clicked market ID so I copy paste the number into input boxes I have created for runners and market prices.

    My main problem at this point is how to pull the data into the grid view from the tlog.

    Code for odds:

    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

    Code for markets

    Code:
    Private Sub bMarkets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bmarkets.Click
            Print("*** Horse Racing - Today's Card ***")
            Dim oMarketsReq As New BFUK.GetAllMarketsReq
            Dim oMarketsResp As BFUK.GetAllMarketsResp
    
            With oMarketsReq
                .header = oHeaderUK()
                ReDim .eventTypeIds(0) : .eventTypeIds(0) = 7   'For horse racing
                ReDim .countries(1) : .countries(0) = "GBR" : .countries(1) = "IRL"
                .fromDate = Today
                .toDate = Today.AddDays(1)
            End With
            oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)
            With BetFairUK.getAllMarkets(oMarketsReq)  'Call getAllMarkets
                CheckHeader(.header)
                Print("ErrorCode = " & .errorCode.ToString)
                If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
                    Dim AllMarkets As New UnpackAllMarkets(.marketData)
                    Dim Names As String(), TodaysCard As New List(Of MarketDataType)
                    With AllMarkets
                        For i = 0 To .marketData.Length - 1
    
                            Names = .marketData(i).menuPath.Split("\")   'This is the filter
                            If Names.Length = 4 AndAlso Not Names(3).StartsWith("Daily") Then
                                If .marketData(i).noOfWinners = 1 Then
    
                                    TodaysCard.Add(.marketData(i))    'Add win markets only
                                End If
                            End If
    
                        Next
                    End With
    
    
    
                    TodaysCard.Sort(New CompareMarketTimes)   'Sort according to market times 
                    For Each Race In TodaysCard    'Print the card
                        With Race
                            Names = .menuPath.Split("\")
                            lbmarkets.Items.Add(.eventDate.ToLocalTime.TimeOfDay.ToString & " " & .marketId & " " & Names(3) & " - " & .marketName)
                        End With
                    Next
    
                End If
            End With
    
        End Sub

    What I have been currently trying to do is dim .marketname into the gridview and print it in the column.

    My other thinking is to try and pull all the data into a datasource then pull it into the grid view.

    Although reading through the previous page I will see if I can achieve what I am after through table build
    Last edited by thewhistler; 02-07-2010, 03:50 PM.

    Leave a comment:


  • Mumbles0
    replied
    Adding a Login form

    Whistler,

    I think you are having trouble trying to access members on the original form from your new Login form. You should be getting compiler errors because of this.

    Let’s assume that you have a main form (TestForm) which contains the existing code and you’ve added a new form (LoginForm) which has TextBoxes for User Name and Password entry.


    The TestForm code could be like this:

    Code:
    [COLOR="Gray"]Public Class TestForm
    
      [COLOR="Black"]Friend[/COLOR] BetFairGL As New BFGlobal.BFGlobalService      'The UK ExchangeService object
      Private SessionToken As String
    
      [COLOR="Black"]Private Sub bLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bLogin.Click
        LoginForm.Show()     'Display the Login form
      End Sub[/COLOR]
    
      [COLOR="Black"]Friend[/COLOR] Sub Print(ByVal Message As String)
        With tLog
          .SelectionStart = .Text.Length
          .SelectedText = vbCrLf & Message
        End With
      End Sub
    
     [COLOR="Black"] Friend[/COLOR] Sub CheckHeader(ByVal Header As BFGlobal.APIResponseHeader)
        With Header
          Print("HeaderCode = " & .errorCode.ToString)
          SessionToken = .sessionToken
        End With
      End Sub
    
      ...............
      ...............
      ...............
    
    End Class[/COLOR]
    Because the LoginForm code requires access to three members of the TestForm class (the object variable BetfairGL, Sub CheckHeader and Sub Print) we add the Friend keyword to permit this. This is called an access modifier and allows the member to be accessed from any other part of the project. Note that BetfairGL was originally declared Private, hence it was only accessible from code within the TestForm class.

    When the Login button is clicked the LoginForm is displayed (using the .Show method).

    LoginForm contains the code which performs the Login operation when the OK button is clicked:

    Code:
    [COLOR="Gray"]Public Class LoginForm
    
      Private Sub Bok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bOK.Click
    
        Dim oLoginReq As New BFGlobal.LoginReq
        Dim oLoginResp As BFGlobal.LoginResp
    
        With oLoginReq
          .username = TBuser.Text
          .password = TBpass.Text
          .productId = 82           'For free API
        End With
    
        oLoginResp = [COLOR="Black"]TestForm.[/COLOR]BetFairGL.login(oLoginReq)     'Call the API
    
        With oLoginResp
          [COLOR="Black"]TestForm.[/COLOR]CheckHeader(.header)
          [COLOR="Black"]TestForm.[/COLOR]Print("ErrorCode = " & .errorCode.ToString)
        End With
    
      End Sub
    
    End Class[/COLOR]
    Because LoginForm views TestForm as being an external object, we must include the prefix TestForm whenever we refer to one of TestForm's members to let the compiler know what object these members belong to. (I hope that makes sense.)

    Try it. You should be able to login now.

    Leave a comment:


  • thewhistler
    replied
    Hi folks,

    I have been trying to make a small app to place bets on betfair.

    I have worked my way through all the steps and vaguely understand how it all ties together.

    Currently a bit stuck

    I previously had a login button coded with a couple of input boxes to enter the user name and password but, I felt it looked better with another form.

    Now when you press the login button it pulls up the new form. Where you then enter your username and password then press login.

    This all seems to work fine apart from one vital bit it doesn't actually log in.

    I am guessing this is due to, I can't seem to reference tlog from the original form into the new login form. Therefore it won't print the api header returns and enable the login?

    Any help would be appreciated


    Code:
    Private Sub Bok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bok.Click
            Dim oLoginReq As New BFGlobal.LoginReq
            Dim oLoginResp As BFGlobal.LoginResp
            With oLoginReq
                .username = Tbuser.Text
                .password = Tbpass.Text
                .productId = 82           'For free API
            End With
    
            oLoginResp = BetfairGL.login(oLoginReq)     'Call the API
            With oLoginResp
                CheckHeader(.header)
                Call Print("ErrorCode = " & .errorCode.ToString)
    
            End With
        End Sub
    Last edited by thewhistler; 30-06-2010, 04:07 PM.

    Leave a comment:


  • UncleScrooge
    replied
    Originally posted by Mumbles0 View Post
    UncleScrooge,

    Looks like you've added a service reference instead of a web reference in Step 2. See this post.

    (You're not the first to do this.)
    works wonders now!

    Thnx again!!!!!!!!

    Leave a comment:


  • Mumbles0
    replied
    UncleScrooge,

    Looks like you've added a service reference instead of a web reference in Step 2. See this post.

    (You're not the first to do this.)

    Leave a comment:


  • UncleScrooge
    replied
    Hi all.
    I'm an amateur in programming in VB.
    Just getting through this thread (absolutely fantastic for the material shown and the patience profuse by Mumble0).
    I started to build the app from "square one" trying to get through all the exercises proposed.
    I downloaded and installed VB 2010 Express.
    I'm still stuck at the beginning.
    I got this error message from VB
    "New" Cannot be used on an interface
    It refers to this:


    Code:
    Public Class BetfairTester
        Dim oHeaderGL As New BFGlobal.APIRequestHeader
        [COLOR="Red"][B]Dim BetfairGL As New BFGlobal.BFGlobalService[/B][/COLOR]
    
        Sub Print(ByVal Message As String)
            With tLog
                .SelectionStart = .Text.Length
                .SelectedText = vbCrLf & Message
            End With
        End Sub
    
        Private Sub bLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bLogin.Click
            Print("*** Login ***")
            Dim oLoginReq As New BFGlobal.LoginReq
            Dim oLoginResp As BFGlobal.LoginResp
            With oLoginReq
                .username = "UserName"
                .password = "Password"
                .productId = 82           'For free API
            End With
            oLoginResp = BetfairGL.login(oLoginReq)     'Call the API
            With oLoginResp
                CheckHeader(.header)
                Print("ErrorCode = " & .errorCode.ToString)
            End With
        End Sub
    
        Private Sub bLogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bLogout.Click
            Print("*** Logout ***")
        End Sub
    
        Private Sub bKeepAlive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bKeepAlive.Click
            Print("*** KeepAlive ***")
        End Sub
        Sub CheckHeader(ByVal Header As BFGlobal.APIResponseHeader)
            With Header
                Print("HeaderCode = " & .errorCode.ToString)
                oHeaderGL.sessionToken = .sessionToken
            End With
        End Sub
    End Class
    it might well be a stupid question so pls forgive my inexperience and naivety.
    Tnhx in advance
    Last edited by UncleScrooge; 29-06-2010, 07:15 AM.

    Leave a comment:


  • Mumbles0
    replied
    UserState object.

    A good question beans.

    For the placeBets example of Step 28:

    In the async response object e the property e.UserState is of type Object, hence it can contain an object of any type. At design time Intellisense does not know what type of object will ultimately be assigned to this property, so it cannot offer any suggestions (apart from the members of the fundamental Object class). The complier will accept anything you type in here. This property name will be resolved at run time when the expression:
    e.UserState.Param

    is evaluated (in a process called "late binding"). If the Param member doesn’t exist (or you’ve miss-spelt it) you will get "MissingMemberException (Public member 'xxx' on type 'UserState' not found)" when your program runs.

    If you wish you can introduce an intermediate variable u in a separate statement to cast the object back to type UserState:
    Dim u As UserState = e.UserState
    Print("MarketId = " & u.Param)

    Intellisense will now work as expected on the variable u.

    A point of confusion: Perhaps unwisely, UserState is the name I’ve given to the class which holds the user parameter. It is also the name of the property of the async response object (e.UserState) which holds our parameter-containing object. So the name UserState refers to two completely different entities. The compiler does not have a problem with this because it sorts names out by context. Thus names can be reused freely as long as their context is unambiguous.


    Response time measurement

    Because UserState can be an object of any complexity, it can hold more than one parameter. Let’s now define another class to hold two parameters:

    Code:
    Class Params
      Property MarketId As Integer
      Property SendTime As Date
      Sub New(ByVal _MarketId As Integer)
        MarketId = _MarketId   'The marketId parameter
        SendTime = Now         'The current time parameter
      End Sub
    End Class
    and use an object from this class instead in the async call statement:
    BetfairUK.placeBetsAsync(oPlaceBetsReq, New Params(MarketId)) 'Call API to place the bets

    This sends the two parameters along with the request object. The parameters are MarketId (as before) and SendTime (which holds the time when the async call was made). These parameters can be recovered in Sub BetfairUK_placeBetsCompleteted (and the overall response time calculated) using code something like this:

    Code:
          ............
    
          With e.Result
            CheckHeader(.header)
    
            Dim p As Params = e.UserState  'The object containing the parameters
            Dim t As TimeSpan = Now - p.SendTime  'The overall response time
            Print("MarketId = " & p.MarketId & "  Time = " & t.ToString)
    
            If .errorCode = BFUK.PlaceBetsErrorEnum.OK Then  'placeBets call OK
            ............
            ............
    You can extend on this idea to pass as many parameters as you like to the event handler for any async call. The UserState object can provide a very useful facility.

    Leave a comment:


  • beans
    replied
    Any idea's why the 'params' does not show up on intelli-sense for UserState? If I type it in I get no error's but it's never listed as one of the possible options.
    I'm wondering how far the userstate object could be extended, for example could we include a StopWatch in it so we can keep track of a response time from the API for async calls?

    Leave a comment:


  • Monairda
    replied
    Hi Mumbles0,

    Thanks for everything. I'll try it!

    Best Regards

    Leave a comment:


  • Mumbles0
    replied
    Step 28. Placing Multiple Bets with placeBets.

    In Step 19 we called placeBets to place a single bet. In the example we assigned our desired bet parameters to the properties of an oBet object (of type BFUK.PlaceBets), then assigned this object to the first element of the .bets array in the request object oPlaceBetsReq. Because the .bets property is an array, we can use this to place several bets at once simply by increasing the length of this array (with a Redim statement), and assigning the parameters for each bet to each element of this array. The length of the .bets array must equal the number of bets to be placed.

    Note this restriction: all bets must be on the same market.

    A scheme to place 3 bets could be like this:

    Code:
      Dim oPlaceBetsReq As New BFUK.PlaceBetsReq      'Create the request object
      Dim oPlaceBetsResp As BFUK.PlaceBetsResp    'A variable to hold the response object
      With oPlaceBetsReq
        .header = oHeaderUK()       'The standard header
        ReDim .bets(2)   'Set array upper bound = 2 (to hold 3 bets)
    
        .bets(0) = New BFUK.PlaceBets  'Create an object in element(0)
        With .bets(0)
          [I]'Assign properties to specify 1st bet[/I]
        End With
    
        .bets(1) = New BFUK.PlaceBets  'Create an object in element(1)
        With .bets(1)
          [I]'Assign properties to specify 2nd bet[/I]
        End With
    
        .bets(2) = New BFUK.PlaceBets    'Create an object in element(2)
        With .bets(2)
          [I]'Assign properties to specify 3rd bet[/I]
        End With
    
      End With
    
      oPlaceBetsResp = BetfairUK.placeBets(oPlaceBetsReq)  'Call API to place the bet
    
      ...........................
    
      [I]process response as per step 19 example[/I]
      ............................
    This extends the example in Step 19 to the multiple bet scenario. In the code there is a minor difference. We don’t create an intermediate oBet object. Here we put a BFUK.PlaceBets object into each element of .bets and assign the properties directly.

    The results of the bet placement are returned in the .betResults array of the response object in the same order as they appear in the .bets array of the request object (at least I assume this is the case - the documentation does not specifically say so but this seems to be what happens).

    Here is another example which uses a List(Of T) object to hold a list of bet details. This is a convenient array-based object because it grows automatically as you add more items. No Redim is required.

    In an application you may be analysing a market looking for betting opportunities. Rather than call placeBets whenever a bet is found, you can save the bet details in this list and submit a batch of bets later on. We create a suitable List object with this statement:

    Code:
    Private BetList As New List(Of BFUK.PlaceBets)
    You call Sub ListBet whenever you wish to add a bet to the List:

    Code:
    Sub ListBet(ByVal MarketId As Integer, ByVal YourSelection As Integer, ByVal YourBetType As BFUK.BetTypeEnum, ByVal BetPrice As Decimal, ByVal BetSize As Decimal)
    
      Dim oBet As New BFUK.PlaceBets   'An object to specify the bet
      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 = MarketId           '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
      BetList.Add(oBet)     'Add this bet to the list
    
    End Sub
    This sub sets up an oBet object in a similar way to Sub PlaceBet of Step 19, but this object is saved in BetList, rather than sent immediately to the API in the request object. You can keep calling Sub ListBet to add bets to the list. You can then send the listed bets to the API in one hit using Sub SubmitBets:

    Code:
    Sub SubmitBets(ByVal MarketId As Integer)
      Dim oPlaceBetsReq As New BFUK.PlaceBetsReq      'Create the request object
      With oPlaceBetsReq
        .header = oHeaderUK()         'The standard header
        .bets = BetList.ToArray       'The array containing the list of bets
      End With
      BetfairUK.placeBetsAsync(oPlaceBetsReq, New UserState(MarketId))  'Call API to place the bets
      BetList.Clear()   'Clear the list
    End Sub
    Here we assign the request object in the usual way. Note the use of the .ToArray property of BetList. This returns a reference to BetList’s internal array.

    I have made this an async call to provide best efficiency, particularly when working with multiple markets. For multiple markets you can to repeat the “list and submit” process for your bets on each market. This can be done in rapid succession.

    Each async call responds via a common event handler (placeBetsCompleted). If you look at the API Guide for placeBets you will see that the response contains the betResults array which returns the betIds (if successful), but there is no marketId or other identifying parameter. So if you receive several responses at once for bets placed on different markets, you don’t know which market each response is for.

    To overcome this problem we can make good use of the optional userState parameter of the async call. We require a simple class to encapsulate a user parameter (or set of parameters in an object or structure):

    Code:
    Class UserState
      Property Param As Object
      Sub New(ByVal Value As Object)
        Param = Value
      End Sub
    End Class
    (Note here I’m using the new single-line Property statement of VB2010. If you are using VB2008 either complete the Property Get/Set snippet or use the Public keyword.)

    Using this we send the marketId along with the request object in the async call. Because this UserState object is returned in the response, we can identify the market associated with each response. The UserState objects thus sent are considered to be unique (even if the marketId is the same).

    An event handler for testing this:

    Code:
    Private Sub BetfairUK_placeBetsCompleted(ByVal sender As Object, ByVal e As BFUK.placeBetsCompletedEventArgs) Handles BetfairUK.placeBetsCompleted
      Try
        If Not e.Cancelled Then
          With e.Result
            CheckHeader(.header)
            Print("MarketId = " & e.UserState.Param) 'The marketId comes back in e.UserState
            If .errorCode = BFUK.PlaceBetsErrorEnum.OK Then  'placeBets call OK
    
              For i = 0 To .betResults.Length - 1
                With .betResults(i)
                  Print(.resultCode.ToString)   'Result of the bet placement
                  If .success Then Print("BetId = " & .betId) 'Print the betId if successful
                End With
              Next
    
            Else
              Print("errorCode = " & .errorCode.ToString) 'If placeBets error
            End If
          End With
        End If
    
      Catch ex As ApplicationException  'If problem
        Print(ex.Message)
      End Try
    
    End Sub
    Note that the response object is returned in e.Result, and e.UserState contains the UserState object exactly as sent in Sub SubmitBets.

    If you can get a scheme working based on these ideas your project should be capable of placing a large number of bets in a short space of time. Good luck.


    An Afterthought:

    If you try a scheme based on this Step to place bets across several markets at once you may be disappointed with the response times. This could be due to a .NET constraint on the number of simultaneous HTTP connections available to make the placeBets calls (the default is 2). To alleviate this, include this statement in your initialization section (I suggest in your startup form’s Load event):

    Net.ServicePointManager.DefaultConnectionLimit = 20
    This will increase the maximum number of HTTP connections from 2 to 20. The number you chose should be the maximum number of concurrent API calls you are likely to make.
    Last edited by Mumbles0; 07-12-2010, 12:55 AM. Reason: Afterthought added

    Leave a comment:


  • waldjunge
    replied
    Hi Mumbles0,
    do you know how to place a bet with a stake less then 2? Lets say for example 0.01 pounds?
    Regards
    Martin

    Leave a comment:


  • Mumbles0
    replied
    Using a DataTable

    Monairda,

    It looks like you have two DataGridView controls side by side, one with runner names (gvDataName) and the other with price and volume data (gvPrices). It is OK to call getMarket to get the list of runner names from Sub MarketForm_Load.

    It may be better to put everything in one table. You could set up all columns of the table in Sub MarketForm_Load and update with price and volume data when it arrives with Sub BuildDataTable.

    Code:
    Private Tabla As New DataTable  'The data table
    
    Private Sub MarketForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
      Dim oMarketReq As New BFUK.GetMarketReq       'Create the request object
      Dim oMarketResp As BFUK.GetMarketResp     'Create a varaible for the response object
      Dim row As DataRow
    
      With Tabla.Columns     'Set up all columns
        .Add("SelectionId")
        .Add("Name")
        .Add("OddBack")
        .Add("OddLay")
        .Add("LPM")
        .Add("Vol")
        .Add("AmountBack")
        .Add("AmountLay")
        .Add("TotalBack")
        .Add("TotalLay")
      End With
    
      With oMarketReq
        .header = MainForm.oHeaderUK()
        .marketId = MarketId
      End With
      oMarketResp = MainForm.BetfairUK.getMarket(oMarketReq)    'Call the API (getMarket)
    
      With oMarketResp                      'Process the response
        MainForm.CheckHeader(.header)
        If .errorCode = BFUK.GetMarketErrorEnum.OK Then
          With .market
            For i = 0 To .runners.Length - 1
              With .runners(i)
                row = Tabla.NewRow
                row("SelectionId") = .selectionId   'Add the Selection Ids
                row("Name") = .name                 'and runner names
                Tabla.Rows.Add(row)
              End With
            Next
          End With
        End If
      End With
    
      gvDataName.DataSource = Tabla   'Show the data
      gvDataName.Refresh()
    
    End Sub

    For this sub the API access objects and methods are on MainForm. You may have to change the scope of the BetfairUK object to Friend or Public.

    Sub BuildDataTable updates the columns row by row. We use the Array.FindIndex method to get the element in the .runnerPrices (and .runnerVolume) corresponding to the selectionId for the row. The order of these arrays is not necessarily the same as the .runners array from getMarket. Also there could be a removed runner.
    Code:
    Private Sub BuildDataTable()
      Dim i, j, k As Integer
      Dim BestBack As Decimal
      Dim TotalBack As Decimal
      Dim TotalLay As Decimal
      Dim TotalVolumen As Decimal
      Dim RowSel As Integer
    
      For i = 0 To Tabla.Rows.Count - 1  'For each row in the DataTable
        RowSel = Tabla.Rows(i)("SelectionId")  'The selectionId for this row
    
        j = Array.FindIndex(oMarketPrices.runnerPrices, Function(x) x.selectionId = RowSel)  'The .runnerPrices array index for this selectionId
        If j >= 0 Then  'Runner exists in .runnerPrices array
    
          With oMarketPrices.runnerPrices(j)   'Update the DataTable
            Tabla.Rows(i)("Vol") = .totalAmountMatched
            Tabla.Rows(i)("LPM") = .lastPriceMatched
            If .bestPricesToBack.Length > 0 Then
              Tabla.Rows(i)("OddBack") = .bestPricesToBack(0).price
              Tabla.Rows(i)("AmountBack") = .bestPricesToBack(0).amountAvailable
              BestBack = .bestPricesToBack(0).price
            End If
            If .bestPricesToLay.Length > 0 Then
              Tabla.Rows(i)("OddLay") = .bestPricesToLay(0).price
              Tabla.Rows(i)("AmountLay") = .bestPricesToLay(0).amountAvailable
            End If
          End With
        End If
    
        TotalBack = 0 : TotalLay = 0 : TotalVolumen = 0
        k = Array.FindIndex(oTradedVolume.runnerVolume, Function(x) x.selectionId = RowSel) 'The .runnerVolume array index for this selection
        If k >= 0 Then'    Runner exists in .runnerVolume array
    
          With oTradedVolume.runnerVolume(k)   'Update the DataTable
            For j = 0 To .tradedVolume.Length - 1
              If BestBack <= .tradedVolume(j).odds Then
                TotalBack = TotalBack + .tradedVolume(j).totalMatchedAmount
              Else
                TotalLay = TotalLay + .tradedVolume(j).totalMatchedAmount
              End If
              TotalVolumen = TotalVolumen + .tradedVolume(j).totalMatchedAmount
            Next
          End With
        End If
    
        Tabla.Rows(i)("TotalBack") = TotalBack  'Update the DataGridView
        Tabla.Rows(i)("TotalLay") = TotalLay
    
      Next  'Next row
    
    End Sub

    Leave a comment:


  • Monairda
    replied
    Handling async calls for multiple markets and linking horse Namess's

    Hi Mumbles0


    Originally posted by Mumbles0 View Post
    Handling async calls for multiple markets
    Monairda,

    There are many ways to handle multiple markets. Here is an approach which uses a separate form for each market of interest using common async call handlers....

    http://forum.bdp.betfair.com/showthr...?t=112&page=33
    I have a problem trying to link the names of the horses at the table created in the call asynchronous.
    I had thought of using the step 12 to carry the load of the form to the selected market.
    But I do not work.
    Code:
    Private Sub MarketForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim oMarketReq As New BFUK.GetMarketReq       'Create the request object
            Dim oMarketResp As BFUK.GetMarketResp     'Create a varaible for the response object
            Dim tabla As New DataTable
            tabla.Columns.Add("IdSelection")
            tabla.Columns.Add("Name")
    
            Dim row As DataRow
    
            With oMarketReq
                .header = oHeaderUK()
                .marketId = MarketId
            End With
            oMarketResp = BetFairUK.getMarket(oMarketReq)    'Call the API
    
            With oMarketResp                      'Process the response
                CheckHeader(.header)
                'Print("ErrorCode = " & .errorCode.ToString)
                If .errorCode = BFUK.GetMarketErrorEnum.OK Then
                    With .market
                        'Print("MarketId = " & .marketId)    'Print id, name and status
                        'Print("Name = " & .name)
                        'Print("Status = " & .marketStatus.ToString)
                        For i = 0 To .runners.Length - 1
                            With .runners(i)
                                row = tabla.NewRow
                                row("IdSelection") = .selectionId
                                row("Name") = .name.ToString
                                tabla.Rows.Add(row)
                                'Print(.selectionId & "  " & .name)   'Print list of runners
                            End With
                        Next
                    End With
                End If
            End With
            gvDataName.DataSource = tabla
            gvDataName.Refresh()
        End Sub
    I would like to link the names of the horses to the table created by the data collected on objects in the Private Sub BuildDatatable(), but I do not know how to do it. Could you help me, please?


    Thanks for your help!!

    Leave a comment:


  • waldjunge
    replied
    Minumum Stake

    The minimum Stake for Back is 2 pounds. There are some tools available which can place less then 2 pounds. Does anybody know how this works? I could not find any help in the API manual.

    Thanks

    Martin

    Leave a comment:

Working...
X