
    !:h                    X   d dl mZ d dlmZ d dl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mZ d dlmZ d dlmZ d dlmZ d dlm Z  d d	lm!Z! d d
lm"Z" d dlm#Z# d dlm$Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dlm)Z) d dlm*Z* d dl+m,Z, d dl-m.Z.  G d dee      Z/y)    )Exchange)ImplicitAPIN)AnyBalancesCurrencyDepositAddressIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersFundingRateFundingRatesTradeTradingFeeInterfaceTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)DuplicateOrderId)NotSupported)RateLimitExceeded)InvalidNonce)	TICK_SIZE)Precisec                   Z    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Z
i fdZdVded	edefd
Zi fdedefdZdi fdedefdZdi fdededefdZdVded	edefdZddi fdedededee   fdZdVd	edefdZdddi fdedededee   fdZdefdZdVd	edefdZi fdedefdZ di fdede!fdZ"i fdefdZ#dVded	ede$fdZ%i fdede$fdZ&i f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(e/fd)Z0dVd*ed	ede1fd+Z2di fd,ede/fd-Z3di fd,ede/fd.Z4di fd,ede/fd/Z5dddi fde/dedefd0Z6dddi fde/dededee1   fd1Z7dddi fde/dededee1   fd2Z8di fd,ede/fd3Z9di fde/fd4Z:d5 Z;i fd6ede<fd7Z=i fd6ede<fd8Z>i fd6ede<fd9Z?di fd6ed%e)d:ede@fd;ZAd< ZBdVd=ed>eCde@fd?ZDdddi fd6e/dededee@   fd@ZEdddi fd6e/dededee@   fdAZFdi fdBefdCZGi fdDZHi fdEZIdi fdBefdFZJdi fdGZKdi fdHZLdVdIZMdVd>eCfdJZNdKdLi ddfdMZOdN ZPdOeQdPedQedRedSedTefdUZR xZSS )Wlbankreturnc           )         | j                  t        t        |          dddg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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dd<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSi dTdUdVdUdWdUdXdUdYdUdZdUd[dUd\dUd]dUd^dUd_dUd`dUdadUdbdUdcdUdddUdedUidfdgi dhdUdidUdjdUdkdUdldUdmdUdndodpdodqdodrdodsdUdtdUdudUdvdUdwdUdxdUdydUi dzdUd{dUd|dUd}dUd~dUddUddUddUddUd`dUddoddoddoddoddUddUddUdUdUdiddddUdUdUdUdiid| j	                  d      | j	                  d      ddxi idddddt
        ddddiddiddiddiddiddiddii dddddddddddddddddddddddddddddddddddddddddddddddddddidd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dd d ddddɜd ddid̜	ddiddid dϜd d dϜdМdќ      S )Nr+   LBankCNv2   TCORSFspotmarginswapfutureoption	addMargincancelAllOrderscancelOrdercreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateReduceOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrderfetchBalancefetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositWithdrawFeeemulatedfetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchIsolatedPositionsfetchLeveragefetchLeverageTiersfetchMarginModefetchMarketsfetchMarkOHLCVfetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchOrdersfetchPositionfetchPositionModefetchPositionsfetchPositionsRisk)fetchPremiumIndexOHLCVfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeesfetchTransactionFeesreduceMarginsetLeveragesetMarginModesetPositionModewithdrawminute1minute5minute15minute30hour1hour2hour4hour6hour8hour12day1week1)1m5m15m30m1h2h4h6h8h12h1d1wzchttps://user-images.githubusercontent.com/1294454/38063602-9605e28a-3302-11e8-81be-64b1e53c4cfb.jpgzhttps://api.lbank.infozhttps://lbkperp.lbank.com)restcontractzhttps://api.lbkex.comzhttps://www.lbank.comz+https://www.lbank.com/en-US/docs/index.htmlzhhttps://support.lbank.site/hc/en-gb/articles/900000535703-Trading-Fees-From-14-00-on-April-7-2020-UTC-8-z'https://www.lbank.com/login/?icode=7QCY)logoapiapi2wwwdocfeesreferralcurrencyPairsg      @accuracyusdToCnywithdrawConfigs	timestampzticker/24hrtickerdepth	incrDepthtradesklinezsupplement/system_pingzsupplement/incrDepthzsupplement/tradeszsupplement/ticker/pricezsupplement/ticker/bookTickerzsupplement/system_status)getpostr   	user_infozsubscribe/get_keyzsubscribe/refresh_keyzsubscribe/destroy_keyget_deposit_addressdeposit_historycreate_order   batch_create_ordercancel_ordercancel_clientOrdersorders_infoorders_info_historyorder_transaction_detailtransaction_historyorders_info_no_dealrq   withdrawCancel	withdrawszsupplement/user_infozsupplement/withdrawzsupplement/deposit_historyzsupplement/withdrawszsupplement/get_deposit_addresszsupplement/asset_detailzsupplement/customer_trade_feezsupplement/api_Restrictionszsupplement/create_order_testzsupplement/create_orderzsupplement/cancel_orderz!supplement/cancel_order_by_symbolzsupplement/orders_infozsupplement/orders_info_no_dealzsupplement/orders_info_history)zsupplement/user_info_accountzsupplement/transaction_history)publicprivater   r   )zcfd/openApi/v1/pub/getTimezcfd/openApi/v1/pub/instrumentzcfd/openApi/v1/pub/marketDatazcfd/openApi/v1/pub/marketOrder)r3   r   z0.001)makertaker)tradingfundingHiverVENPenta)HIT	VET_ERC20PNTmethodspotPublicGetTradesfetchPrivateTransactionFeesfetchPrivateDepositWithdrawFeesfetchDepositAddressDefault$spotPrivatePostSupplementCreateOrderfetchOrderSupplement!spotPrivatePostSupplementUserInfoERC20erc20ETHTRC20trc20TRXOMNIomniASAasaBEP20
bep20(bsc)BSCHThecoBNBbep2BTCbtcDOGEdogecoinMATICmaticPOLYGONOECoecBTCTRONbtctronXRPxrp)r   r   r   r   r   bep20r   r   r   r   r   r   r   r   USDT)cacheSecretAsPem!createMarketBuyOrderRequiresPricerj   rl   rN   rI   r>   r_   rC   networksinverse-networksdefaultNetworks)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedselfTradePreventiontrailingleveragemarketBuyByCostmarketBuyRequiresPriceicebergd   i    )r   limitdaysBack	untilDayssymbolRequired)r   triggerr   r      )r   r   r   r   r   )r   r   r   r   r   r   r   r     )	sandboxr>   createOrdersr\   r_   r^   ra   rF   r]   extendsdefault)linearinverse)r  r3   r5   r6   )idname	countriesversion	rateLimitprohas
timeframesurlsr   r   commonCurrenciesprecisionModeoptionsfeatures)deep_extendsuperr+   describeparse_numberr(   )self	__class__s    D/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/lbank.pyr  zlbank.describe   s   eT ; = @@@ %@ 	@
 %@ %@ U@ "4@ t@ /@ ,U@ 0@ t@ (@ '@  (!@" "5#@$ %@& +E'@( )%)@* $U+@, '-@. (/@0 &t1@2 (3@4 1%5@6 *:7@8 +D9@: &u;@< #E=@> *5?@@ $TA@B "5C@D *5E@F +EG@H )%I@J  K@L %eM@N "5O@P Q@R !%S@T  U@V dW@X "4Y@Z d[@\ !$]@^ t_@`  a@b $Uc@d !%e@f %eg@h +0# $!#$((, %$!&#( @D  !! ~4 ; 0.D CE +S &  '  .s	 
 (  *3  %c  $S  (  %c  $S  5c  3C  0   6s! " ;C# ( 7!)2  *!'*! 0*! 4S	*!
 4S*! 23*! .s*! +A*! 1!*! +A*! 21*! *3*! 23*! 7*!  23!*!" 23#*!& ''*!( -c)*!* (+*!, 3C-*!. 23/*!0 9#1*!2 3C3*!4 =c5*!6 6s7*!8 <S9*!: :3;*!> 5c?*!B ;AC*!D 6qE*!F 6qG*!H @I*!J 5cK*!L =cM*!N =cO*!P =@>AS*!, 3FP :==@=@>A	 	QRj "..w7!..w7
  "!
 '$(593  ;) ?- :( D  4 A!%W%7% W% 7	%
 F% 5% \% <% &% 6% 5% J% W% w% 5%  y!%" 5#%N %$" "'" !  &$ ( %" G$]Qh  %&+(-,0,1).+06:#'#'"'#(	( #(/4$)$)+/27#()$, %)&+!$$*%&*.& ',#($)*.	# ',!$#($)*.( ',!$$(%)#($)*.$ *.#o:x y
 "9  $	 ##KIqb@
 b b	    c                     d}| j                  dd|      \  }}d}|dk(  r| j                  |      }n| j                  |      }| j                  |d      S )a  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://www.lbank.com/en-US/docs/index.html#get-timestamp
        https://www.lbank.com/en-US/docs/contract.html#get-the-current-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        Nri   r5   data)handle_market_type_and_params'contractPublicGetCfdOpenApiV1PubGetTimespotPublicGetTimestampsafe_integer)r  paramstyperesponses       r  
fetch_timezlbank.fetch_time  sb     99+tVTf6>CCFKH226:H*   622r  c                 z    | j                  |      | j                  |      g}|}| j                  |d   |d         S )ao  
        retrieves data on all markets for lbank

        https://www.lbank.com/en-US/docs/index.html#trading-pairs
        https://www.lbank.com/en-US/docs/contract.html#query-contract-information-list

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        r   r   )fetch_spot_marketsfetch_swap_marketsarray_concat)r  r$  marketsPromisesresolvedMarketss       r  fetch_marketszlbank.fetch_markets  sK     ##F+##F+
 *  !3_Q5GHHr  c                    | j                  |      }| j                  |dg       }g }t        dt        |            D ]0  }||   }| j	                  |d      }|j                  d      }|d   }	|d   }
| j                  |	      }| j                  |
      }|dz   |z   }|j                  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 | j                  | j                  | j	                  |d                  | j                  | j                  | j	                  |d                  dd d d| j                  |d      d dd d dd d ddd |d
       3 |S ) Nr  r   symbol_r   /r	  basequotebaseIdquoteIdsettlesettleIdr%  r3   Tr4   Fr5   r6   r7   activer   r  quantityAccuracypriceAccuracyamountpriceminmax
minTranQuar   r=  r>  cost
r  contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedinfo)spotPublicGetAccuracy
safe_valuerangelensafe_stringsplitsafe_currency_codeappendr  parse_precisionsafe_number)r  r$  r&  r  resultimarketmarketIdpartsr5  r6  r3  r4  r0  s                 r  r)  zlbank.fetch_spot_markets  sL   --f5  x4q#d)$ 9	A!WF''9HNN3'E1XFAhG**62D++G4ECZ%'FMM 0h0&0 0 	0
 &0 70 $0 D0 0 0 %0 0 %0 %0 $0  E!0" $#0$   $"&""//0D0DTEUEUV\^pEq0rs!..t/C/CDDTDTU[]lDm/no  $#!
  $//E#
  $#
  $#$  _0 09	t r  c                 x   ddi}| j                  | j                  ||            }| j                  |dg       }g }t        dt	        |            D ]f  }||   }| j                  |d      }| j                  |d      }	| j                  |d      }
|
}| j                  |	      }| j                  |      }| j                  |
      }|dz   |z   d	z   |z   }|j                  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 | j                  |d      d d d d | j                  |d      | j                  |d      dd d d | j                  |d!      | j                  |d"      d | j                  |d#      | j                  |d$      d | j                  |d%      d d d&d |d'
       i |S )(NproductGroupSwapUr  r   r0  baseCurrencyclearCurrencyr2  :r	  r3  r4  r7  r5  r6  r8  r%  r5   r3   Fr4   Tr6   r7   r9  r   r  volumeMultiple
volumeTick	priceTickr<  r?  minOrderVolumemaxOrderVolumepriceLimitLowerValuepriceLimitUpperValueminOrderCostrC  rE  )	*contractPublicGetCfdOpenApiV1PubInstrumentextendrP  rQ  rR  rS  rU  rV  rX  )r  r$  requestr&  r  rY  rZ  r[  r\  r5  r8  r6  r3  r4  r7  r0  s                   r  r*  zlbank.fetch_swap_markets
  s   G
 BB4;;wX^C_`: x4q#d)$ :	A!WF''9H%%fn=F''@HG**62D++G4E,,X6FCZ%'#-6FMM 0h0&0 0 	0
 &0 &0 70 H0 0 0 %0 0 %0 %0 $0  D!0" $#0$   $ 0 09I J"&""..v|D!--fkB  $#!
  $//8HI#//8HI
  $//8NO#//8NO
  $//G#$  _0 0:	v r  Nr   r[  c           	      f   | j                  |d      }| j                  |d      }| j                  ||      }| j                  |di       }| j	                  ||      }|d   r|n|}| j                  i d|d|d| j                  |      d| j                  |dd      d| j                  |dd	      d
d dd dd dd dd d| j                  |d      dd d| j                  |dd      dd dd d| j                  |d      dd | j                  |dd      | j                  |d      |d|      S )Nr   r0  r   r   datetimehighhighestPricelowlowestPricebid	bidVolumeask	askVolumevwapopen	openPricecloselastlatest	lastPricepreviousClosechange
percentageaveragevolvolumeturnover)
baseVolumequoteVolumerN  )r#  rS  safe_symbolrP  safe_marketsafe_tickeriso8601safe_string_2)r  r   r[  r   r\  r0  
tickerDatar  s           r  parse_tickerzlbank.parse_tickerj  s   > %%fk:	##FH5!!(F3__VXr:
!!(F3 ,v: !
f!
!
 Y/!
 D&&tV^D	!

 4%%dE=A!
 4!
 !
 4!
 !
 D!
 D$$T;7!
 T!
 D&&tX{C!
 T!
 d!
  $**4:!!
" t#!
$ ,,T5(C++D*=)!
* + 	r  r0  c                 d   | j                          | j                  |      }|d   r+| j                  |d   g|      }| j                  ||d         S d|d   i}| j	                  | j                  ||            }| j                  |dg       }| j                  |di       }| 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.lbank.com/en-US/docs/index.html#query-current-market-data-new

        :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>`
        r5   r0  r	  r  r   )load_marketsr[  fetch_tickersrP  spotPublicGetTicker24hrrm  	safe_dictr  )	r  r0  r$  r[  responseForSwaprn  r&  r  firsts	            r  fetch_tickerzlbank.fetch_ticker  s     	V$&>"00&2B1CVLO???F84DEEfTl
 //GV0LM, x4tQ+  //r  symbolsc                    | j                          d}|5| j                  |      }t        |      }|dkD  r| j                  |d         }i }d}| j	                  d||      \  }}d}|dk(  r'd|d<   | j                  | j                  ||            }n&d|d<   | j                  | j                  ||            }| j                  |d	g       }| j                  ||      S )
aw  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://www.lbank.com/en-US/docs/index.html#query-current-market-data-new
        https://www.lbank.com/en-US/docs/contract.html#query-contract-market-list

        :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   rh   r5   r`  r_  allr0  r  )
