
    ":h                    n   d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZ ddlmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZm Z m!Z! ddlm"Z"m#Z#m$Z$m%Z%m&Z& ddl'm(Z)m*Z* dd	l+m,Z,m-Z-m.Z. dd
l/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6 	 ddl7m8Z8 ddgZ: G d de)      Z(y# e9$ r dZ8Y w xY w)z4.4.86    N)AnyList)IntStrNumStrings)	Throttler)	BaseError	BadSymbol
BadRequestBadResponseExchangeErrorExchangeNotAvailableRequestTimeoutNotSupportedNullResponseInvalidAddressRateLimitExceededOperationFailed)ConstructorArgs	OrderType	OrderSideOrderRequestCancellationRequest)ExchangeArgumentsRequired)inflate	inflate64gunzip)AiohttpClient)Future)	OrderBookIndexedOrderBookCountedOrderBook)ProxyConnectorBaseExchanger   c                       e Zd ZdZdddZdZdZi ZdZi fde	f fd	Z
d
 Zd:dZd:dZd Zd Zej"                  dk\  rd Zd Zd Zd Zd Zd Zd;dZd Zdi fdZdi fdZd<dZi fdZi fdZdddi fdZdi fd Z d! Z!d" Z"d# Z#e$d$        Z%e$d%        Z&e$d&        Z'i dfd'Z(i dfd(Z)i dfd)Z*d* Z+d+ Z,d, Z-d=d-Z.d=d.Z/d:d/Z0d0 Z1d1 Z2d2 Z3di fd3Z4d4 Z5i fd5Z6ddi fd6e7d7e8d8e8fd9Z9ddi fd6e7d7e8d8e8fd:Z:ddi fd6e7d7e8d8e8fd;Z;ddi fd<e<e7   d7e8d8e8fd=Z=ddi fd6e7d7e8d8e8fd>Z>ddi fd<e<e7   d7e8d8e8fd?Z?ddi fd6e7d7e8d8e8fd@Z@i fd6e7fdAZAddi fd<e<e7   d7e8d8e8fdBZBi fd<e<e7   fdCZCddi fd<e<e7   d7e8d8e8fdDZDddi fd<e<e7   d7e8d8e8fdEZEddi fdFe<e<e7      d7e8d8e8fdGZFi fdFe<e<e7      fdHZGdi fd<e<e7   d8e8fdIZHi fd<e<e7   fdJZIdi fdKeJfdLZKdi fd6e7d8e8fdMZLdi fd6e7d8e8fdNZMi fd6e7fdOZNdi fd<eJfdPZOdi fdQZPdi fd6e7d8e8fdRZQi fd6e7fdSZRi fdTZSdi fd<eJfdUZTi fdVZUi fdWZVdi fd<eJfdXZWdi fd<eJfdYZXdi fd<eJfdZZYi fd6e7fd[ZZi fd<e<e7   fd\Z[i fd<e<e7   fd]Z\i fd^e7d_e]d`e7dae7fdbZ^di fd^e7d_e]dce7fddZ_i fd^e7fdeZ`di fdfe8d6eafdgZbi fd6e7fdhZcdi fd<eJfdiZddi fdjeed6eafdkZfi fd6e7d_e]fdlZgi fd6e7d_e]fdmZhi fd6e7d_e]fdnZidi fd6e7doeafdpZjddddi fd6eadoead7e8d8e8fdqZkddddi fd6eadread7eld8elfdsZmdi fdte7d6eafduZni fd^e7fdvZodwddi fd6e7d7e8d8e8fdxZpi fd6e7fdyZqdi fd<eJfdzZri fd{Zsi fd|Zti fd^e7d_e]fd}Zui fd^e7d_e]fd~Zvi fd6e7d^e7d_e]fdZwi fd^e7d_e]fdZxi fd6e7d^e7d_e]fdZydi fd^e7d_e]d6eafdZzdi fd^e7d_e]d6eafdZ{dddi fd6e7d7e8d8e8fdZ|dddi fd6e7d7e8d8e8fdZ}dddi fd6e7d7e8d8e8fdZ~d>dZdi fd6e7d8e8fdZddi fd<eJfdZddi ddi fdededefdZddi ddi fdededefdZdi fdZdi fde7d6e7d_e]delfdZdi fde7d6e7d_e]delfdZdi fde7d6e7ded_e]delf
dZddi fde7d6e7dreded_eldelfdZddi fde7d6e7dreded_eldelfdZi fd6e7fdZi fd6e7fdZdi fd6eafdZdddi fd<eJd7e8d8e8fdZdddi fd<eJd7e8d8e8fdZi fd6e7fdZi fd6e7fdZdi fd<eJfdZdi fd<eJfdZdi fd<eJfdZdi fd<eJfdZddddi fd^ead6ead7e8d8e8fdZdddi fd^ead7e8d8e8fdZdi fde7d^eafdZi fdZi fdZi fdZi fdZi fdZi fdZi fdZi fdZi fd^e7fdZdi fdKeJfdZdi fdKeJfdZi fd^e7fdZi fd^e7fdZi fd6e7fdZi fd6e7fdZi fd6e7fdZi fd6e7fdZi fd6e7fdZdi fd<eJfdZdi fd<eJfdZdi fd<eJfdZddi fd<eJd8e8fdZdi fd<eJfdZdi fd<eJfdZdi fd<eJfdZdi fde7d6eafdZdi fde7d6eafdZdi fde7d6eafdZi fdÄZdi fd6e7dreded_e]delf
dĄZdi fde7de7de7d_elfdǄZdi fde7d^eafdȄZdddi fd^ead7e8d8e8fdɄZdi fd6eafdʄZdddi fd6e7dreded_e]delf
d˄Zdddi fd6e7dreded_e]delf
d̄Zdddi fd6e7dreded_e]delf
d̈́Zdddi fd6e7dreded_e]delf
d΄Zi fd6e7dede]fdЄZi fd6e7de]fdфZi fd6e7de]fd҄Zi fd6e7dede]fdӄZddi fd6e7dreded_e]deldelfdՄZddi fd6e7dreded_e]deldelfdքZddi fd6e7dreded_e]deldelfd؄Zddi fd6e7dreded_e]deldelfdلZddi fd6e7dreded_e]deldelfdۄZddi fd6e7dreded_e]deldelfd܄Zdddi fd6e7dreded_e]deldeldelfd߄Zdddi fd6e7dreded_e]deldeldelfdZi fde<e   fdZi fde<e   fdZdi fd6e7dreded_e]delf
dZdi fde7d6eafdZdi fde7d6eafdZdi fde<e7   d6eafdZdi fd6eafdZi fde8fdZi fde<e   fdZdi fd6eafdZi fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fde7d6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZddi fd6e7d7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZi fd6e7fdZi fd^e7fdZi fd6e7fdZdi fde7de7d_elfd Zdddi fd^ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd^ead7e8d8e8fdZdddi fd^ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdddi fd6ead7e8d8e8fdZdi fd6e7defdZi fd	Zdi fd6e7d8e8fd
Zi fd^e7fdZi fd6e7ded_e]de]fdZi fd6e7ded_e]de]fdZdi fd6e7ded_e]delfdZdi fd6e7ded_e]delfdZi fd6e7d_e]de]fdZi fd6e7d_e]de]fdZi fd6e7d_e]de]fdZi fd6e7d_e]de]fdZi fd6e7d_e]fdZi fd6e7d_e]fdZ i fd6e7d_e]fdZi fd6e7d_e]fdZi fdZi fd6e7fdZdi fd6e7dreded_e]delf
dZdi fd6e7dreded_e]delf
dZdi fd6e7dreded_e]delf
dZdi fd6e7dreded_e]delf
dZddi fd6e7dreded_e]deldelfdZ	ddi fd6e7dreded_e]deldelfdZ
i fd6e7ded_e]de]de]f
d Zi fd6e7ded_e]de]de]f
d!Zi fd6e7ded_e]de]fd"Zi fd6e7ded_e]de]fd#Zdi fd<eJfd$Zi fd%Zi fd&Zi fd6e7fd'Zi fd(Zi fd6e7fd)Zi fd6e7fd*Zdddi fd7e8d8e8fd+Zdddi fd6e7d7e8d8e8fd,Zdddi fd6e7d7e8d8e8fd-Zdddi fd^ead7e8d8e8fd.Zdddi ddfd/e7d6ead7e8d8e8d0e8f
d1Zddddi fd/e7d6ead7e8d8e8doeaf
d2Zddddi dfd/e7d6ead7e8d8e8doeaf
d3Zdddi ddddfd/e7d6eafd4Zdddi ddfd/e7d6eafd5Zddi fd6e7d7e8d8e8fd6Zdddi fd<eJd7e8d8e8fd7Z di fde7d^eafd8Z!dddi fd^ead7e8d8e8fd9Z" xZ#S (?  r   F   i0u  )maxPingPongMisses	keepAliveNT   configc                 Z   d|v r
|d   | _         |j                  d| j                        | _        |j                  d| j                        | _        d|v| _        |j                  dt        j                               | _        d | _        t        t        | /  |       d | _        d| _        y )Nasyncio_loopaiohttp_trust_envverifysessioncafileF)r.   getr/   r0   own_sessioncertifiwherer2   	throttlersuperr   __init__markets_loadingreloading_markets)selfr,   	__class__s     Z/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/base/exchange.pyr9   zExchange.__init__F   s    V# &~ 6D!',?AWAW!Xjj4;;7$F2jj7==?;h&v.#!&    c                     | j                   S N)r.   r<   s    r>   get_event_loopzExchange.get_event_loopR   s       r?   c                 N    t        | j                  | j                        | _        y rA   )r	   tokenBucketr.   r7   r<   costs     r>   init_throttlerzExchange.init_throttlerU   s    "4#3#3T5F5FGr?   c                 @   K   | j                  |       d {   S 7 wrA   )r7   rF   s     r>   throttlezExchange.throttleX   s     ^^D))))s   c                     | j                   S rA   )r1   rB   s    r>   get_sessionzExchange.get_session[   s    ||r?   c                     | j                   | j                  )| j                  j                  | j                  dz          y y )Na>   requires to release all resources with an explicit call to the .close() coroutine. If you are using the exchange instance with async coroutines, add `await exchange.close()` to your code into a place when you're done with the exchange and don't need the exchange instance anymore (at the end of your async coroutine).)r1   socks_proxy_sessionsloggerwarningidrB   s    r>   __del__zExchange.__del__^   sB    <<#t'@'@'LKK  +k  !k  l (Mr?   )      c                 .   K   | j                          | S wrA   )openrB   s    r>   
__aenter__zExchange.__aenter__c   s     IIKKs   c                 @   K   | j                          d {    y 7 wrA   )close)r<   exc_typeexctbs       r>   	__aexit__zExchange.__aexit__g   s     **,s   c                    | j                   at        j                  dk\  rt        j                         | _         nt        j
                         | _         | j                   | j                  _        | j                  | j                  r t        j                  | j                        n| j                  | _        | j                  r|| j                  | j                  dd      r_t        j                         }|j                  r?|j                  | j                  k7  r&| j                  j!                  |j                         | j"                  rz| j$                  mt'        j(                  | j                  | j                   d      | _        t'        j,                  | j                   | j*                  | j.                        | _        y y y )N)rS      )r2   include_OS_certificatesFTsslloopenable_cleanup_closedrc   	connector	trust_env)r.   sysversion_infoasyncioget_running_looprC   r7   rc   ssl_contextr0   rb   create_default_contextr2   	safe_booloptionsget_default_verify_pathsload_verify_locationsr4   r1   aiohttpTCPConnectortcp_connectorClientSessionr/   )r<   os_default_pathss     r>   rV   zExchange.openj   s^   $6)$+$<$<$>!$+$:$:$<!"&"3"3DNN#QUQ\Q\s99MbfbmbmD  T^^DLLB[]b%c#&#?#?#A #**/?/F/F$++/U$$::BRBYBY:Z 4!(!5!5$:J:JQUQbQbz~!D"00d6G6GSWSeSequ  rH  rH  IDL !5r?   c                 x  K   | j                          d {    | j                  5| j                  r"| j                  j                          d {    d | _        | j	                          d {    | j                          d {    | j                  | j                         d {    y 7 7 a7 D7 .7 wrA   )ws_closer1   r4   rY   close_connectorclose_proxy_sessionssleeptimeout_on_exitrB   s    r>   rY   zExchange.close   s     mmo<<#ll((***DL""$$$'')))jj--... 	 +$).sW   B:B09B:B2B:/B40B:B6"B:*B8+B:2B:4B:6B:8B:c                    K   | j                   )| j                   j                          d {    d | _         | j                  *| j                  j                          d {    d | _        y y 7 B7 wrA   )rt   rY   aiohttp_socks_connectorrB   s    r>   ry   zExchange.close_connector   sn     )$$**,,,!%D''3..44666+/D( 4 - 7s!   *A3A/4A3!A1"A31A3c                    K   | j                   >| j                   D ]'  }| j                   |   j                          d {    ) d | _         y y 7 wrA   )rN   rY   )r<   urls     r>   rz   zExchange.close_proxy_sessions   sT     $$000 =//4::<<<=(,D% 1<s   <AAAGETc                 	  K   | j                  |      }|| _        | j                  ||||      }|1|j                  d| j                  i       || j                  |      z   }d}d}| j                  ||||      \  }	}
}|	r|	}n|
r|
}n{|rat        t        | j                  dz         | j                  i | _
        || j                  vr:| j                          | j                  |      }n| j                  r| j                  }|duxs |du}| j                  ||       | j                   ||	|
