
    i                    X   d dl mZ d dlmZ d dl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 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,dS )    )Exchange)ImplicitAPIN)BalancesCurrencyIntMarketNumOrder	OrderBook	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTradingFeesTransaction)List)ExchangeError)AuthenticationError)PermissionDenied)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)DuplicateOrderId)NotSupported)RateLimitExceeded)InvalidNonce)	TICK_SIZE)Precisec                       e Zd Z fdZi fdZi fdee         fdZi fdZi fdZ	dFd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dFdedefdZddi fd
edededee         fdZdFd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i fdefdZdFd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" Z(dFdede)fd#Z*d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+fd'Z.dddi f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)Z0dddi fd
e+dededee)         fd*Z1di fd$ed
e+fd+Z2di fd
e+fd,Z3d- Z4i fd.efd/Z5i fd.efd0Z6i fd.efd1Z7di fd.ede"de8fd2Z9d3 Z:dFd4e;de8fd5Z<dddi fd.e+dededee8         fd6Z=dddi fd.e+dededee8         fd7Z>di fd8ee         fd9Z?i fd:Z@i fd;ZAdi fd8efd<ZBdi fd=ZCdi fd>ZDdFd?ZEdFd4e;fd@ZFdAdBi ddfdCZGdD ZHdE ZI xZJS )Glbankc           )         |                      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@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|                     d          |                     d          ddxi idddd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          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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_dealrj   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)r.   r   z0.001)makertaker)tradingfundingVENPenta)	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!createMarketBuyOrderRequiresPricerc   re   rG   rD   r9   rX   r>   networksinverse-networksdefaultNetworks)idname	countriesversion	rateLimitprohas
timeframesurlsr   r   commonCurrenciesprecisionModeoptions)deep_extendsuperr'   describeparse_numberr$   )self	__class__s    ^/var/www/html/crypto-bot/backend/venv/lib/python3.11/site-packages/ccxt/async_support/lbank.pyr   zlbank.describe   s[   eT 2 2 ; ; = = >>> %> 	>
 %> %> U> "4> t> /> ,U> 0> t> (> '>  (!>" "5#> >$ %>& +E'>( )%)>* $U+>, '->. (/>0 &t1>2 *:3>4 +D5>6 &u7>8 #E9>: *5;>< $U=>> "5?>@ *5A>B +EC>D )%E> > >F  G>H %eI>J "5K>L M>N !%O>P  Q>R dS>T "4U>V dW>X !$Y>Z t[>\  ]>^ $U_>` !%a>b %ec>d )%e>f tg> >h !%!#$((, %$!&#( {> > >@  !!  ~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 FP :==@=@>A	   	QR Rj "..w77!..w77 
   #! ! '$(593  ;) ?- :( D  4 A!%W%7% W% 7	%
 F% 5% \% <% &% 6% 5% J% W% w% 5%  y!%" 5#%N %$" "'" !  &$ ( % %" G$]Q QGU@
 U@
 U U U	    c                    K   d}|                      dd|          \  }}d}|dk    r|                     |           d{V }n|                     |           d{V }|                     |d          S )a  
        fetches the current integer timestamp in milliseconds from the exchange server
        :see: https://www.lbank.com/en-US/docs/index.html#get-timestamp
        :see: 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
        Nrb   r0   data)handle_market_type_and_params'contractPublicGetCfdOpenApiV1PubGetTimespotPublicGetTimestampsafe_integer)r   paramstyperesponses       r   
fetch_timezlbank.fetch_time7  s       99+tVTTf6>>!II&QQQQQQQQHH!88@@@@@@@@H*   6222r   returnc                    K   |                      |          |                     |          g}t          j        |  d{V }|                     |d         |d                   S )ay  
        retrieves data on all markets for lbank
        :see: https://www.lbank.com/en-US/docs/index.html#trading-pairs
        :see: 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
        Nr   r   )fetch_spot_marketsfetch_swap_marketsasynciogatherarray_concat)r   r   marketsPromisesresolvedMarketss       r   fetch_marketszlbank.fetch_markets\  sq       ##F++##F++
 !( @@@@@@@  !3_Q5GHHHr   c                   K   |                      |           d {V }|                     |dg           }g }t          dt          |                    D ]i}||         }|                     |d          }|                    d          }|d         }	|d         }
|                     |	          }|                     |
          }|dz   |z   }|                    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 |                     | 	                    |                     |d                              |                     | 	                    |                     |d                              dd d d| 
                    |d          d dd d dd d ddd |d
           k|S ) Nr   r   symbol_r   /r   basequotebaseIdquoteIdsettlesettleIdr   r.   Tr/   Fr0   r1   r2   activer   linearquantityAccuracypriceAccuracyamountpriceminmax
minTranQualeverager  r  cost
inverse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partsr  r  r
  r  r  s                 r   r   zlbank.fetch_spot_marketsk  s     33F;;;;;;;;  x44q#d))$$ 9	 9	A!WF''99HNN3''E1XFAhG**622D++G4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\^pEqEq0r0rss!..t/C/CDDTDTU[]lDmDm/n/noo   $#! !
  $//EE# 
  $# 
  $#  $  _0 0 0 0 0 0 0b r   c                 *  K   ddi}|                      |                     ||                     d {V }|                     |dg           }g }t          dt	          |                    D ]}||         }|                     |d          }|                     |d          }	|                     |d          }
|
}|                     |	          }|                     |          }|                     |
          }|dz   |z   d	z   |z   }|                    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          dd d d |                     |d!          |                     |d"          d |                     |d#          |                     |d$          d |                     |d%          d d d&d |d'
           |S )(NproductGroupSwapUr   r   r  baseCurrencyclearCurrencyr	  :r   r
  r  r  r  r  r  r   r0   r.   Fr/   Tr1   r2   r  r   r  volumeMultiple
volumeTick	priceTickr  r  minOrderVolumemaxOrderVolumepriceLimitLowerValuepriceLimitUpperValueminOrderCostr  r  )	*contractPublicGetCfdOpenApiV1PubInstrumentextendr*  r+  r,  r-  r/  r0  r2  )r   r   requestr   r   r3  r4  r5  r6  r  r  r  r
  r  r  r  s                   r   r   zlbank.fetch_swap_markets  s%     G
 HHU\^dIeIeffffffff: x44q#d))$$ :	 :	A!WF''99H%%fn==F''@@HG**622D++G44E,,X6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 J"&""..v|DD!--fkBB   $#! !
  $//8HII#//8HII 
  $//8NOO#//8NOO 
  $//GG#  $  _0 0 0 0 0 0 0b r   Nr5  c           	         |                      |d          }|                     |d          }|                     ||          }|                     |di           }|                     ||          }|d         r|n|}|                     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 |                     |dd          |                     |d          |d|          S )Nr   r  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quoteVolumer(  )r   r-  safe_symbolr*  safe_marketsafe_tickeriso8601safe_string_2)r   r   r5  r   r6  r  
tickerDatar   s           r   parse_tickerzlbank.parse_ticker  s   > %%fk::	##FH55!!(F33__VXr::
!!(F33 ,=vv: !
f!
!
 Y//!
 D&&tV^DD	!

 4%%dE=AA!
 4!
 !
 4!
 !
 D!
 D$$T;77!
 T!
 D&&tX{CC!
 T!
 d!
  $**4::!!
" t#!
$ ,,T5(CC++D*==)!
 !
 !
* +  	r   r  c                   K   |                                   d{V  |                     |          }|d         r?|                     |d         g|           d{V }|                     ||d                   S d|d         i}|                     |                     ||                     d{V }|                     |dg           }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
        :see: 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>`
        Nr0   r  r   r   r   )load_marketsr5  fetch_tickersr*  spotPublicGetTicker24hrrG  	safe_dictri  )	r   r  r   r5  responseForSwaprH  r   r   firsts	            r   fetch_tickerzlbank.fetch_tickerV  s      !!!!!!!!!V$$&> 	F$($6$6x8H7I6$R$RRRRRRRO???F84DEEEfTl
 55dkk'66R6RSSSSSSSS, x44tQ++  ///r   symbolsc                 D  K   |                                   d{V  d}|E|                     |          }t          |          }|dk    r|                     |d                   }i }d}|                     d||          \  }}d}|dk    r5d|d<   |                     |                     ||                     d{V }n4d|d<   |                     |                     ||                     d{V }|                     |d	g           }| 	                    ||          S )
a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
        :see: https://www.lbank.com/en-US/docs/index.html#query-current-market-data-new
        :see: 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   ra   r0   r:  r9  allr  r   )
