
    !:hA                    D   d dl mZ d dlmZ d dl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mZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lm Z  d dlm!Z! d dlm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dl)m*Z*  G d dee      Z+y)    )Exchange)ImplicitAPIN)AnyBalances
CurrenciesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidOrder)NotSupported)RateLimitExceeded)ExchangeNotAvailable)InvalidNonce)	TICK_SIZEc                   "    e Zd Zdef fdZd Zi fdefdZi fdee	   fdZ
i fdZi fdefdZi fdefdZd	i fd
ededefdZdBdede	defdZi fd
edefdZd	i fdedefdZdBdede	defdZd	d	i fd
edededee   fdZi fd
edefdZi fd
efdZi fd
efdZ d	d	d	i fd
e!dedefdZ"de!fdZ#d Z$de!fdZ%dBd ede	de&fd!Z'd	d	d	i fd
e!dededee&   fd"Z(d	d	d	i fd
e!dededee&   fd#Z)d	i fd$ed
e!fd%Z*d	i fd
ed&e+d'e,d(e-d)e.f
d*Z/d	i fd$ed
e!fd+Z0d	i fd
e!fd,Z1d	d	d	i fd-e!dedefd.Z2dBd/ed0e3de4fd1Z5de!fd2Z6d3 Z7d	d	d	i fd-e!dededee8   fd4Z9i fd-ed(e-d5ed6ede8f
d7Z:dBd8ed0e3de8fd9Z;de!de!fd:Z<dCd;Z=d-e>d<ed=ed>ed?ed@efdAZ? xZ@S )Dlatokenreturnc           !         | j                  t        t        |          dddgddi dd ddd	d
dd
dd
dd
dddddd
dd
dddd
dddd
dddddd
i dd
dd
dd
dddd
dd
dd
d dd!d
d"d
d#d
d$d
d%d
d&d
d'd
d(d
d)d
i d*d
d+dd,dd-dd.dd/dd0dd1d
d2d
d3d
d4d
d5d
d6d
d7d
d8dd9dd:dddd
d;d
ddd<d=d>d?id@d?gdAdBdCdDi dEdFdGdFdHdFdIdFdJdFdKdFdLdFdMdFdNdFdOdFdPdFdQdFdRdFdSdFdTdFdUdFii dVdFdWdFdXdFdYdFdZdFd[dFd\dFd]dFd^dFd_dFd`dFdadFdbdFdcdFdddFdedFdfdFdgdFii dhdFdidFdjdFdkdFdldFdmdFdndFdodFdpdFdqdFdrdFdsdFdtdFdudFdvdFdwdFdxdFdydFidzd{t        d|dDd
d| j                  d}      | j                  d}      d~ii ddddddddddddddddddddddddddddddddi dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        dt        t        t        t        t        t        dt        t        t        t        t         t         t         t        ddddddddddddidd
d
dd d
d
d
d ddd
d
dd
d
d
d
dd
d
dd d
ddd d
dd
dd
d
dd
d d
d
ddd d
dddFd dd
d
dd d	d d dÜd d dÜdĜdŜ      S )Nr(   LatokenKYv2  CORSspotTmarginFswapfutureoptioncancelAllOrderscancelOrdercloseAllPositionsclosePositioncreateOrdercreatePostOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsWithdrawalsfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchMarginModefetchMarketsfetchMyTradesfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchTickerfetchTickers	fetchTimeemulated)fetchTradesfetchTradingFeefetchTradingFeesfetchTransactionsfetchTransferfetchTransferstransferzchttps://user-images.githubusercontent.com/1294454/61511972-24c39f00-aa01-11e9-9f7c-471f1d6e5214.jpgrestzhttps://api.latoken.comzhttps://latoken.comzhttps://latoken.com/feesz%https://latoken.com/invite?r=mvgp2djk)logoapiwwwdocfeesreferralgetzbook/{currency}/{quote}   z
chart/weekzchart/week/{currency}/{quote}currencyzcurrency/availablezcurrency/quoteszcurrency/{currency}pairzpair/availabletickerzticker/{base}/{quote}timez trade/history/{currency}/{quote}ztrade/fee/{currency}/{quote}ztrade/feeLevelsztransaction/bindingszauth/accountz'auth/account/currency/{currency}/{type}z
auth/orderzauth/order/getOrder/{id}z"auth/order/pair/{currency}/{quote}z)auth/order/pair/{currency}/{quote}/activezauth/stopOrderzauth/stopOrder/getOrder/{id}z&auth/stopOrder/pair/{currency}/{quote}z-auth/stopOrder/pair/{currency}/{quote}/activez
auth/tradez"auth/trade/pair/{currency}/{quote}z!auth/trade/fee/{currency}/{quote}zauth/transactionzauth/transaction/bindingsz$auth/transaction/bindings/{currency}zauth/transaction/{id}zauth/transferzauth/order/cancelzauth/order/cancelAllz'auth/order/cancelAll/{currency}/{quote}zauth/order/placezauth/spot/depositzauth/spot/withdrawzauth/stopOrder/cancelzauth/stopOrder/cancelAllz+auth/stopOrder/cancelAll/{currency}/{quote}zauth/stopOrder/placezauth/transaction/depositAddresszauth/transaction/withdrawz auth/transaction/withdraw/cancelz!auth/transaction/withdraw/confirmz$auth/transaction/withdraw/resendCodezauth/transfer/emailzauth/transfer/idzauth/transfer/phone)rq   post)publicprivatetradingz0.0049)feeSide	tierBased
percentagemakertakerBUXBuxcoinCBTzCommunity Business TokenCTCCyberTronchainDMDzDiamond CoinFRENFrenchieGDXGoldenXGECzGeco OneGEMNFTmallGMTz	GMT TokenIMCIMCoinMTMonarchTPAYz	Tetra PayTRADEzSmart Trade CoinTSLzTreasure SLUNO
UnobtaniumWARzWarrior TokenINTERNAL_ERRORSERVICE_UNAVAILABLENOT_AUTHORIZED	FORBIDDENBAD_REQUEST	NOT_FOUNDACCESS_DENIEDREQUEST_REJECTEDHTTP_MEDIA_TYPE_NOT_SUPPORTEDMEDIA_TYPE_NOT_ACCEPTABLEMETHOD_ARGUMENT_NOT_VALIDVALIDATION_ERRORACCOUNT_EXPIREDBAD_CREDENTIALSCOOKIE_THEFTCREDENTIALS_EXPIREDINSUFFICIENT_AUTHENTICATION)UNKNOWN_LOCATIONTOO_MANY_REQUESTSINSUFFICIENT_FUNDSORDER_VALIDATION	BAD_TICKS)z$invalid API key, signature or digestzThe API key was revokedzrequest expired or badzFor input stringz!Unable to resolve currency by tagzCan't find currency with tagz7Unable to place order because pair is in inactive statezAPI keys are not available for)exactbroadACCOUNT_TYPE_WALLETACCOUNT_TYPE_SPOT)walletfundingr0   r   )r   r   methodfetchPrivateTradingFee)defaultTypetypesaccountsrd   )IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingleveragemarketBuyByCostmarketBuyRequiresPriceicebergi )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   )	sandboxr9   createOrdersrS   rU   rT   rW   fetchClosedOrders
fetchOHLCV)linearinverse)r0   r2   r3   )idname	countriesversion	rateLimithasurlsrl   precisionModero   commonCurrencies
exceptionsoptionsfeatures)deep_extendsuperr(   describer&   parse_numberr   r$   r   r   r   r   r#   r    r!   r%   r   )self	__class__s    F/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/latoken.pyr   zlatoken.describe   s   gt = ?;;; %; 	;
 %; %; "4; t; $U;  ; t; &u; '; (; "4;  !;" +E#;$ )%%;& '';( ();* "4+;, &u-;. (/;0 1%1;2 +D3;4 +E5;6 &u7;8 '9;: (;;< #E=;> *5?;@ $UA;B *5C;D +EE;F "5G;H I;J  K;L "4M;N dO;P !$Q;R tS;T  U;V 'W;X $UY;Z !%[;\ *5];^ (_;` %ea;b tc;d e;f Tg;h  $#'$)%/!&"& u;z ~5 -- 3C  11$a 8 #A	
 -a *1 .q  )! !! 0  ;A 7 *1  /!*&A1 %a 3A	
 =a DQ )! 7 A! H %a =a <Q +A 4Q  ?!" 0#$ (%(+Q. B1 +A	
 ,Q -a 0 3A Fq / :1 4Q ;A <Q ?  .q!" +A#$ .q%+)+?@ '$!&"&!..x8!..x8!y!1! '! ~	!
 
