Skip to content

Commit 06864f9

Browse files
TexasCodingclaude
andcommitted
fix: resolve session method failures in CI for multi-instrument mode
The session methods (set_session_type, get_session_data, get_session_statistics) were failing in CI because they were checking for self._data which doesn't exist in multi-instrument mode. Updated to properly handle both single and multi-instrument modes by accessing data through instrument contexts. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent 8fda19f commit 06864f9

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

src/project_x_py/trading_suite.py

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,9 +1393,20 @@ async def set_session_type(self, session_type: SessionType) -> None:
13931393
await suite.set_session_type(SessionType.RTH)
13941394
```
13951395
"""
1396-
if hasattr(self, "_data") and hasattr(self._data, "set_session_type"):
1397-
await self._data.set_session_type(session_type)
1398-
logger.info(f"Session type changed to {session_type}")
1396+
# Handle single instrument mode (backward compatibility)
1397+
if self._is_single_instrument and self._single_context:
1398+
if hasattr(self._single_context.data, "set_session_type"):
1399+
await self._single_context.data.set_session_type(session_type)
1400+
logger.info(f"Session type changed to {session_type}")
1401+
# Handle multi-instrument mode
1402+
else:
1403+
for context in self._contexts.values():
1404+
if hasattr(context.data, "set_session_type"):
1405+
await context.data.set_session_type(session_type)
1406+
if self._contexts:
1407+
logger.info(
1408+
f"Session type changed to {session_type} for all instruments"
1409+
)
13991410

14001411
async def get_session_data(
14011412
self, timeframe: str, session_type: SessionType | None = None
@@ -1416,12 +1427,25 @@ async def get_session_data(
14161427
rth_data = await suite.get_session_data("1min", SessionType.RTH)
14171428
```
14181429
"""
1419-
if hasattr(self, "_data") and hasattr(self._data, "get_session_data"):
1420-
return await self._data.get_session_data(timeframe, session_type)
1421-
# Fallback to regular data if no session support
1422-
if hasattr(self, "_data"):
1423-
return await self._data.get_data(timeframe)
1424-
return None
1430+
# Handle single instrument mode (backward compatibility)
1431+
if self._is_single_instrument and self._single_context:
1432+
if hasattr(self._single_context.data, "get_session_data"):
1433+
return await self._single_context.data.get_session_data(
1434+
timeframe, session_type
1435+
)
1436+
# Fallback to regular data if no session support
1437+
return await self._single_context.data.get_data(timeframe)
1438+
1439+
# Handle multi-instrument mode - return dict of data
1440+
result = {}
1441+
for symbol, context in self._contexts.items():
1442+
if hasattr(context.data, "get_session_data"):
1443+
result[symbol] = await context.data.get_session_data(
1444+
timeframe, session_type
1445+
)
1446+
else:
1447+
result[symbol] = await context.data.get_data(timeframe)
1448+
return result if result else None
14251449

14261450
async def get_session_statistics(self, timeframe: str = "1min") -> dict[str, Any]:
14271451
"""
@@ -1437,9 +1461,18 @@ async def get_session_statistics(self, timeframe: str = "1min") -> dict[str, Any
14371461
print(f"ETH Volume: {stats['eth_volume']}")
14381462
```
14391463
"""
1440-
if hasattr(self, "_data") and hasattr(self._data, "get_session_statistics"):
1441-
return await self._data.get_session_statistics(timeframe)
1442-
return {}
1464+
# Handle single instrument mode (backward compatibility)
1465+
if self._is_single_instrument and self._single_context:
1466+
if hasattr(self._single_context.data, "get_session_statistics"):
1467+
return await self._single_context.data.get_session_statistics(timeframe)
1468+
return {}
1469+
1470+
# Handle multi-instrument mode - return dict of stats per instrument
1471+
result = {}
1472+
for symbol, context in self._contexts.items():
1473+
if hasattr(context.data, "get_session_statistics"):
1474+
result[symbol] = await context.data.get_session_statistics(timeframe)
1475+
return result if result else {}
14431476

14441477
# --- Container Protocol Methods ---
14451478
def __getitem__(self, symbol: str) -> InstrumentContext:

0 commit comments

Comments
 (0)