Skip to content

Commit 39043ea

Browse files
authored
Merge pull request #46 from TexasCoding/patching_v4.1
Release v3.1.13 - Critical Event System Fixes
2 parents 7975f33 + ba46509 commit 39043ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3978
-1748
lines changed

CHANGELOG.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,52 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Migration guides will be provided for all breaking changes
1515
- Semantic versioning (MAJOR.MINOR.PATCH) is strictly followed
1616

17+
## [3.1.13] - 2025-08-15
18+
19+
### Fixed
20+
- **🎯 Event System Data Structure Mismatches**: Fixed critical order fill detection issues
21+
- Bracket orders now properly detect fills without timing out
22+
- Event handlers now correctly handle both `order_id` and nested `order` object structures
23+
- Added backward compatibility for different event payload formats
24+
- ManagedTrade now listens to correct events (ORDER_FILLED vs ORDER_MODIFIED)
25+
26+
- **📝 Type Annotations for SignalR Connections**: Improved IDE support and type safety
27+
- Created HubConnection type alias for BaseHubConnection
28+
- Fixed market_connection and user_connection from Any to proper types
29+
- IDEs now recognize connection methods (send, on, start, stop)
30+
- Updated ProjectXRealtimeClientProtocol to match implementation
31+
32+
- **🔧 Real-time Connection Improvements**: Enhanced WebSocket stability
33+
- Added circuit breaker pattern to BatchedWebSocketHandler
34+
- Improved subscription handling with proper event waiting
35+
- Fixed asyncio deprecation warnings (get_event_loop → get_running_loop)
36+
- Better error handling and recovery mechanisms
37+
38+
### Improved
39+
- **📊 Data Storage Robustness**: Major improvements to mmap_storage module
40+
- Fixed critical bug causing data overwrite on initialization
41+
- Implemented binary search for read_window (significant performance boost)
42+
- Added thread-safe operations with RLock
43+
- Fixed file corruption bug in _resize_file
44+
- Replaced print statements with proper logging
45+
46+
- **🧪 Test Coverage**: Dramatically improved client module testing
47+
- Client module coverage increased from 30% to 93%
48+
- Added 70+ comprehensive test cases across all client components
49+
- Fixed bug in _select_best_contract method
50+
- Full test coverage for base.py (100%) and trading.py (98%)
51+
52+
- **🏗️ Order and Position Management**: Enhanced tracking and stability
53+
- Improved order tracking with better event handling
54+
- More robust position manager logic
55+
- Better error recovery in order chains
56+
- Enhanced TradingSuite configuration options
57+
58+
### Documentation
59+
- Updated CHANGELOG.md with comprehensive v3.1.13 changes
60+
- Updated CLAUDE.md Recent Changes section
61+
- Added detailed commit messages for all fixes
62+
1763
## [3.1.12] - 2025-08-15
1864

1965
### Added

CLAUDE.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
44

5-
## Project Status: v3.1.9 - Stable Production Release
5+
## Project Status: v3.1.13 - Stable Production Release
66

77
**IMPORTANT**: This project uses a fully asynchronous architecture. All APIs are async-only, optimized for high-performance futures trading.
88

@@ -162,6 +162,18 @@ uv run python -m build # Alternative build command
162162
- Async event handlers with priority support
163163
- Built-in event types for all trading events
164164

165+
### Available TradingSuite Features
166+
167+
The `Features` enum defines optional components that can be enabled:
168+
169+
- `ORDERBOOK = "orderbook"` - Level 2 market depth and analysis
170+
- `RISK_MANAGER = "risk_manager"` - Position sizing and risk management
171+
- `TRADE_JOURNAL = "trade_journal"` - Trade logging (future)
172+
- `PERFORMANCE_ANALYTICS = "performance_analytics"` - Advanced metrics (future)
173+
- `AUTO_RECONNECT = "auto_reconnect"` - Automatic reconnection (future)
174+
175+
**Note**: OrderManager and PositionManager are always included by default.
176+
165177
### Architecture Patterns
166178

167179
**Async Factory Functions**: Use async `create_*` functions for component initialization:
@@ -288,7 +300,20 @@ async with ProjectX.from_env() as client:
288300

289301
## Recent Changes
290302

291-
### v3.1.12 - Latest Release
303+
### v3.1.13 - Latest Release
304+
- **Fixed**: Event system data structure mismatches causing order fill detection failures
305+
- Bracket orders now properly detect fills without 60-second timeouts
306+
- Event handlers handle both `order_id` and nested `order` object structures
307+
- ManagedTrade correctly listens to ORDER_FILLED instead of ORDER_MODIFIED
308+
- **Fixed**: Type annotations for SignalR hub connections
309+
- Created HubConnection type alias for proper IDE support
310+
- market_connection and user_connection now have proper types instead of Any
311+
- **Improved**: Real-time connection stability with circuit breaker pattern
312+
- **Improved**: Data storage robustness with thread-safety and performance optimizations
313+
- **Enhanced**: Test coverage increased from 30% to 93% for client module
314+
- **Fixed**: Multiple asyncio deprecation warnings
315+
316+
### v3.1.12
292317
- **Enhanced**: Significantly improved `01_events_with_on.py` real-time data example
293318
- Added CSV export functionality with interactive prompts
294319
- Plotly-based candlestick chart generation
@@ -375,7 +400,7 @@ async def main():
375400
suite = await TradingSuite.create(
376401
"MNQ",
377402
timeframes=["1min", "5min"],
378-
features=["orderbook", "risk_manager"],
403+
features=["orderbook", "risk_manager"], # Optional features
379404
initial_days=5
380405
)
381406

