
    ei                         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mZ d dlmZ d dlmZ d dlmZ d dlmZ d dl m!Z!  G d	 d
ee          Z"dS )    )Exchange)ImplicitAPI)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                   n    e Zd Zdef fdZi fde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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+Z0di fded	efd,Z1dddi fd-efd.Z2dddi fd-eded
edee3         fd/Z4d0 Z5d@d1e6de3fd2Z7i fd-ede8fd3Z9i fd-ede8fd4Z:d@d1e6de8fd5Z;d6d7i ddfd8Z<d9e=d:ed;ed<ed=ed>efd?Z> xZ?S )Alunoreturnc           !      h   |                      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	i d:d	d;dd<d	d=d	d>d	d?d	d@d	dAddBddCd	dDd	dEd	dFddGd	dHd	dIddJdi dKddLd	dMd	dNd	dOd	dPd	dQd	dRd	dSd	dTd	dUd	dVd	dWddXddYddZdd[d	d	d	d	d	d	d	d	d	d	d\	d]d^d_d_d`d`dadbg dcdddedfdgiidedhdgiidedgdgdgdgdgdiidgdgdgdgdgdgdgdgdgdgdgdgdgdgdjdgdgdgdgdgdgdgdgdgdgdk
dldgidgdgdmdndodpdqdrdsdtdudvdwdxdydz
d{dd|                     d|          |                     d}          d~it
          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	dddddd	d	d	d	dd	dd	d	d	dd	ddd d	d	d	dd	dddgd d	d	d	ddd id
d d dd d dddd          S )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   )
sandboxrC   r5   createOrdersra   ri   rf   rk   r@   rb   )linearinverse)r(   r*   r+   g     L@)idname	countries	rateLimitversionprohasurlsr   
timeframesfeesprecisionModefeaturesrollingWindowSize)deep_extendsuperr   describeparse_numberr   )self	__class__s    U/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/luno.pyr   zluno.describe   sI   dD 1 1 : : < <+++___ %_ 	_
 %_ %_ 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 AF   !%"&!..w77!..s33	  '  %!4( ',(,,0,0).+06:#'#'"&#(	( ( #($)$)+/27/4#()$ $, %)&+!%$*%+*.& & ',#($)*/	# # ',!%#($)*/( ( ',!%$*%)#($)*/$ $ ',!%$*,-%)#($)*/	* 	*  #GF FP ## 
 ## YP Pb ")A	a?
 a?
 a a a	    c                 j  K   |                      d          si S |                     |           d{V }|                     |dg           }i }t          dt	          |                    D ]}||         }|                     |d          }|                     |          }||vr||ddddddddddddddi i d||<   |                     |d	          }	|                     |	          }
|	|
dddddddddddd|d
	||         d         |
<   |                     ||         dg           }|                    |           |||         d<   t          |
                                          }t          dt	          |                    D ](}||         }|                     ||                   ||<   )|S )z
        fetches all available currencies on an exchange
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        FNdatar   native_currency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_currencieszluno.fetch_currencies6  sM      ..u55 	I44V<<<<<<<< &"==q#n--.. 5	( 5	(A)!,L!!,0ABBB**2..DFNN !%  "# $ $(#'% %
 $(#'$ $	 	 !#+   t. ((v>>I11)<<K&  $#! !
  $#   	 	  !$%5 5F4L$[1* >>&,;;DKK%%%#'F4L  v{{}}%%q#g,,'' 	F 	FA1:D77tEEF4LLr   c                 8  K   |                      |           d{V }g }|                     |dg           }t          dt          |                    D ]}||         }|                     |d          }|                     |d          }|                     |d          }	|                     |          }
|                     |	          }|                     |d          }|                    i d|d	|
d
z   |z   d|
d|ddd|d|	ddddddddddddddd|dk    dddddddddd|                     |                     |                     |d                              |                     |                     |                     |d                              dddd | 	                    |d!          | 	                    |d"          d | 	                    |d#          | 	                    |d$          d d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
        Nr   r   	market_idbase_currencycounter_currencytrading_statusr   symbol/basequotesettle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_marketszluno.fetch_markets  s      0088888888( //(Ir::q#g,,'' 8	 8	AQZF!!&+66B%%fo>>F&&v/ABBG**622D++G4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\^lEmEm0n0noo!..t/C/CDDTDTU[]jDkDk/l/lmm   $#! !
  $//EE#//EE 
  $//DD#//DD 
  $#  $  _0 0 0 0 0 0 0b r   c                 x  K   |                      |           d{V }|                     |dg           }g }t          dt          |                    D ]e}||         }|                     |d          }|                     |d          }|                     |          }	|                    |d|	|d           f|S )aq  
        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
        Nr   r   
account_idasset)r   r   currencyr   )privateGetBalancer3  r  r  r  r  r  )
r   r
  r  walletsr  r  account	accountId
