
    [i                     0    d dl Zd dlZdej        defdZdS )    Ndfreturnc                    | t          |           dk     rdS t          j                            | d         | d         | d         d          }|                                                                }|j        rdS t          |j        d	                   }|	                                                                }|
                                                                }|j        st          |j        d	                   nd
}|j        st          |j        d	                   nd
}t          j                            | d         dd          }d
}	|                                                                }
|                                                                }|                                                                }|
j        si|j        sb|j        s[t          |j        d	                   }|dk    r;t          |
j        d	                   t          |j        d	                   z
  |z  dz  }	|dk    r
||k    rdS dS |	dk    rdS dS )uG  
    Classify the current market condition using ADX and Bollinger Band width.

    Returns one of:
        TRENDING_UP      — ADX > 25 and price above midline
        TRENDING_DOWN    — ADX > 25 and price below midline
        HIGH_VOLATILITY  — BB width > 5% of midband
        SIDEWAYS         — everything else
    N   SIDEWAYShighlowclose   )windowg              )r   
window_devr   d      TRENDING_UPTRENDING_DOWNg      @HIGH_VOLATILITY)lenta_libtrendADXIndicatoradxdropnaemptyfloatilocadx_posadx_neg
volatilityBollingerBandsbollinger_hbandbollinger_lbandbollinger_mavg)r   adx_indicator
adx_seriesadx_val
dmp_series
dmn_seriesdmp_valdmn_valbb_indicatorbb_widthupperlowermidmid_vals                 =/var/www/html/crypto-bot/backend/app/core/market_condition.pydetect_market_conditionr4      s$    
zSWWr\\z L--bj"U)R[Y[-\\M""$$++--J zJOB'((G&&((//11J&&((//11J0:0@IeJOB'(((cG0:0@IeJOB'(((cG $33BwKWX3YYLH((**1133E((**1133E

%
%
'
'
.
.
0
0C; Wu{ W39 W%%Q;;ejn--ejn0E0EEPSVVH||W ="?#~~  :    )pandaspdtar   	DataFramestrr4    r5   r3   <module>r<      sK           - - - - - - - -r5   