Skip to content

Commit

Permalink
Group all API symbols from spec / accounts,betting,streaming for easi…
Browse files Browse the repository at this point in the history
…er import
  • Loading branch information
ml31415 committed Sep 28, 2023
1 parent d6e082f commit b9d6d41
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 63 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ repos:
additional_dependencies: [msgspec, types-requests]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.290
rev: v0.0.291
hooks:
- id: ruff

- repo: https://github.com/asottile/pyupgrade
rev: v3.11.2
rev: v3.13.0
hooks:
- id: pyupgrade

Expand Down
40 changes: 39 additions & 1 deletion betfair_parser/spec/accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,39 @@
from betfair_parser.spec.accounts import enums, operations, type_definitions # noqa
from betfair_parser.spec.accounts import enums, operations, type_definitions
from betfair_parser.spec.accounts.enums import (
AffiliateRelationStatus,
GrantType,
IncludeItem,
ItemClass,
MarketType,
Status,
SubscriptionStatus,
TokenType,
Wallet,
WinLose,
)
from betfair_parser.spec.accounts.operations import (
GetAccountDetails,
GetAccountFunds,
GetAccountStatement,
ListCurrencyRates,
)
from betfair_parser.spec.accounts.type_definitions import (
AccountDetailsResponse,
AccountFundsResponse,
AccountStatementReport,
AccountSubscription,
AffiliateRelation,
ApplicationSubscription,
AuthorisationResponse,
CurrencyRate,
DeveloperApp,
DeveloperAppVersion,
StatementItem,
StatementLegacyData,
SubscriptionHistory,
SubscriptionOptions,
SubscriptionTokenInfo,
VendorAccessTokenInfo,
VendorDetails,
)
from betfair_parser.spec.common import TimeRange # noqa
98 changes: 97 additions & 1 deletion betfair_parser/spec/betting/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,97 @@
from betfair_parser.spec.betting import enums, operations, type_definitions # noqa
from betfair_parser.spec.betting import enums, operations, type_definitions
from betfair_parser.spec.betting.enums import (
BetStatus,
BetTargetType,
ExecutionReportErrorCode,
ExecutionReportStatus,
GroupBy,
InstructionReportErrorCode,
InstructionReportStatus,
MarketBettingType,
MarketProjection,
MarketSort,
MarketStatus,
MarketTypeCode,
MatchProjection,
OrderBy,
OrderProjection,
PersistenceType,
PriceData,
PriceLadderType,
RollupModel,
RunnerStatus,
Side,
SortDir,
TimeGranularity,
TimeInForce,
)
from betfair_parser.spec.betting.listings import (
ListCompetitions,
ListCountries,
ListEvents,
ListEventTypes,
ListMarketBook,
ListMarketCatalog,
ListMarketCatalogue,
ListMarketProfitAndLoss,
ListMarketTypes,
ListRunnerBook,
ListTimeRanges,
ListVenues,
)
from betfair_parser.spec.betting.orders import (
CancelOrders,
ListClearedOrders,
ListCurrentOrders,
PlaceOrders,
ReplaceOrders,
UpdateOrders,
)
from betfair_parser.spec.betting.type_definitions import (
CancelInstruction,
ClearedOrderSummary,
ClearedOrderSummaryReport,
Competition,
CompetitionResult,
CountryCodeResult,
CurrentItemDescription,
CurrentOrderSummary,
CurrentOrderSummaryReport,
Event,
EventResult,
EventType,
ExBestOffersOverrides,
ExchangePrices,
ItemDescription,
KeyLineDescription,
KeyLineSelection,
LimitOnCloseOrder,
LimitOrder,
MarketBook,
MarketCatalogue,
MarketDescription,
MarketFilter,
MarketLicence,
MarketLineRangeInfo,
MarketOnCloseOrder,
MarketRates,
MarketTypeResult,
MarketVersion,
Match,
Order,
PlaceExecutionReport,
PlaceInstruction,
PlaceInstructionReport,
PriceLadderDescription,
PriceProjection,
PriceSize,
ReplaceInstruction,
Runner,
RunnerCatalog,
RunnerMetaData,
StartingPrices,
TimeRangeResult,
UpdateInstruction,
VenueResult,
)
from betfair_parser.spec.common import EventTypeIdCode, OrderType, TimeRange # noqa for reimport
1 change: 0 additions & 1 deletion betfair_parser/spec/betting/enums.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from betfair_parser.spec.common import EventTypeIdCode # noqa for reimport
from betfair_parser.strenums import DocumentedEnum, StrEnum, auto, doc


Expand Down
35 changes: 32 additions & 3 deletions betfair_parser/spec/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
"""Shared definitions between the different API parts."""

