Betfair
Betfair sports betting exchange integration adapter.
This subpackage provides an instrument provider, data and execution clients, configurations, data types and constants for connecting to and interacting with Betfairs’s API.
For convenience, the most commonly used symbols
are re-exported at the subpackage’s top level, so
downstream code can simply import from
posei_trader.adapters.betfair
.
class BetfairDataClientConfig
Bases:
LiveDataClientConfig
Configuration for
BetfairDataClient
instances.
-
Parameters:
- account_currency (str) – The currency for the Betfair account.
- username (str , optional) – The Betfair account username.
- password (str , optional) – The Betfair account password.
- app_key (str , optional) – The Betfair application key.
- cert_dir (str , optional) – The local directory that contains the Betfair certificates.
- instrument_config (BetfairInstrumentProviderConfig , None) – The Betfair instrument provider config.
- subscription_delay_secs (PositiveInt , default 3) – The delay (seconds) before sending the initial subscription message.
- keep_alive_secs (PositiveInt , default 36_000 *(*10 hours )) – The keep alive interval (seconds) for the HTTP client.
- stream_conflate_ms (PositiveInt , optional) – The Betfair data stream conflation setting. Default of None means no explicit value is set for the conflation interval. Betfair interprets this as using its default behaviour for conflation. The default typically applies conflation, so you need to ensure stream_conflate_ms=0 is explicitly set to guarantee no conflation.
account_currency : str
app_key : str | None
certs_dir : str | None
instrument_config : BetfairInstrumentProviderConfig | None
keep_alive_secs : Annotated[int, msgspec.Meta(gt=0)]
password : str | None
stream_conflate_ms : Annotated[int, msgspec.Meta(gt=0)] | None
subscription_delay_secs : Annotated[int, msgspec.Meta(gt=0)] | None
username : str | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
classmethod fully_qualified_name() → str
Return the fully qualified name for the NautilusConfig class.
- Return type: str
handle_revised_bars : bool
property id : str
Return the hashed identifier for the configuration.
- Return type: str
instrument_provider : InstrumentProviderConfig
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
classmethod json_schema() → dict[str, Any]
Generate a JSON schema for this configuration class.
- Return type: dict[str, Any]
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
-
Parameters:
- cls (type) – The type to decode to.
- raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type: Any
routing : RoutingConfig
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
class BetfairExecClientConfig
Bases:
LiveExecClientConfig
Configuration for
BetfairExecClient
instances.
-
Parameters:
- account_currency (str) – The currency for the Betfair account.
- username (str , optional) – The Betfair account username.
- password (str , optional) – The Betfair account password.
- app_key (str , optional) – The Betfair application key.
- certs_dir (str , optional) – The local directory that contains the Betfair certificates.
- instrument_config (BetfairInstrumentProviderConfig , None) – The Betfair instrument provider config.
- calculate_account_state (bool , default True) – If the Betfair account state should be calculated from events.
- request_account_state_secs (NonNegativeInt , default 300 *(*5 minutes )) – The request interval (seconds) for account state checks. If zero, then will not request account state from Betfair.
- reconcile_market_ids_only (bool , default False) – If True, reconciliation only requests orders matching the market IDs listed in the instrument_config. If False, all orders are reconciled.
- ignore_external_orders (bool , default False) – If True, orders received over the stream that aren’t found in the cache will be silently ignored. This is useful when multiple trading nodes share the same Betfair account across different markets.
account_currency : str
app_key : str | None
calculate_account_state : bool
certs_dir : str | None
ignore_external_orders : bool
instrument_config : BetfairInstrumentProviderConfig | None
password : str | None
reconcile_market_ids_only : bool
request_account_state_secs : Annotated[int, msgspec.Meta(ge=0)]
username : str | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
classmethod fully_qualified_name() → str
Return the fully qualified name for the NautilusConfig class.
- Return type: str
property id : str
Return the hashed identifier for the configuration.
- Return type: str
instrument_provider : InstrumentProviderConfig
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes
json_primitives() → dict[str, Any]
Return a dictionary representation of the configuration with JSON primitive types as values.
- Return type: dict[str, Any]
classmethod json_schema() → dict[str, Any]
Generate a JSON schema for this configuration class.
- Return type: dict[str, Any]
classmethod parse(raw: bytes | str) → Any
Return a decoded object of the given cls.
-
Parameters:
- cls (type) – The type to decode to.
- raw (bytes or str) – The raw bytes or JSON string to decode.
- Return type: Any
routing : RoutingConfig
validate() → bool
Return whether the configuration can be represented as valid JSON.
- Return type: bool
class BetfairInstrumentProvider
Bases:
InstrumentProvider
Provides a means of loading BettingInstruments from the Betfair APIClient.
-
Parameters:
- client (BetfairHttpClient) – The Betfair HTTP client for the provider.
- config (InstrumentProviderConfig) – The configuration for the provider.
add(instrument: Instrument) → None
Add the given instrument to the provider.
- Parameters: instrument (Instrument) – The instrument to add.
add_bulk(instruments: list[Instrument]) → None
Add the given instruments bulk to the provider.
- Parameters: instruments (list [Instrument ]) – The instruments to add.
add_currency(currency: Currency) → None
Add the given currency to the provider.
- Parameters: currency (Currency) – The currency to add.
property count : int
Return the count of instruments held by the provider.
- Return type: int
currencies() → dict[str, Currency]
Return all currencies held by the instrument provider.
- Return type: dict[str, Currency]
currency(code: str) → Currency | None
Return the currency with the given code (if found).
- Parameters: code (str) – The currency code.
-
Return type: Currency or
None
- Raises: ValueError – If code is not a valid string.
find(instrument_id: InstrumentId) → Instrument | None
Return the instrument for the given instrument ID (if found).
- Parameters: instrument_id (InstrumentId) – The ID for the instrument
-
Return type: Instrument or
None
async get_account_currency() → str
get_all() → dict[InstrumentId, Instrument]
Return all loaded instruments as a map keyed by instrument ID.
If no instruments loaded, will return an empty dict.
- Return type: dict[InstrumentId, Instrument]
async initialize(reload: bool = False) → None
Initialize the instrument provider.
- Parameters: reload (bool , default False) – If True, then will always reload instruments. If False, then will immediately return if already loaded.
list_all() → list[Instrument]
Return all loaded instruments.
- Return type: list[Instrument]
load(instrument_id: InstrumentId, filters: dict | None = None) → None
Load the instrument for the given ID into the provider, optionally applying the given filters.
-
Parameters:
- instrument_id (InstrumentId) – The instrument ID to load.
- filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
load_all(filters: dict | None = None) → None
Load the latest instruments into the provider, optionally applying the given filters.
- Parameters: filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
async load_all_async(filters: dict | None = None)
Load the latest instruments into the provider asynchronously, optionally applying the given filters.
async load_async(instrument_id: InstrumentId, filters: dict | None = None)
Load the instrument for the given ID into the provider asynchronously, optionally applying the given filters.
-
Parameters:
- instrument_id (InstrumentId) – The instrument ID to load.
- filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
- Raises: ValueError – If instrument_id.venue is not equal to self.venue.
load_ids(instrument_ids: list[InstrumentId], filters: dict | None = None) → None
Load the instruments for the given IDs into the provider, optionally applying the given filters.
-
Parameters:
- instrument_ids (list [InstrumentId ]) – The instrument IDs to load.
- filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
async load_ids_async(instrument_ids: list[InstrumentId], filters: dict | None = None) → None
Load the instruments for the given IDs into the provider, optionally applying the given filters.
-
Parameters:
- instrument_ids (list [InstrumentId ]) – The instrument IDs to load.
- filters (frozendict *[*str , Any ] or dict *[*str , Any ] , optional) – The venue specific instrument loading filters to apply.
- Raises: ValueError – If any instrument_id.venue is not equal to self.venue.
class BetfairInstrumentProviderConfig
Bases:
InstrumentProviderConfig
Configuration for
BetfairInstrumentProvider
instances.
-
Parameters:
- account_currency (str) – The Betfair account currency.
- default_min_notional (PositiveFloat , optional) – The default minimum notional value for instrument definitions (in account currency).
- event_type_ids (list *[*int ] , optional) – The event type IDs to filter for.
- event_ids (list *[*int ] , optional) – The event IDs to filter for.
- market_ids (list *[*str ] , optional) – The market IDs to filter for.
- country_codes (list *[*str ] , optional) – The country codes to filter for.
- market_types (list *[*str ] , optional) – The market types to filter for.
- min_market_start_time (pd.Timestamp , optional) – The minimum market start time (UTC) to filter from (date granularity only).
- max_market_start_time (pd.Timestamp , optional) – The maximum market start time (UTC) to filter to (date granularity only).
account_currency : str
country_codes : list[str] | None
default_min_notional : Annotated[float, msgspec.Meta(gt=0.0)] | None
event_ids : list[int] | None
event_type_ids : list[int] | None
event_type_names : list[str] | None
market_ids : list[str] | None
market_types : list[str] | None
max_market_start_time : Timestamp | None
min_market_start_time : Timestamp | None
dict() → dict[str, Any]
Return a dictionary representation of the configuration.
- Return type: dict[str, Any]
filter_callable : str | None
filters : dict[str, Any] | None
classmethod fully_qualified_name() → str
Return the fully qualified name for the NautilusConfig class.
- Return type: str
property id : str
Return the hashed identifier for the configuration.
- Return type: str
json() → bytes
Return serialized JSON encoded bytes.
- Return type: bytes