
    i                         d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZ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"  G d dee          Z#dS )    )Exchange)ImplicitAPI)Balances
CurrenciesCurrency	IndexTypeIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTransaction)List)ExchangeError)
BadRequest)InsufficientFunds)InvalidOrder)DuplicateOrderId)NotSupported)	TICK_SIZE)Precisec                       e Zd Z fdZi fdefdZi fdee         fdZd2d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di fdededefdZd2dedefdZddi fdedededee         fdZdefdZi fdefdZd Zd2d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i fdede!fdZ$dddi fde!dededee         fdZ%dddi fde!dededee         fdZ&dddi fde!dedefd Z'd3d$e(d%e(d&e(fd'Z)i fd(efd)Z*d2d*e+d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.d/i ddfd0Z0d1 Z1 xZ2S )4lykkec                    |                      t          t          |                                           dddgddi dd ddd	d
dd
dd
dd
dddddddd
dd
dd
dd
dddd
dd
ddi dd
dd
dddddd
dddd
d d
d!d
d"d
d#d
d$d
d%d
d&d
d'dd(d
d)di d*d d+d
d,dd-dd.dd/d
d0d
d1d
d2d
d3d
d4dd5dd6d
d7dd8d
d9d
d:d
d;d
d
d
dd<dd
d=d>d?d?d@dAdBdCgdDdEdFdGdGdGdGdGdGdGdGdGdH	idGdGdGdIdIdIdGdGdGdJ	dIdIdIdGdGdKdIdIdLdMd@dNd
ddOdOdPit          i dQt
          dRt
          dSt
          dTt          dUt          dVt          dWt
          dXt          dYt
          dZt          d[t          d\t          d]t
          d^t          d_t          d`t          dat          t          t          t          t          t          t          t          t          t          t
          db
i dci dd          S )eNr    LykkeUK2   CORSspotTmarginFswapfutureoptioncancelAllOrderscancelOrdercreateOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrder	editOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositsfetchDepositsWithdrawalsfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchOrderTradesfetchPositionModefetchPositionsfetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeesemulated)fetchTransactionsfetchWithdrawalssetLeveragesetMarginModewithdraw)apiKeysecretzdhttps://user-images.githubusercontent.com/1294454/155840500-1ea4fdf0-47c0-4daa-9597-c6c1cd51b9ec.jpgzhttps://hft-apiv2.lykke.com/api)publicprivatezhttps://www.lykke.comz1https://hft-apiv2.lykke.com/swagger/ui/index.htmlz'https://lykkecity.github.io/Trading-APIzWhttps://support.lykke.com/hc/en-us/articles/115002141125-What-are-the-fees-and-charges-)logoapiwwwdocfeesgetg      @)	
assetpairszassetpairs/{id}assetszassets/{id}isalive
orderbookstickerspricesztrades/public/{assetPairId}   )	balancetradesztrades/order/{orderId}zorders/activezorders/closedorders/{orderId}
operationsoperations/deposits/addressesz'operations/deposits/addresses/{assetId})zorders/limitzorders/marketzorders/bulkoperations/withdrawalsrt   )ordersrr   )rh   postdeletetradingr   )	tierBased
percentagemakertaker10011100110120002001220220032004200520062007200820092010201120122013)
2014201520162017201820192020202120222023)exactbroad)idname	countriesversion	rateLimithasrequiredCredentialsurlsrd   rg   precisionMode
exceptionscommonCurrencies)deep_extendsuperr    describer   r   r   r   r   r   r   )self	__class__s    ^/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/lykke.pyr   zlykke.describe   s8   eT 2 2 ; ; = = 999 %9 	9
 %9 %9 "49 t9 t9 '9 (9 "59 U9 9 +E9  )%!9" $T#9 9$ '%9& ('9( "4)9* &t+9,  -9. +D/90 &u192 #E394 *5596 $U798 "599: *5;9< +E=9> "5?9@ A9B !%C9D  E9 9 9F dG9H +EI9J "4K9L dM9N !$O9P uQ9R #ES9T $UU9V !%W9X )%Y9Z t[9\ ]9^ U_9` ta9b "5c9d #Ee9f 'g9 9h &0$)$!& q9 9 9v $ $
 ?@  /G= r  &)+."%'*#&&)#&"%7:
 
 $'"%25)*)*,-&)9<CF
 
 )*)*'(259<  #$,- ' & &P !&"&	  'MM M J	
 - , M L M - - - M - L  L!" L#$ )(((((((()7  : = @!Ge@
 e@
 e e e	    returnc                   K   |                      |           d{V }|                     |dg           }i }t          dt          |                    D ]/}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|
