betfair / API-NG-sample-code

Code snippets in various languages to support API-NG client development
203 stars 576 forks source link

Unable to get Market Information of each Race. #25

Open abdulbarik opened 8 years ago

abdulbarik commented 8 years ago

I am using REST API to get market info of each Race. I have "marketID" "WIN" also have all the details of each race, I didn't get any proper call to get market info of each race. I have tried with end point "listMarketCatalogue" and "listMarketBook" but didn't get any luck.

mgwalm commented 8 years ago

This is a sample from my code which works. however why it isn't working could be more complex than this. ` private async Task LoadFullCatalogue() { var marketFilter = new MarketFilter();

  ISet<string> ids = new HashSet<string>();
  ids.Add(_marketId); // the market i want
  marketFilter.MarketIds = ids;

  ISet<MarketProjection> marketProjections = new HashSet<MarketProjection>();
  marketProjections.Add(MarketProjection.RUNNER_METADATA);
  marketProjections.Add(MarketProjection.EVENT);
  marketProjections.Add(MarketProjection.MARKET_DESCRIPTION);
  marketProjections.Add(MarketProjection.COMPETITION);
  marketProjections.Add(MarketProjection.EVENT_TYPE);
  const string MaxResults = "1";
  const MarketSort MarketSort = MarketSort.FIRST_TO_START;

  try
  {
    var marketCatalogues = await JsonRpcClient.Instance.ListMarketCatalogue(marketFilter, marketProjections, MarketSort, MaxResults);

    // add marked id to each runner
    if (marketCatalogues.Count > 0)
    {
      MarketCatalogue = marketCatalogues[0];
      foreach (var runner in MarketCatalogue.Runners)
      {
        runner.MarketId = MarketCatalogue.MarketId;
        runner.EventDescription = MarketCatalogue.FullDescription;
      }
    }
  }
  catch (Exception ex)
  {
    DialogHelpers.DisplayMessage(ex.Message);
  }
}

`

mgwalm commented 8 years ago

Also the marketProjections specify what data you want. so what exactly do you want?

mgwalm commented 8 years ago

An example of listMarketBook ` // get the market book var ids = new List { MarketCatalogue?.MarketId }; var priceProj = new PriceProjection { Virtualise = true, //?? PriceData = new HashSet() }; priceProj.PriceData.Add(PriceData.EX_BEST_OFFERS);

  try
  {
    StatusMessage = $"Refreshing {MarketCatalogue?.FullDescription}...";
    _cancellationTokenSource = new CancellationTokenSource();

    var books = await JsonRpcClient.Instance.ListMarketBook(ids, priceProj, OrderProjection.EXECUTABLE, MatchProjection.ROLLED_UP_BY_AVG_PRICE, _cancellationTokenSource);
    if (books.Count > 0)
    {
      MarketBook = books[0];

      Runners = new ObservableCollection<Runner>(MarketBook.Runners);

`

abdulbarik commented 8 years ago

I have all events of eventType "7" in my DB, I just want a cronJob in every 15 mins. to get market information of each event of "WIN" type. Here what I tried yet: URL: "https://api-au.betfair.com/exchange/betting/rest/v1.0/listMarketCatalogue/" JSON value: {"filter": { "eventIds": ["26420387"], "marketIds": ["WIN"] }, "sort": "FIRST_TO_START", "maxResults": "100" }

But I am getting empty array every time.

Maybe I am doing something wrong to get this stuff. Please suggest me what I should do to get my task.

Thanks,

mgwalm commented 8 years ago

"marketIds": ["WIN"] is not correct, it should contain the id of a market.

I think it should be "marketTypeCodes": [ "WIN", "PLACE" ],

mgwalm commented 8 years ago

For example ` var marketFilter = new MarketFilter(); var time = new TimeRange(); time.From = DateTime.Now; time.To = DateTime.Now.AddDays(1);

  ISet<string> eventypeIds = new HashSet<string>();
  eventypeIds.Add(eventType.Id);

  marketFilter.EventTypeIds = eventypeIds;
  marketFilter.MarketStartTime = time;
  //marketFilter.MarketCountries = new HashSet<string>
  //                                   {
  //                                     "UK"
  //                                   };
  marketFilter.MarketTypeCodes = new HashSet<string>
                                   {
                                     "WIN"
                                   };

  var marketSort = MarketSort.FIRST_TO_START;
  var maxResults = "550";

  ISet<MarketProjection> marketProjections = new HashSet<MarketProjection>();
  marketProjections.Add(MarketProjection.EVENT);
  marketProjections.Add(MarketProjection.MARKET_DESCRIPTION);
  marketProjections.Add(MarketProjection.MARKET_START_TIME);

  try
  {
    StatusMessage = $"Getting events for {eventType.Name}...";
    var marketCatalogues = await JsonRpcClient.Instance.ListMarketCatalogue(marketFilter, marketProjections, marketSort, maxResults);

`

abdulbarik commented 8 years ago

@mgwalm I just updated "key" with "marketTypeCodes", but still getting blank array.

Am I doing anything wrong in my API call?

mgwalm commented 8 years ago

no, I said you should be using market type codes instead of marketids

what language/environment are you using.

try to mimic my code into whatever you are using.

abdulbarik commented 8 years ago

I am integrating it with REST API. Thanks for your suggestion.

Tjorriemorrie commented 6 years ago

I am also getting a lot of empty lists. Using python's betfairlightweight.

    time_ago = timezone.now() - datetime.timedelta(minutes=10)
    time_fwd = timezone.now() + datetime.timedelta(minutes=30)
    mfilter = market_filter(
        event_type_ids=[ET_HORSE_RACING, ET_GREYHOUND_RACING],
        market_start_time=time_range(
            from_=time_ago.strftime('%Y-%m-%dT%H:%I:%S.000Z'),
            to=time_fwd.strftime('%Y-%m-%dT%H:%I:%S.000Z')
        )
    )
    for i in range(10):
        res = trading.betting.list_market_catalogue(
            mfilter,
            market_projection=[
                'EVENT',
                'MARKET_START_TIME',
                'MARKET_DESCRIPTION',
                'RUNNER_METADATA',
            ],
            sort='FIRST_TO_START',
            max_results=1000,
            lightweight=True)

The body is just empty the whole time 😞