Skip to content

Commit 5bcd086

Browse files
authored
Merge pull request #41 from TexasCoding/patch_v2
v3.1.8: Fix real-time data for E-mini contracts and low-volume periods
2 parents 6337690 + dd6f38a commit 5bcd086

File tree

21 files changed

+546
-188
lines changed

21 files changed

+546
-188
lines changed

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,37 @@ 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.8] - 2025-08-12
18+
19+
### Fixed
20+
- **🔧 Real-time Data Processing**: Fixed real-time data not being processed for E-mini contracts (NQ/ES)
21+
- Symbol matching now handles contract resolution (e.g., NQ resolves to ENQ)
22+
- Stores both original instrument and resolved symbol ID for proper matching
23+
- Affects all contracts where user symbol differs from exchange symbol
24+
25+
### Added
26+
- **⏱️ Bar Timer Mechanism**: Automatic bar creation during low-volume periods
27+
- Creates empty bars (volume=0) at regular intervals when no ticks arrive
28+
- Ensures consistent bar generation for all instruments regardless of trading activity
29+
- Particularly important for low-volume contracts and after-hours trading
30+
- Empty bars maintain price continuity using the last close price
31+
32+
### Improved
33+
- Enhanced symbol validation to support both user-specified and exchange-resolved symbols
34+
- Better handling of futures contract name resolution (NQ→ENQ, ES→EP, etc.)
35+
- More robust real-time data pipeline for all futures contracts
36+
37+
## [3.1.7] - 2025-08-12
38+
39+
### Changed
40+
- Updated documentation and examples for better clarity
41+
- Minor code improvements and optimizations
42+
43+
### Documentation
44+
- Updated CLAUDE.md with current v3.1.7 information
45+
- Corrected code examples to use TradingSuite API
46+
- Removed references to deprecated factory functions
47+
1748
## [3.1.6] - 2025-08-12
1849

1950
### Fixed

CLAUDE.md

Lines changed: 52 additions & 53 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.6 - Stable Production Release
5+
## Project Status: v3.1.8 - 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

@@ -166,29 +166,17 @@ uv run python -m build # Alternative build command
166166

167167
**Async Factory Functions**: Use async `create_*` functions for component initialization:
168168
```python
169-
# Async factory pattern (v2.0.0+)
169+
# TradingSuite - Recommended approach (v3.0.0+)
170170
async def setup_trading():
171-
async with ProjectX.from_env() as client:
172-
await client.authenticate()
173-
174-
# Create managers with async patterns
175-
realtime_client = await create_realtime_client(
176-
client.jwt_token,
177-
str(client.account_id)
178-
)
179-
180-
order_manager = create_order_manager(client, realtime_client)
181-
position_manager = create_position_manager(client, realtime_client)
182-
183-
# Or use the all-in-one factory
184-
suite = await create_trading_suite(
185-
instrument="MNQ",
186-
project_x=client,
187-
jwt_token=client.jwt_token,
188-
account_id=client.account_id
189-
)
190-
191-
return suite
171+
# Simple one-line setup with TradingSuite
172+
suite = await TradingSuite.create(
173+
"MNQ",
174+
timeframes=["1min", "5min"],
175+
features=["orderbook"]
176+
)
177+
178+
# Everything is ready - client authenticated, realtime connected
179+
return suite
192180
```
193181

194182
**Dependency Injection**: Managers receive their dependencies (ProjectX client, realtime client) rather than creating them.
@@ -300,6 +288,16 @@ async with ProjectX.from_env() as client:
300288

301289
## Recent Changes
302290

