
    *i                    z    d dl mZ d dlZd dlmc mZ d dlZ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d	Zy)    )annotationsN)Path)	OrderBook)iter_event_frames)replay_orderbook_windowc                    t               } | j                  dddgdddgd       | j                  } |       }d}||k(  }|st        j                  d|fd	||f      d
t        j                         v st        j                  |       rt        j                  |       nd
t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}}| j                  } |       }d}||k(  }|st        j                  d|fd||f      d
t        j                         v st        j                  |       rt        j                  |       nd
t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}}| j                  ddddddddddddg       | j                  } |       }d}||k(  }|st        j                  d|fd	||f      d
t        j                         v st        j                  |       rt        j                  |       nd
t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}}| j                  } |       }d}||k(  }|st        j                  d|fd||f      d
t        j                         v st        j                  |       rt        j                  |       nd
t        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d x}x}x}}y )N0.3910pricesize0.4120bidsasks)g(\?      $@==)zG%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.best_bid
}()
} == %(py7)sbook)py0py2py4py7zassert %(py9)spy9)g=
ףp=?g      4@)zG%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.best_ask
}()
} == %(py7)sBUY0.405)sider   r   SELL0z0.427)皙?g      @)gzG?g      @)r   apply_snapshotbest_bid
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationbest_askapply_delta)r   @py_assert1@py_assert3@py_assert6@py_assert5@py_format8@py_format10s          0/root/polymarket_arb/tests/test_lpl_orderbook.py!test_orderbook_snapshot_and_deltar7      sc   ;D%t45%t45	
 ==*=?*l*?l****?l******4***4***=***?***l*******==*=?*l*?l****?l******4***4***=***?***l*******VS9fc:fc:	
 ==(=?(j(?j((((?j((((((4(((4(((=(((?(((j(((((((==)=?)k)?k))))?k))))))4)))4)))=)))?)))k)))))))    c                   d}| |z  }|j                  d       |dz  j                  t        j                  |ddgddgd	      d
       dddddddgdddgddddddddddddgidg}|dz  j	                  d d
      5 }|D ])  }|j                  t        j                  |      d!z          + 	 d d d        t        |dd| "      }|d#   }d}||k(  }	|	slt        j                  d$|	fd%||f      t        j                  |      t        j                  |      d&z  }
d'd(|
iz  }t        t        j                  |            d x}x}	}|d)   }d}||k\  }	|	slt        j                  d*|	fd+||f      t        j                  |      t        j                  |      d&z  }
d'd(|
iz  }t        t        j                  |            d x}x}	}t        t        |d,               j                  d
      }d}||v }	|	st        j                  d-|	fd.||f      t        j                  |      d/t        j                          v st        j"                  |      rt        j                  |      nd/d0z  }d1d2|iz  }t        t        j                  |            d x}}	d3}||v }	|	st        j                  d-|	fd.||f      t        j                  |      d/t        j                          v st        j"                  |      rt        j                  |      nd/d0z  }d1d2|iz  }t        t        j                  |            d x}}	y # 1 sw Y   xY w)4Nzlol-test-game1Tparentsrecording_meta.jsonLGDEDG	token_lgd	token_edgslugoutcomes	token_idsutf-8encodingz2026-04-23T09:00:00+00:00   	rest_bookr	   r
   r   r   r   r   )received_at_wallmessage_index