|t        | j                  dz         | j                  r"| j!                  d| j                  ||d|d|       | j"                  j%                  d||||       |}|r|j'                         nd}| j                          ||n| j(                  }t+        ||j-                               }d}d}d}d}	  |t/        j0                  |d	
      ||| j2                  dz  |      4 d{   }|j5                  d       d{   }|j6                  }i }|D ]   }||v r||   dz   ||   z   ||<   ||   ||<   " |j8                  }|j:                  }| j=                  ||||||||      }| j?                  |      }| j@                  r|| _!        | jD                  r|| _#        | jH                  r|| _%        | j                  r#| j!                  d| j                  |||d|d|	       | j"                  j%                  d|||||       ddd      d{    | jg                  |||||||||	       | ji                  |||||       ||S | jk                  |      r|S |dk(  s||S jl                  S 7 7 n7 d# 1 d{  7  sw Y   txY w# tL        jN                  $ r/}djQ                  | j                  ||g      }tS        |      |d}~wtT        jV                  jX                  tZ        jX                  f$ r/}djQ                  | j                  ||g      }t]        |      |d}~wt^        j`                  $ r/}djQ                  | j                  ||g      }tS        |      |d}~wt^        jb                  $ r/}djQ                  | j                  ||g      }te        |      |d}~ww xY ww)z3Perform a HTTP request and return decoded JSON dataNOriginzu - to use SOCKS proxy with ccxt, you need "aiohttp_socks" module that can be installed by "pip install aiohttp_socks"z9 you have set multiple proxies, please use one or anotherz
fetch Request:zRequestHeaders:zRequestBody:z%s %s, Request: %s %sT)encoded  )dataheaderstimeoutproxyreplace)errorsz, z
fetch Response:zResponseHeaders:zResponseBody:z%s %s, Response: %s %s %s  )7prepare_request_headerslast_request_headerscheck_proxy_url_settingsupdateoriginurl_encoder_for_proxy_urlcheck_proxy_settingsr%   r   rQ   rN   rV   get_socks_proxy_sessionaiohttp_proxycheckConflictingProxiesverboselogrO   debugencoder1   getattrloweryarlURLr   textr   statusreasonon_rest_response
parse_jsonenableLastHttpResponselast_http_responseenableLastResponseHeaderslast_response_headersenableLastJsonResponselast_json_responsesocketgaierrorjoinr   
concurrentfuturesTimeoutErrorrj   r   rr   ClientConnectionErrorClientErrorr   handle_errorshandle_http_status_codeis_text_responsecontent)r<   r   methodr   bodyrequest_headersproxyUrlfinal_proxyproxy_session	httpProxy
httpsProxy
socksProxyproxyAgentSetrequest_bodyencoded_bodyfinal_sessionsession_methodhttp_responsehttp_status_codehttp_status_textjson_responseresponseraw_headersheaderedetailss                             r>   fetchzExchange.fetch   sK     66w?$3!00fgtL""Hdkk#:;T;;C@@C,0,E,Ec6SZ\`,a)	:z#K$K%"477  .e  $e  f  f))1,.)$";";;		 $ < <Z H,,K#4/I:T3I$$]H= *1EI^blbx  }G  }Stww)ddee <<HH'&#?PRacqswx163N (,t{{}$		)6)B ?+	0%dhhsD&A+7.=/3||d/B,7	9 v v =E&.mm9m&E E&..) >F(*1&/D*@;vCV*V*5f*=	>
 $,?? #+??  $ 5 56FHXZ]_egnp}  @O  Q]  !^ $ >...;D+1118D....;D+<<HH0$''63HXZlnu  xG  IV  W!!"=vsL\^egtu5v vX 	+-=sFGUbdq  tC  EQ  	R$$%57GfVcd$    )  B-"7  iv
 !Fv v v v8  	7hh56G&w/Q6""//1E1EF 	1hh56G )q0,, 	7hh56G&w/Q6"" 	0hh56G(a/	0s   G.S%13O $N)%O (N1>N,?D N1?O 
N/O AS%)O ,N1/O 1O7N:8O?O S"*P0S"3*QS"3*RS"3*SS""S%c                 L   | j                   i | _         || j                   vrut        j                  || j                  | j                  d      | _        t        j                  | j                  | j
                  | j                        | j                   |<   | j                   |   S )NTra   re   )	rN   r%   from_urlrl   r.   r~   rr   ru   r/   )r<   r   s     r>   r   z Exchange.get_socks_proxy_session  s    %%-(*D%d777+9+B+B$$&&&*,D( 5<4I4ItO`O`lp  mI  mI  UY  Uk  Uk  5lD%%j1((44r?   c                 @  K   |s?| j                   r3| j                  s| j                  | j                         S | j                   S d }| j                  d   du r| j	                          d {   }| j                  |       d {   }| j                  ||      S 7 /7 w)NfetchCurrenciesT)marketsmarkets_by_idset_marketshasfetch_currenciesfetch_markets)r<   reloadparams
currenciesr   s        r>   load_markets_helperzExchange.load_markets_helper  s     ||))++DLL99||#
88%&$.#4466J**62244 72s$   A(B*B+BBBBc                 r  K   |r| j                   r| j                  s3d| _         | j                  ||      }t        j                  |      | _        	 | j                   d{   }d| _         |S 7 # t        j
                  $ r}d| _         d| _        |d}~wt        $ r}d| _         d| _        |d}~ww xY ww)a:  
        Loads and prepares the markets for trading.

        Args:
            reload (bool): If True, the markets will be reloaded from the exchange.
            params (dict): Additional exchange-specific parameters for the request.

        Returns:
            dict: A dictionary of markets.

        Raises:
            Exception: If the markets cannot be loaded or prepared.

        Notes:
            This method is asynchronous.
            It ensures that the markets are only loaded once, even if called multiple times.
            If the markets are already loaded and `reload` is False or not provided, it returns the existing markets.
            If a reload is in progress, it waits for completion before returning.
            If an error occurs during loading or preparation, an exception is raised.
        TNF)r;   r:   r   rj   ensure_futureCancelledError	Exception)r<   r   r   	coroutineresultr   s         r>   load_marketszExchange.load_markets!  s     * 411$:N:N%)D"00@I#*#8#8#CD 		///F "' 0%% 	%*D"#'D G 	%*D"#'D G	sH   AB7A0  A.!A0 %	B7.A0 0B4BB4B//B44B7c                    K   |s)| j                   t        j                   k7  r| j                   S | j                  | j                   | j                          d {         | _         | j                   S 7 wrA   )loaded_feesr   deep_extend
fetch_fees)r<   r   s     r>   	load_feeszExchange.load_feesH  s`     8#7#77'''++D,<,<DOODU>UV ?Vs   AA3A1
A3c                 @   K   | j                  | j                        S wrA   )to_arrayr   r<   r   s     r>   r   zExchange.fetch_marketsO  s     
 }}T\\**s   c                 "   K   | j                   S wrA   )r   r   s     r>   r   zExchange.fetch_currenciesV  s     
 s   1mc                 H   K   | j                  |||||       d {   S 7 wrA   )fetch_ohlcvcr<   symbol	timeframesincelimitr   s         r>   fetchOHLCVCzExchange.fetchOHLCVC]  s%     &&vy%OOOOs   " "c                 B   K   | j                  ||       d {   S 7 wrA   )fetch_tickersr<   symbolsr   s      r>   fetch_full_tickerszExchange.fetch_full_tickers`  s     ''8888   c                 N   K   t        j                  |dz         d {   S 7 wNr   )rj   r{   )r<   millisecondss     r>   r{   zExchange.sleepc  s      ]]<$#67777s   %#%c                 J   K   	  ||  d {    y 7 # t         $ r Y y w xY wwrA   )r   )r<   r   argss      r>   spawn_asynczExchange.spawn_asyncf  s)     	$- 		s(   #  # 	 # #c                     fd}t               | j                  j                   ||       }|j                  |       S )Nc                     | j                         }| j                  | j                                y j                  |       y rA   )	exceptionresolver   reject)asyncio_futurer  futures     r>   callbackz Exchange.spawn.<locals>.callbackn  s8    &002I ~4467i(r?   )r!   r.   create_taskadd_done_callback)r<   r   r   r	  taskr  s        @r>   spawnzExchange.spawnm  s>    	)   ,,VT];x(r?   c                     t        |       S rA   )r   r   s    r>   r   zExchange.inflate|  s    t}r?   c                     t        |       S rA   )r   r  s    r>   r   zExchange.inflate64  s    r?   c                     t        |       S rA   )r   r  s    r>   r   zExchange.gunzip  s    d|r?   c                     t        ||      S rA   )r"   r<   snapshotdepths      r>   
order_bookzExchange.order_book  s    5))r?   c                     t        ||      S rA   )r#   r  s      r>   indexed_order_bookzExchange.indexed_order_book      %00r?   c                     t        ||      S rA   )r$   r  s      r>   counted_order_bookzExchange.counted_order_book  r  r?   c           
      p   | j                   xs i | _         || j                   vr| j                  }| j                  }| j                  }| j                  }| j                  | j                  di       }| j                  | j                  t        | d      t        | dd       | j                  t        | j                  | j                        | j                  d|      }t        ||||||      | j                   |<   | j                         \  }}	}
|s|	r|r|n|	| j                   |   _        | j                   |   S )Nwsr   ping)r   r  r   rJ   r.   )clientshandle_messageon_erroron_closeon_connected
safe_valuero   extend	streamingr   r   r	   rE   r.   r    check_ws_proxy_settingsr   )r<   r   
on_messager!  r"  r#  
ws_optionsro   r   r   r   s              r>   clientzExchange.client  s   ||)rdll",,J}}H}}H,,LtR@Jkk$..tU+fd3<<%d&6&68I8IJ $ 1 13 G !.c:xS_ah iDLL040L0L0N-Iz:Z7@)jS!'||C  r?   c                 Z     | j                   j                  |dz  | j                  |g| S r   )r.   
call_laterr  )r<   r   r   r   s       r>   delayzExchange.delay  s-    +t  ++GdNDJJVQUVVr?   c                 >    d}|rt        | j                  dz         i S )NTz%.handle_message() not implemented yetr   rQ   )r<   r*  messagealwayss       r>   r   zExchange.handle_message  s$    tww)PPQQ	r?   c                      j                          d} j                  |      t        j                  |D cg c]  }j	                  |       c}      }g }	|:|D ]5  }
|
j
                  vs|	j                  |
       |xs dj
                  |
<   7 j                  j                         rj                  n.t        j                  j                   j                  |            } fd}|	r|j                  |       |S c c}w )Nr   Tc                     j                  j                  d      }j                  |dd      r#fd}t        j                   |              y y )Nr  rG      c                  &  K   j                   rj                         d {    	 j                         d {    y 7 7 # t        $ r} j	                  |        Y d } ~ y d } ~ wt
        $ r} j	                  |        Y d } ~ y d } ~ ww xY wwrA   enableRateLimitrJ   sendConnectionErrorr!  r   r   r*  rG   r0  r<   s    r>   send_messagez<Exchange.watch_multiple.<locals>.after.<locals>.send_message  x     ++$ood333+$kk'222 42* +**$ +**+Z   !BABA AA BA 	BA'"B'B3B	B	BBr$  ro   rj   r   futro   r;  rG   r*  r0  r<   s      @r>   afterz&Exchange.watch_multiple.<locals>.after  H    oodllD9G??7FA6D+ %%ln5 r?   )rV   r*  r!   racer  subscriptionsappend	connecteddonerj   r   connectr1   r  )r<   r   message_hashesr0  subscribe_hashessubscriptionbackoff_delaymessage_hashr  missing_subscriptionssubscribe_hashrF  rA  r*  s   `  `         @r>   watch_multiplezExchange.watch_multiple  s    		S!n]lfmmL9]^ "'"2 P!)=)==)00@;G;O4F((8P
 )/(8(8(=(=(?F$$&&v~~dllM'RS 		6  !''.? ^s   Dc                 B     j                          d} j                  |      ||j                  v rj                  |   S j                  |      }j                  j                  |      }|s|xs dj                  |<    j                  }	 j                         \  }
}}|r j                  |      }	j                  j                         rj                  n$t        j                  j                  |	|            } fd}|s|j                  |       |S )Nr   Tc                     j                  j                  d      }j                  |dd      r#fd}t        j                   |              y y )Nr  rG   r4  c                  &  K   j                   rj                         d {    	 j                         d {    y 7 7 # t        $ r} j	                  |        Y d } ~ y d } ~ wt
        $ r} j	                  |        Y d } ~ y d } ~ ww xY wwrA   r6  r:  s    r>   r;  z3Exchange.watch.<locals>.after.<locals>.send_message  r<  r=  r>  r?  s      @r>   rA  zExchange.watch.<locals>.after  rB  r?   )rV   r*  r   r  rD  r3   r1   r'  r   rF  rG  rj   r   rH  r  )r<   r   rM  r0  rO  rK  rL  r  
subscribedselected_sessionr   r   r   rF  rA  r*  s   `  `           @r>   watchzExchange.watch  s   		S!!lfnn&D>>,//|,))--n=
3?3G4F  0<<,0,H,H,J)	:z#;;JG(.(8(8(=(=(?F$$&&v~~6F'VW 		6  ''.r?   c                      y rA    )r<   r*  r0  s      r>   r#  zExchange.on_connected  s     	r?   c                     |j                   | j                  v r<| j                  |j                      j                  r| j                  |j                   = y y y rA   )r   r  errorr<   r*  rZ  s      r>   r!  zExchange.on_error
  s@    ::%$,,vzz*B*H*HVZZ( +I%r?   c                 ~    |j                   ry |j                  | j                  v r| j                  |j                  = y y rA   )rZ  r   r  r[  s      r>   r"  zExchange.on_close  s3    << zzT\\)LL, *r?   c           	      t  K   | j                   rt        j                  | j                   j                         D cg c]%  }t        j                  |j                               ' c}t        j                         d {    | j                   j                         D ]  }| j                   |=  y y c c}w 7 7w)N)return_when)r  rj   waitvaluesr
  rY   ALL_COMPLETEDcopy)r<   r*  r   s      r>   rx   zExchange.ws_close  s     <<,,RVR^R^ReReRgh 3 3FLLN Chv}  wL  wL  M  M  M||((* &LL%& h  Ms   8B8*B1$B8>B6?8B8c                   K   || j                   vr)|j                  t        | j                  dz         |       y 	 | j	                  ddd      }d}| j                   |   }||k  r|j
                  }	| j                  |||       d {   }
| j                  |
|	      }|dk\  rI|j                  |
       | j                  ||	|d         |	j                          |j                  ||       y |dz  }||k  r|j                  t        | j                  dz   t        |      z   dz         |       | j                  |j                  = y 7 # t        $ r:}|j                  ||       | j!                  |||||       d {  7   Y d }~y d }~ww xY ww)	Nz+ loadOrderBook() orderbook is not initiatedwatchOrderBook