rk  market_symbolsr,  r5  r   *contractPublicGetCfdOpenApiV1PubMarketDatarG  rm  	safe_listparse_tickers)	r   rr  r   r5  symbolsLengthrH  r   r   r   s	            r   rl  zlbank.fetch_tickers  sU      !!!!!!!!!))'22GLLMq  WQZ0099.&RXYYf6>>&-GN#!LLT[[Y`bhMiMijjjjjjjjHH %GH!99$++gv:V:VWWWWWWWWH\ ~~h33!!$000r   limitc           	      |  K   |                                   d{V  |                     |          }|d}d|d         i}d}|                     d||          \  }}d}|dk    r5||d<   |                     |                     ||                     d{V }n4||d<   |                     |                     ||                     d{V }|                     |d	i           }|                                 }	|d         r!|                     ||d         |	d
ddd          S |                     ||d         |	          S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
        :see: https://www.lbank.com/en-US/docs/index.html#query-market-depth
        :see: 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<   r  r   rY   r0   r   sizer   bidsasksr  r_  )	rk  r5  r   +contractPublicGetCfdOpenApiV1PubMarketOrderrG  spotPublicGetDepthr*  millisecondsparse_order_book)
r   r  rz  r   r5  rH  r   r   	orderbookr   s
             r   fetch_order_bookzlbank.fetch_order_book  s      !!!!!!!!!V$$=EfTl
 99:JFTZ[[f6>>$GG!MMdkkZaciNjNjkkkkkkkkHH#GFO!44T[[&5Q5QRRRRRRRRHb OOHfb99	%%''	&> 	t((F84DiQWY_ahjrsss$$Yx0@)LLLr   c                    |                      |dd          }||                     |d          }|                     |dd          }||                     |d          }|                     |d          }||                     |d          }|                     |d	          }||                     |d
          }|                     |dd          }d }d }	|X|                    d          }
|                     |
d          }|                     |
d          }d}d}	||dk    rd}n|dk    rd}	|                     |dd          }||                     |d          }|                     |d          }|                     d |          }d }|                     |d          }|.||dk    r|d         n|d         |                     |d          d}|                     ||                     |          |||||	||||||d|          S )Ndate_mstimedealTimer  qtydealQuantityr  	dealPricequoteQtydealVolumePrice	tradeTyper   r  r   r   rz  r   r5  r   tidr   txUuid	orderUuidtradeFeebuyr
  r  tradeFeeRate)r  currencyrate)r   rJ  r  r   orderr   takerOrMakersider  r  r  feer(  )safe_integer_2r   rg  r-  r.  rc  
safe_traderf  )r   trader5  r   amountStringpriceString
costStringr  r   r  r7  typePartr   r  r  r  feeCosts                    r   parse_tradezlbank.parse_trade  sj   L ''y&AA	))%<<I))%5AA++E>BBL&&ug66**5+>>K%%eZ88
))%1BCCJ!!%f==JJsOOE##E1--D''q11HD"L#x''#DD((#*Lud33:!!%22B  44!!$//""5*55/3u}}F6NN6'?((?? C
 "Y//( " 
  
   	r   sincec                   K   |                                   d{V  |                     |          }d|d         i}|||d<   |t          |d          |d<   nd|d<   |                     | j        di           }|                     |dd	          }|                     |d|          }	|                     |d          }d}
