
    )Vj                    F    d dl mZ d dlmZ d dlmZ d dlmZ dd	ZddZ	dS )    )annotations)Any)	BotConfig)PositionStatevaluer   returnfloat | Nonec                Z    	 | d S t          |           S # t          t          f$ r Y d S w xY w)N)float	TypeError
ValueError)r   s    restart_state.py_float_or_noner   	   sD    =4U||z"   tts     **posdict[str, Any]now_tsr   cfgr   atrtuple[PositionState, bool]c                  t          |                     d          p|                     d          pd          }t          |                     d          p|                     d                    }t          |                     d          p|                     d                    }t          |                     d          p|                     d	                    }|d
u p|d
u p|d
u }|'t          |          t          |j                  dz  z
  }||}|'|t          |j                  t          |          z  z
  }t          t          |          t          |          t          |          t          |                     d          p|                     d          pd          t          |                     d          p|                     d          pd                    }	|	|fS )a7  Recover in-memory exit state for an already-open paper/live position.

    Returns (state, reconstructed). reconstructed=True means the position lacked
    persisted state metadata, so we use conservative defaults that make the bot
    eligible for time-stop evaluation rather than holding blindly forever.
    
entryPriceentry_pxg        entryTsentry_ts	highPricehigh_pxatrSlPx	atr_sl_pxNg      N@beActive	be_activeFtrailingActivetrailing_active)r   r   r   r    r"   )r   getr   dead_fish_time_limit_minsatr_sl_multiplierr   bool)
r   r   r   r   entry_pricer   r   r   reconstructedstates
             r   recover_position_stater*      s    --K1D1DKLLKcggi00GCGGJ4G4GHHHSWW[11GSWWY5G5GHHGswwy11ISWW[5I5IJJI$L4L9;LM==E#*G$H$H4$OP5)>#?#?%**#LM	xg	""swwz**Kcggk.B.BKeLLSWW%566]#''BS:T:T]X]^^  E -    N)r   r   r   r	   )
r   r   r   r   r   r   r   r   r   r   )

__future__r   typingr   configr   strategyr   r   r*    r+   r   <module>r1      s    " " " " " "             " " " " " "              r+   