Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/project_x_py/orderbook/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
)
Expand Down
3 changes: 3 additions & 0 deletions tests/orderbook/test_orderbook_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading