Skip to main content

Betting trading framework

Project description

flūmine

Build Status Coverage Status PyPI version Downloads

flumine is an open-source, event-based trading framework for sports betting, designed to simplify the development and execution of betting strategies on betting venues. flumine provides efficient handling of data streams, risk management, and execution capabilities.

docs

join betcode slack group (2.5k+ members!)

overview

  • Event-based Execution: Real-time execution of trading strategies based on incoming market events
  • Custom Strategy Implementation: Easily define and implement trading strategies
  • Risk Management: Integrated risk management tools to monitor and limit exposure
  • Modular Design: Easily extendable and customizable components
  • Simulation: Simulate strategies/execution using historical data
  • Paper Trading: Test strategies in a simulated environment before going live
  • Data: Support for market, order and custom streaming data
  • Venues: Multi venue / concurrent venue support

venues

  • Betfair
  • Betdaq
  • Betconnect (account/execution functionality)
  • Smarkets (roadmap)
  • Matchbook (roadmap)
  • Polymarket (roadmap)
  • Kalshi (roadmap)
  • BetDEX (roadmap)

Backtesting Analysis

Tested on Python 3.9, 3.10, 3.11, 3.12, 3.13 and 3.14.

installation

$ pip install flumine

flumine requires Python 3.9+

setup

Get started...

import betfairlightweight
from flumine import Flumine, BaseStrategy, clients
from flumine.streams.betfairmarketstream import BetfairMarketStream
from betfairlightweight.filters import streaming_market_filter

# Define your strategy here
class ExampleStrategy(BaseStrategy):
    def check_market_book(self, market, market_book) -> bool:
        # process_market_book only executed if this returns True
        return True

    def process_market_book(self, market, market_book):
        # Your strategy logic
        pass

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

# Initialize the framework
framework = Flumine(client)

# Create stream(s) (market data)
stream = BetfairMarketStream(
    framework,
    market_filter=streaming_market_filter(
        event_type_ids=["7"],
        country_codes=["GB"],
        market_types=["WIN"],
    ),
)
framework.add_stream(stream)

# Add your strategy to the framework with a stream
framework.add_strategy(
    ExampleStrategy(streams=[stream])
)

# Start the trading framework
framework.run()

Example strategy with logic and order execution:

import betfairlightweight
from flumine import Flumine, BaseStrategy, clients
from flumine.order.trade import Trade
from flumine.order.order import LimitOrder, OrderStatus
from flumine.markets.market import Market
from flumine.streams.betfairmarketstream import BetfairMarketStream
from betfairlightweight.filters import streaming_market_filter
from betfairlightweight.resources import MarketBook


class ExampleStrategy(BaseStrategy):
    def start(self, flumine) -> 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


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

# Initialize the framework
framework = Flumine(client)

# Create stream(s) (market data)
stream = BetfairMarketStream(
    framework,
    market_filter=streaming_market_filter(
        event_type_ids=["7"],
        country_codes=["GB"],
        market_types=["WIN"],
    ),
)
framework.add_stream(stream)

# Add your strategy to the framework with a stream
framework.add_strategy(
    ExampleStrategy(streams=[stream])
)

# Start the trading 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
  • betdaq-retail - BETDAQ API support
  • betconnect - BetConnect 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-3.0.0b1.tar.gz (3.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flumine-3.0.0b1-py3-none-any.whl (89.4 kB view details)

Uploaded Python 3

File details

Details for the file flumine-3.0.0b1.tar.gz.

File metadata

  • Download URL: flumine-3.0.0b1.tar.gz
  • Upload date:
  • Size: 3.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for flumine-3.0.0b1.tar.gz
Algorithm Hash digest
SHA256 b1a87e54e07df85578275790dd7d6de9a6de3c2831e89aa8d1a31779c59a9abd
MD5 368a6bc0ba167b23f8b1d7e4110f9fe6
BLAKE2b-256 312c5b4cd132eb15a2ee9e697d70ae87a8277081c1e0fabfca56727eddbdfc73

See more details on using hashes here.

File details

Details for the file flumine-3.0.0b1-py3-none-any.whl.

File metadata

  • Download URL: flumine-3.0.0b1-py3-none-any.whl
  • Upload date:
  • Size: 89.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for flumine-3.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b5e090918ad2a716ab73adcd95f77ca2ee585999485cfffbf18a2423eb7311e
MD5 05fcca4971b05dfe397aeb00967c796a
BLAKE2b-256 289c15a98e7d878a47d530fc2f532c009acb7f8f046912cb30d280764edd90bd

See more details on using hashes here.

Supported by

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