Using VB2008 to acccess the Betfair API: A tutorial

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

  • Camper
    replied
    Hi again

    I get this error when I'm executing my program:
    System.IndexOutOfRangeException: Index was outside the bounds of the array.
    ...on this code:
    Code:
       Sub ShowMprices(ByVal MpriceResp As BFUK.GetMarketPricesResp)
            Dim aPriceB(2) As String
            Dim bPriceB(2) As String
            Dim aPriceL(2) As String
            Dim bPriceL(2) As String
            With MpriceResp
                CheckHeader(.header)
                Print("ErrorCode = " & .errorCode.ToString)
                If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then
                    With .marketPrices
                        Dim MS As String
                        MS = Val(bMstatus.Text)
                        MS = .marketStatus
                        Dim MID As String
                        MID = Val(bMarkid.Text)
                        MID = .marketId
                        With .runnerPrices(0)
                            Dim Id0 As String
                            Id0 = Val(bSelecid.Text)
                            Id0 = .selectionId
                                With .bestPricesToBack(0)
                                aPriceB(0) = .price
                                aB0.Text = aPriceB(0)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                aBA0.Text = y
                                End With
                            With .bestPricesToLay(0)
                                aPriceL(0) = .price
                                aL0.Text = aPriceL(0)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                aLA0.Text = y
                            End With
                            With .bestPricesToBack(1)
                                aPriceB(1) = .price
                                aB1.Text = aPriceB(1)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                aBA1.Text = y
                            End With
                            With .bestPricesToLay(1)
                                aPriceL(1) = .price
                                aL1.Text = aPriceL(1)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                aLA1.Text = y
                            End With
                            With .bestPricesToBack(2)
                                aPriceB(2) = .price
                                aB2.Text = aPriceB(2)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                aBA2.Text = y
                            End With
                            With .bestPricesToLay(2)
                                aPriceL(2) = .price
                                aL2.Text = aPriceL(2)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                aLA2.Text = y
                            End With
                        End With
                        With .runnerPrices(1)
                            bSelectid1.Text = .selectionId
                            With .bestPricesToBack(0)
                                bPriceB(0) = .price
                                bB0.Text = bPriceB(0)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox3.Text = y
                            End With
                            With .bestPricesToLay(0)
                                bPriceL(0) = .price
                                bL0.Text = bPriceL(0)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox1.Text = y
                            End With
                            With .bestPricesToBack(1)
                                bPriceB(1) = .price
                                TextBox43.Text = bPriceB(1)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox42.Text = y
                            End With
                            With .bestPricesToLay(1)
                                bPriceL(1) = .price
                                TextBox35.Text = bPriceL(1)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox33.Text = y
                            End With
                            With .bestPricesToBack(2)
                                bPriceB(2) = .price
                                TextBox41.Text = bPriceB(2)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox40.Text = y
                            End With
                            With .bestPricesToLay(2)
                                bPriceL(2) = .price
                                TextBox34.Text = bPriceL(2)
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox32.Text = y
                            End With
                        End With
                    End With
                Else
                    Print("ShowMprices Error")
                End If
            End With
        End Sub
    I googled and it seems that I'm getting this error because I'm using an index here that is higher than the number of items in the array.

    I have no idea how to solve his and believe me I've googled a lot

    Thanks in advance.

    Leave a comment:


  • pubnuts
    replied
    Step 2

    Hi all,

    I am trying to implement step 2 using vb 2010 but I am getting the following error on the BLogin_Click sub.

    Value of type 'BetfairBot.BFGlobal.KeepAliveReq' cannot be converted to 'BetfairBot.BFGlobal.keepAliveIn'

    This error occurs on the following line of code

    oLoginResp = BetfairGL.login(oLoginReq) 'Call the API

    I am getting a similar error on the bKeepAlive_Click sub.

    I don't see anyone else coming across the same error so I must have something wrong.

    I would appreciate it if anyone can help

    Thanks.

    Leave a comment:


  • Camper
    replied
    Thanks for the info, I've already read those a few days ago and used some of the info on my program.

    But let's say I have a back on player one and a lay on player 2, what I need to do to trade out those 2 bets? With multiple positions open on a market I don't know what to do, with one bet only it's quite easy I think.

    I will read those posts you said again, maybe I'm missing something.

    Regards

    Leave a comment:


  • BigSprout
    replied
    Camper,
    the topics pertaining to bet placement are covered in page 19 -> 24

    Step 19. Place a Bet
    Step 21. Cancel a Bet
    Step 22. Change Bet size & price
    Step 23. Changing a Bet
    Step 20. Monitor a Bet

    There is an index of all the steps on page 45, supplied by member "labus", which I have bookmarked

    cheers

    Leave a comment:


  • Camper
    replied
    Thank you! I'm not at my computer now but I will try it later.

    Another thing, I have no idea how to write a code to close a trade using VB, I have to do other things in my program before i start thinking about that but everytime I do I get scared

    I'm reading this topic when I have some free time, I'm currently on page 40 or so, I don't know if that subject will come on the next twenty pages.

    Leave a comment:


  • BigSprout
    replied
    Camper,
    I think the reason why you are getting 2nd best prices is because that is what you are asking for, try changing:

    .bestPricesToBack(1) to .bestPricesToBack(0)
    bestPricesToLay(1) to bestPricesToLay(0)

    Code:
                        With .runnerPrices(1)
                            bSelectid1.Text = .selectionId
                            [B][COLOR="Red"]With .bestPricesToBack(0)[/COLOR][/B]
                                TextBox5.Text = .price
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox3.Text = y
                            End With
                            [COLOR="Red"][B]With .bestPricesToLay(0)[/B][/COLOR]
                                TextBox2.Text = .price
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox1.Text = y
                            End With
                        End With
                    End With

    Leave a comment:


  • Camper
    replied
    I spoted a strange situation today. I have the best price to back and lay to both players displayed on textboxes.

    The first player has the right values on both Back and Lay but I founded a mistake on the second. The Back and lay prices are not the best ones, they show the second best price i don't know why. The same for the avalable amount.

    The code I use is this one:

    Code:
        Sub ShowMprices(ByVal MpriceResp As BFUK.GetMarketPricesResp)
            With MpriceResp
                CheckHeader(.header)
                Print("ErrorCode = " & .errorCode.ToString)
                If .errorCode = BFUK.GetMarketPricesErrorEnum.OK Then
                    With .marketPrices
                        bMstatus.Text = .marketStatus
                        bMarkid.Text = .marketId
                        With .runnerPrices(0)
                            bSelecid.Text = .selectionId
                            With .bestPricesToBack(0)
                                aBodd1.Text = .price
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                bBacka1.Text = y
                            End With
                            With .bestPricesToLay(0)
                                bLay1.Text = .price
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                bLaya1.Text = y
                            End With
                        End With
                        With .runnerPrices(1)
                            bSelectid1.Text = .selectionId
                            With .bestPricesToBack(1)
                                TextBox5.Text = .price
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox3.Text = y
                            End With
                            With .bestPricesToLay(1)
                                TextBox2.Text = .price
                                Dim y As Integer
                                Dim x As Double = .amountAvailable
                                y = Convert.ToInt32(x)
                                TextBox1.Text = y
                            End With
                        End With
                    End With
                Else
                    Print("ShowMprices Error")
                End If
            End With
        End Sub
    I cant spot any error here

    Leave a comment:


  • Camper
    replied
    Solved, I feel idiot now, I logged in at betfair website and change the language to other than English so if .marketname = "Match Odds" couldnt work

    Leave a comment:


  • Camper
    replied
    Suddently my code stoped to work.

    Code:
     Private Sub bMarkets_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bMarkets.Click
            Print("*** Markets ***")
            Dim oMarketsReq As New BFUK.GetAllMarketsReq
            Dim oMarketsResp As BFUK.GetAllMarketsResp
            With oMarketsReq
                .header = oHeaderUK()
                ReDim .eventTypeIds(0) : .eventTypeIds(0) = 2 'For Tennis Matches
                .fromDate = Today
                .toDate = Today.AddDays(1)
            End With
            oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)
            With oMarketsResp
                CheckHeader(.header)
                Print("ErrorCode = " & .errorCode.ToString)
                If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
                    Dim AllMarkets As New UnpackAllMarkets(.marketData)   
                    PopulateTreeView(AllMarkets, tvMarkets)
                    With AllMarkets
                        For i = 0 To .marketData.Length - 1
                            With .marketData(i)
                                If .marketName = "match odds" Then
                                    Print(.marketId & " " & .marketStatus & "  " & .marketName & "  " & .menuPath)
                                End If
                            End With
                        Next
                    End With
                End If
            End With
        End Sub
    I get this on the tLog:
    *** Markets ***
    HeaderCode = OK
    ErrorCode = OK
    It doesn't print .marketid, .marketStatus, .marketName or .menuPath
    I dont recall doing anychange related to this

    Leave a comment:


  • Camper
    replied
    Hi, thanks for the help it worked just fine. I was able to Print only the match odds markets on a texbox by doing this like you said:
    Code:
    With AllMarkets
                        For i = 0 To .marketData.Length - 1
                            With .marketData(i)
                                If .marketName = "Match Odds" Then
                                    Print(.marketId & " " & .marketStatus & "  " & .marketName & "  " & .menuPath)
                                    PopulateTreeView(AllMarkets, tvMarkets)
                                End If
                            End With
                        Next
                    End With
    I want to do another thing, i want to Print only this information, for example:
    I'm getting this:
    103361258 ACTIVE Match Odds \Tennis\Group A\Mercury Insurance Open 2011\First Round Matches\Vesnina v Erakovic
    And i want this:
    103361258 ACTIVE Match Odds \Tennis\Mercury Insurance Open 2011\Vesnina v Erakovic

    Is that possible? By doing this i will get to the match odds far more faster on the treeview, too many clicks the way i have it now.

    Thanks for the help NFLMAN, I'm getting close to what i want
    Last edited by Camper; 02-08-2011, 01:03 AM.

    Leave a comment:


  • NFLMAN
    replied
    Hi Camper,

    I don't use a treeview but you can filter for specific market types like filtering for "match odds" like this:

    Code:
    Dim AllMarkets As New UnpackAllMarkets(oMarketsResp.marketData)
          With AllMarkets
                For i = 0 To .marketData.Length - 1
                     With .marketData(i)
                           If .marketName = "Match Odds" Then
                                  Code for Get Market Prices and placing bet etc.....
                           End if
                     End With
                Next i
          End With
    This will select all singles match odds markets and also any doubles match odds markets. You can filter out the doubles matches too with a bit more code but there are relatively few of these so I don't bother.

    Leave a comment:


  • Camper
    replied
    Hi, i will only use my bot on tennis markets. I was able to do a treeview with only tennis markets and now I'm trying to put it like this:

    Tournament
    • Hour: Player 1 - Player 2: Match Odds


    I read here in this topic about filtering the information but i was unable to do it

    Any idea?

    Leave a comment:


  • Geierkind
    replied
    Originally posted by Geierkind View Post
    Hi,

    This code gives Prices like this:

    MarketId = 4324232
    Runner 1 LPM=
    Back = Lay=
    Runner 2 LPM=
    Back = Lay=

    But I would like to see Prices in the following format:

    MarketID Runner 1 Runner 2 Runner 3 Runner 4 Runner 5
    4324232 [Backodds] [Backodds] [Backodds] [Backodds]

    All those loops are kind of too complicated for me, so I would like to hear some advice how to get this format of Data

    Thanks,

    Timo
    Originally posted by Geierkind View Post

    First Question: How do I modify the code further, so that the Prices function "calls itself" until all Prices are read?

    Second Question: How do I export that big array of all those Prices to Excel the most convenient way?

    I have those problems solved If anyone needs assistance in doing the same thing, just write a PM.

    What about starting another thread, referring to this one where we can publish our solutions for our little problems so if any other guy has the same problem later he doesn't have to scan through all the pages of this thread.

    Regards,

    Timo

    Leave a comment:


  • Camper
    replied
    I've already solved my problems. If anyone has the same problems feel free to ask.

    Leave a comment:


  • Camper
    replied
    Hi again, another problem.

    I was able to open a new form and close the login form by adding this at the end of "Private Sub bLogin_Click":

    Code:
    With oLoginResp
                CheckHeader(.header)
                Print("ErrorCode = " & .errorCode.ToString)
                If .errorCode.ToString = "OK" Then
                    Main.Show()
                    Me.Hide()
                End If
            End With
    The new form appears but when i click to see the events on the textbox i get this error:

    *** Events ***
    HeaderCode = NO_SESSION
    ErrorCode = API_ERROR
    I don't know what I did wrong here.

    Leave a comment:

Working...
X