Some Basic Newbie API-NG questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geoffw123
    Senior Member
    • Mar 2014
    • 250

    #1

    Some Basic Newbie API-NG questions

    Hi

    Just recently started playing with the API-NG so apologies for the very basic questions.

    Q1) I have got the C# Betfair example working OK, but I am having trouble understanding the login mechanism. I am using the interactive login, but I cant seem to find any related code to logging in within the C# Source (Apart from it uses the Appkey/password/token in the header section of each command). This page didn't seem to tally with that example codehttps://api.developer.betfair.com/se...-+API+Endpoint so didn't help my understanding.
    Can anyone take a few moments to explain the NG login mechanism please?

    Q2 Related to Q1. I have got the session token for login by peeking in Firefox for the cookie string, and then pasting that manually into the source code and compiling. This is explained on several pages, but I cant seem to find any docs as to how I should get the session token programmatically at login time ?
    Does anyone have a link to explain how to do that please, or a pointer to some example code ?

    Q3. Is there any call back mechanism, so I can tell when a bet order has been matched ? I know how to do this by polling with the listCurrentOrders command. But is there a more efficient, less comms intensive mode where I don't need to poll and the Server initiates sending a packet when it gets matched ? I am guessing there isn't but thought I would check ?

    Thanks for any help

    Regards Geoff
  • bnl
    Junior Member
    • Nov 2012
    • 108

    #2
    For Q1 and Q2 :
    send login as a POST() form.
    parse the reply for ssoid.

    This is not C#, it's Ada, but you probably get the idea

    Code:
      procedure Login is
        Login_HTTP_Headers : Aws.Headers.List := Aws.Headers.Empty_List;
        AWS_Reply    : Aws.Response.Data;
        Header : AWS.Headers.List;
      begin
        Aws.Headers.Set.Add (Login_HTTP_Headers, "User-Agent", "AWS-BNL/1.0");
    
        declare
          Data : String :=  "username=" & Global_Token.Get_Username & "&" &
                             "password=" & Global_Token.Get_Password &"&" &
                             "login=true" & "&" &
                             "redirectMethod=POST" & "&" &
                             "product=home.betfair.int" & "&" &
                             "product=home.betfair.int" & "&" &
                             "url=https://www.betfair.com/";
        begin
    --      Log(Me & "Login", "Data '" & Data & "'");
    
          AWS_Reply := Aws.Client.Post (Url          => "https://identitysso.betfair.com/api/login",
                                        Data         => Data,
                                        Content_Type => "application/x-www-form-urlencoded",
                                        Headers      => Login_HTTP_Headers,
                                        Timeouts     => Aws.Client.Timeouts (Each => 30.0));
        end ;
        Log(Me & "Login", "reply" & Aws.Response.Message_Body(AWS_Reply));
        
        -- login reply should look something like below (522 chars)
        -- <html>
        -- <head>
        --     <title>Login</title>
        -- </head>
        -- <body onload="document.postLogin.submit()">
        -- <iframe src="https://secure.img-cdn.mediaplex.com/0/16689/universal.html?page_name=loggedin&amp;loggedin=1&amp;mpuid=6081705" HEIGHT="1" WIDTH="1" FRAMEBORDER="0" ></iframe>
        -- <form name="postLogin" action="https://www.betfair.com/" method="POST">
        --     <input type="hidden" name="productToken" value="UeJkdkdojfldlöspdskFmrDhsrHQkOvHu7alH5NCldA="/>
        --     <input type="hidden" name="loginStatus" value="SUCCESS"/>
        -- </form>
        -- </body>
        -- </html>
        
        declare
          String_Reply : String := Aws.Response.Message_Body(AWS_Reply);
        begin  
          if String_Reply'length < 500 then
            raise Login_Failed with "Bad reply from server at login";
          end if;
        end ;
        
        Header := AWS.Response.Header(AWS_Reply);
    
        for i in 1 .. AWS.Headers.Length(Header) loop
          declare
            Head : String := AWS.Headers.Get_Line(Header,i);
            Index_First_Equal : Integer := 0;
            Index_First_Semi_Colon : Integer := 0;
    --  Set-Cookie: ssoid=o604egQ2BuWCG6ij8NMlkdoemkdldmsw7eHLiWoA1vI=; Domain=.betfair.com; Path=/
          begin
            if Position(Head,"ssoid") > Integer(0) then
              Log("Login"," " & Head);
              for i in Head'range loop
                case Head(i) is
                  when '=' =>
                    if Index_First_Equal = 0 then
                      Index_First_Equal := i;
                    end if;
    
                  when ';' =>
                    if Index_First_Semi_Colon = 0 then
                      Index_First_Semi_Colon := i;
                    end if;
                  when others => null;
                end case;
              end loop;
              if Index_First_Equal > Integer(0) and then Index_First_Semi_Colon > Index_First_Equal then
                Log("Login","ssoid: '" & Head(Index_First_Equal +1 .. Index_First_Semi_Colon -1) & "'");
                Global_Token.Set(Head(Index_First_Equal +1 .. Index_First_Semi_Colon -1));
              end if;
            end if;
          end;
        end loop;
      end Login;

    Q3
    This is a bet I placed on a horse -place market


    Code:
    {
    	"method": "SportsAPING/v1.0/placeOrders",
    	"jsonrpc": "2.0",
    	"id": 16,
    	"params": {
    		"marketId": "1.114498460",
    		"instructions": [{
    			"handicap": 0,
    			"limitOrder": {
    				"size": 1.52510E+02,
    				"price": 1.01000E+00,
    				"persistenceType": "PERSIST"
    			},
    			"orderType": "LIMIT",
    			"selectionId": 7850530,
    			"side": "BACK"
    		}]
    	}
    }
    the reply is


    Code:
    {
    	"id": 16,
    	"jsonrpc": "2.0",
    	"result": {
    		"marketId": "1.114498460",
    		"status": "SUCCESS",
    		"instructionReports": [{
    			"betId": "38925383410",
    			"placedDate": "2014-07-04T16:36:37.000Z",
    			"instruction": {
    				"handicap": 0.00000E+00,
    				"limitOrder": {
    					"size": 1.52510E+02,
    					"price": 1.01000E+00,
    					"persistenceType": "PERSIST"
    				},
    				"orderType": "LIMIT",
    				"selectionId": 7850530,
    				"side": "BACK"
    			},
    			"status": "SUCCESS",
    			"sizeMatched": 0.00000E+00,
    			"averagePriceMatched": 0.00000E+00
    		}]
    	}
    }

    Note the Status on instructionReports.
    Bet is placed ok.
    But also note the sizeMatched = 0.
    The bet is not yet matched.
    Placed/accepted, but not matched.


    /Björn

    Comment

    • betdynamics
      Junior Member
      • Sep 2010
      • 534

      #3
      Q1/Q2 - see https://github.com/betfair/API-NG-sample-code

      This contains C# code covering interactive login

      Q3 - no, there is no automatic callback functionality.

      There is talk about Betfair providing a push-based API, but I've not seen any concrete news on that yet.

      Comment

      Working...
      X