Get Event ID from a market book?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kiwicricket
    Junior Member
    • Feb 2019
    • 5

    #1

    Get Event ID from a market book?

    Hi,

    I have a python script using betfairlightweight and i am starting to get the hang of it.

    I have an issue getting the Event Name from a market book though, maybe its not possible but i thought id ask.

    I am trying to do the following:
    Get the market ID of all cricket events
    break up the list into chunks, because it is too large to use in list market book as one request
    create a collection of market books, filter by in play books
    ***
    Issue: print the event name for each market book that is inplay
    ***

    i cant seem to find anyway of getting back from a book, to its event and hence its event name
    i could iterate through the market_id_list and call list_market_book with a list length of one, then create a dictionary with {an_event_name:[market_book_list]} - but then i am making many calls to the betfair server which will me slow.

    HTML Code:
    chunks = [market_id_list[x:x+10] for x in range(0, len(market_id_list), 10)]
    market_books = []
    market_books_inplay = []
    for chunk in chunks:
        market_books = trading.betting.list_market_book(
            market_ids=chunk
        )
        market_books_inplay += [x for x in market_books if x.inplay]
    
    market_book_df = create_market_book_data_frame(market_books_inplay)
    Does anyone know of a way to get from the market book, to its corresponding event and hence event ID?
  • jabe
    Senior Member
    • Dec 2014
    • 705

    #2
    I think you're doing it upside down. The usual way is to use the EventTypeId for cricket to get cricket listMarketCatalogues (you can restrict the returned ones in various ways, such as dates), then you can get the listMarketBook ones that are of interest. It shouldn't take long to call them up.

    Comment

    • LiamP
      Junior Member
      • Oct 2015
      • 284

      #3
      As Jabe said your too ‘deep’ although if you are using streaming it is present in the marketDefinition:

      https://github.com/liampauling/betfa...sources.py#L96

      Comment

      • kiwicricket
        Junior Member
        • Feb 2019
        • 5

        #4
        Thanks guys,

        I actually missed that the MarketCatalogue object has Event ID and Name instance variables, so now when i build Market Catalogue dataframe (i am using pandas) ive added these variables (Market Name, Market ID, Total Matched, Event ID and Event Name) .

        The plan now is to send listMarketBook requests for each unique Event ID. This way i can have a known one to many relationship, and hence I can see the Event Names that have market books that are inplay.

        I had hoped that i had missed a getter on the market book, but i guess i dont need to (if i send the listMarketBook correctly)

        Hi Liam,

        The man himself! I haven't even looked at this resource, because so far i have just been following and amending tutorials (which don't seem to use this resource). I will definitely be looking at this soon though.

        Many thanks for betfairlightweight btw!



        Comment

        • steve88
          Junior Member
          • Dec 2018
          • 10

          #5
          I'm having almost exactly the same problem as Kiwi cricket. I'm also pretty new to this API and have been following the tutorial. When I run the market catalogue object I can't get the event id or event name variables ( I just get an error); and when I run event variable it just comes up as "none". I just want the the market catalogue to list to show the event id for market.

          This is the code I used to produce the market catalogue pandas dataframe. Any help is appreciated.


          market_catalogue_filter = betfairlightweight.filters.market_filter(event_ids =racing_events_today['Event ID'])

          market_catalogues = trading.betting.list_market_catalogue(
          filter=market_catalogue_filter,
          max_results='1000',
          sort='FIRST_TO_START'
          )

          #Create a DataFrame for each market catalogue
          bf_market_list = pd.DataFrame({
          'Market Name': [market_cat_object.market_name for market_cat_object in market_catalogues],
          'Event': [market_cat_object.event for market_cat_object in market_catalogues],
          'Market ID': [market_cat_object.market_id for market_cat_object in market_catalogues],
          })

          print(bf_market_list)

          Comment

          • LiamP
            Junior Member
            • Oct 2015
            • 284

            #6
            You are not asking for it, add market_projection=[’EVENT’] to your list_market_catalogue request.

            See here for the full list that you can request:

            https://docs.developer.betfair.com/d.../Betting+Enums

            Comment

            Working...
            X