! y! z! y! {! x! i! ! +! }! |!  !!&$m)+? %&9  !1	
 ":   $%5 ' 4Z 0 0 '
 &'7 &': #$7  *+;!" 23F#$ )<):*;(4!--2 =P/B.:(29B4=OX6F	3#J  &34/ ,4)/
 6$"  %&+(,,0,1).+06:#'#'"'#(	( #(/4$)$)+/27#()$, %)&+!%$*%)*/& ',#'$)*/	# ',!%#($)*.( $(&+!%$*,-%)#'$)*/	* #'q9v ##
 ##C{aB
 a a	    c                 B    | j                         | j                  d   z
  S )NtimeDifference)millisecondsr   )r   s    r   noncezlatoken.nonceA  s       "T\\2B%CCCr   c                 H    | j                  |      }| j                  |d      S )a[  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://api.latoken.com/doc/v2/#tag/Time/operation/currentTime

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        
serverTime)publicGetTimesafe_integer)r   paramsresponses      r   
fetch_timezlatoken.fetch_timeD  s)     %%f-   <88r   c                 `   | j                  |      }| j                  |      }| j                  | j                  dd      r| j	                          | j                  |d      }g }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  ||	      }| j                  ||
      }|f|i| j                  | j                  |d            }| j                  | j                  |d            }|j                         }| j                  |      }| j                  |d	      }|j                  i d|d
|dz   |z   d|d|ddd|	d|
ddddddddddddddd|dk(  dddddddddd| j                  |d      | j                  |d      dddd | j                  |d!      dd ddd | j                  |d"|z         | j                  |d#|z         d d$| j                  |d%      |d&
        |S )'a"  
        retrieves data on all markets for latoken

        https://api.latoken.com/doc/v2/#tag/Pair/operation/getActivePairs

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        adjustForTimeDifferenceTr   r   baseCurrencyquoteCurrencyNtagstatussymbol/basequotesettlebaseIdquoteIdsettleIdtyper0   r1   Fr2   r3   r4   activePAIR_STATUS_ACTIVEcontractr   quantityTick	priceTick)amountpriceminmaxminOrderQuantityminOrderCostmaxOrderCost)r   r  r  costcreated)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitsr  info)fetch_currencies_from_cachepublicGetPair
safe_valuer   load_time_differenceindex_byrangelensafe_stringsafe_currency_codelower
capitalizeappendsafe_numberr   )r   r   
currenciesr   currenciesByIdresultimarketr   r  r  r   r   r   r   lowercaseQuotecapitalizedQuoter   s                     r   fetch_marketszlatoken.fetch_marketsU  s    55f=
B %%f-* ??4<<)BDI%%'z48q#h-( >	Aa[F!!&$/B%%fn=F&&v?G??>6BL OONGDM'M,E..t/?/?e/TU//0@0@PU0VW!&#'??>#B ))&(; 0"0dSj500 D0 U	0
 d0 f0 w0 0 F0 D0 e0 E0 e0 e0 v)==0  !0" d#0$  $$("&*""&"&"2"26>"J!%!1!1&+!F" $(#'%
 $(#3#3F<N#O#'#
 $(#'"
 $(#3#3FNM]<]#^#'#3#3FNM]<]#^!$  $00C"_0 0>	~ r   c                 ^   | j                  | j                  di       }| j                  |d      }| j                  |dd      }| j                         }|||z
  |kD  r3| j	                  |      }| j                  |||d      | j                  d<   | j                  | j                  d   d      S )NrC   	timestampexpiresr.   )r   r3  r   )r  r   r   r   publicGetCurrencyextend)r   r   r   r3  r4  nowr   s          r   r  z#latoken.fetch_currencies_from_cache  s     //$,,0A2F%%g{;	##GY=!C)Ow#>--f5H.2kk'$ D /DLL*+ t||,=>
KKr   c                 8   | j                  |      }i }t        dt        |            D ]  }||   }| j                  |d      }| j                  |d      }| j	                  |      }| j                  |d      }	| j                  |d      }
d}|
dk(  rd}nd	}| j                  |d
      }|dk(  }| j                  |d      }||||||dd|	| j                  | j                  | j                  |d                  | j                  |d      ddddddi d||<    |S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r   r   r   feer  NCURRENCY_TYPE_ALTERNATIVEothercryptor   CURRENCY_STATUS_ACTIVEr   decimalsminTransferAmountr  )r  withdraw)r   coder  r   r  r  depositr@  r9  r  r  networks)r  r"  r#  r$  r%  r)  r   parse_precision)r   r   r   r,  r-  rs   r   r   rA  r9  currencyTyper  r   r  r   s                  r   fetch_currencieszlatoken.fetch_currencies  sh    33F;B q#h-( &	A{H!!(D1B""8U3C**3/D""8U3C++Hf=LD::  %%h9F 88F##Hf5D   !..t/C/CDDTDTU]_iDj/kl  $//:MN#
  $#!	 +F4L!&	N r   c                     | j                          | j                  |      }|ddd}d}| j                  | j                  ddd      }| j	                  |d|      }| j                  | j                  di       }| j	                  |||      }| j                  |d      }	| j                  |	|g       }
t        dt        |
            D ]  }|
|   }| j	                  |d	      }| j                  |d
      }|||}nt        ||      }| j                  |      }| j                         }| j	                  |d      |d<   | j	                  |d      |d<   |||<    ||d
<   | j                  |      |d<   | j                  |      S )as  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://api.latoken.com/doc/v2/#tag/Account/operation/getBalancesByUser

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        N)r  r3  datetimer>   r   r0   r  r   r   rs   r3  	availablefreeblockedusedrH  )load_marketsprivateGetAuthAccountsafe_string_2r   r$  r  group_byr"  r#  r   r  r%  accountiso8601safe_balance)r   r   r   r,  maxTimestampr   r  r   accountTypebalancesByTypebalancesr-  balance
currencyIdr3  rA  rQ  s                    r   fetch_balancezlatoken.fetch_balance9  s    	--f50 

 ((~}V\]<gr:&&udD9x8??>;Cq#h-( 	#AqkG))':>J))';?I$'#,L#&|Y#?L**:6DllnG"..wDGFO"..w	BGFO"F4L	# +{!\\,7z  ((r   Nr   r   c           	          | j                          | j                  |      }|d   |d   d}|||d<   | j                  | j                  ||            }| j	                  ||ddddd	      S )
aC  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://api.latoken.com/doc/v2/#tag/Order-Book/operation/getOrderBook

        :param str symbol: unified symbol of the market to fetch the order book for
        :param int [limit]: the maximum amount of order book entries to return
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
        r  r  rs   r   Nr   bidaskr  quantity)rM  r.  publicGetBookCurrencyQuoter6  parse_order_book)r   r   r   r   r.  requestr   s          r   fetch_order_bookzlatoken.fetch_order_bookx  s     	V$x(I&
 $GG224;;w3OP" $$XvtUE7T^__r   ru   r.  c                 "   | j                  |d      }| j                  |d      }| j                  |d      }| j                  i d| j                  ||      d|d| j	                  |      dd dd d| j                  |d	      d
| j                  |d      d| j                  |d      d| j                  |d      dd dd d|d|dd dd d| j                  |d      dd | j                  |d      | j                  |d      |d|      S )Nr   	lastPriceupdateTimestampr3  rH  lowhighr]  bestBid	bidVolumebestBidQuantityr^  bestAsk	askVolumebestAskQuantityvwapopencloselastpreviousClosechanger}   	change24haverage	amount24h	volume24h)
baseVolumequoteVolumer  )r$  safe_integer_omit_zerosafe_tickersafe_symbolrR  )r   ru   r.  marketIdrr  r3  s         r   parse_tickerzlatoken.parse_ticker  s   * ##FH54//8IJ	 !
d&&x8!
!
 Y/!
 4	!

 D!
 4##FI6!
 ))&2CD!
 4##FI6!
 ))&2CD!
 D!
 D!
 T!
 D!
 T!
 d!
  $**6;?!!
" t#!
$ **6;?++FK@)!
* + 	r   c                     | j                          | j                  |      }|d   |d   d}| j                  | j                  ||            }| j	                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://api.latoken.com/doc/v2/#tag/Ticker/operation/getTicker

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r  r  )r   r   )rM  r.  publicGetTickerBaseQuoter6  r  r   r   r   r.  rb  r   s         r   fetch_tickerzlatoken.fetch_ticker  sg     	V$8$I&
 00Wf1MN*   622r   symbolsc                 h    | j                          | j                  |      }| j                  ||      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://api.latoken.com/doc/v2/#tag/Ticker/operation/getAllTickers

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        )rM  publicGetTickerparse_tickers)r   r  r   r   s       r   fetch_tickerszlatoken.fetch_tickers  s5     	''/. !!(G44r   tradec                    d }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	|	|rdnd}	n|	d	k(  rd}	n|	d
k(  rd}	|	dk(  }
|r|
rdnd}| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }|dz   |z   }|| j                  v r| j                  |      }| j                  |d      }| j                  |d      }| j                  |d      }d }|||d}| j                  ||| j                  |      ||||||	||||d|      S )Nr3  r  r_  r  
makerBuyer	directionsellbuyTRADE_DIRECTION_BUYTRADE_DIRECTION_SELLr~   r   r   r   r   r   orderr9  )r  rs   )r  r3  rH  r   r   r  r  takerOrMakersider  r  r  r9  )r   r$  r  r%  marketsr.  
safe_traderR  )r   r  r.  r  r3  priceStringamountString
costStringr  r  isBuyr  r  r  r   r   r   r   orderIdfeeCostr9  s                        r   parse_tradezlatoken.parse_trade  s   B %%e[9	&&ug6''z:%%eV4
__UL9
{3<'6UD,,//#-%wg!!%8""5/:&&v.''0e#T\\![[(FeT*""5'2""5%0!C "Y/( " 
  	r   sincec                     | j                          | j                  |      }|d   |d   d}|t        |d      |d<   | j                  | j	                  ||            }| j                  ||||      S )a+  
        get the list of most recent trades for a particular symbol

        https://api.latoken.com/doc/v2/#tag/Trade/operation/getTradesByPair

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r  r  r\  d   r   )rM  r.  r  "publicGetTradeHistoryCurrencyQuoter6  parse_trades)r   r   r  r   r   r.  rb  r   s           r   fetch_tradeszlatoken.fetch_tradesi  s     	V$x(I&
 "5#GG::4;;wPV;WX   65%@@r   c                 8   | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j                  |d      }|dk(  r| j	                  ||      S |dk(  r| j                  ||      S t        | j                  dz         )a  
        fetch the trading fees for a market

        https://api.latoken.com/doc/v2/#tag/Trade/operation/getFeeByPair
        https://api.latoken.com/doc/v2/#tag/Trade/operation/getAuthFeeByPair

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        rd   r   r   fetchPublicTradingFeez not support self method)r  r   r$  omitfetch_private_trading_feefetch_public_trading_feer"   r   )r   r   r   r   defaultMethodr   s         r   fetch_trading_feezlatoken.fetch_trading_fee  s     //$,,0A2F(((<TU!!&(MB68,--11&&AA..00@@tww)CCDDr   c                     | j                          | j                  |      }|d   |d   d}| j                  | j                  ||            }||d   | j	                  |d      | j	                  |d      d d dS Nr  r  r\  r   makerFeetakerFee)r  r   r~   r   r}   r|   )rM  r.  publicGetTradeFeeCurrencyQuoter6  r)  r  s         r   r  z latoken.fetch_public_trading_fee  s    V$x(I&
 66t{{7F7ST X&%%h
;%%h
;
 	
r   c                     | j                          | j                  |      }|d   |d   d}| j                  | j                  ||            }||d   | j	                  |d      | j	                  |d      d d dS r  )rM  r.  #privateGetAuthTradeFeeCurrencyQuoter6  r)  r  s         r   r  z!latoken.fetch_private_trading_fee  s    V$x(I&
 ;;DKKQW<XY X&%%h
;%%h
;
 	
r   c                 0   | j                          i }d}|||d<   d}|C| j                  |      }|d   |d<   |d   |d<   | j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  ||||      S )a\  
        fetch all trades made by the user

        https://api.latoken.com/doc/v2/#tag/Trade/operation/getTradesByTrader
        https://api.latoken.com/doc/v2/#tag/Trade/operation/getTradesByAssetAndTrader

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr   r  rs   r  r   )rM  r.  $privateGetAuthTradePairCurrencyQuoter6  privateGetAuthTrader  )r   r   r  r   r   rb  r.  r   s           r   fetch_my_tradeszlatoken.fetch_my_trades  s     	
 $GG[[(F"("2GJ%i0GG@@WV\A]^H//GV0LMH&   65%@@r   r   c                 4    dddd}| j                  |||      S )Nrp  closedcanceled)ORDER_STATUS_PLACEDORDER_STATUS_CLOSEDORDER_STATUS_CANCELLEDr$  r   r   statusess      r   parse_order_statuszlatoken.parse_order_status  s)    #)#+&0

 &&99r   c                 2    ddd}| j                  |||      S )Nr.  r   )ORDER_TYPE_MARKETORDER_TYPE_LIMITr  r  s      r   parse_order_typezlatoken.parse_order_type  s&    !) '
 &&99r   r   c                 4    dddd}| j                  |||      S )NGTCr   r   )#ORDER_CONDITION_GOOD_TILL_CANCELLED#ORDER_CONDITION_IMMEDIATE_OR_CANCELORDER_CONDITION_FILL_OR_KILLr  )r   r   timeInForcess      r   parse_time_in_forcezlatoken.parse_time_in_force  s)    3838,1

 k;GGr   r  c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |      }| j                  |      }d }	|)|'|dz   |z   }	|	| j                  v r| j	                  |	      }| j                  |d      }
d }|
1|
j                  d      }t        |      }| j                  ||dz
        }| j                  | j                  |d	            }| j                  |d
      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  |d            }| j                  |d      }|-|j                  d      dk\  rd}n|j                  d      dk\  rd}| j                  |d      }| j                  | j                  |d            }| j                  i d|d|d|d|d| j                  |      dd d|d|	d	|d|dd d|d
|d| j                  |d      d|d|d|d d d d d |      S )!Nr   r3  r   r   r   r  _rr   r  r  r_  filledr  r   messagecancelr   r  acceptrp  clientOrderId	conditionr  rH  lastTradeTimestampr   r   postOnlyr   	stopPricer  )rv  	remainingr9  trades)r$  r   r%  r  r.  splitr#  safe_string_lowerr  r  findr  
safe_orderrR  )r   r  r.  r   r3  r  r  r   r   r   	orderSider  partspartsLengthr  r  r  r  r  r   r  r  r   s                          r   parse_orderzlatoken.parse_order  s   X eT*%%e[9	!!%8""5/:&&v.''05#4CZ%'F%V,$$UF3	 OOC(Ee*K))%qAD$$T%5%5eV%DE  0!!%4!!%2v.(()9)9%)JK""5)4||H%*#h'1,((@..t/?/?{/ST  
" 
] 
 E 
 	 

 Y/ 
 !$ 
 f 
 f 
 D 
 ; 
  
 D 
 U 
 D,,UK@ 
 D 
  f! 
" f# 
$ + 
, - 	r   c                    |t        | j                  dz         | j                          d}| j                  |dd      }| j	                  |d      }| j                  |      }|d   |d   d}|r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  ||||      S )a  
        fetch all unfilled currently open orders

        https://api.latoken.com/doc/v2/#tag/Order/operation/getMyActiveOrdersByPair
        https://api.latoken.com/doc/v2/#tag/StopOrder/operation/getMyActiveStopOrdersByPair  # stop

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if fetching trigger orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nz- fetchOpenOrders() requires a symbol argumentr   stopr  r  r\  )
r   r   rM  safe_value_2r  r.  .privateGetAuthStopOrderPairCurrencyQuoteActiver6  *privateGetAuthOrderPairCurrencyQuoteActiveparse_orders)	r   r   r  r   r   r   	isTriggerr.  rb  s	            r   fetch_open_orderszlatoken.fetch_open_orders~  s     >#DGG.]$]^^%%fi@	66*V$x(I&
 JJ4;;W^`fKghHFFt{{SZ\bGcdH.   65%@@r   c                    | j                          i }d}| j                  |dd      }| j                  |ddg      }|||d<   d}|g| j                  |      }|d   |d<   |d   |d<   |r"| j	                  | j                  ||            }ng| j                  | j                  ||            }nE|r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  ||||      S )	a  
        fetches information on multiple orders made by the user

        https://api.latoken.com/doc/v2/#tag/Order/operation/getMyOrders
        https://api.latoken.com/doc/v2/#tag/Order/operation/getMyOrdersByPair
        https://api.latoken.com/doc/v2/#tag/StopOrder/operation/getMyStopOrders       # stop
        https://api.latoken.com/doc/v2/#tag/StopOrder/operation/getMyStopOrdersByPair  # stop

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if fetching trigger orders
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r  r   r  rs   r  r   )
rM  r  r  r.  (privateGetAuthStopOrderPairCurrencyQuoter6  $privateGetAuthOrderPairCurrencyQuoteprivateGetAuthStopOrderprivateGetAuthOrderr  )	r   r   r  r   r   rb  r.  r  r   s	            r   fetch_orderszlatoken.fetch_orders  s     	
 %%fi@	6FI#67$GG[[(F"("2GJ%i0GGHHU\^dIefDDT[[QXZ`Eab77GV8TU33DKK4PQ.   65%@@r   r   c                 (   | j                          d|i}| j                  |dd      }| j                  |ddg      }d}|r"| j                  | j	                  ||            }n!| j                  | j	                  ||            }| j                  |      S )a3  
        fetches information on an order made by the user

        https://api.latoken.com/doc/v2/#tag/Order/operation/getOrderById
        https://api.latoken.com/doc/v2/#tag/StopOrder/operation/getStopOrderById

        :param str id: order id
        :param str [symbol]: not used by latoken fetchOrder
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if fetching a trigger order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r   r  N)rM  r  r  !privateGetAuthStopOrderGetOrderIdr6  privateGetAuthOrderGetOrderIdr  r   r   r   r   rb  r  r   s          r   fetch_orderzlatoken.fetch_order  s     	"
 %%fi@	6FI#67==dkk'SY>Z[H99$++gv:VWH* ))r   r  r  r  r  c           
      X   | j                          | j                  |      }|j                         }|d   |d   |j                         d|| j                         | j	                  ||      | j                         d}	|dk(  r| j                  ||      |	d<   | j                  |dd      }