maxRetriesrS   r   r4  z nonce is behind cache after z tries.)
orderbooksr  r   rQ   handle_optioncachefetch_order_bookget_cache_indexresethandle_deltasclearr  strr  r   r
   load_order_book)r<   r*  messageHashr   r   r   re  triesstoredrh  r  indexr   s                r>   ro  zExchange.load_order_book  sv    (MM-2_(_`bmn	S++,<lANJE__V,F*$#'#8#8#OO
,,Z?A:LL,&&vuUV}=KKMNN6;7
 *$ MM-2Q(QTWXbTc(cfo(opr}~VZZ( P  	SMM![)&&v{FE6RRR	Ssa   8FAE EA#E *F+
E 6AE FE 	F
*F:E=;F FF

Fc                 &    |dk(  ryt        |d      S )Nr   z0e-00g)format)r<   ns     r>   format_scientific_notation_ftxz'Exchange.format_scientific_notation_ftx6  s    6a~r?   c                 :   K   t        | j                  dz         w)Nz% fetchAccounts() is not supported yetr/  r   s     r>   fetch_accountszExchange.fetch_accountsb       477%LLMM   r   r   r   c                 :   K   t        | j                  dz         w)Nz# fetchTrades() is not supported yetr/  r<   r   r   r   r   s        r>   fetch_tradeszExchange.fetch_tradese       477%JJKKr|  c                 :   K   t        | j                  dz         w)Nz% fetchTradesWs() is not supported yetr/  r~  s        r>   fetch_trades_wszExchange.fetch_trades_wsh  r{  r|  c                    K   | j                   d   r| j                  |g|||       d {   S t        | j                  dz         7 w)NwatchLiquidationsForSymbolsz) watchLiquidations() is not supported yet)r   watch_liquidations_for_symbolsr   rQ   r~  s        r>   watch_liquidationszExchange.watch_liquidationsk  sK     8812<<fXueU[\\\477%PPQQ ]s   (A	AA	r   c                 :   K   t        | j                  dz         w)Nz3 watchLiquidationsForSymbols() is not supported yetr/  r<   r   r   r   r   s        r>   r  z'Exchange.watch_liquidations_for_symbolsp  s     477%ZZ[[r|  c                    K   | j                   d   r| j                  |g|||      S t        | j                  dz         w)NwatchMyLiquidationsForSymbolsz+ watchMyLiquidations() is not supported yet)r   !watch_my_liquidations_for_symbolsr   rQ   r~  s        r>   watch_my_liquidationszExchange.watch_my_liquidationss  sB     8834996(E5RXYY477%RRSSs   =?c                 :   K   t        | j                  dz         w)Nz5 watchMyLiquidationsForSymbols() is not supported yetr/  r  s        r>   r  z*Exchange.watch_my_liquidations_for_symbolsx  s     477%\\]]r|  c                 :   K   t        | j                  dz         w)Nz# watchTrades() is not supported yetr/  r~  s        r>   watch_tradeszExchange.watch_trades{  r  r|  c                 :   K   t        | j                  dz         w)Nz% unWatchTrades() is not supported yetr/  r<   r   r   s      r>   un_watch_tradeszExchange.un_watch_trades~  r{  r|  c                 :   K   t        | j                  dz         w)Nz- watchTradesForSymbols() is not supported yetr/  r  s        r>   watch_trades_for_symbolsz!Exchange.watch_trades_for_symbols       477%TTUUr|  c                 :   K   t        | j                  dz         w)Nz/ unWatchTradesForSymbols() is not supported yetr/  r   s      r>   un_watch_trades_for_symbolsz$Exchange.un_watch_trades_for_symbols       477%VVWWr|  c                 :   K   t        | j                  dz         w)Nz/ watchMyTradesForSymbols() is not supported yetr/  r  s        r>   watch_my_trades_for_symbolsz$Exchange.watch_my_trades_for_symbols  r  r|  c                 :   K   t        | j                  dz         w)Nz- watchOrdersForSymbols() is not supported yetr/  r  s        r>   watch_orders_for_symbolsz!Exchange.watch_orders_for_symbols  r  r|  symbolsAndTimeframesc                 :   K   t        | j                  dz         w)Nz, watchOHLCVForSymbols() is not supported yetr/  )r<   r  r   r   r   s        r>   watch_ohlcv_for_symbolsz Exchange.watch_ohlcv_for_symbols       477%SSTTr|  c                 :   K   t        | j                  dz         w)Nz. unWatchOHLCVForSymbols() is not supported yetr/  )r<   r  r   s      r>   un_watch_ohlcv_for_symbolsz#Exchange.un_watch_ohlcv_for_symbols       477%UUVVr|  c                 :   K   t        | j                  dz         w)Nz0 watchOrderBookForSymbols() is not supported yetr/  r<   r   r   r   s       r>   watch_order_book_for_symbolsz%Exchange.watch_order_book_for_symbols       477%WWXXr|  c                 :   K   t        | j                  dz         w)Nz2 unWatchOrderBookForSymbols() is not supported yetr/  r   s      r>   un_watch_order_book_for_symbolsz(Exchange.un_watch_order_book_for_symbols       477%YYZZr|  codesc                 :   K   t        | j                  dz         w)Nz- fetchDepositAddresses() is not supported yetr/  r<   r  r   s      r>   fetch_deposit_addressesz Exchange.fetch_deposit_addresses  r  r|  c                 :   K   t        | j                  dz         w)Nz& fetchOrderBook() is not supported yetr/  r<   r   r   r   s       r>   ri  zExchange.fetch_order_book       477%MMNNr|  c                 :   K   t        | j                  dz         w)Nz( fetchOrderBookWs() is not supported yetr/  r  s       r>   fetch_order_book_wszExchange.fetch_order_book_ws       477%OOPPr|  c                    K   | j                   d   r-| j                  |g|       d {   }| j                  ||      S t        | j                  dz         7 .w)NfetchMarginModesz' fetchMarginMode() is not supported yet)r   fetch_margin_modes	safe_dictr   rQ   )r<   r   r   marginModess       r>   fetch_margin_modezExchange.fetch_margin_mode  sV     88&' $ 7 7& IIK>>+v66tww)RRSS J   &AA/Ac                 :   K   t        | j                  dz         w)Nz( fetchMarginModes() is not supported yetr/  r   s      r>   r  zExchange.fetch_margin_modes  r  r|  c                    K   | j                  ddd      }t        d|      D ]!  }	 | j                  |||       d {   }|c S  y 7 
# t        $ r}|dz   |k(  r|Y d }~?d }~ww xY ww)Nrd  re  rS   r   r4  )rg  rangeri  r   )r<   r   r   r   fetchSnapshotMaxRetriesi	orderBookr   s           r>   fetch_rest_order_book_safez#Exchange.fetch_rest_order_book_safe  s     "&"4"45E|UV"Wq12 	A"&"7"7v"NN	  	  O E55G 6s>   #A)A	AA	A)A			A&
A!A)!A&&A)c                 :   K   t        | j                  dz         w)Nz& watchOrderBook() is not supported yetr/  r  s       r>   watch_order_bookzExchange.watch_order_book  r  r|  c                 :   K   t        | j                  dz         w)Nz( unWatchOrderBook() is not supported yetr/  r  s      r>   un_watch_order_bookzExchange.un_watch_order_book  r  r|  c                 :   K   t        | j                  dz         w)Nz! fetchTime() is not supported yetr/  r   s     r>   
fetch_timezExchange.fetch_time       477%HHIIr|  c                 :   K   t        | j                  dz         w)Nz* fetchTradingLimits() is not supported yetr/  r   s      r>   fetch_trading_limitszExchange.fetch_trading_limits       477%QQRRr|  c                 :   K   t        | j                  dz         w)Nz- fetchCrossBorrowRates() is not supported yetr/  r   s     r>   fetch_cross_borrow_ratesz!Exchange.fetch_cross_borrow_rates  r  r|  c                 :   K   t        | j                  dz         w)Nz0 fetchIsolatedBorrowRates() is not supported yetr/  r   s     r>   fetch_isolated_borrow_ratesz$Exchange.fetch_isolated_borrow_rates  r  r|  c                 :   K   t        | j                  dz         w)Nz* fetchLeverageTiers() is not supported yetr/  r   s      r>   fetch_leverage_tierszExchange.fetch_leverage_tiers  r  r|  c                 :   K   t        | j                  dz         w)Nz) fetchFundingRates() is not supported yetr/  r   s      r>   fetch_funding_rateszExchange.fetch_funding_rates       477%PPQQr|  c                 :   K   t        | j                  dz         w)Nz- fetchFundingIntervals() is not supported yetr/  r   s      r>   fetch_funding_intervalsz Exchange.fetch_funding_intervals  r  r|  c                 :   K   t        | j                  dz         w)Nz( watchFundingRate() is not supported yetr/  r  s      r>   watch_funding_ratezExchange.watch_funding_rate  r  r|  c                 :   K   t        | j                  dz         w)Nz) watchFundingRates() is not supported yetr/  r   s      r>   watch_funding_rateszExchange.watch_funding_rates  r  r|  c                 B   K   | j                  ||       d {   S 7 wrA   )r  r   s      r>   watch_funding_rates_for_symbolsz(Exchange.watch_funding_rates_for_symbols  s     --gv>>>>r   codeamountfromAccount	toAccountc                 :   K   t        | j                  dz         w)Nz  transfer() is not supported yetr/  )r<   r  r  r  r  r   s         r>   transferzExchange.transfer       477%GGHHr|  addressc                 :   K   t        | j                  dz         w)Nz  withdraw() is not supported yetr/  )r<   r  r  r  tagr   s         r>   withdrawzExchange.withdraw  r  r|  c                 :   K   t        | j                  dz         w)Nz, createDepositAddress() is not supported yetr/  r<   r  r   s      r>   create_deposit_addresszExchange.create_deposit_address  r  r|  leveragec                 :   K   t        | j                  dz         w)Nz# setLeverage() is not supported yetr/  )r<   r  r   r   s       r>   set_leveragezExchange.set_leverage  r  r|  c                    K   | j                   d   r-| j                  |g|       d {   }| j                  ||      S t        | j                  dz         7 .w)NfetchLeveragesz% fetchLeverage() is not supported yet)r   fetch_leveragesr  r   rQ   )r<   r   r   	leveragess       r>   fetch_leveragezExchange.fetch_leverage  sV     88$%"22F8VDDI>>)V44tww)PPQQ Er  c                 :   K   t        | j                  dz         w)Nz& fetchLeverages() is not supported yetr/  r   s      r>   r  zExchange.fetch_leverages  r  r|  hedgedc                 :   K   t        | j                  dz         w)Nz' setPositionMode() is not supported yetr/  )r<   r  r   r   s       r>   set_position_modezExchange.set_position_mode       477%NNOOr|  c                 :   K   t        | j                  dz         w)Nz! addMargin() is not supported yetr/  r<   r   r  r   s       r>   
add_marginzExchange.add_margin  r  r|  c                 :   K   t        | j                  dz         w)Nz$ reduceMargin() is not supported yetr/  r  s       r>   reduce_marginzExchange.reduce_margin       477%KKLLr|  c                 :   K   t        | j                  dz         w)Nz! setMargin() is not supported yetr/  r  s       r>   
set_marginzExchange.set_margin  r  r|  r   c                 :   K   t        | j                  dz         w)Nz+ fetchLongShortRatio() is not supported yetr/  )r<   r   r   r   s       r>   fetch_long_short_ratiozExchange.fetch_long_short_ratio       477%RRSSr|  c                 :   K   t        | j                  dz         w)Nz2 fetchLongShortRatioHistory() is not supported yetr/  r   s         r>   fetch_long_short_ratio_historyz'Exchange.fetch_long_short_ratio_history   r  r|  typec                 :   K   t        | j                  dz         w)a  
        fetches the history of margin added or reduced from contract isolated positions
        :param str [symbol]: unified market symbol
        :param str [type]: "add" or "reduce"
        :param int [since]: timestamp in ms of the earliest change to fetch
        :param int [limit]: the maximum amount of changes to fetch
        :param dict params: extra parameters specific to the exchange api endpoint
        :returns dict[]: a list of `margin structures <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        z4 fetchMarginAdjustmentHistory() is not supported yetr/  )r<   r   r  r   r   r   s         r>   fetch_margin_adjustment_historyz(Exchange.fetch_margin_adjustment_history  s      477%[[\\r|  
marginModec                 :   K   t        | j                  dz         w)Nz% setMarginMode() is not supported yetr/  )r<   r	  r   r   s       r>   set_margin_modezExchange.set_margin_mode  r{  r|  c                 :   K   t        | j                  dz         w)Nz6 fetchDepositAddressesByNetwork() is not supported yetr/  r  s      r>   "fetch_deposit_addresses_by_networkz+Exchange.fetch_deposit_addresses_by_network  s     477%]]^^r|  1hc                 :   K   t        | j                  dz         w)Nz0 fetchOpenInterestHistory() is not supported yetr/  r   s         r>   fetch_open_interest_historyz$Exchange.fetch_open_interest_history  r  r|  c                 :   K   t        | j                  dz         w)Nz) fetchOpenInterest() is not supported yetr/  r  s      r>   fetch_open_interestzExchange.fetch_open_interest  r  r|  c                 :   K   t        | j                  dz         w)Nz* fetchOpenInterests() is not supported yetr/  r   s      r>   fetch_open_interestszExchange.fetch_open_interests  r  r|  c                 :   K   t        | j                  dz         w)Nz signIn() is not supported yetr/  r   s     r>   sign_inzExchange.sign_in  s     477%EEFFr|  c                 :   K   t        | j                  dz         w)Nz+ fetchPaymentMethods() is not supported yetr/  r   s     r>   fetch_payment_methodszExchange.fetch_payment_methods!  r  r|  c                 :   K   t        | j                  dz         w)Nzb fetchBorrowRate is deprecated, please use fetchCrossBorrowRate or fetchIsolatedBorrowRate insteadr/  r<   r  r  r   s       r>   fetch_borrow_ratezExchange.fetch_borrow_rate$  s'     477  &J  J  K  	Kr|  c                 :   K   t        | j                  dz         w)Nz$ repayCrossMargin is not support yetr/  r  s       r>   repay_cross_marginzExchange.repay_cross_margin'  r  r|  c                 :   K   t        | j                  dz         w)Nz' repayIsolatedMargin is not support yetr/  r<   r   r  r  r   s        r>   repay_isolated_marginzExchange.repay_isolated_margin*  r  r|  c                 :   K   t        | j                  dz         w)Nz% borrowCrossMargin is not support yetr/  r  s       r>   borrow_cross_marginzExchange.borrow_cross_margin-  r{  r|  c                 :   K   t        | j                  dz         w)Nz( borrowIsolatedMargin is not support yetr/  r  s        r>   borrow_isolated_marginzExchange.borrow_isolated_margin0  r  r|  c                 :   K   t        | j                  dz         w)NzY borrowMargin is deprecated, please use borrowCrossMargin or borrowIsolatedMargin insteadr/  r<   r  r  r   r   s        r>   borrow_marginzExchange.borrow_margin3  s'     477  &A  A  B  	Br|  c                 :   K   t        | j                  dz         w)NzV repayMargin is deprecated, please use repayCrossMargin or repayIsolatedMargin insteadr/  r&  s        r>   repay_marginzExchange.repay_margin6  s     477%}}~~r|  c                 f   K   d}| j                   d   rd}t        | j                  dz   |z         w)Nr   fetchTrades. If you want to build OHLCV candles from trade executions data, visit https://github.com/ccxt/ccxt/tree/master/examples/ and see "build-ohlcv-bars" filez" fetchOHLCV() is not supported yetr   r   rQ   r<   r   r   r   r   r   r0  s          r>   fetch_ohlcvzExchange.fetch_ohlcv9  s9     88M" rG477%IIGSTT   /1c                 f   K   d}| j                   d   rd}t        | j                  dz   |z         w)Nr   fetchTradesWsr,  zC fetchOHLCVWs() is not supported yet. Try using fetchOHLCV instead.r-  r.  s          r>   fetch_ohlcv_wszExchange.fetch_ohlcv_ws?  s:     88O$ rG477%jjmttuur0  c                 :   K   t        | j                  dz         w)Nz" watchOHLCV() is not supported yetr/  r   s         r>   watch_ohlcvzExchange.watch_ohlcvE       477%IIJJr|  c                   K   d}| j                  | j                  |i       }| j                  |dd      }	 | j                  |dd      dury | j                  |dd      }	d }
d}d}||	k  r	  t        | |      i        d {   }
d}	 |
}||j                  |      }|d	   }||j                  |      }|d   }|r>t        |t              r.| j                  |j                               }|r|S t        d
      |S 7 {# t        $ r}|d	z   }||	k(  r|Y d }~nd }~ww xY w|r||	k  r# t        $ r}| j                  dz   |z   dz   }Y d }~nd }~ww xY w|ry t        |      w)Nr   webApiMuteFailureTwebApiEnablewebApiRetries
   r   Fr4  z&could not parse the response into jsonr   zx() failed to fetch correct data from website. Probably webpage markup has been changed, breaking the page custom parser.)r$  ro   rn   r   r   split
