o
    =Wg                     @   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e
Zeje de de ddd	Zed
dd Zejddgddd Zejddgddd Ze
dkrfejddd dS dS )    N)load_dotenv)Flaskrender_templatejsonifyrequestz*/var/www/html/itmcc.backtestingmarket/.envappKey	appSecretcallbackUrlT)verbose/c                   C   s   t dS )Nz
index.html)r    r   r   ,/var/www/html/itmcc.backtestingmarket/app.pyindex   s   r   z/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   er   r   r   get_last_price   s   
r$   z/get_option_detailsc               
   C   sV  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	}|	rm|
rm|	|
 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 )Nr   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   strfloatr   r   option_chainsr   itemsr   r    )r!   r   	from_datestrike_priceoption_datacall_exp_date_mapdate_keystrikes	call_datar,   r-   total_volumer0   r#   r   r   r   get_option_details+   s@   


r=   __main__i  )debugport)osdotenvr   flaskr   r   r   r   	schwabdevtime__name__appClientgetenvr   router   r$   r=   runr   r   r   r   <module>   s,    	


%