
    E#i(                         S SK Jr  S SKJr  S SKJrJrJrJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJr  S SKJr  S SKJr  S SKJr  S SK J!r!   " S	 S
\\5      r"g)    )Exchange)ImplicitAPI)AccountAnyBalances
CurrenciesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterface)List)ExchangeError)ArgumentsRequired)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjr0 4S\4S jjr0 4S\\	   4S jjr
0 4S\\   4S jjrS\4S jr0 4S\4S jjrS	0 4S
\S\S\4S jjrS\4S jrSBS\S\	S\4S jjrS	0 4S\S
\4S jjrS	S	S	0 4S\S
\S\S\4S jjrS	S	S	0 4S
\S\S\S\\   4S jjrS	S	S	0 4S
\S\S\S\\   4S jjrS	S	S	0 4S
\S\S\S\\   4S jjrSBS\S\	S\4S jjrS	0 4S\ S\!4S jjr"0 4S
\S\4S jjr#SBS\S\	S\$4S  jjr%S	S	0 4S
\S\S\S\\$   4S! jjr&S"S	S	0 4S
\S#\S\S\4S$ jjr'SBS\	S\(4S% jjr)S	S	S	0 4S
\S\S\4S& jjr*0 4S
\S\+4S' jjr,S	0 4S
\S(\-S)\.S*\/S+\04
S, jjr1S	0 4S\S
\4S- jjr2S	S	S	0 4S.\4S/ jjr3S	S	S	0 4S.\S\S\S\\4   4S0 jjr5S1 r6SBS2\7S\44S3 jjr80 4S.\S\94S4 jjr:0 4S.\S\94S5 jjr;SBS2\7S\94S6 jjr<S7S80 S	S	4S9 jr=S:\>S;\S<\S=\S>\S?\4S@ jr?SAr@U =rA$ )Cluno   returnc           !      "  > U R                  [        [        U ]  5       SS/ SQSSS0 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_0 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	_E0 S)S	_S*S	_S+S	_S,S	_S-S	_S.S	_S/S	_S0S_S1S	_S2S	_S3S	_S4S	_S5S	_S6S	_S7S	_S8S	_S9S	_E0 S:S	_S;S_S<S	_S=S	_S>S	_S?S	_S@S	_SAS_SBS_SCS	_SDS	_SES	_SFS_SGS	_SHS	_SIS_SJS_E0 SKS_SLS	_SMS	_SNS	_SOS	_SPS	_SQS	_SRS	_SSS	_STS	_SUS	_SVS	_SWS_SXS_SYS_SZS_S[S	_ES	S	S	S	S	S	S	S	S	S\.	ES]S^S_S_S`S`Sa.Sb/ ScQSd.SeSfSg00SeShSg00SeSgSgSgSgSgSi.0SgSgSgSgSgSgSgSgSgSgSgSgSgSgSj.SgSgSgSgSgSgSgSgSgSgSk.
SlSg0SgSgSm.Sn.So.SpSqSrSsStSuSvSwSxSySz.
S{SSU R	                  S|5      U R	                  S}5      S~.0[
        S	SS0S	SS SS	S	S SSSS	S.S	S	S	SS	S	S	S.S S	SSSSS.S	S	S	S	S.S	SS	S	S	S.S	SSS S	S	S	S.S	SSSgS S	S	S	S.SS 0S.
S S S.S S S.S.S.5      $ )Nr   )GBSGZA   1TCORSspotmarginFswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMarginborrowMargincancelOrdercloseAllPositionsclosePositioncreateDepositAddresscreateOrdercreateReduceOnlyOrderfetchAccountsfetchAllGreeksfetchBalancefetchBorrowInterestfetchBorrowRatefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchBorrowRatesfetchBorrowRatesPerSymbolfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchGreeksfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLedgerfetchLeveragefetchLeveragesfetchLeverageTiersfetchLiquidationsfetchLongShortRatiofetchLongShortRatioHistoryfetchMarginAdjustmentHistoryfetchMarginModefetchMarginModesfetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyLiquidationsfetchMySettlementHistoryfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenInterestsfetchOpenOrdersfetchOptionfetchOptionChain
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionForSymbolWsfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsForSymbolfetchPositionsForSymbolWsfetchPositionsHistoryfetchPositionsRiskfetchPremiumIndexOHLCVfetchSettlementHistoryfetchTickerfetchTickersfetchTradesfetchTradingFeefetchTradingFees)	fetchUnderlyingAssetsfetchVolatilityHistoryreduceMarginrepayCrossMarginrepayIsolatedMarginsetLeverage	setMargin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beneficiarieszsend/networksfee_infofunding_address
listorders
listtradessend_feezorders/{id}withdrawalswithdrawals/{id}	transfers)
accountszaddress/validate	postordermarketorder	stoporderr   r   sendzoauth2/grantr   zaccounts/{id}/name)r   zbeneficiaries/{id})r   postputdelete)r   r   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makerr   )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   )
sandboxrD   r6   createOrdersrb   rj   rg   rl   rA   rc   )linearinverse)r)   r+   r,   )idname	countries	rateLimitversionprohasurlsr   
timeframesfeesprecisionModefeatures)deep_extendsuperr   describeparse_numberr   )self	__class__s    C/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/luno.pyr   luno.describe   sm   dD : <+___ %_ 	_
 %_ %_ U_ $U_ '_ _ t_ $U_  _ '_ t_  (!_"  #_$ !%%_& '_( &u)_* "5+_, +E-_. )%/_0 #E1_2 ,U3_4 $T5_6 '7_8 (9_: "4;_< &t=_> &u?_@ 'A_B (C_D #EE_F *5G_H $UI_J uK_L "5M_N *5O_P +EQ_R )%S_T tU_V  W_X !%Y_Z %e[_\ $U]_^ &u__` -ea_b /c_d "5e_f #Eg_h +Ei_j k_l !%m_n !%o_p "5q_r &us_t +Eu_v  w_x dy_z $U{_| +E}_~ %e_@ "4A_B uC_D #EE_F dG_H !$I_J tK_L  M_N +EO_P 'Q_R $US_T !%U_V *5W_X ,UY_Z ([_\ %e]_^ )%__` )%a_b tc_d e_f tg_h "4i_j #Ek_l */*/ %$)',$"!&#(}_B A}89 C'J	 .$ !1 !1$ %&)*"##$"# 2367#$)*)*$%+,&'&'$%'('(,-%&0 %&,-%&'(%&+,'( !())* -a -../Q,)AF  !%"&!..w7!..s3	 '  %!4( ',(,,0,0).+06:#'#'"&#(	( #($)$)+/27/4#()$, %)&+!%$*%+*.& ',#($)*/	# ',!%#($)*/( ',!%$*%)#($)*/$ ',!%$*,-%)#($)*/	*  #GFP ##
 ##YP_`?
 ` `	    c                    U R                  S5      (       d  0 $ U R                  U5      nU R                  US/ 5      n0 n[        S[	        U5      5       H  nX5   nU R                  US5      nU R                  U5      nX;  a  UUSSSSSSSSSS.SSS.S.0 0 S.XH'   U R                  US	5      n	U R                  U	5      n
U	U
SSS.SSS.S.SSSSSUS
.	XH   S   U
'   U R                  XH   S/ 5      nUR                  U5        XU   S'   M     [        UR                  5       5      n[        S[	        U5      5       H  nX   nU R                  XH   5      XH'   M     U$ )z
fetches all available currencies on an exchange
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
Fdatar   native_currencyNminmax)withdrawdeposit)r   code	precisiontyper   activer   r   feelimitsnetworksinfor   )	r   networkr   r   r   r   r   r   r   r   r   )check_required_credentialsprivateGetSendNetworks	safe_listrangelensafe_stringsafe_currency_codenetwork_id_to_codeappendlistkeyssafe_currency_structure)r   paramsresponsecurrenciesDataresultinetworkEntryr   r   	networkIdnetworkCoder   allKeyss                r   fetch_currenciesluno.fetch_currencies5  s    ..u55I..v6 &"=q#n-.A),L!!,0ABB**2.DN !%  "# $ $(#'%
 $(#'$	 !#+ . ((v>I11)<K&  $#!
  $# 	  !$%5FL$[1* >>&,;DKK%#'4L k /n v{{}%q#g,'A:D77EFL ( r   c                 ~   U R                  U5      n/ nU R                  US/ 5      n[        S[        U5      5       GH|  nXE   nU R	                  US5      nU R	                  US5      nU R	                  US5      n	U R                  U5      n
U R                  U	5      nU R	                  US5      nUR                  0 SU_SU
S	-   U-   _S
U
_SU_SS_SU_SU	_SS_SS_SS_SS_SS_SS_SS_SUS:H  _SS_SS_SSSSSSU R                  U R                  U R	                  US5      5      5      U R                  U R                  U R	                  US5      5      5      S.SSS .U R                  US!5      U R                  US"5      S .U R                  US#5      U R                  US$5      S .SSS .S%.SUS&.
E5        GM     U$ )'z
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
r   r   	market_idbase_currencycounter_currencytrading_statusr   symbol/basequotesettleNbaseIdquoteIdsettleIdr   r)   Tr*   Fr+   r,   r-   r   ACTIVEcontractr   volume_scaleprice_scale)amountpricer   
min_volume
max_volume	min_price	max_price)r   r'  r(  cost)
r   contractSizeexpiryexpiryDatetimestrike
optionTyper   r   createdr   )
exchangeGetMarkets
safe_valuer  r  r  r  r  r   parse_precisionsafe_number)r   r  r  r  r   r  marketr   r   r!  r  r  statuss                r   fetch_marketsluno.fetch_markets  s    **62( //(Ir:q#g,'AZF!!&+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 (r r   c                 (   U R                  U5      nU R                  US/ 5      n/ n[        S[        U5      5       HR  nX5   nU R	                  US5      nU R	                  US5      nU R                  U5      n	UR                  USU	US.5        MT     U$ )aK  
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
r   r   
account_idassetN)r   r   currencyr   )privateGetBalancer5  r  r  r  r  r  )
r   r  r  walletsr  r  account	accountId
currencyIdr   s
             r   fetch_accountsluno.fetch_accounts  s     ))&1//(Ir:q#g,'AjG((,?I))'7;J**:6DMM 	  ( r   c                 j   U R                  US/ 5      nUS S S.n[        S[        U5      5       H  nX$   nU R                  US5      nU R	                  U5      nU R                  US5      nU R                  US5      n	U R                  US5      n