isinstancern  r   stripr   rQ   )r<   r   endpointMethodreturnAsJson
startRegexendRegexerrorMessagero   muteOnFailurere  r   retryshouldBreakr   r   splitted_by_startsplitted_by_endjsoneds                     r>   fetch_web_endpointzExchange.fetch_web_endpointH  s    //$,,;w0CTJ#	o~~g~t<DH/2FJHEK*$ %BWT>%B2%FFH"&K G%$+MM*$=!+A.#")--"9)!,GS!99!M%&NOO/  G !  !AIE
* +   *$4  	o77S=61  5o  oL	ol++s   3E#D* E#D* +C>  C<C> A'D* .E#/D* ;E#<C> >	DDD* DD* *	E3EE#EE#c           
         K   | j                  |||       d {   }| j                  || j                  | j                  |d         d      | j                  | j                  |d         dd      d      S 7 ^w)Nasksr   bidsT)rL  rM  )ri  r%  sort_by	aggregate)r<   r   r   r   	orderbooks        r>   fetch_l2_order_bookzExchange.fetch_l2_order_booku  su     //vFF	{{9LL	&0A!BAFLL	&0A!BAtL'
  	 Gs   A:A8AA:c                 l  K   | j                   d   r|sd| j                  vr| j                  |       d {   }t        dt	        |            D ]6  }||   }| j                  | j                  |   ||         | j                  |<   8 | j                         | j                  d<   | j                  S 7 {w)NfetchTradingLimitslimitsLoadedr   )r   ro   r  r  lenr   r   r   )r<   r   r   r   r   r  r   s          r>   load_trading_limitszExchange.load_trading_limits|  s     88()n<!%!:!:7!CCq#g,/ dA$QZF+/+;+;DLL<PRZ[aRb+cDLL(d 04/@/@/B^,|| Ds   4B4B2A<B4publicapir   r   c           	      6  K   | j                   r.| j                  |||||      }| j                  |       d {    | j                         | _        | j                  ||||||      }	|	d   | _        |	d   | _        |	d   | _        d }
| j                  ||dd      \  }
}d }| j                  ||dd      \  }}t        d|
dz         D ],  }	 | j                  |	d   |	d   |	d   |	d          d {   c S  y 7 7 
# t        $ r}t        |t              rv||
k  ro| j                  rA| j!                  d	t#        |      z   d
z   |t#        d      z   z   dz   t#        |
      z   dz          |$|dk7  r| j%                  |       d {  7   n||Y d }~d }~ww xY ww)Nr   r   r   maxRetriesOnFailurer   maxRetriesOnFailureDelayr4  r   zRequest failed with the error: z, retrying z of z...)r7  calculate_rate_limiter_costrJ   r   lastRestRequestTimestampsignr   last_request_bodylast_request_urlhandle_option_and_paramsr  r   r   r=  r   r   r   rn  r{   )r<   pathrX  r   r   r   r   r,   rG   requestretries
