+
    0.j                     x    R t ^ RIHt ^ RIHt ^ RIt^ RIt^ RI	t	^ RI
Ht ]! ]4      t ! R R4      t]! 4       tR# )zTechnical indicators service.)Decimal)AnyN)
get_loggerc                      a  ] tR t^t o Rt^2tV 3R lR ltRV 3R lR lltV 3R lR ltV 3R	 lR
 lt	RV 3R lR llt
RV 3R lR lltRV 3R lR lltV 3R lR ltV 3R lR ltRtV tR# )IndicatorsServicez<Calculate all required technical indicators from OHLCV data.c                J   < V ^8  d   QhRS[ S[,          RS[P                  /# )   candlesreturn)listdictpd	DataFrame)format__classdict__s   "IC:\xampp\htdocs\tradingbinance\backend\app\services\indicators_service.py__annotate__IndicatorsService.__annotate__   s#     
 
DJ 
2<< 
    c                R   \         P                  ! V4      pVP                  '       d   V# R F2  pW2P                  9   g   K  W#,          P	                  \
        4      W#&   K4  	  RVP                  9   d4   \         P                  ! VR,          4      VR&   VP                  RRR7       V# )open	open_timeT)inplace)r   highlowclosevolume)r   r   emptycolumnsastypefloatto_datetime	set_index)selfr	   dfcols   &&  r   candles_to_dataframe&IndicatorsService.candles_to_dataframe   s}    \\'"888I=Cjj '../ > "**$ nnR_=B{OLLdL3	r   Nc                `   < V ^8  d   QhRS[ S[,          RS[R,          RS[S[S[3,          /# )r   r	   paramsNr
   )r   r   strr   )r   r   s   "r   r   r       s<     C
 C
T$Z C
 C
PTUXZ]U]P^ C
r   c                
   T;'       g    / pV P                  V4      p\        V4      V P                  8  d   R RRV P                  R\        V4      /# VR,          pVR,          pVR,          pVR,          pVP                  R^	4      pVP                  R	^4      p	VP                  R
^4      p
VP                  R^4      pVP                  R^4      pVP                  R^4      pVP                  R^4      pVP                  R^4      pVP                  R^4      p\        P
                  P                  WHR7      p\        P
                  P                  WIR7      p\        P
                  P                  WJR7      p\        P
                  P                  WKR7      p\        P                  P                  WLR7      p\        P
                  P                  V4      p\        P                  P                  WMR7      p\        P                  P                  WVWNR7      p\        P
                  P                  WVWOR7      p\        P                  P                  WVVVR7      pV P!                  V4      pV P#                  V4      w  pp\%        VP'                  ^4      P)                  4       4      \%        VP'                  ^4      P+                  4       4      ppV P-                  V4      p V P/                  V4      p!R(p"/ R\%        VP0                  V",          4      bRV P3                  VV"4      bR	V P3                  VV"4      bR
V P3                  VV"4      bRV P3                  VV"4      bRV P3                  VV"4      bRV P3                  VP5                  4       V"4      bRV P3                  VP7                  4       V"4      bRV P3                  VP9                  4       V"4      bRV P3                  VP;                  4       V"4      bRV P3                  VP=                  4       V"4      bRV P3                  VP?                  4       V"4      bRV P3                  VPA                  4       V"4      bRV P3                  VV"4      bRV P3                  VV"4      bRV P3                  VPC                  4       V"4      bRV P3                  VPE                  4       V"4      bRVR VR!VR"VR#VR$V R%V!R&V PG                  VV4      R'V PI                  VP0                  V",          VV"4      /	C# ))errorinsufficient_datarequired	availabler   r   r   r   	sma_shortsma_long	ema_shortema_long
rsi_period	bb_period
atr_period
adx_periodstoch_period)windowpricersimacdmacd_signalmacd_histogrambb_upper	bb_middlebb_lowerbb_widthatradxstoch_kstoch_dvwapsupportsresistancesrecent_high
recent_lowhistorical_volatilityrelative_volumeema_crossoverprice_vs_bb)%r&   lenMIN_CANDLESgettatrendsma_indicatorema_indicatormomentumr;   MACD
volatilityBollingerBandsaverage_true_rangerD   StochasticOscillator_calculate_vwap_find_support_resistancer    tailmaxmin_historical_volatility_relative_volumeiloc_safe_floatr<   r=   	macd_diffbollinger_hbandbollinger_mavgbollinger_lbandbollinger_wbandstochstoch_signal_detect_crossover_price_bb_position)#r#   r	   r)   r$   r   r   r   r   r0   r1   r2   r3   r4   r5   r6   r7   r8   sma_ssma_lema_sema_lr;   r<   bbrC   rD   rl   rG   rH   rI   rJ   rK   hist_volatilityrM   
latest_idxs#   &&&                                r   calculate_allIndicatorsService.calculate_all    s   2&&w/r7T%%%0*d>N>NP[]`ac]dee7&ziHJJ{A.	::j"-JJ{B/	::j"-ZZb1
JJ{B/	ZZb1
ZZb1
zz."5&&u&?&&u&>&&u&?&&u&>kkooeo7xx}}U#]]))%)Bmm..t%.Shhll4el?00E,0W##B' $ = =b A+"'		"(9(9(;"<eCHHRLDTDTDV>WZ55e<//7

U5::j12
))%<
 ((
;
 ))%<	

 ((
;
 4##C4
 D$$TYY[*=
 4++D,<,<,>
K
 d..t~~/?L
 ((););)=zJ
 ))"*;*;*=zJ
 ((););)=zJ
 ((););)=zJ
 4##C4
 4##C4
  t''zB!
