Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
db41f0a
remove old files
TexasCoding Aug 15, 2025
fe78c96
refactor(realtime, risk): Major stabilization and feature implementation
TexasCoding Aug 15, 2025
6bdd91e
refactor(positions): Overhaul PositionManager logic
TexasCoding Aug 15, 2025
72a062f
fix: Resolve bracket order fill detection and circular dependencies
TexasCoding Aug 15, 2025
d14444d
fix(types): Resolve all mypy type checking errors
TexasCoding Aug 15, 2025
29d951b
fix(risk_manager): Set both positions and position_manager attributes…
TexasCoding Aug 15, 2025
16dd217
chore: Clean up and finalize patching_v4 branch
TexasCoding Aug 15, 2025
0ae60cb
docs: Update documentation for TradingSuite features and recent fixes
TexasCoding Aug 15, 2025
7c69848
refactor(client): Improve robustness and fix mypy issues in client mo…
TexasCoding Aug 15, 2025
ffd8a2e
fix(tests): Fix all failing tests after recent refactoring
TexasCoding Aug 15, 2025
09503f6
test: Improve client module test coverage from 30% to 82%
TexasCoding Aug 15, 2025
d243c76
test(client): Add comprehensive tests for base and trading modules
TexasCoding Aug 15, 2025
3edd369
refactor(trading): Improve TradingSuite stability and configuration
TexasCoding Aug 15, 2025
19760e5
refactor(orders): Improve order tracking and chaining
TexasCoding Aug 15, 2025
64eaad5
refactor(data): Improve robustness and performance of storage
TexasCoding Aug 15, 2025
732e8e9
fix(realtime): Add proper type annotations for SignalR hub connections
TexasCoding Aug 15, 2025
2bf4266
fix(events): Fix order event data structure mismatches across event h…
TexasCoding Aug 15, 2025
32ff804
docs: Update documentation for v3.1.13 release
TexasCoding Aug 15, 2025
ba46509
chore: Bump version to 3.1.13
TexasCoding Aug 15, 2025
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
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,52 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Migration guides will be provided for all breaking changes
- Semantic versioning (MAJOR.MINOR.PATCH) is strictly followed

## [3.1.13] - 2025-08-15

### Fixed
- **🎯 Event System Data Structure Mismatches**: Fixed critical order fill detection issues
- Bracket orders now properly detect fills without timing out
- Event handlers now correctly handle both `order_id` and nested `order` object structures
- Added backward compatibility for different event payload formats
- ManagedTrade now listens to correct events (ORDER_FILLED vs ORDER_MODIFIED)

- **πŸ“ Type Annotations for SignalR Connections**: Improved IDE support and type safety
- Created HubConnection type alias for BaseHubConnection
- Fixed market_connection and user_connection from Any to proper types
- IDEs now recognize connection methods (send, on, start, stop)
- Updated ProjectXRealtimeClientProtocol to match implementation

- **πŸ”§ Real-time Connection Improvements**: Enhanced WebSocket stability
- Added circuit breaker pattern to BatchedWebSocketHandler
- Improved subscription handling with proper event waiting
- Fixed asyncio deprecation warnings (get_event_loop β†’ get_running_loop)
- Better error handling and recovery mechanisms

### Improved
- **πŸ“Š Data Storage Robustness**: Major improvements to mmap_storage module
- Fixed critical bug causing data overwrite on initialization
- Implemented binary search for read_window (significant performance boost)
- Added thread-safe operations with RLock
- Fixed file corruption bug in _resize_file
- Replaced print statements with proper logging

- **πŸ§ͺ Test Coverage**: Dramatically improved client module testing
- Client module coverage increased from 30% to 93%
- Added 70+ comprehensive test cases across all client components
- Fixed bug in _select_best_contract method
- Full test coverage for base.py (100%) and trading.py (98%)

- **πŸ—οΈ Order and Position Management**: Enhanced tracking and stability
- Improved order tracking with better event handling
- More robust position manager logic
- Better error recovery in order chains
- Enhanced TradingSuite configuration options

### Documentation
- Updated CHANGELOG.md with comprehensive v3.1.13 changes
- Updated CLAUDE.md Recent Changes section
- Added detailed commit messages for all fixes

## [3.1.12] - 2025-08-15

### Added
Expand Down
31 changes: 28 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

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

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

### Available TradingSuite Features

The `Features` enum defines optional components that can be enabled:

- `ORDERBOOK = "orderbook"` - Level 2 market depth and analysis
- `RISK_MANAGER = "risk_manager"` - Position sizing and risk management
- `TRADE_JOURNAL = "trade_journal"` - Trade logging (future)
- `PERFORMANCE_ANALYTICS = "performance_analytics"` - Advanced metrics (future)
- `AUTO_RECONNECT = "auto_reconnect"` - Automatic reconnection (future)

**Note**: OrderManager and PositionManager are always included by default.

### Architecture Patterns

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

## Recent Changes

### v3.1.12 - Latest Release
### v3.1.13 - Latest Release
- **Fixed**: Event system data structure mismatches causing order fill detection failures
- Bracket orders now properly detect fills without 60-second timeouts
- Event handlers handle both `order_id` and nested `order` object structures
- ManagedTrade correctly listens to ORDER_FILLED instead of ORDER_MODIFIED
- **Fixed**: Type annotations for SignalR hub connections
- Created HubConnection type alias for proper IDE support
- market_connection and user_connection now have proper types instead of Any
- **Improved**: Real-time connection stability with circuit breaker pattern
- **Improved**: Data storage robustness with thread-safety and performance optimizations
- **Enhanced**: Test coverage increased from 30% to 93% for client module
- **Fixed**: Multiple asyncio deprecation warnings

