
    i5                    H   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 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*dS )    )Exchange)ImplicitAPIN)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 fdZd Zi 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d8d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d8d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 Z!d Z"d Z#d8d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&Z.d	i fd
efd'Z/d	d	d	i fd(ededefd)Z0d8d*e1de2fd+Z3d, Z4d- Z5d	d	d	i fd(ededefd.Z6i fd(ed#e+d/ed0ede7f
d1Z8d8d*e1fd2Z9d3 Z:d9d6Z;d7 Z< xZ=S ):latokenc                    |                      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dd
dddddd
d*d
ddd+d,d-d.id/d.gd0d1d2d3i d4d5d6d5d7d5d8d5d9d5d:d5d;d5d<d5d=d5d>d5d?d5d@d5dAd5dBd5dCd5dDd5ii dEd5dFd5dGd5dHd5dId5dJd5dKd5dLd5dMd5dNd5dOd5dPd5dQd5dRd5dSd5dTd5dUd5dVd5ii dWd5dXd5dYd5dZd5d[d5d\d5d]d5d^d5d_d5d`d5dad5dbd5dcd5ddd5ded5dfd5dgd5dhd5ididjt          dkd3d
d|                     dl          |                     dl          dmii dndodpdqdrdsdtdudvdwdxdydzd{d|d}d~d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          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fetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchMarginModefetchMarketsfetchMyTradesfetchOpenOrders
fetchOrderfetchOrderBookemulated)fetchOrdersfetchPositionModefetchTickerfetchTickers	fetchTime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)rc   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fundingr.   r   )r   r   methodfetchPrivateTradingFee)defaultTypetypesaccountsrV   )idname	countriesversion	rateLimithasurlsr^   precisionModera   commonCurrencies
exceptionsoptions)deep_extendsuperr'   describer%   parse_numberr   r#   r   r   r   r   r"   r   r    r$   r   )self	__class__s    `/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/latoken.pyr   zlatoken.describe   su   gt 4 4 = = ? ?/// %/ 	/
 %/ %/ "4/ t/ $U/  / t/ &u/ '/ (/ "4/  !/" +E#/ /$ )%%/& ''/( ()/* "4+/, &u-/. (//0 1%1/2 +D3/4 +E5/6 *57/8 +E9/: "5;/< =/>  ?/@ "4A/B dC/D !$E/ /F  $%*# $!##'$)%/!&"& ]/ / /b ~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8!..x8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$ EQB
 QB
 Q Q Q	    c                 F    |                                  | j        d         z
  S )NtimeDifference)millisecondsr   )r   s    r   noncezlatoken.nonce   s!      ""T\2B%CCCr   c                 h   K   |                      |           d{V }|                     |d          S )a_  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: 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
        N
serverTime)publicGetTimesafe_integer)r   paramsresponses      r   
fetch_timezlatoken.fetch_time   sE       ++F33333333   <888r   returnc                 R  K   |                      |           d{V }|                     |           d{V }|                     | j        dd          r|                                  d{V  |                     |d          }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }	|                     |d          }
|                     ||	          }|                     ||
          }||| 	                    |                     |d                    }| 	                    |                     |d                    }|
                                }|                     |          }|                     |d	          }|                    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|                     |d          |                     |d          dddd |                     |d!          dd ddd |                     |d"|z             |                     |d#|z             d d$|                     |d%          |d&
           |S )'a&  
        retrieves data on all markets for latoken
        :see: 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
        NadjustForTimeDifferenceTr   r   baseCurrencyquoteCurrencytagstatussymbol/basequotesettlebaseIdquoteIdsettleIdtyper.   r/   Fr0   r1   r2   activePAIR_STATUS_ACTIVEcontractlinearquantityTick	priceTick)amountpriceminmaxminOrderQuantityminOrderCostmaxOrderCost)leverager   r   costcreated)
