
    Z-"i              	           S SK r S SKJr  S SKr\\\\4   r " S S\5      r " S S\5      r " S S\5      r	S	\4S
 jr
S	\4S jrS	\4S jr   SS\S\S\S	\4S jjrS\S	\4S jrg)    N)Tuplec                       \ rS rSrS rSrg)URL   c                    U(       a  US   n[        U[        5      (       d-  [        U[        5      (       d  [        S[	        U5       S35      eUR                  S5      (       dQ  UR                  S5      (       d;  UR                  S5      (       d%  UR                  S5      (       d  [        SU S	35      e[        R                  " U /UQ76 $ )
z9
note: we use *value and v0 to allow an empty URL string
r   zUnexpected type for URL: ""zhttp://zhttps://zws://zwss://zPassed string value "z&" is not an "http*://" or "ws*://" URL)
isinstancestrr   	TypeErrortype
startswith
ValueError__new__)clsvaluev0s      Q/home/james-whalen/.local/lib/python3.13/site-packages/alpaca_trade_api/common.pyr   URL.__new__	   s     qBr3'':b#+>+>"<T"XJa HIIMM),,j0I0IMM'**bmmH.E.E #8 =? "@ A A{{3'''     N)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s    (r   r   c                       \ rS rSrSrS rSrg)DATE   z&
date string in the format YYYY-MM-DD
c                 x   U(       d  [        S5      e[        U[        5      (       d  [        S[	        U5       S35      eUR                  S5      S:w  a  [        SU 35      e [        R                  R                  U5        [        R                  X5      $ ! [         a  nU SU 3n[        U5      eS nAff = f)NzUnexpected empty stringzUnexpected type for DATE: "r   -   z5Unexpected date structure. expected "YYYY-MM-DD" got z is not a valid date string: )r   r	   r
   r   r   countdateutilparserparse	Exceptionr   )r   r   emsgs       r   r   DATE.__new__   s    677%%%9$u+aHII;;sq   1169 : :	!OO!!%( {{3&&  	!G8<CC. 	!s   $B 
B9"B44B9r   Nr   r   r   r   __doc__r   r   r   r   r   r   r      s    'r   r   c                       \ rS rSrSrS rSrg)FLOAT-   z
api allows passing floats or float as strings.
let's make sure that param passed is one of the two, so we don't pass
invalid strings all the way to the servers.
c                     [        U[        5      (       d  [        U[        5      (       a  U$ [        U[        5      (       a  [        UR	                  5       5      $ [        SU S35      e)NzUnexpected float format "r   )r	   floatintr
   stripr   )r   r   s     r   r   FLOAT.__new__4   sS    eU##z%'='=LeS!!''4UG1=>>r   r   Nr*   r   r   r   r-   r-   -   s    ?r   r-   returnc                  r    [        [        R                  R                  SS5      R	                  S5      5      $ )NAPCA_API_BASE_URLzhttps://api.alpaca.markets/r   osenvirongetrstripr   r   r   get_base_urlr=   <   s/    rzz~~9;;A6#;H Hr   c                  r    [        [        R                  R                  SS5      R	                  S5      5      $ )NAPCA_API_DATA_URLzhttps://data.alpaca.marketsr7   r8   r   r   r   get_data_urlr@   A   s/    rzz~~:<<BF3KI Ir   c                  r    [        [        R                  R                  SS5      R	                  S5      5      $ )NAPCA_API_STREAM_URLz"https://stream.data.alpaca.marketsr7   r8   r   r   r   get_data_stream_urlrC   F   s-    rzz~~,..4fSk r   key_id
secret_keyoauthc                 @   U=(       d    [         R                  R                  S5      nU =(       d    [         R                  R                  S5      n U c  Uc  [        SS5      eU=(       d    [         R                  R                  S5      nUc  Uc  [        S5      eXU4$ )NAPCA_API_OAUTH_TOKENAPCA_API_KEY_IDz/Key ID must be given to access Alpaca trade APIz (env: APCA_API_KEY_ID)APCA_API_SECRET_KEYzMSecret key must be given to access Alpaca trade API (env: APCA_API_SECRET_KEY)r9   r:   r;   r   )rD   rE   rF   s      r   get_credentialsrK   M   s     ;RZZ^^$:;E8rzz~~&78F~%-J24 	4 Drzz~~.CDJem 6 7 	7 u$$r   api_versionc                 `    U =(       d    [         R                  R                  S5      n U c  Sn U $ )NAPCA_API_VERSIONv2)r9   r:   r;   )rL   s    r   get_api_versionrP   _   s+    C0B!CKr   )NNN)r9   typingr   dateutil.parserr#   r
   Credentialsr   r   r-   r=   r@   rC   rK   rP   r   r   r   <module>rT      s    	  CcM"(# ( '3 '*?C ?Hc H
Ic I
S  #'&*!%%C % #%%*5%$  r   