o
    24¹j�  ã                   @   sV   d Z ddlZddlmZ ddlmZmZ dZi Zi Zdd„ Z	ded	e
d
efdd„ZdS )a?  
fixed_entries.py -- TEST-ONLY entry module (simulator, never live).

Buys exactly the entries listed in a file (sim/entries/*.json): symbol,
time (UTC) and stop -- so different EXIT rules can be compared on the
very same entries. simulate.py --fixed-entries FILE loads it
automatically and points cfg["file"] at FILE.
é    N)Údatetime)ÚEntryDecisionÚ
MarketViewÚfixedc              	   C   sh   | t vr0i }t t| ƒ¡d D ]}| |d |d fg ¡ i |¥dt |d ¡i¥¡ q|t | < t |  S )NÚentriesÚdateÚsymbolÚ_tÚtime)Ú_cacheÚjsonÚloadÚopenÚ
setdefaultÚappendr   Úfromisoformat)ÚpathÚoutÚe© r   ú3/var/www/screener/trade1/sim/rules/fixed_entries.pyÚ_entries   s   ÿr   ÚviewÚstateÚreturnc                 C   sà   | j  ¡  ¡ | jf}t| jd ƒ |g ¡}t |d¡}|t|ƒkr't	ddd�S || }| j |d k r=t	dd|d	 › �d�S |d
 t|< |d | j
krYt	dd| j
› d|d › �d�S t	d|d dd|d	 › �dd„ | ¡ D ƒd�S )NÚfiler   ÚDONEzno more listed entries)r   Úreasonr	   ÚWAITzlisted entry at r
   é   ÚstopÚSKIPzprice z already at/below listed stop TÚBUYzlisted entry c                 S   s    i | ]\}}|  d ¡s||“qS )Ú_)Ú
startswith)Ú.0ÚkÚvr   r   r   Ú
<dictcomp>+   s     zevaluate.<locals>.<dictcomp>)r    r   r   Úplan)Únowr   Ú	isoformatr   r   ÚcfgÚgetÚ_doneÚlenr   ÚpriceÚitems)r   r   ÚkeyÚtodoÚdoner   r   r   r   Úevaluate   s   ÿr5   )Ú__doc__r   r   Ú	rules_apir   r   ÚNAMEr   r.   r   Údictr5   r   r   r   r   Ú<module>   s    
