Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close #550 #563

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand All @@ -21,10 +21,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Check setup.py
run: |
python setup.py check

- name: Install dependencies
run: |
pip install -r requirements.txt
Expand All @@ -47,7 +43,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -89,7 +85,7 @@ jobs:

- name: Build package and docs
run: |
python setup.py sdist bdist_wheel
python -m build
twine check dist/*
mkdocs build

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Lightweight, super fast (uses C and Rust libraries) pythonic wrapper for [Betfai

[join betcode slack group](https://join.slack.com/t/betcode-org/shared_invite/zt-25yz6dt1y-LHya5VzHLOzN3RZEQrSnrA)

Currently tested on Python 3.8, 3.9, 3.10 and 3.11.
Currently tested on Python 3.8, 3.9, 3.10, 3.11 and 3.12.

# installation

Expand Down
4 changes: 2 additions & 2 deletions betfairlightweight/resources/racecardresources.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def __init__(
surface=None,
ratingSymbol=None,
ratingvalue=None,
**kwargs
**kwargs,
):
self.racing_type = racingType
self.surface = surface
Expand Down Expand Up @@ -303,7 +303,7 @@ def __init__(
preRaceMasterRating=None,
preRaceWeightAdjustedMasterRating=None,
seasonMasterRating=None,
**kwargs
**kwargs,
):
self.age = age
self.comment = comment
Expand Down
7 changes: 5 additions & 2 deletions betfairlightweight/streaming/betfairstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ def _create_socket(self) -> socket.socket:
"""Creates ssl socket, connects to stream api and
sets timeout.
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = ssl.wrap_socket(s)
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
context.verify_mode = ssl.CERT_NONE
s = context.wrap_socket(
socket.socket(socket.AF_INET, socket.SOCK_STREAM), server_hostname=self.host
)
s.settimeout(self.timeout)
s.connect((self.host, self.__port))
return s
Expand Down
10 changes: 6 additions & 4 deletions betfairlightweight/streaming/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def __init__(
rc: str = None,
lsrc: str = None,
cd: int = None,
**kwargs
**kwargs,
):
self.publish_time = publish_time
self.bet_id = id
Expand Down Expand Up @@ -487,9 +487,11 @@ def serialise(
"marketId": market_id,
"matchedDate": self._matched_date_string,
"orderType": StreamingOrderType[self.order_type].value,
"persistenceType": StreamingPersistenceType[self.persistence_type].value
if self.persistence_type
else None,
"persistenceType": (
StreamingPersistenceType[self.persistence_type].value
if self.persistence_type
else None
),
"placedDate": self._placed_date_string,
"priceSize": {"price": self.price, "size": self.size},
"regulatorAuthCode": self.regulator_auth_code,
Expand Down
1 change: 0 additions & 1 deletion betfairlightweight/streaming/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ def _process(self, data: list, publish_time: int) -> bool:


class RaceStream(BaseStream):

"""
Cache contains latest update:
marketId: RaceCache
Expand Down
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "betfairlightweight"
description = "Lightweight python wrapper for Betfair API-NG"
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.8"
authors = [
{ name = "Liam Pauling", email = "[email protected]" },
]
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"requests<2.32.0",
]
dynamic = ["version"]

[project.optional-dependencies]
speed = [
"ciso8601==2.3.0",
"orjson==3.9.9",
]
test = [
"black==23.10.0",
"coverage",
"mkdocs",
"mkdocs-material",
"twine",
"wheel",
]

[project.urls]
Homepage = "https://github.com/betcode-org"
Documentation = "https://betcode-org.github.io/betfair/"
Repository = "https://github.com/betcode-org/betfair.git"
"Bug Tracker" = "https://github.com/betcode-org/betfair/issues"
Changelog = "https://github.com/betcode-org/betfair/blob/master/HISTORY.rst"

[tool.hatch.version]
path = "betfairlightweight/__version__.py"
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Tests & Linting
black==23.10.0
black==24.2.0
coverage

# Documentation
Expand Down
50 changes: 0 additions & 50 deletions setup.py

This file was deleted.

17 changes: 14 additions & 3 deletions tests/test_betfairstream.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import socket
import time
import ssl
import threading
from unittest import mock

Expand Down Expand Up @@ -252,13 +253,23 @@ def test_subscribe_to_cricket_matches(self, mock_send):
self.betfair_stream._unique_id, "cricketSubscription"
)

@mock.patch("ssl.wrap_socket")
@mock.patch("ssl.SSLContext")
@mock.patch("socket.socket")
def test_create_socket(self, mock_socket, mock_wrap_socket):
def test_create_socket(self, mock_socket, mock_ssl_context):
self.betfair_stream._create_socket()

mock_socket.assert_called_with(socket.AF_INET, socket.SOCK_STREAM)
assert mock_wrap_socket.call_count == 1
self.assertEqual(mock_ssl_context.call_count, 1)
mock_ssl_context.assert_called_with(ssl.PROTOCOL_TLS)
mock_ssl_context.return_value.wrap_socket.assert_called_with(
mock_socket.return_value, server_hostname="stream-api.betfair.com"
)
mock_ssl_context.return_value.wrap_socket.return_value.settimeout.assert_called_with(
6
)
mock_ssl_context.return_value.wrap_socket.return_value.connect.assert_called_with(
("stream-api.betfair.com", 443)
)

@mock.patch(
"betfairlightweight.streaming.betfairstream.BetfairStream._data",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def test_update_cache_new(self, mock_order_book_runner):
self.order_book_cache.market_id,
1234,
self.order_book_cache.lightweight,
**order_changes
**order_changes,
)

def test_update_cache_closed(self):
Expand Down
Loading