Skip to content

Commit c66242d

Browse files
TexasCodingclaude
andcommitted
Phase 7: Clean up unused features and dead code
- Removed unused imports (overload, Any) from multiple files - Cleaned up commented-out code blocks in position_manager and realtime modules - Fixed remaining linting issues (isinstance union types, bare except clauses) - Auto-fixed import ordering and Optional type hints - Verified no duplicate utility functions exist - All deprecated features properly marked for v4.0.0 removal 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent e5c18c0 commit c66242d

File tree

8 files changed

+14
-35
lines changed

8 files changed

+14
-35
lines changed

src/project_x_py/client/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def main():
5252
"""
5353

5454
import time
55-
from typing import TYPE_CHECKING, Any, TypeVar, overload
55+
from typing import TYPE_CHECKING, Any, TypeVar
5656

5757
import httpx
5858

src/project_x_py/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"""
114114

115115
from dataclasses import dataclass
116-
from typing import Any, Union
116+
from typing import Union
117117

118118
__all__ = [
119119
"Account",

src/project_x_py/order_manager/tracking.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ def add_callback(
336336
This method is provided for backward compatibility only and will be removed in v4.0.
337337
"""
338338
# Deprecation warning handled by decorator
339-
pass
340339

341340
async def _trigger_callbacks(self, event_type: str, data: Any) -> None:
342341
"""

src/project_x_py/position_manager/core.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ async def main():
8080
from project_x_py.position_manager.monitoring import PositionMonitoringMixin
8181
from project_x_py.position_manager.operations import PositionOperationsMixin
8282
from project_x_py.position_manager.reporting import PositionReportingMixin
83-
84-
# from project_x_py.position_manager.risk import RiskManagementMixin # DEPRECATED
8583
from project_x_py.position_manager.tracking import PositionTrackingMixin
8684
from project_x_py.risk_manager import RiskManager
8785
from project_x_py.types.config_types import PositionManagerConfig

src/project_x_py/position_manager/operations.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ async def close_position_direct(
172172

173173
# Synchronize orders - cancel related orders when position is closed
174174
# Note: Order synchronization methods will be added to AsyncOrderManager
175-
# if self._order_sync_enabled and self.order_manager:
176-
# await self.order_manager.on_position_closed(contract_id)
177175

178176
self.stats["closed_positions"] += 1
179177
else:
@@ -300,10 +298,6 @@ async def partially_close_position(
300298

301299
# Synchronize orders - update order sizes after partial close
302300
# Note: Order synchronization methods will be added to AsyncOrderManager
303-
# if self._order_sync_enabled and self.order_manager:
304-
# await self.order_manager.sync_orders_with_position(
305-
# contract_id, account_id
306-
# )
307301

308302
self.stats["positions_partially_closed"] += 1
309303
else:

src/project_x_py/realtime/__init__.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,8 @@ async def on_quote_update(event):
7878
await suite.disconnect()
7979
8080
81-
# V3.1: Low-level direct usage (advanced users only)
82-
# from project_x_py import ProjectX
83-
# from project_x_py.realtime import ProjectXRealtimeClient
84-
#
85-
# async def low_level_example():
86-
# async with ProjectX.from_env() as client:
87-
# await client.authenticate()
88-
# # Create real-time client directly
89-
# realtime = ProjectXRealtimeClient(
90-
# jwt_token=client.session_token,
91-
# account_id=str(client.account_info.id),
92-
# )
93-
# await realtime.connect()
94-
# await realtime.subscribe_market_data(["MNQ", "ES"])
81+
# V3.1: Low-level direct usage is available for advanced users
82+
# See documentation for direct ProjectXRealtimeClient usage
9583
9684
asyncio.run(main())
9785
```

src/project_x_py/utils/stats_tracking.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import traceback
1111
from collections import deque
1212
from datetime import datetime
13-
from typing import Any, Optional
13+
from typing import Any
1414

1515

1616
class StatsTrackingMixin:
@@ -30,14 +30,14 @@ def _init_stats_tracking(self, max_errors: int = 100) -> None:
3030
"""
3131
self._error_count = 0
3232
self._error_history: deque[dict[str, Any]] = deque(maxlen=max_errors)
33-
self._last_activity: Optional[datetime] = None
33+
self._last_activity: datetime | None = None
3434
self._start_time = time.time()
3535

3636
def _track_error(
3737
self,
3838
error: Exception,
39-
context: Optional[str] = None,
40-
details: Optional[dict[str, Any]] = None,
39+
context: str | None = None,
40+
details: dict[str, Any] | None = None,
4141
) -> None:
4242
"""
4343
Track an error occurrence.
@@ -95,11 +95,11 @@ def get_memory_usage_mb(self) -> float:
9595
size += sys.getsizeof(attr)
9696

9797
# For collections, also count items
98-
if isinstance(attr, (list, dict, set, deque)):
98+
if isinstance(attr, list | dict | set | deque):
9999
try:
100100
for item in attr.values() if isinstance(attr, dict) else attr:
101101
size += sys.getsizeof(item)
102-
except:
102+
except (AttributeError, TypeError):
103103
pass # Skip if iteration fails
104104

105105
# Convert to MB

src/project_x_py/utils/task_management.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import asyncio
1212
import logging
13-
from typing import TYPE_CHECKING, Any, Optional
13+
from typing import TYPE_CHECKING, Any
1414
from weakref import WeakSet
1515

1616
if TYPE_CHECKING:
@@ -51,7 +51,7 @@ def _init_task_manager(self) -> None:
5151
self._cleanup_in_progress = False
5252

5353
def _create_task(
54-
self, coro: Any, name: Optional[str] = None, persistent: bool = False
54+
self, coro: Any, name: str | None = None, persistent: bool = False
5555
) -> "Task[Any]":
5656
"""
5757
Create and track an async task.
@@ -136,7 +136,7 @@ async def _cleanup_tasks(self, timeout: float = 5.0) -> None:
136136
asyncio.gather(*pending_tasks, return_exceptions=True),
137137
timeout=timeout,
138138
)
139-
except asyncio.TimeoutError:
139+
except TimeoutError:
140140
logger.warning(
141141
f"{len([t for t in pending_tasks if not t.done()])} tasks "
142142
f"did not complete within {timeout}s timeout"
@@ -212,7 +212,7 @@ async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
212212

213213

214214
def create_fire_and_forget_task(
215-
coro: Any, name: Optional[str] = None, error_handler: Optional[callable] = None
215+
coro: Any, name: str | None = None, error_handler: callable | None = None
216216
) -> "Task[Any]":
217217
"""
218218
Create a fire-and-forget task with optional error handling.

0 commit comments

Comments
 (0)