|	d
k    r0|                     |                     ||                     d{V }
n/| 	                    |                     ||                     d{V }
| 
                    |
dg           }|                     ||||          S )a  
        get the list of most recent trades for a particular symbol
        :see: https://www.lbank.com/en-US/docs/index.html#query-historical-transactions
        :see: 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>`
        Nr  r   r  iX  r}  rc   r   r   spotPublicGetSupplementTradesr   )rk  r5  r  r*  r   r-  omitr  rG  r   rw  parse_trades)r   r  r  rz  r   r5  rH  r   defaultMethodr   r   r   s               r   fetch_tradeszlbank.fetch_tradesw  s      !!!!!!!!!V$$fTl
 #GFO!%ooGFOO!GFO//$,rBB(((<QRR!!&(MBB68,,444!??GU[@\@\]]]]]]]]HH!55dkk'66R6RSSSSSSSSH" &"55  >>>r   c           	         |                      |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r               )safe_timestampr2  )r   ohlcvr5  s      r   parse_ohlcvzlbank.parse_ohlcv  s     q))UA&&UA&&UA&&UA&&UA&&
 	
r   rw   c                 .  K   |                                   d{V  |                     |          }|d}nt          |d          }|2|                     |          }|                                 |dz  |z  z
  }|d         |                     | j        ||          |                     |dz            |d}|                     | 	                    ||                     d{V }	| 
                    |	dg           }
|                     |
||||          S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
        :see: 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
        Nd   i  i  r   )r  r   r  r}  r   )rk  r5  r  parse_timeframer  r-  r   parse_to_intspotPublicGetKlinerG  r*  parse_ohlcvs)r   r  	timeframer  rz  r   r5  durationrH  r   ohlcvss              r   fetch_ohlcvzlbank.fetch_ohlcv  s9      !!!!!!!!!V$$=EEt$$E=++I66H%%''(T/E*AAETl$$T_iKK%%edl33	
 
 00Wf1M1MNNNNNNNN6266,   E5IIIr   c                    |                      |d          }|||                     |          d}|                     |d          }|                     |d          }||                     |di           }|                     |di           }t          |                                          }t          dt          |                    D ]j}	||	         }
|                     |
          }|                                 }| 	                    ||
          |d<   | 	                    ||
          |d<   |||<   k| 
                    |          S |                     |d	          }|t          dt          |                    D ]}	||	         }| 	                    |d
          }
|                     |
          }|                                 }| 	                    |d          |d<   | 	                    |d          |d<   |||<   | 
                    |          S t          |t                    }|du rt          dt          |                    D ]}	||	         }| 	                    |d          }
|                     |
          }|                                 }| 	                    |d          |d<   | 	                    |d          |d<   |||<   | 
                    |          S d S )Nts)r(  r   rJ  r   toBtcfreezefreer   usedbalancesassetlockedTcoin	usableAmt	freezeAmt)r   rf  r*  listkeysr+  r,  r/  accountr-  safe_balance
isinstance)r   r   r   r3  r   r  r  r  
currenciesr4  
currencyIdcoder  r  item	codeInnerisArrays                    r   parse_balancezlbank.parse_balance  s   \ %%h55	"Y//
 

 x00g..??4266D??444Ddiikk**J1c*oo.. ' '']
..z::,,.."&"2"24"D"D"&"2"24"D"D&t$$V,,,??4441c(mm,, , ,{!--dG<<
 33J??	,,.."&"2"24"@"@"&"2"24"B"B$+y!!$$V,,,T4((d??1c$ii(( , ,Aw!--dF;;
 33J??	,,.."&"2"24"E"E"&"2"24"E"E$+y!!$$V,,,tr   c                   K   |                                   d{V  |                     | j        di           }|                     |dd          }|                     |d|          }d}|dk    r|                                  d{V }n;|dk    r|                                  d{V }n|                                  d{V }|                     |          S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders
        :see: https://www.lbank.com/en-US/docs/index.html#asset-information
        :see: https://www.lbank.com/en-US/docs/index.html#account-information
        :see: 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>`
        Nr>   r   r   (spotPrivatePostSupplementUserInfoAccountspotPrivatePostUserInfo)rk  r*  r   r-  r  r  r   r  )r   r   r   r  r   r   s         r   fetch_balancezlbank.fetch_balancen  s      !!!!!!!!!//$,CC(((<_``!!&(MBB???!JJLLLLLLLLHH000!99;;;;;;;;HH!CCEEEEEEEEH> !!(+++r   c                     |                      |d          }|                     |          }|||                     |d          |                     |d          d d dS )Nr  makerCommissiontakerCommission)r(  r  r   r   r\  	tierBased)r-  rc  r2  )r   r  r5  r6  r  s        r   parse_trading_feezlbank.parse_trading_fee  so     ##C22!!(++%%c+<==%%c+<==
 
 	