retryDelayr  r   s                 r>   fetch2zExchange.fetch2  s    33CvvVD--%%%(,(9(9(;%))D#vvwE$+I$6!!( '77F[]^_
!::64Icefg
Fq'A+& 	A!ZZ8I7S\K]_fgm_nooo	 1 & p 
a17{<< HH%FQ%OR_%_cdgjklgmcm%nqw%wz}  F  {G  &G  JO  &O  P&2q"&**Z"888G
sY   6FC7BF#C;.C9/C;2F9C;;	FA=FF
FFFFc           	      L   K   | j                  |||||||       d {   S 7 wrA   )rf  )r<   rb  rX  r   r   r   r   r,   s           r>   rc  zExchange.request  s'     [[sFFGT6RRRR   $"$c                   K   |r| j                  |       d {   | _        n6| j                  r| j                  S | j                  |       d {   | _        | j                  | j                  d      | _        | j                  S 7 m7 8w)NrQ   )rz  accountsindex_byaccountsById)r<   r   r   s      r>   load_accountszExchange.load_accounts  sq     "&"5"5f"==DM}}}}$&*&9&9&&A A MM$-->}} >
 !Bs!   BB6BB	7B	BrQ   pricec                 J   K   | j                  ||d|||       d {   S 7 w)Nbuyedit_limit_orderr<   rQ   r   r  rn  r   s         r>   edit_limit_buy_orderzExchange.edit_limit_buy_order  s'     **2vufeVTTTT   #!#c                 J   K   | j                  ||d|||       d {   S 7 w)Nsellrq  rs  s         r>   edit_limit_sell_orderzExchange.edit_limit_sell_order  s'     **2vvvufUUUUru  sidec           	      L   K   | j                  ||d||||       d {   S 7 wNr   )
edit_order)r<   rQ   r   ry  r  rn  r   s          r>   rr  zExchange.edit_limit_order  s'     __R$vVVVVrh  c                    K   | j                  ||       d {    | j                  ||||||       d {   S 7 "7 wrA   )cancel_ordercreate_orderr<   rQ   r   r  ry  r  rn  r   s           r>   r|  zExchange.edit_order  sC     F+++&&vtT65&QQQ 	,Q   ?;?=??c                    K   | j                  ||       d {    | j                  ||||||       d {   S 7 "7 wrA   )cancel_order_wscreate_order_wsr  s           r>   edit_order_wszExchange.edit_order_ws  sC     ""2v...))&$feVTTT 	/Tr  c                 :   K   t        | j                  dz         w)Nz% fetchPosition() is not supported yetr/  r  s      r>   fetch_positionzExchange.fetch_position  r{  r|  c                 :   K   t        | j                  dz         w)Nz' fetchPositionWs() is not supported yetr/  r  s      r>   fetch_position_wszExchange.fetch_position_ws  r  r|  c                 :   K   t        | j                  dz         w)Nz% watchPosition() is not supported yetr/  r  s      r>   watch_positionzExchange.watch_position  r{  r|  c                 :   K   t        | j                  dz         w)Nz& watchPositions() is not supported yetr/  r  s        r>   watch_positionszExchange.watch_positions  r  r|  c                 F   K   | j                  ||||       d {   S 7 wrA   )r  r  s        r>   watch_position_for_symbolsz#Exchange.watch_position_for_symbols  s#     ))'5%HHHHs   !!c                 :   K   t        | j                  dz         wa_  
        fetches all open positions for specific symbol, unlike fetchPositions(which is designed to work with multiple symbols) so self method might be preffered for one-market position, because of less rate-limit consumption and speed
        :param str symbol: unified market symbol
        :param dict params: extra parameters specific to the endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>` with maximum 3 items - possible one position for "one-way" mode, and possible two positions(long & short) for "two-way"(a.k.a. hedge) mode
        z/ fetchPositionsForSymbol() is not supported yetr/  r  s      r>   fetch_positions_for_symbolz#Exchange.fetch_positions_for_symbol        477%VVWWr|  c                 :   K   t        | j                  dz         wr  r/  r  s      r>   fetch_positions_for_symbol_wsz&Exchange.fetch_positions_for_symbol_ws  r  r|  c                 :   K   t        | j                  dz         wNz& fetchPositions() is not supported yetr/  r   s      r>   fetch_positionszExchange.fetch_positions  r  r|  c                 :   K   t        | j                  dz         wr  r/  r   s      r>   fetch_positions_wszExchange.fetch_positions_ws  r  r|  c                 :   K   t        | j                  dz         w)Nz* fetchPositionsRisk() is not supported yetr/  r   s      r>   fetch_positions_riskzExchange.fetch_positions_risk  r  r|  c                 :   K   t        | j                  dz         w)Nz% fetchBidsAsks() is not supported yetr/  r   s      r>   fetch_bids_askszExchange.fetch_bids_asks  r{  r|  c                 :   K   t        | j                  dz         w)Nz+ fetchBorrowInterest() is not supported yetr/  )r<   r  r   r   r   r   s         r>   fetch_borrow_interestzExchange.fetch_borrow_interest  r  r|  c                 :   K   t        | j                  dz         w)Nz# fetchLedger() is not supported yetr/  r<   r  r   r   r   s        r>   fetch_ledgerzExchange.fetch_ledger  r  r|  c                 :   K   t        | j                  dz         w)Nz( fetchLedgerEntry() is not supported yetr/  r<   rQ   r  r   s       r>   fetch_ledger_entryzExchange.fetch_ledger_entry  r  r|  c                 :   K   t        | j                  dz         w)Nz$ fetchBalance() is not supported yetr/  r   s     r>   fetch_balancezExchange.fetch_balance  r  r|  c                 :   K   t        | j                  dz         w)Nz& fetchBalanceWs() is not supported yetr/  r   s     r>   fetch_balance_wszExchange.fetch_balance_ws  r  r|  c                 :   K   t        | j                  dz         w)Nz$ watchBalance() is not supported yetr/  r   s     r>   watch_balancezExchange.watch_balance  r  r|  c                 J   K   | j                  |       d {   }||   S 7 	wrA   )r  )r<   partr   balances       r>   fetch_partial_balancezExchange.fetch_partial_balance  s(     **622t} 3s   #!
#c                 B   K   | j                  d|       d {   S 7 w)Nfreer  r   s     r>   fetch_free_balancezExchange.fetch_free_balance       //????r   c                 B   K   | j                  d|       d {   S 7 w)Nusedr  r   s     r>   fetch_used_balancezExchange.fetch_used_balance  r  r   c                 B   K   | j                  d|       d {   S 7 w)Ntotalr  r   s     r>   fetch_total_balancezExchange.fetch_total_balance  s     //@@@@r   c                 :   K   t        | j                  dz         w)Nz# fetchStatus() is not supported yetr/  r   s     r>   fetch_statuszExchange.fetch_status  r  r|  c                    K   | j                   d   st        | j                  dz         | j                  |g|       d {   S 7 w)NfetchTransactionFeesz+ fetchTransactionFee() is not supported yet)r   r   rQ   fetch_transaction_feesr  s      r>   fetch_transaction_feezExchange.fetch_transaction_fee  sC     xx./tww)VVWW00$@@@@s   >A AAc                 :   K   t        | j                  dz         w)Nz, fetchTransactionFees() is not supported yetr/  r  s      r>   r  zExchange.fetch_transaction_fees  r  r|  c                 :   K   t        | j                  dz         w)Nz0 fetchDepositWithdrawFees() is not supported yetr/  r  s      r>   fetch_deposit_withdraw_feesz$Exchange.fetch_deposit_withdraw_fees  r  r|  c                    K   | j                   d   st        | j                  dz         | j                  |g|       d {   }| j	                  ||      S 7 w)NfetchDepositWithdrawFeesz/ fetchDepositWithdrawFee() is not supported yet)r   r   rQ   r  r$  )r<   r  r   feess       r>   fetch_deposit_withdraw_feez#Exchange.fetch_deposit_withdraw_fee  sV     xx23tww)ZZ[[55tffEEtT** Fs   >A AAc                 $  K   | j                          d {    | j                  d   st        | j                  dz         | j	                  |       d {   }| j                  ||      }|t        | j                  dz   |z         |S 7 u7 7w)NfetchBorrowRatesz, fetchCrossBorrowRate() is not supported yetzI fetchCrossBorrowRate() could not find the borrow rate for currency code )r   r   r   rQ   r  r$  r   )r<   r  r   borrowRatesrates        r>   fetch_cross_borrow_ratez Exchange.fetch_cross_borrow_rate"  s     !!!xx*+tww)WWXX 99&AA{D1<*u ux| |}} 	" B!   BB?BB6BBc                 $  K   | j                          d {    | j                  d   st        | j                  dz         | j	                  |       d {   }| j                  ||      }|t        | j                  dz   |z         |S 7 u7 7w)Nr  z/ fetchIsolatedBorrowRate() is not supported yetzL fetchIsolatedBorrowRate() could not find the borrow rate for market symbol )r   r   r   rQ   r  r  r   )r<   r   r   r  r  s        r>   fetch_isolated_borrow_ratez#Exchange.fetch_isolated_borrow_rate,  s     !!!xx*+tww)ZZ[[ <<VDD~~k62<*x x  |B  !B  C  C 	" Er  c                 T  K   | j                   d   rz| j                          d {    | j                  |      }|d   }| j                  |g|       d {   }| j	                  ||      }|t        | j                  dz   |z         |S t        | j                  dz         7 ~7 Ow)NfetchTickersr   z, fetchTickers() could not find a ticker for z# fetchTicker() is not supported yet)r   r   marketr   r  r   rQ   r   r<   r   r   r  tickerstickers         r>   fetch_tickerzExchange.fetch_ticker6  s     88N###%%%[[(FH%F ..x@@G^^GV4F~"477-[#[^d#deetww)NNOO & A"   #B(B$0B(B&AB(&B(c                 T  K   | j                   d   rz| j                          d {    | j                  |      }|d   }| j                  |g|       d {   }| j	                  ||      }|t        | j                  dz   |z         |S t        | j                  dz         7 ~7 Ow)NfetchMarkPricesr   z/ fetchMarkPrices() could not find a ticker for ' fetchMarkPrices() is not supported yet)r   r   r  fetch_mark_pricesr  r   rQ   r   r  s         r>   fetch_mark_pricezExchange.fetch_mark_priceD  s     88%&##%%%[[(FH%F 22F8VDDG^^GV4F~"477-^#^ag#ghhtww)RRSS & Er  c                 T  K   | j                   d   rz| j                          d {    | j                  |      }|d   }| j                  |g|       d {   }| j	                  ||      }|t        | j                  dz   |z         |S t        | j                  dz         7 ~7 Ow)NfetchTickersWsr   z- fetchTickerWs() could not find a ticker for z% fetchTickerWs() is not supported yet)r   r   r  fetch_tickers_wsr  r   rQ   r   r  s         r>   fetch_ticker_wszExchange.fetch_ticker_wsR  s     88$%##%%%[[(FH%F 116(FCCG^^GV4F~"477-\#\_e#efftww)PPQQ & Dr  c                 :   K   t        | j                  dz         w)Nz# watchTicker() is not supported yetr/  r  s      r>   watch_tickerzExchange.watch_ticker`  r  r|  c                 :   K   t        | j                  dz         wNz$ fetchTickers() is not supported yetr/  r   s      r>   r   zExchange.fetch_tickersc  r  r|  c                 :   K   t        | j                  dz         w)Nr  r/  r   s      r>   r  zExchange.fetch_mark_pricesf  r  r|  c                 :   K   t        | j                  dz         wr  r/  r   s      r>   r  zExchange.fetch_tickers_wsi  r  r|  c                 :   K   t        | j                  dz         w)Nz' fetchOrderBooks() is not supported yetr/  r  s       r>   fetch_order_bookszExchange.fetch_order_booksl  r  r|  c                 :   K   t        | j                  dz         w)Nz% watchBidsAsks() is not supported yetr/  r   s      r>   watch_bids_askszExchange.watch_bids_askso  r{  r|  c                 :   K   t        | j                  dz         w)Nz$ watchTickers() is not supported yetr/  r   s      r>   watch_tickerszExchange.watch_tickersr  r  r|  c                 :   K   t        | j                  dz         w)Nz& unWatchTickers() is not supported yetr/  r   s      r>   un_watch_tickerszExchange.un_watch_tickersu  r  r|  c                 :   K   t        | j                  dz         w)Nz" fetchOrder() is not supported yetr/  r<   rQ   r   r   s       r>   fetch_orderzExchange.fetch_orderx  r6  r|  c                 :   K   t        | j                  dz         w)Nz$ fetchOrderWs() is not supported yetr/  r  s       r>   fetch_order_wszExchange.fetch_order_ws{  r  r|  c                 N   K   | j                  |||       d {   }|d   S 7 	w)Nr   )r  )r<   rQ   r   r   orders        r>   fetch_order_statuszExchange.fetch_order_status~  s.      &&r66::X ;s   %#
%c                    K   | j                  | j                  |d      | j                  |d      |       d {   S 7 wNrQ   r   )r  safe_stringr<   r  r   s      r>   fetch_unified_orderzExchange.fetch_unified_order  s>     %%d&6&6ud&CTEUEUV[]eEfhnoooos   7A >A c                 :   K   t        | j                  dz         w)Nz# createOrder() is not supported yetr/  r<   r   r  ry  r  rn  r   s          r>   r  zExchange.create_order  r  r|  fromCodetoCodec                 :   K   t        | j                  dz         w)Nz* createConvertTrade() is not supported yetr/  )r<   rQ   r  r   r  r   s         r>   create_convert_tradezExchange.create_convert_trade  r  r|  c                 :   K   t        | j                  dz         w)Nz) fetchConvertTrade() is not supported yetr/  r  s       r>   fetch_convert_tradezExchange.fetch_convert_trade  r  r|  c                 :   K   t        | j                  dz         w)Nz0 fetchConvertTradeHistory() is not supported yetr/  r  s        r>   fetch_convert_trade_historyz$Exchange.fetch_convert_trade_history  r  r|  c                 :   K   t        | j                  dz         w)Nz) fetchPositionMode() is not supported yetr/  r  s      r>   fetch_position_modezExchange.fetch_position_mode  r  r|  c	                    K   |t        | j                  dz         ||d<   |||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)  
        create a trailing order by providing the symbol, type, side, amount, price and trailingAmount
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency, or number of contracts
        :param float [price]: the price for the order to be filled at, in units of the quote currency, ignored in market orders
        :param float trailingAmount: the quote amount to trail away from the current market price
        :param float [trailingTriggerPrice]: the price to activate a trailing order, default uses the price argument
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz? createTrailingAmountOrder() requires a trailingAmount argumenttrailingAmounttrailingTriggerPricecreateTrailingAmountOrderz1 createTrailingAmountOrder() is not supported yetr   rQ   r   r  r   	r<   r   r  ry  r  rn  r  r  r   s	            r>   create_trailing_amount_orderz%Exchange.create_trailing_amount_order  s      !#DGG.o$opp#1 +-AF)*88/0**64vufUUU477%XXYY V   AA0A.A0c	                    K   |t        | j                  dz         ||d<   |||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)r
  NzA createTrailingAmountOrderWs() requires a trailingAmount argumentr  r  createTrailingAmountOrderWsz3 createTrailingAmountOrderWs() is not supported yetr   rQ   r   r  r   r  s	            r>   create_trailing_amount_order_wsz(Exchange.create_trailing_amount_order_ws  s      !#DGG.q$qrr#1 +-AF)*8812--fdD&%QWXXX477%ZZ[[ Yr  c	                    K   |t        | j                  dz         ||d<   |||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)  
        create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency, or number of contracts
        :param float [price]: the price for the order to be filled at, in units of the quote currency, ignored in market orders
        :param float trailingPercent: the percent to trail away from the current market price
        :param float [trailingTriggerPrice]: the price to activate a trailing order, default uses the price argument
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        NzA createTrailingPercentOrder() requires a trailingPercent argumenttrailingPercentr  createTrailingPercentOrderz2 createTrailingPercentOrder() is not supported yetr  	r<   r   r  ry  r  rn  r  r  r   s	            r>   create_trailing_percent_orderz&Exchange.create_trailing_percent_order  s      "#DGG.q$qrr$3 !+-AF)*8801**64vufUUU477%YYZZ Vr  c	                    K   |t        | j                  dz         ||d<   |||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)r  NzC createTrailingPercentOrderWs() requires a trailingPercent argumentr  r  createTrailingPercentOrderWsz4 createTrailingPercentOrderWs() is not supported yetr  r  s	            r>    create_trailing_percent_order_wsz)Exchange.create_trailing_percent_order_ws  s      "#DGG.s$stt$3 !+-AF)*8823--fdD&%QWXXX477%[[\\ Yr  rG   c                    K   | j                   d   s| j                   d   r-| j                   d   r| j                  |d||d|       d{   S t        | j                  dz         7 w)  
        create a market order by providing the symbol, side and cost
        :param str symbol: unified symbol of the market to create an order in
        :param str side: 'buy' or 'sell'
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        createMarketOrderWithCostcreateMarketBuyOrderWithCostcreateMarketSellOrderWithCostr  r4  Nz1 createMarketOrderWithCost() is not supported yet)r   r  r   rQ   r<   r   ry  rG   r   s        r>   create_market_order_with_costz&Exchange.create_market_order_with_cost  sq      88/0TXX>\5]bfbjbj  lK  cL**68T4FSSS477%XXYY T   AA(	A&
A(c                    K   | j                   d   s| j                  d   r| j                  |dd|d|       d{   S t        | j                  dz         7 w)a  
        create a market buy order by providing the symbol and cost
        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        !createMarketBuyOrderRequiresPricer"  r  rp  r4  Nz4 createMarketBuyOrderWithCost() is not supported yetro   r   r  r   rQ   r<   r   rG   r   s       r>   !create_market_buy_order_with_costz*Exchange.create_market_buy_order_with_cost  sZ      <<;<Ig@h**68UD!VTTT477%[[\\ U   8AAAc                    K   | j                   d   s| j                  d   r| j                  |dd|d|       d{   S t        | j                  dz         7 w)a  
        create a market sell order by providing the symbol and cost
        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        "createMarketSellOrderRequiresPricer#  r  rw  r4  Nz5 createMarketSellOrderWithCost() is not supported yetr)  r*  s       r>   "create_market_sell_order_with_costz+Exchange.create_market_sell_order_with_cost  sZ      <<<=JiAj**68VT1fUUU477%\\]] Vr,  c                    K   | j                   d   s| j                   d   r-| j                   d   r| j                  |d||d|       d{   S t        | j                  dz         7 w)r   createMarketOrderWithCostWscreateMarketBuyOrderWithCostWscreateMarketSellOrderWithCostWsr  r4  Nz3 createMarketOrderWithCostWs() is not supported yet)r   r  r   rQ   r$  s        r>    create_market_order_with_cost_wsz)Exchange.create_market_order_with_cost_ws  sq      8812txx@`7afjfnfn  pQ  gR--fhdAvVVV477%ZZ[[ Wr&  triggerPricec                    K   |t        | j                  dz         ||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)  
        create a trigger stop order(type 1)
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency or the number of contracts
        :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
        :param float triggerPrice: the price to trigger the stop order, in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz6 createTriggerOrder() requires a triggerPrice argumentr5  createTriggerOrderz* createTriggerOrder() is not supported yetr  r<   r   r  ry  r  rn  r5  r   s           r>   create_trigger_orderzExchange.create_trigger_order   ss      #DGG.f$fgg!-~88()**64vufUUU477%QQRR V   AA)
A'A)c                    K   |t        | j                  dz         ||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)r7  Nz8 createTriggerOrderWs() requires a triggerPrice argumentr5  createTriggerOrderWsz, createTriggerOrderWs() is not supported yetr  r9  s           r>   create_trigger_order_wsz Exchange.create_trigger_order_ws3  st      #DGG.h$hii!-~88*+--fdD&%QWXXX477%SSTT Yr;  stopLossPricec                    K   |t        | j                  dz         ||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)  
        create a trigger stop loss order(type 2)
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency or the number of contracts
        :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
        :param float stopLossPrice: the price to trigger the stop loss order, in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz8 createStopLossOrder() requires a stopLossPrice argumentr?  createStopLossOrderz+ createStopLossOrder() is not supported yetr  r<   r   r  ry  r  rn  r?  r   s           r>   create_stop_loss_orderzExchange.create_stop_loss_orderF  ss       #DGG.h$hii"/88)***64vufUUU477%RRSS Vr;  c                    K   |t        | j                  dz         ||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)rA  Nz: createStopLossOrderWs() requires a stopLossPrice argumentr?  createStopLossOrderWsz- createStopLossOrderWs() is not supported yetr  rC  s           r>   create_stop_loss_order_wsz"Exchange.create_stop_loss_order_wsY  st       #DGG.j$jkk"/88+,--fdD&%QWXXX477%TTUU Yr;  takeProfitPricec                    K   |t        | j                  dz         ||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)  
        create a trigger take profit order(type 2)
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency or the number of contracts
        :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
        :param float takeProfitPrice: the price to trigger the take profit order, in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nz< createTakeProfitOrder() requires a takeProfitPrice argumentrH  createTakeProfitOrderz- createTakeProfitOrder() is not supported yetr  r<   r   r  ry  r  rn  rH  r   s           r>   create_take_profit_orderz!Exchange.create_take_profit_orderl  st      "#DGG.l$lmm$3 !88+,**64vufUUU477%TTUU Vr;  c                    K   |t        | j                  dz         ||d<   | j                  d   r| j                  ||||||       d{   S t	        | j                  dz         7 w)rJ  Nz> createTakeProfitOrderWs() requires a takeProfitPrice argumentrH  createTakeProfitOrderWsz/ createTakeProfitOrderWs() is not supported yetr  rL  s           r>   create_take_profit_order_wsz$Exchange.create_take_profit_order_ws  su      "#DGG.n$noo$3 !88-.--fdD&%QWXXX477%VVWW Yr;  
takeProfitstopLossc	           
         K   | j                  ||||||||      }| j                  d   r| j                  ||||||       d{   S t        | j                  dz         7 w)  
        create an order with a stop loss or take profit attached(type 3)
        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much you want to trade in units of the base currency or the number of contracts
        :param float [price]: the price to fulfill the order, in units of the quote currency, ignored in market orders
        :param float [takeProfit]: the take profit price, in units of the quote currency
        :param float [stopLoss]: the stop loss price, in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.takeProfitType]: *not available on all exchanges* 'limit' or 'market'
        :param str [params.stopLossType]: *not available on all exchanges* 'limit' or 'market'
        :param str [params.takeProfitPriceType]: *not available on all exchanges* 'last', 'mark' or 'index'
        :param str [params.stopLossPriceType]: *not available on all exchanges* 'last', 'mark' or 'index'
        :param float [params.takeProfitLimitPrice]: *not available on all exchanges* limit price for a limit take profit order
        :param float [params.stopLossLimitPrice]: *not available on all exchanges* stop loss for a limit stop loss order
        :param float [params.takeProfitAmount]: *not available on all exchanges* the amount for a take profit
        :param float [params.stopLossAmount]: *not available on all exchanges* the amount for a stop loss
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        $createOrderWithTakeProfitAndStopLossNz< createOrderWithTakeProfitAndStopLoss() is not supported yet)$set_take_profit_and_stop_loss_paramsr   r  r   rQ   	r<   r   r  ry  r  rn  rQ  rR  r   s	            r>   +create_order_with_take_profit_and_stop_lossz4Exchange.create_order_with_take_profit_and_stop_loss  sp     * ::64vW\^hjrtz{88:;**64vufUUU477%ccdd V   AA"A A"c	           
         K   | j                  ||||||||      }| j                  d   r| j                  ||||||       d{   S t        | j                  dz         7 w)rT  &createOrderWithTakeProfitAndStopLossWsNz> createOrderWithTakeProfitAndStopLossWs() is not supported yet)rV  r   r  r   rQ   rW  s	            r>   .create_order_with_take_profit_and_stop_loss_wsz7Exchange.create_order_with_take_profit_and_stop_loss_ws  sq     * ::64vW\^hjrtz{88<=--fdD&%QWXXX477%eeff YrY  ordersc                 :   K   t        | j                  dz         w)Nz$ createOrders() is not supported yetr/  r<   r]  r   s      r>   create_orderszExchange.create_orders  r  r|  c                 :   K   t        | j                  dz         w)Nz" editOrders() is not supported yetr/  r_  s      r>   edit_orderszExchange.edit_orders  r6  r|  c                 :   K   t        | j                  dz         w)Nz% createOrderWs() is not supported yetr/  r  s          r>   r  zExchange.create_order_ws  r{  r|  c                 :   K   t        | j                  dz         w)Nz# cancelOrder() is not supported yetr/  r  s       r>   r~  zExchange.cancel_order  r  r|  c                 :   K   t        | j                  dz         w)Nz% cancelOrderWs() is not supported yetr/  r  s       r>   r  zExchange.cancel_order_ws  r{  r|  idsc                 :   K   t        | j                  dz         w)Nz& cancelOrdersWs() is not supported yetr/  )r<   rf  r   r   s       r>   cancel_orders_wszExchange.cancel_orders_ws  r  r|  c                 :   K   t        | j                  dz         w)Nz' cancelAllOrders() is not supported yetr/  r  s      r>   cancel_all_orderszExchange.cancel_all_orders  r  r|  r   c                 :   K   t        | j                  dz         w)Nz, cancelAllOrdersAfter() is not supported yetr/  )r<   r   r   s      r>   cancel_all_orders_afterz Exchange.cancel_all_orders_after  r  r|  c                 :   K   t        | j                  dz         w)Nz. cancelOrdersForSymbols() is not supported yetr/  r_  s      r>   cancel_orders_for_symbolsz"Exchange.cancel_orders_for_symbols  r  r|  c                 :   K   t        | j                  dz         w)Nz) cancelAllOrdersWs() is not supported yetr/  r  s      r>   cancel_all_orders_wszExchange.cancel_all_orders_ws  r  r|  c                 p   K   | j                  | j                  |d      | j                  |d      |      S wr  )r~  r  r  s      r>   cancel_unified_orderzExchange.cancel_unified_order  s8       !1!1%!>@P@PQVX`@acijjs   46c                    K   | j                   d   r'| j                   d   rt        | j                  dz         t        | j                  dz         w)NfetchOpenOrdersfetchClosedOrdersze fetchOrders() is not supported yet, consider using fetchOpenOrders() and fetchClosedOrders() insteadz# fetchOrders() is not supported yetr-  r~  s        r>   fetch_orderszExchange.fetch_orders  sU     88%&4884G+Htww  *Q   Q  R  R477%JJKKs   AAc                 :   K   t        | j                  dz         w)Nz% fetchOrdersWs() is not supported yetr/  r~  s        r>   fetch_orders_wszExchange.fetch_orders_ws  r{  r|  c                 :   K   t        | j                  dz         w)Nz( fetchOrderTrades() is not supported yetr/  )r<   rQ   r   r   r   r   s         r>   fetch_order_tradeszExchange.fetch_order_trades  r  r|  c                 :   K   t        | j                  dz         w)Nz# watchOrders() is not supported yetr/  r~  s        r>   watch_orderszExchange.watch_orders  r  r|  c                    K   | j                   d   r/| j                  ||||       d {   }| j                  |dd      S t        | j                  dz         7 /w)NfetchOrdersr   rV   z' fetchOpenOrders() is not supported yetr   rv  	filter_byr   rQ   r<   r   r   r   r   r]  s         r>   fetch_open_orderszExchange.fetch_open_orders  sY     88M",,VUE6JJF>>&(F;;477%NNOO K   'AA0Ac                    K   | j                   d   r/| j                  ||||       d {   }| j                  |dd      S t        | j                  dz         7 /w)NfetchOrdersWsr   rV   z) fetchOpenOrdersWs() is not supported yetr   rx  r  r   rQ   r  s         r>   fetch_open_orders_wszExchange.fetch_open_orders_ws  sY     88O$//ufMMF>>&(F;;477%PPQQ Nr  c                    K   | j                   d   r/| j                  ||||       d {   }| j                  |dd      S t        | j                  dz         7 /w)Nr~  r   closedz) fetchClosedOrders() is not supported yetr  r  s         r>   fetch_closed_orderszExchange.fetch_closed_orders  sY     88M",,VUE6JJF>>&(H==477%PPQQ Kr  c                 :   K   t        | j                  dz         w)Nz4 fetchCanceledAndClosedOrders() is not supported yetr/  r~  s        r>    fetch_canceled_and_closed_ordersz)Exchange.fetch_canceled_and_closed_orders  s     477%[[\\r|  c                    K   | j                   d   r/| j                  ||||       d {   }| j                  |dd      S t        | j                  dz         7 /w)Nr  r   r  z+ fetchClosedOrdersWs() is not supported yetr  r  s         r>   fetch_closed_orders_wszExchange.fetch_closed_orders_ws
  sY     88O$//ufMMF>>&(H==477%RRSS Nr  c                 :   K   t        | j                  dz         w)Nz% fetchMyTrades() is not supported yetr/  r~  s        r>   fetch_my_tradeszExchange.fetch_my_trades  r{  r|  c                 :   K   t        | j                  dz         w)Nz+ fetchMyLiquidations() is not supported yetr/  r~  s        r>   fetch_my_liquidationszExchange.fetch_my_liquidations  r  r|  c                 :   K   t        | j                  dz         w)Nz) fetchLiquidations() is not supported yetr/  r~  s        r>   fetch_liquidationszExchange.fetch_liquidations  r  r|  c                 :   K   t        | j                  dz         w)Nz' fetchMyTradesWs() is not supported yetr/  r~  s        r>   fetch_my_trades_wszExchange.fetch_my_trades_ws  r  r|  c                 :   K   t        | j                  dz         w)Nz% watchMyTrades() is not supported yetr/  r~  s        r>   watch_my_tradeszExchange.watch_my_trades  r{  r|  c                 :   K   t        | j                  dz         w)Nz# fetchGreeks() is not supported yetr/  r  s      r>   fetch_greekszExchange.fetch_greeks  r  r|  c                 :   K   t        | j                  dz         w)Nz( fetchOptionChain() is not supported yetr/  r  s      r>   fetch_option_chainzExchange.fetch_option_chain"  r  r|  c                 :   K   t        | j                  dz         w)Nz# fetchOption() is not supported yetr/  r  s      r>   fetch_optionzExchange.fetch_option%  r  r|  c                 :   K   t        | j                  dz         w)Nz) fetchConvertQuote() is not supported yetr/  )r<   r  r   r  r   s        r>   fetch_convert_quotezExchange.fetch_convert_quote(  r  r|  c                 :   K   t        | j                  dz         w)a%  
        fetch history of deposits and withdrawals
        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        z0 fetchDepositsWithdrawals() is not supported yetr/  r  s        r>   fetch_deposits_withdrawalsz#Exchange.fetch_deposits_withdrawals+  s      477%WWXXr|  c                 :   K   t        | j                  dz         w)Nz% fetchDeposits() is not supported yetr/  r~  s        r>   fetch_depositszExchange.fetch_deposits6  r{  r|  c                 :   K   t        | j                  dz         w)Nz( fetchWithdrawals() is not supported yetr/  r~  s        r>   fetch_withdrawalszExchange.fetch_withdrawals9  r  r|  c                 :   K   t        | j                  dz         w)Nz' fetchDepositsWs() is not supported yetr/  r  s        r>   fetch_deposits_wszExchange.fetch_deposits_ws<  r  r|  c                 :   K   t        | j                  dz         w)Nz* fetchWithdrawalsWs() is not supported yetr/  r  s        r>   fetch_withdrawals_wszExchange.fetch_withdrawals_ws?  r  r|  c                 :   K   t        | j                  dz         w)Nz/ fetchFundingRateHistory() is not supported yetr/  r~  s        r>   fetch_funding_rate_historyz#Exchange.fetch_funding_rate_historyB  r  r|  c                 :   K   t        | j                  dz         w)Nz+ fetchFundingHistory() is not supported yetr/  r~  s        r>   fetch_funding_historyzExchange.fetch_funding_historyE  r  r|  c                 :   K   t        | j                  dz         w)Nz% closePosition() is not supported yetr/  )r<   r   ry  r   s       r>   close_positionzExchange.close_positionH  r{  r|  c                 :   K   t        | j                  dz         w)Nz) closeAllPositions() is not supported yetr/  r   s     r>   close_all_positionszExchange.close_all_positionsK  r  r|  c                 :   K   t        | j                  dz         w)Nz( fetchL3OrderBook() is not supported yet)r   rQ   r  s       r>   fetch_l3_order_bookzExchange.fetch_l3_order_bookN  s     #MMNNr|  c                 :  K   | j                   d   rO| j                  |g|       d {   }| j                  ||      }|t        | j                  dz   |z   dz         |S | j                   d   r| j                  |d      }| j                  |d      }| j                  ||       d {   }|| j                  ||      S t        |j                               }| j                  |d      }| j                  ||      S t        | j                  dz         7 7 ow)NfetchDepositAddressesz< fetchDepositAddress() could not find a deposit address for zc, make sure you have created a corresponding deposit address in your wallet on the exchange websitefetchDepositAddressesByNetworknetworkr   z+ fetchDepositAddress() is not supported yet)r   r  r$  r   rQ   r  omitr  r  listkeysr   )	r<   r  r   depositAddressesdepositAddressr  addressStructuresr  keys	            r>   fetch_deposit_addresszExchange.fetch_deposit_addressQ  s.    88+,%)%A%A4&&%QQ!__-=tDN%$TWW/m%mpt%t  x]  &]  ^  ^%%XX67&&vy9GYYvy1F&*&M&MdTZ&[ ["~~&7AA-2245&&tQ/~~&7==tww)VVWW#  R !\s#   &DDB D)D*A.DDc                 J   K   | j                  |d||||       d {   S 7 wr{  r  r<   r   ry  r  rn  r   s         r>   create_limit_orderzExchange.create_limit_orderf  s'     &&vwfeVTTTTru  c                 J   K   | j                  |d||||       d {   S 7 wr{  r  r  s         r>   create_limit_order_wszExchange.create_limit_order_wsi  s(     ))&'4PVWWWWru  c                 J   K   | j                  |d||||       d {   S 7 wNr  r  r  s         r>   create_market_orderzExchange.create_market_orderl  s'     &&vxvufUUUUru  c                 J   K   | j                  |d||||       d {   S 7 wr  r  r  s         r>   create_market_order_wszExchange.create_market_order_wso  s(     ))&(D&%QWXXXXru  c                 J   K   | j                  |dd|||       d {   S 7 wNr   rp  r  r<   r   r  rn  r   s        r>   create_limit_buy_orderzExchange.create_limit_buy_orderr  s'     &&vwvufUUUUru  c                 J   K   | j                  |dd|||       d {   S 7 wr  r  r  s        r>   create_limit_buy_order_wsz"Exchange.create_limit_buy_order_wsu  s(     ))&'5&%QWXXXXru  c                 J   K   | j                  |dd|||       d {   S 7 wNr   rw  r  r  s        r>   create_limit_sell_orderz Exchange.create_limit_sell_orderx  s'     &&vwvVVVVru  c                 J   K   | j                  |dd|||       d {   S 7 wr  r  r  s        r>   create_limit_sell_order_wsz#Exchange.create_limit_sell_order_ws{  s(     ))&'665RXYYYYru  c                 J   K   | j                  |dd|d |       d {   S 7 wNr  rp  r  r  s       r>   create_market_buy_orderz Exchange.create_market_buy_order~  s'     &&vxfUUUUru  c                 J   K   | j                  |dd|d |       d {   S 7 wr  r  r  s       r>   create_market_buy_order_wsz#Exchange.create_market_buy_order_ws  s(     ))&(E64QWXXXXru  c                 J   K   | j                  |dd|d |       d {   S 7 wNr  rw  r  r  s       r>   create_market_sell_orderz!Exchange.create_market_sell_order  s'     &&vxvVVVVru  c                 J   K   | j                  |dd|d |       d {   S 7 wr  r  r  s       r>   create_market_sell_order_wsz$Exchange.create_market_sell_order_ws  s(     ))&(FFDRXYYYYru  c                    K   | j                  |       d {   }| j                         }||z
  | j                  d<   | j                  d   S 7 5w)NtimeDifference)r  r   ro   )r<   r   
