betfairlightweight - get the json request being sent?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • noel
    Junior Member
    • Sep 2023
    • 2

    #1

    betfairlightweight - get the json request being sent?

    How do I get the json request being sent to the API when using betfairlightweight?
    Say if I run list_market_book(). How do I catch what the request will be?

  • carlabrott
    Junior Member
    • Nov 2023
    • 1

    #2
    Hello, I think you can utilize the built-in logging functionality provided by the library. Here's how you can enable logging and capture the request:

    1. Import the betfairlightweight library and enable logging:

    python
    import logging
    from betfairlightweight import APIClient
    # Enable logging
    logging.basicConfig(level=logging.INFO)</code>

    2. Create an instance of the APIClient and set the desired configuration options:

    python
    client = APIClient(username='YOUR_USERNAME',
    password='YOUR_PASSWORD',
    app_key='YOUR_APP_KEY',
    certs='certs')


    Make sure to replace 'YOUR_USERNAME', 'YOUR_PASSWORD', 'YOUR_APP_KEY', and 'certs' with your actual Betfair account details and the correct file path to your SSL certificates.

    3. Add a custom handler to the client's logger to capture the request:

    python
    logger = logging.getLogger('betfairlightweight')
    logger.addHandler(logging.FileHandler('request.log '))

    This code will create a log file named request.log where the captured request information will be stored.

    4. Make the API call you want to capture the request for:

    python
    client.login()
    client.keep_alive()
    # Perform other API calls, such as list_market_book()

    5. After executing the desired API calls, check the contents of the request.log file to see the captured JSON request:

    python
    with open('request.log', 'r') as file:
    request_data = file.read()
    print(request_data)​

    geometry dash lite
    Last edited by carlabrott; 08-11-2023, 09:57 PM.

    Comment

    Working...
    X