r  market_symbolsrR  r[  r   *contractPublicGetCfdOpenApiV1PubMarketDatarm  r  	safe_listparse_tickers)	r  r  r$  r[  symbolsLengthrn  r%  r&  r  s	            r  r  zlbank.fetch_tickers  s     	))'2GLMq WQZ099.&RXYf6>&-GN#FFt{{SZ\bGcdH %GH33DKK4PQH\ ~~h3!!$00r  r   c           	         | j                          | j                  |      }|d}d|d   i}d}| j                  d||      \  }}d}|dk(  r'||d<   | j                  | j	                  ||            }n&||d<   | j                  | j	                  ||            }| j                  |d	i       }| j                         }	|d   r| j                  ||d   |	d
ddd      S | 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.lbank.com/en-US/docs/index.html#query-market-depth
        https://www.lbank.com/en-US/docs/contract.html#get-handicap

        :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<   r0  r	  r`   r5   r   sizer  bidsasksr>  r  r   r   )	r  r[  r   +contractPublicGetCfdOpenApiV1PubMarketOrderrm  spotPublicGetDepthrP  millisecondsparse_order_book)
r  r0  r   r$  r[  rn  r%  r&  	orderbookr   s
             r  fetch_order_bookzlbank.fetch_order_book  s%    	V$=EfTl
 99:JFTZ[f6>$GGGGT[]cHdeH#GFO..t{{7F/KLHb OOHfb9	%%'	&>((F84DiQWY_ahjrss$$Yx0@)VU[]^`abbr  tradec                 b   | j                  |dd      }|| j                  |d      }| j                  |dd      }|| j                  |d      }| j                  |d      }|| j                  |d      }| j                  |d	      }|| j                  |d
      }| j                  |dd      }d }d }	|J|j	                  d      }
| j                  |
d      }| j                  |
d      }d}d}	||dk(  rd}n|dk(  rd}	| j                  |dd      }|| j                  |d      }| j                  |d      }| j                  d |      }d }| j                  |d      }|#||dk(  r|d   n|d   | j                  |d      d}| j                  || j                  |      |||||	||||||d|      S )Ndate_mstimedealTimer=  qtydealQuantityr>  	dealPricequoteQtydealVolumePrice	tradeTyper%  r1  r   r   r   r   r[  r   tidr	  txUuid	orderUuidtradeFeebuyr3  r4  tradeFeeRate)rD  currencyrate)r   rp  r0  r	  orderr%  takerOrMakersider>  r=  rD  feerN  )safe_integer_2r#  r  rS  rT  r  
safe_trader  )r  r  r[  r   amountStringpriceString
costStringr  r%  r  r]  typePartr	  r  r0  r  feeCosts                    r  parse_tradezlbank.parse_tradep  s   L ''y&A	))%<I))%5A++E>BL&&ug6**5+>K%%eZ8
))%1BCJ!!%f=JJsOE##E1-D''q1HD"L#x'#D(#*Lud3:!!%2B  4!!$/""5*5/3u}F6N6'?((?C
 "Y/( " 
  	r  sincec                    | j                          | j                  |      }d|d   i}|||d<   |t        |d      |d<   nd|d<   | j                  | j                  di       }| j                  |dd	      }| j                  |d|      }	| j                  |d      }d}
|	d
k(  r"| j                  | j                  ||            }
n!| j                  | j                  ||            }
| j                  |
dg       }| j                  ||||      S )a~  
        get the list of most recent trades for a particular symbol

        https://www.lbank.com/en-US/docs/index.html#query-historical-transactions
        https://www.lbank.com/en-US/docs/index.html#recent-transactions-list

        :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>`
        r0  r	  Nr  iX  r  rj   r   r   spotPublicGetSupplementTradesr  )r  r[  r@  rP  r  rS  omitr  rm  r   r  parse_trades)r  r0  r  r   r$  r[  rn  r  defaultMethodr   r&  r   s               r  fetch_tradeszlbank.fetch_trades  s    	V$fTl
 #GFO!%oGFO!GFO//$,,rB(((<QR!!&(MB68,4499$++gv:VWH//GV0LMH" &"5  >>r  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r   r            )safe_timestamprX  )r  ohlcvr[  s      r  parse_ohlcvzlbank.parse_ohlcv  sn     q)UA&UA&UA&UA&UA&
 	
r  r~   c                    | j                          | j                  |      }|d}nt        |d      }|*| j                  |      }| j	                         |dz  |z  z
  }|d   | j                  | j                  ||      | j                  |dz        t        |dz   d      d}| j                  | j                  ||            }	| j                  |	dg       }
| j                  |
||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://www.lbank.com/en-US/docs/index.html#query-k-bar-data

        :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 exchange API endpoint
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        r   r  i  r	  r   )r0  r%  r  r  r  )r  r[  r@  parse_timeframer  rS  r  parse_to_intspotPublicGetKlinerm  r  parse_ohlcvs)r  r0  	timeframer  r   r$  r[  durationrn  r&  ohlcvss              r  fetch_ohlcvzlbank.fetch_ohlcv  s     	V$=Et$E=++I6H%%'8d?U+BCETl$$T__iK%%edl3	4(	
 **4;;w+GH&"5,   E5IIr  c                    | j                  |d      }||| j                  |      d}| j                  |d      }| j                  |d      }|| j                  |di       }| j                  |di       }t        |j	                               }t        dt        |            D ]W  }	||	   }
| j                  |
      }| j                         }| j                  ||
      |d<   | j                  ||
      |d<   |||<   Y | j                  |      S | j                  |d	      }|t        dt        |            D ]i  }	||	   }| j                  |d
      }
| j                  |
      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S t        |t              }|du rt        dt        |            D ]i  }	||	   }| j                  |d      }
| j                  |
      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   k | j                  |      S y )Nts)rN  r   rp  r  toBtcfreezefreer   usedbalancesassetlockedTcoin	usableAmt	freezeAmt)r#  r  rP  listkeysrQ  rR  rU  accountrS  safe_balance
isinstance)r  r&  r   rY  r  r  r  r  
currenciesrZ  
currencyIdcoder  r  item	codeInnerisArrays                    r  parse_balancezlbank.parse_balanceK  sp   \ %%h5	"Y/

 x0g.??426D??44Ddiik*J1c*o. '']
..z:,,."&"2"24"D"&"2"24"D&t' $$V,,??441c(m, ,{!--dG<
 33J?	,,."&"2"24"@"&"2"24"B$+y!, $$V,,T4(d?1c$i( ,Aw!--dF;
 33J?	,,."&"2"24"E"&"2"24"E$+y!, $$V,,r  c                    | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }	d }
|	%| j	                  |	dz  dz        }t        |      dz   }
i d	|d|d
|d|d|d|d| j                  |      dd dd dd dd dd dd dd dd d|
S )Nr0  markedPriceunderlyingPricefundingRatenextFeeTimepositionFeeTimer  hrN  	markPrice
indexPricefundingTimestampfundingDatetimer   rp  nextFundingRatenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeinterval)rS  r  rX  r#  r  strr  )r  r   r[  r\  r0  r   r  r  fundingTimer  intervalStringr
  s               r  parse_funding_ratezlbank.parse_funding_rate  s     ##FH5!!(F3$$V];	%%f.?@
&&v}=''>++F4EF&((2)=)BCH ]S0N
F
f
 
 *	

 ;
 
 t||K8
 
 
 t
 #D
 "4
 "4
 '
 &t
  !
 	
r  c                     | j                          | j                  |      }| j                  |d   g|      }| j                  ||d         S )aq  
        fetch the current funding rate

        https://www.lbank.com/en-US/docs/contract.html#query-contract-market-list

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
        r0  )r  r[  fetch_funding_ratesrP  )r  r0  r$  r[  r  s        r  fetch_funding_ratezlbank.fetch_funding_rate  sN     	V$22F84D3EvNx0@AAr  c                     | j                          | j                  |      }ddi}| j                  | j                  ||            }| j	                  |dg       }| j                  ||      S )a  
        fetch the funding rate for multiple markets

        https://www.lbank.com/en-US/docs/contract.html#query-contract-market-list

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rates-structure>`, indexed by market symbols
        r_  r`  r  )r  r  r  rm  r  parse_funding_rates)r  r  r$  rn  r&  r  s         r  r  zlbank.fetch_funding_rates  sq     	%%g.G
 BB4;;wX^C_`0 ~~h3''g66r  c                 F   | j                          | j                  | j                  di       }| j                  |dd      }| j                  |d|      }d}|dk(  r| j	                         }n&|dk(  r| j                         }n| j                         }| j                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://www.lbank.com/en-US/docs/index.html#asset-information
        https://www.lbank.com/en-US/docs/index.html#account-information
        https://www.lbank.com/en-US/docs/index.html#get-all-coins-information

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        rC   r   r   N(spotPrivatePostSupplementUserInfoAccountspotPrivatePostUserInfo)r  rP  r  rS  r  r  r   r  )r  r$  r  r  r   r&  s         r  fetch_balancezlbank.fetch_balance/  s     	//$,,C(((<_`!!&(MB??DDFH00335H==?H> !!(++r  r  c                     | j                  |d      }| j                  |      }||| j                  |d      | j                  |d      d d dS )Nr0  makerCommissiontakerCommission)rN  r0  r   r   r  	tierBased)rS  r  rX  )r  r  r[  r\  r0  s        r  parse_trading_feezlbank.parse_trading_feee  s^     ##C2!!(+%%c+<=%%c+<=
 	
