
    i3                    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    R/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/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                 X    |                      |          }|                     |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
        
serverTime)publicGetTimesafe_integer)r   paramsresponses      r   
fetch_timezlatoken.fetch_time   s/     %%f--   <888r   returnc                 *   |                      |          }|                     |          }|                     | j        dd          r|                                  |                     |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
        adjustForTimeDifferenceTr   r   baseCurrencyquoteCurrencyN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}    55f==
B %%f--* ??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                    |                      | j        di           }|                     |d          }|                     |dd          }|                                 }|	||z
  |k    r6|                     |          }|                     |||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#>#>--f55H.2kk'$ D D / /DL*+ t|,=>
KKKr   c                    |                      |          }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
        r   r   r   feer   N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    33F;;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                    |                                   |                     |          }|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    	--f55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           	         |                                   |                     |          }|d         |d         d}|||d<   |                     |                     ||                    }|                     ||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
        r   r   re   r   Nr1  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224;;w3O3OPP" $$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                     |                                   |                     |          }|d         |d         d}|                     |                     ||                    }|                     ||          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>`
        r   r   )r   r   )r#  r  publicGetTickerBaseQuoter  rU  r   r   r   r  r9  r   s         r   fetch_tickerzlatoken.fetch_tickeru  s~     	V$$8$I&
 
 00Wf1M1MNN*   6222r   symbolsc                     |                                   |                     |          }|                     ||          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>`
        )r#  publicGetTickerparse_tickers)r   rZ  r   r   s       r   fetch_tickerszlatoken.fetch_tickers  sA     	''//. !!(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                 "   |                                   |                     |          }|d         |d         d}|t          |d          |d<   |                     |                     ||                    }|                     ||||          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>`
        r   r   r3  Nd   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::4;;wPV;W;WXX   65%@@@r   c                 `   |                      | j        di           }|                     |dd          }|                     |d|          }|                     |d          }|dk    r|                     ||          S |dk    r|                     ||          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   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,,---11&&AAA...00@@@tw)CCDDDr   c                 6   |                                   |                     |          }|d         |d         d}|                     |                     ||                    }||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&
 
 66t{{7F7S7STT X&%%h
;;%%h
;;
 
 	
r   c                 6   |                                   |                     |          }|d         |d         d}|                     |                     ||                    }||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&
 
 ;;DKKQW<X<XYY X&%%h
;;%%h
;;
 
 	
r   c                 t   |                                   i }d}|||d<   d}|U|                     |          }|d         |d<   |d         |d<   |                     |                     ||                    }n)|                     |                     ||                    }|                     ||||          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@@WV\A]A]^^HH//GV0L0LMMH&   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                    |t          | j        dz             |                                  d}|                     |dd          }|                     |d          }|                     |          }|d         |d         d}|r*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    ||||          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  s     >#DG.]$]^^^%%fi@@	66**V$$x(I&
 
  	eJJ4;;W^`fKgKghhHHFFt{{SZ\bGcGcddH.   65%@@@r   c                    |                                   i }d}|                     |dd          }|                     |ddg          }|||d<   d}||                     |          }|d         |d<   |d         |d<   |r*|                     |                     ||                    }n|                     |                     ||                    }nU|r*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    ||||          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  sY    	
 %%fi@@	6FI#677$GG[[((F"("2GJ%i0GG cHHU\^dIeIeffDDT[[QXZ`EaEabb R77GV8T8TUU33DKK4P4PQQ.   65%@@@r   r   c                 h   |                                   d|i}|                     |dd          }|                     |ddg          }d}|r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |          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>`
        r   r  r  N)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 	X==dkk'SY>Z>Z[[HH99$++gv:V:VWWH* )))r   r   rh  r   r   c           
         |                                   |                     |          }|                                }|d         |d         |                                d||                                 |                     ||          |                                 d}	|dk    r|                     ||          |	d<   |                     |dd          }