| j                  |ddg      }d	}|
7| j                  ||
      |	d<   | j                  | j                  |	|            }n!| j                  | j                  |	|            }| j                  ||      S )
a7  
        create a trade order

        https://api.latoken.com/doc/v2/#tag/Order/operation/placeOrder
        https://api.latoken.com/doc/v2/#tag/StopOrder/operation/placeStopOrder  # stop

        :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 of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param float [params.triggerPrice]: the price at which a trigger order is triggered at

 EXCHANGE SPECIFIC PARAMETERS
        :param str [params.condition]: "GTC", "IOC", or  "FOK"
        :param str [params.clientOrderId]: [0 .. 50] characters, client's custom order id(free field for your convenience)
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r  r  r  )r   r   r  r  r  r  r_  r3  LIMITr  r   r  N)rM  r.  upperuuidamount_to_precisionsecondsprice_to_precisionrO  r  privatePostAuthStopOrderPlacer6  privatePostAuthOrderPlacer  )r   r   r  r  r  r  r   r.  uppercaseTyperb  r   r   s               r   create_orderzlatoken.create_order$  s*   ( 	V$

"8,#I.JJL!!YY[ 00@
 G##66vuEGG))&.+N6NK#@A##'#:#:6<#PGK 99$++gv:VWH55dkk'66RSH &11r   c                 (   | j                          d|i}| j                  |dd      }| j                  |ddg      }d}|r"| j                  | j	                  ||            }n!| j                  | j	                  ||            }| j                  |      S )a!  
        cancels an open order

        https://api.latoken.com/doc/v2/#tag/Order/operation/cancelOrder
        https://api.latoken.com/doc/v2/#tag/StopOrder/operation/cancelStopOrder  # stop

        :param str id: order id
        :param str symbol: not used by latoken cancelOrder()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if cancelling a trigger order
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r   r   r  N)rM  r  r  privatePostAuthStopOrderCancelr6  privatePostAuthOrderCancelr  r  s          r   cancel_orderzlatoken.cancel_order_  s     	"
 %%fi@	6FI#67::4;;wPV;WXH66t{{7F7STH ))r   c                     | j                          i }d}| j                  |dd      }| j                  |ddg      }d}|g| j                  |      }|d   |d<   |d   |d<   |r"| j	                  | j                  ||            }ng| j                  | j                  ||            }nE|r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  d|i      gS )	a+  
        cancel all open orders in a market

        https://api.latoken.com/doc/v2/#tag/Order/operation/cancelAllOrders
        https://api.latoken.com/doc/v2/#tag/Order/operation/cancelAllOrdersByPair

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.trigger]: True if cancelling trigger orders
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r  r  rs   r  r   r  )
rM  r  r  r.  .privatePostAuthStopOrderCancelAllCurrencyQuoter6  *privatePostAuthOrderCancelAllCurrencyQuote!privatePostAuthStopOrderCancelAllprivatePostAuthOrderCancelAllr  )r   r   r   rb  r.  r  r   s          r   cancel_all_orderszlatoken.cancel_all_orders  s    	
 %%fi@	6FI#67[[(F"("2GJ%i0GGNNt{{[bdjOklJJ4;;W^`fKghAA$++gW]B^_==dkk'SY>Z[ OO 
 	
