o
    bZ1h
                     @   s   d dl Z d dlmZ d dlmZmZmZmZ d dlZd dl	Z
ed ededdZeje de d	e d
ddZejddgddd Zejddgddd ZdS )    N)load_dotenv)	Blueprintrender_templatejsonifyrequestz$/var/www/html/backtestingmarket/.envccitm	templates)template_folderappKey	appSecretcallbackUrlT)verbosez/get_last_pricePOST)methodsc               
   C   s   t  } | d}|stddidfS zt| }||i di dd}td|id	fW S  tyU } ztd
| d|  tddidfW  Y d }~S d }~ww )NtickererrorzTicker no proporcionado  quote	lastPriceN/A
last_price   z&Error al obtener el precio del ticker : zError al obtener el precio  )	r   get_jsongetr   clientr   json	Exceptionprint)datar   
quote_datar   e r#   (/var/www/html/backtestingmarket/ccitm.pyget_last_price   s   
r%   z/get_option_detailsc               
   C   s^  t d t } | d}| d}tt| d}|r!|r!|s)tddidfS zatj||||hd	 }|d	i }|
 D ]A\}}||v r|| d
 }|ddkr|dd
}	|dd
}
|dd
}|	rq|
rq|	|
 d nd}t|	|
||ddf  W S q@tddidfW S  ty } zt d| d|  tddidfW  Y d }~S d }~ww )NzEntrando a get_option_detailsr   datestriker   u   Faltan parámetrosr   )fromDatetoDater'   callExpDateMapr   putCallCALLbidasktotalVolume   r   )r-   r.   	mid_pricer/   r   u=   No se encontró una opción call con los datos proporcionadosi  u1   Error al obtener los detalles de la opción para r   u+   Error al obtener los detalles de la opciónr   )r   r   r   r   strfloatr   r   option_chainsr   itemsr   )r    r   	from_datestrike_priceoption_datacall_exp_date_mapdate_keystrikes	call_datar-   r.   total_volumer1   r"   r#   r#   r$   get_option_details$   sB   


r>   )osdotenvr   flaskr   r   r   r   	schwabdevpandaspd__name__ccitm_bpClientgetenvr   router%   r>   r#   r#   r#   r$   <module>   s"   