[
        R                  " X5      n[
        R                  " X5      nXs;   aD  [
        R                  " X7   S   U5      X7   S'   [
        R                  " X7   S   U5      X7   S'   M  U R                  5       nXS'   XS'   XU'   M     U R                  U5      $ )	Nr   )r   	timestampdatetimer   r>  reservedunconfirmedusedtotal)	r5  r  r  r  r  r   
string_addrB  safe_balance)r   r  rA  r  r  walletrD  r   rJ  rK  r   reservedUnconfirmedbalanceUnconfirmedrB  s                 r   parse_balanceluno.parse_balance  s7   //(Ir:

 q#g,'AZF))&':J**:6D''
;H**6=AK&&vy9G")"4"4X"K!(!3!3G!I~'.'9'9&,v:NPc'dV$(/(:(:6<;PRd(eW%,,."5#5 &t! ("   ((r   c                 f    U R                  5         U R                  U5      nU R                  U5      $ )aM  
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@  rS  )r   r  r  s      r   fetch_balanceluno.fetch_balance  s3     	))&1 !!(++r   Nr  r   c           	      @   U R                  5         U R                  U5      nSUS   0nSnUb'  US::  a!  U R                  U R                  XS5      5      nO U R	                  U R                  XS5      5      nU R                  US5      nU R                  XdS   USSS	S
5      $ )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   rH  r  bidsasksr(  volume)rV  r8  publicGetOrderbookTopextendpublicGetOrderbooksafe_integerparse_order_book)r   r  r   r  r8  requestr  rH  s           r   fetch_order_bookluno.fetch_order_book-  s     	V$F4L
 #11$++g2NOH..t{{7/KLH%%h<	$$Xh/?FTZ\cemnnr   r9  c                 .    SS0nU R                  X!U5      $ )NPENDINGopen)r  )r   r9  statusess      r   parse_order_statusluno.parse_order_statusF  s%     v
 &99r   orderr8  c                    U R                  US5      nU R                  U R                  US5      5      nUS:X  a  UOUnS nU R                  US5      nUS:X  d  US:X  a  SnOUS:X  d  US	:X  a  S
nU R                  US5      nU R                  Xr5      nU R                  US5      nU R                  US5      n	U R	                  US5      n
U R	                  US5      nU R                  US5      nU R                  US5      nS nU
b	  U
US   S.nOUb  UUS   S.nU R                  US5      nU R                  0 SU_SS _SU R                  U5      _SU_SS _SU_SUS   _SS _SS _SS _SU_SU_S S _S!U	_S"U_S#U_S$S _S UUS S%.EU5      $ )&Ncreation_timestampstateri  r   ASKSELLsellBIDBUYbuyrZ  limit_pricelimit_volumefee_counterfee_baser  counterr  r-  r?  order_idr   clientOrderIdrI  rH  lastTradeTimestampr9  r  r   postOnlysider(  r   r'  filledr-  	remaining)r   r   r   average)rb  rk  r  safe_marketr7  
safe_orderiso8601)r   rm  r8  rH  r9  r  	orderTypemarketIdr(  r'  quoteFeebaseFeer  r-  r   r   s                   r   parse_orderluno.parse_orderM  s\   $ %%e-AB	(()9)9%)IJ"f,6$$UF3	I$7D5 i5&8D##E62!!(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                     U R                  5         SU0nU R                  U R                  XC5      5      nU R                  U5      $ )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   )rV  privateGetOrdersIdr`  r  r   r   r  r  rd  r  s         r   fetch_orderluno.fetch_order  sH     	"
 **4;;w+GH))r   rp  sincec                     U R                  5         0 nS nUb  XS'   Ub  U R                  U5      nUS   US'   U R                  U R                  Xe5      5      nU R	                  US/ 5      n	U R                  XX45      $ )Nrp  r   rZ  orders)rV  r8  privateGetListordersr`  r  parse_orders)
r   rp  r  r  r   r  rd  r8  r  r  s
             r   fetch_orders_by_stateluno.fetch_orders_by_state  s    $G[[(F$TlGFO,,T[[-IJ(B7  >>r   c                 (    U R                  SXX45      $ )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r  r   r  r  r   r  s        r   fetch_ordersluno.fetch_orders  s     ))$uMMr   c                 (    U R                  SXX45      $ )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>`
