Using VB2008 to acccess the Betfair API: A tutorial

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

  • Mumbles0
    replied
    Reply to Aitor (re: getAllMarkets filter)

    Your function works OK for me. When I make the test call:

    Code:
    Private Sub bTestAitor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bTestAitor.Click
    
      With TeamEvents(Today.AddDays(7), Today, "Real Madrid", 1)
        For i = 0 To .Count - 1
          With .Item(i)
            Print(.menuPath & "*" & .marketName)
          End With
        Next
      End With
    
    End Sub
    the function returns all 28 markets with .menuPath =
    \Soccer\UEFA Champions League\Fixtures 10 March\Real Madrid v Lyon

    and all 37 markets with .menuPath =
    \Soccer\Spanish Soccer\Primera Division\Fixtures 14 March\Valladolid v Real Madrid

    Make sure that the date limits you use include days when your team (equipo) is playing in a Champions League match.

    Leave a comment:


  • Aitor
    replied
    Why doesnt work with Champions League

    Hello!I have a small problem using this function. y put the name of a football team there like "equipo" and the code is the football code, this is correct when i put a name of for example a spanish football team, but the problem is that one team is playing champions league, this doesn´t appear. what is hapening???what is wrong?


    Private Function TeamEvents(ByVal fecha As Date, ByVal fechaini As Date, ByVal equipo As String, ByVal cod As String) As List(Of MarketDataType)
    Dim Names As String(), Equipos As New List(Of MarketDataType)

    Dim oMarketsReq As New BFUK.GetAllMarketsReq
    Dim oMarketsResp As BFUK.GetAllMarketsResp
    With oMarketsReq
    .header = oHeaderUK()
    ReDim .eventTypeIds(0) : .eventTypeIds(0) = cod
    .fromDate = fechaini
    .toDate = fecha 'Today.AddDays(2) esto seria hoy y mañana
    End With
    oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq) 'Call the UK API

    With oMarketsResp
    CheckHeader(.header)
    Print("ErrorCode = " & .errorCode.ToString)
    If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
    Dim AllMarkets As New UnpackAllMarkets(.marketData)
    With AllMarkets
    For i = 0 To .marketData.Length - 1
    If .marketData(i).menuPath.Contains(equipo) Then
    Names = .marketData(i).menuPath.Split("\") 'Lo filtramos segun su /
    Equipos.Add(.marketData(i)) 'Añadir un mercado a la lista
    End If
    Next
    End With
    Equipos.Sort(New CompareMarketTimes) 'Ordenamos los mercados por fecha
    End If
    End With
    Return Equipos
    End Function

    Leave a comment:


  • Monairda
    replied
    Mumbles,

    Thank you very much, I will try to implement it

    Best Regards

    Leave a comment:


  • Mumbles0
    replied
    Processing data from 2 async calls.

    Monairda,

    Perhaps your problem is when to process the data from the 2 responses. This is what I do:
    Define a call counter to count the responses, clear it, the send the 2 async requests:

    Code:
    [COLOR="Gray"]Private oMarketPrices As UnpackMarketPricesCompressed
    Private oTradedVolume As UnpackMarketTradedVolumeCompressed
    [COLOR="Black"]Private CallCount As Integer[/COLOR]
    
    Private Sub GetMarketData()    'Sub to send the requests
      [COLOR="Black"]CallCount = 0  'Clear the call count
      [I]Call getMarketPricesCompressedAsync (as per step 14)[/I]
      [I]Call getMarketTradedVolumeCompressedAsync (as per step 24)[/I][/COLOR] 
    End Sub[/COLOR]
    The API now sends back the 2 responses. Problem is we don’t know which one comes back first, so we count them in the event handlers. When both responses have been received CallCount = 2, so now we call a sub to process the 2 unpacked data objects.

    Code:
    [COLOR="Gray"]Private Sub BetfairUK_getMarketPricesCompressedCompleted(ByVal sender As Object, ByVal e As BFUK.getMarketPricesCompressedCompletedEventArgs) Handles BetfairUK.getMarketPricesCompressedCompleted
      .........
      [I](Code similar to Step 14)[/I]
      .........
      If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then
        oMarketPrices = New UnpackMarketPricesCompressed(.marketPrices)   'Unpack the market prices data
        [COLOR="Black"]CallCount += 1    'Count this response
        If CallCount = 2 Then BuildDataTable()   'Process responses when both received[/COLOR]
      End If
      .........
      .........
    End Sub
    
    Private Sub BetfairUK_getMarketTradedVolumeCompressedCompleted(ByVal sender As Object, ByVal e As BFUK.getMarketTradedVolumeCompressedCompletedEventArgs) Handles BetfairUK.getMarketTradedVolumeCompressedCompleted
      ........
      [I](Code similar to Step 24)[/I]
      ........
      If .errorCode = BFUK.GetMarketTradedVolumeCompressedErrorEnum.OK Then
        oTradedVolume = New UnpackMarketTradedVolumeCompressed(.tradedVolume)  'Unpack the traded volume data
        [COLOR="Black"]CallCount += 1  'Count this response
        If CallCount = 2 Then BuildDataTable()  'Process responses when both received[/COLOR]
      End If
      .........
      .........
    End Sub
    
    [COLOR="Black"]Private Sub BuildDataTable()
      [I]Builds a data table from data contained in oMarketPrices and oTradedVolume objects[/I]
    End Sub[/COLOR][/COLOR]
    Sub BuildDataTable is only called once, from the event handler which handles the second response (whichever that is). This ensures that both responses have arrived before output processing commences.
    Last edited by Mumbles0; 15-05-2010, 11:09 AM.

    Leave a comment:


  • Monairda
    replied
    Sorry Mumbles,

    Maybe I am not properly explained. I do not want the data that shows column To Back or To Lay. I want the data that appears in the column Amount Matched, attached an image.

    I understood that this data showed the call to getMarketTradedVolumeCompressedCompleted, print the table of odds and amounts matched.
    That's why I wondered whether there was any call that returns a datatable

    I would like to do this table:

    Marketid | SelectionId | totalAmountMatched | lastPriceMatched | bestPricesToBack(0).price | bestPricesToBack(0).amountAvailable | tradedVolume(j).totalMatchedAmount (Sum amount matched From Odds 1.01 to 2.40 in this image) | tradedVolume(j).totalMatchedAmount ( Sum amount matched From Odds 2.42 to 1000 in this image)

    I had thought to cross the information of the two calls (getmarketTradedVolumCompressedCompeted +getMarketPricesCompressedCompleted) and set up a datatable, but I do not know how to pass information from one call to another

    Thanks

    Last edited by Monairda; 04-03-2010, 09:20 PM.

    Leave a comment:

Working...
X