r   c                    K   |                      |          }|                     |                     |d|d         i                     d{V }|                     ||          S )ae  
        fetch the trading fees for a market
        :see: 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   N)r5  fetch_trading_feesrG  rn  )r   r  r   r5  r3  s        r   fetch_trading_feezlbank.fetch_trading_fee  sl       V$$..t{{6JPVW[P\C]/^/^________~~ff---r   c                 b  K   |                                   d{V  i }|                     |                     ||                     d{V }|                     |dg           }i }t	          dt          |                    D ]*}|                     ||                   }|d         }|||<   +|S )ae  
        fetch the trading fees for multiple markets
        :see: 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
        Nr   r   r  )rk  )spotPrivatePostSupplementCustomerTradeFeerG  r*  r+  r,  r  )	r   r   rH  r   r   r3  r4  r  r  s	            r   r  zlbank.fetch_trading_fees  s       !!!!!!!!!GGT[]cHdHdeeeeeeeex44q#d))$$ 	! 	!A((a11C]F F6NNr   r  c                    K   |                                   d{V  |                     |          }|d         st          | j        dz             d|d<   |                     |dd|d|           d{V S )a-  
        create a market buy order by providing the symbol and cost
        :see: https://www.lbank.com/en-US/docs/index.html#place-order
        :see: 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>`
        Nr.   z9 createMarketBuyOrderWithCost() supports spot orders onlyFr   r5  r  )rk  r5  r!   r   r   )r   r  r  r   r5  s        r   !create_market_buy_order_with_costz'lbank.create_market_buy_order_with_cost  s       !!!!!!!!!V$$f~ 	ftw)ddeee6;23&&vxdFSSSSSSSSSr   r   r  r  r  c                   K   |                                   d{V  |                     |          }|                     |dd          }|                     |dd          }	|                     |d          }
|                     |g d          }d|d	         i}|
d
k    }|
dk    }|	p|
dk    }|dk    r|s|s|rt          | j        dz             |dk    rd||d<   |                     ||          |d<   | 	                    ||          |d<   |r|dz   dz   |d<   nR|r|dz   dz   |d<   nC|r|dz   dz   |d<   n4|dk    r-|dk    r&|dz   dz   |d<   | 	                    ||          |d<   n|dk    r|dz   dz   |d<   d}d}| 
                    |ddd          \  }}|                     |d          }|                     |d          }||                     ||          }n|ro|t          | j        dz             |                     |          }|                     |          }t          j        ||          }|                     ||          }n|                     ||          }||d<   |||d<   |                     | j        di           }|                     |dd          }|                     |d|          }|                     |d          }d}|d k    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d!i           }|                     |                     |d"          |d#|          S )$a  
        create a trade order
        :see: https://www.lbank.com/en-US/docs/index.html#place-order
        :see: 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 fullfilled, 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>`
        N	custom_idclientOrderIdpostOnlyFtimeInForce)r  r  r  r  r  r   IOCFOKPOr5  zw createOrder() does not allow market FOK, IOC, or postOnly orders. Only limit IOC, FOK, and postOnly orders are allowedrz  r   r  r  r  iocfokr   sellr  Tr9   r   r  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   r(  )rk  r5  rg  	safe_boolsafe_string_upperr  r   r   price_to_precisionamount_to_precisionhandle_option_and_paramsr2  cost_to_precisionnumber_to_stringr%   
string_mulr*  r   r-  r  rG  r   
safe_order)r   r  r   r  r  r  r   r5  r  r  r  rH  r  r  r   quoteAmountr   r  r  r  costRequestr   r  r   r   r3  s                             r   r   zlbank.create_order  s\      !!!!!!!!!V$$**6;PP>>&*e<<,,V]CC6#\#\#\]]fTl
 e#e#2kT1H3#tw  *c   c  d  d  d7??"GFO#66vuEEGG $ 8 8 H HGH 7"&*u"4 7"&*u"4 7"&*w"6Xv~~"&*x"7$($<$<VV$L$L!!"&*x"7"481<@<Y<YZ`bo  rU  W[  =\  =\916''776622#"&"8"8"F"FKK6 	I}*47  6q  ,q  r  r  r'+'<'<V'D'D&*&;&;E&B&B&-&8{&S&S&*&<&<V[&Q&Q"&"8"8"H"HK#. $#0GK //$,rBB(((<bcc!!&(MBB68,,111!<<T[[RX=Y=YZZZZZZZZHH!FFt{{SZ\bGcGcddddddddH 6266""6:66 
  
   	r   c                 B    ddddddd}|                      |||          S )NcanceledrT  closed)z-101234)r-  )r   statusstatusess      r   parse_order_statuszlbank.parse_order_status>  s:    
 
 &&999r   c           	         |                      |dd          }|                      |dd          }|                     |dd          }|                     |d          }|                     |d          }|                     ||          }d }d	}	d
}
|                     |d          }|                    d          }|                     |d          }|                     |d          }|dk    rd}
|dk    rd}	d}|dk    rd}|dk    rd}|                     |d          }|                     |d          }d }|dk    r|                      |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)|          S )*NorderIdr  r  r  r  create_timer  r  Frz  r   r  r   r   r5  r   Tr  r  r  r  r  r  cummulativeQuoteQty
buy_marketorigQtyr  executedQtydeal_amountr   rJ  r   lastTradeTimestampr  r  r  	stopPricetriggerPricer  filled)	remainingr   r  r(  r]  )rg  r  r-  rd  r.  r  rf  r	  )r   r  r5  r   r  r   	rawStatusr6  r  r  r   rawTyper7  r  r  r  r  r  filledStrings                      r   parse_orderzlbank.parse_orderI  s   F y*==**5/;OO''v}EE	$$UH55	##E844!!(F33""5&11c""q))##E1--xDwHKuKuK  00%%e-BCC
l""--eYIIL))%NN  
" 
] 
 Y// 
 	 

 !$ 
 d--i88 
 fX& 
 D 
 ; 
  
 D 
 U 
  
 D 
 J 
  l! 