inverse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_markets  s       ;;FCCCCCCCC
B ++F33333333* ??4<)BDII 	.++---------z488q#h--(( >	 >	Aa[F!!&$//B%%fn==F&&v??G??>6BBL OONGDDM'M,E..t/?/?e/T/TUU//0@0@PU0V0VWW!&#'??>#B#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"J!%!1!1&+!F!F" " $(#'% %
 $(#3#3F<N#O#O#'# #
 $(#'" "
 $(#3#3FNM]<]#^#^#'#3#3FNM]<]#^#^! ! $  $00CC"_0 0 0 0 0 0b r   c                   K   |                      | j        di           }|                     |d          }|                     |dd          }|                                 }|	||z
  |k    r<|                     |           d {V }|                     |||d          | j        d<   |                      | j        d         d          S )NrA   	timestampexpiresr,   )r   r	  r   )r   r   r   r   publicGetCurrencyextend)r   r   r   r	  r
  nowr   s          r   r   z#latoken.fetch_currencies_from_cache  s       //$,0A2FF%%g{;;	##GY==!!C)Ow#>#>!33F;;;;;;;;H.2kk'$ D D / /DL*+ t|,=>
KKKr   c                   K   |                      |           d{V }i }t          dt          |                    D ] }||         }|                     |d          }|                     |d          }|                     |          }|                     |d          }	|                     |d          }
d}|
dk    rd}nd	}|                     |d
          }|dk    }|                     |d          }||||||dd|	|                     |                     |                     |d                              |                     |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
        Nr   r   r   feer   CURRENCY_TYPE_ALTERNATIVEothercryptor   CURRENCY_STATUS_ACTIVEr   decimalsminTransferAmountr   )r   withdraw)r   coder   r   r   r   depositr  r  r   r   networks)r   r   r   r   r   r   r   parse_precision)r   r   r   r  r  re   r   r   r  r  currencyTyper   r   r   r   s                  r   fetch_currencieszlatoken.fetch_currencies  s      99&AAAAAAAAB q#h--(( &	 &	A{H!!(D11B""8U33C**3//D""8U33C++Hf==LD:::  %%h99F 88F##Hf55D   !..t/C/CDDTDTU]_iDjDj/k/kll  $//:MNN# 
  $#! !	 	 + F4LL. r   c                   K   |                                   d{V  |                     |           d{V }|ddd}d}|                     | j        ddd          }|                     |d|          }|                     | j        di           }|                     |||          }|                     |d          }	|                     |	|g           }
t          dt          |
                    D ]}|
|         }|                     |d	          }| 	                    |d
          }|||}nt          ||          }|                     |          }|                                 }|                     |d          |d<   |                     |d          |d<   |||<   ||d
<   |                     |          |d<   |                     |          S )aw  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: 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   r	  datetimer<   r   r.   r   r   r   re   r	  	availablefreeblockedusedr  )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
currencyIdr	  r  r'  s                    r   fetch_balancezlatoken.fetch_balance  s      !!!!!!!!!33F;;;;;;;;0 
 

 ((~}V\]]<<gr::&&udD99x88??>;CCq#h--(( 	# 	#AqkG))':>>J))';??I$'#,LL#&|Y#?#?L**:66DllnnG"..wDDGFO"..w	BBGFO"F4LL*{!\\,77z  (((r   Nr   limitc           	      (  K   |                                   d{V  |                     |          }|d         |d         d}|||d<   |                     |                     ||                     d{V }|                     ||ddddd	          S )
aG  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: 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
        Nr   r   re   r   r1  bidaskr   quantity)r#  r  publicGetBookCurrencyQuoter  parse_order_book)r   r   r1  r   r  requestr   s          r   fetch_order_bookzlatoken.fetch_order_book"  s       !!!!!!!!!V$$x(I&
 
 $GG88Wf9U9UVVVVVVVV" $$XvtUE7T^___r   r  c                    |                      |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|          S )Nr   	lastPriceupdateTimestampr	  r  lowhighr4  bestBid	bidVolumebestBidQuantityr5  bestAsk	askVolumebestAskQuantityvwapopencloselastpreviousClosechangero   	change24haverage	amount24h	volume24h)
baseVolumequoteVolumer   )r   r   safe_tickersafe_symbolr(  )r   rg   r  marketIdrI  r	  s         r   parse_tickerzlatoken.parse_tickerF  s   * ##FH5544%%f.?@@	 !
d&&x88!
!
 Y//!
 4	!

 D!
 4##FI66!
 ))&2CDD!
 4##FI66!
 ))&2CDD!
 D!
 D!
 T!
 D!
 T!
 d!
  $**6;??!!
" t#!
$ **6;??++FK@@)!
 !
 !