dk    rd	nd
}|                     |d          }|                     |d          }|                     |d          }| }|||||	|||d|                     |                     |                     |d                              |                     |d          dd|                     |d          dddi d||<   1|S )a  
        fetches all available currencies on an exchange
        :see: https://lykkecity.github.io/Trading-API/#get-all-assets
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        Npayloadr   assetIdsymbolr   type
erc20TokencryptootherblockchainDepositEnabledblockchainWithdrawal
isDisabledaccuracycashoutMinimalAmountminmaxlowVolumeAmount)r^   amount)r   codeinfor   r   activedepositr^   fee	precisionlimitsnetworks)publicGetAssets
safe_valuerangelensafe_stringparse_numberparse_precision)r   paramsresponse
currenciesresulticurrencyr   r   r   rawTyper   r   r^   r   r   s                   r   fetch_currencieszlykke.fetch_currencies   s      --f55555555__Xy"==
> q#j//** !	 !	A!!}H!!(I66B##Hh77D##Hf55D&&x88G '< 7 788gDooh0JKKGx1GHHH<@@J#^F  "$!..t/C/CDDTDTU]_iDjDj/k/kll  $x9OPP#! !
  $x9JKK# 	 	 + F4LL. r   c                   K   |                      |           d{V }|                     |dg           }g }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                    d          \  }}|                     |          }|                     |          }|dz   |z   }|                    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"d|d#
           |S )$a  
        retrieves data on all markets for lykke
        :see: https://lykkecity.github.io/Trading-API/#get-asset-by-id
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nr   r   assetPairIdr   baseAssetIdquoteAssetId/r   r   basequotebaseIdquoteIdsettlesettleIdr   r'   Tr(   Fr)   r*   r+   contractr   linearbaseAssetAccuracypriceAccuracy)r   price	minVolumer   minOppositeVolume)r   r   costleverage)
inversecontractSizeexpiryexpiryDatetimestrike
optionTyper   r   createdr   )publicGetAssetpairsr   r   r   r   splitsafe_currency_codeappendr   r   safe_number)r   r   r   marketsr   r   marketr   r   r   r   r   r   r   r   r   s                   r   fetch_marketszlykke.fetch_markets
  s      11&99999999//(Ir::& q#g,,'' :	 :	AQZF!!&-88B##FF33D**6=AAK++FNCCL"jjooOFG**622D++G44ECZ%'FMM 0b0&0 0 	0
 +0 <0 $0 D0 0 0 %0 0 %0 %0 E0  $!0" $#0$   $"&""//0D0DTEUEUV\^qErEr0s0stt!..t/C/CDDTDTU[]lDmDm/n/noo   $//DD# 
  $# 
  $//8KLL# 
  $#! ! $  _0 0 0 0 0 0 0b r   Nr   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          |d|          S )Nr   	lastPricer   	timestampdatetimehighlowbid	bidVolumeask	askVolumevwapopencloselastpreviousClosechangepriceChanger{   average
volumeBasevolumeQuote)
baseVolumequoteVolumer   )r   safe_marketsafe_tickeriso8601)r   tickerr   r   marketIdr  s         r   parse_tickerzlykke.parse_tickerc  s   R 	##FM::!!(F33  55 !
d&&vx88!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 U!
 E!
 T!
 d&&v}==!
  $!!
" t#!
$ **6<@@++FMBB)!
 !
 !
