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 everyone, first I have to say thanks for this thread, very helpful indeed!i

    I'm new to VB but I successfully completed all the steps in this tutorial and now I'm trying to make some changes. I would love to have a form to Login and after that a "main" form with the rest of the bot but for now I'm trying to add a textbox to input the password because i dont feel safe having a program with my password on it, the username i don't really care.

    I failed at doing this, does anyone have an idea to me?

    PS: Sorry for my english.
    Last edited by Camper; 28-07-2011, 07:09 PM.

    Leave a comment:


  • Geierkind
    replied
    Changing format of Prices

    Hi,

    I need some help.

    You remember the Prices-Sub:

    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
    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

    Leave a comment:


  • NFLMAN
    replied
    Thanks BigSprout - that method worked and saved me a lot of extra coding :-)

    Leave a comment:


  • BigSprout
    replied
    Hi NFLMan,

    I had a similar problem and this is how I solved it:

    MyBotId represents the Bot number (Bot1, Bot2,...etc)

    Code:
    Public Sub PlaceMyBets(ByVal MyBotId As Integer)
    
    
    	' the code
    
    	StateCount += 1
    	BetfairExch.placeBetsAsync(oPlaceBetsReq, StateCount + (MyBotId * 10000))
    
    	'if MyBotId = 1 then the number sent is 10,000 + StateCount
    	'if MyBotId = 2 then the number sent is 20,000 + StateCount
    
    end sub
    
    
    
    Private Sub BetFairExCh_PlaceBetsCompleted(ByVal sender As Object, ByVal e As BFExService.placeBetsCompletedEventArgs) Handles BetfairExch.placeBetsCompleted
    
    	Dim MyBotId as Integer= e.UserState \ 10000
    
    	'MyBotId = 1 or 2, dependent on which Bot sent the bet
    	'this can then be used to differentiate between bots
    
    end sub
    I then added this line to "MyTimer", so that StateCount didn't exceed 10,000:

    If StateCount > 9950 then StateCount = 0

    hope this helps

    Leave a comment:


  • NFLMAN
    replied
    Just wanted to ask the best way to track multiple bot actions:

    For example, I have 2 bots running on seperate timers placing bets at various time intervals on different markets and betting criteria.

    Bot 1 places async bets and writes the bet details to a log file. I then use this log file later to provide statistics. This works well as I know all the bets in this log file belong to bot1.

    When I start using bot 2, I want it to write to the same log file but I want to be able to distinguish which bot placed which bet.

    I'm thinking along the lines of passing a parameter containing a botID reference (generated by the timer tick event) through to the PlaceBet sub. I can then link the botID ref to the PlaceBet response's BetID and send this data to the log file.

    Am I going about this in the right manner or is there a smarter way to acheive what I need?

    Leave a comment:


  • Geierkind
    replied
    Originally posted by Mumbles0 View Post
    Optimus,

    If you want your MpricesReq function to cycle continuously through the .marketData() array each time it is called, define a simple index variable to point to the next .marketData() element to be returned:

    Code:
    [COLOR="Gray"][COLOR="Black"]Dim iMarket As Integer  'Index for AllMarkets.marketData array[/COLOR]
    
    Function MpricesReq() As BFUK.GetMarketPricesReq
      Dim oMPReq As New BFUK.GetMarketPricesReq
      With oMPReq
        .header = oHeaderUK()
    [COLOR="Black"]    .marketId = AllMarkets.marketData(iMarket).marketId  'The next marketId in the array
        iMarket += 1  'Increment the index
        If iMarket = AllMarkets.marketData.Length Then iMarket = 0 'Reset the index when end of array is reached[/COLOR]
      End With
      Return oMPReq
    End Function[/COLOR]
    When the end of the [FONT="Courier New"marketData[/FONT] array is reached, the index is reset back to the start.
    Hi, I have 2 problems regarding Optimus Post, perhaps you, or any other kind person could give me some advice.

    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?

    Leave a comment:


  • McTash
    replied
    Have a look here

    https://docs.developer.betfair.com/b...MC.00008338-MC

    The GetInPlayMarkets should give you what you want.

    That link takes you to the API docs. They are very useful if you want see what calls are available for each service etc.

    Leave a comment:


  • Sports API + VB .Net
    replied
    In-Play Markets

    I want to make a tab INPLAY in which there should be a treeview having all the inplay events like

    Cricket
    === Ind vs Pak
    Race
    === Newt
    Soccer
    === Manutd vs Fulham

    i already have designed a treeview having all the markets (active , inplay) as betfair treeview but now i want this one....

    can some one help me out which service of api allow me to retrieve only inplay markets i will be waiting for your reply

    Leave a comment:


  • Geierkind
    replied
    Originally posted by Mumbles0 View Post
    Optimus,

    The market data returned from the getAllMarkets call is unpacked into the .marketData() array within the AllMarkets object, so you don’t need a separate array. All you have to do is put the AllMarkets object variable outside the sub:



    When the end of the .marketData array is reached, the index is reset back to the start.
    Well, I'm not the most established person around, but tomorrow I will try to get this thing (I have the exact same problem as Optimus as it seems) running Would be really great. So thanks for your big help here! You are kind of a savior

    Leave a comment:


  • davecon
    replied
    Originally posted by Optimus Prime Number
    Hi OPN
    You seem to be trying to run before you can crawl here my friend - No offence
    Thanks to Mumbles who has shared with us all his vast experience regarding the API and programming VB in general,
    not to mention the vast amount of time sacrificed to assist us all whenever possible, for which, I myself and sure countless others are truly grateful ( Thanks mumbles mate )
    However, he is not employed by us - We need to learn ourselves based on the guys free gift to us all
    Speaking for myself I had virtually zilch programming knowledge except for playing around with VB6 years ago and was completely clueless how to access the API before I came upon this thread
    Yet in just a couple of short Months I have built myself a bot that can do things that I could have only dreamed about and have astounded myself at what I have achieved and am still learning every single Day and find the journey totally fascinating ( Thanks Mumbles mate )
    I soon realized that I had to grasp a better understanding of all the basics in VB before I started digging into the advanced stuff in this great tutorial (btw Arrays still do my head in!!)
    You can purchase many Books on the subject from Amazon for next to nothing (I got a 2008 one for a penny! )
    Or alternatively you can download all the latest books for free (Not sure about the legality and please do so at your own risk)
    http://www.free-ebooks-download.org/...basic-2010.php
    There are loads of ways to achieve what you are attempting although just quite not sure what that is lol
    VB has a host of just basic controls that you could use for your purpose until you advance at your own pace such as list boxes, combos and the like
    Soon you will find yourself in a very short time building some astounding applications from this brilliant thread
    I wish you all the greatest success in your own journey and hope it will be as fruitful as mine
    Dave
    ps Did I fail to mention
    (Thanks Mumbles mate )

    Leave a comment:


  • Mumbles0
    replied
    Optimus,

    The market data returned from the getAllMarkets call is unpacked into the .marketData() array within the AllMarkets object, so you don’t need a separate array. All you have to do is put the AllMarkets object variable outside the sub:

    Code:
    [COLOR="Gray"][COLOR="Black"]Dim AllMarkets As UnpackAllMarkets[/COLOR]
    
    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
        .fromDate = Today
        .toDate = Now.AddDays(1)
      End With
      oMarketsResp = BetFairUK.getAllMarkets(oMarketsReq)
      With oMarketsResp
        CheckHeader(.header)
        Print("ErrorCode = " & .errorCode.ToString)
        If .errorCode = BFUK.GetAllMarketsErrorEnum.OK Then
          [COLOR="Black"]AllMarkets = New UnpackAllMarkets(.marketData)  'Unpack the market data[/COLOR]
        End If
      End With
    End Sub[/COLOR]
    If you want your MpricesReq function to cycle continuously through the .marketData() array each time it is called, define a simple index variable to point to the next .marketData() element to be returned:

    Code:
    [COLOR="Gray"][COLOR="Black"]Dim iMarket As Integer  'Index for AllMarkets.marketData array[/COLOR]
    
    Function MpricesReq() As BFUK.GetMarketPricesReq
      Dim oMPReq As New BFUK.GetMarketPricesReq
      With oMPReq
        .header = oHeaderUK()
    [COLOR="Black"]    .marketId = AllMarkets.marketData(iMarket).marketId  'The next marketId in the array
        iMarket += 1  'Increment the index
        If iMarket = AllMarkets.marketData.Length Then iMarket = 0 'Reset the index when end of array is reached[/COLOR]
      End With
      Return oMPReq
    End Function[/COLOR]
    When the end of the .marketData array is reached, the index is reset back to the start.

    Leave a comment:


  • NFLMAN
    replied
    Originally posted by antonello273 View Post
    Good day to all, i say because how can i download the market of soccer?
    I would suggest starting on page 1 of this thread and posting here if and when you get stuck. If you follow all the steps in sequence you will discover how to get the soccer markets.

    Leave a comment:


  • antonello273
    replied
    Market Soccer

    Good day to all, i say because how can i download the market of soccer?

    Leave a comment:


  • BigSprout
    replied
    Dave,
    thanks for that, I certainly will have a play with it now to learn all its functions,

    cheers Les

    Leave a comment:


  • davecon
    replied
    Hi Granted and BigSprout

    The Mouse Right Click Function(Or Left Click if you are left handed) is reserved mainly for use with the Context Menu on nearly every application (The Short Cut Menu) I would be lost without it
    You can set a ContextMenuStrip to the Main Form Itself And/Or All each seperate controls in VB as many as desired

    I assume you are not using any at the moment so you could in fact just Use the MouseDown Event for your Button (Or most controls) as so:

    '** for a TestButton "btnTestButton" **

    Private Sub btnTestButton_MouseDown _
    (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles btnTestButton.MouseDown

    '///// e.Button = Windows.Forms.MouseButtons \\\\\

    If e.Button = MouseButtons.Right Then

    Print("Right Button Pressed")
    'Put your code here

    ElseIf e.Button = MouseButtons.Left Then
    Print("Left Button Pressed")
    'Put your code here

    ElseIf e.Button = MouseButtons.Middle Then
    Print("Middle Buttton Pressed")
    'Put your code here

    End If 'e.Button

    'There is also
    'e.Button = MouseButtons.XButton1
    'e.Button = MouseButtons.XButton2
    'e.Button = MouseButtons.None

    End Sub 'btnTestButton_MouseDown

    However the best way in my opinion would be to make use of the ContextMenuStrip to achieve just a Right Click if Required (and a host of other commands) while at the same time you can see how it works

    In the Toolbox look for Menus & Toolbars and Drag or Double Click a "ContextMenuStrip" Control onto the Form
    You will see it at the Bottom (With Timers etc) with default name "ContextMenuStrip1"

    (Left Click on the Control and you will see at the Top of your Form the Menu with a "Type Here" thingy - This is where you would put your Items in a Drop Down Menu and set each one of them like any other Control such as the Click Event as Desired
    You can access this at any time to add or modify commands by just left clicking the Control (Dont use the Properties at first its far too complex)

    However ignore the MenuItems for now and just Re- Name your ContextMenuStrip1 in the Properties Window as you would any other Control (If desired) I have named it cmBtnTestButton

    Then once Re-named Double Click the Control at the Bottom(Not the Menu Items) and it will open up the Controls "Opening" Event

    Private Sub cmBtnTestButton_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cmBtnTestButton.Opening

    cmBtnTestButton.Visible = False 'If you dont want to see anything else and just do a Right Click command

    Print("Mouse Right Click")
    'Put Code Here

    End Sub 'cmBtnTestButton Opening

    Finally you need to set your ContextMenuStrip to the Desired Control in this case our TestButton - So Click on your TestButton and in the Properties Window you will see the Property "ContextMenuStrip" Set to None
    Just Click on this and you will see your cmStrip Listed And Click to set it to the Control

    Now when you Right Click on your Button it will act as you desire (hopefully)
    And of Course assuming you have cancelled out the MouseDown Code

    The ContextMenuStrip is a great tool to play around with and will only enhance your Program

    Hope this helps Guys
    Cheers
    Dave

    Leave a comment:

Working...
X