r  c                     | j                  |      }| j                  | j                  |d|d   i            }| j                  ||      S )aa  
        fetch the trading fees for a market

        https://www.lbank.com/en-US/docs/index.html#transaction-fee-rate-query

        :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>`
        categoryr	  )r[  fetch_trading_feesrm  r  )r  r0  r$  r[  rY  s        r  fetch_trading_feezlbank.fetch_trading_feex  sH     V$((Vj&QU,=W)XY~~ff--r  c                    | j                          i }| j                  | j                  ||            }| j                  |dg       }i }t	        dt        |            D ]   }| j                  ||         }|d   }|||<   " |S )aa  
        fetch the trading fees for multiple markets

        https://www.lbank.com/en-US/docs/index.html#transaction-fee-rate-query

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>` indexed by market symbols
        r  r   r0  )r  )spotPrivatePostSupplementCustomerTradeFeerm  rP  rQ  rR  r  )	r  r$  rn  r&  r   rY  rZ  r  r0  s	            r  r  zlbank.fetch_trading_fees  s     	AA$++gW]B^_x4q#d)$ 	!A((a1C]F F6N	! r  rD  c                     | j                          | j                  |      }|d   st        | j                  dz         d|d<   | j	                  |dd|d|      S )a#  
        create a market buy order by providing the symbol and cost

        https://www.lbank.com/en-US/docs/index.html#place-order
        https://www.lbank.com/en-US/docs/index.html#place-an-order

        :param str symbol: unified symbol of the market to create an order in
        :param float cost: how much you want to trade in units of the quote currency
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r3   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr   r[  r  N)r  r[  r%   r	  r   )r  r0  rD  r$  r[  s        r  !create_market_buy_order_with_costz'lbank.create_market_buy_order_with_cost  s`     	V$f~tww)ddee6;23  5$fMMr  r%  r  r=  r>  c                    | j                          | j                  |      }| j                  |dd      }| j                  |dd      }	| j	                  |d      }
| j                  |g d      }d|d   i}|
d	k(  }|
d
k(  }|	xs |
dk(  }|dk(  r|s|s|rt        | j                  dz         |dk(  r]||d<   | j                  ||      |d<   | j                  ||      |d<   |r|dz   dz   |d<   n-|r|dz   dz   |d<   n|r|dz   dz   |d<   n|dk(  r|dk(  r!|dz   dz   |d<   | j                  ||      |d<   n|dk(  r|dz   dz   |d<   d}d}| j                  |ddd      \  }}| j                  |d      }| j                  |d      }|| j                  ||      }ny|re|t        | j                  dz         | j                  |      }| j                  |      }t        j                  ||      }| j                  ||      }n| j                  ||      }||d<   |||d<   | j!                  | j"                  di       }| j%                  |dd      }| j%                  |d|      }| j                  |d      }d}|d k(  r"| j'                  | j)                  ||            }n!| j+                  | j)                  ||            }| j!                  |d!i       }| j-                  | j%                  |d"      |d#|      S )$a  
        create a trade order

        https://www.lbank.com/en-US/docs/index.html#place-order
        https://www.lbank.com/en-US/docs/index.html#place-an-order

        :param str symbol: unified symbol of the market to create an order in
        :param str type: 'market' or 'limit'
        :param str side: 'buy' or 'sell'
        :param float amount: how much of currency you want to trade in units of base currency
        :param float [price]: the price at which the order is to be 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>`
        	custom_idclientOrderIdpostOnlyFr   )r&  r'  r   r(  r0  r	  r   r   r   r[  zw createOrder() does not allow market FOK, IOC, or postOnly orders. Only limit IOC, FOK, and postOnly orders are allowedr   r%  r>  r=  r1  iocfokr   sellr  NTr>   r   rD  z createOrder() requires the price argument for market buy orders to calculate the total cost to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to False and pass the cost to spend in the amount argumentr   r   spotPrivatePostCreateOrderr  order_id)r	  rN  )r  r[  r  	safe_boolsafe_string_upperr  r#   r	  price_to_precisionamount_to_precisionhandle_option_and_paramsrX  cost_to_precisionnumber_to_stringr)   
string_mulrP  r  rS  r,  rm  r   
safe_order)r  r0  r%  r  r=  r>  r$  r[  r'  r(  r   rn  r)  r*  r   quoteAmountr   rD  r  r  costRequestr  r  r   r&  rY  s                             r  r   zlbank.create_order  sx    	V$**6;P>>&*e<,,V]C6#\]fTl
 e#e#2kT1H3#tww  *c   c  d  d7?"GFO#66vuEGG $ 8 8 HGH"&*u"4"&*u"4"&*w"6Xv~"&*x"7$($<$<VV$L!"&*x"7"481<@<Y<YZ`bo  rU  W[  =\916''7662#"&"8"8"FK6}*477  6q  ,q  r  r'+'<'<V'D&*&;&;E&B&-&8&8{&S&*&<&<V[&Q"&"8"8"HK#. $#0GK //$,,rB(((<bc!!&(MB68,1166t{{7F7STH@@WV\A]^H 626""6:6 
  	r  statusc                 :    ddddddd}| j                  |||      S )Ncanceledrz  closed)z-101234)rS  )r  r9  statusess      r  parse_order_statuszlbank.parse_order_status	  s2    
 &&99r  r  c                 4   | j                  |dd      }| j                  |dd      }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  ||      }d }d	}	d
}
| j                  |dd      }|j	                  d      }| j                  |d      }| j                  |d      }|dk(  rd}
|dk(  rd}	d}|dk(  rd}|dk(  rd}| j                  |d      }| j                  |d      }d }|dk7  r| j                  |dd      }| j                  |dd      }| j                  i 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 d*|      S )+NorderIdr-  r'  r&  r  create_timer9  r0  Fr   r%  r  r1  r   r   r[  r   Tr   r)  r   r*  r   r>  cummulativeQuoteQty
buy_marketorigQtyr=  executedQtydeal_amountr	  rp  r   lastTradeTimestampr   r(  r  r   rD  filled	remaining)r   r  rN  r  )r  r  rS  r  rT  r6  r  rC  )r  r  r[  r	  r'  r   	rawStatusr\  r   r(  r%  rawTyper]  r  r  r>  r  r  filledStrings                      r  parse_orderzlbank.parse_order  sn   p y*=**5/;O''v}E	$$UH5	##E84!!(F3$$UFK@c"q)##E1-xDwHKuKuK  0%%e-BC
l"--eYIL))%N  
" 
] 
 Y/ 
 	 

 !$ 
 d--i8 
 fX& 
 D 
 ; 
  
 D 
 U 
 D 
 J 
 l 
  l! 
