Skip to content

Commit 9802b1a

Browse files
authored
Merge pull request #62 from TexasCoding/v3.5.1_testing
fix: resolve critical TradingSuite bugs identified by TDD test suite (v3.5.1)
2 parents 3eac14b + 06864f9 commit 9802b1a

22 files changed

+2944
-78
lines changed

.claude/agents/code-reviewer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
name: code-reviewer
33
description: Perform thorough code reviews for the project-x-py async trading SDK, focusing on async patterns, real-time performance, financial data integrity, and API stability. Use PROACTIVELY for PR reviews and before releases.
4+
tools: Glob, Grep, LS, Read, WebFetch, TodoWrite, WebSearch, BashOutput, KillBash, ListMcpResourcesTool, ReadMcpResourceTool, Bash
45
model: sonnet
56
color: yellow
67
---

.claude/commands/test-module.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
3. Refactor: Improve the code's design and quality while ensuring all tests remain green.
2424
* **Bug Discovery**: The primary goal of this TDD approach is to uncover any bugs in the core logic. If a test fails, it is because the implementation is incorrect, not the test. Fix the code to match the
2525
test's expectations.
26+
* **Fix All Issues/Bugs Found when they are found**: When testing reveals a bug in core logic we need to fix the bug immediately. Never make tests pass without fixing the underlying issue!
2627

2728
## Final Deliverable:
2829

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"filename": "CHANGELOG.md",
134134
"hashed_secret": "89a6cfe2a229151e8055abee107d45ed087bbb4f",
135135
"is_verified": false,
136-
"line_number": 1984
136+
"line_number": 2010
137137
}
138138
],
139139
"README.md": [
@@ -325,5 +325,5 @@
325325
}
326326
]
327327
},
328-
"generated_at": "2025-08-30T16:25:48Z"
328+
"generated_at": "2025-08-30T21:20:10Z"
329329
}

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ 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.5.1] - 2025-01-30
18+
19+
### 🐛 Fixed
20+
21+
**Critical Bug Fixes from TDD Test Suite**:
22+
- **Context Manager Re-entry**: Fixed issue where TradingSuite context manager couldn't be re-entered after exit
23+
- **ManagedTrade Attributes**: Added missing property accessors for `risk_manager`, `order_manager`, and `position_manager`
24+
- **Event Loop Handling**: Fixed `get_stats_sync()` to properly handle nested event loops using ThreadPoolExecutor
25+
- **Deprecation Warnings**: Ensured consistent deprecation warnings when accessing components directly
26+
- **Config Validation**: Fixed config file validation to check file extension before attempting file operations
27+
28+
**Session Management Fixes**:
29+
- Fixed `set_session_type()`, `get_session_data()`, and `get_session_statistics()` to work correctly in multi-instrument mode
30+
- Session methods now properly iterate over all instrument contexts when in multi-instrument mode
31+
- Added fallback for single-instrument backward compatibility mode
32+
33+
**Test Suite Fixes**:
34+
- Updated benchmark tests to use private attributes (`_orders`, `_positions`, etc.)
35+
- Fixed integration tests to properly mock multi-instrument contexts
36+
- Resolved statistics and event bus test failures caused by property-only access
37+
38+
### 🔧 Changed
39+
40+
- Component attributes (`data`, `orders`, `positions`, `orderbook`, `risk_manager`) are now stored as private attributes with deprecation warning properties
41+
- Context manager always initializes when entering context, regardless of `auto_connect` setting
42+
1743
## [3.5.0] - 2025-01-25
1844

1945
### 🚀 Major Feature: Multi-Instrument TradingSuite

README.md

Lines changed: 3 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.5.0 - Multi-Instrument TradingSuite
24+
## 🚀 v3.5.1 - Multi-Instrument TradingSuite with Critical Bug Fixes
2525

26-
**Latest Version**: v3.5.0 - Major enhancement enabling TradingSuite to manage multiple instruments simultaneously. This revolutionary feature enables complex multi-asset trading strategies, portfolio management, and cross-instrument analysis while maintaining full backward compatibility.
26+
**Latest Version**: v3.5.1 - Critical bug fixes for TradingSuite including context manager re-entry, event loop handling, and session management in multi-instrument mode. The v3.5.0 release introduced multi-instrument support enabling complex multi-asset trading strategies while maintaining full backward compatibility.
2727

2828
**Key Benefits**:
2929
- 🎯 **Multi-Asset Strategies**: Trade ES vs NQ pairs, commodity spreads, sector rotation
@@ -32,7 +32,7 @@ This Python SDK acts as a bridge between your trading strategies and the Project
3232
- 🛡️ **Backward Compatible**: Existing single-instrument code continues to work
3333
-**Performance Optimized**: Parallel context creation and resource sharing
3434

