
    i:                     $   d Z ddlmZ g dZ G d de      Z G d de      Z G d d	e      Z G d
 de      Z G d de      Z	 G d de      Z
 G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zy)a  
ProjectX Custom Exceptions

Author: @TexasCoding
Date: 2025-08-02

Overview:
    Defines custom exception classes for the ProjectX API client. Provides
    comprehensive error handling with categorized exceptions for different
    types of errors, including authentication, network, data validation,
    and trading-specific errors.

Key Features:
    - Hierarchical exception structure with base ProjectXError
    - Categorized exceptions for different error types
    - Error code support for programmatic error handling
    - Response data preservation for debugging
    - Comprehensive error context and metadata
    - Type-safe exception handling across the SDK

Exception Categories:
    - Authentication: Login, token, and permission errors
    - Connection: Network, timeout, and SSL errors
    - Server: Server-side errors and API issues
    - Client: Client-side errors and invalid requests
    - Data: Validation, parsing, and format errors
    - Trading: Order, position, and instrument errors

Example Usage:
    ```python
    from project_x_py.exceptions import (
        ProjectXError,
        ProjectXAuthenticationError,
        ProjectXRateLimitError,
        ProjectXOrderError,
    )

    try:
        await client.authenticate()
    except ProjectXAuthenticationError as e:
        print(f"Authentication failed: {e}")
        print(f"Error code: {e.error_code}")

    try:
        await order_manager.place_order(...)
    except ProjectXRateLimitError as e:
        print(f"Rate limit exceeded: {e}")
        # Handle rate limiting with retry logic

    try:
        await client.get_instrument("INVALID")
    except ProjectXInstrumentError as e:
        print(f"Instrument error: {e}")

    # Generic error handling
    try:
        # API operation
        pass
    except ProjectXError as e:
        print(f"ProjectX error: {e}")
        if e.response_data:
            print(f"Response data: {e.response_data}")
    ```

Exception Hierarchy:
    - ProjectXError: Base exception for all ProjectX errors
    - ProjectXAuthenticationError: Authentication and authorization errors
    - ProjectXRateLimitError: Rate limiting and throttling errors
    - ProjectXServerError: Server-side errors (5xx status codes)
    - ProjectXClientError: Client-side errors (4xx status codes)
    - ProjectXConnectionError: Network and connection errors
    - ProjectXDataError: Data validation and processing errors
    - ProjectXOrderError: Order placement and management errors
    - ProjectXPositionError: Position management errors
    - ProjectXInstrumentError: Instrument-related errors

Error Handling Features:
    - Error code support for programmatic handling
    - Response data preservation for debugging
    - Comprehensive error context and metadata
    - Type-safe exception handling
    - Hierarchical error categorization
    - Consistent error message formatting

See Also:
    - `utils.error_handler`: Error handling decorators and utilities
    - `utils.error_messages`: Standardized error messages
    )Any)InvalidOrderParametersProjectXAuthenticationErrorProjectXClientErrorProjectXConnectionErrorProjectXDataErrorProjectXErrorProjectXInstrumentErrorProjectXOrderErrorProjectXPositionErrorProjectXRateLimitErrorProjectXServerErrorRiskLimitExceededc            	       L     e Zd ZdZ	 	 ddededz  deeef   dz  f fdZ xZ	S )r	   z'Base exception for ProjectX API errors.Nmessage
error_coderesponse_datac                 H    t         |   |       || _        |xs i | _        y)z
        Initialize ProjectX error.

        Args:
            message: Error message
            error_code: Optional error code
            response_data: Optional response data from API
        N)super__init__r   r   )selfr   r   r   	__class__s       P/home/work/apex_v16/venv/lib/python3.12/site-packages/project_x_py/exceptions.pyr   zProjectXError.__init__o   s&     	!$*0b    )NN)
__name__
__module____qualname____doc__strintdictr   r   __classcell__)r   s   @r   r	   r	   l   sE    1
 "&/3	11 $J1 CH~,	1 1r   r	   c                       e Zd ZdZy)r   zAuthentication-related errors.Nr   r   r   r    r   r   r   r          (r   r   c                       e Zd ZdZy)r   zRate limiting errors.Nr$   r%   r   r   r   r      s    r   r   c                       e Zd ZdZy)r   zServer-side errors (5xx).Nr$   r%   r   r   r   r          #r   r   c                       e Zd ZdZy)r   zClient-side errors (4xx).Nr$   r%   r   r   r   r      r)   r   r   c                       e Zd ZdZy)r   zConnection and network errors.Nr$   r%   r   r   r   r      r&   r   r   c                       e Zd ZdZy)r   z&Data validation and processing errors.Nr$   r%   r   r   r   r          0r   r   c                       e Zd ZdZy)r   z&Order placement and management errors.Nr$   r%   r   r   r   r      r-   r   r   c                       e Zd ZdZy)r   zPosition management errors.Nr$   r%   r   r   r   r          %r   r   c                       e Zd ZdZy)r
   zInstrument-related errors.Nr$   r%   r   r   r
   r
      s    $r   r
   c                       e Zd ZdZy)r   zRisk limit exceeded errors.Nr$   r%   r   r   r   r      r0   r   r   c                       e Zd ZdZy)r   z Invalid order parameters errors.Nr$   r%   r   r   r   r      s    *r   r   N)r   typingr   __all__	Exceptionr	   r   r   r   r   r   r   r   r   r
   r   r   r%   r   r   <module>r7      s   Wr  1I 1,)- ) ]  $- $$- $)m )1 11 1&M &%m %& &+] +r   