* +  	r   r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     | j        dd          }d}|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |dg           }|                     |                     |di           |          S )	a5  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: https://lykkecity.github.io/Trading-API/#get-current-prices
        :see: https://lykkecity.github.io/Trading-API/#24hr-ticker-price-change-statistics
        :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>`
        NassetPairIdsr   fetchTickerMethodpublicGetTickerspublicGetPricesr   r   )	load_marketsr   r   optionsr  extendr  r   r  )r   r   r   r   requestmethodr   r  s           r   fetch_tickerzlykke.fetch_ticker  s!      !!!!!!!!!V$$F4L
 !!$,0CEWXX&&&!11$++gv2N2NOOOOOOOOHH!224;;w3O3OPPPPPPPPH9b99D   B!?!?HHHr   symbolsc                    K   |                                   d{V  |                     |           d{V }|                     |dg           }|                     ||          S )a,  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://lykkecity.github.io/Trading-API/#24hr-ticker-price-change-statistics
        :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>`
        Nr   )r  r  r   parse_tickers)r   r!  r   r   rm   s        r   fetch_tickerszlykke.fetch_tickers  s~       !!!!!!!!!..v66666666//(Ir::$ !!'7333r   limitc           	        K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     |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://lykkecity.github.io/Trading-API/#asset-pair-order-book-ticker
        :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   depthr   r   r   r   bidsaskspv)r  r   publicGetOrderbooksr  r   safe_integerparse_order_book)
r   r   r%  r   r   r  r   r   	orderbookr   s
             r   fetch_order_bookzlykke.fetch_order_book  s       !!!!!!!!!V$$6$<
 $GG11$++gv2N2NOOOOOOOO//(Ir::0 OOGQ33	%%i==	$$Yx0@)VU[]`befffr   c                    |                      |d          }|                     ||          }|d         }|                     |dd          }|                      |d          }|                     |d          }|                     |dd          }|                     |dd          }	|	|                     |d	d          }	|                     |d
          }
|                     ||||                     |          |d ||
d ||	d d d|          S )Nr   r   r   orderIdr   r   volumer   r  side)r   r   r   r   r   r   orderr4  takerOrMakerr   r   r   r   )r   r  safe_string_2r-  safe_string_lower
safe_trader  )r   trader   r  r   r   r2  r   r   r   r4  s              r   parse_tradezlykke.parse_trade+  s0   : ##E=99!!(F33!tT22""5)44%%e[99	""5'7;;##E8X>>>''|XFFF%%eV44"Y//  
  
   	r   sincec                 B  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a&  
        get the list of most recent trades for a particular symbol
        :see: https://lykkecity.github.io/Trading-API/#get-public-trades
        :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   taker   )r  r    publicGetTradesPublicAssetPairIdr  r   parse_trades)	r   r   r<  r%  r   r   r  r   r   s	            r   fetch_tradeszlykke.fetch_tradesc  s       !!!!!!!!!V$$6$<
 #GFO>>t{{7TZ?[?[\\\\\\\\9b99    >>>r   c                 x   d|i}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                                 }|                     |d          }|                     |d          }	||d<   |	|d<   |||<   |                     |          S )Nr   r   r   	availablereservedfreeused)r   r   r   r   accountsafe_balance)
r   r   r   r   rp   
currencyIdr   rG  rE  rF  s
             r   parse_balancezlykke.parse_balance  s     (#q#h--(( 		# 		#AqkG))'9==J**:66DllnnG##G[99D##GZ88D"GFO"GFO"F4LL  (((r   c                    K   |                                   d{V  |                     |           d{V }|                     |dg           }|                     |          S )ap  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://lykkecity.github.io/Trading-API/#get-the-current-balance
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        Nr   )r  privateGetBalancer   rJ  )r   r   r   r   s       r   fetch_balancezlykke.fetch_balance  s|       !!!!!!!!!//77777777//(Ir:: !!'***r   c           
      H    dddddddddd	}|                      |||          S )Nr  closedcanceledrejected)	OpenPendingInOrderBook
ProcessingMatched	CancelledRejectedReplacedPlaced)r   )r   statusstatusess      r   parse_order_statuszlykke.parse_order_status  sC    ! #""

 

 &&999r   c           	      ,   |                      |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|          S )Nr   r[  r   r   lastTradeTimestampr   r   r4  r3  remainingVolumefilledVolumer   r   clientOrderIdr   r   timeInForcepostOnly	stopPricetriggerPricer   r  )filled	remainingr[  r   rq   )r   r]  safe_symbolr8  r-  