|                     |ddg          }d	}|
C|                     ||
          |	d<   | 	                    | 
                    |	|                    }n)|                     | 
                    |	|                    }|                     ||          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>`
        r   r   r  )r   r   rh  r  r   r  r6  r	  LIMITr   r  r  N)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  sc   $ 	V$$

"8,#I.JJLL!!YY[[ 00@@
 
 G###66vuEEGG))&.+NN6NK#@AA##'#:#:6<#P#PGK 99$++gv:V:VWWHH55dkk'66R6RSSH &111r   c                 h   |                                   d|i}|                     |dd          }|                     |ddg          }d}|r*|                     |                     ||                    }n)|                     |                     ||                    }|                     |          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>`
        r   r  r  N)r#  r  r{  privatePostAuthStopOrderCancelr  privatePostAuthOrderCancelr  r  s          r   cancel_orderzlatoken.cancel_order  s     	"
 %%fi@@	6FI#677 	U::4;;wPV;W;WXXHH66t{{7F7S7STTH )))r   c                 H   |                                   i }d}|                     |dd          }|                     |ddg          }d}||                     |          }|d         |d<   |d         |d<   |r*|                     |                     ||                    }n|                     |                     ||                    }nU|r*|                     |                     ||                    }n)|                     |                     ||                    }|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  s6    	
 %%fi@@	6FI#677[[((F"("2GJ%i0GG iNNt{{[bdjOkOkllJJ4;;W^`fKgKghh \AA$++gW]B^B^__==dkk'SY>Z>Z[[ r   r  c                    |                                   i }|                     |                     ||                    }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     	
 11$++gv2N2NOO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                     |                                   |                     |          }|                     |          }|                     |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>`
        r  )r#  re   privateGetAuthTransferr  parse_transfers)r   r  rs  r1  r   re   r   	transferss           r   fetch_transferszlatoken.fetch_transfers  sl     	==&&..v66@ NN8Y;;	##IxFFFr   fromAccount	toAccountc                    |                                   |                     |          }|d         ||                     ||          d}d}|                    d          dk    r*|                     |                     ||                    }nft          |          dk    r*|                     |                     ||                    }n)|                     |                     ||                    }| 	                    |          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>`
        r   )re   	recipientvalueN@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  s     	==&& "//f==
 

 >>#!##88Wf9U9UVVHH^^r!!55dkk'66R6RSSHH88Wf9U9UVVH. ""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'      sG       R R R R RhD D D !# 9 9 9 9 $& @ @$v, @ @ @ @D 24 L L L L ') O OZ O O O Ob $& ;) ;)( ;) ;) ;) ;)z :>b "` "`s "`3 "`Y "` "` "` "`H- -6 -V - - - -^ 02 #3 #33 #3f #3 #3 #3 #3J 04B  5  5W  57  5  5  5  5DO O O5 O O O Ob 6:UW A A3 As A# A\`af\g A A A A< 57 E E E;N E E E E( <> 
 
s 
 
 
 
2 =? 
 
 
 
 
 
2 -1tRV_a /A /Ac /A /AC /A /A /A /Ab: : :: : :H H Hc c c5 c c c cJ /3TXac 2A 2A 2A3 2Ac 2Ahlmrhs 2A 2A 2A 2Ah *.Dt\^ >A >A3 >Ac >A >Acghmcn >A >A >A >A@ 26b )* )*c )*3 )* )* )* )*V gksu 72 723 72i 72y 72RW 72`c 72 72 72 72r 37r * *s *C * * * *B /32 & & & & & &P .2SW`b /H /Hs /H# /HS /H /H /H /Hb<
 <
x <
; <
 <
 <
 <
|: : :3 3 3 +/TPT]_ -G -GC -Gs -G# -G -G -G -G^ [] 1- 1-S 1-% 1-c 1-c 1-an 1- 1- 1- 1-f$
 $
 $
 $
 $
 $
L: : :P P P P.      r   r'   )+ccxt.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   ( ' ' ' ' ' - - - - - -  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   