
    !:h                         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    C/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/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                 |   | j                  |      }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 )'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
        ri   r   	market_idbase_currencycounter_currencytrading_statusr   symbol/basequotesettleN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    **62( //(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 r   c                 &   | j                  |      }| j                  |dg       }g }t        dt        |            D ]R  }||   }| j	                  |d      }| j	                  |d      }| j                  |      }	|j                  |d|	|d       T |S )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
        rq   r   
account_idassetN)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     ))&1//(Ir:q#g,' 
	AajG((,?I))'7;J**:6DMM 	 
	 r   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                 f    | j                          | j                  |      }| j                  |      S )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>`
        )load_marketsr   r  )r   r   r   s      r   fetch_balancezluno.fetch_balance  s3     	))&1 !!(++r   Nr   r   c           	      B   | j                          | j                  |      }d|d   i}d}|'|dk  r"| j                  | j                  ||            }n!| j	                  | j                  ||            }| j                  |d      }| j                  ||d   |ddd	d
      S )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
        pairr   Nd   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
 #11$++gv2NOH..t{{7F/KLH%%h<	$$Xvh/?FTZ\cemnnr   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                     | j                          d|i}| j                  | j                  ||            }| j                  |      S )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>`
        r   )r  privateGetOrdersIdr  rH  r   r   r   r   r!  r   s         r   fetch_orderzluno.fetch_order  sJ     	"
 **4;;w+GH))r   r+  sincec                     | j                          i }d }|||d<   || j                  |      }|d   |d<   | j                  | j                  ||            }| j	                  |dg       }	| j                  |	|||      S )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,,T[[&-IJ(B7  >>r   c                 ,    | j                  d||||      S )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     ))$ufMMr   c                 ,    | j                  d||||      S )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$  rU  rV  s        r   fetch_open_orderszluno.fetch_open_ordersD  s     )))VUE6RRr   c                 ,    | j                  d||||      S )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>`
        COMPLETErU  rV  s        r   fetch_closed_orderszluno.fetch_closed_ordersR  s     ))*feUFSSr   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   rg  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                    | j                          | j                  |      }| j                  |      }| j                  |d   d      }t	        |j                               }i }t        dt        |            D ]7  }||   }| j                  |      }	|	d   }
||   }| j                  ||	      ||
<   9 | j                  |d|      S )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>`
        ro   r  r   r   )r  market_symbolspublicGetTickersindex_bylistkeysr   r   rA  ro  filter_by_array_tickers)r   rp  r   r   ro   idsr   r   r   r   r   rn   s               r   fetch_tickerszluno.fetch_tickers  s     	%%g.((0-- 3V<7<<>"q#c(# 	?AQB%%b)FH%FR[F!..vv>F6N	? ++FHgFFr   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://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>`
        r  r   )r  r   publicGetTickerr  ro  r   r   r   r   r!  r   s         r   fetch_tickerzluno.fetch_ticker  s`     	V$F4L
 ''GV(DE   622r   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                     | j                          | j                  |      }d|d   i}|||d<   | j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )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>`
        r  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''GV(DE (B7  >>r   r   c                    | j                          | j                  |      }| j                  | j                  ||      |d   d}|| j	                  |      |d<   n*d| j                  |      z  }| j                         |z
  |d<   | j                  | j                  ||            }	| j                  |	dg       }
| j                  |
||||      S )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
        r   )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11$++gv2NO" )R8  E5IIr   c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr  r%  r_  r`  rf  r  )r  r   )r   ohlcvr   s      r   parse_ohlcvzluno.parse_ohlcv\  sn     e[1UF+UF+UE*UG,UH-
 	
r   c                 2   |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   |||d<   | j	                  | j                  ||            }| j                  |dg       }| j                  ||||      S )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>`
        z+ 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,,T[[&-IJ, (B7  >>r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }||| j	                  |d      | j	                  |d      dddS )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>`
        r  r   	maker_fee	taker_feeN)r   r   r   r   r   r   )r  r   privateGetFeeInfor  r   r|  s         r   fetch_trading_feezluno.fetch_trading_fee  s     	V$F4L
 ))$++gv*FG %%h<%%h<
 	
r   r   r<  r   r   c                     | j                          | j                  |      }d|d   i}d}	|dk(  rk|j                         |d<   |dk(  r| j                  |d   |      |d<   n| j                  |d   |      |d	<   | j	                  | j                  ||            }	n]| j                  |d   |      |d
<   | j                  |d   |      |d<   |dk(  rdnd|d<   | j                  | j                  ||            }	| j                  |	|	d   d|      S )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>`
        r  r   Nr   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  s3    	V$F4L
 8"jjlGFOu},0,D,DVHEUW],^())-)A)A&BRTZ)[&224;;w3OPH $ 8 89I6 RGH#66vh7GOGG(,eEGFO00Wf1MNH:& 
  	r   c                     | j                          d|i}| j                  | j                  ||            }| j                  d|i      S )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>`
        r8  r   )r  privatePostStoporderr  rB  rK  s         r   cancel_orderzluno.cancel_order  sV     	
 ,,T[[&-IJ H 
  	r   r  c           	          |d}|d}d }|| j                  ||      d}| j                  |||| j                  ||            S )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  sW    =E=Exxu-
   ueT[[&5QRRr   c                    | j                          | j                          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                  ||            }| j                  |dg       }| j                  ||||      S )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   rt  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

 88VW9UV//(NB?  (E5AAr   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                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||      S )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>`
        r   r   )r  r   privatePostFundingAddressr  parse_deposit_addressr   r  r   r   r!  r   s         r   create_deposit_addresszluno.create_deposit_address  s`     	==&Xd^
 11$++gv2NO* ))(H==r   c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  ||      S )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>`
        r   r   )r  r   privateGetFundingAddressr  r  r  s         r   fetch_deposit_addresszluno.fetch_deposit_address  s`     	==&Xd^
 00Wf1MN* ))(H==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  rY  r\  r   ro  r   r   ry  r}  r   r  r  r  ru  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 %' 4= 2) )4 $& ,( ,. :>b os o3 oY o2: :E Ev E EN 26b *c *3 *$ ?CQUdhqs ?3 ? ?3 ?^a ? *.Dt\^ N3 Nc N Ncghmcn N /3TXac S S3 Sc Shlmrhs S 154VZce T# TS TPS Tjnotju T#4 # #6 #J 04B GW G7 G0 02 33 3f 36R Rv R Rh 6:UW "?3 "?s "?# "?\`af\g "?H 26DW[df *J# *Jc *JQT *JX
 
4 
$ -1tRV_a .?c .? .?C .?` 57 
 
;N 
@ gksu %3 %i %y %RW %`c %N 37r s C 2 37d$WY SC S (,$TZ\ .B .BC .Bs .Baefqar .B`
:1( 1k 1f 8: &>3 &>n &>P 79 %># %>^ %>N
h 
R` 
> &eBSW Pc 3 S # X\ dg r   r   N)"ccxt.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>r/     sP    ( * O  O  O  O  O  O  * . 4 %|8[ |r   