" l# 
$ - 
  
  
. /  	r   r   c                 P  K   |                                   d{V  |                     |d          }|3|                     | j        di           }|                     |dd          }|dk    r|                     |||           d{V S |                     |||           d{V S )a  
        fetches information on an order made by the user
        :see: https://www.lbank.com/en-US/docs/index.html#query-order
        :see: https://www.lbank.com/en-US/docs/index.html#query-order-new
        :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>`
        Nr   rX   r   )rk  r-  r*  r   fetch_order_supplementfetch_order_default)r   r   r  r   r   r   s         r   fetch_orderzlbank.fetch_order  s       !!!!!!!!!!!&(33>oodlL"EEG%%gx9OPPF+++44RHHHHHHHHH--b&&AAAAAAAAAr   c                 b  K   |t          | j        dz             |                                  d {V  |                     |          }|d         |d}|                     |                     ||                     d {V }|                     |di           }|                     |          S )N( fetchOrder() requires a symbol argumentr   r  r  r   )r   r   rk  r5  #spotPrivatePostSupplementOrdersInforG  rn  r  )r   r   r  r   r5  rH  r   r3  s           r   r  zlbank.fetch_order_supplement  s      >#DG.X$XYYY!!!!!!!!!V$$Tl
 
 AA$++gW]B^B^________, &"55'''r   c                   K   |t          | j        dz             |                                  d {V  |                     |          }|d         |d}|                     |                     ||                     d {V }|                     |dg           }t          |          }|dk    r|                     |d                   S t          | j        dz             )Nr   r   )r  r  r   r   r   z0 fetchOrder() can only fetch one order at a time)
r   r   rk  r5  spotPrivatePostOrdersInforG  r*  r,  r  r   )	r   r   r  r   r5  rH  r   r3  	numOrderss	            r   r  zlbank.fetch_order_default  s      >#DG.X$XYYY!!!!!!!!!V$$Tl
 
 77GV8T8TUUUUUUUU* 6266KK	>>##F1I... TW'YYZZZr   c                 <  K   |t          | j        dz             |                                  d{V  |                     |          }|                     |d|          }|                     |d          }d|d         i}|||d<   |5|                     |d          |d<   |                     |dz   d          |d	<   |                     |                     ||                     d{V }| 	                    |d
g           }| 
                    ||||          S )a  
        fetch all trades made by the user
        :see: 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>`
        Nz+ fetchMyTrades() requires a symbol argument
start_dater  r   r}  -i \&end_dater   )r   r   rk  r5  r*  r  ymd!spotPrivatePostTransactionHistoryrG  rw  r  )	r   r  r  rz  r   r5  rH  r   r   s	            r   fetch_my_tradeszlbank.fetch_my_trades!  sA      >#DG.[$[\\\!!!!!!!!!V$$e<<6<00fTl
 #GFO$(HHUC$8$8GL!"&((58+;S"A"AGJ??GU[@\@\]]]]]]]]* &"55  >>>r   c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d}|d         d|d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	|||          S )	a8  
        fetches information on multiple orders made by the user
        :see: 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>`
        Nz) fetchOrders() requires a symbol argumentr  r   r   r  current_pagepage_lengthr   orders)	r   r   rk  r5  *spotPrivatePostSupplementOrdersInfoHistoryrG  r*  rw  parse_orders
r   r  r  rz  r   r5  rH  r   r3  r1  s
             r   fetch_orderszlbank.fetch_ordersW  s       >#DG.Y$YZZZ!!!!!!!!!V$$=ETl 
 
 HHU\^dIeIeffffffff8 6266"55  >>>r   c                   K   |t          | j        dz             |                                  d{V  |                     |          }|d}|d         d|d}|                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	|||          S )	a  
        fetch all unfilled currently open orders
        :see: 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>`
        Nz- fetchOpenOrders() requires a symbol argumentr  r   r   r.  r   r1  )	r   r   rk  r5  )spotPrivatePostSupplementOrdersInfoNoDealrG  r*  rw  r3  r4  s
             r   fetch_open_orderszlbank.fetch_open_orders  s       >#DG.]$]^^^!!!!!!!!!V$$=ETl 
 

 GGT[]cHdHdeeeeeeee8 6266"55  >>>r   c                   K   |t          | j        dz             |                                  d{V  |                     |dd          }|                     |ddg          }|                     |          }|d         |d}|||d<   |                     |                     ||                     d{V }|                     |di           }|S )a  
        cancels an open order
        :see: 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>`
        Nz) cancelOrder() requires a symbol argumentorigClientOrderIdr  r   r!  r   )	r   r   rk  rg  r  r5  $spotPrivatePostSupplementCancelOrderrG  r*  )	r   r   r  r   r  r5  rH  r   r3  s	            r   r   zlbank.cancel_order  s      >#DG.Y$YZZZ!!!!!!!!!**63FXX6$7#IJJV$$Tl
 
 $+8G'(BB4;;wX^C_C_```````` 6266r   c                 :  K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |dg           }|S )a  
        cancel all open orders in a market
        :see: 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>`
        Nz- cancelAllOrders() requires a symbol argumentr  r   r   )r   r   rk  r5  ,spotPrivatePostSupplementCancelOrderBySymbolrG  r*  )r   r  r   r5  rH  r   r3  s          r   cancel_all_orderszlbank.cancel_all_orders  s       >#DG.]$]^^^!!!!!!!!!V$$fTl
 JJ4;;W^`fKgKghhhhhhhh$ 6266r   c                     |                      | j        d          }|                     ||          }|                      | j        di           }|                     |d|          }|                     |||          }|S )Nr   r   network)r*  r   r  r-  )r   currencyCoder   r   defaultNetworkr   r@  s          r   get_network_code_for_currencyz#lbank.get_network_code_for_currency  sw    //$,8IJJ//NN??4<R@@((NKK""8Wg>>r   r  c                   K   |                                   d{V  |                     | j        di           }|                     |dd          }|                     |d|          }|                     |d          }d}|dk    r|                     ||           d{V }n|                     ||           d{V }|S )a  
        fetch the deposit address for a currency associated with self account
        :see: https://www.lbank.com/en-US/docs/index.html#get-deposit-address
        :see: 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>`
        NrD   r   r   fetchDepositAddressSupplement)rk  r*  r   r-  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J(((<XYY!!&(MBB68,,444!BB4PPPPPPPPHH!??fMMMMMMMMHr   c                 b  K   |                                   d {V  |                     |          }d|d         i}|                     ||          }|||d<   |                     |d          }|                     |                     ||                     d {V }|                     |d          }|                     |d          }|                     |d          }	|                     |d          }
