
    !:hH                         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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   G d	 d
ee      Z!y)    )Exchange)ImplicitAPI)AccountAnyBalancesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterface)List)ExchangeError)ArgumentsRequired)	TICK_SIZE)Precisec                   0    e Zd Zdef fdZi fdee   fdZi fdee   fdZ	de
fdZi fde
fdZdi fded	edefd
ZdefdZd>dede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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dee   fdZd>dededefdZdi fdedefdZi fdedefdZ d>dedede!fdZ"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$d>dede%fd"Z&dddi fdeded	efd#Z'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ddi fd+efd,Z0dddi fd+eded	edee1   fd-Z2d. Z3d>d/e4de1fd0Z5i fd+ede6fd1Z7i fd+ede6fd2Z8d>d/e4de6fd3Z9d4d5i ddfd6Z:d7e;d8ed9ed:ed;ed<efd=Z< xZ=S )?lunoreturnc                  @   | j                  t        t        |          ddg 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	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	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@g dAdBdCdDdEiidCdFdEiidCdEdEdEdEdEdGidEdEdEdEdEdEdEdEdEdEdEdEdEdHdEdEdEdEdEdEdEdEdEdEdI
dJdEidEdEdKdLdMdNdOdPdQdRdSdTdUdVdWdX
dYdd| j	                  dZ      | j	                  d[      d\it
        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dad	d	d	d	dbd	d_d	d	d	dcd	d_d`d d	d	d	ddd	d_d`dEd d	d	d	dedfd idg	d d dhd d dhdidj      S )kNr   )GBSGZA   1TCORSspotmarginFswapfutureoption	addMargincancelOrdercloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreateReduceOnlyOrderfetchAccountsfetchBalancefetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositAddressfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchTickerfetchTickersfetchTrades)fetchTradingFeefetchTradingFeesreduceMarginsetLeveragesetMarginModesetPositionModez"https://www.luno.com/invite/44893Azchttps://user-images.githubusercontent.com/1294454/27766607-8c1a69d8-5ede-11e7-930c-540b5eb9be24.jpgzhttps://api.luno.com/apiz!https://api.luno.com/api/exchange)publicprivateexchangeexchangePrivatezhttps://www.luno.com)zhttps://www.luno.com/en/apizhttps://npmjs.org/package/bitxz&https://github.com/bausmeier/node-bitx)referrallogoapiwwwdocgetmarkets   candles)	orderbookorderbook_toptickertickerstrades)zaccounts/{id}/pendingzaccounts/{id}/transactionsbalancebeneficiariesfee_infofunding_address
listorders
listtradessend_feezorders/{id}withdrawalswithdrawals/{id}	transfers)
accountszaddress/validate	postordermarketorder	stoporderrt   rx   sendzoauth2/grantrr   zaccounts/{id}/name)ry   zbeneficiaries/{id})rh   postputdelete)ra   rb   r_   r`   <   i,  i  i  i  i0*  i@8  iQ i i:	 )
1m5m15m30m1h3h4h1d3d1wtradingz0.0010)	tierBased
percentagetakermaker)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventioniceberg  i )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r   )r   r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   daysBackCanceledr   r   r   r   r   )	sandboxr1   createOrdersrG   rK   rJ   rM   r6   rH   )linearinverse)r'   r)   r*   )idname	countries	rateLimitversionprohasurlsre   
timeframesfeesprecisionModefeatures)deep_extendsuperr   describeparse_numberr   )self	__class__s    Q/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/async_support/luno.pyr   zluno.describe   s"   dD : <+::: %: 	:
 %: %: U: t: $U:  : ': t: (:  : :  )%!:" $T#:$ '%:& (':( &t):* &u+:, #E-:. *5/:0 $U1:2 "53:4 *55:6 +E7:8 t9::  ;:< %e=:> "5?:@ A:B !%C:D  E:F dG:H +EI:J "4K:L dM:N !$O:P tQ:R  S:T 'U:V $UW:X !%Y:Z *5[:\ (]:^ %e_:` )%a:b tc:d e:f tg:h $($) %$!&#(s:x A}89 C'J	 .$ !1 !1$ %&)*"##$"# 2367#$)*$%+,&'&'$%'('(,-%&. %&,-%&'(%&+,'( !())* -a -../O+)@D  !%"&!..w7!..s3	 '  %&+(,,0,0).+06:#'#'"&#(	( #($)$)+/27/4#()$, %)&+!%$*%+*.& ',#($)*/	# ',!%#($)*/( ',!%$*%)#($)*/$ ',!%$*,-%)#($)*/	*  #ACJ ##
 ##SMSw?
 w w	    c                   K   | j                  |       d{   }g }| j                  |dg       }t        dt        |            D ]|  }||   }| j	                  |d      }| j	                  |d      }| j	                  |d      }	| j                  |      }