r   rA  c                     | j                          i }| j                  | j                  ||            }d}|| j                  |      }| j	                  |dg       }| j                  ||||      S )am  
 @deprecated
        use fetchDepositsWithdrawals instead

        https://api.latoken.com/doc/v2/#tag/Transaction/operation/getUserTransactions

        :param str code: unified currency code for the currency of the transactions, default is None
        :param int [since]: timestamp in ms of the earliest transaction, default is None
        :param int [limit]: max number of transactions to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Ncontent)rM  privateGetAuthTransactionr6  rs   	safe_listparse_transactions)	r   rA  r  r   r   rb  r   rs   r  s	            r   fetch_transactionszlatoken.fetch_transactions  sx     	
 11$++gv2NO6 }}T*H..9b9&&w%GGr   transactionrs   c                    | j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  | j                  |d            }| j	                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |d	      }d d d d
}| j	                  |d      }|
||d<   ||d<   | j                  | j                  |d            }i d|d|d|d|d| j                  |      dd d|	d|
d|
dd d|d|d|d|d|d|dd d d |dS )Nr   r3  rs   r   r  senderAddressrecipientAddresstransactionHashmemo)rs   r  ratetransactionFeer  r  r  txidrH  networkaddressFrom	addressToaddresstagFromtagTor   updated)commentinternalr9  )r$  r   r%  parse_transaction_statusr)  parse_transaction_typerR  )r   r  rs   r   r3  rY  rA  r   r  r  r  r  r  r9  r  r  s                   r   parse_transactionzlatoken.parse_transaction  s
   & k40%%k;?	%%k:>