rh  r  r  s        r   fetch_open_ordersluno.fetch_open_orders  s     )))VERRr   c                 (    U R                  SXX45      $ )a  
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>`
COMPLETEr  r  s        r   fetch_closed_ordersluno.fetch_closed_orders  s     ))*fUSSr   r   c                    U R                  US5      nU R                  US5      nU R                  XB5      nU R                  US5      nU R                  0 SU_SU_SU R	                  U5      _SS _SS _SU R                  US5      _S	S _S
U R                  US
5      _SS _SS _SS _SU_SU_SS _SS _SS _SS _U R                  US5      S US.EU5      $ )NrH  rZ  
last_trader  rI  highlowbid	bidVolumeask	askVolumevwapri  closelastpreviousClosechanger   r  rolling_24_hour_volume)
baseVolumequoteVolumer   )rb  r  safe_symbolsafe_tickerr  )r   r   r8  rH  r  r  r  s          r   parse_tickerluno.parse_ticker  sp    %%fk:	##FF3!!(35 !
f!
!
 Y/!
 D	!

 4!
 4##FE2!
 !
 4##FE2!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **63KL)!
* + 	r   symbolsc                    U R                  5         U R                  U5      nU R                  U5      nU R                  US   S5      n[	        UR                  5       5      n0 n[        S[        U5      5       H4  nXW   nU R                  U5      n	U	S   n
XH   nU R                  X5      Xj'   M6     U R                  USU5      $ )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>`
r   rZ  r   r  )rV  market_symbolspublicGetTickersindex_byr  r	  r  r  r  r  filter_by_array_tickers)r   r  r  r  r   idsr  r  r   r8  r  r   s               r   fetch_tickersluno.fetch_tickers  s     	%%g.((0-- 3V<7<<>"q#c(#AB%%b)FH%F[F!..v>FN $ ++FHgFFr   c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  XS5      $ )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>`
rZ  r   )rV  r8  publicGetTickerr`  r  r   r  r  r8  rd  r  s         r   fetch_tickerluno.fetch_ticker  s\     	V$F4L
 ''G(DE   22r   tradec                    U R                  US5      nU R                  US5      nS nS nUbX  U R                  US5      nUS:X  d  US:X  a  SnOUS:X  d  US:X  a  S	nUS:X  a  US
   (       a  SnO$US	:X  a  US
   (       d  SnOSnOUS
   (       a  S	OSnU R                  US5      nU R                  US5      n	S n
S nUb$  [        R                  " US5      (       d  US   n
UnO&U	b#  [        R                  " U	S5      (       d  US   n
U	nU R                  US5      nU R	                  UUUU R                  U5      US   US UUU R                  US5      U R                  USS5      U R                  US5      UU
S.S.U5      $ )Nr}  sequencer   rq  rr  rs  rt  ru  rv  is_buyr   r   rz  ry  0.0r  r  rH  r  r(  r^  r{  r|  )r   r   rH  rI  r  rm  r   r  takerOrMakerr(  r'  r-  r   )r  r   string_equalsrb  
safe_trader  safe_string_2)r   r  r8  orderIdr   r  r  r   feeBaseStringfeeCounterStringfeeCurrencyfeeCostrH  s                r   parse_tradeluno.parse_trade5  s   B ""5*5eZ0##E62D46>%-TU]v~%/&uX&&!(O5D((
;++E=A$((>>$Vn')(()95AA$Wo*%%e[9	"Y/X&(%%eW5((&A$$UI6' 
$ % 	r   c                     U R                  5         U R                  U5      nSUS   0nUb  X&S'   U R                  U R                  Xd5      5      nU R	                  US/ 5      nU R                  XX#5      $ )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>`
rZ  r   r  r   )rV  r8  publicGetTradesr`  r  parse_trades	r   r  r  r   r  r8  rd  r  r   s	            r   fetch_tradesluno.fetch_trades  s~     	V$F4L
 $G''G(DE (B7  >>r   r   	timeframec                    U R                  5         U R                  U5      nU R                  U R                  X"5      US   S.nUb  U R	                  U5      US'   O*SU R                  U5      -  nU R                  5       U-
  US'   U R                  U R                  Xu5      5      n	U R                  U	S/ 5      n
U R                  XX#U5      $ )aT  

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   )durationrZ  r  i@B r   )rV  r8  r5  r   parse_to_intparse_timeframemillisecondsexchangePrivateGetCandlesr`  r  parse_ohlcvs)r   r  r  r  r   r  r8  rd  r  r  ohlcvss              r   fetch_ohlcvluno.fetch_ohlcv  s     	V$N4L
 #007GG"T%9%9)%DDH#002X=GG11$++g2NO" )R8  5IIr   c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )NrH  ri  r  r  r  r^  )rb  r7  )r   ohlcvr8  s      r   parse_ohlcvluno.parse_ohlcv  sn     e[1UF+UF+UE*UG,UH-
 	