| j                  |	      }| j	                  |d      }|j                  i d|d	|
d
z   |z   d|
d|ddd|d|	ddddddddddddddd|dk(  dddddddddd| j                  | j                  | j	                  |d                  | j                  | j                  | j	                  |d                  dddd | j                  |d!      | j                  |d"      d | j                  |d#      | j                  |d$      d ddd d%d|d&
        |S 7 w)'a!  
        retrieves data on all markets for luno

        https://www.luno.com/en/developers/api#tag/Market/operation/Markets

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nri   r   	market_idbase_currencycounter_currencytrading_statusr   symbol/basequotesettlebaseIdquoteIdsettleIdtyper'   Tr(   Fr)   r*   r+   activeACTIVEcontractr   volume_scaleprice_scale)amountprice)minmax
min_volume
max_volume	min_price	max_price)r   r   r   cost)
r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)
exchangeGetMarkets
safe_valuerangelensafe_stringsafe_currency_codeappendr   parse_precisionsafe_number)r   paramsresponseresultri   imarketr   r   r   r   r   statuss                r   fetch_marketszluno.fetch_markets  s     0088( //(Ir:q#g,' 8	AQZF!!&+6B%%fo>F&&v/ABG**62D++G4E%%f.>?FMM 0b0$*u,0 0 	0
 $0 &0 70 D0 0 0 %0 0 %0 %0 6X-0  E!0" $#0$   $"&""//0D0DTEUEUV\^lEm0no!..t/C/CDDTDTU[]jDk/lm  $#!
  $//E#//E
  $//D#//D
  $#$  _0 08	r _ 9s   GGF1Gc                 B  K   | j                  |       d{   }| j                  |dg       }g }t        dt        |            D ]R  }||   }| j	                  |d      }| j	                  |d      }| j                  |      }	|j                  |d|	|d       T |S 7 w)as  
        fetch all the accounts associated with a profile

        https://www.luno.com/en/developers/api#tag/Accounts/operation/getBalances

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        Nrq   r   
account_idasset)r   r   currencyr   )privateGetBalancer   r   r   r   r   r   )
r   r   r   walletsr   r   account	accountId
currencyIdcodes
             r   fetch_accountszluno.fetch_accountsf  s      //77//(Ir:q#g,' 
	AajG((,?I))'7;J**:6DMM 	 
	  8s   BBBBc                 n   | j                  |dg       }|d d d}t        dt        |            D ]  }||   }| j                  |d      }| j	                  |      }| j                  |d      }| j                  |d      }	| j                  |d      }
t        j                  ||	      }t        j                  |
|	      }||v rEt        j                  ||   d   |      ||   d<   t        j                  ||   d   |      ||   d<   | j                         }||d<   ||d<   |||<    | j                  |      S )	Nrq   )r   	timestampdatetimer   r   reservedunconfirmedusedtotal)	r   r   r   r   r   r   
string_addr  safe_balance)r   r   r   r   r   walletr  r  r	  r
  rq   reservedUnconfirmedbalanceUnconfirmedr  s                 r   parse_balancezluno.parse_balance  sR   //(Ir:

 q#g,' 	'AQZF))&':J**:6D''