|                     | j        di           }| 	                    ||
|
          }|||	||d	S )
N	assetCoder   netWorkr@  r   addressmemor   r  rL  tagr@  r(  )
rk  r  rC  r   spotPrivatePostGetDepositAddressrG  r*  r-  r   r  )r   r  r   r  rH  r@  r   r3  rL  rO  	networkIdinverseNetworksnetworkCodes                r   rG  z#lbank.fetch_deposit_address_default+  sZ     !!!!!!!!!==&&$
 44T6BB!(GIYYvy11F>>t{{7TZ?[?[\\\\\\\\ 622""6955vv..$$VY77	//$,8JBOO,,_iSS"
 
 	
r   c                   K   |                                   d {V  |                     |          }d|d         i}|                     | j        d          }|                     |d          }|                     |||          }|||d<   |                     |d          }|                     |                     ||                     d {V }|                     |d          }|                     |d          }	|                     |d          }
|                     | j        d	i           }|                     |||          }||	|
||d
S )Nr  r   r   r@  networkNamer   rL  rM  r   rN  )	rk  r  r*  r   r  r-  r  *spotPrivatePostSupplementGetDepositAddressrG  )r   r  r   r  rH  r   r@  r   r3  rL  rO  rR  rS  s                r   rF  z&lbank.fetch_deposit_address_supplementQ  sr     !!!!!!!!!==&&HTN
 ??4<<<((;;""8Wg>>%,GM"YYvy11FHHU\^dIeIeffffffff 622""6955vv..//$,8JBOO,,_gwOO"
 
 	
r   c                   K   |                      ||          \  }}|                     |           |                                  d{V  |                     |d          }|                     |d          }|                     d|d           |                     |          }||d         ||d}|||d<   |                     |dd          }	|                     |ddg          }|                     | j	        d	          }
|                     |
|	|	          }|||d<   | 
                    |                     ||                     d{V }|                     |d
i           }||                     |d          dS )a  
        make a withdrawal
        :see: 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>`
        Nr  rj   r   )rL  r  r  r  rM  r@  rU  r   r   
withdrawId)r(  r   )handle_withdraw_tag_and_paramscheck_addressrk  r-  r  check_required_argumentr  safe_string_upper_2r*  r   !spotPrivatePostSupplementWithdrawrG  )r   r  r  rL  rO  r   r  r  rH  r@  r   rQ  r   r3  s                 r   rj   zlbank.withdrawx  s      99#vFFV7###!!!!!!!!!vu--65))$$Ze<<<==&&TN	
 
 ?!GFO**69mLL6I}#=>>??4<<<$$Xw@@	 %.GM"??GU[@\@\]]]]]]]] 6266""6<88
 
 	
r   c                 z    dddddddddddd}|                      |                     ||i           ||          S )	Npendingokfailedr   transfer)r  r  r  r  5)r  r  r  r  )deposit
withdrawal)r-  r*  )r   r  r   r  s       r   parse_transaction_statuszlbank.parse_transaction_status  sk       	 
 
 $ C CVVTTTr   r  c                 2   |                      |d          }d }|d}nd}|                      |d          }|                     |dd          }|                     | j        di           }|                      |d          }|                      |||          }	|                      |d	          }
d }d }|dk    r|
}n|
}|                     |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k    |dS )Nr   rd  re  txId
insertTime	applyTimer   rU  rL  r  r  coidr  r  )r  r  r(  txidr   rJ  r@  	addressToaddressFromrO  tagTotagFromr   r  updatedrb  )commentinternalr  )	r-  r  r*  r   r2  rg  r/  rf  rf  )r   transactionr  r   r   rl  r   r   rQ  r@  rL  rn  rm  r  r  r  r  r  r  s                      r   parse_transactionzlbank.parse_transaction  sk   < k400:DDDV44''\;OO	??4<1CRHH$$[-@@	""8Y	BB"";	::	9!KKI!!+x88''VVDD
&&z8<<..t/?/?X/V/VX\]]"";66  C
K
"
 D
 	

 Y//
 w
 w
 
 ;
 4
 T
 t
 D
 f
 
  f!
" t#
$ :-)
 
 
 	
r   c                 ~  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	|||          S )a  
        fetch all deposits made to an account
        :see: 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)rk  r  'spotPrivatePostSupplementDepositHistoryrG  r*  rw  parse_transactions)
r   r  r  rz  r   rH  r  r   r   depositss
             r   fetch_depositszlbank.fetch_deposits  s       !!!!!!!!!
 }}T**H&tnGFO#(GK EEdkkRY[aFbFbcccccccc0 x44>>$<<&&x5%HHHr   c                 ~  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	|                     |	|||          S )a#  
        fetch all withdrawals made from an account
        :see: 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  rw  r   r   )rk  r  "spotPrivatePostSupplementWithdrawsrG  r*  rw  rz  )
r   r  r  rz  r   rH  r  r   r   r   s
             r   fetch_withdrawalszlbank.fetch_withdrawalsF  s       !!!!!!!!!

 }}T**H&tnGFO#(GK @@WV\A]A]^^^^^^^^6 x44NN4b99	&&y(E5IIIr   codesc                   K   |                                   d{V  |                     d          }d}|du r|                     | j        di           }|                     |dd          }|                     |d|          }|                     |d          }|dk    r|                     |           d{V }n7|                     |           d{V }n|                     |           d{V }|S )aQ  
         * @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>`
        NFTre   r   r   fetchPublicTransactionFees)rk  check_required_credentialsr*  r   r-  r  fetch_public_transaction_feesfetch_private_transaction_fees)r   r  r   isAuthorizedr3  r   r  r   s           r   fetch_transaction_feeszlbank.fetch_transaction_fees{  s-      !!!!!!!!!66u==4oodl4JBOOG ,,Wh@]^^M%%fhFFFYYvx00F555#AA&IIIIIIII#BB6JJJJJJJJ==fEEEEEEEEFr   c                   K   |                                   d {V  |                                  d {V }|                     |dg           }i }t          dt	          |                    D ]}||         }|                     |d          }|                     |          }|                     |dg           }	i ||<   t          dt	          |	                    D ]e}