r   c                 .   Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R	                  U R                  Xd5      5      nU R                  US/ 5      nU R                  XX#5      $ )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 argumentrZ  r   r  r   r   )r   r   rV  r8  privateGetListtradesr`  r  r  r  s	            r   fetch_my_tradesluno.fetch_my_trades  s     >#DGG.[$[\\V$F4L
 $G$G,,T[[-IJ, (B7  >>r   c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nUUU R	                  US5      U R	                  US5      SSS.$ )a1  
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>`
rZ  r   	maker_fee	taker_feeN)r   r  r   r   r   r   )rV  r8  privateGetFeeInfor`  r7  r  s         r   fetch_trading_feeluno.fetch_trading_fee  s     	V$F4L
 ))$++g*FG %%h<%%h<
 	
r   r   r  r'  r(  c                 "   U R                  5         U R                  U5      nSUS   0nSn	US:X  ak  UR                  5       US'   US:X  a  U R                  US   U5      US'   OU R                  US   U5      US	'   U R	                  U R                  X5      5      n	O]U R                  US   U5      US
'   U R                  US   U5      US'   US:X  a  SOSUS'   U R                  U R                  X5      5      n	U R                  U	U	S   S.U5      $ )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>`
rZ  r   Nr8  r   rv  r  counter_volumebase_volumer^  r(  rt  rq  r}  )r   r   )	rV  r8  upperamount_to_precisionprivatePostMarketorderr`  price_to_precisionprivatePostPostorderr  )
r   r  r   r  r'  r(  r  r8  rd  r  s
             r   create_orderluno.create_order;  s/    	V$F4L
 8"jjlGFOu},0,D,DVHEUW],^())-)A)A&BRTZ)[&224;;w3OPH $ 8 89I6 RGH#66vh7GOGG(,eEGFO00W1MNH:& 
  	r   c                     U R                  5         SU0nU R                  U R                  XC5      5      nU R                  SU05      $ )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>`