;H**6=AK&&vy9G")"4"4X{"K!(!3!3G[!Iv~'.'9'9&,v:NPc'dtV$(/(:(:6$<;PRd(etW%,,."5#5 &t!	'"   ((r   c                    K   | j                          d{    | j                  |       d{   }| j                  |      S 7 .7 w)au  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://www.luno.com/en/developers/api#tag/Accounts/operation/getBalances

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        N)load_marketsr   r  )r   r   r   s      r   fetch_balancezluno.fetch_balance  sI      !!!//77 !!(++ 	"7s   A	AA	AA	A	Nr   r   c           	        K   | j                          d{    | j                  |      }d|d   i}d}|/|dk  r*| j                  | j                  ||             d{   }n)| j	                  | j                  ||             d{   }| j                  |d      }| j                  ||d   |ddd	d
      S 7 7 \7 4w)a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://www.luno.com/en/developers/api#tag/Market/operation/GetOrderBookFull
        https://www.luno.com/en/developers/api#tag/Market/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
        Npairr   d   r  r   bidsasksr   volume)r  r   publicGetOrderbookTopextendpublicGetOrderbooksafe_integerparse_order_book)r   r   r   r   r   requestr   r  s           r   fetch_order_bookzluno.fetch_order_book  s      !!!V$F4L
 #!77GV8TUUH!44T[[&5QRRH%%h<	$$Xvh/?FTZ\cemnn 	" VRs4   CB;A	C B=!)C
B?1C=C?Cr   c                 0    ddi}| j                  |||      S )NPENDINGopen)r   )r   r   statusess      r   parse_order_statuszluno.parse_order_status  s'     v
 &&99r   orderr   c                    | j                  |d      }| j                  | j                  |d            }|dk(  r|n|}d }| j                  |d      }|dk(  s|dk(  rd}n|dk(  s|d	k(  rd
}| j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }	| j	                  |d      }
| j	                  |d      }| j                  |d      }| j                  |d      }d }|
	|
|d   d}n
|||d   d}| j                  |d      }| j                  i d|dd d| j                  |      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creation_timestampstater%  r   ASKSELLsellBIDBUYbuyr  limit_pricelimit_volumefee_counterfee_baser   counterr   r   r   order_idr   clientOrderIdr  r  lastTradeTimestampr   r   r   postOnlysider   r   r   filledr   	remaining)rp   feer   average)r  r'  r   safe_marketr   
safe_orderiso8601)r   r(  r   r  r   r<  	orderTypemarketIdr   r   quoteFeebaseFeer=  r   r?  r   s                   r   parse_orderzluno.parse_order  s^   $ %%e-AB	(()9)9%)IJ"f,6$$UF3	I$7D5 i5&8D##E62!!(F3  6!!%8##E=9""5*5!!%0y1 "7OC  "6NC eZ0  
" 
T 
 Y/ 
 	 

 !$ 
 f 
 fX& 
 D 
 4 
  
 D 
 U 
 D 
 f 
 f 
  D! 
" # 
$ + 
, - 	r   r   c                    K   | j                          d{    d|i}| j                  | j                  ||             d{   }| j                  |      S 7 B7 w)a  
        fetches information on an order made by the user

        https://www.luno.com/en/developers/api#tag/Orders/operation/GetOrder

        :param str id: order id
        :param str symbol: not used by luno fetchOrder
        :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  privateGetOrdersIdr  rH  r   r   r   r   r!  r   s         r   fetch_orderzluno.fetch_order  sc      !!!"
 00Wf1MNN)) 	" Os!   AA,AAAAr+  sincec                 .  K   | j                          d {    i }d }|||d<   || j                  |      }|d   |d<   | j                  | j                  ||             d {   }| j	                  |dg       }	| j                  |	|||      S 7 z7 -w)Nr+  r   r  orders)r  r   privateGetListordersr  	safe_listparse_orders)