&&z8<..t/?/?X/VW!!+x8&&{OD$$[2DE	->?  f5

 "";0@A!CK"C
O**4+;+;K+PQ
K
"
 D
 	

 Y/
 t
 ;
 
 y
 t
 U
 5
 D
 f
 
  f!
" t#
$ )
 	
r   c                 6    ddddd}| j                  |||      S )Nokpendingr  )TRANSACTION_STATUS_CONFIRMEDTRANSACTION_STATUS_EXECUTEDTRANSACTION_STATUS_CHECKINGTRANSACTION_STATUS_CANCELLEDr  r  s      r   r  z latoken.parse_transaction_status!  s,    ,0+/+4,6	
 &&99r   c                 2    ddd}| j                  |||      S )NrB  
withdrawal)TRANSACTION_TYPE_DEPOSITTRANSACTION_TYPE_WITHDRAWALr  )r   r  r   s      r   r   zlatoken.parse_transaction_type*  s&    (1+7
 tT22r   c                     | j                          | j                  |      }| j                  |      }| j                  |dg       }| j	                  ||||      S )aF  
        fetch a history of internal transfers made on an account

        https://api.latoken.com/doc/v2/#tag/Transfer/operation/getUsersTransfers

        :param str code: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of  transfers structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transfer structures <https://docs.ccxt.com/#/?id=transfer-structure>`
        r  )rM  rs   privateGetAuthTransferr
  parse_transfers)r   rA  r  r   r   rs   r   	transferss           r   fetch_transferszlatoken.fetch_transfers1  sZ     	==&..v6@ NN8Y;	##IxFFr   fromAccount	toAccountc                    | j                          | j                  |      }|d   || j                  ||      d}d}|j                  d      dk\  r"| j	                  | j                  ||            }nQt        |      dk(  r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |      S )a  
        transfer currency internally between wallets on the same account

        https://api.latoken.com/doc/v2/#tag/Transfer/operation/transferByEmail
        https://api.latoken.com/doc/v2/#tag/Transfer/operation/transferById
        https://api.latoken.com/doc/v2/#tag/Transfer/operation/transferByPhone

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r   )rs   	recipientvalueN@r   $   )
rM  rs   currency_to_precisionr  privatePostAuthTransferEmailr6  r#  privatePostAuthTransferIdprivatePostAuthTransferPhoneparse_transfer)	r   rA  r  r2  r3  r   rs   rb  r   s	            r   ri   zlatoken.transferb  s     	==& "//f=

 >>#!#88Wf9UVH^r!55dkk'66RSH88Wf9UVH. ""8,,r   ri   c                    | j                  |d      }| j                  |d      }| j                  |d      }|| j                  |d      | j                  |d      | j                  |      | j	                  ||      | j                  |d      | j                  |d      | j                  |d      | j                  |      d	S )	Nr3  rs   r   r   transferringFundsr2  r3  )	r  r   r3  rH  rs   r  r2  r3  r   )safe_timestampr$  r   rR  r%  r)  parse_transfer_status)r   ri   rs   r3  rY  r   s         r   r=  zlatoken.parse_transfer  s    . ''+>	%%h