|	|
         }|                     |d          }|                     | j        d         ||          }|                     |d          }||||         |<   f|i |dS )	Nr   r   r  networkListr   r   withdrawFeerj   rd  r(  )	rk  r   r*  r+  r,  r-  r/  r   r2  )r   r   r   r3  withdrawFeesr4  entryr  r  r  jnetworkEntryrQ  rS  r  s                  r   r  z$lbank.fetch_private_transaction_fees  s      !!!!!!!!!??AAAAAAAA> 6266q#f++&& 	: 	:A1IE))%88J**:66D//%CCK!#L1c+..// : :*1~ ,,\6BB	"..t|<N/OQZ\eff&&|]CC?69L&{3: %
 
 	
r   c                 T  K   |                                   d {V  |                     |dd          }|                     |ddg          }i }| |                     |          }|d         |d<   |                     |                     ||                     d {V }|                     |dg           }i }t          dt          |                    D ]}||         }	|                     |	d          }
|
dk    r| 	                    |	d          }| 
                    |          }| 	                    |	d          }| 	                    | j        d	         ||          }||}| 	                    |	d
          }||         i ||<   |                     |          ||         |<   |i |dS )Nr  rJ  r   r   r   canWithDrawtruechainr   r  r  )rk  rg  r  r  spotPublicGetWithdrawConfigsrG  r*  r+  r,  r-  r/  r   r   )r   r   r  rH  r  r   r3  r  r4  r  canWithdrawr  r  r  r@  r  s                   r   r  z#lbank.fetch_public_transaction_fees  s      !!!!!!!!!!!&&+>>6FK#899}}T**H#+D>GK ::4;;wPV;W;WXXXXXXXX, 6266q#f++&& 	J 	JA!9D//$>>Kf$$!--dK@@
 33J??	((w77**4<8J+KUTYZZ?'G&&tU33	*2.0L+373D3DS3I3IY'0$
 
 	
r   c                   K   |                                   d{V  |                     d          }d}|du r|                     | j        di           }|                     |dd          }|                     |d|          }|                     |d          }|dk    r|                     ||           d{V  n9|                     ||           d{V  n|                     ||           d{V  |S )a  
        when using private endpoint, only returns information for currencies with non-zero balance, use public method by specifying self.options['fetchDepositWithdrawFees']['method'] = 'fetchPublicDepositWithdrawFees'
        :see: https://www.lbank.com/en-US/docs/index.html#get-all-coins-information
        :see: https://www.lbank.com/en-US/docs/index.html#withdrawal-configurations
        :param str[]|None 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>`
        NFTrG   r   r   fetchPublicDepositWithdrawFees)rk  r  r*  r   r-  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	  s9      !!!!!!!!!66u==4oodl4NPRSSG ,,Wh@abbM%%fhFFFYYvx00F999==eVLLLLLLLLLL>>ufMMMMMMMMMM99%HHHHHHHHHr   c                    K   |                                   d {V  |                     |           d {V }|                     |dg           }|                     ||d          S )Nr   r  )rk  r   rw  parse_deposit_withdraw_fees)r   r  r   r   r   s        r   r  z)lbank.fetch_private_deposit_withdraw_fees	  s       !!!!!!!!!??GGGGGGGG> ~~h33//eVDDDr   c                    K   |                                   d {V  i }|                     |                     ||                     d {V }|                     |dg           }|                     ||          S )Nr   )rk  r  rG  r*  "parse_public_deposit_withdraw_fees)r   r  r   rH  r   r   s         r   r  z(lbank.fetch_public_deposit_withdraw_feesA	  s       !!!!!!!!!::4;;wPV;W;WXXXXXXXX, x4466tUCCCr   c                    i }t          dt          |                    D ]8}||         }|                     |d          }|du r|                     |d          }|                     |          }||                     ||          r|                     |d          }	|	|                     ||          }
|
|                     |g          ||<   n!||         d                             |           |                     |d          }|                     | j	        d         ||          }||	d d	d d d	d
||         d         |<   *|	d d	||         d<   :|S )Nr   r  TrJ  r  r(  r  r   r  r\  rj   rd  r   rj   )
r+  r,  r*  r-  r/  in_arrayr2  deposit_withdraw_feer0  r   )r   r   r  r3  r4  r  r  r  r  r  resultValuer  rS  s                r   r  z(lbank.parse_public_deposit_withdraw_fees_	  s   " q#h--(( 	 	A1+C//#}==Kd""!--c;??
..z::=DMM$$>$>="&"2"23">">K".&*oofd&C&C&.+/+D+DcU+K+KF4LL"4L077<<< $ 0 0g > >&*&6&6t|DV7WY^`e&f&f&2 ,726-" -"
 ,026," ,"	E 	EF4L4[AA (3.28 8F4L4 r   c                    |                      |          }|                     |dg           }t          dt          |                    D ]}||         }|                     |d          }|                     | j        d         ||          }|                     |d          }	|                     |d          }
|	|
r|	d d|d<   |	d dd d dd	|d
         |<   |S )Nr  r   r   r   r  	isDefaultr  rj   r  r   )r  r*  r+  r,  r-  r  r   r2  )r   r  r  r3  r  r  r  rQ  rS  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hhK**<GGKkBBI& *&** *F:&  +&*! !
  $&*   	3 	3z";/ r   r   GETc           
         |                      ||                     |                    }| j        d         d         dz   | j        z   dz   |                     ||          z   }|d         dk    r|dz  }n-| j        d         d         dz   |                     ||          z   }|d         d	k    r2|r.|d