35-
See [CHANGELOG.md](CHANGELOG.md) for complete v3.5.0 release notes and migration guide.
35+
See [CHANGELOG.md](CHANGELOG.md) for complete v3.5.1 bug fixes and v3.5.0 release notes with migration guide.
3636

3737
### 📦 Production Stability Guarantee
3838

docs/index.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
**project-x-py** is a high-performance **async Python SDK** for the [ProjectX Trading Platform](https://www.projectx.com/) Gateway API. This library enables developers to build sophisticated trading strategies and applications by providing comprehensive async access to futures trading operations, real-time market data, Level 2 orderbook analysis, and a complete technical analysis suite with 58+ TA-Lib compatible indicators including pattern recognition.
99

10-
!!! note "Version 3.5.0 - Multi-Instrument TradingSuite"
11-
**Revolutionary Release**: Complete multi-instrument support enabling traders to manage multiple futures contracts simultaneously. Features include pairs trading, cross-market arbitrage, portfolio-level risk management, and advanced analytics across instruments. Full backward compatibility maintained with zero breaking changes.
10+
!!! note "Version 3.5.1 - Multi-Instrument TradingSuite with Critical Bug Fixes"
11+
**Latest Release**: Critical bug fixes for TradingSuite including context manager re-entry, event loop handling, and session management in multi-instrument mode. The v3.5.0 release introduced revolutionary multi-instrument support enabling traders to manage multiple futures contracts simultaneously with pairs trading, cross-market arbitrage, and portfolio-level risk management. Full backward compatibility maintained.
1212

1313
!!! note "Stable Production Release"
1414
Since v3.1.1, this project maintains strict semantic versioning with backward compatibility between minor versions. Breaking changes only occur in major version releases (4.0.0+). Deprecation warnings are provided for at least 2 minor versions before removal.
@@ -216,6 +216,14 @@ mnq_context = suite["MNQ"] # Access specific instrument
216216

217217
## Recent Changes
218218

219+
### v3.5.1 - Critical Bug Fixes (2025-01-30)
220+
- **Fixed**: Context manager re-entry issue in TradingSuite
221+
- **Fixed**: ManagedTrade missing property accessors
222+
- **Fixed**: Event loop handling in `get_stats_sync()` for nested async contexts
223+
- **Fixed**: Inconsistent deprecation warnings for direct component access
224+
- **Fixed**: Config file validation order (extension check before file operations)
225+
- **Fixed**: Session management methods in multi-instrument mode
226+
219227
### v3.5.0 - Multi-Instrument TradingSuite (2025-01-25)
220228
- **MAJOR**: Revolutionary multi-instrument support for simultaneous contract management
221229
- **Added**: `InstrumentContext` dataclass for encapsulating instrument-specific managers

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "project-x-py"
3-
version = "3.5.0"
3+
version = "3.5.1"
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" }

src/project_x_py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
- `utils`: Utility functions and calculations
110110
"""
111111

112-
__version__ = "3.5.0"
112+
__version__ = "3.5.1"
113113
__author__ = "TexasCoding"
114114

115115
# Core client classes - renamed from Async* to standard names

src/project_x_py/indicators/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
)
203203

204204
# Version info
205-
__version__ = "3.5.0"
205+
__version__ = "3.5.1"
206206
__author__ = "TexasCoding"
207207

208208

src/project_x_py/risk_manager/core.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,15 @@ async def attach_risk_orders(
526526
# Create bracket response structure
527527
from project_x_py.models import BracketOrderResponse
528528

529+
# Success should only be True if ALL requested orders succeeded
530+
success = True
531+
if stop_loss and (not stop_response or not stop_response.success):
532+
success = False
533+
if take_profit and (not target_response or not target_response.success):
534+
success = False
535+
529536
bracket_response = BracketOrderResponse(
530-
success=bool(stop_response or target_response),
537+
success=success,
531538
entry_order_id=None, # No entry for existing position
532539
stop_order_id=stop_response.orderId
533540
if stop_response and stop_response.success
@@ -541,7 +548,9 @@ async def attach_risk_orders(
541548
entry_response=None,
542549
stop_response=stop_response,
543550
target_response=target_response,
544-
error_message=None,
551+
error_message=None
552+
if success
553+
else "One or more risk orders failed to place",
545554
)
546555

547556
# Setup trailing stop if configured
@@ -902,9 +911,10 @@ async def _monitor_trailing_stop(
902911
while True:
903912
# Get current price
904913
if self.positions is None:
905-
raise ValueError(
906-
"Position manager not set. Call set_position_manager() to resolve circular dependency."
914+
logger.warning(
915+
"Position manager not set for trailing stop monitoring. Exiting monitor."
907916
)
917+
break
908918

909919
current_positions = await self.positions.get_all_positions()
910920
current_pos = next(

0 commit comments

Comments
 (0)