291+
### v3.1.8 - Latest Release
292+
- **Fixed**: Real-time data processing for E-mini contracts (NQ/ES) that resolve to different symbols
293+
- **Added**: Bar timer mechanism to create empty bars during low-volume periods
294+
- **Improved**: Symbol matching to handle contract resolution (e.g., NQ→ENQ)
295+
- **Enhanced**: Real-time data manager now properly processes all futures contracts
296+
297+
### v3.1.7 - Previous Release
298+
- Minor updates and improvements
299+
- Documentation enhancements
300+
303301
### v3.1.6 - Critical Deadlock Fix
304302
- **Fixed**: Deadlock when calling `suite.data` methods from event handler callbacks (Issue #39)
305303
- **Improved**: Event emission now non-blocking to prevent handler deadlocks
@@ -343,29 +341,31 @@ async with ProjectX.from_env() as client:
343341
- All core modules organized as packages with focused submodules
344342
- Improved code organization and maintainability
345343

346-
### Trading Suite Usage
344+
### Trading Suite Usage (v3.0.0+)
347345
```python
348346
# Complete trading suite with all managers
349-
from project_x_py import create_trading_suite
347+
from project_x_py import TradingSuite
350348

351349
async def main():
352-
suite = await create_trading_suite(
353-
instrument="MNQ",
350+
suite = await TradingSuite.create(
351+
"MNQ",
354352
timeframes=["1min", "5min"],
355-
enable_orderbook=True,
356-
enable_risk_management=True
353+
features=["orderbook", "risk_manager"],
354+
initial_days=5
357355
)
358356

359357
# All managers are integrated and ready
360-
await suite.start()
358+
# No need to call start() - already connected
361359

362360
# Access individual managers
363-
order = await suite.order_manager.place_market_order(
364-
"MNQ", 1, "BUY"
361+
order = await suite.orders.place_market_order(
362+
contract_id=suite.instrument_info.id,
363+
side=0, # Buy
364+
size=1
365365
)
366366

367-
position = suite.position_manager.get_position("MNQ")
368-
bars = suite.data_manager.get_bars("MNQ", "1min")
367+
position = await suite.positions.get_position("MNQ")
368+
bars = await suite.data.get_data("1min")
369369
```
370370

371371
### Key Async Examples
@@ -375,24 +375,23 @@ async with ProjectX.from_env() as client:
375375
await client.authenticate()
376376
bars = await client.get_bars("MNQ", days=5)
377377

378-
# Real-time data
378+
# Real-time data with TradingSuite
379379
async def stream_data():
380-
async with ProjectX.from_env() as client:
381-
await client.authenticate()
382-
383-
realtime = await create_realtime_client(
384-
client.jwt_token,
385-
str(client.account_id)
386-
)
387-
388-
data_manager = create_realtime_data_manager(
389-
"MNQ", client, realtime
390-
)
391-
392-
# Set up callbacks
393-
data_manager.on_bar_received = handle_bar
394-
395-
# Start streaming
396-
await realtime.connect()
397-
await data_manager.start_realtime_feed()
380+
suite = await TradingSuite.create(
381+
"MNQ",
382+
timeframes=["1min", "5min"]
383+
)
384+
385+
# Register event handlers
386+
from project_x_py import EventType
387+
388+
async def handle_bar(event):
389+
print(f"New bar: {event.data}")
390+
391+
await suite.on(EventType.NEW_BAR, handle_bar)
392+
393+
# Data is already streaming
394+
# Access current data
395+
current_price = await suite.data.get_current_price()
396+
bars = await suite.data.get_data("1min")
398397
```

GEMINI.md

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

33
This file provides guidance to Google's Gemini models when working with code in this repository.
44

5-
## Project Status: v3.1.1 - Stable Production Release
5+
## Project Status: v3.1.7 - 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

@@ -96,7 +96,7 @@ uv run python -m build # Alternative build command
9696

9797
## Project Architecture
9898

99-
### Core Components (v3.0.1 - Multi-file Packages)
99+
### Core Components (v3.0.2 - Multi-file Packages)
100100

101101
**ProjectX Client (`src/project_x_py/client/`)**
102102
- Main async API client for TopStepX ProjectX Gateway
@@ -166,29 +166,17 @@ uv run python -m build # Alternative build command
166166

167167
**Async Factory Functions**: Use async `create_*` functions for component initialization:
168168
```python
169-
# Async factory pattern (v2.0.0+)
169+
# TradingSuite - Recommended approach (v3.0.0+)
170170
async def setup_trading():
171-
async with ProjectX.from_env() as client:
172-
await client.authenticate()
173-
174-
# Create managers with async patterns
175-
realtime_client = await create_realtime_client(
176-
client.jwt_token,
177-
str(client.account_id)
178-
)
179-
180-
order_manager = create_order_manager(client, realtime_client)
181-
position_manager = create_position_manager(client, realtime_client)
182-
183-
# Or use the all-in-one factory
184-
suite = await create_trading_suite(
185-
instrument="MNQ",
186-
project_x=client,
187-
jwt_token=client.jwt_token,
188-
account_id=client.account_id
189-
)
190-
191-
return suite
171+
# Simple one-line setup with TradingSuite
172+
suite = await TradingSuite.create(
173+
"MNQ",
174+
timeframes=["1min", "5min"],
175+
features=["orderbook"]
176+
)
177+
178+
# Everything is ready - client authenticated, realtime connected
179+
return suite
192180
```
193181

194182
**Dependency Injection**: Managers receive their dependencies (ProjectX client, realtime client) rather than creating them.
@@ -300,6 +288,34 @@ async with ProjectX.from_env() as client:
300288

301289
## Recent Changes
302290

291+
### v3.1.7 - Latest Release
292+
- Minor updates and improvements
293+
- Documentation enhancements
294+
295+
### v3.1.6 - Critical Deadlock Fix
296+
- **Fixed**: Deadlock when calling `suite.data` methods from event handler callbacks (Issue #39)
297+
- **Improved**: Event emission now non-blocking to prevent handler deadlocks
298+
- **Enhanced**: Event triggering moved outside lock scope for better concurrency
299+
- **Added**: Missing asyncio import in data_processing module
300+
- **Maintained**: Full API compatibility - no breaking changes
301+
302+
### v3.1.5 - Enhanced Bar Data Retrieval
303+
- **Added**: Optional `start_time` and `end_time` parameters to `get_bars()` method
304+
- **Improved**: Precise time range specification for historical data queries
305+
- **Enhanced**: Full timezone support with automatic UTC conversion
306+
- **Maintained**: Complete backward compatibility with existing `days` parameter
307+
308+
### v3.1.4 - WebSocket Connection Fix
309+
- **Fixed**: Critical WebSocket error with missing `_use_batching` attribute
310+
- **Improved**: Proper mixin initialization in ProjectXRealtimeClient
311+
- **Enhanced**: More robust real-time connection handling
312+
313+
### v3.0.2 - Bug Fixes and Improvements
314+
- **Order Lifecycle Tracking**: Fixed asyncio concurrency and field reference issues
315+
- **Order Templates**: Fixed instrument lookup to use cached object
316+
- **Cleanup Functionality**: Added comprehensive order/position cleanup
317+
- **Documentation**: Updated all docs to reflect current version
318+
303319
### v3.0.1 - Production Ready
304320
- **Performance Optimizations**: Enhanced connection pooling and caching
305321
- **Event Bus System**: Unified event handling across all components
@@ -319,29 +335,31 @@ async with ProjectX.from_env() as client:
319335
- All core modules organized as packages with focused submodules
320336
- Improved code organization and maintainability
321337

322-
### Trading Suite Usage
338+
### Trading Suite Usage (v3.0.0+)
323339
```python
324340
# Complete trading suite with all managers
325-
from project_x_py import create_trading_suite
341+
from project_x_py import TradingSuite
326342

327343
async def main():
328-
suite = await create_trading_suite(
329-
instrument="MNQ",
344+
suite = await TradingSuite.create(
345+
"MNQ",
330346
timeframes=["1min", "5min"],
331-
enable_orderbook=True,
332-
enable_risk_management=True
347+
features=["orderbook", "risk_manager"],
348+
initial_days=5
333349
)
334350

335351
# All managers are integrated and ready
336-
await suite.start()
352+
# No need to call start() - already connected
337353

338354
# Access individual managers
339-
order = await suite.order_manager.place_market_order(
340-
"MNQ", 1, "BUY"
355+
order = await suite.orders.place_market_order(
356+
contract_id=suite.instrument_info.id,
357+
side=0, # Buy
358+
size=1
341359
)
342360

343-
position = suite.position_manager.get_position("MNQ")
344-
bars = suite.data_manager.get_bars("MNQ", "1min")
361+
position = await suite.positions.get_position("MNQ")
362+
bars = await suite.data.get_data("1min")
345363
```
346364

347365
### Key Async Examples
@@ -351,24 +369,23 @@ async with ProjectX.from_env() as client:
351369
await client.authenticate()
352370
bars = await client.get_bars("MNQ", days=5)
353371

354-
# Real-time data
372+
# Real-time data with TradingSuite
355373
async def stream_data():
356-
async with ProjectX.from_env() as client:
357-
await client.authenticate()
358-
359-
realtime = await create_realtime_client(
360-
client.jwt_token,
361-
str(client.account_id)
362-
)
363-
364-
data_manager = create_realtime_data_manager(
365-
"MNQ", client, realtime
366-
)
367-
368-
# Set up callbacks
369-
data_manager.on_bar_received = handle_bar
370-
371-
# Start streaming
372-
await realtime.connect()
373-
await data_manager.start_realtime_feed()
374+
suite = await TradingSuite.create(
375+
"MNQ",
376+
timeframes=["1min", "5min"]
377+
)
378+
379+
# Register event handlers
380+
from project_x_py import EventType
381+
382+
async def handle_bar(event):
383+
print(f"New bar: {event.data}")
384+
385+
await suite.on(EventType.NEW_BAR, handle_bar)
386+
387+
# Data is already streaming
388+
# Access current data
389+
current_price = await suite.data.get_current_price()
390+
bars = await suite.data.get_data("1min")
374391
```

0 commit comments

Comments
 (0)