Skip to content

Commit 80ff201

Browse files
authored
Merge pull request #10 from TexasCoding:refactoring_14
feat(orderbook): fix volume accumulation and enhance market structure analytics
2 parents 7ed0dac + 1079356 commit 80ff201

File tree

12 files changed

+843
-421
lines changed

12 files changed

+843
-421
lines changed

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Old implementations are removed when improved
1414
- Clean, modern code architecture is prioritized
1515

16+
## [1.1.4] - 2025-01-30
17+
18+
### Fixed
19+
- **📊 OrderBook Volume Accumulation**: Fixed critical bug where market depth updates were accumulating volumes instead of replacing them
20+
- Market depth updates now correctly replace volume at price levels rather than adding to them
21+
- Resolved extremely high volume readings that were incorrect
22+
- Fixed handling of DomType 3/4 (BestBid/BestAsk) vs regular bid/ask updates
23+
24+
- **📈 OHLCV Volume Interpretation**: Fixed misinterpretation of GatewayQuote volume field
25+
- GatewayQuote volume represents daily total, not individual trade volume
26+
- OHLCV bars now correctly show volume=0 for quote-based updates
27+
- Prevents unrealistic volume spikes (e.g., 29,000+ per 5-second bar)
28+
29+
- **🔍 Trade Classification**: Improved trade side classification accuracy
30+
- Now captures bid/ask prices BEFORE orderbook update for correct classification
31+
- Uses historical spread data to properly classify trades as buy/sell
32+
- Added null handling for edge cases
33+
34+
### Enhanced
35+
- **🧊 Iceberg Detection**: Added price level refresh history tracking
36+
- OrderBook now maintains history of volume updates at each price level
37+
- Tracks up to 50 updates per price level over 30-minute windows
38+
- Enhanced `detect_iceberg_orders` to use historical refresh patterns
39+
- Added `get_price_level_history()` method for analysis
40+
41+
- **📊 Market Structure Analysis**: Refactored key methods to use price level history
42+
- `get_support_resistance_levels`: Now identifies persistent levels based on order refresh patterns
43+
- `detect_order_clusters`: Finds price zones with concentrated historical activity
44+
- `get_liquidity_levels`: Detects "sticky" liquidity that reappears after consumption
45+
- All methods now provide institutional-grade analytics based on temporal patterns
46+
47+
### Added
48+
- **🔧 Debug Scripts**: New diagnostic tools for market data analysis
49+
- `working_market_depth_debug.py`: Comprehensive DOM type analysis
50+
- `test_trade_classification.py`: Verify trade side classification
51+
- `test_enhanced_iceberg.py`: Test iceberg detection with history
52+
- `test_refactored_methods.py`: Verify all refactored analytics
53+
54+
### Technical Details
55+
- Price level history stored as `dict[tuple[float, str], list[dict]]` with timestamp and volume
56+
- Support/resistance now uses composite strength score (40% refresh count, 30% volume, 20% rate, 10% consistency)
57+
- Order clusters detect "magnetic" price levels with persistent order placement
58+
- Liquidity detection finds market maker zones with high refresh rates
59+
1660
## [1.1.3] - 2025-01-29
1761

1862
### Fixed

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ This Python SDK acts as a bridge between your trading strategies and the Project
2424

2525
**IMPORTANT**: This project is under active development. New updates may introduce breaking changes without backward compatibility. During this development phase, we prioritize clean, modern code architecture over maintaining legacy implementations.
2626

27-
**Current Version**: v1.1.3 (Contract Selection & Interactive Demo)
27+
**Current Version**: v1.1.4 (Contract Selection & Interactive Demo)
2828