* +  	r   c                   K   |                                   d{V  |                     |          }|d         |d         d}|                     |                     ||                     d{V }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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>`
        Nr   r   )r   r   )r#  r  publicGetTickerBaseQuoter  rU  r   r   r   r  r9  r   s         r   fetch_tickerzlatoken.fetch_tickeru  s       !!!!!!!!!V$$8$I&
 
 66t{{7F7S7STTTTTTTT*   6222r   symbolsc                    K   |                                   d{V  |                     |           d{V }|                     ||          S )a"  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: 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>`
        N)r#  publicGetTickerparse_tickers)r   rZ  r   r   s       r   fetch_tickerszlatoken.fetch_tickers  si       !!!!!!!!!--f55555555. !!(G444r   c                 Z   d }|                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }|                     |d          }	|	|rdnd}	n|	d	k    rd}	n|	d
k    rd}	|	dk    }
|r|
rdnd}|                     |d          }|                     |d          }|                     |          }|                     |          }|dz   |z   }|| j        v r|                     |          }|                     |d          }|                     |d          }|                     |d          }d }|||d}|                     |||                     |          ||||||	||||d|          S )Nr	  r   r6  r   
makerBuyer	directionsellbuyTRADE_DIRECTION_BUYTRADE_DIRECTION_SELLrp   rq   r   r   r   r   orderr  )r   re   )r   r	  r  r   r   rf  r   takerOrMakersider   r   r   r  )r   r   r   r   marketsr  
safe_trader(  )r   trader  r   r	  priceStringamountString
costStringr`  rh  isBuyrg  r   r   r   r   r   r   orderIdfeeCostr  s                        r   parse_tradezlatoken.parse_trade  s   B %%e[99	&&ug66''z::%%eV44
__UL99
{33<'266UDD,,,///#-E%Ewwg!!%88""5/::&&v..''00e#T\!![[((FeT**""5'22""5%00! C "Y//( " 
  
   	r   sincec                 >  K   |                                   d{V  |                     |          }|d         |d         d}|t          |d          |d<   |                     |                     ||                     d{V }|                     ||||          S )a/  
        get the list of most recent trades for a particular symbol
        :see: 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>`
        Nr   r   r3  d   r1  )r#  r  r   "publicGetTradeHistoryCurrencyQuoter  parse_trades)r   r   rs  r1  r   r  r9  r   s           r   fetch_tradeszlatoken.fetch_trades  s       !!!!!!!!!V$$x(I&
 
 "5#GG@@WV\A]A]^^^^^^^^   65%@@@r   c                 |  K   |                      | j        di           }|                     |dd          }|                     |d|          }|                     |d          }|dk    r|                     ||           d{V S |dk    r|                     ||           d{V S t          | j        dz             )a  
        fetch the trading fees for a market
        :see: https://api.latoken.com/doc/v2/#tag/Trade/operation/getFeeByPair
        :see: 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>`
        rV   r   r   N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F(((<TUU!!&(MBB68,,---77GGGGGGGGG...66vvFFFFFFFFFtw)CCDDDr   c                 R  K   |                                   d {V  |                     |          }|d         |d         d}|                     |                     ||                     d {V }||d         |                     |d          |                     |d          d d dS Nr   r   r3  r   makerFeetakerFee)r   r   rp   rq   ro   rn   )r#  r  publicGetTradeFeeCurrencyQuoter  r   rX  s         r   r}  z latoken.fetch_public_trading_fee?  s      !!!!!!!!!V$$x(I&
 
 <<T[[RX=Y=YZZZZZZZZ X&%%h
;;%%h
;;
 
 	
r   c                 R  K   |                                   d {V  |                     |          }|d         |d         d}|                     |                     ||                     d {V }||d         |                     |d          |                     |d          d d dS r  )r#  r  #privateGetAuthTradeFeeCurrencyQuoter  r   rX  s         r   r|  z!latoken.fetch_private_trading_feeX  s      !!!!!!!!!V$$x(I&
 
 AA$++gW]B^B^________ X&%%h
;;%%h
;;
 
 	
r   c                   K   |                                   d{V  i }d}|||d<   d}|[|                     |          }|d         |d<   |d         |d<   |                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     ||||          S )af  
        fetch all trades made by the user
        :see: https://api.latoken.com/doc/v2/#tag/Trade/operation/getTradesByTrader
        :see: 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>`
        Nr1  r   re   r   r   )r#  r  $privateGetAuthTradePairCurrencyQuoter  privateGetAuthTraderw  )r   r   rs  r1  r   r9  r  r   s           r   fetch_my_tradeszlatoken.fetch_my_tradesq  s
      !!!!!!!!!
 $GG[[((F"("2GJ%i0GG!FFt{{SZ\bGcGcddddddddHH!55dkk'66R6RSSSSSSSSH&   65%@@@r   c                 <    dddd}|                      |||          S )NrG  closedcanceled)ORDER_STATUS_PLACEDORDER_STATUS_CLOSEDORDER_STATUS_CANCELLEDr   r   r   statusess      r   parse_order_statuszlatoken.parse_order_status  s1    #)#+&0
 

 &&999r   c                 :    ddd}|                      |||          S )Nr  r1  )ORDER_TYPE_MARKETORDER_TYPE_LIMITr  r  s      r   parse_order_typezlatoken.parse_order_type  s.    !) '
 
 &&999r   c                 <    dddd}|                      |||          S )NGTCIOCFOK)#ORDER_CONDITION_GOOD_TILL_CANCELLED#ORDER_CONDITION_IMMEDIATE_OR_CANCELORDER_CONDITION_FILL_OR_KILLr  )r   timeInForcetimeInForcess      r   parse_time_in_forcezlatoken.parse_time_in_force  s1    3838,1
 

 k;GGGr   c           	      p   |                      |d          }|                     |d          }|                      |d          }|                      |d          }|                     |          }|                     |          }d }	|(|&|dz   |z   }	|	| j        v r|                     |	          }|                      |d          }
