a
    à’ƒjn  ã                   @   s&  d Z ddlZej dd¡ ddlZg Zd…dd„Zd†d	d
„Ze	dƒ ddddœZ
e e
i ¡Zeded dkded › dee
 ¡ ƒd›ded d›�ƒ e e
deddd�i¡Zeded dkded d›d ed! d›d"ed d#›�ƒ ed$ed% d&ƒe
d& k�oed% d'ƒe
d' kd(e
d& d›d)ed% d&ƒd›d*e
d' d›d)ed% d'ƒd›�ƒ e	d+ƒ d,dd-d.œZe ei ¡Zed/ed d0kd1ee ¡ ƒd›ded d›�ƒ ed2ed dkd3ed d›�ƒ ed4ed5d6„ eD ƒƒƒ e	d7ƒ e ed8ed,d9d�i¡Zed:eed d; ƒd<k ded d›�ƒ ed=d8ed> v d?ed> › �ƒ ed@eedA d8 d9 ƒd<k dBedA d8 › �ƒ e ed8ed,dd�i¡ZedCeed d, ƒd<k ded d›�ƒ edDd8ed> vƒ edEed! ed! kdFed! d›dGed! d›�ƒ e	dHƒ e d,dd-d.œd8edIdd�i¡ZedJed dKkded d›dLedM dN dO›dPejdN dQ›dR�ƒ edSed dkƒ e	dTƒ dUdV„ e ¡ D ƒZe ee¡ZedWed> g kƒ edXeed dY ƒd<k ded d›�ƒ edZed ed ked d›d[ed d›d\ed ed  dN d]›d^�ƒ e	d_ƒ ddd`dœZdadV„ e ¡ D ƒZeeddb�Ze ee¡Zedceed% d'ƒd` ƒd<k dded% d'ƒd›�ƒ eded6„ eD ƒƒZedfeee ¡ ƒd< ked›dgee ¡ ƒd›dhee ¡ ƒd›�ƒ edieed d< ked›djed d›�ƒ eedkdl�Ze ee¡Zedmeed% dƒdk ƒd<k dned% dƒd›�ƒ e eeeddddoœdl�¡Zedped% d'ƒd`kdqed% d'ƒd›dr�ƒ e	dsƒ e e
deddd�i¡Zedted dkded › �ƒ e	duƒ d,dd-d.œZd8ed,ddvdw�iZe ee¡Zedxeed d, ƒd<k ded d›�ƒ edyd8ed> vd?ed> › �ƒ d8dddddd,dzœiZe ee¡Zed{eed ƒd<k ded d›�ƒ ed|d8ed> v d?ed> › �ƒ ed}ed! dkd~ed! d›�ƒ edeed% d8ƒd, ƒd<k d€ed% d8ƒd›�ƒ e	d�e�s d‚ndƒe› � ƒ e e�rd„nd¡ dS )‡a  Tests for the budget rule -- the arithmetic that decides whether real money
completes a book.

The reference case is the Alaves book of 2026-08-15, which the maker completed
at 0.99 against a 1.00 payout: a locked loss. These tests exist so that book
cannot happen again silently.
é    NzE:\soccer\mainÚ c                 C   s>   t d|rdnd› d| › |r"d| nd› �ƒ |s:t | ¡ d S )Nz  [ÚpassZFAILz] z  r   )ÚprintÚfailsÚappend)ZlabelZcondZextra© r   ú"E:\soccer\main\test_book_budget.pyÚcheck   s    ,r	   ç        Fc                 C   s@   i }| d ur| |d< |r ||d< |r,d|d< |d ur<||d< |S )NÚfill_pxÚfill_qtyTÚfill_loggedZprice_centsr   )ÚpxÚqtyÚloggedZcentsÚsr   r   r   Úleg   s    r   zC=== the Alaves book: 0.40 + 0.34 + 0.25 = 0.99 vs a 1.00 payout ===gš™™™™™Ù?gÃõ(\�ÂÕ?g      Ð?)ÚALAÚTIEÚGETzsum 0.99 is refused outrightZdecisionZgatez	decision=z sum=z.2fz target=Útargetz.4fr   ç      ð?©r   r   z(after ALA fills, the touch is not enoughZscalez
collected=Z	collectedz need=Zneedz scale=z.3fz&and TIE/GET are priced above the touchÚ	floor_forr   r   zTIE z->z  GET z:
=== a book with real overround is quoted at the touch ===gáz®GáÚ?gìQ¸…ëÑ?)ÚHÚDÚAzdecision is quoteÚquotezsum=z#scale <= 1 so legs sit at the touchzscale=zfloor equals the touchc                 c   s*   | ]"}t td  |ƒt|  ƒdk V  qdS )r   gê-�™—q=N)ÚabsÚbÚgood©Ú.0Útr   r   r   Ú	<genexpr>:   s   r$   z
=== fractional fills ===r   g      à?z!half a leg banks half the premiumgáz®GáÊ?g•Ö&è.>z!the half-filled leg is still openZ	open_legszopen=zand only its remainder countsZopen_qtyzopen_qty[H]=z#a whole leg banks the whole premiumzand drops out of the open legsz(half-filled needs MORE than fully-filledz
half need=z vs full need=z
=== abandonment ===gš™™™™™¹?z'a book that cannot recover is abandonedZabandonz worst=Zworst_over_touchéd   z.1fzc over touch (cap z.0fzc)z*abandon beats gate once money is committedz
=== completed book ===c                 C   s   i | ]\}}|t |d d�“qS )r   r   )r   ©r"   r#   Úvr   r   r   Ú
<dictcomp>X   ó    r(   zno open legszcollected the full 1.04g¤p=
×£ð?zand it beat the targetz > z, net z+.2fÚczA
=== the ratchet: never re-quote a leg below where it started ===g¤p=
×£Ð?c                 C   s   i | ]\}}|d |i“qS )Úfloor_pxr   r&   r   r   r   r(   e   r)   )r   z GET is NOT followed down to 0.25ztouch 0.25 -> quote c                 c   s   | ]}t d  |ƒV  qdS )r   N)r   r!   r   r   r   r$   p   r)   z*quoted sum never falls below the entry sumz
 vs entry z, drifted touch z#and never below target once quotingz vs target g…ëQ¸…Û?)r   za rising touch IS followed upztouch 0.43 -> quote )r+   r   r   z9after a fill, floors are the higher of ratchet and budgetz
GET floor z (ratchet 0.26)z.
=== the gate only applies before any fill ===z,a partially filled bad book is never "gated"zA
=== a leg closed outside the maker must not stay "collected" ===T)r   r   r   z*a stale fill is still counted as collectedzand its leg is not offered)r   Z	fill_cashr   Z
logged_qtyr   r+   z$after the reset nothing is collectedzthe leg is open againzthe full dollar is owed againzneed=z1and the ratchet still holds it at its first pricezH floor Ú
z
ALL PASSEDz
FAILURES: é   )r   )Nr
   FN) Ú__doc__ÚsysÚpathÚinsertZmm_maker_liveZMLr   r	   r   r   ZalavesZbook_budgetr   ÚsumÚvaluesr    Úallr   ZfullZMAX_ABOVE_TOUCHÚitemsZdoneZalagetZopenedÚdictZdriftedZquotedZrisenZphantomZstaleZhealedÚexitr   r   r   r   Ú<module>   s  

ÿÿ&ÿ(ÿÿþÿÿÿ
 ÿÿ&ÿ ÿÿÿ
ÿÿÿÿÿþÿþ"ÿþÿþÿ ÿÿÿÿ þ