r   r+  r   rM  r   r   r!  r   r   rO  s
             r   fetch_orders_by_statezluno.fetch_orders_by_state)  s     !!!$GG[[(F$TlGFO224;;w3OPP(B7  >> 	" Qs"   BBAB%B&,BBc                 H   K   | j                  d||||       d{   S 7 w)a>  
        fetches information on multiple orders made by the user

        https://www.luno.com/en/developers/api#tag/Orders/operation/ListOrders

        :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>`
        NrS  r   r   rM  r   r   s        r   fetch_orderszluno.fetch_orders6  s'      //feUFSSSS   " "c                 H   K   | j                  d||||       d{   S 7 w)a  
        fetch all unfilled currently open orders

        https://www.luno.com/en/developers/api#tag/Orders/operation/ListOrders

        :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>`
        r$  NrU  rV  s        r   fetch_open_orderszluno.fetch_open_ordersD  s(      //	65%QWXXXXrX  c                 H   K   | j                  d||||       d{   S 7 w)aE  
        fetches information on multiple closed orders made by the user

        https://www.luno.com/en/developers/api#tag/Orders/operation/ListOrders

        :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>`
        COMPLETENrU  rV  s        r   fetch_closed_orderszluno.fetch_closed_ordersR  s(      //
FE5RXYYYYrX  rn   c                    | j                  |d      }| j                  |d      }| j                  ||      }| j                  |d      }| j                  i d|d|d| j	                  |      dd dd d| j                  |d      d	d d
| j                  |d
      dd dd dd d|d|dd dd dd dd | j                  |d      d |d|      S )Nr  r  
last_trader   r  highlowbid	bidVolumeask	askVolumevwapr%  closelastpreviousClosechanger   r@  rolling_24_hour_volume)
baseVolumequoteVolumer   )r  r   safe_symbolsafe_tickerrC  )r   rn   r   r  rE  r   rh  s          r   parse_tickerzluno.parse_ticker`  sr    %%fk:	##FF3!!(F35 !
f!
!
 Y/!
 D	!

 4!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **63KL)!
* + 	r   symbolsc                   K   | j                          d{    | j                  |      }| j                  |       d{   }| j                  |d   d      }t	        |j                               }i }t        dt        |            D ]7  }||   }| j                  |      }	|	d   }
||   }| j                  ||	      ||
<   9 | j                  |d|      S 7 7 w)a"  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://www.luno.com/en/developers/api#tag/Market/operation/GetTickers

        :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>`
        Nro   r  r   r   )r  market_symbolspublicGetTickersindex_bylistkeysr   r   rA  rp  filter_by_array_tickers)r   rq  r   r   ro   idsr   r   r   r   r   rn   s               r   fetch_tickerszluno.fetch_tickers  s      !!!%%g...v66-- 3V<7<<>"q#c(# 	?AQB%%b)FH%FR[F!..vv>F6N	? ++FHgFF 	"6s"   CC)C CBCCc                    K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  ||      S 7 W7 w)a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://www.luno.com/en/developers/api#tag/Market/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   publicGetTickerr  rp  r   r   r   r   r!  r   s         r   fetch_tickerzluno.fetch_ticker  sy      !!!V$F4L
 --dkk'6.JKK   622 	"
 L"   A2A.A A2A0A20A2tradec                    | j                  |d      }| j                  |d      }d }d }|H| j                  |d      }|dk(  s|dk(  rd}n|dk(  s|dk(  rd	}|dk(  r|d
   rd}n|d	k(  r|d
   sd}nd}n	|d
   rd	nd}| j                  |d      }| j                  |d      }	d }
d }|t        j                  |d      s'|d   }
|}n|	t        j                  |	d      s|d   }
|	}| j                  |d      }| j	                  |||| j                  |      |d   |d ||| j                  |d      | j                  |dd      | j                  |d      ||
dd|      S )Nr8  sequencer   r,  r-  r.  r/  r0  r1  is_buyr   r   r5  r4  0.0r   r   r  r   r   r  r6  r7  )r   r   r  r  r   r(  r   r<  takerOrMakerr   r   r   r?  )r   r   string_equalsr  
safe_traderC  safe_string_2)r   r  r   orderIdr   r  r<  r   feeBaseStringfeeCounterStringfeeCurrencyfeeCostr  s                r   parse_tradezluno.parse_trade  s   B ""5*5eZ0##E62D46>%-TU]v~%/&uX&&!(O5D((
;++E=A$((>$Vn')(()95A$Wo*%%e[9	"Y/X&(%%eW5((&A$$UI6' 
$ % 	r   c                    K   | j                          d{    | j                  |      }d|d   i}|||d<   | j                  | j                  ||             d{   }| j	                  |dg       }| j                  ||||      S 7 s7 -w)a.  
        get the list of most recent trades for a particular symbol

        https://www.luno.com/en/developers/api#tag/Market/operation/ListTrades

        :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   rM  rp   )r  r   publicGetTradesr  rQ  parse_trades	r   r   rM  r   r   r   r!  r   rp   s	            r   fetch_tradeszluno.fetch_trades  s      !!!V$F4L
 $GG--dkk'6.JKK (B7  >>- 	" Ls"   BB
ABB,BBr   c                   K   | j                          d{    | j                  |      }| j                  | j                  ||      |d   d}|| j	                  |      |d<   n*d| j                  |      z  }| j                         |z
  |d<   | j                  | j                  ||             d{   }	| j                  |	dg       }
| j                  |
||||      S 7 7 .w)a  

        https://www.luno.com/en/developers/api#tag/Market/operation/GetCandles

        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :param str symbol: unified symbol of the market to fetch OHLCV data for
        :param str timeframe: the length of time each candle represents
        :param int [since]: timestamp in ms of the earliest candle to fetch
        :param int [limit]: the maximum amount of candles to fetch
        :param dict params: extra parameters specific to the luno api endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr   )durationr  rM  i@B rk   )r  r   r   r   parse_to_intparse_timeframemillisecondsexchangePrivateGetCandlesr  rQ  parse_ohlcvs)r   r   	timeframerM  r   r   r   r!  r  r   ohlcvss              r   fetch_ohlcvzluno.fetch_ohlcv0  s      !!!V$IN4L
 #007GG"T%9%9)%DDH#002X=GG77GV8TUU" )R8  E5II; 	" Vs"   C%C!BC%4C#5-C%#C%c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr  r%  r`  ra  rg  r  )r  r   )r   ohlcvr   s      r   parse_ohlcvzluno.parse_ohlcv\  sn     e[1UF+UF+UE*UG,UH-
 	
r   c                 b  K   |t        | j                  dz         | j                          d{    | j                  |      }d|d   i}|||d<   |||d<   | j	                  | j                  ||             d{   }| j                  |dg       }| j                  ||||      S 7 z7 -w)a  
        fetch all trades made by the user

        https://www.luno.com/en/developers/api#tag/Orders/operation/ListUserTrades

        :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>`
        Nz+ fetchMyTrades() requires a symbol argumentr  r   rM  r   rp   )r   r   r  r   privateGetListtradesr  rQ  r  r  s	            r   fetch_my_tradeszluno.fetch_my_tradesn  s      >#DGG.[$[\\!!!V$F4L
 $GG$GG224;;w3OPP, (B7  >>A 	" Qs"   .B/B+AB/?B- ,B/-B/c                   K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }||| j	                  |d      | j	                  |d      dddS 7 n7 /w)aa  
        fetch the trading fees for a market

        https://www.luno.com/en/developers/api#tag/Orders/operation/getFeeInfo

        :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>`
        Nr  r   	maker_fee	taker_fee)r   r   r   r   r   r   )r  r   privateGetFeeInfor  r   r}  s         r   fetch_trading_feezluno.fetch_trading_fee  s      !!!V$F4L
 //GV0LMM %%h<%%h<
 	
 	"
 Ns"   B	BA B	B.B	B	r   r<  r   r   c                 f  K   | j                          d{    | j                  |      }d|d   i}d}	|dk(  rs|j                         |d<   |dk(  r| j                  |d   |      |d<   n| j                  |d   |      |d	<   | j	                  | j                  ||             d{   }	ne| j                  |d   |      |d
