Skip to content

Commit 3b3540a

Browse files
committed
fix: Align current price to tick size in get_current_price()
- Apply tick alignment when getting price from tick data - Bar close prices are already aligned from previous fix - Ensures get_current_price() always returns tick-aligned values This fixes the issue where current price could be misaligned (e.g., $23,927.62) when sourced from raw tick data.
1 parent 858e490 commit 3b3540a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/project_x_py/realtime_data_manager/data_access.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class DataAccessMixin:
112112
data_lock: "asyncio.Lock"
113113
data: dict[str, pl.DataFrame]
114114
current_tick_data: list[dict[str, Any]] | deque[dict[str, Any]]
115+
tick_size: float
115116

116117
async def get_data(
117118
self,
@@ -235,9 +236,14 @@ async def get_current_price(self) -> float | None:
235236
"""
236237
# Try to get from tick data first
237238
if self.current_tick_data:
238-
return float(self.current_tick_data[-1]["price"])
239+
# Import here to avoid circular import
240+
from project_x_py.order_manager.utils import align_price_to_tick
239241

240-
# Fallback to most recent bar close
242+
raw_price = float(self.current_tick_data[-1]["price"])
243+
# Align the price to tick size
244+
return align_price_to_tick(raw_price, self.tick_size)
245+
246+
# Fallback to most recent bar close (already aligned)
241247
async with self.data_lock:
242248
for tf_key in ["1min", "5min", "15min"]: # Check common timeframes
243249
if tf_key in self.data and not self.data[tf_key].is_empty():

0 commit comments

Comments
 (0)