" t''(:(:(<jI#
$ D;;*#_T33E5A4225::j3I2zZ5
 	
r   c                N   < V ^8  d   QhRS[ P                  RS[RS[R,          /# )r   seriesidxr
   Nr   Seriesintr    )r   r   s   "r   r   r   e   s*      ")) # %$, r   c                z    VP                   V,          p\        P                  ! V4      '       d   R # \        V4      # N)re   r   isnar    )r#   rz   r{   vals   &&& r   rf   IndicatorsService._safe_floate   s*    kk#773<<Szr   c                H   < V ^8  d   QhRS[ P                  RS[R,          /# )r   r$   r
   N)r   r   r    )r   r   s   "r   r   r   k   s#      ",, 54< r   c                @   R VP                   9  g   VR ,          P                  4       ^ 8X  d   R# VR,          VR,          ,           VR,          ,           ^,          pW!R ,          ,          P                  4       VR ,          P                  4       ,          p\        V4      # )r   Nr   r   r   )r   sumr    )r#   r$   typical_pricerG   s   &&  r   r^   !IndicatorsService._calculate_vwapk   sv    2::%H)9)9);q)@Fbi/"W+=B8,113bl6F6F6HHT{r   c          	      v   < V ^8  d   QhRS[ P                  RS[RS[S[S[,          S[S[,          3,          /# )r   r$   r9   r
   )r   r   r~   tupler   r    )r   r   s   "r   r   r   r   s>     % %2<< % %eTXY^T_aefkalTlNm %r   c                0   VR ,          P                   pVR,          P                   p. . re\        V\        V4      V,
          4       F  pWG,          \        WGV,
          Wr,           ^,            4      8X  d!   VP	                  \        WG,          4      4       W7,          \        W7V,
          Wr,           ^,            4      8X  g   K}  VP	                  \        W7,          4      4       K  	  \        \        V4      4      RR p\        \        V4      4      RR pWV3# )r   r   N)	valuesrangerQ   rb   appendr    ra   sortedset)r#   r$   r9   highslowsrH   rI   is   &&&     r   r_   *IndicatorsService._find_support_resistancer   s    6
!!%y "B+vs2w/0Aw#dv:
Q?@@dg/x3uZ!*q.ABB""5?3	 1 #h-(-S-.rs3$$r   c                @   < V ^8  d   QhRS[ P                  RS[RS[/# )r   r   r9   r
   r|   )r   r   s   "r   r   r      s+     @ @BII @s @E @r   c                   \         P                  ! WP                  ^4      ,          4      P                  4       p\	        V4      V8  d   R# \        VP                  V4      P                  4       \         P                  ! R4      ,          4      # )           im  )	nplogshiftdropnarQ   r    r`   stdsqrt)r#   r   r9   returnss   &&& r   rc   (IndicatorsService._historical_volatility   s]    &&Q/0779w<& W\\&)--/"''#,>??r   c                @   < V ^8  d   QhRS[ P                  RS[RS[/# )r   r   r9   r
   r|   )r   r   s   "r   r   r      s&     0 0ryy 0# 0u 0r   c                    VP                  V4      P                  4       pV^ 8X  d   R# \        VP                  R,          V,          4      # )    r   rP   )r`   meanr    re   )r#   r   r9   avg_vols   &&& r   rd   "IndicatorsService._relative_volume   s;    ++f%**,a<V[[_w.//r   c                T   < V ^8  d   QhRS[ P                  RS[ P                  RS[/# )r   shortlongr
   )r   r}   r*   )r   r   s   "r   r   r      s*     	 	ryy 			 	c 	r   c                   \        V4      ^8  g[   \        P                  ! VP                  R,          4      '       g.   \        P                  ! VP                  R,          4      '       d   R# VP                  R,          VP                  R,          ,
          pVP                  R,          VP                  R,          ,
          pV^ u;8:  d
   V8  d    R#  V^ u;8  d
   V8  d    R#  R# R# )r   nonebullishbearishrP   )rQ   r   r   re   )r#   r   r   	prev_diff	curr_diffs   &&&  r   rn   #IndicatorsService._detect_crossover   s    u:>RWWUZZ^44		"8N8NJJrNTYYr]2	JJrNTYYr]2	%I% &%I% &r   c                Z   < V ^8  d   QhRS[ RS[P                  P                  RS[RS[/# )r   r:   rt   r{   r
   )r    rT   rZ   r[   r~   r*   )r   r   s   "r   r   r      s5     	 	 	2==3O3O 	VY 	^a 	r   c                   VP                  4       P                  V,          pVP                  4       P                  V,          p\        P                  ! V4      '       g   \        P                  ! V4      '       d   R # W8:  d   R# W8  d   R# R# )unknownbelow_lowerabove_upperwithin_bands)rh   re   rj   r   r   )r#   r:   rt   r{   upperlowers   &&&&  r   ro   $IndicatorsService._price_bb_position   sc    ""$))#.""$))#.775>>RWWU^^> > r    r   )
   )   )__name__
__module____qualname____firstlineno____doc__rR   r&   rw   rf   r^   r_   rc   rd   rn   ro   __static_attributes____classdictcell__)r   s   @r   r   r      sl     FK
 
C
 C
J  % %@ @0 0	 		 	r   r   )r   decimalr   typingr   numpyr   pandasr   rT   app.core.loggingr   r   loggerr   indicators_servicer   r   r   <module>r      s<    #     	 '	H	R Rj '( r   