safe_orderr  )r   r5  r   r   r[  r  r   r   r_  r   r   r4  r   rh  rg  r   s                   r   parse_orderzlykke.parse_order  s;   " eT**(()9)9%)J)JKK##E=99!!(F33%%eV44!..u6JKK%%e[99	  00%%eV44!!%22$$U,=>>	!!%88v..  
E 
" 
 T 
 	 

 Y// 
 !"4 
 f 
 D 
 4 
  
 D 
 U 
  
 D 
 f 
  D! 
" t# 
$ "- 
  
  
. /  	r   r   r4  r   r   c                 ~  K   |                                   d{V  |                     |          }|d         |                     |          t          |                     |d         |                    d}|dk    r,t          |                     |d         |                    |d<   d}	|                     |          dk    r0|                     |                     ||                     d{V }	n/|                     |                     ||                     d{V }	| 	                    |	d          }
| 
                    |
d	          }|d
k    r|                     |
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i|          S )a  
        create a trade order
        :see: https://lykkecity.github.io/Trading-API/#place-a-limit-order
        :see: https://lykkecity.github.io/Trading-API/#place-a-market-order
        :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
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r   )r   r4  r3  r%  r   r
   r   r2  r   r   rb  r   r   r_  r   r4  r   r   r  rg  rh  r[  r   rq   )r  r   
capitalizefloatamount_to_precisionprice_to_precisionprivatePostOrdersMarketr  privatePostOrdersLimitr   r   r   rj  )r   r   r   r4  r   r   r   r   queryr   r   r   s               r   create_orderzlykke.create_order  s|      !!!!!!!!!V$$!$<OOD))D44VH5EvNNOO
 

 7??"4#:#:6(;KU#S#STTE'N??4  H,,77E68R8RSSSSSSSSFF66t{{5&7Q7QRRRRRRRRF* //&)44gy118$$Wg66E  
" 
F 
 T 
 	 

  
 !$ 
 fX& 
 D 
 D 
 U 
 f 
 D 
 t 
 d 
  
  d! 
" 4# 
$ d% 
  
& '  	r   r   c                 l   K   d|i}|                      |                     ||                     d{V S )a  
        cancels an open order
        :see: https://lykkecity.github.io/Trading-API/#cancel-orders-by-id
        :param str id: order id
        :param str symbol: unified symbol of the market the order was made in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r2  N)privateDeleteOrdersOrderIdr  )r   r   r   r   r  s        r   cancel_orderzlykke.cancel_orderF  sJ       r
 44T[[&5Q5QRRRRRRRRRr   c                    K   |                                   d{V  i }d}| |                     |          }|d         |d<   |                     |                     ||                     d{V S )a  
        cancel all open orders
        :see: https://lykkecity.github.io/Trading-API/#mass-cancel-orders
        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r   )r  r   privateDeleteOrdersr  )r   r   r   r  r   s        r   cancel_all_orderszlykke.cancel_all_ordersZ  s       !!!!!!!!!
 [[((F%+D\GM" --dkk'6.J.JKKKKKKKKKr   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |d          }|                     |          S )ap  
        fetches information on an order made by the user
        :see: https://lykkecity.github.io/Trading-API/#get-order-by-id
        :param str symbol: not used by lykke fetchOrder
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr2  r   )r  privateGetOrdersOrderIdr  r   rk  )r   r   r   r   r  r   r   s          r   fetch_orderzlykke.fetch_orderr  s       !!!!!!!!!r
 55dkk'66R6RSSSSSSSS//(I66( (((r   c                 8  K   |                                   d{V  d}||                     |          }i }|||d<   |                     |                     ||                     d{V }|                     |d          }|                     ||||          S )a  
        fetch all unfilled currently open orders
        :see: https://lykkecity.github.io/Trading-API/#get-active-or-closed-orders
        :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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr>  r   )r  r   privateGetOrdersActiver  r   parse_orders	r   r   r<  r%  r   r   r  r   r   s	            r   fetch_open_orderszlykke.fetch_open_orders         !!!!!!!!![[((F
 #GFO44T[[&5Q5QRRRRRRRR//(I66,   &%???r   c                 8  K   |                                   d{V  d}||                     |          }i }|||d<   |                     |                     ||                     d{V }|                     |d          }|                     ||||          S )aG  
        fetches information on multiple closed orders made by the user
        :see: https://lykkecity.github.io/Trading-API/#get-active-or-closed-orders
        :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
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Nr>  r   )r  r   privateGetOrdersClosedr  r   r  r  s	            r   fetch_closed_orderszlykke.fetch_closed_orders  r  r   c                 \  K   |                                   d{V  i }d}|||d<   | |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |d          }|                     ||||          S )a  
        fetch all trades made by the user
        :see: https://lykkecity.github.io/Trading-API/#get-trade-history
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Nr>  r   r   fromr   )r  r   privateGetTradesr  r   r@  )	r   r   r<  r%  r   r  r   r   r   s	            r   fetch_my_tradeszlykke.fetch_my_trades  s       !!!!!!!!!
 #GFO[[((F%+D\GM"#GFO..t{{7F/K/KLLLLLLLL//(I66,   &%???r   r   ro      priceKey	amountKeycountOrIdKeyc                     |                      ||          }t          j        |                      ||                    }|                     |          |                     |          gS N)r   r   
