Skip to main content

Betting trading framework

Project description

flūmine

Build Status Coverage Status PyPI version Downloads

Betting trading framework with a focus on:

  • simplicity
  • modular
  • pythonic
  • rock-solid
  • safe

Backtesting Analysis

Support for market, order and custom streaming data.

docs

join betcode slack group

Tested on Python 3.8, 3.9, 3.10, 3.11 and 3.12.

installation

$ pip install flumine

flumine requires Python 3.8+

setup

Get started...

import betfairlightweight
from flumine import Flumine, clients

trading = betfairlightweight.APIClient("username")
client = clients.BetfairClient(trading)

framework = Flumine(
    client=client,
)

Example strategy:

from flumine import BaseStrategy
from flumine.order.trade import Trade
from flumine.order.order import LimitOrder, OrderStatus
from flumine.markets.market import Market
from betfairlightweight.filters import streaming_market_filter
from betfairlightweight.resources import MarketBook


class ExampleStrategy(BaseStrategy):
    def start(self) -> None:
        print("starting strategy 'ExampleStrategy'")

    def check_market_book(self, market: Market, market_book: MarketBook) -> bool:
        # process_market_book only executed if this returns True
        if market_book.status != "CLOSED":
            return True

    def process_market_book(self, market: Market, market_book: MarketBook) -> None:
        # process marketBook object
        for runner in market_book.runners:
            if runner.status == "ACTIVE" and runner.last_price_traded < 1.5:
                trade = Trade(
                    market_id=market_book.market_id,
                    selection_id=runner.selection_id,
                    handicap=runner.handicap,
                    strategy=self
                )
                order = trade.create_order(
                    side="LAY",
                    order_type=LimitOrder(price=1.01, size=2.00)
                )
                market.place_order(order)

    def process_orders(self, market: Market, orders: list) -> None:
        for order in orders:
            if order.status == OrderStatus.EXECUTABLE:
                if order.size_remaining == 2.00:
                    market.cancel_order(order, 0.02)  # reduce size to 1.98
                if order.order_type.persistence_type == "LAPSE":
                    market.update_order(order, "PERSIST")
                if order.size_remaining > 0:
                    market.replace_order(order, 1.02)  # move


strategy = ExampleStrategy(
    market_filter=streaming_market_filter(
        event_type_ids=["7"],
        country_codes=["GB"],
        market_types=["WIN"],
    )
)

framework.add_strategy(strategy)

Run framework:

framework.run()

Features

  • Streaming
  • Multiple strategies
  • Multiple clients
  • Order execution
  • Paper trading
  • Simulation
  • Event simulation (multi market)
  • Middleware and background workers to enable Scores / RaceCard / InPlayService

Dependencies

flumine relies on these libraries:

  • betfairlightweight - Betfair API support
  • tenacity - Used for connection retrying (streaming)
  • python-json-logger - JSON logging
  • requests - HTTP support
  • smart-open - Efficient streaming of very large files from/to storages such as S3, including (de)compression

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flumine-2.6.6.tar.gz (3.3 MB view details)

Uploaded Source

Built Distribution

flumine-2.6.6-py3-none-any.whl (79.3 kB view details)

Uploaded Python 3

File details

Details for the file flumine-2.6.6.tar.gz.

File metadata

  • Download URL: flumine-2.6.6.tar.gz
  • Upload date:
  • Size: 3.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for flumine-2.6.6.tar.gz
Algorithm Hash digest
SHA256 f3aa2d1f71e21c29c60c38bacd113a7b3de6e43ac0cec5010811afdc4d4e9ecc
MD5 9206930ebae618a22244a1164d57ffa6
BLAKE2b-256 a6f630d29a93be6f876c1dfbddf5b259d236e2c86565824c2e4e5f88098b55b6

See more details on using hashes here.

File details

Details for the file flumine-2.6.6-py3-none-any.whl.

File metadata

  • Download URL: flumine-2.6.6-py3-none-any.whl
  • Upload date:
  • Size: 79.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.18

File hashes

Hashes for flumine-2.6.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4428404dcdbd3c7a9f5eefa231b5127f31226b1cfcbb40207b49e77e5cb9d67f
MD5 f11492680c7ec1ab26ccb13181d047c2
BLAKE2b-256 26d9ceea87faaed1342b5f6da2ed246d2a62f91c5b2098f017f2f8e5912c8cd4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page