serverTimerA  s       r>   load_time_differencezExchange.load_time_difference  sN     ??622
!!#).);%&||,-- 3s   AA6Ac                   K   | j                   d   rZ| j                  |      }|d   st        | j                  dz         | j	                  |g       d {   }| j                  ||      S t        | j                  dz         7 .w)NfetchLeverageTierscontractz: fetchMarketLeverageTiers() supports contract markets onlyz0 fetchMarketLeverageTiers() is not supported yet)r   r  r   rQ   r  r$  r   )r<   r   r   r  tierss        r>   fetch_market_leverage_tiersz$Exchange.fetch_market_leverage_tiers  s~     88()[[(F*%*f fgg33VH==E??5&11tww)[[\\ >s   ABB/Bc                    K   | j                   d   st        | j                  dz         | j                  |ddi      }| j	                  ||||||       d {   S 7 w)NcreatePostOnlyOrderz+ createPostOnlyOrder() is not supported yetpostOnlyTr   r   rQ   r%  r  r<   r   r  ry  r  rn  r   querys           r>   create_post_only_orderzExchange.create_post_only_order  s^     xx-.tww)VVWWFZ$67&&vtT65%PPPP   AAAAc                    K   | j                   d   st        | j                  dz         | j                  |ddi      }| j	                  ||||||       d {   S 7 w)NcreatePostOnlyOrderWsz- createPostOnlyOrderWs() is not supported yetr  Tr   r   rQ   r%  r  r  s           r>   create_post_only_order_wsz"Exchange.create_post_only_order_ws  s^     xx/0tww)XXYYFZ$67))&$feUSSSSr  c                    K   | j                   d   st        | j                  dz         | j                  |ddi      }| j	                  ||||||       d {   S 7 w)NcreateReduceOnlyOrderz- createReduceOnlyOrder() is not supported yet
reduceOnlyTr  r  s           r>   create_reduce_only_orderz!Exchange.create_reduce_only_order  s^     xx/0tww)XXYYF\4$89&&vtT65%PPPPr  c                    K   | j                   d   st        | j                  dz         | j                  |ddi      }| j	                  ||||||       d {   S 7 w)NcreateReduceOnlyOrderWsz/ createReduceOnlyOrderWs() is not supported yetr  Tr  r  s           r>   create_reduce_only_order_wsz$Exchange.create_reduce_only_order_ws  s^     xx12tww)ZZ[[F\4$89))&$feUSSSSr  c                    K   | j                   d   st        | j                  dz         |t        | j                  dz         | j	                  |d|i      }| j                  ||||||       d {   S 7 w)NcreateStopOrderz' createStopOrder() is not supported yetz2 create_stop_order() requires a stopPrice argument	stopPrice)r   r   rQ   r   r%  r  	r<   r   r  ry  r  rn  r5  r   r  s	            r>   create_stop_orderzExchange.create_stop_order  sy     xx)*tww)RRSS#DGG.b$bccF[,$?@&&vtT65%PPPP   A/A81A62A8c                    K   | j                   d   st        | j                  dz         |t        | j                  dz         | j	                  |d|i      }| j                  ||||||       d {   S 7 w)NcreateStopOrderWsz) createStopOrderWs() is not supported yetz2 createStopOrderWs() requires a stopPrice argumentr   )r   r   rQ   r   r%  r  r  s	            r>   create_stop_order_wszExchange.create_stop_order_ws  sy     xx+,tww)TTUU#DGG.b$bccF[,$?@))&$feUSSSSr  c                    K   | j                   d   st        | j                  dz         | j                  |d|i      }| j	                  |d||||       d {   S 7 w)NcreateStopLimitOrderz, createStopLimitOrder() is not supported yetr   r   r  r<   r   ry  r  rn  r5  r   r  s           r>   create_stop_limit_orderz Exchange.create_stop_limit_order  s^     xx./tww)WWXXF[,$?@&&vwfeUSSSSr  c                    K   | j                   d   st        | j                  dz         | j                  |d|i      }| j	                  |d||||       d {   S 7 w)NcreateStopLimitOrderWsz. createStopLimitOrderWs() is not supported yetr   r   r  r	  s           r>   create_stop_limit_order_wsz#Exchange.create_stop_limit_order_ws  s_     xx01tww)YYZZF[,$?@))&'4PUVVVVr  c                    K   | j                   d   st        | j                  dz         | j                  |d|i      }| j	                  |d||d |       d {   S 7 w)NcreateStopMarketOrderz- createStopMarketOrder() is not supported yetr   r  r  r<   r   ry  r  r5  r   r  s          r>   create_stop_market_orderz!Exchange.create_stop_market_order  s^     xx/0tww)XXYYF[,$?@&&vxvtUSSSSr  c                    K   | j                   d   st        | j                  dz         | j                  |d|i      }| j	                  |d||d |       d {   S 7 w)NcreateStopMarketOrderWsz/ createStopMarketOrderWs() is not supported yetr   r  r  r  s          r>   create_stop_market_order_wsz$Exchange.create_stop_market_order_ws  s_     xx12tww)ZZ[[F[,$?@))&(D&$PUVVVVr  c                 :   K   t        | j                  dz         w)Nz' fetchLastPrices() is not supported yetr/  r   s      r>   fetch_last_priceszExchange.fetch_last_prices  r  r|  c                 :   K   t        | j                  dz         w)Nz( fetchTradingFees() is not supported yetr/  r   s     r>   fetch_trading_feeszExchange.fetch_trading_fees  r  r|  c                 :   K   t        | j                  dz         w)Nz* fetchTradingFeesWs() is not supported yetr/  r   s     r>   fetch_trading_fees_wszExchange.fetch_trading_fees_ws  r  r|  c                    K   | j                   d   st        | j                  dz         | j                  |       d {   }| j	                  ||      S 7 w)NfetchTradingFeesz' fetchTradingFee() is not supported yet)r   r   rQ   r  r  )r<   r   r   r  s       r>   fetch_trading_feezExchange.fetch_trading_fee  sQ     xx*+tww)RRSS,,V44~~dF++ 5s   <AAAc                 :   K   t        | j                  dz         w)Nz. fetchConvertCurrencies() is not supported yetr/  r   s     r>   fetch_convert_currenciesz!Exchange.fetch_convert_currencies  r  r|  c                   K   | j                   d   r| j                          d {    | j                  |      }|d   }|d   st        | j                  dz         | j                  |g|       d {   }| j                  ||      }|t        | j                  dz   |z         |S t        | j                  dz         7 7 Ow)NfetchFundingRatesr   r  z2 fetchFundingRate() supports contract markets onlyz) fetchFundingRate() returned no data for z( fetchFundingRate() is not supported yet)	r   r   r  r   rQ   r  r$  r   r   r<   r   r   r  ratesr  s         r>   fetch_funding_ratezExchange.fetch_funding_rate  s     88'(##%%%[[(FH%F*%*^ ^__22F8VDDE??5&1D|"477-X#X[a#abbtww)SSTT &
 E#   #CCAC3C4ACCc                   K   | j                   d   r| j                          d {    | j                  |      }|d   }|d   st        | j                  dz         | j                  |g|       d {   }| j                  ||      }|t        | j                  dz   |z         |S t        | j                  dz         7 7 Ow)NfetchFundingIntervalsr   r  z6 fetchFundingInterval() supports contract markets onlyz- fetchFundingInterval() returned no data for z, fetchFundingInterval() is not supported yet)	r   r   r  r   rQ   r  r$  r   r   r"  s         r>   fetch_funding_intervalzExchange.fetch_funding_interval  s     88+,##%%%[[(FH%F*%*b bcc66xHHE??5&1D|"477-\#\_e#efftww)WWXX &
 Ir%  c           
         K   | j                   d   r1ddi}| j                  ||||| j                  ||             d{   S t        | j                  dz         7 w)aL  
        fetches historical mark price candlestick data containing the open, high, low, and close price of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns float[][]: A list of candles ordered, open, high, low, close, None
        fetchMarkOHLCVrn  markNz& fetchMarkOHLCV() is not supported yetr   r/  r%  r   rQ   r<   r   r   r   r   r   rc  s          r>   fetch_mark_ohlcvzExchange.fetch_mark_ohlcv  sg      88$%G ))&)UE4;;W^`fKghhhtww)QQRR i   <AAAc           
         K   | j                   d   r1ddi}| j                  ||||| j                  ||             d{   S t        | j                  dz         7 w)a>  
        fetches historical index price candlestick data containing the open, high, low, and close price of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
 @returns {} A list of candles ordered, open, high, low, close, None
        fetchIndexOHLCVrn  rs  Nz' fetchIndexOHLCV() is not supported yetr,  r-  s          r>   fetch_index_ohlcvzExchange.fetch_index_ohlcv  sg      88%&G ))&)UE4;;W^`fKghhhtww)RRSS ir/  c           
         K   | j                   d   r1ddi}| j                  ||||| j                  ||             d{   S t        | j                  dz         7 w)aU  
        fetches historical premium index price candlestick data containing the open, high, low, and close price of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns float[][]: A list of candles ordered, open, high, low, close, None
        fetchPremiumIndexOHLCVrn  premiumIndexNz. fetchPremiumIndexOHLCV() is not supported yetr,  r-  s          r>   fetch_premium_index_ohlcvz"Exchange.fetch_premium_index_ohlcv0  sg      88,-G ))&)UE4;;W^`fKghhhtww)YYZZ ir/  c                    K   | j                   d   r| j                  ||||       d{   S t        | j                  dz         7 w)a8  
 @deprecated
        *DEPRECATED* use fetchDepositsWithdrawals instead
        :param str code: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        fetchDepositsWithdrawalsNz) fetchTransactions() is not supported yet)r   r  r   rQ   r  s        r>   fetch_transactionszExchange.fetch_transactionsB  sJ      88./88ueVTTTtww)TTUU Us   'AAAr   maxEntriesPerRequestc                   K   d }| j                  ||dd      \  }}d }	| j                  ||dd      \  }	}d }