### v3.1.12
- **Enhanced**: Significantly improved `01_events_with_on.py` real-time data example
- Added CSV export functionality with interactive prompts
- Plotly-based candlestick chart generation
Expand Down Expand Up @@ -375,7 +400,7 @@ async def main():
suite = await TradingSuite.create(
"MNQ",
timeframes=["1min", "5min"],
features=["orderbook", "risk_manager"],
features=["orderbook", "risk_manager"], # Optional features
initial_days=5
)

Expand Down
48 changes: 45 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ A **high-performance async Python SDK** for the [ProjectX Trading Platform](http

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.

## πŸš€ v3.1.11 - Stable Production Release
## πŸš€ v3.1.13 - Stable Production Release

**Latest Version**: v3.1.11 - Fixed ManagedTrade market price fetching for risk-managed trades. See [CHANGELOG.md](CHANGELOG.md) for full release history.
**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.

### πŸ“¦ Production Stability Guarantee

Expand Down Expand Up @@ -251,6 +251,38 @@ Or use a config file (`~/.config/projectx/config.json`):
}
```

### Available Features

TradingSuite supports optional features that can be enabled during initialization:

| Feature | String Value | Description |
|---------|-------------|-------------|
| **OrderBook** | `"orderbook"` | Level 2 market depth, bid/ask analysis, iceberg detection |
| **Risk Manager** | `"risk_manager"` | Position sizing, risk validation, managed trades |
| **Trade Journal** | `"trade_journal"` | Trade logging and performance tracking (future) |
| **Performance Analytics** | `"performance_analytics"` | Advanced metrics and analysis (future) |
| **Auto Reconnect** | `"auto_reconnect"` | Automatic WebSocket reconnection (future) |

**Note:** PositionManager and OrderManager are always included and don't require feature flags.

```python
# Enable specific features
suite = await TradingSuite.create(
"MNQ",
features=["orderbook", "risk_manager"]
)

# Access feature-specific components
if suite.orderbook: # Only available when orderbook feature is enabled
spread = await suite.orderbook.get_bid_ask_spread()

if suite.risk_manager: # Only available when risk_manager feature is enabled
sizing = await suite.risk_manager.calculate_position_size(
entry_price=100.0,
stop_loss=99.0
)
```

### Component Overview

#### ProjectX Client
Expand Down Expand Up @@ -296,11 +328,19 @@ icebergs = await suite.orderbook.detect_iceberg_orders()
```

#### RiskManager
Risk management and managed trades (when enabled):
Risk management and managed trades (requires feature flag):
```python
# Enable risk manager in features
suite = await TradingSuite.create("MNQ", features=["risk_manager"])

# Risk manager integrates with PositionManager automatically
# Use for position sizing and risk validation
sizing = await suite.risk_manager.calculate_position_size(
entry_price=100.0,
stop_loss=99.0,
risk_percent=0.02 # Risk 2% of account
)

# Use managed trades for automatic risk management
async with suite.managed_trade(max_risk_percent=0.01) as trade:
# Market price fetched automatically (v3.1.11+)
Expand All @@ -310,6 +350,8 @@ async with suite.managed_trade(max_risk_percent=0.01) as trade:
)
```

**Note:** RiskManager requires the `"risk_manager"` feature flag and automatically integrates with PositionManager for comprehensive risk tracking.

### Technical Indicators

All 58+ indicators work with async data pipelines:
Expand Down
69 changes: 0 additions & 69 deletions RELEASE_NOTES_v3.1.11.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
project = "project-x-py"
copyright = "2025, Jeff West"
author = "Jeff West"
release = "3.1.12"
version = "3.1.12"
release = "3.1.13"
version = "3.1.13"

# -- General configuration ---------------------------------------------------

Expand Down
17 changes: 16 additions & 1 deletion examples/02_order_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,22 @@ async def main() -> bool:
print("πŸ“ EXAMPLE 3: BRACKET ORDER")
print("=" * 50)

entry_price = current_price - Decimal("5.0") # Entry $5 below market
try:
market_data = await suite.client.get_bars(
"MNQ", days=days, interval=interval
)
if market_data is not None and not market_data.is_empty():
current_price = Decimal(
str(market_data.select("close").tail(1).item())
)
latest_time = market_data.select("timestamp").tail(1).item()
print(f"βœ… Retrieved MNQ price: ${current_price:.2f}")
print(f" Data from: {latest_time} ({days}d {interval}min bars)")
except Exception:
print("❌ Failed to get market data")
return False

entry_price = current_price - Decimal("1.00") # Entry $5 below market
stop_loss = entry_price - Decimal("10.0") # $10 risk
take_profit = entry_price + Decimal("20.0") # $20 profit target (2:1 R/R)

Expand Down
1 change: 1 addition & 0 deletions examples/03_position_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ async def main() -> bool:
suite = await TradingSuite.create(
"MNQ",
timeframes=["1min", "5min"],
features=["risk_manager"],
)

print(
Expand Down
Loading
Loading