Skip to content

Commit

Permalink
Dropping py3.9 support and syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ml31415 committed May 3, 2024
1 parent 9f8fd43 commit 5a1bf4f
Show file tree
Hide file tree
Showing 22 changed files with 588 additions and 616 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12']
name: build - Python ${{ matrix.python-version }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}

Expand Down
25 changes: 12 additions & 13 deletions betfair_parser/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"""

from collections import defaultdict
from typing import Optional, Union

from betfair_parser.spec.streaming import (
LPV,
Expand Down Expand Up @@ -78,12 +77,12 @@ def __init__(self) -> None:
self.best_display_available_to_lay: dict[int, LPV] = {}
self.starting_price_back: dict[float, float] = {}
self.starting_price_lay: dict[float, float] = {}
self.starting_price_near: Optional[float] = None
self.starting_price_far: Optional[float] = None
self.starting_price_near: float | None = None
self.starting_price_far: float | None = None
self.traded: dict[float, float] = {}
self.last_traded_price: Optional[float] = None
self.total_volume: Optional[float] = None
self.handicap: Optional[float] = None
self.last_traded_price: float | None = None
self.total_volume: float | None = None
self.handicap: float | None = None

def update(self, rc: RunnerChange) -> None:
if rc.atb:
Expand Down Expand Up @@ -136,13 +135,13 @@ def __repr__(self) -> str:


class ChangeCache:
clk: Optional[str] = None
initial_clk: Optional[str] = None
publish_time: Optional[int] = None
stream_unreliable: Optional[bool] = False
conflate_ms: Optional[int] = None
clk: str | None = None
initial_clk: str | None = None
publish_time: int | None = None
stream_unreliable: bool | None = False
conflate_ms: int | None = None

def update_meta(self, msg: Union[MCM, OCM]) -> None:
def update_meta(self, msg: MCM | OCM) -> None:
if msg.initial_clk:
self.initial_clk = msg.initial_clk
if msg.clk:
Expand Down Expand Up @@ -218,7 +217,7 @@ def __init__(self) -> None:
self.matched_lays: dict[float, float] = {}
self.unmatched_orders: dict[int, Order] = {}
self.executed_orders: dict[int, Order] = {} # Does only contain recently completed orders
self.handicap: Optional[float] = None
self.handicap: float | None = None

def update(self, orc: OrderRunnerChange) -> None:
if orc.hc:
Expand Down
21 changes: 10 additions & 11 deletions betfair_parser/spec/accounts/operations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import partial
from typing import Optional

from betfair_parser.exceptions import AccountAPINGException
from betfair_parser.spec.accounts.enums import IncludeItem, Wallet
Expand All @@ -21,36 +20,36 @@ class _AccountRequest(Request, frozen=True, tag_field="method", tag=accounts_tag


class _GetAccountFundsParams(Params, frozen=True):
wallet: Optional[Wallet] = None # Name of the wallet in question. Global wallet is returned by default
wallet: Wallet | None = None # Name of the wallet in question. Global wallet is returned by default


class GetAccountFunds(_AccountRequest, kw_only=True, frozen=True):
"""Returns the available to bet amount, exposure and commission information."""

params: Optional[_GetAccountFundsParams] = None
params: _GetAccountFundsParams | None = None
return_type = Response[AccountFundsResponse]


class GetAccountDetails(_AccountRequest, kw_only=True, frozen=True):
"""Returns the details relating your account, including your discount rate and Betfair point balance."""

params: Optional[Params] = None
params: Params | None = None
return_type = Response[AccountDetailsResponse]


class _GetAccountStatementParams(Params, frozen=True):
locale: Optional[str] = None # The language to be used where applicable. Defaults to account settings
from_record: Optional[int] = None # Specifies the first record that will be returned, defaults to 0
record_count: Optional[int] = None # Specifies the maximum number of records to be returned. Maximum 100
locale: str | None = None # The language to be used where applicable. Defaults to account settings
from_record: int | None = None # Specifies the first record that will be returned, defaults to 0
record_count: int | None = None # Specifies the maximum number of records to be returned. Maximum 100

# Return items with an itemDate within this date range. Both from and to date times are inclusive.
# If from is not specified then the oldest available items will be in range. If to is not specified
# then the latest items will be in range. nb. This itemDataRange is currently only applied when
# includeItem is set to ALL or not specified, else items are NOT bound by itemDate.
# Please note: You can only retrieve account statement items for the last 90 days.
item_date_range: Optional[TimeRange] = None
include_item: Optional[IncludeItem] = None # Which items to include, if not specified then defaults to ALL.
wallet: Optional[Wallet] = None # Which wallet to return statementItems for. Defaults to UK
item_date_range: TimeRange | None = None
include_item: IncludeItem | None = None # Which items to include, if not specified then defaults to ALL.
wallet: Wallet | None = None # Which wallet to return statementItems for. Defaults to UK


class GetAccountStatement(_AccountRequest, kw_only=True, frozen=True):
Expand All @@ -61,7 +60,7 @@ class GetAccountStatement(_AccountRequest, kw_only=True, frozen=True):


class _ListCurrencyRatesParams(Params, frozen=True):
from_currency: Optional[str] = None # The currency from which the rates are computed. Only GBP for now.
from_currency: str | None = None # The currency from which the rates are computed. Only GBP for now.


class ListCurrencyRates(_AccountRequest, kw_only=True, frozen=True):
Expand Down
146 changes: 72 additions & 74 deletions betfair_parser/spec/accounts/type_definitions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from betfair_parser.spec.accounts.enums import (
AffiliateRelationStatus,
ItemClass,
Expand All @@ -15,46 +13,46 @@ class ApplicationSubscription(BaseMessage, frozen=True):
"""Application subscription details"""

subscription_token: str # Application key identifier
expiry_date_time: Optional[Date] = None
expired_date_time: Optional[Date] = None
created_date_time: Optional[Date] = None
activation_date_time: Optional[Date] = None
cancellation_date_time: Optional[Date] = None
subscription_status: Optional[SubscriptionStatus] = None
client_reference: Optional[str] = None
vendor_client_id: Optional[str] = None
expiry_date_time: Date | None = None
expired_date_time: Date | None = None
created_date_time: Date | None = None
activation_date_time: Date | None = None
cancellation_date_time: Date | None = None
subscription_status: SubscriptionStatus | None = None
client_reference: str | None = None
vendor_client_id: str | None = None


class SubscriptionHistory(BaseMessage, frozen=True):
"""Application subscription history details"""

subscription_token: str # Application key identifier
expiry_date_time: Optional[Date] = None
expired_date_time: Optional[Date] = None
created_date_time: Optional[Date] = None
activation_date_time: Optional[Date] = None
cancellation_date_time: Optional[Date] = None
subscription_status: Optional[SubscriptionStatus] = None
client_reference: Optional[str] = None
expiry_date_time: Date | None = None
expired_date_time: Date | None = None
created_date_time: Date | None = None
activation_date_time: Date | None = None
cancellation_date_time: Date | None = None
subscription_status: SubscriptionStatus | None = None
client_reference: str | None = None


class SubscriptionTokenInfo(BaseMessage, frozen=True):
"""Subscription token information"""

subscription_token: str
activated_date_time: Optional[Date] = None
expiry_date_time: Optional[Date] = None
expired_date_time: Optional[Date] = None
cancellation_date_time: Optional[Date] = None
subscription_status: Optional[SubscriptionStatus] = None
activated_date_time: Date | None = None
expiry_date_time: Date | None = None
expired_date_time: Date | None = None
cancellation_date_time: Date | None = None
subscription_status: SubscriptionStatus | None = None


class AccountSubscription(BaseMessage, frozen=True):
"""Application subscription details"""

subscription_tokens: list[SubscriptionTokenInfo]
application_name: Optional[str] = None
application_version_id: Optional[str] = None
application_name: str | None = None
application_version_id: str | None = None


class DeveloperAppVersion(BaseMessage, frozen=True):
Expand All @@ -77,10 +75,10 @@ class DeveloperAppVersion(BaseMessage, frozen=True):

# Public unique string provided to the Vendor that they can use to pass to the
# Betfair API in order to identify themselves.
vendor_id: Optional[str] = None
vendor_id: str | None = None
# Private unique string provided to the Vendor that they pass with certain calls
# to confirm their identity. Linked to a particular App Key.
vendor_secret: Optional[str] = None
vendor_secret: str | None = None


class DeveloperApp(BaseMessage, frozen=True):
Expand All @@ -94,103 +92,103 @@ class DeveloperApp(BaseMessage, frozen=True):
class AccountFundsResponse(BaseMessage, frozen=True):
"""Response for retrieving available to bet."""

available_to_bet_balance: Optional[float] = None
exposure: Optional[float] = None
retained_commission: Optional[float] = None # Sum of retained commission.
exposure_limit: Optional[float] = None
available_to_bet_balance: float | None = None
exposure: float | None = None
retained_commission: float | None = None # Sum of retained commission.
exposure_limit: float | None = None

# User Discount Rate. Please note: Betfair AUS/NZ customers should not rely on this to determine
# their discount rates which are now applied at the account level.
discount_rate: Optional[float] = None
points_balance: Optional[int] = None
discount_rate: float | None = None
points_balance: int | None = None

# This is not documented in the API description, but seems to be present anyway
wallet: Optional[Wallet] = None
wallet: Wallet | None = None


class AccountDetailsResponse(BaseMessage, frozen=True):
"""Response for Account details."""

# Default user currency Code. See Currency Parameters for minimum bet sizes relating to each currency.
currency_code: Optional[str] = None
first_name: Optional[str] = None
last_name: Optional[str] = None
locale_code: Optional[str] = None
currency_code: str | None = None
first_name: str | None = None
last_name: str | None = None
locale_code: str | None = None

# Region based on users zip/postcode (ISO 3166-1 alpha-3 format). Defaults to GBR if
# zip/postcode cannot be identified.
region: Optional[str] = None
timezone: Optional[str] = None # User Time Zone.
region: str | None = None
timezone: str | None = None # User Time Zone.

# User Discount Rate. Please note: Betfair AUS/NZ customers should not rely on this to
# determine their discount rates which are now applied at the account level.
discount_rate: Optional[float] = None
points_balance: Optional[int] = None # The Betfair points balance.
country_code: Optional[str] = None # The customer's country of residence (ISO 2 Char format)
discount_rate: float | None = None
points_balance: int | None = None # The Betfair points balance.
country_code: str | None = None # The customer's country of residence (ISO 2 Char format)


class StatementLegacyData(BaseMessage, frozen=True):
"""Summary of a cleared order."""

avg_price: Optional[float] # The average matched price of the bet (null if no part has been matched)
avg_price: float | None # The average matched price of the bet (null if no part has been matched)

# The amount of the stake of your bet. (0 for commission payments or deposit/withdrawals)
bet_size: Optional[float] = None
bet_type: Optional[str] = None # Back or lay
bet_category_type: Optional[str] = None # Exchange, Market on Close SP bet, or Limit on Close SP bet.
commission_rate: Optional[str] = None # Commission rate on market
event_id: Optional[int] = None # Please note: this is the Id of the market without the associated exchangeId
event_type_id: Optional[int] = None
bet_size: float | None = None
bet_type: str | None = None # Back or lay
bet_category_type: str | None = None # Exchange, Market on Close SP bet, or Limit on Close SP bet.
commission_rate: str | None = None # Commission rate on market
event_id: int | None = None # Please note: this is the Id of the market without the associated exchangeId
event_type_id: int | None = None

# Full Market Name. For card payment items, this field contains the card name
full_market_name: Optional[str] = None
gross_bet_amount: Optional[float] = None # The winning amount to which commission is applied.
full_market_name: str | None = None
gross_bet_amount: float | None = None # The winning amount to which commission is applied.

# Market Name. For card transactions, this field indicates the type of card
# transaction (deposit, deposit fee, or withdrawal).
market_name: Optional[str] = None
market_name: str | None = None

# Market type. For account deposits and withdrawals, marketType is set to NOT_APPLICABLE.
market_type: Optional[str] = None
placed_date: Optional[Date] = None # Date and time of bet placement
market_type: str | None = None
placed_date: Date | None = None # Date and time of bet placement

# Id of the selection (this will be the same for the same selection across markets)
selection_id: Optional[int] = None
selection_name: Optional[str] = None # Name of the selection
start_date: Optional[Date] = None # Date and time at the bet portion was settled
transaction_type: Optional[str] = None # Debit or credit
transaction_id: Optional[int] = None # The unique reference Id assigned to account deposit and withdrawals.
win_lose: Optional[WinLose] = None
selection_id: int | None = None
selection_name: str | None = None # Name of the selection
start_date: Date | None = None # Date and time at the bet portion was settled
transaction_type: str | None = None # Debit or credit
transaction_id: int | None = None # The unique reference Id assigned to account deposit and withdrawals.
win_lose: WinLose | None = None

# In the instance of a dead heat, this field will indicate the number of winners
# involved in the dead heat (null otherwise)
dead_heat_price_divisor: Optional[float] = None
dead_heat_price_divisor: float | None = None

# Currently returns same value as avgPrice. Once released will display the average matched
# price of the bet with no rounding applied
avg_price_raw: Optional[float] = None
avg_price_raw: float | None = None


class StatementItem(BaseMessage, kw_only=True, frozen=True):
"""Summary of a cleared order."""

# An external reference, eg. equivalent to betId in the case of an exchange bet statement item.
ref_id: Optional[str] = None
ref_id: str | None = None

# The date and time of the statement item, eg. equivalent to settledData for an exchange
# bet statement item. (in ISO-8601 format, not translated)
item_date: Date
amount: Optional[float] = None # The amount of money the balance is adjusted by
balance: Optional[float] = None
amount: float | None = None # The amount of money the balance is adjusted by
balance: float | None = None

# Class of statement item. This value will determine which set of keys will be included in itemClassData
item_class: Optional[ItemClass] = None
item_class: ItemClass | None = None
# Key value pairs describing the current statement item. The set of keys will be
# determined by the itemClass
item_class_data: Optional[dict[str, str]] = None
item_class_data: dict[str, str] | None = None
# Set of fields originally returned from APIv6. Provided to facilitate migration from
# APIv6 to API-NG, and ultimately onto itemClass and itemClassData
legacy_data: Optional[StatementLegacyData] = None
legacy_data: StatementLegacyData | None = None


class AccountStatementReport(BaseMessage, frozen=True):
Expand All @@ -201,8 +199,8 @@ class AccountStatementReport(BaseMessage, frozen=True):


class CurrencyRate(BaseMessage, frozen=True):
currency_code: Optional[str] = None # Three-letter ISO 4217 code
rate: Optional[float] = None # Exchange rate for the currency specified in the request
currency_code: str | None = None # Three-letter ISO 4217 code
rate: float | None = None # Exchange rate for the currency specified in the request


class AuthorisationResponse(BaseMessage, frozen=True):
Expand All @@ -219,12 +217,12 @@ class SubscriptionOptions(BaseMessage, frozen=True, rename=None):

# How many days should a created subscription last for. Open-ended subscription created
# if value not provided. Relevant only if createdSubscription is true.
subscription_length: Optional[int] = None
subscription_length: int | None = None

# An existing subscription token that the caller wishes to be activated instead of creating a new one.
# Ignored is createSubscription is true.
subscription_token: Optional[str] = None
client_reference: Optional[str] = None # Any client reference for this subscription token request.
subscription_token: str | None = None
client_reference: str | None = None # Any client reference for this subscription token request.


class VendorAccessTokenInfo(BaseMessage, frozen=True, rename=None):
Expand All @@ -249,7 +247,7 @@ class VendorDetails(BaseMessage, frozen=True):

app_version_id: int # Internal id of the application
vendor_name: str
redirect_url: Optional[str] = None # URL to be redirected to
redirect_url: str | None = None # URL to be redirected to


class AffiliateRelation(BaseMessage, frozen=True):
Expand Down
Loading

0 comments on commit 5a1bf4f

Please sign in to comment.