<   | j                  |d   |      |d<   |dk(  rdnd|d<   | j                  | j                  ||             d{   }	| j                  |	|	d   d|      S 7 7 7 !w)a  
        create a trade order

        https://www.luno.com/en/developers/api#tag/Orders/operation/PostMarketOrder
        https://www.luno.com/en/developers/api#tag/Orders/operation/PostLimitOrder

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr  r   r   r   r1  r   counter_volumebase_volumer  r   r/  r,  r8  )r   r   )	r  r   upperamount_to_precisionprivatePostMarketorderr  price_to_precisionprivatePostPostorderrB  )
r   r   r   r<  r   r   r   r   r!  r   s
             r   create_orderzluno.create_order  sV     !!!V$F4L
 8"jjlGFOu},0,D,DVHEUW],^())-)A)A&BRTZ)[&!88Wf9UVVH $ 8 89I6 RGH#66vh7GOGG(,eEGFO!66t{{7F7STTH:& 
  	' 	" W
 Us5   D1D*BD1'D-(A%D1D/D1-D1/D1c                    K   | j                          d{    d|i}| j                  | j                  ||             d{   }| j                  d|i      S 7 D7 w)a  
        cancels an open order

        https://www.luno.com/en/developers/api#tag/Orders/operation/StopOrder

        :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>`
        Nr8  r   )r  privatePostStoporderr  rB  rK  s         r   cancel_orderzluno.cancel_order  so      !!!
 224;;w3OPP H 
  	 	" Qs!   AA,AAAAr  c           	         K   |d}|d}d }|| j                  ||      d}| j                  |||| j                  ||             d {   S 7 w)Nrj   )min_rowmax_row)sumfetch_ledgerr  )r   r  entryr   r   rM  r!  s          r   fetch_ledger_by_entrieszluno.fetch_ledger_by_entries  sb     =E=Exxu-
 &&tUE4;;wPV;WXXXXs   AA	A
Ac                 X  K   | j                          d{    | j                          d{    d}| j                  |d      }| j                  |d      }| j                  |d      }|{|t	        | j
                  dz         | j                  |      }| j                  | j                  d      }	| j                  |	|      }
|
t        | j
                  dz   |z         |
d   }||d}d	}n||t        | j
                  d
z         |||z
  |kD  r|dk  r||z
  }n
|dkD  r||z   }||z
  dkD  rt        | j
                  dz         |||d}| j                  | j                  ||             d{   }| j                  |dg       }| j                  ||||      S 7 7 w7 1w)aj  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://www.luno.com/en/developers/api#tag/Accounts/operation/ListTransactions

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        Nr   r  r  zU fetchLedger() requires a currency code argument if no account id specified in paramsr   z- fetchLedger() could not find account id for r   izS fetchLedger() require both params 'max_row' and 'min_row' or neither to be definedr   z@ fetchLedger() requires the params 'max_row' - 'min_row' <= 1000)r   r  r  transactions)r  load_accountsr   r   r   r   r   ru  r{   r    privateGetAccountsIdTransactionsr  parse_ledger)r   r  rM  r   r   r   r   r  r  accountsByCurrencyCoder  r!  r   entriess                 r   r  zluno.fetch_ledger  s     !!!  """fd+//&)4//&)4:|'  3J  )J  K  K}}T*H%)]]4==*%M"oo&<dCG#DGG.]$]`d$deeB?wGG_*   A  A7!2U!:!|!E/1!E/Wt#*l lmm

 >>t{{6SZ?[\\//(NB?  (E5AAE 	""> ]s2   F*F"F*F%EF*6F(7,F*%F*(F*c                 *   |j                  d      }dddddddddddd}d }| j                  |d	      }| j                  |d
      }| j                  |d      }| j                  ||d       }||dk(  rd}|dk(  r|dk(  r| j                  |d      }||dS )N r?  transactionreleasedr	  r  failed)