currencyIdr   s
             r   fetch_accountszluno.fetch_accounts  s       //77777777//(Ir::q#g,,'' 
	 
	AajG((,??I))'7;;J**:66DMM 	      r   c                    |                      |dg           }|d d d}t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |d          }|                     |d          }	|                     |d          }
t          j        ||	          }t          j        |
|	          }||v rUt          j        ||         d         |          ||         d<   t          j        ||         d         |          ||         d<   |                                 }||d<   ||d<   |||<    |                     |          S )	Nr   )r   	timestampdatetimer   r;  reservedunconfirmedusedtotal)	r3  r  r  r  r  r   
string_addr?  safe_balance)r   r  r>  r  r  walletrA  r   rF  rG  r   reservedUnconfirmedbalanceUnconfirmedr?  s                 r   parse_balancezluno.parse_balance  sx   //(Ir::
 

 q#g,,'' 	' 	'AQZF))&'::J**:66D''
;;H**6=AAK&&vy99G")"4X{"K"K!(!3G[!I!Iv~~'.'9&,v:NPc'd'dtV$(/(:6$<;PRd(e(etW%%,,.."5#5 &t  (((r   c                    K   |                                   d{V  |                     |           d{V }|                     |          S )as  
        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=  rO  )r   r
  r  s      r   fetch_balancezluno.fetch_balance  sg       !!!!!!!!!//77777777 !!(+++r   Nr  r   c           	        K   |                                   d{V  |                     |          }d|d         i}d}|6|dk    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d          }|                     ||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
        Npairr   d   rD  r  bidsasksr&  volume)rQ  r6  publicGetOrderbookTopextendpublicGetOrderbooksafe_integerparse_order_book)r   r  r   r
  r6  requestr  rD  s           r   fetch_order_bookzluno.fetch_order_book.  s      !!!!!!!!!V$$F4L
 #!77GV8T8TUUUUUUUUHH!44T[[&5Q5QRRRRRRRRH%%h<<	$$Xvh/?FTZ\cemnnnr   r7  c                 8    ddi}|                      |||          S )NPENDINGopen)r  )r   r7  statusess      r   parse_order_statuszluno.parse_order_statusG  s*     v
 &&999r   orderr6  c                    |                      |d          }|                     |                     |d                    }|dk    r|n|}d }|                     |d          }|dk    s|dk    rd}n|dk    s|d	k    rd
}|                     |d          }|                     ||          }|                     |d          }|                     |d          }	|                     |d          }
|                     |d          }|                     |d          }|                     |d          }d }|
|
|d         d}n|||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%|          S )&Ncreation_timestampstaterb  r   ASKSELLsellBIDBUYbuyrT  limit_pricelimit_volumefee_counterfee_baser  counterr  r+  r<  order_idr   clientOrderIdrE  rD  lastTradeTimestampr7  r  r   postOnlysider&  r   r%  filledr+  	remaining)r   r   r   average)r\  rd  r  safe_marketr5  
safe_orderiso8601)r   re  r6  rD  r7  ry  	orderTypemarketIdr&  r%  quoteFeebaseFeerz  r+  r   r   s                   r   parse_orderzluno.parse_orderN  s   $ %%e-ABB	(()9)9%)I)IJJ"f,,6$$UF33	I$7$7DD5  i5&8&8D##E622!!(F33  66!!%88##E=99""5*55!!%00y11 "7O CC  "6N C eZ00  
" 
T 
 Y// 
 	 

 !$ 
 f 
 fX& 
 D 
 4 
  
 D 
 U 
 D 
 f 
 f 
  D! 