| j                  ||dd      \  }
}d }|}| j                  ||d|      \  }}d}g }d}| j                  |d	d
      }| j                  |||      \  }}|
dk(  r|t        | j                  dz         |}||k  r|dz  }	 |
dk(  r||dz
  |d<    t        | |      |d ||       d {   }t        |      }| j                  rYd| j                  |      z   dz   |z   dz   | j                  |      z   }||d| j                  |      z   z  }| j                  |       |dk(  rn!d}| j                  ||      }| j                  |d      }| j                  |dd      }|||k  rn t        | |      ||||       d {   }t        |      }| j                  rYd| j                  |      z   dz   |z   dz   | j                  |      z   }||d| j                  |      z   z  }| j                  |       |dk(  rnMd}| j                  ||      }| j                  ||dz
        }| j                  |d      dz   }|||k\  rn||k  r|}|r| j                  |      }|dk(  rdnd}| j                  ||||      S 7 7 # t        $ r}|dz  }||	kD  r|Y d }~Xd }~ww xY ww)NpaginationCallsr;  re  rS   paginationDirectionbackwardremoveRepeatedr   untilltillforwardzM pagination requires a since argument when paginationDirection set to forwardr4  untilzDynamic pagination call  method  response length z timestamp 	timestamp
fetchOHLCV)ra  safe_integer_2)handle_max_entries_per_request_and_paramsr   rQ   r   rU  r   number_to_stringr   array_concatr$  safe_integerr   #remove_repeated_elements_from_arrayfilter_by_since_limit)r<   r   r   r   r   r   r:  r?  maxCallsre  r=  paginationTimestampremoveRepeatedOptioncallsr   r   rC  r   responseLengthbackwardMessagefirstElementforwardMessagelastr   uniqueResultsr  s                             r>   fetch_paginated_call_dynamicz%Exchange.fetch_paginated_call_dynamicQ  s    88IZ\^_&
!::66<YZ[
F"&*&C&CFFTiku&v#V"-'+'D'DVVUegu'v$f##FHf='+'U'UV\^rtz'{$f9,}'  3B  )B  C  C"'xQJE)&*4 +6*=*Aw%:WT6%:64I]_e%ffH%(]N||*DtG\G\]bGc*cfp*psy*y  }P  +P  SW  Sh  Sh  iw  Sx  +x.:+}t?T?TUh?i/iiO1%*F!..vx@F#'??8Q#?L*.*=*=lKYZ*[')0Cu0L &;WT6%:6CVXlnt%uuH%(]N||)CdF[F[\aFb)beo)orx)x  |O  *O  RV  Rg  Rg  hv  Rw  *w.:*md>S>STg>h.hhN0%*F!..vx@F??8^a5GHD*.*;*;D+*NQR*R')0Cu0LO xX  DDVLMl*a))-sKKQ  g"  v  !J&G 's   CK"'K  ,J;-A9K  &K"(A K  (K")K  J>A9K  ;K"<AK  K"	2K";K  >K   	K	KK"KK"c                 R  K   d }| j                  ||dd      \  }}d}||k  rC	 |r#|dk7  r t        | |      |||||       d {   S  t        | |      ||||       d {   S g S 7 #7 # t        $ r(}	t        |	t              r|	|dz  }||kD  r|	Y d }	~	nd }	~	ww xY w||k  rAw)Nre  rS   r   fetchFundingRateHistoryr4  )ra  r   r   r=  r   )
r<   r   r   r   r   r   r   re  r   r   s
             r>   safe_deterministic_callz Exchange.safe_deterministic_call  s     
!::66<YZ[
F
"
+D!D!6v!6vy%QVX^!___!6v!6vueV!TTT 	 `T a!23G!J&G '	 
"s^   !B' A, A(A, B'	A, !A*"A, %B'(A, *A, ,	B5BB'BB'c                   K   d }| j                  ||dd      \  }}| j                  |||      \  }}| j                         }	g }
| j                  |      dz  }||z  }|	||z  z
  dz
  }|t	        ||      }nt	        |d      }| j                  |dd      }|\t        t        j                  ||z
        |z        }||kD  r3t        | j                  dz   t        |      z   d	z   t        |      z         t        d
|      D ]L  }|||k\  r nC||	k\  r n<|
j                  | j                  ||||||             | j                  ||      dz
  }N t!        j"                  |
  d {   }g }t        d
t%        |            D ]  }| j'                  |||         } | j)                  |      }|dk(  rd
nd}| j+                  ||||      S 7 cw)Nr<  r;  r   r4  l   82>rC  rA  z the number of required calls is greater than the max number of calls allowed, either increase the paginationCalls or decrease the since-until gap. Current paginationCalls limit is z required calls is r   rG  rF  )ra  rI  r   parse_timeframemaxrH  intmathceilr   rQ   rn  r  rE  r\  sumrj   gatherrU  rK  rM  rN  )r<   r   r   r   r   r   r   r:  rO  currenttaskstimestepcurrentSincerC  requiredCallsr  resultsr   rX  r  s                        r>   "fetch_paginated_call_deterministicz+Exchange.fetch_paginated_call_deterministic  s7    88IZ\^_&'+'U'UV\^rtz'{$f##%##I.5**(T/2Q6|U3L|];L##FGV<		55= :T ABMx'   ,c  "c  fi  jr  fs  "s  vK  "K  NQ  R_  N`  "`  a  aq(# 	<A!(=w&LL55fflThjsu{|}88L$7!;L	<  ..q#g,' 	;A&&vwqz:F	;@@Hl*a))-sKK /s   E"G
$G%A$G
c
                   K   d }
| j                  ||dd      \  }
}d }| j                  ||dd      \  }}| j                  ||	|      \  }	}d }d}d}g }| j                  |d      }| j                  |d      }||
k  r	 ||| j	                  |      |z   }|||<   d }|dk(  r t        | |      |       d {   }ng|dk(  s|d	k(  r t        | |      ||       d {   }nA|d
k(  r t        | |      ||||	|       d {   }n t        | |      |||	|       d {   }d}t        |      }| j                  rE|dn|}|dz   }dt        |      z   dz   |z   dz   t        |      z   dz   |z   }| j                  |       |dk(  rn| j                  ||      }| j                  ||dz
        }d }t        d|      D ]F  }||z
  dz
  }| j                  ||      }| j                  |d      }| j                  ||      }|D|} n |n&| j                  |d      }|||k  rn|dz  }||