event_typeasset_idraw_jsonz2026-04-23T09:00:01+00:00   price_change price_changesr   r   r   rM   r   r   r   orderbook_events.jsonlw
)rB   atwindow_seconds	data_rootprocessed_eventsr   z%(py1)s == %(py4)spy1r   assert %(py6)spy6rows)>=)z%(py1)s >= %(py4)soutput_path)in)z%(py1)s in %(py3)soutput)r]   py3zassert %(py5)spy5z0.4)mkdir
write_textjsondumpsopenwriter   r&   r'   r+   r,   r-   r   str	read_textr(   r)   r*   )tmp_pathrB   
market_dirr`   frowresult@py_assert0r1   @py_assert2@py_format5@py_format7rd   @py_format4@py_format6s                  r6   test_replay_orderbook_windowrz   "   s   DDJT"''33

"EN);7	
  4 	 !<%##)489#)489		
 !<($/ %!' #	"		
D8 /
/	5	5cG	5	L ,PQ 	,CGGDJJsOd*+	,, %&	F $%**%****%***%**********&>Q>Q>Q>Q#f]+,-777IF ;&    ;&   ;      &   &       5F?5F5FF, ,s   /L==Mc                j   d}| |z  }|j                  d       |dz  j                  t        j                  |ddgddgd	      d
       ddddddddddgdddgddddddddddddgdddgdddddddd d d!dd"d#d$d%gidd&d'd(dd)ddddd*d"d+d,dg}|d-z  j	                  d.d
      5 }|D ])  }|j                  t        j                  |      d/z          + 	 d d d        t        || d01      \  }}|D cg c]  }|d2   	 }	}g d3}
|	|
k(  }|slt        j                  d4|fd5|	|
f      t        j                  |	      t        j                  |
      d6z  }d7d8|iz  }t        t        j                  |            d x}	x}}
|d   d9   d   d:   }	d;}
|	|
k(  }|slt        j                  d4|fd5|	|
f      t        j                  |	      t        j                  |
      d6z  }d7d8|iz  }t        t        j                  |            d x}	x}}
|d   d<   d=   d>   }	d;}
|	|
k(  }|slt        j                  d4|fd5|	|
f      t        j                  |	      t        j                  |
      d6z  }d7d8|iz  }t        t        j                  |            d x}	x}}
|d   d?   d@   }	d+}
|	|
k(  }|slt        j                  d4|fd5|	|
f      t        j                  |	      t        j                  |
      d6z  }d7d8|iz  }t        t        j                  |            d x}	x}}
|d   dA   }	dB}
|	|
k(  }|slt        j                  d4|fd5|	|
f      t        j                  |	      t        j                  |
      d6z  }d7d8|iz  }t        t        j                  |            d x}	x}}
y # 1 sw Y   xY wc c}w )CNzlol-test-event-game1Tr:   r<   r=   r>   r?   r@   rA   rE   rF   z2026-04-23T09:00:00.020+00:00z2026-04-23T09:00:00.000+00:00rH   rI   r	   r
   r   r   r   r   )rJ   exchange_tsrK   connection_idrL   rM   outcomerN   z2026-04-23T09:00:00.030+00:00z2026-04-23T09:00:00.010+00:00rO   z0.59z0.61z2026-04-23T09:00:01.020+00:00z2026-04-23T09:00:01.000+00:00   rP   rQ   rR   r   r   r   rS   z2026-04-23T09:00:01.040+00:00z2026-04-23T09:00:01.030+00:00   last_trade_price120xabc)rM   r   r   r   transaction_hashrT   rU   rV      )rB   rY   depthrL   )rI   rP   r   r   r[   r\   r^   r_   booksr%   r#   changed_levelsr   r   trader   delay_msr   )rg   rh   ri   rj   rk   rl   r   r&   r'   r+   r,   r-   )ro   rB   rp   r`   rq   rr   _metaframesframert   r1   ru   rv   rw   s                 r6   *test_event_replay_reconstructs_from_eventsr   ^   s   !DDJT"''33

"EN);7	
  4 	 !@:%##)489#)489	
 !@:%##)489#)489	
 !@:($/ %!' #	"		
( !@:,#'$+	
]>D~ /
/	5	5cG	5	L ,PQ 	,CGGDJJsOd*+	,, &481MME6-34EE,4 4 9 4 9   	4 9   	 5   	9     	 
 !9Wk*:6=#=6#====6#===6===#=======!9%&q)'29c92c99992c9992999c9999999!9W01<W<1W<<<<1W<<<1<<<W<<<<<<<!9Z (D( D(((( D((( (((D(((((((, , 5s   //N#<N0#N-)returnNone)ro   r   r   r   )
__future__r   builtinsr(   _pytest.assertion.rewrite	assertionrewriter&   ri   pathlibr   analysis.lpl_orderbook.recorderr   #analysis.lpl_orderbook.event_replayr   analysis.lpl_orderbook.replayr   r7   rz   r    r8   r6   <module>r      s,    "     5 A A*.9x[)r8   