Skip to content

Commit 5d07e91

Browse files
TexasCodingclaude
andcommitted
test: improve session module testing and documentation (v3.5.5)
Testing improvements: - Add comprehensive test coverage for session filtering functionality - Test DST transitions, timezone handling, and edge cases - Fix 11 bugs discovered through TDD methodology - Achieve 163/163 tests passing with 88% coverage - Reduce cyclomatic complexity in 4 functions - Fix all MyPy type annotation errors Documentation updates: - Complete rewrite of session documentation for accuracy - Remove references to non-existent methods - Update all examples to use correct async patterns - Create 5 new working example scripts - Add comprehensive README with 935 lines of examples Bug fixes: - Fix DST transition detection for edge cases - Handle naive datetime objects correctly - Fix BREAK session detection logic - Fix DataFrame boolean evaluation in examples - Fix Polars correlation calculation methods - Add proper type checking for dictionary operations Code quality: - Make 4 sync functions private for async compliance - Add type annotations throughout - Fix IDE type checking issues with pragmas - Pass all ruff, mypy, and bandit checks Breaking changes: - None - maintains backward compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 855bbe7 commit 5d07e91

17 files changed

+2488
-1003
lines changed

.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": 2107
136+
"line_number": 2149
137137
}
138138
],
139139
"README.md": [
@@ -325,5 +325,5 @@
325325
}
326326
]
327327
},
328-
"generated_at": "2025-08-31T20:27:03Z"
328+
"generated_at": "2025-09-01T00:25:00Z"
329329
}

CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,48 @@ 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.5] - 2025-01-21
18+
19+
### ✅ Testing
20+
21+
**Comprehensive Sessions Module Testing**:
22+
- **163 Tests Passing**: Complete test suite for sessions module with 88% coverage
23+
- **TDD Methodology**: All tests validate expected behavior, not current implementation
24+
- **Bug Fixes**: Fixed 11 critical bugs including DST transitions, naive datetime handling, and BREAK session detection
25+
- **Async Compliance**: Made 4 sync functions private to maintain 100% async public API
26+
- **Complexity Reduction**: Refactored 4 high-complexity functions using helper methods
27+
- **Type Safety**: Fixed all MyPy type annotation errors with proper generic types
28+
29+
### 📝 Documentation
30+
31+
**Sessions Documentation Overhaul**:
32+
- **Complete Guide**: Created comprehensive README.md for sessions module with working examples
33+
- **5 Example Scripts**: Created tested, working examples for all session functionality:
34+
- `01_basic_session_filtering.py` - Basic filtering and market status
35+
- `02_session_statistics.py` - Statistics and analytics
36+
- `03_session_indicators.py` - Session-aware indicators
37+
- `04_session_comparison.py` - RTH vs ETH comparison
38+
- `05_multi_instrument_sessions.py` - Multi-instrument management
39+
- **API Accuracy**: Fixed all incorrect method signatures and usage patterns
40+
- **DataFrame Safety**: Added proper None checks and `.is_empty()` evaluations throughout
41+
42+
### 🐛 Fixed
43+
44+
**Session Module Bugs**:
45+
- **DST Transitions**: Fixed edge cases during daylight saving time transitions
46+
- **Naive Datetime Handling**: Properly handle naive datetimes with timezone awareness
47+
- **BREAK Session Detection**: Fixed incorrect BREAK period detection logic
48+
- **DataFrame Evaluation**: Fixed "ambiguous truth value" errors with proper boolean checks
49+
- **Correlation Calculation**: Fixed Polars Series correlation method usage
50+
- **Type Conversions**: Added safe type conversions with None checks
51+
52+
### 🔧 Changed
53+
54+
- **Public API**: Made sync utility functions private with underscore prefix to maintain async consistency
55+
- **Example Organization**: Moved all session examples to dedicated `examples/sessions/` directory
56+
- **Documentation Structure**: Renamed guide to README.md for automatic GitHub display
57+
- **Error Handling**: Improved error messages and added comprehensive troubleshooting section
58+
1759
## [3.5.4] - 2025-01-31
1860

1961
### 🚀 Added

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.4 - Lorenz Formula Indicator & Test Suite Improvements
24+
## 🚀 v3.5.5 - Sessions Module Testing & Documentation
2525

26-
**Latest Version**: v3.5.4 - Introduces the Lorenz Formula indicator applying chaos theory to market analysis, plus comprehensive test suite reorganization and enhanced statistics module coverage.
26+
**Latest Version**: v3.5.5 - Comprehensive testing and documentation improvements for the ETH vs RTH Trading Sessions feature, ensuring production-ready session filtering and analysis.
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.4 features including the new Lorenz indicator and test improvements.
35+
See [CHANGELOG.md](CHANGELOG.md) for complete v3.5.5 features including sessions module improvements and comprehensive example scripts.
3636

