Giter Site home page Giter Site logo

betfair2.py's Introduction

betfair2.py is a Python wrapper for the Betfair API.

Installation

>> pip install git+https://github.com/BenderV/betfair2.py.git
Requirements
  • Python >= 2.7 or >= 3.3
Application Keys

You will need an Application Key to log in to the Betfair API. You can find instructions for creating a key at https://api.developer.betfair.com/services/webapps/docs/display/1smk3cen4v3lu3yomq5qye0ni/Application+Keys

SSL Certificates

For non-interactive login, you must generate a self-signed SSL certificate and upload it to your Betfair account. Betfair.py includes tools for simplifying this process. To create a self-signed certificate, run (you must clone this repo for this to work) :

invoke ssl

This will generate the following files in the certs directory :

betfair.crt
betfair.csr
betfair.key
betfair.pem

You can write SSL certificates to another directory by passing the --name parameter :

invoke ssl --name=path/to/certs/betfair

Once you have generated the files, you can upload the betfair.crt file to Betfair at https://myaccount.betfair.com/accountdetails/mysecurity?showAPI=1.

Examples

Create a Betfair client and log in :

>> from betfair import Betfair
>> client = Betfair('app_key', 'certs/betfair.pem')
>> client.login('username', 'password')

Refresh session token :

>> client.keep_alive()

Log out :

>> client.logout()

List all tennis markets :

>> from betfair.models import MarketFilter
>> event_types = client.list_event_types(
        MarketFilter(text_query='tennis')
    )
>> print(len(event_types))                 # 2
>> print(event_types[0].event_type.name)   # 'Tennis'
>> tennis_event_type = event_types[0]
>> markets = client.list_market_catalogue(
        MarketFilter(event_type_ids=[tennis_event_type.event_type.id],
                     market_projection=["EVENT", "COMPETITION", "RUNNER_METADATA",
                                        "MARKET_START_TIME", "RUNNER_DESCRIPTION", 
                                        "MARKET_DESCRIPTION", "EVENT_TYPE"],
                     max_results=100))
    )
>> markets[0].market_name                  # 'Djokovic Tournament Wins'

Transform model to dictionary

>> from betfair import utils
>> markets = utils.model_to_dict(markets)

Original author

Joshua Carp (jmcarp)

License

MIT licensed. See the bundled LICENSE file for more details

Testing

To run tests :

$ py.test

betfair2.py's People

Contributors

jmcarp avatar petedmarsh avatar benderv avatar ms5 avatar goetzk avatar matthew-odonnell avatar seriousdude avatar jontonsoup avatar skozilla avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.