" # 
$ + 
, - 	r  r	  c                     | j                          | j                  |d      }|0| j                  | j                  di       }| j                  |dd      }|dk(  r| j	                  |||      S | j                  |||      S )a  
        fetches information on an order made by the user

        https://www.lbank.com/en-US/docs/index.html#query-order
        https://www.lbank.com/en-US/docs/index.html#query-order-new

        :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_   r   )r  rS  rP  r  fetch_order_supplementfetch_order_default)r  r	  r0  r$  r   r  s         r  fetch_orderzlbank.fetch_order  s     	!!&(3>oodllL"EG%%gx9OPF++..r66BB''FF;;r  c                    |t        | j                  dz         | j                          | j                  |      }|d   |d}| j	                  | j                  ||            }| j                  |di       }| j                  |      S )N( fetchOrder() requires a symbol argumentr	  r0  rE  r  )r   r	  r  r[  #spotPrivatePostSupplementOrdersInform  r  rR  )r  r	  r0  r$  r[  rn  r&  rY  s           r  rT  zlbank.fetch_order_supplement  s    >#DGG.X$XYYV$Tl
 ;;DKKQW<XY, &"5''r  c                 h   |t        | j                  dz         | j                          | j                  |      }|d   |d}| j	                  | j                  ||            }| j                  |dg       }t        |      }|dk(  r| j                  |d         S t        | j                  dz         )NrX  r	  )r0  r-  r  r   r   z0 fetchOrder() can only fetch one order at a time)
r   r	  r  r[  spotPrivatePostOrdersInform  rP  rR  rR  r   )	r  r	  r0  r$  r[  rn  r&  rY  	numOrderss	            r  rU  zlbank.fetch_order_default  s    >#DGG.X$XYYV$Tl
 11$++gv2NO* 626K	>##F1I.. TWW'YYZZr  c                    |t        | j                  dz         | j                          | j                  |      }| j	                  |d|      }| j                  |d      }d|d   i}|||d<   |-| j                  |d      |d<   | j                  |dz   d      |d<   | j                  | j                  ||            }| j                  |d	g       }| j                  ||||      S )
a  
        fetch all trades made by the user

        https://www.lbank.com/en-US/docs/index.html#past-transaction-details

        :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 trade 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 argument
start_dater0  r	  r  -i \&end_dater  )r   r	  r  r[  rP  r  ymd!spotPrivatePostTransactionHistoryrm  r  r  )	r  r0  r  r   r$  r[  rn  r&  r   s	            r  fetch_my_tradeszlbank.fetch_my_trades  s     >#DGG.[$[\\V$e<6<0fTl
 #GFO$(HHUC$8GL!"&((58+;S"AGJ99$++gv:VW* &"5  >>r  c                 H   |t        | j                  dz         | j                          | j                  |      }|d}|d   d|d}| j	                  | j                  ||            }| j                  |di       }| j                  |dg       }	| j                  |	|||      S )a4  
        fetches information on multiple orders made by the user

        https://www.lbank.com/en-US/docs/index.html#query-all-orders

        :param str symbol: unified market symbol of the market orders were made in
        :param int [since]: the earliest time in ms to fetch orders for
        :param int [limit]: the maximum number of order structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        z) fetchOrders() requires a symbol argumentr   r	  r   r0  current_pagepage_lengthr  orders)	r   r	  r  r[  *spotPrivatePostSupplementOrdersInfoHistoryrm  rP  r  parse_orders
r  r0  r  r   r$  r[  rn  r&  rY  ri  s
             r  fetch_orderszlbank.fetch_orders;  s     >#DGG.Y$YZZV$=ETl 
 BB4;;wX^C_`8 626"5  >>r  c                 H   |t        | j                  dz         | j                          | j                  |      }|d}|d   d|d}| j	                  | j                  ||            }| j                  |di       }| j                  |dg       }	| j                  |	|||      S )a  
        fetch all unfilled currently open orders

        https://www.lbank.com/en-US/docs/index.html#current-pending-order

        :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 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>`
        z- fetchOpenOrders() requires a symbol argumentr   r	  r   rf  r  ri  )	r   r	  r  r[  )spotPrivatePostSupplementOrdersInfoNoDealrm  rP  r  rk  rl  s
             r  fetch_open_orderszlbank.fetch_open_ordersu  s     >#DGG.]$]^^V$=ETl 

 AA$++gW]B^_8 626"5  >>r  c                 n   |t        | j                  dz         | j                          | j                  |dd      }| j	                  |ddg      }| j                  |      }|d   |d}|||d<   | j                  | j                  ||            }| j                  |di       }| j                  |      S )a  
        cancels an open order

        https://www.lbank.com/en-US/docs/index.html#cancel-order-new

        :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>`
        z) cancelOrder() requires a symbol argumentorigClientOrderIdr'  r	  rY  r  )
r   r	  r  r  r  r[  $spotPrivatePostSupplementCancelOrderrm  r  rR  )	r  r	  r0  r$  r'  r[  rn  r&  r  s	            r  r   zlbank.cancel_order  s     >#DGG.Y$YZZ**63FX6$7#IJV$Tl
 $+8G'(<<T[[RX=YZ ~~h3%%r  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}| j	                  | j                  ||            }| j                  |dg       }| j                  |      S )a  
        cancel all open orders in a market

        https://www.lbank.com/en-US/docs/index.html#cancel-all-pending-orders-for-a-single-trading-pair

        :param str symbol: unified market symbol of the market to cancel orders in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        z- cancelAllOrders() requires a symbol argumentr0  r	  r  )r   r	  r  r[  ,spotPrivatePostSupplementCancelOrderBySymbolrm  r  rk  )r  r0  r$  r[  rn  r&  r  s          r  cancel_all_orderszlbank.cancel_all_orders  s     >#DGG.]$]^^V$fTl
 DDT[[QXZ`Eab$ ~~h3  &&r  c                     | j                  | j                  d      }| j                  ||      }| j                  | j                  di       }| j                  |d|      }| j                  |||      }|S )Nr   r   network)rP  r  r/  rS  )r  currencyCoder$  r   defaultNetworkr   rx  s          r  get_network_code_for_currencyz#lbank.get_network_code_for_currency  sl    //$,,8IJ//N??4<<R@((NK""8Wg>r  r  c                 *   | j                          | j                  | j                  di       }| j                  |dd      }| j                  |d|      }| j	                  |d      }d}|dk(  r| j                  ||      }|S | j                  ||      }|S )a  
        fetch the deposit address for a currency associated with self account

        https://www.lbank.com/en-US/docs/index.html#get-deposit-address
        https://www.lbank.com/en-US/docs/index.html#the-user-obtains-the-deposit-address

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        rI   r   r   NfetchDepositAddressSupplement)r  rP  r  rS  r   fetch_deposit_address_supplementfetch_deposit_address_default)r  r  r$  r  r  r   r&  s          r  fetch_deposit_addresszlbank.fetch_deposit_address  s     	//$,,0ErJ(((<XY!!&(MB68,44<<T6JH  99$GHr  c                    | j                          | j                  |      }d|d   i}| j                  ||      }|||d<   | j                  |d      }| j	                  | j                  ||            }| j                  |d      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  | j                  di       }| j                  ||
|
      }|||||	d	S )