3737
### 📦 Production Stability Guarantee
3838

docs/api/trading-suite.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ async def session_setup():
9292

9393
# Custom session times
9494
from datetime import time
95-
import pytz
9695

9796
custom_config = SessionConfig(
9897
session_type=SessionType.RTH,
99-
custom_times=SessionTimes(
98+
session_times=SessionTimes(
10099
rth_start=time(9, 0),
101100
rth_end=time(15, 30),
102-
timezone=pytz.timezone("US/Eastern")
101+
eth_start=time(18, 0),
102+
eth_end=time(17, 0)
103103
)
104104
)
105105

@@ -228,13 +228,18 @@ async def multi_instrument_sessions():
228228
# Set session type for all instruments
229229
await suite.set_session_type(SessionType.RTH)
230230

231-
# Get session data for all instruments
231+
# Get session data for all instruments (returns dict)
232232
session_data = await suite.get_session_data("5min", SessionType.RTH)
233-
# Returns: {"MNQ": data, "MES": data}
233+
# Returns: {"MNQ": DataFrame, "MES": DataFrame}
234+
235+
for symbol, data in session_data.items():
236+
if data is not None and not data.is_empty():
237+
print(f"{symbol} RTH bars: {len(data)}")
234238

235239
# Get session statistics for all instruments
236240
session_stats = await suite.get_session_statistics("5min")
237-
# Returns: {"MNQ": stats, "MES": stats}
241+
# Returns: {"MNQ": stats_dict, "MES": stats_dict} for multi-instrument
242+
# or just stats_dict for single instrument
238243

239244
await suite.disconnect()
240245
```
@@ -303,8 +308,7 @@ async def custom_configuration():
303308

304309
# Session configuration (v3.4.0+)
305310
session_config = SessionConfig(
306-
session_type=SessionType.RTH,
307-
product="MNQ" # Product-specific session times
311+
session_type=SessionType.RTH
308312
)
309313

310314
suite = await TradingSuite.create(
@@ -437,7 +441,7 @@ async def data_access():
437441
### Session-Aware Data Access (v3.4.0+)
438442

439443
```python
440-
from project_x_py.sessions import SessionType
444+
from project_x_py.sessions import SessionType, SessionConfig
441445

442446
async def session_data_access():
443447
# Create suite with session configuration
@@ -446,22 +450,22 @@ async def session_data_access():
446450
timeframes=["1min", "5min"],
447451
session_config=SessionConfig(session_type=SessionType.RTH)
448452
)
449-
mnq_data = suite["MNQ"].data
450-
451-
# Get session-specific data
452-
rth_data = await mnq_data.get_session_bars("5min", SessionType.RTH)
453-
eth_data = await mnq_data.get_session_bars("5min", SessionType.ETH)
453+
mnq_context = suite["MNQ"]
454454

455-
# Session trades
456-
rth_trades = await mnq_data.get_session_trades(SessionType.RTH)
455+
# Get session-specific data using data manager methods
456+
rth_data = await mnq_context.data.get_session_data("5min", SessionType.RTH)
457+
eth_data = await mnq_context.data.get_session_data("5min", SessionType.ETH)
457458

458-
# Session statistics
459-
from project_x_py.sessions import SessionStatistics
460-
stats = SessionStatistics(suite["MNQ"])
461-
rth_stats = await stats.calculate_session_stats(SessionType.RTH)
459+
# Get session statistics from data manager
460+
session_stats = await mnq_context.data.get_session_statistics("5min")
462461

463-
print(f"RTH Volatility: {rth_stats['volatility']:.2%}")
464-
print(f"RTH Volume: {rth_stats['total_volume']:,}")
462+
if session_stats:
463+
print(f"RTH Volume: {session_stats.get('rth_volume', 0):,}")
464+
print(f"ETH Volume: {session_stats.get('eth_volume', 0):,}")
465+
print(f"RTH VWAP: ${session_stats.get('rth_vwap', 0):.2f}")
466+
print(f"ETH VWAP: ${session_stats.get('eth_vwap', 0):.2f}")
467+
print(f"RTH Range: ${session_stats.get('rth_range', 0):.2f}")
468+
print(f"ETH Range: ${session_stats.get('eth_range', 0):.2f}")
465469

466470
await suite.disconnect()
467471
```

0 commit comments

Comments
 (0)