" # 
$ + 
  
  
, -  	r   r   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     |          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>`
        Nr   )rQ  privateGetOrdersIdrZ  r  r   r   r  r
  r^  r  s         r   fetch_orderzluno.fetch_order  s       !!!!!!!!!"
 00Wf1M1MNNNNNNNN)))r   rh  sincec                 P  K   |                                   d {V  i }d }|||d<   | |                     |          }|d         |d<   |                     |                     ||                     d {V }|                     |dg           }	|                     |	|||          S )Nrh  r   rT  orders)rQ  r6  privateGetListordersrZ  r   parse_orders)
r   rh  r  r  r   r
  r^  r6  r  r  s
             r   fetch_orders_by_statezluno.fetch_orders_by_state  s      !!!!!!!!!$GG[[((F$TlGFO224;;w3O3OPPPPPPPP(B77  >>>r   c                 D   K   |                      d||||           d{V 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r  r   r  r  r   r
  s        r   fetch_orderszluno.fetch_orders  s6       //feUFSSSSSSSSSr   c                 D   K   |                      d||||           d{V 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>`
        ra  Nr  r  s        r   fetch_open_orderszluno.fetch_open_orders  s7       //	65%QWXXXXXXXXXr   c                 D   K   |                      d||||           d{V S )aC  
        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>`
        COMPLETENr  r  s        r   fetch_closed_orderszluno.fetch_closed_orders  s7       //
FE5RXYYYYYYYYYr   r   c                    |                      |d          }|                     |d          }|                     ||          }|                     |d          }|                     i d|d|d|                     |          dd dd d|                     |d          d	d d
|                     |d
          dd dd dd d|d|dd dd dd dd |                     |d          d |d|          S )NrD  rT  
last_trader  rE  highlowbid	bidVolumeask	askVolumevwaprb  closelastpreviousClosechanger   r|  rolling_24_hour_volume)
baseVolumequoteVolumer   )r\  r  safe_symbolsafe_tickerr  )r   r   r6  rD  r  r  r  s          r   parse_tickerzluno.parse_ticker  s    %%fk::	##FF33!!(F3355 !
f!
!
 Y//!
 D	!

 4!
 4##FE22!
 !
 4##FE22!
 !
 D!
 D!
 T!
 D!
 T!
 d!
  $!!
" t#!
$ **63KLL)!
 !
 !
* +  	r   symbolsc                   K   |                                   d{V  |                     |          }|                     |           d{V }|                     |d         d          }t	          |                                          }i }t          dt          |                    D ]H}||         }|                     |          }	|	d         }
||         }| 	                    ||	          ||
<   I| 
                    |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>`
        Nr   rT  r   r  )rQ  market_symbolspublicGetTickersindex_byr  r  r  r  r}  r  filter_by_array_tickers)r   r  r
  r  r   idsr  r  r   r6  r  r   s               r   fetch_tickerszluno.fetch_tickers  s      !!!!!!!!!%%g....v66666666-- 3V<<7<<>>""q#c((## 	? 	?AQB%%b))FH%FR[F!..vv>>F6NN++FHgFFFr   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          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>`
        NrT  r   )rQ  r6  publicGetTickerrZ  r  r   r  r
  r6  r^  r  s         r   fetch_tickerzluno.fetch_ticker  s       !!!!!!!!!V$$F4L
 --dkk'6.J.JKKKKKKKK   6222r   tradec                 :   |                      |d          }|                      |d          }d }d }|X|                      |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}|                      |d          }|                      |d          }	d }