r}  r   )rV  privatePostStoporderr`  r  r  s         r   cancel_orderluno.cancel_orderb  sT     	
 ,,T[[-IJ H 
  	r   r   c           	          Uc  SnUc  SnS nUU R                  X#5      S.nU R                  XX0R                  Xd5      5      $ )Nr   )min_rowmax_row)sumfetch_ledgerr`  )r   r   entryr   r  r  rd  s          r   fetch_ledger_by_entriesluno.fetch_ledger_by_entries{  sO    =E=Exx-
   e[[5QRRr   c                    U R                  5         U R                  5         SnU R                  US5      nU R                  US5      nU R                  US5      nUc|  Uc  [	        U R
                  S-   5      eU R                  U5      nU R                  U R                  S5      n	U R                  X5      n
U
c  [        U R
                  S-   U-   5      eU
S   nUc  Uc  SnS	nOUb  Uc  [        U R
                  S
-   5      eUb  X-
  U:  a  US::  a  X-
  nO
US:  a  Xs-   nX-
  S:  a  [        U R
                  S-   5      eUUUS.nU R                  U R                  XK5      5      nU R                  US/ 5      nU R                  XX#5      $ )a*  
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)rV  load_accountsr  r5  r   r   r?  r  r   r    privateGetAccountsIdTransactionsr`  parse_ledger)r   r   r  r   r  r?  r   r  r  accountsByCurrencyCoderB  rd  r  entriess                 r   r
  luno.fetch_ledger  s    	fd+//&)4//&)4:|'  3J  )J  K  K}}T*H%)]]4==*%M"oo&<CG#DGG.]$]`d$deeB?wGG_*   A  A!2U!:!|!/1!/t#*l lmm

 88V9UV//(NB?  EAAr   c                 0   UR                  S5      nSSSSSSSSSSSS.nS nU R                  US	5      nU R                  US
5      nU R                  US5      nU R                  X5S 5      nUc  US:X  a  SnUS:X  a  US:X  a  U R                  US5      nUUS.$ )N r   transactionreleasedrJ  r  failed)
WithdrawalTradingPaymentSentDepositReceivedReleasedReservedSoldBoughtFailurer         rm     )r   referenceId)splitr  )	r   commentwordstypesr)  	firstWord	thirdWord
fourthWordr   s	            r   parse_ledger_commentluno.parse_ledger_comment  s    c"$!$%""
 $$UA.	$$UA.	%%eQ/