N	assetCoder	  netWorkrx  r  addressmemor   rN  r  rx  r  tag)
r  r  r{  r   spotPrivatePostGetDepositAddressrm  rP  rS  r  r/  )r  r  r$  r  rn  rx  r&  rY  r  r  	networkIdinverseNetworksnetworkCodes                r  r  z#lbank.fetch_deposit_address_default  s   ==&$
 44T6B!(GIYYvy1F88Wf9UV 62""695vv.$$VY7	//$,,8JBO,,_iS"
 	
r  c                 $   | j                          | j                  |      }d|d   i}| j                  | j                  d      }| j	                  |d      }| j                  |||      }|||d<   | j                  |d      }| j                  | j                  ||            }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  | j                  d	i       }| j	                  |||      }||||	|
d
S )Nr  r	  r   rx  networkNamer  r  r  r   r  )	r  r  rP  r  r/  rS  r  *spotPrivatePostSupplementGetDepositAddressrm  )r  r  r$  r  rn  r   rx  r&  rY  r  r  r  r  s                r  r~  z&lbank.fetch_deposit_address_supplement?  s   ==&HTN
 ??4<<<((;""8Wg>%,GM"YYvy1FBB4;;wX^C_` 62""695vv.//$,,8JBO,,_gwO"
 	
r  r  c                 l   | j                  ||      \  }}| j                  |       | j                          | j                  |d      }| j	                  |d      }| j                  d|d       | j                  |      }||d   ||d}|||d<   | j                  |dd      }	| j	                  |ddg      }| j                  | j                  d      }
| j                  |
|	|	      }|||d<   | j                  | j                  ||            }| j                  |d	i       }|| j                  |d
      dS )a  
        make a withdrawal

        https://www.lbank.com/en-US/docs/index.html#withdrawal

        :param str code: unified currency code
        :param float amount: the amount to withdraw
        :param str address: the address to withdraw to
        :param str tag:
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
        r  rq   r	  )r  r  r=  r  r  rx  r  r   r  
withdrawId)rN  r	  )handle_withdraw_tag_and_paramscheck_addressr  rS  r  check_required_argumentr  safe_string_upper_2rP  r  !spotPrivatePostSupplementWithdrawrm  )r  r  r=  r  r  r$  r  r  rn  rx  r   r  r&  rY  s                 r  rq   zlbank.withdrawf  sJ    99#vFV7#vu-65)$$Ze<==&TN	
 ?!GFO**69mL6I}#=>??4<<<$$Xw@	 %.GM"99$++gv:VW 626""6<8
 	
r  c                 j    dddddddddddd}| j                  | j                  ||i       ||      S )	Npendingokfailedr;  transfer)r>  r?  r@  rA  5)r>  r?  r@  rA  )deposit
withdrawal)rS  rP  )r  r9  r%  rB  s       r  parse_transaction_statuszlbank.parse_transaction_status  sV      	
 $ CVVTTr  transactionr  c                    | j                  |d      }d }|d}nd}| j                  |d      }| j                  |dd      }| j                  | j                  di       }| j                  |d      }| j                  |||      }	| j                  |d	      }
d }d }|dk(  r|
}n|
}| j	                  |d
      }| j                  |dd      }| j                  ||      }| j                  | j                  |d      |      }d }| j	                  |d      }|||d}i d|d|d|d|d| j                  |      d|	d	|
d|d|dd dd dd d|d
|d|d|dd d |dk(  |dS )Nr	  r  r  txId
insertTime	applyTimer   r  r  r=  r  coidr9  r  )rD  r  rN  txidr   rp  rx  	addressToaddressFromr  tagTotagFromr%  r  updatedr  )commentinternalr  )	rS  r  rP  r  rX  r  rU  r  r  )r  r  r  r	  r%  r  r   r   r  rx  r  r  r  r=  r  r  r9  r  r  s                      r  parse_transactionzlbank.parse_transaction  s-   < k40:DDV4''\;O	??4<<1CRH$$[-@	""8Y	B"";	:	9!KI!!+x8''VVD
&&z8<..t/?/?X/VX\]"";6 C
K
"
 D
 	

 Y/
 w
 w
 
 ;
 4
 T
 t
 D
 f
 
  f!
" t#
$ :-)
 	
r  c                 $   | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |di       }| j                  |dg       }	| j                  |	|||      S )a  
        fetch all deposits made to an account

        https://www.lbank.com/en-US/docs/index.html#get-recharge-history

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr	  r  	startTimer  depositOrders)r  r  'spotPrivatePostSupplementDepositHistoryrm  rP  r  parse_transactions)
r  r  r  r   r$  rn  r  r&  r  depositss
             r  fetch_depositszlbank.fetch_deposits	  s     	
 }}T*H&tnGFO#(GK ??GU[@\]0 x4>>$<&&x5%HHr  c                 $   | j                          i }d}|| j                  |      }|d   |d<   |||d<   | j                  | j                  ||            }| j	                  |di       }| j                  |dg       }	| j                  |	|||      S )a  
        fetch all withdrawals made from an account

        https://www.lbank.com/en-US/docs/index.html#get-withdrawal-history

        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Nr	  r  r  r  r   )r  r  "spotPrivatePostSupplementWithdrawsrm  rP  r  r  )