from betfair_parser.spec.common.enums import * # noqa
from betfair_parser.spec.common.messages import * # noqa
from betfair_parser.spec.common.type_definitions import * # noqa
from betfair_parser.spec.common.enums import (
EndpointType,
EventTypeIdCode,
OrderResponse,
OrderSide,
OrderStatus,
OrderType,
RegulatorCode,
)
from betfair_parser.spec.common.messages import BaseMessage, BaseResponse, Params, Request, Response, decode, encode
from betfair_parser.spec.common.type_definitions import (
BetId,
CompetitionId,
CountryCode,
CustomerOrderRef,
CustomerRef,
CustomerStrategyRef,
Date,
EventId,
EventTypeId,
ExchangeId,
Handicap,
IDType,
MarketId,
MarketType,
MatchId,
Price,
SelectionId,
Size,
TimeRange,
Venue,
)
2 changes: 1 addition & 1 deletion betfair_parser/spec/common/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def decode(raw: bytes, type: Any = Any) -> Any:
try:
return msgspec.json.decode(raw, strict=False, type=type) # type: ignore
return msgspec.json.decode(raw, strict=False, type=type)
except msgspec.DecodeError as e:
raise JSONError(str(e)) from e

Expand Down
4 changes: 2 additions & 2 deletions betfair_parser/spec/common/type_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from betfair_parser.spec.common.messages import BaseMessage


Date = Annotated[datetime.datetime, msgspec.Meta(title="Date", tz=True)]
IDType = Annotated[
int, msgspec.Meta(title="IDType", description="integer data, but defined and encoded as string", ge=0)
]

# Type aliases with minimalistic validation.
# Type aliases as defined within the XML specification with minimalistic validation added.

Date = Annotated[datetime.datetime, msgspec.Meta(title="Date", tz=True)]
MarketType = Annotated[str, msgspec.Meta(title="MarketType")]
Venue = Annotated[str, msgspec.Meta(title="Venue")]
MarketId = Annotated[str, msgspec.Meta(title="MarketId")] # The only ID, that actually needs to be a string
Expand Down
48 changes: 36 additions & 12 deletions betfair_parser/spec/streaming/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

from msgspec.json import Decoder

from betfair_parser.spec.betting.enums import MarketBettingType # noqa: F401
from betfair_parser.spec.betting.enums import MarketStatus # noqa: F401
from betfair_parser.spec.betting.enums import MarketTypeCode # noqa: F401
from betfair_parser.spec.betting.enums import RunnerStatus # noqa: F401
from betfair_parser.spec.streaming.enums import ChangeType # noqa: F401
from betfair_parser.spec.streaming.enums import SegmentType # noqa: F401
from betfair_parser.spec.betting.enums import MarketBettingType, MarketStatus, MarketTypeCode, RunnerStatus # noqa
from betfair_parser.spec.streaming import enums, type_definitions
from betfair_parser.spec.streaming.enums import (
ChangeType,
LapseStatusReasonCode,
MarketDataFilterFields,
PriceLadderDefinitionType,
SegmentType,
StatusErrorCode,
)
from betfair_parser.spec.streaming.messages import (
MCM,
OCM,
Expand All @@ -18,12 +22,32 @@
OrderSubscription,
Status,
)
from betfair_parser.spec.streaming.type_definitions import MarketDataFilter # noqa: F401
from betfair_parser.spec.streaming.type_definitions import MarketDataFilterFields # noqa: F401
from betfair_parser.spec.streaming.type_definitions import MarketDefinition # noqa: F401
from betfair_parser.spec.streaming.type_definitions import MarketFilter # noqa: F401
from betfair_parser.spec.streaming.type_definitions import OrderFilter # noqa: F401
from betfair_parser.spec.streaming.type_definitions import RunnerChange # noqa: F401
from betfair_parser.spec.streaming.type_definitions import (
AvailableToBack,
AvailableToLay,
BestAvailableToBack,
BestAvailableToLay,
BestDisplayAvailableToBack,
BestDisplayAvailableToLay,
KeyLineDefinition,
KeyLineSelection,
MarketChange,
MarketDataFilter,
MarketDefinition,
MarketFilter,
MatchedOrder,
Order,
OrderFilter,
OrderMarketChange,
OrderRunnerChange,
PriceLadderDefinition,
RunnerChange,
RunnerDefinition,
StartingPriceBack,
StartingPriceLay,
StrategyMatchChange,
Trade,
)


STREAM_REQUEST = Union[Authentication, MarketSubscription, OrderSubscription, Heartbeat]
Expand Down
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ combine_as_imports = true
skip = "*.bz2,*.json,*.xml,poetry.lock"
ignore-regex = ".*codespell-ignore$"

[tool.ruff]
fix = false
line-length = 120

[tool.mypy]
strict_optional = false
ignore_missing_imports = true
warn_no_return = true
warn_unused_ignores = true
check_untyped_defs = true

[tool.ruff]
fix = false
line-length = 120

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]
2 changes: 1 addition & 1 deletion tests/integration/test_completeness.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_enum(spec, node):
min_values = 1 if xml_typename in ("Status", "ItemClass", "TokenType", "TimeInForce") else 2
assert len(valid_values) >= min_values
assert node.get("type") == "string"
for value_node in valid_values.iter("value"): # type: ignore
for value_node in valid_values.iter("value"):
value_name = value_node.get("name")
assert hasattr(datatype_cls, value_name), f"Enum field {xml_typename}.{value_name} not set"

Expand Down
Loading

0 comments on commit b9d6d41

Please sign in to comment.