Using VB2008 to acccess the Betfair API: A tutorial

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

  • Monairda
    replied
    Thank you very much BigSprout

    I'll try what you mention.

    Cheers

    Leave a comment:


  • BigSprout
    replied
    Moniarda,

    I think it is a datagridview that is being used (or you can use one the same way), except buttons have been used in some columns

    If you put a "DGV" on a form:
    click on it and select "Colums - collections"
    an "Edit Colums" window pops up

    click "Add" - Add Column window displayed with:
    Name: Column1
    Type: DataGridViewTextBoxColumn
    HeaderText: Column1

    Look at - Type: DataGridViewTextBoxColumn

    to the right is a down arrow for a drop down box display
    Click on the arrow

    there is now a list of selections including "DataGridViewButtonColumn"
    You can also use this box to add "checkbox, combobox....etc" to your datagridview


    so for the runner names you would use the default DataGridViewTextBoxColumn

    then select dropdown box and select "DataGridViewButtonColumn" for your Back/SP/Lay information
    this will now display buttons in the selected columns instead of text boxes

    cheers

    Leave a comment:


  • Monairda
    replied
    How to create a user control to show the datas

    Good night

    I would like to advise me how to start to make a panel for the data request to the API with a custom user control. An example might start with something like the bot written in C # (http://forum.bdp.betfair.com/attachm...1&d=1256657197)

    Can you help me create a custom user control that contains the information Mumbles has taught us to ask the API and stop using the Gridview control?

    Thank you very much!!

    Leave a comment:


  • bamboozled
    replied
    Spotted the problem

    Duh - I am concatenating the counter to the selectionid which is obviously giving me mismatched selectionids. Stupid!

    Leave a comment:


  • bamboozled
    replied
    selectionid problem

    Fantastic tutorial for which many thanks. I modified showmprices slightly
    Code:
    Print("Runner " & i + 1 & .selectionId & "  LPM = " & .lastPriceMatched)
    The selectionids which shows here are different from the selectionids returned in getrunners for the same market. Why is this and how can I be be sure I've linked correct price with runner?

    Leave a comment:


  • vrps1991
    replied
    Hi people.
    I would like how can i modified it:

    Code:
    Module Unpack
        Class MarketDataType           'For getAllMarkets data
            Public marketId As Integer
            Public marketName As String
            Public marketType As String
            Public marketStatus As String
            Public eventDate As DateTime
            Public menuPath As String
            Public eventHeirachy As String
            Public betDelay As Integer
            Public exchangeId As Integer
            Public countryCode As String
            Public lastRefresh As DateTime
            Public noOfRunners As Integer
            Public noOfWinners As Integer
            Public totalAmountMatched As Double
            Public bspMarket As Boolean
            Public turningInPlay As Boolean
        End Class
    
        Class UnpackAllMarkets       'For getAllMArkets
            Public marketData As MarketDataType() = {}  'The returned array of market data
            Private Const BaseDate As DateTime = #1/1/1970#
            Private Const ColonCode = "&%^@"  'The substitute code for "\:"
    
            Sub New(ByVal MarketString As String)
                Dim n As Integer, Mdata, Field As String()
    
                Mdata = MarketString.Replace("\:", ColonCode).Split(":") 'Get array of Market substrings
                n = UBound(Mdata) - 1
                ReDim marketData(n)
    
                For i = 0 To n
                    Field = Mdata(i + 1).Replace("\~", "-").Split("~") 'Get array of data fields
                    marketData(i) = New MarketDataType
                    With marketData(i)
                        .marketId = Field(0)   'Load the array items
                        .marketName = Field(1).Replace(ColonCode, ":")
                        .marketType = Field(2)
                        .marketStatus = Field(3)
                        .eventDate = BaseDate.AddMilliseconds(Field(4))
                        .menuPath = Field(5).Replace(ColonCode, ":")
                        .eventHeirachy = Field(6)
                        .betDelay = Field(7)
                        .exchangeId = Field(8)
                        .countryCode = Field(9)
                        .lastRefresh = BaseDate.AddMilliseconds(Field(10))
                        .noOfRunners = Field(11)
                        .noOfWinners = Field(12)
                        .totalAmountMatched = Val(Field(13))
                        .bspMarket = (Field(14) = "Y")
                        .turningInPlay = (Field(15) = "Y")
    
                    End With
                Next
            End Sub
        End Class
    End Module
    to obtain:

    Market Info;
    Selections (First runner);
    Winner ;
    Back Prices
    and
    Profit/Loss

    ?

    Someone can help me?

    Leave a comment:


  • 1nner
    replied
    Originally posted by Mumbles0 View Post
    1nner,

    The API Guide mentions that a session will expire after about 20 minutes of inactivity. For as long as I have been using the API (about 3 years) this does not seem to be the case. From my experience, inactive session tokens persist a lot longer than 20 minutes. They usually remain current for a day or two. I don’t know why this is so.

    However, this does not unduly worry me (in fact I find it convenient). Saves me having to log in all the time.

    Note that all communications (which will contain the session token) between your computer and the API are encrypted. This level of security should be adequate for most purposes.

    If you are using a computer that can be accessed by others, and you don’t like the idea of having an active session token hanging around, then it’s a good idea to log out rather than leave your session idle.
    Thanks for that - as long as they do expire eventually I'm not too worried.

    Cheers

    Leave a comment:


  • Sports API + VB .Net
    replied
    Hi Mumble regarding this post my question is that , through this tutorial i have learned to call the api service like "getmarket" through button but if requirment is that when using treeview we double click on anymarket so how will we assign some values of button "bRunners" like .marketstatus or .name to any lable on our project will we make globle variable or how ? please sorry if i have again bother you.........
    i want to use some values from different api calls to my project like on banner i want to show selected marketstatus, marketname, numberofrunners, no.ofwinners etc etc how will this task done please help me out.......... i have no one but only you to ask question ... please reply

    Leave a comment:


  • Sports API + VB .Net
    replied
    Mumble Thanks for your kind reply but let me tell you that my intention was'nt to bother you but to understand the basic of how to design a bot for my use because i am not a expert developer but with your help now i am able to accomplish my pending tasks plus in future if i stuck somewhere in programming a bot i will again ask for your help i hope you will not mind this..... Thanks Again Brother.

    Leave a comment:


  • Mumbles0
    replied
    Reply to Sports API + VB. Net

    App to show runners & prices

    I have said this before - I am not going to write your application for you. But you can proceed like this:

    The grid to use is a DataGridView, which you will find in the ToolBox. You place this on your form and set up columns for runner name, selectionId, best back prices, and best lay prices. You must learn how to do this.

    When you click on a market in your TreeView, the AfterSelect event fires. From this event handler you call getMarket to return the list of runners (see Step 12). You load a column of the DataGridView with the list of runners, and put the selectionIds in another column.

    From the Tick event of a timer you can call getMarketPricesCompressed to get the best back and lay prices (see Step 14). You then update the appropriate columns in the grid with these prices.

    Cricket Group C

    There is a problem with getAllMarkets, affecting Tennis, Golf, Cricket and Rugby Union. An unwanted GROUP heading is given in the menuPath. You can eliminate this by modifying the PopulateTreeView sub as shown here:

    Code:
    [COLOR="Gray"]Friend Sub PopulateTreeView(ByVal AllMarkets As UnpackAllMarkets, ByVal TreeView As TreeView)
      Dim Ids, Names As String(), Nodes As TreeNodeCollection
    
      TreeView.Nodes.Clear()             'Start afresh
      With AllMarkets
        For i = 0 To .marketData.Length - 1   'For each market
          With .marketData(i)
            Ids = .eventHeirachy.Split("/")  'Array of Ids
            Names = .menuPath.Split("\")   'Array of names
    
    [COLOR="Black"]        If Ids.Length = Names.Length Then  'Workaround to remove "Group" names in tennis, golf, cricket & rugby union
              Dim n = UBound(Names)
              For j = 3 To n
                Names(j - 1) = Names(j)
              Next
              ReDim Preserve Names(n - 1)
            End If[/COLOR]
    
            Nodes = TreeView.Nodes      'Initial collection of child nodes
            For j = 1 To UBound(Ids)  'For each event list item
              If Not Nodes.ContainsKey(Ids(j)) Then
                Dim Node As New TreeNode   'Add a new node if it doesn't exist
                Node.Text = If(j <= UBound(Names), Names(j), .marketName)
                Node.Name = Ids(j)  'This is the key
                Nodes.Add(Node)
              End If
              Nodes = Nodes(Ids(j)).Nodes  'Next level down
            Next
          End With
        Next
      End With
    
    End Sub[/COLOR]

    Leave a comment:


  • Mumbles0
    replied
    Session timeout

    1nner,

    The API Guide mentions that a session will expire after about 20 minutes of inactivity. For as long as I have been using the API (about 3 years) this does not seem to be the case. From my experience, inactive session tokens persist a lot longer than 20 minutes. They usually remain current for a day or two. I don’t know why this is so.

    However, this does not unduly worry me (in fact I find it convenient). Saves me having to log in all the time.

    Note that all communications (which will contain the session token) between your computer and the API are encrypted. This level of security should be adequate for most purposes.

    If you are using a computer that can be accessed by others, and you don’t like the idea of having an active session token hanging around, then it’s a good idea to log out rather than leave your session idle.

    Leave a comment:


  • Sports API + VB .Net
    replied
    Hi Mumble thanks for help but i want little more help , i am using the same piece of code on my tester and populate treeview function in module unpack but the result is not as same as i expected this is what i am getting:
    1st of all my treeview loads like:
    +Soccer
    +Tennis
    +Cricket
    +HorseRacing
    when i click on cricket it shows like :
    -Cricket
    +Group C
    +Group C
    +Group C
    when i click on Group C then:
    -Cricket
    -Group C
    +ICC Cricket World Cup 2011 (some have childs)
    ICC Cricket World Cup 2011 (some dont have childs)
    +ICC Cricket World Cup 2011
    +ICC Cricket World Cup 2011
    ICC Cricket World Cup 2011
    ICC Cricket World Cup 2011
    +ICC Cricket World Cup 2011
    When i click on 1st +icc cricketworldcup 2011 it shows
    +fixture 02March
    When i click on 2nd +icc cricketworldcup 2011 it shows
    +fixture 03March
    why this is happening you have mention in your help that it is prefereble to use menu name instead of ids but when i run the for loop in populate treeview function in module unpack you had mention then i did'nt get any id for further getmarkets and other services please help me out

    Leave a comment:


  • Sports API + VB .Net
    replied
    Thanks mumble everything is fine on befairtester form but where to place this lines so that everytime when i double click on a market from treeviewer it display selectionids and their prices (as happens on betfair website)

    With MpriceResp.marketPrices
    For i = 0 To .runnerPrices.Length - 1 'Look up the runnerPrices array
    With .runnerPrices(i)
    If .selectionId = 3013615 Then 'selectionId match

    'The price data for Rio Royale is available here

    Exit For
    End If
    End With
    Next
    End With

    one more thing i want to ask how to make treeview as same as betfair means where and when to fire getmarkets and other required services and what will be a piece of code to display data from respond array to grid (and also suggest me which grid of vb2010 is more efficient) i want to design a bot as same as betfair main website . please dont ignore i will be waiting for your kind reply Mumble.......

    Leave a comment:


  • 1nner
    replied
    Session not expiring

    Hi,

    Thanks for the great tutorial, it's extremely helpful. One thing I noticed when loading the saved session ID is that it continues to successfully work (ie I don't have to re login) for many hours (10+) after I've been away from the computer. I thought it was meant to time out after 20 minutes for security. Do you have any idea why this might be happening?

    Regards,

    Andrew
    Last edited by 1nner; 01-03-2011, 03:40 PM.

    Leave a comment:


  • BigSprout
    replied
    Personally I find this quite dumb, but there is a better way using buffered graphics.
    You're right, with a nice break and starting afresh, it kind of all fell into place - I do not know what I was doing wrong in not getting the graphics to display on another form, but after removing the parameter "dim g As System.Windows.Forms.PaintEventArgs"...etc it still all worked.

    Moved on to now displaying graphs of the price changes and updating every second.

    Eagerly awaiting future steps in displaying graphics to see how far off track I have gone.

    cheers Les

    Leave a comment:

Working...
X