README.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ A **high-performance async Python SDK** for the [ProjectX Trading Platform](http
2121

2222
This Python SDK acts as a bridge between your trading strategies and the ProjectX platform, handling all the complex API interactions, data processing, and real-time connectivity.
2323

24-
## 🚀 v3.1.11 - Stable Production Release
24+
## 🚀 v3.1.13 - Stable Production Release
2525

26-
**Latest Version**: v3.1.11 - Fixed ManagedTrade market price fetching for risk-managed trades. See [CHANGELOG.md](CHANGELOG.md) for full release history.
26+
**Latest Version**: v3.1.13 - Fixed critical event system issues affecting bracket order fill detection and improved real-time connection stability. See [CHANGELOG.md](CHANGELOG.md) for full release history.
2727

2828
### 📦 Production Stability Guarantee
2929

@@ -251,6 +251,38 @@ Or use a config file (`~/.config/projectx/config.json`):
251251
}
252252
```
253253

254+
### Available Features
255+
256+
TradingSuite supports optional features that can be enabled during initialization:
257+
258+
| Feature | String Value | Description |
259+
|---------|-------------|-------------|
260+
| **OrderBook** | `"orderbook"` | Level 2 market depth, bid/ask analysis, iceberg detection |
261+
| **Risk Manager** | `"risk_manager"` | Position sizing, risk validation, managed trades |
262+
| **Trade Journal** | `"trade_journal"` | Trade logging and performance tracking (future) |
263+
| **Performance Analytics** | `"performance_analytics"` | Advanced metrics and analysis (future) |
264+
| **Auto Reconnect** | `"auto_reconnect"` | Automatic WebSocket reconnection (future) |
265+
266+
**Note:** PositionManager and OrderManager are always included and don't require feature flags.
267+
268+
```python
269+
# Enable specific features
270+
suite = await TradingSuite.create(
271+
"MNQ",
272+
features=["orderbook", "risk_manager"]
273+
)
274+
275+
# Access feature-specific components
276+
if suite.orderbook: # Only available when orderbook feature is enabled
277+
spread = await suite.orderbook.get_bid_ask_spread()
278+
279+
if suite.risk_manager: # Only available when risk_manager feature is enabled
280+
sizing = await suite.risk_manager.calculate_position_size(
281+
entry_price=100.0,
282+
stop_loss=99.0
283+
)
284+
```
285+
254286
### Component Overview
255287

256288
#### ProjectX Client
@@ -296,11 +328,19 @@ icebergs = await suite.orderbook.detect_iceberg_orders()
296328
```
297329

298330
#### RiskManager
299-
Risk management and managed trades (when enabled):
331+
Risk management and managed trades (requires feature flag):
300332
```python
301333
# Enable risk manager in features
302334
suite = await TradingSuite.create("MNQ", features=["risk_manager"])
303335

336+
# Risk manager integrates with PositionManager automatically
337+
# Use for position sizing and risk validation
338+
sizing = await suite.risk_manager.calculate_position_size(
339+
entry_price=100.0,
340+
stop_loss=99.0,
341+
risk_percent=0.02 # Risk 2% of account
342+
)
343+
304344
# Use managed trades for automatic risk management
305345
async with suite.managed_trade(max_risk_percent=0.01) as trade:
306346
# Market price fetched automatically (v3.1.11+)
@@ -310,6 +350,8 @@ async with suite.managed_trade(max_risk_percent=0.01) as trade:
310350
)
311351
```
312352

353+
**Note:** RiskManager requires the `"risk_manager"` feature flag and automatically integrates with PositionManager for comprehensive risk tracking.
354+
313355
### Technical Indicators
314356

315357
All 58+ indicators work with async data pipelines:

RELEASE_NOTES_v3.1.11.md

Lines changed: 0 additions & 69 deletions
This file was deleted.

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 = "3.1.12"
27-
version = "3.1.12"
26+
release = "3.1.13"
27+
version = "3.1.13"
2828

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

examples/02_order_management.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,22 @@ async def main() -> bool:
270270
print("📝 EXAMPLE 3: BRACKET ORDER")
271271
print("=" * 50)
272272

273-
entry_price = current_price - Decimal("5.0") # Entry $5 below market
273+
try:
274+
market_data = await suite.client.get_bars(
275+
"MNQ", days=days, interval=interval
276+
)
277+
if market_data is not None and not market_data.is_empty():
278+
current_price = Decimal(
279+
str(market_data.select("close").tail(1).item())
280+
)
281+
latest_time = market_data.select("timestamp").tail(1).item()
282+
print(f"✅ Retrieved MNQ price: ${current_price:.2f}")
283+
print(f" Data from: {latest_time} ({days}d {interval}min bars)")
284+
except Exception:
285+
print("❌ Failed to get market data")
286+
return False
287+
288+
entry_price = current_price - Decimal("1.00") # Entry $5 below market
274289
stop_loss = entry_price - Decimal("10.0") # $10 risk
275290
take_profit = entry_price + Decimal("20.0") # $20 profit target (2:1 R/R)
276291

examples/03_position_management.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ async def main() -> bool:
247247
suite = await TradingSuite.create(
248248
"MNQ",
249249
timeframes=["1min", "5min"],
250+
features=["risk_manager"],
250251
)
251252

252253
print(

0 commit comments

Comments
 (0)