Powershell Bot errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pete101
    Junior Member
    • Sep 2019
    • 22

    #1

    Powershell Bot errors

    Hi Guys,

    I am slowly learning programing (at the age of 64), and was given a simple guide for creating a "Betfair Bot".

    Unfortunately, large parts of the book are out of date, and much of the code needs modified before it will work.

    I managed to create my self-certificate and upload it ok, but I am now struggling to get my test bot to log into the site.
    My code is as follows:

    Code:
    ####################
    # Function Section #
    ####################
    
    ###############################
    # Get Self Signed Certificate #
    ###############################
    Function get-cert {get-pfxcertificate -filepath "c:\Program Files\OpenSSL-Win64\bin\client.p12"}
    
    ###################################################################
    # Logs in and receives session token used for all remaining calls #
    ###################################################################
    Function login {
    $postParams = @{username='[I]myusername[/I]';password='[I]mypassword[/I]'}
    $thumbprint = $cert.Thumbprint
    $RET = invoke-webrequest -uri
    https://identitysso-cert.betfair.com/api/certlogin -Certificate $cert -Method Post -
    body $postParams -Headers @{"X-Application"="[I]mybot[/I]"} -
    ContentType "application/x-www-form-urlencoded"
    $RET | ConvertFrom-Json
    }
    
    #####################
    # Main Code Section #
    #####################
    $cert= get-cert        # Certificate
    $Ret = login $cert    # Login

    My PC returns the follwoing:
    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.


    Try the new cross-platform PowerShell https://aka.ms/pscore6

    PS C:\WINDOWS\system32>
    Oops, something went wrong. Please report this bug with the details below.
    Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
    -----------------------------------------------------------------------
    Last 1 Keys:
    Ctrl+v


    Exception:
    System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
    Parameter name: top
    Actual value was -38.
    at System.Console.SetCursorPosition(Int32 left, Int32 top)

    Invoke-WebRequest : Missing an argument for parameter 'Uri'. Specify a parameter of type 'System.Uri' and try again.
    At line:28 char:26
    + $RET = invoke-webrequest -uri
    + ~~~~
    + CategoryInfo : InvalidArgument: ( [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.Invo keWebRequestCommand

    https://identitysso-cert.betfair.com/api/certlogin : The term 'https://identitysso-cert.betfair.com/api/certlogin' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling
    of the name, or if a path was included, verify that the path is correct and try again.
    At line:29 char:1
    + https://identitysso-cert.betfair.com/api/certlogin -Certificate $cert ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (https://identit...m/api/certlogin:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    body : The term 'body' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:30 char:1
    + body $postParams -Headers @{"X-Application"="RD_BETFAIR_BOT"} -
    + ~~~~
    + CategoryInfo : ObjectNotFound: (body:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    ContentType : The term 'ContentType' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
    again.
    At line:31 char:1
    + ContentType "application/x-www-form-urlencoded"
    + ~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (ContentType:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.
    At line:32 char:8
    + $RET | ConvertFrom-Json
    + ~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidData: ( [ConvertFrom-Json], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Mic rosoft.PowerShell.Commands.ConvertFromJsonCommand



    I am guessing that the above is more than just a simple syntax error, but I am at a loss as to how to fix it.

    I have tried various varients of the above code, but still get the same errors.

    The myusername, mypassword & mybot replace the actual data. Other than that the code is unchanged.

    Are there any gurus out there who can give a young-at-heart 64 year old some pointers?

    Many thanks.

    Best wishes.

    Pete
  • bfexplorer
    Senior Member
    • Sep 2018
    • 212

    #2
    Originally posted by Pete101 View Post
    Hi Guys,

    I am slowly learning programing (at the age of 64), and was given a simple guide for creating a "Betfair Bot".
    I am myself 53 years old.

    Betfair documented available libraries for different programming languages here:

    https://docs.developer.betfair.com/d...ni/Sample+Code

    Unfortunately my library is not there, but you can find it here:

    https://github.com/StefanBelo/Bfexplorer-BOT-SDK

    or simple bot strategy scripts, here:

    https://gist.github.com/StefanBelo

    My approach for betfair bot sdk is different as the rest of libraries offer, as you need to program directly only your betting or trading strategy, not login, browsing events and markets, placing, updating and/or cancelling bets, that all is already programmed as well as base trading bots.

    Of course you can use my code to do the "low level programming", for instance here:

    https://github.com/StefanBelo/Bfexpl...ole/Program.cs

    or here on one level up, on the bfexplorer app domain:

    https://github.com/StefanBelo/Bfexpl...ole/Program.fs

    but as I said, you really need to program just strategy, for instance here is betfair australia team ML strategy implemented by my bot for bfexplorer executing fully automated strategy, so strategy running 24/7:

    http://bfexplorer.net/Community/BlogContent/434

    In my post there are references to other betfair apps, and how they automate the above strategy (better to say do not automate at all), so you can compare among different approaches.

    Comment

    • Pete101
      Junior Member
      • Sep 2019
      • 22

      #3
      bfexplorer Thank you :-)

      An excellent response. Much appreciated.

      Best regards,

      Pete

      Comment

      Working...
      X