diff --git a/pocketoptionapi_async/client.py b/pocketoptionapi_async/client.py index 2c162e5..7c9f261 100644 --- a/pocketoptionapi_async/client.py +++ b/pocketoptionapi_async/client.py @@ -85,11 +85,10 @@ def __init__(self, ssid: str, is_demo: bool = True, region: Optional[str] = None # Add handler for JSON data messages (contains detailed order data) self._websocket.add_event_handler('json_data', self._on_json_data) - - # Enhanced monitoring and error handling + # Enhanced monitoring and error handling + from .monitoring import error_monitor, health_checker self._error_monitor = error_monitor self._health_checker = health_checker - self._connection_health_checks() # Performance tracking self._operation_metrics: Dict[str, List[float]] = defaultdict(list) @@ -920,8 +919,7 @@ async def _on_authenticated(self, data: Dict[str, Any]) -> None: if self.enable_logging: logger.success("✅ Successfully authenticated with PocketOption") self._connection_stats['successful_connections'] += 1 - await self._emit_event('authenticated', data) - + await self._emit_event('authenticated', data) async def _on_balance_updated(self, data: Dict[str, Any]) -> None: """Handle balance update""" try: @@ -964,7 +962,34 @@ async def _on_stream_update(self, data: Dict[str, Any]) -> None: async def _on_candles_received(self, data: Dict[str, Any]) -> None: """Handle candles data received""" if self.enable_logging: - logger.info(f"🕯️ Candles received: {len(data)} data points") + logger.info(f"🕯️ Candles received with data: {type(data)}") + + # Check if we have pending candle requests + if hasattr(self, '_candle_requests') and self._candle_requests: + # Parse the candles data + try: + candles = self._parse_candles_data(data) + if self.enable_logging: + logger.info(f"🕯️ Parsed {len(candles)} candles from response") + + # Resolve any pending futures (take the first one for now) + # In a more sophisticated implementation, we could match by asset/timeframe + for request_id, future in list(self._candle_requests.items()): + if not future.done(): + future.set_result(candles) + if self.enable_logging: + logger.debug(f"Resolved candle request: {request_id}") + break + + except Exception as e: + if self.enable_logging: + logger.error(f"Error processing candles data: {e}") + # Resolve futures with empty result + for request_id, future in list(self._candle_requests.items()): + if not future.done(): + future.set_result([]) + break + await self._emit_event('candles_received', data) async def _on_disconnected(self, data: Dict[str, Any]) -> None: diff --git a/client_test.py b/tests/client_test.py similarity index 100% rename from client_test.py rename to tests/client_test.py diff --git a/enhanced_test.py b/tests/enhanced_test.py similarity index 100% rename from enhanced_test.py rename to tests/enhanced_test.py diff --git a/integration_tests.py b/tests/integration_tests.py similarity index 100% rename from integration_tests.py rename to tests/integration_tests.py diff --git a/test_balance_fix.py b/tests/test_balance_fix.py similarity index 100% rename from test_balance_fix.py rename to tests/test_balance_fix.py diff --git a/test_candles_fix.py b/tests/test_candles_fix.py similarity index 100% rename from test_candles_fix.py rename to tests/test_candles_fix.py diff --git a/test_complete_order_tracking.py b/tests/test_complete_order_tracking.py similarity index 100% rename from test_complete_order_tracking.py rename to tests/test_complete_order_tracking.py diff --git a/test_complete_ssid.py b/tests/test_complete_ssid.py similarity index 100% rename from test_complete_ssid.py rename to tests/test_complete_ssid.py diff --git a/test_demo_live_connection.py b/tests/test_demo_live_connection.py similarity index 100% rename from test_demo_live_connection.py rename to tests/test_demo_live_connection.py diff --git a/test_demo_live_fix.py b/tests/test_demo_live_fix.py similarity index 100% rename from test_demo_live_fix.py rename to tests/test_demo_live_fix.py diff --git a/test_fixed_connection.py b/tests/test_fixed_connection.py similarity index 100% rename from test_fixed_connection.py rename to tests/test_fixed_connection.py diff --git a/test_new_api.py b/tests/test_new_api.py similarity index 100% rename from test_new_api.py rename to tests/test_new_api.py diff --git a/test_order_fix.py b/tests/test_order_fix.py similarity index 100% rename from test_order_fix.py rename to tests/test_order_fix.py diff --git a/test_order_logging_fixes.py b/tests/test_order_logging_fixes.py similarity index 100% rename from test_order_logging_fixes.py rename to tests/test_order_logging_fixes.py diff --git a/test_order_placement_fix.py b/tests/test_order_placement_fix.py similarity index 100% rename from test_order_placement_fix.py rename to tests/test_order_placement_fix.py diff --git a/test_order_tracking_complete.py b/tests/test_order_tracking_complete.py similarity index 100% rename from test_order_tracking_complete.py rename to tests/test_order_tracking_complete.py diff --git a/test_order_tracking_fix.py b/tests/test_order_tracking_fix.py similarity index 100% rename from test_order_tracking_fix.py rename to tests/test_order_tracking_fix.py diff --git a/test_persistent_connection.py b/tests/test_persistent_connection.py similarity index 100% rename from test_persistent_connection.py rename to tests/test_persistent_connection.py diff --git a/test_ssid_formats.py b/tests/test_ssid_formats.py similarity index 100% rename from test_ssid_formats.py rename to tests/test_ssid_formats.py