r  r  r  r   r$  rn  r  r&  r  r   s
             r  fetch_withdrawalszlbank.fetch_withdrawals8	  s     	

 }}T*H&tnGFO#(GK ::4;;wPV;WX6 x4NN4b9	&&y(E5IIr  codesc                 v   | j                          | j                  d      }d}|du r| j                  | j                  di       }| j	                  |dd      }| j	                  |d|      }| j                  |d      }|dk(  r| j                  |      }|S | j                  |      }|S | j                  |      }|S )aG  
 @deprecated
        please use fetchDepositWithdrawFees instead
        :param str[]|None codes: not used by lbank fetchTransactionFees()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        FNTrl   r   r   fetchPublicTransactionFees)r  check_required_credentialsrP  r  rS  r  fetch_public_transaction_feesfetch_private_transaction_fees)r  r  r$  isAuthorizedrY  r  r  r   s           r  fetch_transaction_feeszlbank.fetch_transaction_feeso	  s     	66u=4oodll4JBOG ,,Wh@]^M%%fhFFYYvx0F55;;FC
  <<VD  77?Fr  c                    | j                          | j                         }| j                  |dg       }i }t        dt	        |            D ]  }||   }| j                  |d      }| j                  |      }| j                  |dg       }	i ||<   t        dt	        |	            D ]V  }
|	|
   }| j                  |d      }| j                  | j                  d   ||      }| j                  |d      }|O|||   |<   X  |i |dS )	Nr  r   r  networkListr
  r   withdrawFeerq   r  rN  )	r  r   rP  rQ  rR  rS  rU  r  rX  )r  r$  r&  rY  withdrawFeesrZ  entryr  r  r  jnetworkEntryr  r  r  s                  r  r  z$lbank.fetch_private_transaction_fees	  s)    	99;> 626q#f+& 	:A1IE))%8J**:6D//%CK!#L1c+./ :*1~ ,,\6B	"..t||<N/OQZ\ef&&|]C?69L&{3:	: %
 	
r  c                    | j                          | j                  |dd      }| j                  |ddg      }i }|| j                  |      }|d   |d<   | j	                  | j                  ||            }| j                  |dg       }i }t        dt        |            D ]  }||   }	| j                  |	d      }
|
dk(  s | j                  |	d      }| j                  |      }| j                  |	d      }| j                  | j                  d	   ||      }||}| j                  |	d
      }||   i ||<   | j                  |      ||   |<    |i |dS )Nr  r  r	  r  r   canWithDrawtruechainr   r  r  )r  r  r  r  spotPublicGetWithdrawConfigsrm  rP  rQ  rR  rS  rU  r  r  )r  r$  r  rn  r  r&  rY  r  rZ  r  canWithdrawr  r  r  rx  r  s                   r  r  z#lbank.fetch_public_transaction_fees	  s    	!!&&+>6FK#89}}T*H#+D>GK 44T[[&5QR, 626q#f+& 	JA!9D//$>Kf$!--dK@
 33J?	((w7**4<<8J+KUTYZ?'G&&tU3	*2.0L+373D3DS3IY'0	J %
 	
r  c                 |   | j                          | j                  d      }d}|du r| j                  | j                  di       }| j	                  |dd      }| j	                  |d|      }| j                  |d      }|dk(  r| j                  ||      }|S | j                  ||      }|S | j                  ||      }|S )ar  
        when using private endpoint, only returns information for currencies with non-zero balance, use public method by specifying self.options['fetchDepositWithdrawFees']['method'] = 'fetchPublicDepositWithdrawFees'

        https://www.lbank.com/en-US/docs/index.html#get-all-coins-information
        https://www.lbank.com/en-US/docs/index.html#withdrawal-configurations

        :param str[] [codes]: array of unified currency codes
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
        FNTrN   r   r   fetchPublicDepositWithdrawFees)r  r  rP  r  rS  r  "fetch_public_deposit_withdraw_fees#fetch_private_deposit_withdraw_fees)r  r  r$  r  r&  r  r  r   s           r  fetch_deposit_withdraw_feesz!lbank.fetch_deposit_withdraw_fees	  s     	66u=4oodll4NPRSG ,,Wh@abM%%fhFFYYvx0F99BB5&Q
   CCE6R  >>ufMHr  c                     | j                          | j                  |      }| j                  |dg       }| j                  ||d      S )Nr  r  )r  r   r  parse_deposit_withdraw_fees)r  r  r$  r&  r  s        r  r  z)lbank.fetch_private_deposit_withdraw_fees
  sI     	99&A> ~~h3//eVDDr  c                     | j                          i }| j                  | j                  ||            }| j                  |dg       }| j	                  ||      S )Nr  )r  r  rm  rP  "parse_public_deposit_withdraw_fees)r  r  r$  rn  r&  r  s         r  r  z(lbank.fetch_public_deposit_withdraw_fees7
  sW     	44T[[&5QR, x466tUCCr  c                 B   i }t        dt        |            D ]  }||   }| j                  |d      }|du s | j                  |d      }| j	                  |      }|| j                  ||      sX| j                  |d      }	|	m| j                  ||      }
|
| j                  |g      ||<   n||   d   }|j                  |       | j                  |d      }| j                  | j                  d   ||      }||	d d	d d d	d
||   d   |<   |	d d	||   d<    |S )Nr   r  Tr  r  rN  r  r   r  r  rq   r  r   rq   )
rQ  rR  rP  rS  rU  in_arrayrX  deposit_withdraw_feerV  r  )r  r&  r  rY  rZ  r  r  r  r  r  resultValueresultCodeInfor  r  s                 r  r  z(lbank.parse_public_deposit_withdraw_feesU
  s`   " q#h-(  	A1+C//#}=Kd"!--c;?
..z:=DMM$$>"&"2"23">K".&*oofd&C&.+/+D+DcU+KF4L-3D\&-AN*11#6 $ 0 0g >&*&6&6t||DV7WY^`e&f&2 ,726-"
 ,026,"	EF4L4[A (3.28F4L4; 	B r  c                 t   | j                  |      }| j                  |dg       }t        dt        |            D ]{  }||   }| j	                  |d      }| j                  | j                  d   ||      }| j                  |d      }	| j                  |d      }
|	a|
r|	d d|d<   |	d dd d dd	|d
   |<   } |S )Nr  r   r
  r   r  	isDefaultr  rq   r  r   )r  rP  rQ  rR  rS  r/  r  rX  )r  r  r  rY  r  r  r  r  r  r  r  s              r  parse_deposit_withdraw_feez lbank.parse_deposit_withdraw_fee
  s    6 **3/ooc="=q#k*+ 	A&q>L((v>I00>P1QS\^ghK**<GKkBI&*&**F:&  +&*!
  $&* 	3z";/	, r  r   GETc           
         | j                  || j                  |            }| j                  d   d   dz   | j                  z   dz   | j	                  ||      z   }|d   dk(  r|dz  }n(| j                  d   d   dz   | j	                  ||      z   }|d   d	k(  r+|rN|d
| j                  | j                  |            z   z  }n&| j                          t        | j                               }	| j                         | j                         z   }
| j                  d| j                  i|      }d }t        | j                        dkD  rd}nd}| j!                  | j                  | j                  |
||	d|                  }| j#                  |      }| j%                  |d      }|j'                         }d }|dk(  r| j)                  | j*                  dd      }d }|rX| j-                  | j*                  d      }|d| j/                  | j#                  | j                              }|| j*                  d<   n*| j/                  | j#                  | j                              }| j1                  ||d      }nN|dk(  rI| j3                  | j#                  |      | j#                  | j                        t4        j6                        }||d<   | j                  | j                  |            }d|	||
d}||||dS )Nr   r   r2  r   r3   z.dor   r   r   ?api_key    RSA
HmacSHA256)echostrsignature_methodr   md5r   Tpemsha256signz!application/x-www-form-urlencoded)zContent-Typer   r  r  )urlr   bodyheaders)r  extract_paramsr  r  implode_params	urlencodekeysortr  r  r  uuid22uuid16rm  apiKeyrR  secret	rawencodeencodehashupperr.  r  rP  convert_secret_to_pemrsahmachashlibr  )r  pathr   r   r$  r  r  queryr  r   r  signatureMethodauthencodedr  uppercaseHashr  r   r  s                      r  r  z
lbank.sign
  s   		&$"5"5d";<iiv&,t||;cADDWDWX\^dDeeq6V5LC))E":.4t7J7J4QW7XXCq6XsT^^DLL,?@@@++-D--/0Ikkmdkkm3GKK4;;!E #O4;;"$"'".>>$,,t{{"$3&< 	0 # D
 kk$'G99We,D JJLMD%'#'>>$,,@RTX#Y #//$,,>C{"88T[[9QR.1U+44T[[5MNCxxsH= L0yy]!;T[[=UW^WeWef E&M>>$,,u"56D C&$3"	G fdwOOr  c                     d}t        |      dz
  }| j                  ||z        }| j                  |d      }d}t        d|      D ].  }||z  }| j                  ||      }|| j                  || dz   z  }0 |dz   S )N@   r   r   z-----BEGIN PRIVATE KEY-----

