Best offer from all soccer events in today

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cks1007
    Junior Member
    • Mar 2020
    • 9

    #1

    Best offer from all soccer events in today

    Hi. Is it possible to get best offer from all soccer events in today by PHP?
    for example, today has 10 soccer events.
    every event has 20 market
    how to get 10*20 market best offer?
    should I use betting api or stream api?
  • denimen9
    Junior Member
    • Feb 2019
    • 7

    #2
    If you want to use betting api, the request body should look like:

    Code:
    [{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listEvents", "params": {"filter":{"eventTypeIds":["1"],"marketStartTime":{"to":"2020-03-17T23:00:00Z"}}}, "id": 1}]
    Where you set eventTypeIds to 1 (Soccer), marketStartTime to today and hour mark to 23:00 should get you all events from today for Soccer

    Comment

    • cks1007
      Junior Member
      • Mar 2020
      • 9

      #3
      hi denime9
      can you advice me how to get all "best offer" from all soccer events?

      Comment

      • denimen9
        Junior Member
        • Feb 2019
        • 7

        #4
        Hi CKS,

        Considering you made a successful login and got the token next call you should do is fetching all events for Soccer like:

        PHP Code:
        $curl curl_init();
            
        curl_setopt_array($curl, array(
                
        CURLOPT_URL => "https://api.betfair.com/exchange/betting/json-rpc/v1",
                
        CURLOPT_RETURNTRANSFER => true,
                
        CURLOPT_ENCODING => "",
                
        CURLOPT_MAXREDIRS => 10,
                
        CURLOPT_TIMEOUT => 10,
                
        CURLOPT_FOLLOWLOCATION => true,
                
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                
        CURLOPT_CUSTOMREQUEST => "POST",
                
        CURLOPT_POSTFIELDS =>"[{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listEvents", "params": {"filter":{"eventTypeIds":[1]}}, "id": 1}]",
                
        CURLOPT_HTTPHEADER => array(
                  
        "X-Application: ".$appKey,
                  
        "X-Authentication: ".$token,
                  
        "Accept:  application/json",
                  
        "Content-Type: application/x-www-form-urlencoded"
                
        ),
            ));

            
        $response curl_exec($curl);
            
        curl_close($curl);
            
        $aEvent=json_decode($response,true); 

        After that the $aEvent should contain all soccer events (eventId, eventName, startTime etc..). After you get the event list you should do a foreach and get marketCatalogue (catalogue of bettypes for given event) like so:

        PHP Code:
        $curl curl_init();
        curl_setopt_array($curl, array(
            
        CURLOPT_URL => "https://api.betfair.com/exchange/betting/json-rpc/v1",
            
        CURLOPT_RETURNTRANSFER => true,
            
        CURLOPT_ENCODING => "",
            
        CURLOPT_MAXREDIRS => 10,
            
        CURLOPT_TIMEOUT => 10,
            
        CURLOPT_FOLLOWLOCATION => true,
            
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            
        CURLOPT_CUSTOMREQUEST => "POST",
            
        CURLOPT_POSTFIELDS =>"[{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listMarketCatalogue", "params": {"filter":{"eventIds":[$eventId],"marketBettingTypes":["ODDS"]},"maxResults":"100","marketProjection":["COMPETITION","EVENT","EVENT_TYPE","RUNNER_DESCRIPTION"]}, "id": 1}]",
            
        CURLOPT_HTTPHEADER => array(
                
        "X-Application:  ".$appKey,
                
        "X-Authentication:  ".$token,
                
        "Accept:  application/json",
                
        "Content-Type: application/x-www-form-urlencoded"
            
        ),
        ));

        $response curl_exec($curl);
        curl_close($curl);
        $aMarket=json_decode($response,true); 

        Then you should loop through $aMarket array and gather the marketId's that you want the odds for and after that you make one more call to get "BEST OFFER" odds for the market like:

        PHP Code:
        $marketIdCollection="1.170186585,1.170186556,1.170186599' // string of comma separated marketID's

        $curl = curl_init();
        curl_setopt_array(
        $curl, array(
            CURLOPT_URL => "
        https://api.betfair.com/exchange/betting/json-rpc/v1",
            
        CURLOPT_RETURNTRANSFER => true,
            
        CURLOPT_ENCODING => "",
            
        CURLOPT_MAXREDIRS => 10,
            
        CURLOPT_TIMEOUT => 10,
            
        CURLOPT_FOLLOWLOCATION => true,
            
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            
        CURLOPT_CUSTOMREQUEST => "POST",
            
        CURLOPT_POSTFIELDS =>"[{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listMarketBook", "params": {"marketIds":[".$marketIdCollection."],"priceProjection":{"priceData":["EX_BEST_OFFERS"]}}, "id": 1}]",
            
        CURLOPT_HTTPHEADER => array(
                
        "X-Application:  01sBbMInsLPwIbF6",
                
        "X-Authentication:  092pOh6eQVUHtTtmlszBt8AwORnyxPVKc9R/cayMN8I=",
                
        "Accept:  application/json",
                
        "Content-Type: application/x-www-form-urlencoded"
            
        ),
        ));

        $response curl_exec($curl);
        curl_close($curl);
        $aPrice=json_decode($response,true); 

        If you printout $aPrice you should see the prices and volumes for each selection
        Last edited by denimen9; 17-03-2020, 06:36 PM.

        Comment

        • cks1007
          Junior Member
          • Mar 2020
          • 9

          #5
          hi denimen9

          thanks again for your kindly reply.
          actually , I do as your advice already.
          1. listMarketCatalogue to get all MArket
          2. use listMarketBook loop to find price and size

          just wondering if BetFair API offer any easier way to get what we need?
          for example, in Pinnacle API
          it's east to use following code to get all soccer odds...

          $param = array("sportid" => "29" , "isLive"=>"0" , "oddsFormat"=>"Decimal", "toCurrenceCode"=>"EUR");
          $a=$client->getOdds($param);

          Comment

          • denimen9
            Junior Member
            • Feb 2019
            • 7

            #6
            Not at the moment, what you can do is save eventId's and marketId's and after few mins of whatever use only listMarketBook to get prices and sizes. Those responses already contain STATUS info to check if given bet type is open or if price is active or not.

            Yes, pinnacle is more like a classical feed (like bookies used to offer prices) but betfair gives a lot of data so it has to be like this, i think. But this api has been runing for 5+ years now, lets see what happens in next version.

            Comment

            Working...
            X