$7LyE1DJZ7%:**5!4K&
 	
r   r?  c                    U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  Xb5      nU R                  Xb5      nU R                  US5      nU R                  US5      n	U R                  US5      n
U R                  US5      nU
nS	nU R	                  U5      nUS
   nUS   nS nS n[
        R                  " U	S	5      (       d/  [
        R                  " X5      nSn[
        R                  " U	5      nOi[
        R                  " US	5      (       a  Sn[
        R                  " U5      nO4[
        R                  " US	5      (       a  Sn[
        R                  " U5      n[
        R                  " U	S5      (       d  [
        R                  " US5      (       a  SnO:[
        R                  " U	S5      (       d  [
        R                  " US5      (       a  SnU R                  UUUUUS UUU R                  U5      UU R                  U5      U R                  U5      U R                  U
5      US S.U5      $ )N	row_indexr=  rH  r?  available_deltabalance_deltar   descriptionr  r   r)  okpendingcanceledr   inout)r   r   	directionrB  r)  referenceAccountr   r?  r'  rH  rI  beforeafterr9  r   )r  rb  r  safe_currencyr1  r   r  
string_sub
string_abs	string_lt	string_gtsafe_ledger_entryparse_to_numericr  )r   r  r?  r   r=  rH  rD  r   r5  r6  r@  r+  r?  r'  r  r   r)  r=  r9  s                      r   parse_ledger_entryluno.parse_ledger_entry  s<   e[1%%e\:
%%e[9	%%eZ8
&&z<%%j;**52CD((@  	2""5-8**73f~]+	$$]E::''=FF''6F66F''8F66F''8F]C00G4E4EoWZ4[4[I}c22g6G6GY\6]6]I%%"!& $++F3"Y/++F3**51'
  ! 	r   c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  XS5      $ )a  
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   )rV  r?  privatePostFundingAddressr`  parse_deposit_addressr   r   r  r?  rd  r  s         r   create_deposit_addressluno.create_deposit_address  s\     	==&Xd^
 11$++g2NO* ))(==r   c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  XS5      $ )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   )rV  r?  privateGetFundingAddressr`  rL  rM  s         r   fetch_deposit_addressluno.fetch_deposit_address0  s\     	==&Xd^
 00W1MN* ))(==r   c                     U R                  US5      nU R                  X25      nUUS U R                  US5      U R                  US5      S.$ )Nr?  addressr   )r   r?  r   rU  tag)safe_string_upperr  r  )r   depositAddressr?  rD  r   s        r   rL  luno.parse_deposit_addressW  sY    * ++NJG