d }| t          j        |d          s
|d         }
|}n!|	t          j        |	d          s
|d         }
|	}|                     |d          }|                     ||||                     |          |d         |d |||                      |d          |                     |dd          |                      |d          ||
dd|          S )Nru  sequencer   ri  rj  rk  rl  rm  rn  is_buyr   r   rr  rq  0.0r  r  rD  r  r&  rX  rs  rt  )r   r   rD  rE  r  re  r   ry  takerOrMakerr&  r%  r+  r   )r  r   string_equalsr\  
safe_trader  safe_string_2)r   r  r6  orderIdr   r  ry  r   feeBaseStringfeeCounterStringfeeCurrencyfeeCostrD  s                r   parse_tradezluno.parse_trade6  s   B ""5*55eZ00##E622D46>>%--TU]]v~~%/~&uX&&!(O755D((
;;++E=AA$(>> ($Vn')()95AA +$Wo*%%e[99	"Y//X&(%%eW55((&AA$$UI66'  
  
$ %  	r   c                 B  K   |                                   d{V  |                     |          }d|d         i}|||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          S )a,  
        get the list of most recent trades for a particular symbol

        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>`
        NrT  r   r  r   )rQ  r6  publicGetTradesrZ  r   parse_trades	r   r  r  r   r
  r6  r^  r  r   s	            r   fetch_tradeszluno.fetch_trades  s       !!!!!!!!!V$$F4L
 $GG--dkk'6.J.JKKKKKKKK (B77  >>>r   r   	timeframec                   K   |                                   d{V  |                     |          }|                     | j        ||          |d         d}||                     |          |d<   n2d|                     |          z  }|                                 |z
  |d<   |                     |                     ||                     d{V }	| 	                    |	dg           }
| 
                    |
||||          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
        Nr   )durationrT  r  i@B r   )rQ  r6  r3  r   parse_to_intparse_timeframemillisecondsexchangePrivateGetCandlesrZ  r   parse_ohlcvs)r   r  r  r  r   r
  r6  r^  r  r  ohlcvss              r   fetch_ohlcvzluno.fetch_ohlcv  s!      !!!!!!!!!V$$INN4L
 
 #0077GG"T%9%9)%D%DDH#0022X=GG77GV8T8TUUUUUUUU" )R88  E5IIIr   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )NrD  rb  r  r  r  rX  )r\  r5  )r   ohlcvr6  s      r   parse_ohlcvzluno.parse_ohlcv  s     e[11UF++UF++UE**UG,,UH--
 	
r   c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   |||d<   |                     |                     ||                     d{V }|                     |dg           }|                     ||||          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>`
        Nz+ fetchMyTrades() requires a symbol argumentrT  r   r  r   r   )r   r   rQ  r6  privateGetListtradesrZ  r   r  r  s	            r   fetch_my_tradeszluno.fetch_my_trades  s       >#DG.[$[\\\!!!!!!!!!V$$F4L
 $GG$GG224;;w3O3OPPPPPPPP, (B77  >>>r   c                 8  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|||                     |d          |                     |d          dddS )a_  
        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>`
        NrT  r   	maker_fee	taker_fee)r   r  r   r   r   r   )rQ  r6  privateGetFeeInforZ  r5  r  s         r   fetch_trading_feezluno.fetch_trading_fee  s       !!!!!!!!!V$$F4L
 //GV0L0LMMMMMMMM %%h<<%%h<<
 
 	
r   r   ry  r%  r&  c                   K   |                                   d{V  |                     |          }d|d         i}d}	|dk    r|                                |d<   |dk    r |                     |d         |          |d<   n|                     |d         |          |d	<   |                     |                     ||                     d{V }	nz|                     |d         |          |d
<   |                     |d         |          |d<   |dk    rdnd|d<   |                     |                     ||                     d{V }	|                     |	|	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>`
        NrT  r   r6  r   rn  r  counter_volumebase_volumerX  r&  rl  ri  ru  )r   r   )	rQ  r6  upperamount_to_precisionprivatePostMarketorderrZ  price_to_precisionprivatePostPostorderr~  )
