Skip to content

Commit 579fe60

Browse files
TexasCodingclaude
andcommitted
fix(stats): Address typing and timing issues in statistics tracking
- Fixed timing measurement in _process_tick_data to properly track duration - Added null check for order_obj to prevent union-attr type errors - Added pyright ignore comments for mixin attribute access - Track both successful and failed operations with accurate timings All mypy type checks now pass! 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
1 parent a56d80d commit 579fe60

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/project_x_py/order_manager/tracking.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ async def fill_handler(event: Any) -> None:
410410
event_order_id = event_data.get("order_id")
411411
if not event_order_id and "order" in event_data:
412412
order_obj = event_data.get("order")
413-
if hasattr(order_obj, "id"):
413+
if order_obj and hasattr(order_obj, "id"):
414414
event_order_id = order_obj.id
415415
if event_order_id == order_id:
416416
is_filled = True
@@ -425,7 +425,7 @@ async def terminal_handler(event: Any) -> None:
425425
event_order_id = event_data.get("order_id")
426426
if not event_order_id and "order" in event_data:
427427
order_obj = event_data.get("order")
428-
if hasattr(order_obj, "id"):
428+
if order_obj and hasattr(order_obj, "id"):
429429
event_order_id = order_obj.id
430430
if event_order_id == order_id:
431431
is_filled = False

src/project_x_py/realtime_data_manager/data_processing.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ async def _process_tick_data(self, tick: dict[str, Any]) -> None:
290290
Args:
291291
tick: Dictionary containing tick data (timestamp, price, volume, etc.)
292292
"""
293+
import time
294+
295+
start_time = time.time()
293296
try:
294297
if not self.is_running:
295298
return
@@ -298,15 +301,6 @@ async def _process_tick_data(self, tick: dict[str, Any]) -> None:
298301
price = tick["price"]
299302
volume = tick.get("volume", 0)
300303

301-
# Track tick processing if enhanced stats available
302-
if hasattr(self, "track_operation"):
303-
await self.track_operation(
304-
"process_tick",
305-
0.1, # Placeholder timing, actual timing tracked elsewhere
306-
success=True,
307-
metadata={"price": price, "volume": volume},
308-
)
309-
310304
# Collect events to trigger after releasing the lock
311305
events_to_trigger = []
312306

@@ -338,8 +332,27 @@ async def _process_tick_data(self, tick: dict[str, Any]) -> None:
338332
self.memory_stats["ticks_processed"] += 1
339333
await self._cleanup_old_data()
340334

335+
# Track operation timing if enhanced stats available
336+
if hasattr(self, "track_operation"):
337+
duration_ms = (time.time() - start_time) * 1000
338+
await self.track_operation( # pyright: ignore[reportAttributeAccessIssue]
339+
"process_tick",
340+
duration_ms,
341+
success=True,
342+
metadata={"price": price, "volume": volume},
343+
)
344+
341345
except Exception as e:
342346
self.logger.error(f"Error processing tick data: {e}")
347+
# Track failed operation if enhanced stats available
348+
if hasattr(self, "track_operation"):
349+
duration_ms = (time.time() - start_time) * 1000
350+
await self.track_operation( # pyright: ignore[reportAttributeAccessIssue]
351+
"process_tick",
352+
duration_ms,
353+
success=False,
354+
metadata={"error": str(e)},
355+
)
343356

344357
async def _update_timeframe_data(
345358
self,

0 commit comments

Comments
 (0)