&&z<"''	B##NF;
 	
r   r   GETc                    U R                   S   U   S-   U R                  -   S-   U R                  X5      -   nU R                  X@R	                  U5      5      nU(       a  USU R                  U5      -   -  nUS:X  d  US:X  aB  U R                  5         U R                  U R                  S-   U R                  -   5      n	SSU	-   0nXsXeS	.$ )
Nr   r  ?r   r   :AuthorizationzBasic )urlmethodbodyheaders)
r   r   implode_paramsomitextract_params	urlencoder   string_to_base64apiKeysecret)
r   pathr   r`  r  rb  ra  r_  queryauths
             r   sign	luno.signv  s    iis#c)DLL83>ATATUYAbb		&"5"5d";<3...C9#):":++-((s):T[[)HIDDG dOOr   httpCodereasonr_  r`  rb  ra  c
                     Uc  g U R                  US5      n
U
b*  [        U R                  S-   U R                  U5      -   5      eg )Nerrorr  )r5  r   r   json)r   ro  rp  r_  r`  rb  ra  r  requestHeadersrequestBodyrr  s              r   handle_errorsluno.handle_errors  sE    '2#		(0C CDDr    )N)B__name__
__module____qualname____firstlineno__r   r   r   r  r   r   r:  r   rE  r   rS  rW  strr   r   re  r   rk  dictr   r  r  r  r  r  r  r   r  r   r   r  r  r   r  r  r  r  r  r  r   r  r   r   floatr   r  r  r  r   r
  r1  r	   rH  r
   rN  rR  rL  rm  intrv  __static_attributes____classcell__)r   s   @r   r   r      s1   a# aF	 ') RZ Rh $& 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 9=4^bkm *J# *J# *JS *JX[ *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   r   typingr   ccxt.base.errorsr   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r   rx  r   r   <module>r     sP    ( * [  [  [  [  [  [  * . 4 %y8[ yr   