Placing bet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tippete
    Junior Member
    • Mar 2016
    • 42

    #1

    Placing bet

    I just want to place a simple straight bet using these parameters . what else do i need for the bet to fire?


    Public Class PlaceOrdersRequest
    Public jsonrpc As String = "2.0"
    Public method As String = "SportsAPING/v1.0/placeOrders"
    Public params As New PlaceOrdersParams
    Public PlaceBet(side, size, price)
    Dim side As String = "BACK"
    Dim size As Double = "2"
    Dim price As Double = "3"
    End Class
    Public Class PlaceOrdersParams
    Public marketId As Double = 1.178055765

    Public instructions As New List(Of PlaceInstructions)
    End Class

    Public Class PlaceInstructions
    Public selectionId = 37187232
    Public handicap As Double = 0
    Public side As String = "BACK"
    Public orderType As String = "LIMIT"
    Public limitOrder As String = "LimitOrder"
    End Class

    Public Class LimitOrder
    Public size As Double = "2"
    Public price As Double = "30"
    Public persistenceType As String = "LAPSE"
    Public id = 1
    End Class

    End Class
  • tippete
    Junior Member
    • Mar 2016
    • 42

    #2
    So is this a "betting" forum . where nobody knows how to place a bet, or are people not willing to share secrets?

    Comment

    • jabe
      Senior Member
      • Dec 2014
      • 705

      #3
      Do you have a generalised routine that will make the call?

      Comment

      • tippete
        Junior Member
        • Mar 2016
        • 42

        #4
        Thanks for the reply Jabe. What do you mean by the call? I have a routine to login. then get the markets , select a runner . I have got outputs for the selection.
        I have a routine at the moment that will place a bet but i have to click on the selections name in a datagrid to bet. My idea is to take the info and make an automatic bet .I have the selection id . market id, runners name, marketStartTime and course. Just want a simple automatic bet. Dont need to know if the bets taken or anyother info.

        Comment

        • jabe
          Senior Member
          • Dec 2014
          • 705

          #5
          Okay, I think I've got that. Sounds like you've got the basics in place, so it sounds like you need a timer that will periodically check for the required condition(s) to place your bet. VB.Net provides timers, but it's worth noting that what it calls a second is a bit off. But that shouldn't be a problem.


          Let me know if this is helpful, and why not if it isn't.

          Comment

          • tippete
            Junior Member
            • Mar 2016
            • 42

            #6
            There is already a timer used and it checks the conditions when the race is due off and gives me the selections. Its joining these selections and placing the bets i am struggling with.

            Comment

            • jabe
              Senior Member
              • Dec 2014
              • 705

              #7
              (In case you haven't read this yet, I missed the part about placing multiple bets in a single call, so I've gone through that in the next post)


              Got it. This sounds like a program structure matter. I wrote my first computer program about 43 years ago and there are still situations in which a flow chart or structure chart is helpful. It might be worth your while doing some research into that and drawing on paper how the subroutines relate to each other. I worked in IT for over 20 years. I was never trained in object oriented programming and I really shouldn't have started with such a complicated program, but so far so good. I've learnt something from most programs I've written, even if it's only that there was probably a better or simpler way of doing part (or all) of it.

              It looks like you are coding in Visual Basic.Net, which is what mine is written in.

              If I come across a feature I've never used before, I often write a small test program so I can play around with the feature and get a good idea of what it does and how I should use it. I can go back to these programs and try other changes whenever it might help (or when I've forgotten it all).


              I aimed to make my program as automated as possible. I can interact with it in these ways:

              1. I can choose which events it bets on and what the basic bet amount will be. The program will only bet on events I've chosen if the conditions I've coded are satisfied.

              2. I can check on the current state of all events (before, during, after). If your event is football, you'll want updates during each game.

              The basic structure is as follows:

              1. The log-in process.

              2. Initialisation.
              Set any global variables (I'm aware that global variables may be frowned upon by OOP folk).
              Make all the basic calls to the API and store essential data for the day's events.
              Populate relevant screen displays.
              Etc!

              (I should point out here that my program also saves a lot of the day's data to external files, along with the current state of events. This is to make restarting the program quicker (no calls to the API) and to help remember chosen events and their state. This is an alternative initialisation and would be processed if files containing data saved for the current date exists. This may be unnecessary for most purposes)

              3. Main processing.
              This is where the timer is started.
              All the day's events are stored in a collection. The items are sequenced by start time. The start time will be compared with the current time. The nearer to the start time it gets, the more frequently they are checked. At some point the program needs to decide whether the conditions indicate that a bet wil be made.

              4. Calling the API.
              My program has two subroutines that call the API. They are similar, except (IIRC) for the end points. One is for account related calls and the other is for bet related calls.
              I also have subroutines for each API call (listCountry, listCompetition, listMarketBook, etc (and 3 or 4 for the assorted cancelOrders ones)), and these all call either the routine that makes the call for bet related calls or the subroutine that makes the account related calls.
              From the timer, there will be a call to a subroutine for the particular API call. It will contain the minimum amount of information - at this point it's probably easier to show you some code:

              Example:

              Call to place an order - note that this starts off the placing of the bet and the variable rec ends up with the information returned from the call:

              Code:
              Dim rec = API_placeOrders(i.marketId, i.selectionId, i.side, i.size, i.price)
              This is the call-specific code that adds the data passed from the previous call into a JSON string ready for the actual call to the API. The line creating the variable intext could be removed and the data that makes up intext could be coded into the parameter of the call to API_sendBetReq:

              Code:
              Public Function API_placeOrders(marketId, selectionId, side, size, price)
              Dim intext = """marketId"":""" & marketId & """,""async"": true,""instructions"":[{""selectionId"": """ & selectionId & """,""handicap"": ""0"",""side"": """ & side & """,""orderType"": ""LIMIT"",""limitOrder"":{""size"":" & size & ",""price"":" & price & ",""persistenceType"": ""LAPSE""}}]"
              Return API_sendBetReq("placeOrders", intext)
              End Function
              With the call to API_sendBetReq containing the changeable data to be sent to Betfair, API_sendBetReq can just add the standard bits and pieces to it and prepare and make the call.

              Code:
              Private Function API_sendAccReq(ByVal method As String)
              The method string received is added into the JSON string this way:

              Code:
              Dim postData As String = "{""jsonrpc"": ""2.0"", ""method"": ""AccountAPING/v1.0/" & method & """}"
              As you can see, by building up the JSON string this way, you won't need to have separate variables for words such as LAPSE, LIMIT, and Limit Order which might be the same every time in your program, unless your program will make other types of bets.


              I hope this answers some of the questions you've been having. I usually look on here every day so I'll watch out for your replies.
              Last edited by jabe; 24-01-2021, 07:43 PM.

              Comment

              • jabe
                Senior Member
                • Dec 2014
                • 705

                #8
                Originally posted by tippete View Post
                There is already a timer used and it checks the conditions when the race is due off and gives me the selections. Its joining these selections and placing the bets i am struggling with.
                Apologies - just noticed something I missed.

                So you have multiple selections. I reckon placing a handful of bets separately wouldn't delay things too much, by let me work out how you place multiples bets in a single call.

                If you look at the layout of a JSON string, you'll find that you can list an array within square brackets. Often this array only has one item. According to the documentation, instructions is a list of PlaceInstruction items. In the code above from my program, the instructions parameter looked like this:

                ""instructions"":[{""selectionId"": """ & selectionId & """,""handicap"": ""0"",""side"": """ & side & """,""orderType"": ""LIMIT"",""limitOrder"":{""size"":" & size & ",""price"":" & price & ",""persistenceType"": ""LAPSE""}}]

                For now, I'll simplify things and say

                Bet1 = {""selectionId"": """ & selectionId & """,""handicap"": ""0"",""side"": """ & side & """,""orderType"": ""LIMIT"",""limitOrder"":{""size"":" & size & ",""price"":" & price & ",""persistenceType"": ""LAPSE""}}

                So ""instructions"":[Bet1]

                If you want multiple bets, you can have Bet2 = {""selectionId"": """ & selectionId2 & """,""handicap"": ""0"",""side"": """ & side2 & """,""orderType"": ""LIMIT"",""limitOrder"":{""size"":" & size2 & ",""price"":" & price2 & ",""persistenceType"": ""LAPSE""}}
                Etc.

                For multiple bets in a single call, it's a case of adding more bet details to the instructions list, like this:

                ""instructions"":[Bet1, Bet2, Bet3, ....]

                until you have as many as you want.

                Sorry for missing that earlier.

                Comment

                • tippete
                  Junior Member
                  • Mar 2016
                  • 42

                  #9
                  Thanks for the comprehensive reply Jabe, much appreciated. It is definetely a program structure matter. My programming is very poor. I have been into horseracing over 40 years and computers for over 30. I tend to get away with excel for everything i do , but have dabbled in basic dos in the early days but didnt get far. My enthusiasm was boosted about 5 years ago when "Programming for Betfair " landed in my hands . I completed most of the tasks i believe by following the book and copying the code. About six months back i was surfing internet and found a program i liked but i thought i could get the presentation to suit my needs by adapting the betfair program to do the tasks how i wanted them. Anyway when i got the output i wanted and some checking i realised it was not far from automated.

                  I have copied the runnerForm and usercontrol from "Programming for Betfair but stripped it down to the bare minimum. So the program sorts the selections and i have to click on the datagrid , which opens a runnerForm and backs the horse. The following code is used to open the runnerForm and transfer the details.

                  Private Sub DataGridView1_CellContentClick(sender As Object,
                  e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

                  If e.ColumnIndex = 6 Then

                  Dim runnerForm As New RunnerForm(DataGridView1.Item("runnerName", e.RowIndex).Value _
                  & " - " & DataGridView1.Item("marketStartTime", e.RowIndex).Value & " " &
                  DataGridView1.Item("course", e.RowIndex).Value,
                  DataGridView1.Item("marketId", e.RowIndex).Value,
                  DataGridView1.Item("selectionId", e.RowIndex).Value)


                  runnerFormDictionary.Add(DataGridView1.Item("selec tionId", e.RowIndex).Value,
                  runnerForm)
                  End If

                  End Sub


                  I thought i might get away with something simple like below to replace this code but i am just working on trial and error not really understanding whats going on

                  .'Public Sub TextBox16_TextChanged(sender As Object, e As EventArgs) Handles TextBox16.TextChanged

                  ' RunnerForm.

                  ' Dim runnerName As String = TextBox11.Text
                  ' Dim marketStartTime As String = TextBox12.Text
                  ' Dim course As String = TextBox13.Text
                  ' Dim marketId As String = TextBox14.Text
                  ' Dim selectionId As Integer = TextBox15.Text

                  ' runnerFormDictionary.(selectionId" = TextBox15.Text runnerForm)

                  'End Sub

                  Its very complex to me with the runnerform, sportsapi request and usercontrol.
                  If theres no way round this then start a fresh and keep it simple.

                  Think tomorrow i will do what you suggest and make a new program with just basic login and manually feed data into 5 textboxes
                  with a runners details for start time, runners name, selection id, marketID and Course.
                  See where i can get . I will need lots of help!!!!

                  Regards.

                  Comment

                  • tippete
                    Junior Member
                    • Mar 2016
                    • 42

                    #10
                    Sorry Jabe . Seems some confusion there . I only have one selection per race

                    Comment

                    • jabe
                      Senior Member
                      • Dec 2014
                      • 705

                      #11
                      Originally posted by tippete View Post
                      Sorry Jabe . Seems some confusion there . I only have one selection per race
                      No problem. It was the bit where you mentioned joining the selections.

                      Comment

                      • jabe
                        Senior Member
                        • Dec 2014
                        • 705

                        #12
                        Originally posted by tippete View Post
                        ......

                        Its very complex to me with the runnerform, sportsapi request and usercontrol.
                        If theres no way round this then start a fresh and keep it simple.

                        Think tomorrow i will do what you suggest and make a new program with just basic login and manually feed data into 5 textboxes
                        with a runners details for start time, runners name, selection id, marketID and Course.
                        See where i can get . I will need lots of help!!!!

                        Regards.
                        Before you do start a new program, let's review things.

                        1. Your program makes a list of possible selections for each race and puts them in a grid display.

                        2. You choose one, click it, and a bet is made.

                        That sounds like it's nearly finished to me. All you need to do now is let the program decide which horse to choose.

                        You choose one, so you know why you choose it. We should be able to work out how to get the program to make that decision.

                        Comment

                        • tippete
                          Junior Member
                          • Mar 2016
                          • 42

                          #13
                          The program does chose the one to back. It just cant press the datagrid cell that contains the horses name.

                          Comment

                          • jabe
                            Senior Member
                            • Dec 2014
                            • 705

                            #14
                            Originally posted by tippete View Post
                            The program does chose the one to back. It just cant press the datagrid cell that contains the horses name.
                            Well, in that case, when it's decided which horse, it needs to pass the details of that horse to the bet subroutine. It can still display on the datagrid. In fact, I think the program probably can press the cell, but you don't need it to. I'm pretty sure there are ways to trigger things like click and double-click and other such actions without them really being done. Been a while since I tried it though.

                            Comment

                            • tippete
                              Junior Member
                              • Mar 2016
                              • 42

                              #15
                              Thats what i was hoping but dammed if i'm clever enough

                              Comment

                              Working...
                              X