k  r| j!                  |      }|dk(  rdnd}| j#                  ||||      S 7 7 7 b7 G# t        $ r}|dz  }||kD  r|Y d }~`d }~ww xY ww)Nr<  r;  re  rS   r   r   fetchAccountsgetLeverageTiersPaginatedfetchPositionsfetchOpenInterestHistoryr   r4  zCursor pagination call rD  rE  z cursor inforF  rG  )ra  rI  r  r  parse_to_intr   rU  r   rn  r   rK  r  r  r$  rL  r   sort_cursor_paginated_resultrN  ) r<   r   r   r   r   r   cursorReceived
cursorSentcursorIncrementr:  rO  re  cursorValuer  r   r   r   r   rS  cursorString	iterationcursorMessagerW  jrs  entryrr  cursorlastTimestampr   sortedr  s                                    r>   fetch_paginated_call_cursorz$Exchange.fetch_paginated_call_cursor  sD    88IZ\^_&
!::66<YZ[
F'+'U'UV\^rtz'{$f$$V[9	6;/(l+*&2&*&7&7&D&V)4F:&_,%:WT6%:6%BBH::fHX>X%:WT6%:66%JJH99%:WT6%:69eUikq%rrH%:WT6%:65J^`f%ggH!$X<<*5*=2KL!"QI$=I$NQ[$[^d$dgz$z  ~A  BP  ~Q  %Q  T^  %^  am  %mMHH]+!Q&**68<~~h0BC"q.1 A*Q.2E NN8U;E>>%8D!__T>BF)&, & $ 1 1$ D ,1F
 FA[ (l\ 226:l*a))&%DDQ  CJrg6  !J&G 's   A;J>9I) 7I8%I) I #I) I#I) I& A'I) JA8I) I) J	I) "J/.JI)  I) #I) &I) )	J2J>JJJc                   K   d }| j                  ||dd      \  }}d }	| j                  ||dd      \  }	}| j                  |||      \  }}d}
d}g }|
|k  r	 |
dz   ||<    t        | |      ||||       d {   }d}t        |      }| j                  r9|
t        d      z   }d|z   dz   |z   d	z   t        |      z   }| j                  |       |dk(  rn| j                  ||      }|
dz  }
|
|k  r| j                  |      }|d
k(  rdnd}| j                  ||||      S 7 # t        $ r}|dz  }||	kD  r|Y d }~Ud }~ww xY ww)Nr<  r;  re  rS   r   r4  zIncremental pagination call rD  rE  rG  rF  )ra  rI  r   rU  r   rn  r   rK  r   rt  rN  )r<   r   r   r   r   r   pageKeyr:  rO  re  r  r   r   r   rS  rz  incrementalMessager   r  r  s                       r>    fetch_paginated_call_incrementalz)Exchange.fetch_paginated_call_incremental  s    88IZ\^_&
!::66<YZ[
F'+'U'UV\^rtz'{$f(l"#a%w!6v!6vuFZ\b!cc!$X<<!"SVI)G))SV`)`ci)il)  CF  GU  CV  *V&HH/0!Q&**68<
 FA# (l$ 226:l*a))&%DD# d  !J&G 'sU   AE D! 7D8AD! ED! &
E1.ED! !	E *D;6E;E  Ec                    K   | j                   d   r| j                  |g|||       d{   }|S t        | j                  dz         7 w)  
        fetches the history of margin added or reduced from contract isolated positions
        :param str [symbol]: unified market symbol
        :param int [since]: timestamp in ms of the position
        :param int [limit]: the maximum amount of candles to fetch, default=1000
        :param dict params: extra parameters specific to the exchange api endpoint
        :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
        fetchPositionsHistoryNz, fetchPositionHistory() is not supported yet)r   fetch_positions_historyr   rQ   )r<   r   r   r   r   	positionss         r>   fetch_position_historyzExchange.fetch_position_history&  sR      88+,"::F8UESYZZItww)WWXX [s   (AA	Ac                 :   K   t        | j                  dz         w)r  z- fetchPositionsHistory() is not supported yetr/  r  s        r>   r  z Exchange.fetch_positions_history5  s      477%TTUUr|  c                 :   K   t        | j                  dz         w)a*  
        fetches a transfer
        :param str id: transfer id
        :param [str] code: unified currency code
        :param dict params: extra parameters specific to the exchange api endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        z% fetchTransfer() is not supported yetr/  r  s       r>   fetch_transferzExchange.fetch_transfer@  s      477%LLMMr|  c                 :   K   t        | j                  dz         w)a  
        fetches a transfer
        :param str id: transfer id
        :param int [since]: timestamp in ms of the earliest transfer to fetch
        :param int [limit]: the maximum amount of transfers to fetch
        :param dict params: extra parameters specific to the exchange api endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        z& fetchTransfers() is not supported yetr/  r  s        r>   fetch_transferszExchange.fetch_transfersJ  s      477%MMNNr|  rA   )r   NN)F)NNN)NN($  __name__
__module____qualname__synchronousr&  r  
newUpdatesr  r|   r   r9   rC   rH   rJ   rL   rR   rh   ri   rW   r]   rV   rY   ry   rz   r   r   r   r   r   r   r   r   r   r{   r  r  staticmethodr   r   r   r  r  r  r*  r-  r   rP  rV  r#  r!  r"  rx   ro  rx  rz  rn  r   r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  ri  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  floatr  r  r  r   r  r  r  boolr  r  r  r   r  r  r   r  r  r  r  r  r  r  r  r  r  r   r"  r$  r'  r)  r/  r3  r5  rJ  rQ  rV  r   rf  rc  rm  rt  rx  r   rr  r   r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r+  r/  r4  r:  r>  rD  rG  rM  rP  rX  r\  r   r`  rb  r  r~  r  rh  rj  rl  r   rn  rp  rr  rv  rx  rz  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  r  r$  r(  r.  r2  r6  r9  rY  r\  rl  r  r  r  r  r  r  __classcell__)r=   s   @r>   r   r   ;   s}!   KI DJGO13 
' 
'!H*l 6!		I*/0-m ^5 05R 
5 ).b %N  *, + -/  37d$WY P 04B 98
       #%D * +-D 1 +-D 1!2W%N)V
)-& HLTV S2X +- N <@d[] L LS L L ?CQU^` NC N N3 N BFTXac Rs R3 Rc R
 UYgktv \DI \c \ad \ EIW[df T# Tc TQT T
 X\jnwy ^tCy ^QT ^dg ^ <@d[] L LS L L 9; NC N OSaenp Vd3i V V[^ V LN Xc X RVdhqs Xc X3 X^a X OSaenp Vd3i V V[^ V aesw  AC U$tCy/ UZ] Ump U ^` WT$s)_ W SW_a Y$s) YC Y PR [T#Y [ >B" V7 V @DB OS O O CGr Q QC Q ;= Tc T ;?r Q Q >B" 	 @DB OS O O =? Q Q ') J =A S' S 57 V 8: Y =A S' S <@ R R @DB VW V <> Qs Q DF Rc R PR ?T#Y ? ac I3 I IC ITW I JNVX I3 I I I >@ U U ?C2 L3 L L 8: R3 R 8<B OW O CGr Pd PC P CE Js JE J FH M# Mu M CE Js JE J JNVX T3 T3 T BFX\ko  C  LN [3 [RU [eh [x{ [ CGTXgkz~  HJ 
]C 
]c 
]ad 
]tw 
] DHPR N NS N JL _S _ HLZ^mqz| Y YTW Ygj Y =? R R =A S' S $& G 24 T HJ KC K K IK MS M% M Y[ P# PS P% P JL Nc N5 N Z\ Q3 Qc Q5 Q KOWY B BU BC B JNVX s E 3  8<$]ajl U UC UWZ U ;?T`dmo v3 vs vZ] v 8<$]ajl K KC KWZ K+,Z CGr  C  <@VX   -5U2^bpt} c X[ jm : .6eB_cqu  A Ss SY\ Skn S */r 	 \`hj US U# Uu UUX U ]aik Vc V3 V VVY V imuw W Wc W WTY Wbe W fjx|  FH R3 R R9 RI R_b Rru R im{  IK Uc U3 Ui Uy Ube Uux U 8: N3 N ;= Pc P 26b N3 N 8<$]ajl OW OC OWZ O CGUYhluw I Is Ibe I DF Xs X GI X# X 8<B OW O ;?r O O =A S' S 8<B NW N 7;$]apt} T TC TWZ Tjm T .2SW`b Ls L# LS L =A Q3 Qc Q *, M -/ O *, M 8:  /1 @ /1 @ 02 A )+ L =? A A
 =A U' U BFb Yw Y BD +S + ?A #  DF s  68 P P :< TS T 9; RC R 68 L L 6:" M7 M :>b Pw P 9=R Mg M :>DY[ Pw Pc P 8<B NW N 6:" M7 M 9=R Og O 8<B KC K K ;?r Ms MC M ?C2 3   79 p mqy{ L LI LY LX] Lfi L ]aik SS SC S SVY S >B" RC Rs R =Atbfoq Yc Y Y\_ Y 7;2 R R }A  RV  mq  z| Z ZI ZU^ Zhm Zvy Z, @D  UY  pt  } \C \y \Xa \kp \y| \, ~B  TX  os  |~ [# [Y [V_ [in [wz [, AE  W[  rv  A ]S ]	 ]Yb ]lq ]z} ], eg Z# ZY ZV[ Z XZ 
]c 
] 
] Y[ 
^s 
^% 
^ hj \S \	 \Y^ \ uy  OS  \^ S SI SY S`e Snq S  IL S& x|  RV  _a UC Uy UPY Uch Uqt U  LO U& w{  RV  _a T3 Ti Ty Tbg Tps T  LO T& z~  UY  bd Vc V VR[ Vej Vsv V  OR V& y}  VZ  ce VS V	 VQZ Vdi Vru V  PS V& |@  Y]  fh X X9 XT] Xgl Xux X  SV X& LP  dh  z~  GI e eS\ edm ew| e  FI e  ^a e  tw e4 OS  gk  }A  JL g3 gV_ ggp gz g  IL g  ad g  wz g4 FH M$|*< M DF K\(: K pt|~ NC Ny N	 N[` Nil N 9=R LS L# L <@ N NS N DHPR O$s) OS O 59 Pc P BD US U Y[ Wd;N6O W 8<B R R 8: k 04$UYbd L LC Ls L
 37TX\eg NC Ns NRU N ?CQUdhqs Q3 Q Q3 Q^a Q 04$UYbd L LC Ls L 59tZ^gi Pc P PTW P 8<$]ajl R RC RWZ R 7;\`ik R R3 RVY R DHVZimvx ]S ]PS ]cf ] :>D_cln T3 Tc TY\ T 37TX\eg NC Ns NRU N 9=4^bkm T# TS TX[ T BFTXac Rs R3 Rc R 6:[_hj Ps P# PUX P 37TX\eg NC Ns NRU N 68 L L :< QS Q 68 L L SW_a R# Rs RC R <@daenp 	YS 	Y 	Y[^ 	Y 26DW[df N3 Nc NQT N 59tZ^gi Qc Q QTW Q 37TX\eg PC Ps PRU P 6:[_hj Ss S# SUX S >BPTcgpr Xs X# X]` X 9=4^bkm T# TS TX[ T CGr N3 Ni N 02 R CGr O OC O =? X X* jl Us U) UU U[` U mo X# XY XPU X^c X cgoq V V9 Ve V\_ V fjrt Y3 Yi YQV Y_b Y ]_ V3 V Ve V `b Yc Y5 YQV Y ^` WC W Wu W ac Zs ZE ZRW Z PR VC V V SU Ys YE Y QS WS W% W TV Z ZU Z 13 . EG ] ] w{  DF Q3 Qi Qy Qbg Qps Q z~  GI Tc T TR[ Tej Tsv T y}  FH QS Q	 QQZ Qdi Qru Q |@  IK T T9 TT] Tgl Tux T rv  LP  Y[ Qc Q Q) Q]b Qkn Q  FI Q uy  OS  \^ T TI TY T`e Tnq T  IL T DF TC Ty TRW T`e Tuz T GI Ws W) WUZ Wch Wx} W wy TS T	 TSX Thm T z| W W9 WV[ Wkp W :>b Pw P /1 Q 24 S ;= ,c , 57 W <> Us U  @B Y3 Y  8<$]ajl SC SWZ S$ >BPTcgpr Tc T# T]` T$ FJX\koxz [c [RU [eh [$ 48dY]fh VS V VSV V MQ_crv  @B  `d  uy CL CLc CLY\ CLlo CL  Z] CLJ HLZ^mq  EI  RT C  TW gj   B $ SWeix|  PT  ]_  vz Ls LC L_b Lru L  JM LB LPW[cgpr  DH  UY  ko  FJ <E <ES <E| QU\`hluw  BF  ]a ES E# E> FJX\eg Y3 Ys YRU Y @DRVeirt 	VW 	VC 	V_b 	V 9=R Ns N# N 154VZce 	O# 	OS 	OPS 	O 	Or?   );__version__rj   concurrent.futuresr   r   r5   rr   rb   rh   r   ra  typingr   r   ccxt.base.typesr   r   r   r   !ccxt.async_support.base.throttlerr	   ccxt.base.errorsr
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ccxt.base.exchanger   r&   r   $ccxt.async_support.base.ws.functionsr   r   r   )ccxt.async_support.base.ws.aiohttp_clientr    !ccxt.async_support.base.ws.futurer!   %ccxt.async_support.base.ws.order_bookr"   r#   r$   aiohttp_socksr%   ImportError__all__rX  r?   r>   <module>r     s   
       
 
    2 2 8 P  P  P  P d d K L K C 4 _ _
, X O| X O  Ns   B* *B43B4