betfairlightweight


Namebetfairlightweight JSON
Version 2.20.1 PyPI version JSON
download
home_page
SummaryLightweight python wrapper for Betfair API-NG
upload_time2024-03-12 09:38:09
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2023, Liam Pauling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords
VCS
bugtrack_url
requirements requests black coverage mkdocs mkdocs-material build twine
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <a href="https://github.com/betcode-org">
    <img src="docs/images/logo-full.png" title="betcode-org">
  </a>
</p>

# betfairlightweight

![Build Status](https://github.com/betcode-org/betfair/actions/workflows/test.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/liampauling/betfair/badge.svg?branch=master)](https://coveralls.io/github/liampauling/betfair?branch=master) [![PyPI version](https://badge.fury.io/py/betfairlightweight.svg)](https://pypi.python.org/pypi/betfairlightweight) [![Downloads](https://pepy.tech/badge/betfairlightweight)](https://pepy.tech/project/betfairlightweight)

Lightweight, super fast (uses C and Rust libraries) pythonic wrapper for [Betfair API-NG](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni) allowing all betting operations (including market and order streaming) and account operations, see [examples](https://github.com/betcode-org/betfair/tree/master/examples).

[docs](https://betcode-org.github.io/betfair/)

[join betcode slack group](https://join.slack.com/t/betcode-org/shared_invite/zt-25yz6dt1y-LHya5VzHLOzN3RZEQrSnrA)

Currently tested on Python 3.8, 3.9, 3.10, 3.11 and 3.12.

# installation

```bash
$ pip install betfairlightweight
```

To use C/Rust libraries install with

```bash
$ pip install betfairlightweight[speed]
```

# setup

In order to connect to the Betfair API you will need an App Key, SSL Certificates and a username/password.

### App Key
Follow [these](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Application+Keys) instructions to get your app key, you can either use a delayed or live key.

### SSL certificates
Follow [these](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Non-Interactive+%28bot%29+login) instructions to set up your SSL certificates. Save your .ctr and .key files to a local directory. The default directory where the library is looking for the keys is '/certs' but you can specify any other directory.

### Using the library

The library can then be used as follows:

```python
import betfairlightweight

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

trading.login()
```

or the following for interactive login with no certs (not as secure)

```python
import betfairlightweight

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

trading.login_interactive()
```


```python
event_types = trading.betting.list_event_types()

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

Following endpoints are available:

- trading.[login](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Non-Interactive+%28bot%29+login)
- trading.[login_interactive](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Interactive+Login+-+API+Endpoint)
- trading.[keep_alive](https://docs.developer.betfair.com/pages/viewpage.action?pageId=3834909#Login&SessionManagement-KeepAlive)
- trading.[logout](https://docs.developer.betfair.com/pages/viewpage.action?pageId=3834909#Login&SessionManagement-Logout)

- trading.[betting](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Betting+API)
- trading.[account](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Accounts+API)
- trading.[navigation](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Navigation+Data+For+Applications)
- trading.[scores](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Race+Status+API)
- trading.[streaming](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Exchange+Stream+API)
- trading.[historical](https://historicdata.betfair.com/#/apidocs)

- trading.in_play_service
- trading.race_card


# 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 or a market stream (one per listener). The listener can hold a cache and push market_books/order_books out via a queue.

[Exchange Stream API](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Exchange+Stream+API)

```python
from betfairlightweight.filters import (
    streaming_market_filter,
    streaming_market_data_filter,
)

betfair_socket = trading.streaming.create_stream()

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(
    market_filter=market_filter,
    market_data_filter=market_data_filter,
)

betfair_socket.start()  # blocking
```

# historic data

The historic endpoint provides some basic abstraction for the historicdata api:

[Historic Data API](https://historicdata.betfair.com/#/apidocs)

```python

trading.historic.get_my_data()

[{'plan': 'Basic Plan', 'purchaseItemId': 1343, 'sport': 'Cricket', 'forDate': '2017-06-01T00:00:00'}]
```

Taking advantage of the streaming code lightweight can parse/output historical data in the same way it process streaming data allowing backtesting or with a custom listener, csv creation (see [examples](https://github.com/betcode-org/betfair/tree/master/examples)).

[Historic Data](https://historicdata.betfair.com/#/home)

```python

stream = trading.streaming.create_historical_stream(
    file_path='horse-racing-pro-sample',
)

stream.start()
```

or use the  stream generator:

```python

stream = trading.streaming.create_historical_generator_stream(
    file_path='horse-racing-pro-sample',
)

g = stream.get_generator()

for market_books in g():
    print(market_books)
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "betfairlightweight",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Liam Pauling <a@unknown.com>",
    "download_url": "https://files.pythonhosted.org/packages/21/3b/aec960e73e204e6ac4c6b8f0c91dacc9da112a8626f21220e0a5d30c79da/betfairlightweight-2.20.1.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <a href=\"https://github.com/betcode-org\">\n    <img src=\"docs/images/logo-full.png\" title=\"betcode-org\">\n  </a>\n</p>\n\n# betfairlightweight\n\n![Build Status](https://github.com/betcode-org/betfair/actions/workflows/test.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/liampauling/betfair/badge.svg?branch=master)](https://coveralls.io/github/liampauling/betfair?branch=master) [![PyPI version](https://badge.fury.io/py/betfairlightweight.svg)](https://pypi.python.org/pypi/betfairlightweight) [![Downloads](https://pepy.tech/badge/betfairlightweight)](https://pepy.tech/project/betfairlightweight)\n\nLightweight, super fast (uses C and Rust libraries) pythonic wrapper for [Betfair API-NG](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni) allowing all betting operations (including market and order streaming) and account operations, see [examples](https://github.com/betcode-org/betfair/tree/master/examples).\n\n[docs](https://betcode-org.github.io/betfair/)\n\n[join betcode slack group](https://join.slack.com/t/betcode-org/shared_invite/zt-25yz6dt1y-LHya5VzHLOzN3RZEQrSnrA)\n\nCurrently tested on Python 3.8, 3.9, 3.10, 3.11 and 3.12.\n\n# installation\n\n```bash\n$ pip install betfairlightweight\n```\n\nTo use C/Rust libraries install with\n\n```bash\n$ pip install betfairlightweight[speed]\n```\n\n# setup\n\nIn order to connect to the Betfair API you will need an App Key, SSL Certificates and a username/password.\n\n### App Key\nFollow [these](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Application+Keys) instructions to get your app key, you can either use a delayed or live key.\n\n### SSL certificates\nFollow [these](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Non-Interactive+%28bot%29+login) instructions to set up your SSL certificates. Save your .ctr and .key files to a local directory. The default directory where the library is looking for the keys is '/certs' but you can specify any other directory.\n\n### Using the library\n\nThe library can then be used as follows:\n\n```python\nimport betfairlightweight\n\ntrading = betfairlightweight.APIClient('username', 'password', app_key='app_key', certs='/certs')\n\ntrading.login()\n```\n\nor the following for interactive login with no certs (not as secure)\n\n```python\nimport betfairlightweight\n\ntrading = betfairlightweight.APIClient('username', 'password', app_key='app_key')\n\ntrading.login_interactive()\n```\n\n\n```python\nevent_types = trading.betting.list_event_types()\n\n[<EventTypeResult>, <EventTypeResult>, ..]\n```\n\nFollowing endpoints are available:\n\n- trading.[login](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Non-Interactive+%28bot%29+login)\n- trading.[login_interactive](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Interactive+Login+-+API+Endpoint)\n- trading.[keep_alive](https://docs.developer.betfair.com/pages/viewpage.action?pageId=3834909#Login&SessionManagement-KeepAlive)\n- trading.[logout](https://docs.developer.betfair.com/pages/viewpage.action?pageId=3834909#Login&SessionManagement-Logout)\n\n- trading.[betting](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Betting+API)\n- trading.[account](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Accounts+API)\n- trading.[navigation](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Navigation+Data+For+Applications)\n- trading.[scores](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Race+Status+API)\n- trading.[streaming](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Exchange+Stream+API)\n- trading.[historical](https://historicdata.betfair.com/#/apidocs)\n\n- trading.in_play_service\n- trading.race_card\n\n\n# streaming\n\nCurrently two listeners available, below will run the base listener which prints anything it receives. Stream listener is able to hold an order stream or a market stream (one per listener). The listener can hold a cache and push market_books/order_books out via a queue.\n\n[Exchange Stream API](https://docs.developer.betfair.com/display/1smk3cen4v3lu3yomq5qye0ni/Exchange+Stream+API)\n\n```python\nfrom betfairlightweight.filters import (\n    streaming_market_filter,\n    streaming_market_data_filter,\n)\n\nbetfair_socket = trading.streaming.create_stream()\n\nmarket_filter = streaming_market_filter(\n    event_type_ids=['7'],\n    country_codes=['IE'],\n    market_types=['WIN'],\n)\nmarket_data_filter = streaming_market_data_filter(\n    fields=['EX_ALL_OFFERS', 'EX_MARKET_DEF'],\n    ladder_levels=3\n)\n\nbetfair_socket.subscribe_to_markets(\n    market_filter=market_filter,\n    market_data_filter=market_data_filter,\n)\n\nbetfair_socket.start()  # blocking\n```\n\n# historic data\n\nThe historic endpoint provides some basic abstraction for the historicdata api:\n\n[Historic Data API](https://historicdata.betfair.com/#/apidocs)\n\n```python\n\ntrading.historic.get_my_data()\n\n[{'plan': 'Basic Plan', 'purchaseItemId': 1343, 'sport': 'Cricket', 'forDate': '2017-06-01T00:00:00'}]\n```\n\nTaking advantage of the streaming code lightweight can parse/output historical data in the same way it process streaming data allowing backtesting or with a custom listener, csv creation (see [examples](https://github.com/betcode-org/betfair/tree/master/examples)).\n\n[Historic Data](https://historicdata.betfair.com/#/home)\n\n```python\n\nstream = trading.streaming.create_historical_stream(\n    file_path='horse-racing-pro-sample',\n)\n\nstream.start()\n```\n\nor use the  stream generator:\n\n```python\n\nstream = trading.streaming.create_historical_generator_stream(\n    file_path='horse-racing-pro-sample',\n)\n\ng = stream.get_generator()\n\nfor market_books in g():\n    print(market_books)\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023, Liam Pauling  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Lightweight python wrapper for Betfair API-NG",
    "version": "2.20.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/betcode-org/betfair/issues",
        "Changelog": "https://github.com/betcode-org/betfair/blob/master/HISTORY.rst",
        "Documentation": "https://betcode-org.github.io/betfair/",
        "Homepage": "https://github.com/betcode-org",
        "Repository": "https://github.com/betcode-org/betfair.git"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e61e5cf5446b48279f8bb807d47c58c9683f4fcc6fbac15c8b42c01b1863e91",
                "md5": "09d7d12793401bf64bc98a92538dfa48",
                "sha256": "8ce8d0142fd877ddace21ddd4635f1fb99da264bf6835832b047019cb6d9a91e"
            },
            "downloads": -1,
            "filename": "betfairlightweight-2.20.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "09d7d12793401bf64bc98a92538dfa48",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 69226,
            "upload_time": "2024-03-12T09:38:07",
            "upload_time_iso_8601": "2024-03-12T09:38:07.135489Z",
            "url": "https://files.pythonhosted.org/packages/4e/61/e5cf5446b48279f8bb807d47c58c9683f4fcc6fbac15c8b42c01b1863e91/betfairlightweight-2.20.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "213baec960e73e204e6ac4c6b8f0c91dacc9da112a8626f21220e0a5d30c79da",
                "md5": "4eb6885a3facd4c568462bc98c15b157",
                "sha256": "2e57cc8fce9c9030c0d497029c8e3ce6722caaa2b08687330dc1549c9ec2e2fa"
            },
            "downloads": -1,
            "filename": "betfairlightweight-2.20.1.tar.gz",
            "has_sig": false,
            "md5_digest": "4eb6885a3facd4c568462bc98c15b157",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 218732,
            "upload_time": "2024-03-12T09:38:09",
            "upload_time_iso_8601": "2024-03-12T09:38:09.233840Z",
            "url": "https://files.pythonhosted.org/packages/21/3b/aec960e73e204e6ac4c6b8f0c91dacc9da112a8626f21220e0a5d30c79da/betfairlightweight-2.20.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-12 09:38:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "betcode-org",
    "github_project": "betfair",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    "<",
                    "2.32.0"
                ]
            ]
        },
        {
            "name": "black",
            "specs": [
                [
                    "==",
                    "24.2.0"
                ]
            ]
        },
        {
            "name": "coverage",
            "specs": []
        },
        {
            "name": "mkdocs",
            "specs": []
        },
        {
            "name": "mkdocs-material",
            "specs": []
        },
        {
            "name": "build",
            "specs": []
        },
        {
            "name": "twine",
            "specs": []
        }
    ],
    "lcname": "betfairlightweight"
}
        
Elapsed time: 0.22304s