r   r  r   ry  r%  r&  r
  r6  r^  r  s
             r   create_orderzluno.create_order<  s      !!!!!!!!!V$$F4L
 8"jjllGFOu}},0,D,DVHEUW],^,^()))-)A)A&BRTZ)[)[&!88Wf9U9UVVVVVVVVHH $ 8 89I6 R RGH#66vh7GOOGG(,eeEGFO!66t{{7F7S7STTTTTTTTH:& 
  
   	r   c                    K   |                                   d{V  d|i}|                     |                     ||                     d{V }|                     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>`
        Nru  r   )rQ  privatePostStoporderrZ  r~  r  s         r   cancel_orderzluno.cancel_orderc  s       !!!!!!!!!
 224;;w3O3OPPPPPPPP H 
   	r   r   c           	         K   |d}|d}d }||                      ||          d}|                     ||||                     ||                     d {V S )Nr   )min_rowmax_row)sumfetch_ledgerrZ  )r   r   entryr   r
  r  r^  s          r   fetch_ledger_by_entrieszluno.fetch_ledger_by_entries|  s|      =E=Exxu--
 
 &&tUE4;;wPV;W;WXXXXXXXXXr   c                   K   |                                   d{V  |                                  d{V  d}|                     |d          }|                     |d          }|                     |d          }||t	          | j        dz             |                     |          }|                     | j        d          }	|                     |	|          }
|
t          | j        dz   |z             |
d         }||d}d	}n||t          | j        d
z             | ||z
  |k    r|dk    r||z
  }n|dk    r||z   }||z
  dk    rt          | j        dz             |||d}| 
                    |                     ||                     d{V }|                     |dg           }|                     ||||          S )ax  
        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-entry-structure>`
        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)rQ  load_accountsr  r3  r   r   r<  r  r   r    privateGetAccountsIdTransactionsrZ  parse_ledger)r   r   r  r   r
  r<  r   r  r  accountsByCurrencyCoder?  r^  r  entriess                 r   r  zluno.fetch_ledger  s<      !!!!!!!!!  """""""""fd++//&)44//&)44:|'  3J  )J  K  K  K}}T**H%)]]4=*%M%M"oo&<dCCG#DG.]$]`d$deeeB?wGGG_*   A  A  A7!2U!:!:!||!E/1!E/Wt##*l lmmm
 

 >>t{{6SZ?[?[\\\\\\\\//(NB??  (E5AAAr   c                 `   |                     d          }dddddddddddd}d }|                     |d	          }|                     |d
          }|                     |d          }|                     ||d           }||dk    rd}|dk    r|dk    r|                     |d          }||dS )N r   transactionreleasedrF  r  failed)
WithdrawalTradingPaymentSentDepositReceivedReleasedReservedSoldBoughtFailurer         re     )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7LyE11DJZ7%:%:**5!44K&
 
 	
r   r<  c                    |                      |d          }|                      |d          }|                     |d          }|                      |d          }|                     ||          }|                     ||          }|                      |d          }|                      |d          }	|                      |d          }
|                      |d          }|
}d	}|                     |          }|d
         }|d         }d }d }t          j        |	d	          s,t          j        |
|	          }d}t          j        |	          }nWt          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}|                     |||||d |||                     |          ||                     |          |                     |          |                     |
          |d d|          S )N	row_indexr:  rD  r<  available_deltabalance_deltar   descriptionr  r   r  okpendingcanceledr   inout)r   r   	directionr?  r  referenceAccountr   r<  r%  rD  rE  beforeafterr7  r   )r  r\  r  safe_currencyr  r   r  
string_sub
string_abs	string_lt	string_gtsafe_ledger_entryparse_to_numericr  )r   r  r<  r   r:  rD  rA  r   r  r  r$  r  r#  r%  r  r   r  r!  r7  s                      r   parse_ledger_entryzluno.parse_ledger_entry  s   e[11%%e\::
%%e[99	%%eZ88
&&z8<<%%j(;;**52CDD((@@  	22""5-88**733f~]+	$]E:: 		9'}==FF'66FF66 	9F'88FF66 	9F'88F]C00 	G4EoWZ4[4[ 	II}c22 	g6GY\6]6] 	I%%"!& $++F33"Y//++F33**511'
 '
  !  	r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          S )a1  
        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   )rQ  r<  privatePostFundingAddressrZ  parse_deposit_addressr   r   r
  r<  r^  r  s         r   create_deposit_addresszluno.create_deposit_address	  s       !!!!!!!!!==&&Xd^
 77GV8T8TUUUUUUUU* ))(H===r   c                   K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     ||          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>`
        Nr;  r   )rQ  r<  privateGetFundingAddressrZ  r/  r0  s         r   fetch_deposit_addresszluno.fetch_deposit_address1  s       !!!!!!!!!==&&Xd^
 66t{{7F7S7STTTTTTTT* ))(H===r   c                     |                      |d          }|                     ||          }||d |                     |d          |                     |d          dS )Nr<  addressr   )r   r<  r   r6  tag)safe_string_upperr  r  )r   depositAddressr<  rA  r   s        r   r/  zluno.parse_deposit_addressX  sl    * ++NJGG
&&z8<<"''	BB##NF;;
 
 	
r   r   GETc                    | j         d         |         dz   | j        z   dz   |                     ||          z   }|                     ||                     |                    }|r|d|                     |          z   z  }|dk    s|dk    r@|                                  |                     | j        dz   | j	        z             }	dd|	z   i}||||d	S )
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   signz	luno.signw  s    is#c)DL83>ATATUY[aAbAbb		&$"5"5d";";<< 	/3....C9#):":":++---((s):T[)HIIDDG fdwOOOr   httpCodereasonr?  r@  rB  rA  c
                     |d S |                      |d          }
|
-t          | j        dz   |                     |          z             d S )Nerrorr  )r3  r   r   json)r   rN  rO  r?  r@  rB  rA  r  requestHeadersrequestBodyrQ  s              r   handle_errorszluno.handle_errors  sP    4'22#		(0C0C CDDDtr   )N)@__name__
__module____qualname__r   r   r   r  r   r   r8  r   rB  r   rO  rR  strr   r   r_  r   rd  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  r  r	   r,  r
   r1  r4  r/  rM  intrU  __classcell__)r   s   @r   r   r      s       b# b b b b b bH	 -/ R R: R R R Rh *, X XV X X X Xt +-  g    2) ) ) ) )4 *, , , , , , ,. @DB o oS o oS\ o o o o2: : : : :E E Ev E E E E EN 8<B * *C * * * * *$ EIW[jnwy ? ? ?c ?QT ?dg ? ? ? ? 04$UYbd T T TC Ts Timnsit T T T T 59tZ^gi Y Yc Y YTW Ynrsxny Y Y Y Y 7;\`ik Z Z Z3 ZVY Zptuzp{ Z Z Z Z# #4 # #6 # # # #J 6:" G G7 G G G G G0 68 3 3 3F 3 3 3 36R R Rv R R R R Rh <@d[] "? "? "?S "? "?bfglbm "? "? "? "?H ?CQUdhqs *J *J *J *J3 *J^a *J *J *J *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# Y Y Y Y .2SW`b .B .Bs .B# .BS .Bgklwgx .B .B .B .B`
 
 
:1 1( 1k 1 1 1 1f >@ &> &> &>N &> &> &> &>P =? %> %> %>> %> %> %> %>N
 
h 
R` 
 
 
 
> &eBSW P P P 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   r   typingr   ccxt.base.errorsr   r   ccxt.base.decimal_to_precisionr   ccxt.base.preciser   r    r   r   <module>rf     s   6 5 5 5 5 5 * * * * * * [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [  [       * * * * * * . . . . . . 4 4 4 4 4 4 % % % % % %z z z z z8[ z z z z zr   