z-----END PRIVATE KEY-----)rR  r  sumrQ  r  )	r  r  
lineLengthsecretLengthnumLinesr  rZ  startends	            r  r  zlbank.convert_secret_to_pem
  s    
6{Q$$\J%>?88Ha(-q(# 	1A
NE((5*-C4;;uS)D00C	1 000r  httpCodereasonr  r   r  r  c
                    |y | j                  |d      }
|
dk(  s|
s+| j                  |d      }| j                  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/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGi dHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdg|| j                  |            }| j                  i dt        dt        d
t        dt
        dt        dt        dt        dt        dt        dt        dt        dt        dt        d t        d"t        d$t        d&t        i d(t        d*t        d,t        d.t        d0t        d2t        d4t        d6t        d8t        d:t        d<t        d>t        d@t        dBt        dDt        dFt        dHt        t        t        t        t        t        t        t        t        t        t        t        t        t        t        t        dh|t              } ||      y )iNrY  false
error_code10000zInternal error10001z(The required parameters can not be empty10002zValidation failed10003zInvalid parameter10004zRequest too frequent10005zSecret key does not exist10006zUser does not exist10007zInvalid signature10008zInvalid Trading Pair10009z0Price and/or Amount are required for limit order10010z9Price and/or Amount must be less than minimum requirement10013zThe amount is too small10014z+Insufficient amount of money in the account10015zInvalid order type10016zInsufficient account balance10017zServer Error10018z$Page size should be between 1 and 5010019z+Cancel NO more than 3 orders in one request10020zVolume < 0.00110021zPrice < 0.0110022zInvalid authorization10023z!Market Order is not supported yet10024zUser cannot trade on self pair10025zOrder has been filled10026zOrder has been cancelld10027zOrder is cancelling10028zWrong query time10029zfrom is not in the query time10030z0from do not match the transaction type of inqury10031z=echostr length must be valid and length must be from 30 to 4010033zFailed to create order10036zcustomID duplicated10100zHas no privilege to withdraw10101zInvalid fee rate to withdraw10102zToo little to withdraw10103z#Exceed daily limitation of withdraw10104zCancel was rejected10105zRequest has been cancelled10106zNone trade time10107zStart price exception10108zcan not create order10109zwallet address is not mapping10110ztransfer fee is not mapping10111z	mount > 010112zfee is too lower10113ztransfer fee is 010600z5intercepted by replay attacks filter, check timestamp10601zInterface closed unavailable10701zinvalid asset code10702znot allowed deposit)r8  r9  r:  r;  r<  r=  r>  r?  r@  rA  rB  rC  rD  rE  rF  )rP  rS  jsonr   r   r&   r    r#   r!   r   r   r'   r$   r"   )r  r  r  r  r   r  r  r&  requestHeadersrequestBodysuccess	errorCodemessage
ErrorClasss                 r  handle_errorszlbank.handle_errors  s   //(H5gW((<@I&& 5()5(C5( ,5( ,	5(
 /5( 45( .5( ,5( /5( K5( T5( 25( F5(  -!5(" 7#5($ %5(& ?'5(( F)5(* )+5(, -5(. 0/5(0 <15(2 935(4 055(6 275(8 .95(: +;5(< 8=5(> K?5(@ XA5(B 1C5(D .E5(F 7G5(H 7I5(J 1K5(L >M5(N .O5(P 5Q5(R *S5(T 0U5(V /W5(X 8Y5(Z 6[5(\ ]5(^ +_5(` ,a5(b Pc5(d 7e5(f -g5(h .i5(j $))H-k5/Gl  2*2*,2* 2* *	2*
 ,2* ,2* ,2* 2* 2* 2* 2* *2* 2* *2* 2*  !2*" #2*$ %2*& '2*( ))2** +2*, )-2*. /2*0 12*2 32*4 52*6 72*8 92*: ;2*< =2*> )?2*@ )A2*B C2*D *E2*F '&&##&'&####&")c2*d -e2)Jf W%%r  )N)T__name__
__module____qualname__r   r  r	   r'  r   r
   r.  r)  r*  dictr   r  r  r  r   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   rC  r   rR  rV  rT  rU  rd  rm  rp  r   rv  r{  r   r  r  r~  r   rq   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  intrN  __classcell__)r  s   @r  r+   r+      s   c# cJ !# %3s %3N $& I$v, I" )+ M^ )+ ^@:4 : :6 :x 02 *03 *0f *0X 04B J1W J17 J1X :>b Pcs Pc3 PcY Pcd[ [v [ [z 6:UW 2?3 2?s 2?# 2?\`af\g 2?h
 
4 
( 26DW[df 4J# 4Jc 4JQT 4Jkoptku 4Jl{ {z,
 ,
; ,
\ 68 B BK B 6:" (77 (7 (7T $& 4,( 4,l
T 
6 
EX 
& 57 . .;N . )+ { ( RT N N5 N& gksu Z3 Zi Zy ZRW Z`c Zx	: 	:J Jv J JX 26b <c <3 <* =A  (  (c  (D :>b *[c *[3 *[X -1tRV_a 6?c 6? 6?C 6?p *.Dt\^ 8?3 8?c 8? 8?cghmcn 8?t /3TXac 5? 5?3 5?c 5?hlmrhs 5?n 37r &&s &&C &&P /32 $' $'L 79 # ^ . ?A $
# $
^ $
L BD %
S %
 %
N DHPR 9
S 9
% 9
# 9
Wb 9
vU$P
T P
X P
Q\ P
d *.Dt\^ 1I3 1Ic 1I 1Icghsct 1If -1tRV_a 5Jc 5J 5JC 5Jfjkvfw 5Jn 7;2 G 2 57 6
p 46 4
l <@  6 9=R $EL 8<B D<3j3 3j &eBSW 5Pn
1pc p3 pS p# pX\ pdg pr  r+   )0ccxt.base.exchanger   ccxt.abstract.lbankr   r   ccxt.base.typesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   typingr   ccxt.base.errorsr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   ccxt.base.decimal_to_precisionr(   ccxt.base.preciser)   r+    r  r  <module>r^     st    ( +  n  n  n  n  n  n  * 0 - . ' & . + ) - ) . ) 4 %V-Hk V-r  