2929
**Production Ready SDK Components**:
3030
- Complete ProjectX Gateway API integration with connection pooling
3131
- Historical and real-time market data APIs with intelligent caching
3232
- 55+ technical indicators with computation caching (Full TA-Lib compatibility)
33-
- Institutional-grade orderbook analysis tools with memory management and dynamic tick size detection
33+
- Institutional-grade orderbook analysis with price level history tracking
3434
- Portfolio and risk management APIs
35+
- **NEW v1.1.4**: Fixed orderbook volume accumulation and OHLCV interpretation
36+
- **NEW v1.1.4**: Enhanced iceberg detection with refresh pattern analysis
37+
- **NEW v1.1.4**: Market structure analytics based on temporal patterns
3538
- **NEW**: 50-70% performance improvements through optimization
3639
- **NEW**: 60% memory usage reduction with sliding windows
3740
- **NEW**: Sub-second response times for cached operations
@@ -310,9 +313,15 @@ orderbook = create_orderbook("MGC", project_x=client) # Uses real instrument me
310313
depth_snapshot = orderbook.get_orderbook_snapshot()
311314
best_prices = orderbook.get_best_bid_ask()
312315

313-
# Advanced analysis
314-
iceberg_orders = orderbook.detect_iceberg_orders()
315-
imbalance = orderbook.calculate_order_imbalance()
316+
# Advanced analysis with price level history
317+
iceberg_orders = orderbook.detect_iceberg_orders() # Now uses refresh patterns
318+
support_resistance = orderbook.get_support_resistance_levels() # Persistent levels
319+
order_clusters = orderbook.detect_order_clusters() # Historical activity zones
320+
liquidity_levels = orderbook.get_liquidity_levels(min_volume=5) # Sticky liquidity
321+
322+
# Price level history tracking
323+
history_stats = orderbook.get_price_level_history()
324+
print(f"Tracked levels: {history_stats['total_tracked_levels']}")
316325

317326
# Monitor memory usage
318327
memory_stats = orderbook.get_memory_stats()
@@ -611,7 +620,7 @@ We welcome contributions! Please follow these guidelines:
611620

612621
## 📝 Changelog
613622

614-
### Version 1.1.3 (Latest) - 2025-01-29
623+
### Version 1.1.4 (Latest) - 2025-01-29
615624
**🔧 Contract Selection & Interactive Tools**
616625

617626
**Breaking Changes:**

docs/api/orderbook.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ Advanced Level 2 orderbook management and market microstructure analysis.
66
Overview
77
--------
88

9-
The OrderBook class provides institutional-grade orderbook analytics for real-time market depth analysis. It includes advanced features like iceberg order detection, market imbalance analysis, volume profiling, and dynamic support/resistance identification.
9+
The OrderBook class provides institutional-grade orderbook analytics for real-time market depth analysis. It includes advanced features like iceberg order detection with price level history tracking, market imbalance analysis, volume profiling, and dynamic support/resistance identification based on temporal patterns.
10+
11+
**New in v1.1.4**: Enhanced analytics using price level refresh history for detecting persistent levels, iceberg orders, and market maker activity zones.
1012

1113
.. currentmodule:: project_x_py
1214

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
project = "project-x-py"
2424
copyright = "2025, Jeff West"
2525
author = "Jeff West"
26-
release = "1.1.3"
27-
version = "1.1.3"
26+
release = "1.1.4"
27+
version = "1.1.4"
2828

2929
# -- General configuration ---------------------------------------------------
3030

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "project-x-py"
3-
version = "1.1.3"
3+
version = "1.1.4"
44
description = "High-performance Python SDK for futures trading with real-time WebSocket data, technical indicators, order management, and market depth analysis"
55
readme = "README.md"
66
license = { text = "MIT" }
@@ -34,6 +34,7 @@ dependencies = [
3434
"polars>=1.31.0", # TODO: Update to 1.31.0
3535
"pytz>=2025.2",
3636
"requests>=2.32.4",
37+
"rich>=14.1.0",
3738
"signalrcore>=0.9.5",
3839
"websocket-client>=1.0.0",
3940
]

src/project_x_py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from typing import Any, Optional
2525

26-
__version__ = "1.1.3"
26+
__version__ = "1.1.4"
2727
__author__ = "TexasCoding"
2828

2929
# Core client classes

src/project_x_py/indicators/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
)
135135

136136
# Version info
137-
__version__ = "1.1.3"
137+
__version__ = "1.1.4"
138138
__author__ = "TexasCoding"
139139

140140

0 commit comments

Comments
 (0)