d }|
=|
                    d          }t          |          }|                     ||dz
            }|                     |                      |d	                    }|                      |d
          }|                      |d          }|                      |d          }|                      |d          }| 	                    |                      |d                    }|                      |d          }|7|
                    d          dk    rd}n|
                    d          dk    r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 |          S )!Nr   r	  r   r   r   rh  _rd   r   r   r6  filledr   r   messagecancelr   r  acceptrG  clientOrderId	condition	stopPricer   r  lastTradeTimestampr   r  postOnlytriggerPricer   )r  rM  	remainingr  trades)r   r   r   ri  r  splitr   safe_string_lowerr  r  findr  
safe_orderr(  )r   rf  r  r   r	  r   r   r   r   r   	orderSiderh  partspartsLengthr   r   r   r  r   r   r  r  r  r  s                           r   parse_orderzlatoken.parse_order  s`   X eT**%%e[99	!!%88""5/::&&v..''005#4CZ%'F%%V,,$$UF33	 OOC((Ee**K))%qAAD$$T%5%5eV%D%DEE  00!!%44!!%22v..(()9)9%)J)JKK""5)44||H%%**#h''1,,((@@..t/?/?{/S/STT''{;;  
" 
] 
 E 
 	 

 Y// 
 !$ 
 f 
 f 
 D 
 ; 
  
 D 
 U 
  
 L 
  D! 
" f# 
$ - 
  
  
. /  	r   c                   K   |t          | j        dz             |                                  d{V  d}|                     |dd          }|                     |d          }|                     |          }|d         |d         d}|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }| 	                    ||||          S )a  
        fetch all unfilled currently open orders
        :see: https://api.latoken.com/doc/v2/#tag/Order/operation/getMyActiveOrdersByPair
        :see: 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 argumenttriggerstopr   r   r3  )
r   r   r#  safe_value_2r{  r  .privateGetAuthStopOrderPairCurrencyQuoteActiver  *privateGetAuthOrderPairCurrencyQuoteActiveparse_orders)	r   r   rs  r1  r   r   	isTriggerr  r9  s	            r   fetch_open_orderszlatoken.fetch_open_orders  s9      >#DG.]$]^^^!!!!!!!!!%%fi@@	66**V$$x(I&
 
  	k!PPQUQ\Q\]dflQmQmnnnnnnnnHH!LLT[[Y`bhMiMijjjjjjjjH.   65%@@@r   c                   K   |                                   d{V  i }d}|                     |dd          }|                     |ddg          }|||d<   d}||                     |          }|d         |d<   |d         |d<   |r0|                     |                     ||                     d{V }n|                     |                     ||                     d{V }na|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }| 	                    ||||          S )	a  
        fetches information on multiple orders made by the user
        :see: https://api.latoken.com/doc/v2/#tag/Order/operation/getMyOrders
        :see: https://api.latoken.com/doc/v2/#tag/Order/operation/getMyOrdersByPair
        :see: https://api.latoken.com/doc/v2/#tag/StopOrder/operation/getMyStopOrders       # stop
        :see: 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  r1  r   re   r   r   )
