Skip to content

Lightweight python wrapper for Betfair API-NG (with streaming)

License

Notifications You must be signed in to change notification settings

oughtotrade/betfairlightweight

 
 

Repository files navigation

betfairlightweight

Build Status Coverage Status PyPI version

Lightweight, super fast (uses c libraries) pythonic wrapper for Betfair API-NG allowing all betting operations (including market and order streaming) and most account operations, see examples.

Documentation

Currently tested on Python 2.7, 3.4, 3.5 and 3.6.

installation

$ pip install betfairlightweight

setup

Add your certificates to '/certs/' and app_key to environment variables with username as key before using.

.bash_profile

export username = "appkey"

The library can then be used as follows:

>>> import betfairlightweight

>>> trading = betfairlightweight.APIClient('username', 'password', app_key='app_key')

>>> trading.login()
>>> event_types = trading.betting.list_event_types()

[<EventTypeResult>, <EventTypeResult>, ..]

streaming

Currently two listeners available, below will run the base listener which prints anything it receives. Stream listener is able to hold an order stream and a market stream, although it is recommended to have one socket per stream. The listener can hold a cache and push market_books/order_books out via a queue.

Exchange Stream API

from betfairlightweight.filters import (
    streaming_market_filter,
    streaming_market_data_filter,
)

betfair_socket = trading.streaming.create_stream(
    unique_id=2,
    description='Test Market Socket',
)

market_filter = streaming_market_filter(
    event_type_ids=['7'],
    country_codes=['IE'],
    market_types=['WIN'],
)
market_data_filter = streaming_market_data_filter(
    fields=['EX_ALL_OFFERS', 'EX_MARKET_DEF'],
    ladder_levels=3
)

betfair_socket.subscribe_to_markets(
    unique_id=12345,
    market_filter=market_filter,
    market_data_filter=market_data_filter,
)
betfair_socket.start(async=False)

About

Lightweight python wrapper for Betfair API-NG (with streaming)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%