Two Errors Placing Bet with Windows Powershell

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AutomatesXYZ
    Junior Member
    • Apr 2016
    • 3

    #1

    Two Errors Placing Bet with Windows Powershell

    Hi,
    I bought a kindle book that teaches how to make a betfair bot. I'm half way through and really unimpressed at all the spelling mistakes and code errors, but nevertheless I'd like to get it working if I can.

    It uses Windows Powershell and I'm running into two errors when trying to place a bet.

    1. The [0] index in
    Code:
    $selectionId = $getmarketbook.result.runners[0].selectionId
    returns the 2nd result, [1] returns the 1st result and [2] returns the 3rd result.

    2. When I run $bet I get error
    Code:
    jsonrpc error
    ------- -----
    2.0     @{code=-32602; message=DSC-0018}
    Code:
    #############################
    #Places a Back Bet we pass the function to  the following variables $selectionId,$Odds,$marketID,$stake
    #############################
    
    Function placebet {
    $method = "SportsAPING/v1.0/placeOrders"
    $postdata = [ORDERED]@{"jsonrpc" = "2.0";
    "method" = $method
    "params" = @{"marketIds" = @($marketID);"instructions"=[object[]][ORDERED]@{"selectionId" = [int]$selectionId;"side" = "BACK";"orderType" = "LIMIT"; "limitOrder" = [ORDERED]@{"size"=$stake;"price"=$Odds;"persistenceType"="LAPSE";}
    }}
    }
    $postdata = $postdata | ConvertTo-Json -depth 7
    
    $bet = invoke-webrequest -uri https://api.betfair.com/exchange/betting/json-rpc/v1 -Method Post -Headers @{"X-Application"="XXXXXXX";"X-Authentication"=$sessiontoken} -ContentType "application/json" -body $postdata 
    $bet | convertfrom-json
    }
    
    #############################
    #MAIN CODE SECTION
    #############################
    
    $cert = get-cert
    $RET = login $cert
    $sessiontoken = $RET.sessiontoken
    $stake = get-account
    $races = get-marketcatalogue
    $UKracearray = @()
    
    foreach($race in $races.result)
    {If ($race.event.countrycode -eq "GB")
    {$UKracearray += $race}
    }
    
    $marketID = $UKracearray[0].marketID
    
    $getmarketbook = get-marketbook $marketID
    
    $getmarketbook.result.runners | sort lastPriceTraded
    
    $selectionId = $getmarketbook.result.runners[0].selectionId
    $Odds = $getmarketbook.result.runners[0].lastPriceTraded
    
    $bet = placebet $selectionId,$Odds,$marketID,$stake

    I can post more code if it's needed.

    Any idea where I'm going wrong?
  • Lopiner
    Junior Member
    • Feb 2009
    • 117

    #2
    Hi AUTOMATESXYZ, and welcome to the forum

    When you say you get the 2nd result when using the 0 index are you comparing it to the site or are you checking the runners array and seeing it in the 2nd place?

    I don't know Power Shell but it seems that you are sorting the runners array by lastPriceTraded. That would explain a different order from the API original response and the site.

    $getmarketbook.result.runners | sort lastPriceTraded

    For the bet placement error are you staking all your funds? Try to stake a little bit less than all the funds just to make sure you are not exceeding the maximum liability and make sure your stake is over the minimum 2€/2£/2$. Also round the stake to two decimal places.

    In my opinion you would be much better off with the VB.Net example available here on the site (or converting the C# example of the sample code). Syntax is very similar and a lot of people are developing for .net so you would get a lot of support and sample code from the users of the forum.

    Edit, don't forget that this can be 0 $Odds = $getmarketbook.result.runners[0].lastPriceTraded if no odds were traded for that runner.
    Last edited by Lopiner; 19-04-2016, 09:09 AM.
    fooledbyabet.com

    Comment

    • AutomatesXYZ
      Junior Member
      • Apr 2016
      • 3

      #3
      Thanks for the quick reply.

      I've bought another book, that looks more professional and it is coded in VB, so I'll try that next, but I've worked half way through this so I really wanted to get it working. I think it's something simple that is causing the error.

      When the script runs I see the list of runners in the next race and they are sorted in order of odds, from the lowest first, but when I then run $selectionId = $getmarketbook.result.runners[0].selectionId it returns the second item in that list of runners, so the second favourite, not the 1st, which is what I wanted.

      The script is designed to stake 5% of my funds, which is around £7 and when I run $stake that amount is correct, so I don't think that is the issue here.

      Comment

      • betdynamics
        Junior Member
        • Sep 2010
        • 534

        #4
        Try changing:

        Code:
        "params" = @{"marketIds" = @($marketID);
        to

        Code:
        "params" = @{"marketId" = @($marketID);
        i.e. remove the 's' afer marketId

        The error code you are receiving is telling you that the JSON string is incorrect or doesn't provide a mandatory parameter. marketId is a mandatory parameter.

        With regard to your indexing issue, I think Lopiner is correct - it looks like you may be looking at an unsorted list, but taking selectionId from a sorted list (sorted by lastPriceTraded)


        By the way, what was the original book (the one using PowerShell) called?

        Comment

        • AutomatesXYZ
          Junior Member
          • Apr 2016
          • 3

          #5
          Thank you both.

          I have made the changes you suggested. I closed Powershell and restarted it and now the indexing issue seems to be fixed.

          I removed the 's' afer marketId but I still get the error message with $bet.


          The Kindle book using powershell is called: "A Beginners Step by Step Guide to Writing a Betfair Bot: Betfair Secrets" by Andy Stephens

          It is a shame there are so many spelling errors and mistakes in the code, because I found the writing style is actually pretty good at explaining things to a beginner, but the code has obviously been copy/pasted complete with errors, all the way through, so it's very frustrating. There's supposed to be a companion website but it doesn't exist.

          I'm just going to leave it now and go and start the other book, which is called 'Programming for Betfair' by James Butler.

          Comment

          • betdynamics
            Junior Member
            • Sep 2010
            • 534

            #6
            If it was possible to see the final value of $postdata that would help identify the issue (although providing a fix may be challenging unless someone knows PowerShell syntax).

            Is it possible to capture the final value of the $postdata variable and display that as a string, so that we can see what it contains?

            We would need to see the contents AFTER the following line was executed:

            Code:
            $postdata = $postdata | ConvertTo-Json -depth 7

            Comment

            • StefanBelo.
              Junior Member
              • Jan 2009
              • 105

              #7
              Originally posted by AutomatesXYZ View Post
              I'm just going to leave it now and go and start the other book, which is called 'Programming for Betfair' by James Butler.
              You do not have to know betfair api nor how to program for betfair api. You can skip this step and use my bot sdk, then all you need is to program your bot strategy utilizing anything what bfexplorer already offers, so what you will do is to program bot automation, entry and exit points, and so on.

              You can use bfexplorer for free when posting on bfexplorer forum:

              http://bfexplorer.net/Products/BfexplorerBotSDK

              For instance here is such example of bot automation:

              Back selection n seconds after a lay

              It executes two bots, any bots you setup in bfexplorer, with specified Timeout interval.

              Here is the bot trigger code:

              https://gist.github.com/StefanBelo/b...e4bcc01d016fe2
              betfair bot platform, bfexplorer bot sdk

              Comment

              • jabe
                Senior Member
                • Dec 2014
                • 698

                #8
                I may be wrong about this, but your JSON string appears to have three things wrong with it. I've just tested such a string (not yours) with the delimiters, etc, as I'd expect, and it worked, but when I changed the delimiters to the way yours are, it didn't work.

                JSON strings use a colon : rather than an assign/equals sign =
                JSON strings separate items with a comma , rather than a semi-colon ;
                You have a surplus semi-colon after "persistenceType"="LAPSE" in your limitOrder.

                I believe your JSON string should look more like this:

                "params": @{"marketIds": @($marketID),
                "instructions":[
                object[]][ORDERED]@{"selectionId": [int]$selectionId,
                "side": "BACK",
                "orderType": "LIMIT",
                "limitOrder": [ORDERED]@{"size":$stake,"price":$Odds,"persistenceType":"L APSE"}
                }}

                I don't know anything about PowerShell coding, so I don't know whether your variables are correctly coded within the JSON string.

                Comment

                Working...
                X