r#  r  r{  r  (privateGetAuthStopOrderPairCurrencyQuoter  $privateGetAuthOrderPairCurrencyQuoteprivateGetAuthStopOrderprivateGetAuthOrderr  )	r   r   rs  r1  r   r9  r  r  r   s	            r   fetch_orderszlatoken.fetch_ordersR  s      !!!!!!!!!
 %%fi@@	6FI#677$GG[[((F"("2GJ%i0GG i!%!N!Nt{{[bdjOkOk!l!lllllll!%!J!J4;;W^`fKgKg!h!hhhhhhh X!%!=!=dkk'SY>Z>Z![![[[[[[[!%!9!9$++gv:V:V!W!WWWWWWW.   65%@@@r   r   c                   K   |                                   d{V  d|i}|                     |dd          }|                     |ddg          }d}|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |          S )a  
        fetches information on an order made by the user
        :see: https://api.latoken.com/doc/v2/#tag/Order/operation/getOrderById
        :see: https://api.latoken.com/doc/v2/#tag/StopOrder/operation/getStopOrderById
        :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>`
        Nr   r  r  )r#  r  r{  !privateGetAuthStopOrderGetOrderIdr  privateGetAuthOrderGetOrderIdr  r   r   r   r   r9  r  r   s          r   fetch_orderzlatoken.fetch_order  s       !!!!!!!!!"
 %%fi@@	6FI#677 	^!CCDKKPWY_D`D`aaaaaaaaHH!??GU[@\@\]]]]]]]]H* )))r   r   rh  r   r   c           
        K   |                                   d{V  |                     |          }|                                }|d         |d         |                                d||                                 |                     ||          |                                 d}	|dk    r|                     ||          |	d<   |                     |dd	          }
|                     |dd	g          }d}|
I|                     ||
          |	d	<   | 	                    | 
                    |	|                     d{V }n/|                     | 
                    |	|                     d{V }|                     ||          S )
aV  
        create a trade order
        :see: https://api.latoken.com/doc/v2/#tag/Order/operation/placeOrder
        :see: 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 fullfilled, 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>`
        Nr   r   r  )r   r   rh  r  r   r  r6  r	  LIMITr   r  r  )r#  r  upperuuidamount_to_precisionsecondsprice_to_precisionr%  r{  privatePostAuthStopOrderPlacer  privatePostAuthOrderPlacer  )r   r   r   rh  r   r   r   r  uppercaseTyper9  r  r   s               r   create_orderzlatoken.create_order  s     $ !!!!!!!!!V$$

