Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions pocketoptionapi_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,21 +973,13 @@ def _parse_candles_data(self, candles_data: List[Any], asset: str, timeframe: in
if isinstance(candles_data, list):
for candle_data in candles_data:
if isinstance(candle_data, (list, tuple)) and len(candle_data) >= 5:
# Server format: [timestamp, open, low, high, close]
# Note: Server sends low/high swapped compared to standard OHLC format
raw_high = float(candle_data[2])
raw_low = float(candle_data[3])

# Ensure high >= low by swapping if necessary
actual_high = max(raw_high, raw_low)
actual_low = min(raw_high, raw_low)

# Server format: [timestamp, open, close, high, low]
candle = Candle(
timestamp=datetime.fromtimestamp(candle_data[0]),
open=float(candle_data[1]),
high=actual_high,
low=actual_low,
close=float(candle_data[4]),
high=float(candle_data[3]),
low=float(candle_data[4]),
close=float(candle_data[2]),
volume=float(candle_data[5])
if len(candle_data) > 5
else 0.0,
Expand Down Expand Up @@ -1263,7 +1255,8 @@ def _parse_stream_candles(
timeframe=timeframe,
)
candles.append(candle)
elif isinstance(item, (list, tuple)) and len(item) >= 6:
elif isinstance(item, (list, tuple)) and len(item) >= 5:
# Server format: [timestamp, open, close, high, low]
candle = Candle(
timestamp=datetime.fromtimestamp(item[0]),
open=float(item[1]),
Expand Down