WithdrawalTradingPaymentSentDepositReceivedReleasedReservedSoldBoughtFailurer         r(     )r   referenceId)splitr   )	r   commentwordstypesr  	firstWord	thirdWord
fourthWordr   s	            r   parse_ledger_commentzluno.parse_ledger_comment;  s    c"$!$%""
 $$UA.	$$UA.	%%eQ/
y$7LyE1DJZ7%:**5!4K&
 	
r   r   c                 d   | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }|
}d	}| j	                  |      }|d
   }|d   }d }d }t        j                  |	d	      s.t        j                  |
|	      }d}t        j                  |	      }n[t        j                  |d	      rd}t        j                  |      }n-t        j                  |d	      rd}t        j                  |      }t        j                  |	d      st        j                  |d      rd}n.t        j                  |	d      st        j                  |d      rd}| j                  |||||d ||| j                  |      || j                  |      | j                  |      | j                  |
      |d d|      S )N	row_indexr   r  r   available_deltabalance_deltarq   descriptionr  r   r  okpendingcanceledr   inout)r   r   	directionr  r  referenceAccountr   r   r   r  r  beforeafterr   r?  )r   r  r   safe_currencyr  r   r  
string_sub
string_abs	string_lt	string_gtsafe_ledger_entryparse_to_numericrC  )r   r  r   r   r   r  r  r  r  r  r  r  r  r   r   r   r  r  r   s                      r   parse_ledger_entryzluno.parse_ledger_entryX  s-   e[1%%e\:
%%e[9	%%eZ8
&&z8<%%j(;**52CD((@  	2""5-8**73f~]+	$$]E:''}=FF''6F6F''8F6F''8F]C0G4E4EoWZ4[I}c2g6G6GY\6]I%%"!& $++F3"Y/++F3**51'
  ! 	r   c                    K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  ||      S 7 W7 w)a3  
        create a currency deposit address

        https://www.luno.com/en/developers/api#tag/Receive/operation/createFundingAddress

        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.name]: an optional name for the new address
        :param int [params.account_id]: an optional account id for the new address
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr   r   )r  r   privatePostFundingAddressr  parse_deposit_addressr   r  r   r   r!  r   s         r   create_deposit_addresszluno.create_deposit_address  sy      !!!==&Xd^
 77GV8TUU* ))(H==5 	"
 Vr  c                    K   | j                          d{    | j                  |      }d|d   i}| j                  | j                  ||             d{   }| j	                  ||      S 7 W7 w)a  
        fetch the deposit address for a currency associated with self account

        https://www.luno.com/en/developers/api#tag/Receive/operation/getFundingAddress

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.address]: a specific cryptocurrency address to retrieve
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        Nr   r   )r  r   privateGetFundingAddressr  r  r  s         r   fetch_deposit_addresszluno.fetch_deposit_address  sy      !!!==&Xd^
 66t{{7F7STT* ))(H==5 	"
 Ur  c                     | j                  |d      }| j                  ||      }||d | j                  |d      | j                  |d      dS )Nr   addressr   )r   r   networkr  tag)safe_string_upperr   r   )r   depositAddressr   r  r  s        r   r  zluno.parse_deposit_address  s[    * ++NJG
&&z8<"''	B##NF;
 	
r   r_   GETc                    | j                   d   |   dz   | j                  z   dz   | j                  ||      z   }| j                  || j	                  |            }|r|d| j                  |      z   z  }|dk(  s|dk(  rB| j                          | j                  | j                  dz   | j                  z         }	dd|	z   i}||||d	S )
Nre   r   ?r`   rb   :AuthorizationzBasic )urlmethodbodyheaders)
r   r   implode_paramsomitextract_params	urlencodecheck_required_credentialsstring_to_base64apiKeysecret)
r   pathre   r
  r   r  r  r	  queryauths
             r   signz	luno.sign  s    iis#c)DLL83>ATATUY[aAbb		&$"5"5d";<3...C9#):":++-((s):T[[)HIDDG fdwOOr   httpCodereasonr	  r
  r  r  c
                     |y | j                  |d      }
|
*t        | j                  dz   | j                  |      z         y )Nerrorr  )r   r   r   json)r   r  r  r	  r
  r  r  r   requestHeadersrequestBodyr  s              r   handle_errorszluno.handle_errors  sE    '2#		(0C CDDr   )N)>__name__
__module____qualname__r   r   r   r   r   r   r  r   r  r  strr
   r   r"  r   r'  dictr   rH  rL  rS  rW  rZ  r]  r   rp  r   r   rz  r~  r   r  r  r  rv  r  r  r   r  r   r   floatr   r  r  r  r   r  r  r   r  r	   r  r  r  r  intr   __classcell__)r   s   @r   r   r      s   x# xt *, XV Xt +- g 2) )4 *, , ,. @DB oS o oS\ o2: :E Ev E EN 8<B *C * *$ EIW[jnwy ? ?c ?QT ?dg ? 04$UYbd T TC Ts Timnsit T 59tZ^gi Yc Y YTW Ynrsxny Y 7;\`ik Z Z3 ZVY Zptuzp{ Z#4 # #6 #J 6:" G7 G G0 68 3 3F 36R Rv R Rh <@d[] "? "?S "? "?bfglbm "?H 8<$]ajl *J *JC *JWZ *JX
 
4 
$ 37TX\eg .?C .?s .?RU .?` ;= 
c 
AT 
@ mqy{ % %I %Y %X] %fi %N 9=R S # 2 9=DPT]_ Y# Y .2SW`b .Bs .B# .BS .Bgklwgx .B`
:1( 1k 1f >@ &> &>N &>P =? %> %>> %>N
h 
R` 
> &eBSW Pc 3 S # X\ dg r   r   N)" ccxt.async_support.base.exchanger   ccxt.abstract.lunor   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    r   r   <module>r1     sP    6 * O  O  O  O  O  O  * . 4 %|8[ |r   