|                     |                     |                    z   z  }na|                                  t          | 	                                          }	| 
                                |                                 z   }
|                     d| j        i|          }d }t          | j                  dk    rd}nd}|                     |                     |                     |
||	d|                              }|                     |          }|                     |d          }|                                }d }|dk    r|                     | j        dd          }d }|rU|                     | j        d          }|7|                     |                     | j                            }|| j        d<   n-|                     |                     | j                            }|                     ||d          }nR|dk    rL|                     |                     |          |                     | j                  t4          j                  }||d<   |                     |                     |                    }d|	||
d}||||dS )Nr   r   r	  r   r.   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  strr  uuid22uuid16rG  apiKeyr,  secret	rawencodeencodehashupperr  r   r*  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	  s7   		&$"5"5d";";<<iv&,t|;cADDWDWX\^dDeDeeq6V5LCC)E":.4t7J7J4QW7X7XXCq6X AsT^^DLL,?,?@@@@++---D--//00Ikkmmdkkmm3GKK4;! E #O4;"$$"'".>>$,,t{{"$3&< < 	0 0 # #  D
 kk$''G99We,,D JJLLMD%''#'>>$,@RTX#Y#Y # O//$,>>C{"88T[9Q9QRR.1U+44T[[5M5MNNCxxsH== L00yy]!;!;T[[=U=UW^Weff E&M>>$,,u"5"566D C&$3"	 G fdwOOOr   c                    d}t          |          dz
  }|                     ||z            }|                     |d          }d}t          d|          D ]2}||z  }|                     ||          }|| j        ||         dz   z  }3|dz   S )N@   r   r   z-----BEGIN PRIVATE KEY-----

z-----END PRIVATE KEY-----)r,  r  sumr+  r  )	r   r  
lineLengthsecretLengthnumLinesr  r4  startends	            r   r  zlbank.convert_secret_to_pem	  s    
6{{Q$$\J%>??88Ha((-q(## 	1 	1A
NE((5*--C4;uSy)D00CC000r   c
                 ,   |d S |                      |d          }
|
dk    s|
sp|                     |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/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||                     |                    }|                      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                    } ||          d S )iNr3  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)r  r  r   r  r  r  r  r  r  r  r  r	  r
  r  r  )r*  r-  jsonr   r   r"   r   r   r   r   r   r#   r    r   )r   httpCodereasonr  r   r  r  r   requestHeadersrequestBodysuccess	errorCodemessage
ErrorClasss                 r   handle_errorszlbank.handle_errors
  sa   4//(H5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( 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( 5( 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( 5(j $))H--k5/ 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*. /2*0 12*2 32*4 52*6 72*8 92*: ;2*< =2*> )?2*@ )A2*B C2*D *E2* 2*F '&&##&'&####&")c2* 2* 2*d -e2) 2)Jf *W%%%tr   )N)K__name__
__module____qualname__r   r   r   r   r  r   r   r   ri  r  rq  r   r   rl  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  r  r  r,  r5  r8  r   r>  rC  rH  rG  rF  r   rj   rf  r   ru  r|  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__)r   s   @r   r'   r'      s       V V V V Vp ') #3 #3 #3 #3J *, I IV I I I I /1 M M M M^ /1 ^ ^ ^ ^@: :6 :V : : : :x 68 (0 (0 (0F (0 (0 (0 (0T 6:" H1 H17 H1 H1 H1 H1 H1T @DB NM NMS NM NMS\ NM NM NM NM`[ [ [5 [ [ [ [z <@d[] 0? 0? 0?S 0? 0?bfglbm 0? 0? 0? 0?d
 
 
4 
 
 
 
( 8<$]ajl 2J 2J 2JC 2JWZ 2Jquvzq{ 2J 2J 2J 2Jh{ { { { {z *, 2, 2, 2, 2, 2, 2,h
 
V 
?R 
 
 
 
& ;= 
. 
.c 
.AT 
. 
. 
. 
. /1  [    $ XZ T Tc T T T T T" mqy{ X X XI XY XX] Xfi X X X Xt	: 	: 	:v v v5 v v v vp 8<B B BC B B B B B$ CGr  (  (s  (C  (  (  (  (D @DB *[ *[C *[ *[ *[ *[ *[X 37TX\eg 4? 4?C 4?s 4?RU 4? 4? 4? 4?l 04$UYbd 6? 6? 6?C 6?s 6?imnsit 6? 6? 6? 6?p 59tZ^gi 3? 3?c 3? 3?TW 3?nrsxny 3? 3? 3? 3?j 9=R $ $S $# $ $ $ $L 59 " "c " " " "H   =?      * EG $
 $
 $
 $
 $
 $
L HJ %
 %
3 %
 %
 %
 %
N EIQS 7
 7
3 7
 7
Xc 7
 7
 7
 7
rU U U$P
 P
x P
; P
 P
 P
 P
d 04$UYbd /I /I /IC /Is /Iimnyiz /I /I /I /Ib 37TX\eg 3J 3JC 3Js 3JRU 3Jlpq|l} 3J 3J 3J 3Jj ?C2  $s)    2 ;= 6
 6
 6
 6
p :< 4
 4
 4
 4
l BFb  w    2 ?C2 $E $E $E $EL >B" D D D D<2 2 2 2h3 3 3 3 3 3j &eBSW 5P 5P 5P 5Pn
1 
1 
1p p p p p p pr   r'   )- ccxt.async_support.base.exchanger   ccxt.abstract.lbankr   r   r  ccxt.base.typesr   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$     s   6 5 5 5 5 5 + + + + + +   ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~       * * * * * * 0 0 0 0 0 0 - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & . . . . . . + + + + + + ) ) ) ) ) ) - - - - - - ) ) ) ) ) ) . . . . . . ) ) ) ) ) ) 4 4 4 4 4 4 % % % % % %^) ^) ^) ^) ^)Hk ^) ^) ^) ^) ^)r   