
    5i                         S SK r S SKJr  S SKrS SKJrJrJr  S SKrS SK	r	S SK
J
r
Jr  S SKJr  S\S\4S jrS	\S\\   4S
 jrS\\\4   S\\\4   S\4S jrS rS rS rg)    N)Decimal)UnionOptionalDict)datetimetimezone)UnknownDateFormatdate_strreturnc                 f   [         R                  " S[        R                  5      n[        R
                  " U SS0S9nU(       d  [        U 5      eUR                  b  UR                  R                  U5      c  UR                  [        R                  S9n[        X!-
  R                  5       S-  5      $ )a$  Convert UTC date to milliseconds

If using offset strings add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"

See dateparse docs for formats http://dateparser.readthedocs.io/en/latest/

:param date_str: date in readable format, i.e. "January 01, 2018", "11 hours ago UTC", "now UTC"
r   TIMEZONEUTC)settings)tzinfog     @@)r   fromtimestampr   utc
dateparserparser	   r   	utcoffsetreplacepytzinttotal_seconds)r
   epochds      ]/var/www/html/BTCUSD/btcusdt_trading_app/venv/lib/python3.13/site-packages/binance/helpers.pydate_to_millisecondsr      s     ,,Qx||<E&,,XU@STA)) 	xx188--a08IITXXI& 	((*V344    intervalc                 r    SSSSSS.n [        U SS 5      XS      -  S	-  $ ! [        [        4 a     gf = f)
a?  Convert a Binance interval string to milliseconds

:param interval: Binance interval string, e.g.: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w

:return:
     int value of interval in milliseconds
     None if interval prefix is not a decimal integer
     None if interval suffix is not one of m, h, d, w

   <   i  iQ i:	 )smhr   wNi  )r   
ValueErrorKeyError)r   seconds_per_units     r   interval_to_millisecondsr+   &   sZ     (8CR=!$4b\$BBTII! s   # 66quantity	step_sizec           	      n    [        [        U 5      5      n [        X [        [        U5      5      -  -
  5      $ )zxRounds a given quantity to a specific step size

:param quantity: required
:param step_size: required

:return: decimal
)r   strfloat)r,   r-   s     r   round_step_sizer1   >   s.     s8}%Hws9~'>>>??r   c                 L    U c  U $ [        U 5      [        :X  a  U $ [        U 5      $ )N)typer   r   )ts_strs    r   convert_ts_strr5   L   s(    ~F|s''r   c                 \    U c  U $ [         R                  " U 5      nUR                  SS5      $ )N  )jsondumpsr   )lress     r   convert_list_to_json_arrayr=   T   s*    y
**Q-C;;sBr   c                       [         R                  " 5       n U $ ! [         aW  n[        U5      R	                  S5      (       a2  [         R
                  " 5       n [         R                  " U 5        U s SnA$ e SnAff = f)zcheck if there is an event loop in the current thread, if not create one
inspired by https://stackoverflow.com/questions/46727787/runtimeerror-there-is-no-current-event-loop-in-thread-in-async-apscheduler
z(There is no current event loop in threadN)asyncioget_event_loopRuntimeErrorr/   
startswithnew_event_loopset_event_loop)loopes     r   get_looprG   [   sd    	%%' q6GHH))+D""4(Ks!    
A:AA5.A:4A55A:)r?   decimalr   r9   typingr   r   r   r   r   r   r   binance.exceptionsr	   r/   r   r   r+   r0   r1   r5   r=   rG    r   r   <module>rL      s       ( (   ' 053 53 50s x} 0@E7N#@05eWn0E@
@( r   