"8,#I.JJLL!!YY[[ 00@@
 
 G###66vuEEGG))&.+NN6NK#@AA##'#:#:6<#P#PGK !??GU[@\@\]]]]]]]]HH!;;DKKQW<X<XYYYYYYYYH &111r   c                   K   |                                   d{V  d|i}|                     |dd          }|                     |ddg          }d}|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |          S )a+  
        cancels an open order
        :see: https://api.latoken.com/doc/v2/#tag/Order/operation/cancelOrder
        :see: 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>`
        Nr   r  r  )r#  r  r{  privatePostAuthStopOrderCancelr  privatePostAuthOrderCancelr  r  s          r   cancel_orderzlatoken.cancel_order  s       !!!!!!!!!"
 %%fi@@	6FI#677 	[!@@WV\A]A]^^^^^^^^HH!<<T[[RX=Y=YZZZZZZZZH )))r   c                   K   |                                   d{V  i }d}|                     |dd          }|                     |ddg          }d}||                     |          }|d         |d<   |d         |d<   |r0|                     |                     ||                     d{V }n|                     |                     ||                     d{V }na|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|S )a5  
        cancel all open orders in a market
        :see: https://api.latoken.com/doc/v2/#tag/Order/operation/cancelAllOrders
        :see: 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   re   r   r   )	r#  r  r{  r  .privatePostAuthStopOrderCancelAllCurrencyQuoter  *privatePostAuthOrderCancelAllCurrencyQuote!privatePostAuthStopOrderCancelAllprivatePostAuthOrderCancelAll)r   r   r   r9  r  r  r   s          r   cancel_all_orderszlatoken.cancel_all_orders  s      !!!!!!!!!
 %%fi@@	6FI#677[[((F"("2GJ%i0GG o!%!T!TUYU`U`ahjpUqUq!r!rrrrrrr!%!P!PQUQ\Q\]dflQmQm!n!nnnnnnn b!%!G!GT[]cHdHd!e!eeeeeee!%!C!CDKKPWY_D`D`!a!aaaaaaa r   r  c                 ,  K   |                                   d{V  i }|                     |                     ||                     d{V }d}||                     |          }|                     |dg           }|                     ||||          S )a{  
         * @deprecated
        use fetchDepositsWithdrawals instead
        :see: 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)r#  privateGetAuthTransactionr  re   	safe_listparse_transactions)	r   r  rs  r1  r   r9  r   re   r  s	            r   fetch_transactionszlatoken.fetch_transactions?  s       !!!!!!!!!
 77GV8T8TUUUUUUUU6 }}T**H..9b99&&w%GGGr   re   c                    |                      |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S )Nr   r	  re   r   r   senderAddressrecipientAddresstransactionHashmemo)re   r   ratetransactionFeer   r   r   txidr  networkaddressFrom	addressToaddresstagFromtagTor   updated)commentinternalr  )r   r   r   parse_transaction_statusr   parse_transaction_typer(  )r   transactionre   r   r	  r/  r  r   r   r  r  r  r  r  rq  r   s                   r   parse_transactionzlatoken.parse_transactionp  sF   & k400%%k;??	%%k:>>
&&z8<<..t/?/?X/V/VWW!!+x88&&{ODD$$[2DEE	->??  f55
 

 "";0@AA!CK"C
O**4+;+;K+P+PQQ
K
"
 D
 	

 Y//
 t
 ;
 
 y
 t
 U
 5
 D
 f
 
  f!
" t#
$ )
 
 
 	
r   c                 <    dddd}|                      |||          S )Nokr  )TRANSACTION_STATUS_CONFIRMEDTRANSACTION_STATUS_EXECUTEDTRANSACTION_STATUS_CANCELLEDr  r  s      r   r  z latoken.parse_transaction_status  s1    ,0+/,6
 

 &&999r   c                 :    ddd}|                      |||          S )Nr  
withdrawal)TRANSACTION_TYPE_DEPOSITTRANSACTION_TYPE_WITHDRAWALr  )r   r   r   s      r   r  zlatoken.parse_transaction_type  s.    (1+7
 
 tT222r   c                    K   |                                   d{V  |                     |          }|                     |           d{V }|                     |dg           }|                     ||||          S )aJ  
        fetch a history of internal transfers made on an account
        :see: 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>`
        Nr  )r#  re   privateGetAuthTransferr  parse_transfers)r   r  rs  r1  r   re   r   	transferss           r   fetch_transferszlatoken.fetch_transfers  s       !!!!!!!!!==&&44V<<<<<<<<@ NN8Y;;	##IxFFFr   fromAccount	toAccountc                 H  K   |                                   d{V  |                     |          }|d         ||                     ||          d}d}|                    d          dk    r0|                     |                     ||                     d{V }nrt          |          dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }| 	                    |          S )a  
        transfer currency internally between wallets on the same account
        :see: https://api.latoken.com/doc/v2/#tag/Transfer/operation/transferByEmail
        :see: https://api.latoken.com/doc/v2/#tag/Transfer/operation/transferById
        :see: 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>`
        Nr   )re   	recipientvalue@r   $   )
r#  re   currency_to_precisionr  privatePostAuthTransferEmailr  r   privatePostAuthTransferIdprivatePostAuthTransferPhoneparse_transfer)	r   r  r   r  r  r   re   r9  r   s	            r   r[   zlatoken.transfer  sK      !!!!!!!!!==&& "//f==
 

 >>#!##!>>t{{7TZ?[?[\\\\\\\\HH^^r!!!;;DKKQW<X<XYYYYYYYYHH!>>t{{7TZ?[?[\\\\\\\\H. ""8,,,r   c                    |                      |d          }|                     |d          }|                     |d          }||                     |d          |                     |d          |                     |          |                     ||          |                     |d          |                     |d          |                     |d          |                     |          d	S )	Nr	  re   r   r   transferringFundsr  r  )	r   r   r	  r  re   r   r  r  r   )safe_timestampr   r   r(  r   r   parse_transfer_status)r   r[   re   r	  r/  r   s         r   r  zlatoken.parse_transfer  s    . ''+>>	%%h
;;
!!(H55""8T22**8[AAY////
HEE&&x1DEE++HmDD))(K@@0088

 

 
	
r   c                 @    dddddd}|                      |||          S )Nr  pendingfailedr  )TRANSFER_STATUS_COMPLETEDTRANSFER_STATUS_PENDINGTRANSFER_STATUS_REJECTEDTRANSFER_STATUS_UNVERIFIEDTRANSFER_STATUS_CANCELLEDr  r  s      r   r  zlatoken.parse_transfer_statusE  s7    )-'0(0*3)3
 
 &&999r   rj   GETc                 V   d| j         z   dz   |                     ||          z   }|}|                     ||                     |                    }	|                     |	          }
|dk    r
|	r|d|
z   z  }|dk    r|                                  ||z   |
z   }|                     |                     |          |                     | j                  t          j
                  }| j        |dd}|dk    rd|d	<   |                     |	          }| j        d
         d         |z   }||||dS )Nr   r#  ?rk   zHMAC-SHA512)zX-LA-APIKEYzX-LA-SIGNATUREzX-LA-DIGESTPOSTzapplication/jsonzContent-Typer^   r\   )urlr   bodyheaders)r   implode_paramsr{  extract_params	urlencodecheck_required_credentialshmacencodesecrethashlibsha512apiKeyjsonr   )r   pathr^   r   r   r)  r(  r9  requestStringqueryurlencodedQueryauth	signaturer'  s                 r   signzlatoken.signO  sC   $s*T-@-@v-N-NN		&$"5"5d";";<<..//U?? 7!66)++---G#o5D		$++d"3"3T[[5M5Mw~^^I#{"+, G
 *<'yy''iv&6fdwOOOr   c
                    |sd S |                      |d          }
| j        dz   |z   }|
D|                     | j        d         |
|           |                     | j        d         |
|           |                     |d          }|                      |d          }||S|                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nr   r   r   error)r   r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   r   )r   r  reasonr'  r   r)  r(  r   requestHeadersrequestBodyr  feedbackr>  errorMessages                 r   handle_errorszlatoken.handle_errorsf  s    	4 ""8Y777S=4'001I7T\]]]001I7T\]]]'22''y99<#;001I5RZ[[[001I4QYZZZ)))tr   )N)rj   r#  NNN)>__name__
__module____qualname__r   r   r   r   r	   r  r   r   r  r   r0  strr   r   r:  r   rU  rY  r   r   r^  r   rr  rx  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
  r   r[   r  r  r;  rF  __classcell__)r   s   @r   r'   r'      sU       R R R R RhD D D ') 9 9 9 9 *, @ @V @ @ @ @D 8: L L L L -/ O O: O O O Ob *, ;) ;) ;) ;) ;) ;)z @DB "` "`S "` "`S\ "` "` "` "`H- -6 -V - - - -^ 68 #3 #3 #3F #3 #3 #3 #3J 6:"  5  57  5  5  5  5  5DO O O5 O O O Ob <@d[] A A AS A Abfglbm A A A A< ;= E Ec EAT E E E E( BD 
 
S 
 
 
 
2 CE 
 
c 
 
 
 
2 37TX\eg /A /AC /As /ARU /A /A /A /Ab: : :: : :H H Hc c c5 c c c cJ 59tZ^gi 2A 2Ac 2A 2ATW 2Anrsxny 2A 2A 2A 2Ah 04$UYbd >A >A >AC >As >Aimnsit >A >A >A >A@ 8<B )* )*C )* )* )* )* )*V mqy{ 72 72 72I 72Y 72X] 72fi 72 72 72 72r 9=R * *S *# * * * *B 59 & &c & & & &P 48dY]fh /H /HS /H /HSV /H /H /H /Hb<
 <
x <
; <
 <
 <
 <
|: : :3 3 3 154VZce -G -G# -GS -GPS -G -G -G -G^ ac 1- 1-3 1- 1-C 1-TW 1-gt 1- 1- 1- 1-f$
 $
 $
 $
 $
 $
L: : :P P P P.      r   r'   )+ ccxt.async_support.base.exchanger   ccxt.abstract.latokenr   r1  ccxt.base.typesr   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>rT     sr   6 5 5 5 5 5 - - - - - -  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L  L       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . ) ) ) ) ) ) ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 ) ) ) ) ) ) 4 4 4 4 4 4_ _ _ _ _h _ _ _ _ _r   