;
!!(H5""8T2**8[AY///
HE&&x1DE++HmD))(K@008

 
	
r   c                 8    dddddd}| j                  |||      S )Nr#  r$  failedr  )TRANSFER_STATUS_COMPLETEDTRANSFER_STATUS_PENDINGTRANSFER_STATUS_REJECTEDTRANSFER_STATUS_UNVERIFIEDTRANSFER_STATUS_CANCELLEDr  r  s      r   rA  zlatoken.parse_transfer_status  s/    )-'0(0*3)3
 &&99r   c                 ,   d| j                   z   dz   | j                  ||      z   }|}| j                  || j                  |            }	| j	                  |	      }
|dk(  r
|	r|d|
z   z  }|dk(  r| j                          ||z   |
z   }| j                  | j                  |      | j                  | j                        t        j                        }| j                  |dd}|dk(  rd|d	<   | j                  |	      }| j                  d
   d   |z   }||||dS )Nr   GET?ry   zHMAC-SHA512)zX-LA-APIKEYzX-LA-SIGNATUREzX-LA-DIGESTPOSTzapplication/jsonzContent-Typerl   rj   )urlr   bodyheaders)r   implode_paramsr  extract_params	urlencodecheck_required_credentialshmacencodesecrethashlibsha512apiKeyjsonr   )r   pathrl   r   r   rO  rN  rb  requestStringqueryurlencodedQueryauth	signaturerM  s                 r   signzlatoken.sign  s   $s*T-@-@v-NN		&$"5"5d";<../U?!66)++-G#o5D		$++d"3T[[5Mw~~^I#{{"+,G
 *<'yy'iiv&6fdwOOr   reasonrM  r   rO  rN  c
                    |sy | j                  |d      }
| j                  dz   |z   }|
@| j                  | j                  d   |
|       | j	                  | j                  d   |
|       | j                  |d      }| j                  |d      }||K| j                  | j                  d   ||       | j	                  | j                  d   ||       t        |      y )Nr   r   r   error)r$  r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr  r   )r   rA  rb  rM  r   rO  rN  r   requestHeadersrequestBodyr  feedbackre  errorMessages                 r   handle_errorszlatoken.handle_errors  s     ""8Y777S=4'001I7T\]001I7T\]'2''y9<#;001I5RZ[001I4QYZ))r   )N)rx   rJ  NNN)A__name__
__module____qualname__r   r   r   r	   r   r   r
   r1  r  r   rF  r   rZ  strr   rc  dictr   r  r  r   r   r  r   r  r  r   r  r  r  r   r  r  r  r  r   r  r  r  r  r   r   floatr   r  r   r  r  r   r   r!  r  r   r   r1  ri   r=  rA  ra  intrl  __classcell__)r   s   @r   r(   r(      s	   b# bH	D !# 9s 9" $& B$v, BH 24 L ') OZ Ob $& =)( =)~ :>b $`s $`3 $`Y $`L-4 - -6 -^ 02 %33 %3f %3N 04B "5W "57 "5HO Ov O Ob 6:UW A3 As A# A\`af\g A@ 57 E E;N E, <> 
s 
2 =? 
 
2 -1tRV_a 1Ac 1A 1AC 1Af: ::Hs Ha av a aF /3TXac 4A 4A3 4Ac 4Ahlmrhs 4Al *.Dt\^ @A3 @Ac @A @Acghmcn @AD 26b ,*c ,*3 ,*\ gksu 923 92i 92y 92RW 92`c 92v 37r !*s !*C !*F /32 ,
 ,
\ .2SW`b 1Hs 1H# 1HS 1Hf<
T <
X <
Q\ <
|:s :3 +/TPT]_ /GC /Gs /G# /Gdhivdw /Gb [] 3-S 3-% 3-c 3-c 3-an 3-j$
t $
x $
= $
L:C :C :P.# s  c TX `c r   r(   ),ccxt.base.exchanger   ccxt.abstract.latokenr   rW  ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   ccxt.base.decimal_to_precisionr&   r(    r   r   <module>r|     sq    ( -  Q  Q  Q  Q  Q  Q  * 0 - - . ' & . ) ) . 1 ) 4Wh Wr   