string_absr   )r   bidaskr  r  r  r   r   s          r   parse_bid_askzlykke.parse_bid_ask!  s^      22#D$4$4VY$G$GHH!!%(($*;*;F*C*CDDr   r   c                   K   |                                   d{V  |                     |          }d|                     |d          i}|                     |                     ||                     d{V }|                     |d          }|                     |d          }|                     |           |||d|dS )a  
        fetch the deposit address for a currency associated with self account
        :see: https://lykkecity.github.io/Trading-API/#get-deposit-address-for-a-given-asset
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr   r   baseAddressaddressExtension)r   addresstagnetworkr   )r  r   r   ,privateGetOperationsDepositsAddressesAssetIdr  check_address)r   r   r   r   r  r   r  r  s           r   fetch_deposit_addresszlykke.fetch_deposit_address&  s       !!!!!!!!!==&&t''$77
 JJ4;;W^`fKgKghhhhhhhh ""8];;x);<<7###
 
 	
r   r   c                 (   d }d }d }d }d }d }d }	t          |t                    r|}n|                     |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S )NoperationIdr   totalVolumer   r   r   )r   r   r   r   txidr   r  addressFromr  	addressTotagFromr  tagTor   r   r[  updated)internalcommentr   )
isinstancestrr   r   r   r-  r  )r   transactionr   r   r   r   r   r   r   r   feeCosts              r   parse_transactionzlykke.parse_transactionI  s    	k3'' 	BB!!+}==B&&{I>>G**7H==D%%k=AAF##K88D))+{CCI&&{E::G  C
K
"
 D
 	

 Y//
 t
 4
 t
 
 t
 4
 T
 D
 f
 
  d!
" t#
$ )
 
 
 	
r   c                 :  K   |                                   d{V  i }|||d<   |                     |                     ||                     d{V }|                     |dg           }d}||                     |          }|                     ||||          S )a  
        fetch history of deposits and withdrawals
        :see: https://lykkecity.github.io/Trading-API/#get-the-history-of-withdrawals-and-deposits
        :param str [code]: unified currency code for the currency of the deposit/withdrawals, default is None
        :param int [since]: timestamp in ms of the earliest deposit/withdrawal, default is None
        :param int [limit]: max number of deposit/withdrawals to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr>  r   )r  privateGetOperationsr  r   r   parse_transactions)	r   r   r<  r%  r   r  r   r   r   s	            r   fetch_deposits_withdrawalsz lykke.fetch_deposits_withdrawals  s       !!!!!!!!!
 #GFO224;;w3O3OPPPPPPPP//(Ir::  }}T**H&&w%GGGr   c                   K   |                                   d{V  |                     |           |                     |          }|d         t          |                     ||                    |d}|||d<   |                     |                     ||                     d{V }|                     ||          S )a  
        make a withdrawal
        :see: https://lykkecity.github.io/Trading-API/#withdrawal
        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr   )r   r3  destinationAddressdestinationAddressExtension)r  r  r   rn  currency_to_precision privatePostOperationsWithdrawalsr  r  )	r   r   r   r  r  r   r   r  r   s	            r   r^   zlykke.withdraw  s       !!!!!!!!!7###==&&~D66tVDDEE")
 
 ?58G12>>t{{7TZ?[?[\\\\\\\\ %%h999r   ra   GETc                 "   | j         d         |         dz   |                     ||          z   }|                     ||                     |                    }ddd}|dk    r|r|d|                     |          z   z  }n|dk    r|dk    s|d	k    r|r|d|                     |          z   z  }|                                  d
| j        z   |d<   |dk    r|r|                     |          }|dk    r|                                 |d<   ||||dS )Nrd   r   zapplication/json)AcceptzContent-Typera   ?rb   r  DELETEzBearer AuthorizationPOSTru   zX-Request-ID)urlr  bodyheaders)	r   implode_paramsomitextract_params	urlencodecheck_required_credentialsr_   jsonuuid)	r   pathrd   r  r   r  r  r  rs  s	            r   signz
lykke.sign  sG   is#c)D,?,?f,M,MM		&$"5"5d";";<<(.
 
 (?? 3sT^^E2222I%Vx%7%7 73!6!666C++---'04;'>GO$ -99V,,D///*.))++'fdwOOOr   c
                 d   |d S |                      |di           }
|                     |
d          }|||dk    rv| j        dz   |z   }|                     |
d          }|                     | j        d         ||           |                     | j        d         ||           t          |          d S )Nerrorr   0 messager   r   )r   r   r   throw_exactly_matched_exceptionr   throw_broadly_matched_exceptionr   )r   r   reasonr  r  r  r  r   requestHeadersrequestBodyr  	errorCodefeedbackr  s                 r   handle_errorszlykke.handle_errors  s    4'266$$UF33	!	S(8(8w}t+H&&ui88G001I9V^___001I7T\]]])))tr   r  )r   ro   r  )3__name__
__module____qualname__r   r   r   r   r
   r   r   r  r  r   r   r   r$  r	   r   r0  r   r;  rA  r   rJ  rM  r]  r   rk  r   r   rn  r   rt  r   rw  rz  r}  r  r  r  r   r  r  r   r   r  r  r^   r  r  __classcell__)r   s   @r   r    r       sl       f f f f fP -/ J J: J J J JX *, W WV W W W WrB B6 BV B B B BH 68 7I 7I 7IF 7I 7I 7I 7Ir 6:" 4 47 4 4 4 4 4< @DB +g +gS +g +gS\ +g +g +g +gZ6 6 65 6 6 6 6p <@d[] #? #? #?S #? #?bfglbm #? #? #? #?J) ) ) ) )0 *, + + + + + +2: : :5 5 55 5 5 5 5n mqy{ F F FI FY FX] Ffi F F F FP 9=R S SS S# S S S S( 59 L Lc L L L L0 8<B !) !)C !) !) !) !) !)F 59tZ^gi +@ +@c +@ +@TW +@nrsxny +@ +@ +@ +@Z 7;\`ik +@ +@ +@3 +@VY +@ptuzp{ +@ +@ +@ +@Z 37TX\eg 0@ 0@C 0@s 0@RU 0@ 0@ 0@ 0@dE Ei E	 Een E E E E
 =? !
 !
 !
 !
 !
 !
F9
 9
x 9
; 9
 9
 9
 9
v <@daenp %H %HS %H %H[^ %Huy  {F  vG %H %H %H %HN EIQS : :3 : : : : :8 &eBSW P P P P.      r   r    N)$ ccxt.async_support.base.exchanger   ccxt.abstract.lykker   ccxt.base.typesr   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   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r     r   r   <module>r     s   6 5 5 5 5 5 + + + + + + s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s  s       * * * * * * ' ' ' ' ' ' . . . . . . ) ) ) ) ) ) - - - - - - ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %U U U U UHk U U U U Ur   