Announcement

Collapse
No announcement yet.

A lightweight Betfair API-NG Ruby wrapper

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • A lightweight Betfair API-NG Ruby wrapper

    There doesn't appear to be much life in this forum, which is a shame because Ruby is such a great language!

    Anyway, I wrote a simple Ruby wrapper for Betfair API-NG (JSON). It uses Ruby's hash to JSON marshalling to give you a simple, familiar interface.

    I've only implemented what I needed, at this stage, but feel free to check it out and contribute/request new features if you wish.


  • #2
    This looks pretty solid, thanks for releasing it. I'm going to be using as-is, but you can expect to hear from me on github as and when I want to make pull requests.

    Comment


    • #3
      Thanks are in order from me as well, now that I am starting to get better hang of it I am finding more and more possible uses for the API.

      But, one problem I seem to encounter almost daily is that list_market_book doesn't return the market. I am querying it with only one market id and it works most of the time but not always and I have trouble debugging it. It will fail for example when I try to find one specific runner with

      Code:
      book["runners"].detect {|f| f["selectionId"] == selection}["lastPriceTraded"].nil?
      And the error this produces is

      Code:
      `[]': no implicit conversion of String into Integer (TypeError)
      Any ideas on how I should approach this?

      Now that I look my code. It is plausible that this comes from removed runners, but shouldn't lastPriceTraded still be there anyway, at least as nil even if selection itself was not open for trading anymore?

      Comment


      • #4
        No problem .

        The error message is usually a result of treating an array like a hash, i.e. calling some_array["something"]. It's either the book object itself, or an item inside book["runners"] which is an array, not the hash you're expecting. I don't know why this would be, you'll have to do some debugging. If you caught the error and printed out the book object, it should be quite clear what's going on.

        Comment


        • #5
          I have been trying to catch the error but so far it has been elusive. And so far it has been impossible to replicate manually so I need to have bot running and hope that my error catching code indeed catches the error this time around

          That I did check that it is not purely removed runner. In that kind of case statement above returns true as I expected it to.

          Comment


          • #6
            Now I did catch the error. This is the error I am getting:

            Code:
            ["detail", {"exceptionname"=>"APINGException", "APINGException"=>{"errorDetails"=>"", "errorCode"=>"TIMEOUT_ERROR", "requestUUID"=>"prdang034-02170718-005e5ae28b"}}]
            It does seem to appear together with removed runners. But even then not in all cases.

            And it does seem that waiting for few seconds and then trying again is a workaround for this.
            Last edited by Racealyst; 06-03-2016, 03:27 PM.

            Comment


            • #7
              That's a standard timeout message which could occur at any time and with any request (not just listMarketBook).

              Your code needs to be able to handle this type of message - as you say, the next request is likely to be successful.

              If you get repeated timeout messages then it is probably worth alerting the BDP team as this tends to suggest an errant node in their server farm.

              Comment


              • #8
                Yeah, found that out as well now. And have amended my code

                Comment


                • #9
                  Ah, that's interesting. I don't think I've ever had a timeout before (that I'm aware of), my personal use of the API is very light though.

                  If it's worth it we can build some re-try behaviour into the library.

                  Comment


                  • #10
                    I certainly don't think the library should automatically retry - the decision on whether to resubmit should be left to the calling program or should be specified via some parameter.

                    For instance, what would happen if you placed a bet and received a timeout message? You don't know whether the bet has been accepted or not and automatically retrying the placement may result in multiple bets being placed.

                    Comment


                    • #11
                      That's a good point. We could auto-retry if and only if the user has passed a "customerRef" (https://api.developer.betfair.com/se...ni/placeOrders) though.

                      but meh, if there's no demand I won't bother .

                      Comment

                      Working...
                      X