diff --git a/CHANGELOG.md b/CHANGELOG.md index dd6082d..443a530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Orderbook `get_statistics()` failed with "Analysis failed" under polars 2.0 + because `pl.count()` no longer accepts zero arguments. Trade-side counts now + use `pl.len()` (compatible with polars 1.31+ and 2.0). + ### Internal - Normalize Polars `Series.sum()` aggregates to `float`/`int` before diff --git a/src/project_x_py/orderbook/analytics.py b/src/project_x_py/orderbook/analytics.py index d18a5ac..5082938 100644 --- a/src/project_x_py/orderbook/analytics.py +++ b/src/project_x_py/orderbook/analytics.py @@ -592,7 +592,7 @@ async def get_statistics(self) -> dict[str, Any]: # Optimized: Single pass through data with aggregation trade_stats = self.orderbook.recent_trades.group_by("side").agg( [ - pl.count().alias("count"), + pl.len().alias("count"), pl.col("volume").sum().alias("total_volume"), ] ) diff --git a/tests/orderbook/test_orderbook_analytics.py b/tests/orderbook/test_orderbook_analytics.py index 18b9437..8b1dd8d 100644 --- a/tests/orderbook/test_orderbook_analytics.py +++ b/tests/orderbook/test_orderbook_analytics.py @@ -447,6 +447,9 @@ async def test_get_statistics(self, market_analytics): assert result["total_bid_size"] == 100 assert result["total_ask_size"] == 100 assert result["total_trades"] == 5 + # Fixture sides: buy, sell, buy, sell, buy + assert result["buy_trades"] == 3 + assert result["sell_trades"] == 2 class TestErrorHandling: