
    j                     P    S r SSKrSSKrSSKrSSKJrJrJrJrJ	r	   " S S5      r
g)ut   
V11 — Market: ventana de 15 min en Polymarket.

Igual que V10: obtener tokens + strike. Outcome siempre oficial.
    N   )Config	GAMMA_API	PRICE_APIUAisoc                       \ rS rSrS\S\4S jr SS\R                  S\	S\
4S jjrS\R                  S\S	-  4S
 jrSrg	)Market
   start_tscfgc                     Xl         XR                  -   U l        UR                   U 3U l        S U l        S U l        S U l        S U l        X l	        g )N)
r   win_secsend_tsslug_prefixslug	token_yestoken_nostrikestrike_source_cfg)selfr   r   s       /var/www/html/Poly/v12/market.py__init__Market.__init__   sL    !!LL0OO,XJ7	!	    sessionbinance_pricereturnc                    [        S5       GHV  n UR                  [         SU R                   3S[        S9R                  5       nUS   S   n[
        R                  " US   5      nUS   US   sU l        U l         U R                  R                  [        U R                  5      U R                  R                  [        U R                  5      S	.n[        R                  " [         US
[        S9R                  5       nUR                  S5      (       a  [#        US   5      U l        SU l          g US:  a  X l        SU l        [+        SUS S35          g[+        S5          g   g! [(         a     NAf = f! [,        [.        [0        4 ax  n	[+        SUS-    SU	 35        UR3                  5         UR5                  5         UR6                  R9                  [        5        [:        R<                  " SU-   5         S n	A	GM  S n	A	f[(         a9  n	[+        SUS-    SU	 35        [:        R<                  " SU-   5         S n	A	GM5  S n	A	ff = f)N   /r   timeoutheadersmarketsr   clobTokenIdsr   )symboleventStartTimevariantendDate   )paramsr$   r%   	openPrice
polymarketTbinancez  [strike] usando Binance $z,.2fz (polymarket.com bloqueado)z-[market] tokens OK pero sin strike disponibleFz[market] intento z/8 (conn):    z/8: )rangegetr   r   r   jsonloadsr   r   r   price_symbolr   r   price_variantr   requestsr   floatr   r   	ExceptionprintConnectionErrorConnectionResetErrorOSErrorcloser   r%   updatetimesleep)
r   r   r   attemptrmtokensr-   pres
             r   
fetch_dataMarket.fetch_data   s   QxG,(KK k499+.B   $&  iLOAn$5606q	6!9-"&))"8"8*-dmm*<#'99#:#:#&t{{#3	F "!&!Rdf  vvk**&+B{O&<-9*# + !1$"/K)2D&7d7K L7 8 9EGI  \ - !  $%97C ()'!)KsCD  "&&r*

1w;'' ()'!)D<=

1w;''(sP   A,E8>B2E(2$E8E8(
E52E84E55E88IA,H  I-IINc                 N   [        S5       GH  n UR                  [         SU R                   3S[        S9R                  5       nUS   S   nUR                  SS5      nUR                  S	5      =(       d    S
R                  5       nU(       a  US:w  a    gUR                  S5      nUR                  S5      n[        U[        5      (       a  [
        R                  " U5      n[        U[        5      (       a  [
        R                  " U5      nU(       a  U(       a  [        U5      [        U5      :w  a    gSn	[        U5       H  u  p [        U5      S:  a  U
n	  OM     U	c    g[        Xy   5      R                  5       R                  5       nUR!                  S5      (       a    gUR!                  S5      (       a    g  g   g! [        [        4 a     M  f = f! ["        [$        [&        4 au  n[)        SUS-    SU 35        UR+                  5         UR-                  5         UR.                  R1                  [        5        [2        R4                  " S5         SnAGMU  SnAf[6         a6  n[)        SUS-    SU 35        [2        R4                  " S5         SnAGM  SnAff = f)uw   Outcome oficial de Polymarket via Gamma API.
NUNCA infiere — solo devuelve Up/Down cuando el mercado está resuelto.
   r"   r   r#   r&   r   closedFumaResolutionStatus resolvedNoutcomesoutcomePricesgGz?upUpdownDownz[outcome] intento r   z/3 (conn): z/3: r1   )r2   r3   r   r   r   r4   lower
isinstancestrr5   len	enumerater9   	TypeError
ValueErrorstrip
startswithr<   r=   r>   r;   r?   r   r%   r@   rA   rB   r:   )r   r   rC   rD   rE   rM   umarQ   priceswin_idxiplabelrH   s                 r   fetch_outcomeMarket.fetch_outcomeG   s;    QxG-KK k499+.B   $&  iLOx/%% 56<"CCE
!255,551h,,#zz(3Hfc**!ZZ/FvX#f+1M%f-DA! 8t+&'G! , . ?H-.446<<>##D))##F++!K  ^ ) &z2 ! ! $%97C *719+[DE  "&&r*

1 *719+T!=>

1sb   BGBG8GG	G'?G(GGGGGJ$1A)I!!J$.*JJ$)r   r   r   r   r   r   r   r   )r   )__name__
__module____qualname____firstlineno__intr   r   r8   Sessionr9   boolrI   rY   rf   __static_attributes__ r   r   r
   r
   
   sZ     6  +,0("2"2 0"'0040d3X%5%5 3#* 3r   r
   )__doc__r4   rA   r8   configr   r   r   r   r   r
   rp   r   r   <module>rs      s$   
   9 9p pr   