
    !:h                       d dl mZ d dlmZ d dl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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#m0Z0 d dl#m1Z1 d dl#m2Z2 d dl3m4Z4 d dl3m5Z5 d dl6m7Z7  G d dee      Z8y)    )Exchange)ImplicitAPIN)AccountAnyBalancesBorrowInterestBool
CurrenciesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypeStrStringsTickerTickersTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)InvalidNonce)TRUNCATE)	TICK_SIZE)Precisec                       e Zd Zdef fdZd Zi fdefdZi fdZi fde	e
   fdZdrdefdZi fd	Zi fdefd
Zi fde	e   fdZi fdefdZi fdefdZdsdefdZd Zdsde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i fdedefdZ i fdedefdZ!dsde
de"fdZ#dddi fdededede	e"   fd Z$i fdede%fd!Z&i fdede%fd"Z'dsdede%fd#Z(i fdede	e%   fd$Z)di fdedede*fd%Z+d& Z,di fded'e-d(e.d)e/d*e0f
d+Z1i fded(e.d,e/fd-Z2i fded,e/fd.Z3i fded,e/fd/Z4i fd0e	e5   fd1Z6defd2Z7di fded'e-d(e.d)e/d*e0f
d3Z8ddi fd4eded'e-d(e.d)e0d*e0fd5Z9di fd4ede:fd6Z;di fde:fd7Z<dddi fde:dedefd8Z=dddi fde:dedede	e>   fd9Z?dddi fde:dedede	e>   fd:Z@di fd4ede:fd;ZAdsd<ede
de>fd=ZBdddi fd4ede:dedefd>ZCdddi fde:dedefd?ZDddi fdededede	eE   fd@ZFdsdAede
deEfdBZGi fdedeHfdCZIdi fded)e/dDedeJfdEZKdFe:fdGZLdsdHededeJfdIZMdddi fde:dedede	eJ   fdJZNdddi fde:dedede	eJ   fdKZOdL ZPi fdeQfdMZRi fded)e/dNedOedeSf
dPZTdsdQededeSfdRZUdFe:de:fdSZVdT ZWdsdUededeXfdVZYdddi fde:dedede	eX   fdWZZi fdXZ[dsdefdYZ\ddddi fde:de:dedede	e]   f
dZZ^dsd[ede
de]fd\Z_dddi fdedefd]Z`ddi fdededefd^Zad_ Zbi fded)e/fd`Zci fdeded)e/fdaZdi fdefdbZei fdedefdcZfdsdefddZgdi fdeefdfZhdi fdgede:fdhZididji ddfdkZjdekdledmednedoedpefdqZl xZmS )tkucoinreturnc                 \    | j                  t        t        |          i ddddddgddd	d
dddddddddi dd ddddddddddddddddddddddddd dd!dd"dd#di d$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4di d5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDddEdi dFddGddHddIddJddKddLddMddNddOddPddQddRddSddTddUddVdi dWddXddYddZdd[dd\dd]dd^dd_dd`ddaddbddcdddddeddfddgdddddhdidjdkdldldmdmdndodldpdqdrgdsdtddddudvi dwdxdydxdzd{d|d}d~dddddxdd{dd}dd{ddxddxddxddxddxdd}dd}dddddidi dddddddd}dddddd}ddddddddddddddddddddi dddddddddddd}dd}dd}dd}dd}ddddddddddddddi dddddddd}dddd}dddddddd}dd}ddddddddddɓddi ddɓdd͓dd͓dddddddddd͓ddՓdddddddddddddddd}d}ddޜi dddddddddddd{dddddddddddddddddddd}ddi dddddd}dddddd͓dd͓dd͓dd͓dddddddddddddd͓ddi ddddddddddddddddd ddd}dd͓dddd}dd͓dd}dd}dd}d}dddddi ddxddxdd}ddxd	dd
dddddxdddd}ddxddxddxdd}dddd}dd{ddiddidi dd}dddddddd}ddddddddddddxdddd}dd}ddd dd!dddd}d}dxd{dd{d{dd"
d#d#ddd$dd%d&diidddd}ddddd'dd}d}d}d(d)d}iddddddddddd*	d+did+didd,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=t        d>i d?t
        d@t
        dAt
        dBt
        dCt        dDt        dEt        dFt        dGt        dHt        dIt        dJt        dKt        dLt        dMt        dNt        dOt        i dPt        dQt        dRt        dSt        dTt        dUt        dVt
        dWt        dXt        dYt        dZt        d[t
        d\t        d]t        d^t        d_t        d`t        i dat        dbt        dct        ddt        det        dft        dgt        dht        dit        djt        dkt        dlt        dmt        dnt        dot        dpt        dqt        i drt        dst        dtt        dut        dvt        dwt        dxt        dyt        dzt        d{t        d|t        d}t        d~t        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt
        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt         dt        dt"        dt        dt        dt        dt        dt        dt        dt        dt        dt        i dt        dt        dt        dt        dt        dt         dt        dt        dt        dt$        dt        dt        dt        dt        dt        dt        dt        t        t        ddddd| j'                  d      | j'                  d      | j'                  d      | j'                  d      g| j'                  d      | j'                  d      g| j'                  d      | j'                  d      g| j'                  dP      | j'                  d      g| j'                  d      | j'                  d      g| j'                  d      | j'                  d      g| j'                  d«      | j'                  dë      g| j'                  dī      | j'                  dū      g| j'                  dƫ      | j'                  dǫ      g| j'                  dȫ      | j'                  dɫ      g| j'                  dʫ      | j'                  d˫      g| j'                  d̫      | j'                  dͫ      g| j'                  dΫ      | j'                  dϫ      gg| j'                  d      | j'                  d      g| j'                  d      | j'                  d      g| j'                  d      | j'                  d      g| j'                  dP      | j'                  dū      g| j'                  d      | j'                  dͫ      g| j'                  d      | j'                  d      g| j'                  d«      | j'                  d      g| j'                  dī      | j'                  d      g| j'                  dƫ      | j'                  dЫ      g| j'                  dȫ      | j'                  dЫ      g| j'                  dʫ      | j'                  dЫ      g| j'                  d̫      | j'                  dЫ      g| j'                  dΫ      | j'                  dЫ      ggdќdҜddi i dӜdԜdՐd֐dאdؐdِdڐdۜd dܐdݐdސddddddddiddidddd
dddii dd
dddd
dd
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dd
ddܓi dd
dddd
dd
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dddiiddddddddddddddddddd
i ddddddd ddddddddd	d
dddddddddddddddddi ddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=i d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_i d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dddi ddddddddddddddddddddddddddddddddddi dddddddddddddddddddddddddddddddddÐdēi dŐdƓdǐdȓdɐdʓdːd̓d͐dΓdϐdГdѐdғdӐdԓdՐd֓dאdؓdِdړdېdܓdݐdޓdߐdddddddi dddddddddddddd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di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      S (  Nidr2   nameKuCoin	countriesSC	rateLimit
   versionv2	certifiedTprocommentzPlatform 2.0quoteJsonNumbersFhasCORSspotmarginswapfutureoptionborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercloseAllPositionsclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTriggerOrder	editOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersByStatusfetchOrderTradesfetchPositionHistoryfetchPositionModefetchPositionsHistoryfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransfersfetchWithdrawalsrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModesetPositionMode)signIntransferwithdrawurlszdhttps://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpgz2https://www.kucoin.com/ucenter/signup?rcode=E5wkqezhttps://api.kucoin.comzhttps://api-futures.kucoin.comzhttps://kucoin.com/_apizhttps://api-broker.kucoin.com)publicprivatefuturesPrivatefuturesPublicwebExchangebrokerearnzhttps://www.kucoin.comzhttps://docs.kucoin.com)logoreferralapiwwwdocrequiredCredentials)apiKeysecretpasswordr   
currenciesg      @currencies/{currency}symbols   zmarket/orderbook/level1   zmarket/allTickersg     6@zmarket/statsmarketsz%market/orderbook/level{level}_{limit}zmarket/orderbook/level2_20zmarket/orderbook/level2_100zmarket/historieszmarket/candlesprices	timestampstatuszmark-price/{symbol}/currentmark-price/all-symbols      )zmargin/configannouncementszbullet-public   )getpostz	user-info   accountsg      @zaccounts/{accountId}zaccounts/ledgerszhf/accounts/ledgers   zhf/margin/account/ledgersztransaction-historyzsub/userzsub-accounts/{subUserId}zsub-accountszsub/api-keyzmargin/account(   zmargin/accountszisolated/accountsdeposit-addressesdepositszhist-depositswithdrawalszhist-withdrawalszwithdrawals/quotaszaccounts/transferableztransfer-listzbase-feez
trade-feeszmarket/orderbook/level{level}zmarket/orderbook/level2zmarket/orderbook/level3zhf/accounts/openedzhf/orders/activezhf/orders/active/symbolszhf/margin/order/active/symbolszhf/orders/donezhf/orders/{orderId}z"hf/orders/client-order/{clientOid}zhf/orders/dead-cancel-all/queryzhf/fillsorderszlimit/ordersorders/{orderId}zorder/client-order/{clientOid}fillszlimit/fillsz
stop-order   zstop-order/{orderId}z stop-order/queryOrderByClientOidoco/order/{orderId}zoco/order/details/{orderId}oco/client-order/{clientOid}
oco/orderszhf/margin/orders/active   zhf/margin/orders/donehf/margin/orders/{orderId})hf/margin/orders/client-order/{clientOid}   zhf/margin/fillszetf/infozmargin/currencieszrisk/limit/strategyzisolated/symbolszmargin/symbolszisolated/account/{symbol}2   zmargin/borrowzmargin/repayzmargin/interestzproject/listzproject/marketInterestRatezredeem/orderszpurchase/orderszbroker/api/rebase/download)migrate/user/account/statusaffiliate/inviter/statisticszsub/user/createdzsub/api-key/update-   zaccounts/universal-transferzaccounts/sub-transferzaccounts/inner-transfertransfer-outtransfer-inz	hf/orders   zhf/orders/testzhf/orders/synczhf/orders/multizhf/orders/multi/synczhf/orders/alterzhf/orders/dead-cancel-allorders/testorders/multiz	oco/orderzhf/margin/orderzhf/margin/order/testzmargin/orderzmargin/order/testpurchaseredeemzlend/purchase/updatebullet-privatezposition/update-user-leveragezdeposit-address/createzwithdrawals/{withdrawalId}zhf/orders/sync/{orderId}z'hf/orders/sync/client-order/{clientOid}zhf/orders/cancel/{orderId}zhf/orders/cancelAllz!stop-order/cancelOrderByClientOidzstop-order/cancel)r   r   r   hf/margin/orders)r   r   deletezcontracts/activezcontracts/{symbol}tickerzlevel2/snapshotzlevel2/depth20zlevel2/depth100ztrade/historyzkline/queryzinterest/queryzindex/queryzpremium/queryztrade-statisticszfunding-rate/{symbol}/currentzcontract/funding-rateszlevel2/message/queryg&S?zaccount-overviewzaccount-overview-all	   
stopOrdersrecentDoneOrderszorders/byClientOidrecentFillsopenOrderStatisticsposition	positionszmargin/maxWithdrawMarginzcontracts/risk-limit/{symbol}zfunding-history)
r   r   r   r   r   z#position/margin/auto-deposit-statuszmargin/withdrawMarginzposition/margin/deposit-marginz position/risk-limit-level/changer   g      ?)r   zorders/client-order/{clientOid}r   r   r   zcurrency/currency/chain-info)zbroker/nd/infobroker/nd/accountbroker/nd/account/apikeyzbroker/nd/rebase/downloadasset/ndbroker/deposit/listzbroker/nd/transfer/detailzbroker/nd/deposit/detailzbroker/nd/withdraw/detail)zbroker/nd/transferr   r   zbroker/nd/account/update-apikeyr   )	zotc-loan/loanzotc-loan/accountszearn/redeem-previewzearn/saving/productszearn/hold-assetszearn/promotion/productszearn/kcs-staking/productszearn/staking/productszearn/eth-staking/productszearn/orders)r   r   r   r   r   r   r   
timeframes1min3min5min15min30min1hour2hour4hour6hour8hour12hour1day1week1month)1m3m5m15m30m1h2h4h6h8h12h1d1w1MprecisionMode
exceptionszThe order does not exist.zorder not existzorder not exist.order_not_exist&order_not_exist_or_not_allow_to_cancelz)Order size below the minimum requirement.z7The withdrawal amount is below the minimum requirement.z8Unsuccessful! Exceeded the max. funds out-transfer limitz The amount increment is invalid.z.The quantity is below the minimum requirement.400401403404405415429500503101030103000130101130102130103130104130105130106130107130108130201130202130203130204130301130302130303130304130305130306130307130308130309130310130311130312130313130314130315126000126001126002126003126004126005126006126007126009126010126011126013126015126021126022126027126028126029126030126033126034126036126037126038126039126041126042126043126044126045126046126047126048135005135018200004210014210021230003260000260100300000400000400001400002400003400004400005400006400007400008400100400200400330400350400370400400400401400500400600400760401000408000411100415000400303500000260220600100600101900014)zExceeded the access frequencyzrequire more permission)exactbroadfeesz0.001050200z0.0009z0.00081000z0.000720004000z0.00068000z0.000515000z0.0004525000z0.000440000z0.0003560000z0.000380000z0.00025z-0.00005)takermaker)	tierBased
percentager  r  tiers)r  r  r   deposit)tradingfundingBIFIFVAIOTWAXPAPTOSLAUNCHTOKENALTzFTX Users' Debt)BIFIVAIWAXr  KALTFUDv1-private_get_fillsr   )webApiEnablewebApiRetrieswebApiMuteFailurefetchTickersFees
includeFeeGETv3)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r  POSTDELETEr  )r   r   r   ccxtz$9e58cc35-5b5e-4133-92ec-166e3f077cb8)r5   keyccxtfuturesz$1b327198-f30c-4f14-a0ac-918871282f15)rD   rG   tradeisolatedmaincontractpooltrade_hf)
rD   rE   crossr  r  r  rG   rF   mininghfBRC20btcBTCNATIVESEGWITbech32ERC20ethTRC20trxHRC20hecoMATICmaticKCCkccSOLsolALGOalgoEOSeosBEP20bscBEP2bnbARBONEarbitrumAVAXXavaxAVAXCavaxcTLOStlosCFXcfxACAacaOPoptimismONTontGLMRglmrCSPRcsprKLAYklayXRDxrdRVNrvnNEARnearAPTaptosETHWethwTONtonBCHbchBSVbchsvBCHAbchabcOSMOosmoNANOnanoXLMxlmVETvetIOSTiostZILzilXRPxrpTOMOtomoXMRxmrCOTIcotiXTZxtzADAadar  waxpTHETAthetaONEoneIOTEXiotxNULSnulsKSMksmLTCltcWAVESwavesDOTdotSTEEMsteemQTUMqtumDOGEdogeFILfilXYMxymFLUXfluxATOMatomXDCxdcKDAkdaICPicpCELOceloLSKlskVSYSvsysKARkarXCHxchFLOWflowBANDbandEGLDegldHBARhbarXPRxprARarFTMftmKAVAkavaKMAkmaXECxecIOTAiotaHNThntASTRastrPDEXpdexMETISmetisZECzecPOKTpoktOASYSoasOASISoasisETCetcAKTaktFSNfsnSCRTscrtCFGcfgICXicxKMDkmdNEMSTXstxDGBdgbDCRdcrCKBckbELAelaHYDRAhydraBTMbtmKARDIAkaiSXPsxpNEBLneblZENzenSDNsdnLTOltoWEMIXwemixEVEReverBNCbncBNCDOTbncdotAIONaionGRINgrinLOKIlokiQKCqkcTTPIVXpivxSEROseroMETERmeter	STATEMINE	statemineDVPNdvpnXPRTxprtMOVRmovrERGOergoABBCabbcDIVIdiviPURApuraDFIdfiNEON3neon3DOCKdockTRUEtrueCScsORAIoraiBASEbaseMARGIN_TRADEMARGIN_ISOLATED_TRADETRADE)r  r  rD   )r  r<   symbolSeparatorfetchMyTradesMethodtimeDifferenceadjustForTimeDifferencerc   rw   r   versionspartneraccountsByTypenetworksmarginModes)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergmax   )r  limitdaysBack	untilDayssymbolRequired)r  triggerr  r  i  )r  r  r  r  r  )r  r  r  daysBackCanceledr  r  r  r  r    )	sandboxrS   rT   r{   r   r   fetchOrdersr`   r|   )linearinverse)rD   rF   rG   )commonCurrenciesoptionsfeatures)deep_extendsuperr2   describer/   r)   r(   r   r&   r$   r    r*   r+   r,   r!   r'   r%   r-   r"   parse_number)self	__class__s    E/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/kucoin.pyr  zkucoin.describe#   s&   fd < > UA
(UA
HUA
 $UA
 	UA

 tUA
 UA
 4UA
 ~UA
 UA
  YYY $Y 	Y
 %Y %Y $TY 'Y "4Y tY $UY  Y 'Y /Y ,TY  0!Y" t#Y$ %Y& &t'Y( ')Y* (+Y, "4-Y. %d/Y0 T1Y2  3Y4 5Y6 &t7Y8 +D9Y: )$;Y< $T=Y> '?Y@ (AYB "4CYD &tEYF (GYH 1$IYJ  KYL *4MYN +DOYP &uQYR #ESYT *5UYV $UWYX "5YYZ *5[Y\ +E]Y^ #D_Y` taYb %ecYd /eYf "5gYh +EiYj kYl !%mYn !$oYp "4qYr  sYt duYv $UwYx +EyYz "4{Y| d}Y~ !$Y@ "5AYB &tCYD #DEYF 'GYH $UIYJ (KYL )%MYN tOYP tQYR SYT TUYV tWYX "4YYZ #E[Y\ &t]Y^ !%_Y` #DaYb #DcYd &teYf tgYh  iYj "5kYl    qYUA
H ~P67&F%E#<=4 0-IUA
j " $kUA
t $c 0 "1	
 21 ,T ' "3 @ 5a 6q +C )# !# $S  !#!$ 6q%& 1!'( *,)++2 (1<M#RM #CM /	M
 +AM .qM 4QM .qM #BM 3DM 'M &rM )"M *2M  ,R!M" ,S#M$ #C%M& ('M( &r)M* +B+M, -b-M. 0/M0 (1M2 #A3M4 %a5M8 89M: 21;M< 21=M> -a?M@ +AAMB 3ACMD 9!EMF )!GMH .qIMJ =aKML :1MMN #AOMP !!QMR 'SMT +AUMV 9!WMX  YMZ &r[M\ %a]M^ /_M` ;AaMb .qcMd 6qeMf 7gMh %aiMl 21mMn 0oMp 5aqMr DQsMt *1uMv #BwMx ,RyMz .r{M| +B}M~ )!M@ 4RAMB (CMD 'EMF *2GMH 'IMJ 5cKML (MMN *2OMR 5aSMT 898:YM\(*D( &r( -b	( ,R( &s( 6q( 0( 22( '( &r( $Q( )!(  )!!(" *1#($ /%(& *1'(( 4Q)(* !!+(, &q-(. '/(0 %a1(2 $Q3(6 *17(8 /9(: ';(< ,Q=(> (?(@ 'A(B #BC(D !"E(F /G(J )"K(L 8M(N 1"O(R%r 5b	 .q 3A =a B1 5a $Q .r +A 9! !"  /!" <Q#$ ,Q%& .q'( 7)* '(67EF,.3qSj*C,c !! *3	
 )# *2 ( &s )# &q 6s ( +C 8 1#  $Q!" !!#& /'. (-"8-q +C	
 / ( !! %a +C +C -c   &s .r  #A!" $Q#$ 3B%& 8'( *3)0 )+')"#'((+?@13:;<=*,  -0;>"$&*	M,#\ 6  +,-.455678564556	 /0-.45;<	 3A#. *+-./203,/36581458
 &s &ssluUA
N OUA
n YoUA
p x/x%}x 'x &}	x
 =lx @x N}x OPax 7
x Elx :x .x <x <x <x  <!x" ,#x$ /%x& /'x( .)x* l+x, j-x. m/x0 m1x2 m3x4 /5x6 l7x8 m9x: m;x< .=x> m?x@ /AxB jCxD /ExF .GxH lIxJ lKxL lMxN lOxP lQxR lSxT lUxV mWxX lYxZ l[x\ l]x^ l_x` laxb mcxd lexf mgxh lixj mkxl .mxn moxp mqxr msxt muxv mwxx /yxz m{x| l}x~ lx@ lAxB lCxD lExF lGxH lIxJ lKxL lMxN mOxP mQxR mSxT mUxV mWxX mYxZ l[x\ l]x^ l_x` .axb .cxd mexf mgxh /ixj lkxl /mxn /oxp nqxr /sxt luxv iwxx 1yxz l{x| 1}x~ 1x@ 1AxB 1CxD 1ExF lGxH /IxJ lKxL lMxN lOxP lQxR jSxT 1UxV lWxX iYxZ l[x\ j]x^ j_x` .axb jcxd .exf 2gxh nixj /kxl lmxn joxt 6G/?u~qUA
n !%"&!..w7!..w7 "..s3T5F5Fw5OP!..t4d6G6G6PQ!..u5t7H7H7RS!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..v68I8I(8ST!..v68I8I(8ST!..w79J9J99UV!..w79J9J89TU!..w79J9J99UV!..w79J9J89TU!..w79J9J99UV"  "..s3T5F5Fw5OP!..t4d6G6G6QR!..u5t7H7H7RS!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I#8NO!..v68I8I#8NO!..v68I8I#8NO!..w79J9J:9VW!..w79J9J:9VW!..w79J9J:9VW!..w79J9J:9VW!..w79J9J:9VW"!%N "'"' "!	O-oUA
L  ))! #&':"#+0$(%&)-$ '! !% *.59'+6:-1 	' ''  8'  '	' 
 +D'  .t'  0'  0'  6t'  6t'  <T'  24'   :4!' " ;D#' $ )$%' ( 6t)' * =d+' , 4T-' . 9$/' 0 H1' 2 .t3' 4 '5' 6 07' 8 ,T9' : +D;' < .t=' > +D?' @ 9$A' B ,TC' D .tE' F :4G' H -dI' J ;DK' L :4M' P!.! :4	!
 4T! 6t! +D! 5d! (! .t! 3D! ,T! +D!  '!!" %d#!$ 3D%!& <T'!( *4)!4 ;?IM0437<@*.#K Z *D!'o\@ %E
 ,E $&% *"%(&$$#OUO%xO UO U	O
 VO WO 5O 5O FO 5O UO EO jO VO WO  F!O" 5#O$ 5%O& *'O( 5)O* F+O, F-O. F/O0 51O2 53O4 F5O6 77O8 F9O: 5;O< 5=O> 7?O@ HAOB FCOD FEOF 5GOH 5IOJ FKOL 5MON 5OOP FQOR 5SOT FUOV 5WOX 5YOZ 6[O\ W]O^ 5_O` VaOb FcOd 5eOf 5gOh WiOj 5kOl WmOn FoOp FqOr 5sOt 5uOv FwOx FyOz 5{O| 5}O~ 5O@ FAOB 5COD FEOF 5GOH 5IOJ FKOL FMON FOOP FQOR 5SOT $UOV 5WOX FYOZ 5[O\ 5]O^ F_O` 5aOb FcOd FeOf WgOh 5iOj FkOl UmOn WoOp 5qOr 5sOt 5uOv FwOx 5yOz 5{O| 5}O~ 5O@ 5AOB 5COD 5EOF 5GOH 5IOJ WKOL 5MON eOOP 5QOR FSOT 5UOV 5WOX 5YOZ W[O^ F_O` 5aOb hcOf FgOh FiOj FkOl 5mOn $oOp FqOr FsOt WuOv  wOx FyOz F{O| F}O~ FO@ FAOB FCOD FEOF 5GOJ WKOL FMON FOOP $QOR FSOT FUOb , 7# u
_D  %&*(,,0,1)-+/6:#'#'"&#'	( #($)$)+/27/3#')$. q% '+!%$(%&*.& ',#'$)*.	# '+!$#'$)*.( $(&*!$$(,0%&#'$)*.	*  #u=~ ##
 ##GG[UA
 U U	    c                 B    | j                         | j                  d   z
  S )Nr  )millisecondsr  )r  s    r  noncezkucoin.nonce;  s       "T\\2B%CCCr  c                 H    | j                  |      }| j                  |d      S )aA  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://docs.kucoin.com/#server-time

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns int: the current integer timestamp in milliseconds from the exchange server
        data)publicGetTimestampsafe_integer)r  paramsresponses      r  
fetch_timezkucoin.fetch_time>  s)     **62   622r  c                     | j                  |      }| j                  |di       }| j                  |d      }|dk(  rdndddd|dS )aA  
        the latest known information on the availability of the exchange API

        https://docs.kucoin.com/#service-status

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
        r  r   openokmaintenanceN)r   updatedetaurlinfo)publicGetStatus	safe_dictsafe_string)r  r  r  r  r   s        r  fetch_statuszkucoin.fetch_statusQ  s\     ''/ ~~h3!!$1%/dm
 	
r  c                    d}| j                  |ddd      \  }}g }|j                  | j                  |             | j                  d      }|xr | j	                  |dd      }|r@|j                  | j                  |             |j                  | j                  |             |r |j                  | j                  |             |r|j                  | j                                |}| j                  |d   d      }|r| j                  |d	   di       ni }| j                  |d
g       }	| j                  |	d      }
|r|d   ni }| j                  |dg       }| j                  |d      }|rdnd	}| j                  ||i       }| j                  | j                  |di       dg       }| j                  |d      }g }t        dt        |            D ]  }||   }| j                  |d      }|j                  d      \  }}| j!                  |      }| j!                  |      }| j                  ||i       }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }||
v }||v } | j	                  |dd      xs |xs | }!|j                  i d|d|dz   |z   d|d|ddd|d|ddddddd|!d || d!d"dd#dd$dd%| j	                  |d&      d'ddd| j#                  t%        j&                  ||            | j#                  t%        j&                  ||            ddddd| j)                  |d(      | j)                  |d)      d*ddd+| j)                  |d,      | j)                  |d-      d+ddd+| j)                  |d.      | j)                  |d/      d+d0d|d1        | j*                  d2   r| j-                          |S )3aE  
        retrieves data on all markets for kucoin

        https://docs.kucoin.com/#get-symbols-list-deprecated
        https://docs.kucoin.com/#get-all-tickers

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of objects representing market data
        Nrw   r  TFmarginablesr   r  r   itemssymbolr   r   r   r  makerFeeRatetakerFeeRatemakerCoefficienttakerCoefficientisMarginEnabledr5   /r  quotesettlebaseIdquoteIdsettleIdtyperD   rE   r  )r  r  rF   rG   rH   activeenableTradingr  baseIncrementpriceIncrement)amountpriceminr  baseMinSizebaseMaxSizequoteMinSizequoteMaxSize)r  r  r  cost)r  r  r  r  contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr  r  )handle_option_and_paramsappendpublicGetSymbolscheck_required_credentials	safe_boolprivateGetMarginSymbolsprivateGetIsolatedSymbolspublicGetMarketAllTickersload_migration_status	safe_listr  index_byrangelenr  splitsafe_currency_coder  r0   
string_mulsafe_numberr  load_time_difference)"r  r  r  promisescredentialsSetrequestMarginables	responsessymbolsData	crossData
crossItems	crossByIdisolatedDataisolatedItemsisolatedById
tickersIdxtickersResponsetickerItemstickersByIdresultimarketr5   r  r  r  r  r   r
  r  r  r  hasCrossMarginhasIsolatedMarginisMarginables"                                     r  fetch_marketszkucoin.fetch_marketsn  s     #'#@#@Ykmq#r &--f560 88?+[v}VZ0[OOD88@A OOD::6BC, OOD::6BC4 OOD6689	nnYq\6:@RDNN9Q<<XZ	^^Iw;
MM*h7	'9y|r|VR@}}]H=,Q!
..JCnnT^^OVR%PRZ\^_mmK:q#k*+ E	A ^F!!&(3B hhsmOFG**62D++G4E^^KR8F++FNCL++FNCL#//8JK#//8JK IoN!#|!3>>&2CUKr~rarLMM 6b6$*u,6 6 	6
 $6 &6 76 D6 6 6 ,6 + 1 6  !6" %#6$ %%6& $..A'6( E)6* **7+=+=lL\+]^**7+=+=lL\+]^ $"&""..vG!--f6FG  $#!
  $//F#//F
  $#
  $//G#//G$  k6 6E	L <<12%%'r  forcec                     d| j                   vs| j                   d   |r/| j                         }| j                  |d      | j                   d<   y)a   
        :param boolean force: load account state for non hf
        loads the migration status for the account(hf or not)

        https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/get-user-type

        :returns any: ignore
        r  r  T)r  privateGetHfAccountsOpenedr/  )r  rS  rL  s      r  r3  zkucoin.load_migration_status-  sJ     $$,,t*<*D::<F!%!?DLLr  c                     | j                  | j                  dd      }d }||rd}nd}| j                  |d|      }| j                  |d      }||gS )Nr  FT)r/  r  omit)r  r  migratedloadedHfr  s        r  handle_hf_and_paramszkucoin.handle_hf_and_params;  s\    dEB >>&$964(F|r  c                     | j                  |      }| j                  |dg       }i }t        dt        |            D ]  }||   }| j	                  |d      }| j	                  |d      }| j                  |      }	i }
| j                  |dg       }| j	                  |d      }| j                  | j                  |            }t        |      }|st        d|      D ]  }||   }| j	                  |d      }| j                  ||	      }| j                  |dd	      }| j                  |d
d	      }||| j	                  |d      ||xr || j                  |d      ||| j                  | j                  | j	                  |d                  | j                  |d      | j                  |d      d| j                  |d      | j                  |d      ddd
|
|<    |dk(  xr |dk(  }| j                  |||	|rdnd|||
dddddd      ||	<    |S )a  
        fetches all available currencies on an exchange

        https://docs.kucoin.com/#get-currencies

        :param dict params: extra parameters specific to the exchange API endpoint
        :returns dict: an associative dictionary of currencies
        r  r   currencyfullNamechainsr(  chainIdisWithdrawEnabledFisDepositEnabled	chainNamewithdrawalMinFeewithdrawPrecisionwithdrawalMinSizemaxWithdrawr  depositMinSize
maxDepositr   r  )
r  r5   r6   coder  feer  r   r(  r)  2fiatcryptoN)r5   r6   rj  r  r(  r  r  r  r   r  rk  r)  )publicGetCurrenciesr4  r6  r7  r  r9  r  parse_precisionnetwork_id_to_coder/  r;  safe_currency_structure)r  r  r  currenciesDatarL  rM  entryr5   r6   rj  r  r^  rawPrecisionr(  chainsLengthjchainr_  networkCodechainWithdrawEnabledchainDepositEnabledisFiats                         r  fetch_currencieszkucoin.fetch_currenciesG  si    ++F3L &"=q#n-. 7	A"1%E!!%4B##E:6D**2.DH^^E8R8F++E;?L))$*>*>|*LMIv;L1l+ q	**5)<"55gtD'+~~e=PRW'X$&*nnU<NPU&V#!! ,,UK@'2J7J++E3EF2 4!%!2!243G3GHXHXY^`sHt3u!v $(#3#3E;N#O#'#3#3E=#I%
 $(#3#3E;K#L#'#3#3E<#H$	)%8 #c)B0AF77"(h&$ 9 F4LU7	p r  c           	      L   | j                  |      }| j                  |dg       }g }t        dt        |            D ]e  }||   }| j	                  |d      }| j	                  |d      }| j                  |      }	| j	                  |d      }
|j                  ||
|	|	|d       g |S )aP  
        fetch all the accounts associated with a profile

        https://docs.kucoin.com/#list-accounts

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
        r  r   r5   r\  r  )r5   r  r\  rj  r  )privateGetAccountsr4  r6  r7  r  r9  r,  )r  r  r  r  rL  rM  account	accountId
currencyIdrj  r  s              r  fetch_accountszkucoin.fetch_accounts  s     **620 ~~h3q#d)$ 	A1gG(($7I))':>J**:6D##GV4DMM  	 r  rj  c                 h   | j                          | j                  |      }d|d   i}d}| j                  |      \  }}|"| j                  |      j	                         |d<   | j                  | j                  ||            }| j                  |di       }i }| j                  |d      ||<   ||i dS )aY  
        *DEPRECATED* please use fetchDepositWithdrawFee instead

        https://docs.kucoin.com/#get-withdrawal-quotas

        :param str code: unified currency code
        :param dict params: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r\  r5   Nrx  r  withdrawMinFee)r  r   r  )	load_marketsr\  handle_network_code_and_paramsnetwork_code_to_idlowerprivateGetWithdrawalsQuotasextendr  r;  )	r  rj  r  r\  requestry  r  r  withdrawFeess	            r  fetch_transaction_feezkucoin.fetch_transaction_fee  s     	==&
 "AA&IV"#66{CIIKGG33DKK4PQ~~h3!--d4DET$
 	
r  c                 P   | j                          | j                  |      }d|d   i}d}| j                  |      \  }}|"| j                  |      j	                         |d<   | j                  | j                  ||            }| j                  |d      }| j                  ||      S )aD  
        fetch the fee for deposits and withdrawals

        https://docs.kucoin.com/#get-withdrawal-quotas

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: The chain of currency. This only apply for multi-chain currency, and there is no need for single chain currency; you can query the chain through the response of the GET /api/v2/currencies/{currency} interface
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r\  r5   Nrx  r  )	r  r\  r  r  r  r  r  r  parse_deposit_withdraw_feer  rj  r  r\  r  ry  r  r  s           r  fetch_deposit_withdraw_feez!kucoin.fetch_deposit_withdraw_fee  s     	==&
 "AA&IV"#66{CIIKGG33DKK4PQ& ~~h/..tX>>r  Nr\  c                    d|v r|d ddd d di d}| j                  |dg       }t        dt        |            D ]Z  }||   }| j                  | j	                  |d      | j	                  |d            }| j                  |d      ddd d dd	|d
   |<   \ |S | j                  |d      }||ddd d di d}	| j	                  |d      }
| j                  |
| j	                  |d            }|d d dd	|	d
   |<   |	S )Nr^  F)rk  r  )r  r   r  r  r   r_  rj  r  ri  r  rx  )r4  r6  r7  rq  r  r;  )r  rk  r\  	resultNewr^  rM  rx  networkCodeNewminWithdrawFeerL  	networkIdry  s               r  r  z!kucoin.parse_deposit_withdraw_fee+  ss     s? "'
  "& I ^^C26F1c&k* q	!%!8!89I9I%QZ9[]a]m]mnvx~]  "A  $//7GH&+!
  $&* 	9	*%n5 ))#/?@%#
 " 
 $$S'2	--i9I9I(TZ9[\&"+
z;' r  c                    | j                  | j                  |dd      }| j                  |d|      }| j                  | j                  d      }| j                  ||      }|Ct	        |j                               }t        | j                  dz   dj                  |      z         | j                  |d      }|dk(  xs |dk(  xs |d	k(  S )
NdefaultTyper  r  r  z' isFuturesMethod() type must be one of z, r  rG   futures)
safe_string_2r  r  r  listkeysr   r5   joinrW  )r  
methodNamer  r  requestedTyper  r  r  s           r  is_futures_methodzkucoin.is_futures_methodp  s     ((z=RYZ((E6FG><++-.D*S SVZV_V_`dVe eff66*z!Otx'7OTY=NOr  r   rN  c           	      `   | j                  |d      }|t        j                  |d      }| j                  |dd      }| j                  |d|      }| j                  |d      }| j	                  ||d      }|d   }| j                  |d      }| j                  |d	      }| j                  |g d
      }	| j                  i d|d|	d| j                  |	      d| j                  |d      d| j                  |d      d| j                  |dd      d| j                  |d      d| j                  |dd      d| j                  |d      dd d| j                  |d      d|d|dd d| j                  |d      d|d | j                  |d!      ||| j                  |d"      |d#|      S )$N
changeRate100lastlastTradedPricer  r	  r  volvolValue)timedatetime	timePointr   r  highlowbidbuybestBid	bidVolumebestBidSizeasksellbestAsk	askVolumebestAskSizevwapr  closepreviousClosechangechangePricer  averageaveragePricevalue)
baseVolumequoteVolume	markPricer  )r  r0   r:  r  safe_marketsafe_integer_nsafe_tickeriso8601)
r  r   rN  r  r  marketIdr	  r  r  r   s
             r  parse_tickerzkucoin.parse_ticker  sF   p %%fl;
! ++J>J!!&&2CD6##FH5!!(FC8!%%fe4
&&vz:''0QR	 !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4%%feY?!
 ))&-@!
 4%%ffi@!
 ))&-@!
 D!
 D$$VV4!
 T!
 D!
 T!
 d&&v}=!
  *!!
" t''?#!
$ %&))&':+!
, - 	r  r   c                    | j                          | j                  |      }| j                  |      }| j                  |di       }| j	                  |dg       }| j                  |d      }i }t        dt        |            D ]8  }|||   d<   | j                  ||         }	| j                  |	d      }
|
4|	||
<   : | j                  |d|      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://docs.kucoin.com/#get-all-tickers

        :param str[]|None symbols: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r  r   r  r   r	  )r  market_symbolsr2  r  r4  r  r6  r7  r  r  filter_by_array_tickers)r  r   r  r  r  tickersr  rL  rM  r   r	  s              r  fetch_tickerszkucoin.fetch_tickers  s     	%%g.11&9: ~~h3..x4  v.q#g,' 	(A!%GAJv&&wqz2F%%fh7F!!'v	( ++FHgFFr  c                     | j                          | j                  |      }| j                  |      }| j                  |dg       }| j	                  |      S )a  
        fetches the mark price for multiple markets

        https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-all-margin-trading-pairs-mark-prices

        :param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
        r  )r  r  publicGetMarkPriceAllSymbolsr4  parse_tickers)r  r   r  r  r  s        r  fetch_mark_priceszkucoin.fetch_mark_prices  sS     	%%g.44V<~~h3!!$''r  r	  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| 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://docs.kucoin.com/#get-24hr-stats

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r	  r5   r  )r  rN  publicGetMarketStatsr  r  r  r  r	  r  rN  r  r  r  s          r  fetch_tickerzkucoin.fetch_ticker!  sr     	V$fTl
 ,,T[[&-IJ0 ~~h3  v..r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )a  
        fetches the mark price for a specific market

        https://www.kucoin.com/docs/rest/margin-trading/margin-info/get-mark-price

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
        r	  r5   r  )r  rN  publicGetMarkPriceSymbolCurrentr  r  r  r  s          r  fetch_mark_pricezkucoin.fetch_mark_priceK  sp     	V$fTl
 77GV8TU~~h3  v..r  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r   r   r   r   r   )safe_timestampr;  )r  ohlcvrN  s      r  parse_ohlcvzkucoin.parse_ohlcv_  sn     q)UA&UA&UA&UA&UA&
 	
r  r   sincer  c           	      ~   | j                          d}| j                  |dd      \  }}|r| j                  d|||||d      S | j                  |      }|d   }|| j	                  | j
                  ||      d}	| j                  |      dz  }
| j                         }|h| j                  t        t        j                  |dz                    |	d<   || j                  | j                  d	d      }| j                  |||
z        }n=|;|||
z  z
  }| j                  t        t        j                  |dz                    |	d<   | j                  t        t        j                  |dz                    |	d
<   | j                  | j!                  |	|            }| j#                  |dg       }| j%                  |||||      S )aq  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://docs.kucoin.com/#get-klines

        :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
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Fr|   paginater  r5   )r	  r    startAtfetchOHLCVLimitendAtr  )r  r+  "fetch_paginated_call_deterministicrN  r  r   parse_timeframer  parse_to_intintmathfloorr  r  sumpublicGetMarketCandlesr  r4  parse_ohlcvs)r  r	  	timeframer  r  r  r  rN  r  r  durationr  r  r  s                 r  fetch_ohlcvzkucoin.fetch_ohlcvt  s    	88zZ&::<QVX]_hjprvwwV$$<$$T__iK
 ''	2T9!!#!%!2!23tzz%$,7O3P!QGI}
 ))$,,8I4PHHUEH$45EEH,,E!%!2!23tzz%$,7O3P!QGI,,SEDL1I-JK..t{{7F/KL ~~h3  vy%GGr  c                 6   | j                          | j                  |      }d|d   i}d}| j                  |      \  }}|| j                  |      |d<   | j	                  | j                  ||            }| j                  |di       }| j                  ||      S )a  

        https://www.kucoin.com/docs/rest/funding/deposit/create-deposit-address-v3-

        create a currency deposit address
        :param str code: unified currency code of the currency for the deposit address
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the blockchain network name
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r\  r5   Nrx  r  )r  r\  r  r  privatePostDepositAddressCreater  r  parse_deposit_addressr  s           r  create_deposit_addresszkucoin.create_deposit_address  s     	==&
 "AA&IV"#66{CGG77GV8TU  ~~h3))$99r  c                    | j                          | j                  |      }d|d   i}d}| j                  |      \  }}|"| j                  |      j	                         |d<   | j
                  d   d   d   d   }d	| j
                  d   d   d   d<   | j                  | j                  ||            }|| j
                  d   d   d   d<   | j                  |d
      }|t        | j                  dz         | j                  ||      S )a  
        fetch the deposit address for a currency associated with self account

        https://docs.kucoin.com/#get-deposit-addresses-v2

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.network]: the blockchain network name
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r\  r5   Nrx  r  r   r  r   r  r  zr fetchDepositAddress() returned an empty response, you might try to run createDepositAddress() first and try again)r  r\  r  r  r  r  privateGetDepositAddressesr  
safe_valuer   r5   r  )	r  rj  r  r\  r  ry  r<   r  r  s	            r  fetch_deposit_addresszkucoin.fetch_deposit_address  s0    	==&
 "AA&IV"#66{CIIKGG,,z*95e<=PQJNZ +E23FG224;;w3OP KRZ +E23FGx0<  +_  !_  `  `))$99r  c                    | j                  |d      }||j                  dd      }d }|*| j                  |d         }|dk7  r| j                  |       ||| j	                  | j                  |d            || j                  |d      dS )	Naddresszbitcoincash: r5   NIMr_  memo)r  r\  networkr  tag)r  replacer9  check_addressrq  )r  depositAddressr\  r  rj  s        r  r  zkucoin.parse_deposit_address  s    "">9=oonb9G**8D>:Du}""7+"..t/?/?PY/Z[##NF;
 	
r  c                    | j                          | j                  |      }d|d   i}| j                  d   d   d   d   }d| j                  d   d   d   d<   | j                  | j	                  ||            }|| j                  d   d   d   d<   | j                  |dg       }| j                  ||d	   gd
d|d	   i      }| j                  |d      S )a  

        https://docs.kucoin.com/#get-deposit-addresses-v2

        fetch the deposit address for a currency associated with self account
        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an array of `address structures <https://docs.ccxt.com/#/?id=address-structure>`
        r\  r5   r  r   r  r   r=   r  rj  Fr  )r  r\  r  r  r  r4  parse_deposit_addressesr5  )	r  rj  r  r\  r  r<   r  r^  parseds	            r  "fetch_deposit_addresses_by_networkz)kucoin.fetch_deposit_addresses_by_network  s     	==&
 ,,z*95e<=PQJNZ +E23FG224;;w3OP  KRZ +E23FG&"5--fx7G6H%(R
  }}VY//r  c           
      ^   | j                          | j                  |      }| j                  |dd      }d|d   i}| j                  d      }d}|r|_|dk(  r8||d<   |(|dk(  s|dk(  r||d	<   nt	        | j
                  d
z         |r|nd|d	<   | j                  | j                  ||            }n!| j                  | j                  ||            }| j                  |di       }	| j                  |	d      }
| j                  |	|d   |
dd|dz
  |dz
        }| j                  |	d      |d<   |S )a  
        fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

        https://www.kucoin.com/docs/rest/spot-trading/market-data/get-part-order-book-aggregated-
        https://www.kucoin.com/docs/rest/spot-trading/market-data/get-full-order-book-aggregated-

        :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
        levelr   r	  r5   FNr   d   r  z2 fetchOrderBook() limit argument must be 20 or 100r  r  bidsasksr   sequencer  )r  rN  r  r.  r   r5   'publicGetMarketOrderbookLevelLevelLimitr  privateGetMarketOrderbookLevel2r  parse_order_book)r  r	  r  r  rN  r  r  isAuthenticatedr  r  r   	orderbooks               r  fetch_order_bookzkucoin.fetch_order_book.  s[    	V$!!&'15!6$<099%@%"3z#( $#+0(+DGG6j,jkk,15s CCDKKPWY_D`aH;;DKKQW<XYH@ ~~h3%%dF3	))$x0@)VU[]bef]fhmpqhqr	!..tZ@	'r  c                     | j                  |dd      }| j                  |d      }| j                  |d      }|d u}|d u}|r|s|r|s|r|rt        | j                  dz         |||gS )Nr  	stopPricer  r  zW createOrder() - you should use either triggerPrice or stopLossPrice or takeProfitPrice)safe_value_2r  r   r5   )r  r  r  r  r  
isStopLossisTakeProfits          r  handle_trigger_priceszkucoin.handle_trigger_pricesq  s    ((M@//&2CD"$.
&d2<\mQ]bn  +D  !D  E  Em_==r  r  sider  r  c                 `   | j                          | j                  |      }| j                  |dd      }| j                  |d      }d}	| j	                  |      \  }	}d}
| j                  |ddd      \  }
}| j                  |      \  }}}| j                  |d      }|xs |xs |}| j                  d|      }| j                  |d      }|dk(  xs |du}| j                  ||||||      }d}|r:|r| j                  |      }n|	r| j                  |      }ns| j                  |      }na|r| j                  |      }nM|r| j                  |      }n9|
r| j                  |      }n%|	r| j!                  |      }n| j#                  |      }| j%                  |d	i       }| j'                  ||      S )
a  
        Create an order on the exchange

        https://docs.kucoin.com/spot#place-a-new-order
        https://docs.kucoin.com/spot#place-a-new-order-2
        https://docs.kucoin.com/spot#place-a-margin-order
        https://docs.kucoin.com/spot-hf/#place-hf-order
        https://www.kucoin.com/docs/rest/spot-trading/orders/place-order-test
        https://www.kucoin.com/docs/rest/margin-trading/orders/place-margin-order-test
        https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/sync-place-hf-order

        :param str symbol: Unified CCXT market symbol
        :param str type: 'limit' or 'market'
        :param str side: 'buy' or 'sell'
        :param float amount: the amount of currency to trade
        :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
        :param float [params.triggerPrice]: The price at which a trigger order is triggered at
        :param str [params.marginMode]: 'cross',  # cross(cross mode) and isolated(isolated mode), set to cross by default, the isolated mode will be released soon, stay tuned
        :param str [params.timeInForce]: GTC, GTT, IOC, or FOK, default is GTC, limit orders only
        :param str [params.postOnly]: Post only flag, invalid when timeInForce is IOC or FOK

 EXCHANGE SPECIFIC PARAMETERS
        :param str [params.clientOid]: client order id, defaults to uuid if not passed
        :param str [params.remark]: remark for the order, length cannot exceed 100 utf8 characters
        :param str [params.tradeType]: 'TRADE',  # TRADE, MARGIN_TRADE  # not used with margin orders
 limit orders ---------------------------------------------------
        :param float [params.cancelAfter]: long,  # cancel after n seconds, requires timeInForce to be GTT
        :param bool [params.hidden]: False,  # Order will not be displayed in the order book
        :param bool [params.iceberg]: False,  # Only a portion of the order is displayed in the order book
        :param str [params.visibleSize]: self.amount_to_precision(symbol, visibleSize),  # The maximum visible size of an iceberg order
 market orders --------------------------------------------------
        :param str [params.funds]:  # Amount of quote currency to use
 stop orders ----------------------------------------------------
        :param str [params.stop]:  Either loss or entry, the default is loss. Requires triggerPrice to be defined
 margin orders --------------------------------------------------
        :param float [params.leverage]: Leverage size of the order
        :param str [params.stp]: '',  # self trade prevention, CN, CO, CB or DC
        :param bool [params.autoBorrow]: False,  # The system will first borrow you funds at the optimal interest rate and then place an order for you
        :param bool [params.hf]: False,  # True for hf order
        :param bool [params.test]: set to True to test an order, no order will be created but the request will be validated
        :param bool [params.sync]: set to True to use the hf sync call
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        testFNrS   sync	tradeTyper   r  r  )r  rN  r/  rW  rZ  r+  r  r  handle_margin_mode_and_paramscreate_order_requestprivatePostMarginOrderTestprivatePostHfOrdersTestprivatePostOrdersTestprivatePostStopOrderprivatePostMarginOrderprivatePostHfOrdersSyncprivatePostHfOrdersprivatePostOrdersr  parse_order)r  r	  r  r  r  r  r  rN  	testOrderr  useSyncr  r  r  r  isTriggerOrdermarginResultr  isMarginOrderorderRequestr  r  s                         r  create_orderzkucoin.create_order{  s   Z 	V$NN6659	66*..v6
F77vW\]7;7Q7QRX7Y4m_$$V[9	&J-J?99-P%%lA6
!^3Mz7M00tVUTZ[::<H77E55lC00>H22<@H33LAH//=H--l;H ~~h3f--r  r"  c                 v    | j                          d|i}| j                  |d||d| j                  ||            S )a  
        create a market order by providing the symbol, side and cost

        https://www.kucoin.com/docs/rest/spot-trading/orders/place-order

        :param str symbol: unified symbol of the market to create an order in
        :param str side: 'buy' or 'sell'
        :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>`
        r"  rN  N)r  r.  r  )r  r	  r  r"  r  reqs         r  create_market_order_with_costz$kucoin.create_market_order_with_cost  sF     	D
   4tT[[QTV\E]^^r  c                 J    | j                          | j                  |d||      S )a  
        create a market buy order by providing the symbol and cost

        https://www.kucoin.com/docs/rest/spot-trading/orders/place-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>`
        r  r  r1  r  r	  r"  r  s       r  !create_market_buy_order_with_costz(kucoin.create_market_buy_order_with_cost  s'     	11&%vNNr  c                 J    | j                          | j                  |d||      S )a  
        create a market sell order by providing the symbol and cost

        https://www.kucoin.com/docs/rest/spot-trading/orders/place-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>`
        r  r3  r4  s       r  "create_market_sell_order_with_costz)kucoin.create_market_sell_order_with_cost  s'     	11&&$OOr  r   c           	         | j                          g }d}t        dt        |            D ]  }||   }| j                  |d      }||}n||k7  rt	        | j
                  dz         | j                  |d      }|dk7  rt	        | j
                  dz         | j                  |d      }	| j                  |d	      }
| j                  |d
      }| j                  |di       }| j                  |||	|
||      }|j                  |        | j                  |      }|d   |d}d}| j                  |      \  }}d}| j                  |ddd      \  }}d}|r"| j                  | j                  ||            }nE|r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j!                  |di       }| j#                  |dg       }| j%                  |      S )aA  
        create a list of trade orders

        https://www.kucoin.com/docs/rest/spot-trading/orders/place-multiple-orders
        https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/place-multiple-hf-orders
        https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/sync-place-multiple-hf-orders

        :param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
        :param dict [params]:  extra parameters specific to the exchange API endpoint
        :param bool [params.hf]: False,  # True for hf orders
        :param bool [params.sync]: False,  # True to use the hf sync call
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        Nr   r	  z; createOrders() requires all orders to have the same symbolr  r  z* createOrders() only supports limit ordersr  r  r  r  r5   )r	  	orderListFrT   r  r  )r  r6  r7  r  r$   r5   r  r  r,  rN  rZ  r+  privatePostHfOrdersMultiSyncr  privatePostHfOrdersMultiprivatePostOrdersMultir  r4  parse_orders)r  r   r  ordersRequestsr	  rM  rawOrderr  r  r  r  r  orderParamsr-  rN  r  r  r)  r  r  s                       r  create_orderszkucoin.create_orders	  s    	q#f+& 	0AayH''(;H~!X%$TWW/l%lmm##Hf5Dw +W!WXX##Hf5D__Xx8FOOHg6E//(HbAK44XtT6SXZefL!!,/!	0" V$Tl'
 ..v6
F77PVX]^88Wf9UVH44T[[&5QRH224;;w3OPH> ~~h3~~dFB/  &&r  c                 
   | j                  |      }| j                  |t        |d   d   | j                  | j                        }|dk(  r9t        | j                  dz   |d   z   dz   | j                  |d   d         z         |S )	Nr  quoteIncrementrx  z amount of r	  z2 must be greater than minimum amount precision of r(  r  )rN  decimal_to_precisionr.   r  paddingModer(   r5   number_to_string)r  r	  r  rN  rL  s        r   market_order_amount_to_precisionz'kucoin.market_order_amount_to_precisionW	  s    V$**68VF^L\=]_c_q_qsw  tD  tD  ES=tww69II  MA   A  DH  DY  DY  Z`  al  Zm  nv  Zw  Dx   x  y  yr  c                 d   | j                  |      }| j                  |dd| j                               }| j                  |ddg      }|||d   |d}	| j	                  |dd      }
d }d }d }| j                  d|      \  }}|dk(  rV|
,| j                  |ddg      }| j                  ||
      }||	d<   nT| j                  ||      }| j                  ||      |	d	<   n,| j                  ||      }||	d	<   | j                  ||      |	d
<   | j                  |d      }| j                  |      \  }}}|xs |xs |}|dk(  xs |d u}| j                  |g d      }|r|r| j                  ||      |	d<   nI|s|rE|r"|dk(  rdnd|	d<   | j                  ||      |	d<   n!|dk(  rdnd|	d<   | j                  ||      |	d<   |dk(  rt        | j                  dz         |dk(  r"| j                  d   |   |	d<   n|r
|dk(  rd|	d<   d }| j                  |dk(  d|      \  }}|rd|	d<   | j                  |	|      S )N	clientOidclientOrderIdr5   )rI  r  r	  r  r"  fundsrS   rN  sizer  r  r  )r  r  r  r  r  r  rt  lossstopr  z= createOrder does not support isolated margin for stop ordersr  r  marginModelFTpostOnly)rN  r  uuidrW  safe_number_2r  rG  amount_to_precisionprice_to_precisionr  r  r$   r5   r  handle_post_onlyr  )r  r	  r  r  r  r  r  rN  rJ  r  quoteAmountamountString
costStringr  r  r  r  r  r*  r,  rP  s                        r  r  zkucoin.create_order_request^	  s   V$**6;QUQZQZQ\]6K#AB&Tl	
 ((A

!??vV
F8&6FG+<=!BB6;W
#- #77G"&":":66"J33FFCL*GFO#66vuEGG$$V[9	7;7Q7QRX7Y4m_&J-J?!^3Mz7M6#de'+'>'>v|'T$/ 26%-gfGFO+/+B+B6=+YGK(15fWGFO+/+B+B6?+[GK(Z' +j!jkkw&'+||M'B:'N$Z')3&001A5&Q&"&GJ{{7F++r  r5   c                 z   | j                          | j                  |      }d|d   i}	| j                  |dd      }
|
|
|	d<   n||	d<   || j                  ||      |	d<   || j	                  ||      |	d<   | j                  | j                  |	|            }| j                  |di       }| j                  ||      S )	a=  
        edit an order, kucoin currently only supports the modification of HF orders

        https://docs.kucoin.com/spot-hf/#modify-order

        :param str id: order id
        :param str symbol: unified symbol of the market to create an order in
        :param str type: not used
        :param str side: not used
        :param float amount: how much of the currency you want to trade in units of the 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
        :param str [params.clientOrderId]: client order id, defaults to id if not passed
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        r	  r5   rI  rJ  orderIdnewSizenewPricer  )	r  rN  r  rS  rT  privatePostHfOrdersAlterr  r  r'  )r  r5   r	  r  r  r  r  r  rN  r  rJ  r  r  s                r  
edit_orderzkucoin.edit_order	  s      	V$fTl
 **6;P$#0GK !#GI!%!9!9&&!IGI"&"9"9&%"HGJ00Wf1MN ~~h3f--r  c                    | j                          i }| j                  |dd      }| j                  |ddd      }d}| j                  |      \  }}d}| j	                  |ddd      \  }}|s|r3|t        | j                  d	z         | j                  |      }	|	d
   |d<   d}
| j                  |g d      }|||d<   |r"| j                  | j                  ||            }
ni|r"| j                  | j                  ||            }
nE|r"| j                  | j                  ||            }
n!| j                  | j                  ||            }
| j                  |
d      }
| j                  |
      S ||d<   |r"| j!                  | j                  ||            }
n|r"| j#                  | j                  ||            }
ng|rD| j%                  | j                  ||            }
| j                  |
d      }
| j                  |
      S | j'                  | j                  ||            }
| j                  |
d      }| j)                  |dg       }| j+                  |d      }| j-                  ||d      S )aG  
        cancels an open order

        https://docs.kucoin.com/spot#cancel-an-order
        https://docs.kucoin.com/spot#cancel-an-order-2
        https://docs.kucoin.com/spot#cancel-single-order-by-clientoid
        https://docs.kucoin.com/spot#cancel-single-order-by-clientoid-2
        https://docs.kucoin.com/spot-hf/#cancel-orders-by-orderid
        https://docs.kucoin.com/spot-hf/#cancel-order-by-clientoid
        https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/sync-cancel-hf-order-by-orderid
        https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/sync-cancel-hf-order-by-clientoid

        :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
        :param bool [params.trigger]: True if cancelling a stop order
        :param bool [params.hf]: False,  # True for hf order
        :param bool [params.sync]: False,  # True to use the hf sync call
        :returns: Response from the exchange
        rI  rJ  rN  r  FNrL   r  z8 cancelOrder() requires a symbol parameter for hf ordersr5   r	  )rI  rJ  rN  r  r  rZ  cancelledOrderIdsr   )r  r5   )r  r  safe_bool_2rZ  r+  r#   r5   rN  rW  ,privateDeleteStopOrderCancelOrderByClientOidr  -privateDeleteHfOrdersSyncClientOrderClientOid)privateDeleteHfOrdersClientOrderClientOid&privateDeleteOrderClientOrderClientOidr  r'  privateDeleteStopOrderOrderId privateDeleteHfOrdersSyncOrderIdprivateDeleteHfOrdersOrderIdprivateDeleteOrdersOrderIdr4  r  
safe_order)r  r5   r	  r  r  rJ  r  r  r)  rN  r  r  orderIdsrZ  s                 r  cancel_orderzkucoin.cancel_order	  sx   * 	**6;P""669eD..v6
F77vW\]~'2l(lmm[[(F &tGH6#TU$#0GK LLT[[Y`bhMij MMdkkZaciNjkII$++V]_eJfg  FFt{{SZ\bGcd ~~h7H##H--!#GI==dkk'SY>Z[ @@WV\A]^<<T[[RX=YZ  >>(F;''11::4;;wPV;WX >>(F3D~~d,?DH&&x3G??$  r  c                    | j                          i }| j                  |dd      }d}| j                  |      \  }}| j                  |d      }| j	                  d|      \  }}|| j                  |      |d<   |4| j                  d   |   |d<   |dk(  r|rt        | j                  d	z         d}|r#| j                  | j                  ||            }|S |rH|#| j                  | j                  ||            }|S | j                  | j                  ||            }|S | j                  | j                  ||            }|S )
a  
        cancel all open orders

        https://docs.kucoin.com/spot#cancel-all-orders
        https://docs.kucoin.com/spot#cancel-orders
        https://docs.kucoin.com/spot-hf/#cancel-all-hf-orders-by-symbol

        :param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param bool [params.trigger]: *invalid for isolated margin* True if cancelling all stop orders
        :param str [params.marginMode]: 'cross' or 'isolated'
        :param str [params.orderIds]: *stop orders only* Comma seperated order IDs
        :param bool [params.hf]: False,  # True for hf order
        :returns: Response from the exchange
        rN  FNrK   r	  r  r  r  zA cancelAllOrders does not support isolated margin for stop orders)r  r/  rZ  rW  r  	market_idr  r$   r5   privateDeleteStopOrderCancelr  privateDeleteHfOrdersCancelAllprivateDeleteHfOrdersprivateDeleteOrders)	r  r	  r  r  r  r  r  queryr  s	            r  cancel_all_orderszkucoin.cancel_all_orders4
  s\     	..7..v6
F66* >>?PRXY
E $v 6GH!#'<<#>z#JGK Z'G +n!noo88We9TUH  ~>>t{{7TY?Z[
   55dkk'56QR  //GU0KLHr  c                    | j                          |j                         }| j                  |d      }| j                  |ddd      }d}	| j	                  |      \  }	}|	r|t        | j                  dz         | j                  |g d      }| j                  d|      \  }
}|d	k(  rd
}n|dk(  rd}d|i}d}|| j                  |      }|d   |d<   |||d<   |||d<   |r||d<   | j                  | j                  d   |
d      |d<   d}|r"| j                  | j                  ||            }nq|	rN|d
k(  r"| j                  | j                  ||            }nH|dk(  rC| j                  | j                  ||            }n!| j!                  | j                  ||            }| j#                  |d      }|| j%                  ||||      S | j'                  |di       }| j#                  |dg       }| j%                  ||||      S )a  
        fetch a list of orders

        https://docs.kucoin.com/spot#list-orders
        https://docs.kucoin.com/spot#list-stop-orders
        https://docs.kucoin.com/spot-hf/#obtain-list-of-active-hf-orders
        https://docs.kucoin.com/spot-hf/#obtain-list-of-filled-hf-orders

        :param str status: *not used for stop orders* 'open' or 'closed'
        :param str symbol: unified market symbol
        :param int [since]: timestamp in ms of the earliest order
        :param int [limit]: max number of orders to return
        :param dict [params]: exchange specific params
        :param int [params.until]: end time in ms
        :param str [params.side]: buy or sell
        :param str [params.type]: limit, market, limit_stop or market_stop
        :param str [params.tradeType]: TRADE for spot trading, MARGIN_TRADE for Margin Trading
        :param int [params.currentPage]: *trigger orders only* current page
        :param str [params.orderIds]: *trigger orders only* comma seperated order ID list
        :param bool [params.trigger]: True if fetching a trigger order
        :param bool [params.hf]: False,  # True for hf order
        :returns: An `array of order structures <https://docs.ccxt.com/#/?id=order-structure>`
        untilrN  r  FNz@ fetchOrdersByStatus() requires a symbol parameter for hf orders)rN  r  tillrv  r   r  r  closeddoner   r5   r	  r  pageSizer  r  r  r  r  r  )r  r  r  ra  rZ  r#   r5   rW  r  rN  r  r  privateGetStopOrderr  privateGetHfOrdersActiveprivateGetHfOrdersDoneprivateGetOrdersr4  r=  r  )r  r   r	  r  r  r  lowercaseStatusrv  r  r  r  rs  r  rN  r  listDataresponseDatar   s                     r  fetch_orders_by_statuszkucoin.fetch_orders_by_status]
  s3   0 	 ,,.!!&'2""669eD..v6
F6>#DGG.p$pqq6#GH >>?TV\]
Ef$&O($Oo
 [[(F &tGH!&GI"'GJ$GG#//]0KZY`a//GU0KLH(*88We9TU F*66t{{7E7RS,,T[[%-HIHX >>(F3$$XvueDD~~h;gr:  >>r  c                     | j                          d}| j                  |dd      \  }}|r| j                  d||||      S | j                  d||||      S )ao  
        fetches information on multiple closed orders made by the user

        https://docs.kucoin.com/spot#list-orders
        https://docs.kucoin.com/spot#list-stop-orders
        https://docs.kucoin.com/spot-hf/#obtain-list-of-active-hf-orders
        https://docs.kucoin.com/spot-hf/#obtain-list-of-filled-hf-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
        :param int [params.until]: end time in ms
        :param str [params.side]: buy or sell
        :param str [params.type]: limit, market, limit_stop or market_stop
        :param str [params.tradeType]: TRADE for spot trading, MARGIN_TRADE for Margin Trading
        :param bool [params.trigger]: True if fetching a trigger order
        :param bool [params.hf]: False,  # True for hf order
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Fr`   r  ry  r  r+  fetch_paginated_call_dynamicr  r  r	  r  r  r  r  s         r  fetch_closed_orderszkucoin.fetch_closed_orders
  si    , 	88ATV`a&445H&RWY^`fgg**665%PPr  c                     | j                          d}| j                  |dd      \  }}|r| j                  d||||      S | j                  d||||      S )a  
        fetch all unfilled currently open orders

        https://docs.kucoin.com/spot#list-orders
        https://docs.kucoin.com/spot#list-stop-orders
        https://docs.kucoin.com/spot-hf/#obtain-list-of-active-hf-orders
        https://docs.kucoin.com/spot-hf/#obtain-list-of-filled-hf-orders

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch open orders for
        :param int [limit]: the maximum number of  open orders structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: end time in ms
        :param bool [params.trigger]: True if fetching trigger orders
        :param str [params.side]: buy or sell
        :param str [params.type]: limit, market, limit_stop or market_stop
        :param str [params.tradeType]: TRADE for spot trading, MARGIN_TRADE for Margin Trading
        :param int [params.currentPage]: *trigger orders only* current page
        :param str [params.orderIds]: *trigger orders only* comma seperated order ID list
        :param bool [params.hf]: False,  # True for hf order
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
        Fr   r  r  r  r  s         r  fetch_open_orderszkucoin.fetch_open_orders
  si    0 	88ART^_&445FPUW\^dee**8VUE6RRr  c                    | j                          i }| j                  |dd      }| j                  |ddd      }d}| j                  |      \  }}d}|| j	                  |      }|r"|t        | j                  dz         |d   |d	<   | j                  |g d
      }d}	|y||d<   |r,||d   |d	<   | j                  | j                  ||            }	n|r"| j                  | j                  ||            }	n| j                  | j                  ||            }	n|t        | j                  dz         ||d<   |r"| j                  | j                  ||            }	nE|r"| j                  | j                  ||            }	n!| j                  | j                  ||            }	| j!                  |	di       }
t#        |
t$              r| j'                  |
d      }
| j)                  |
|      S )a  
        fetch an order

        https://docs.kucoin.com/spot#get-an-order
        https://docs.kucoin.com/spot#get-single-active-order-by-clientoid
        https://docs.kucoin.com/spot#get-single-order-info
        https://docs.kucoin.com/spot#get-single-order-by-clientoid
        https://docs.kucoin.com/spot-hf/#details-of-a-single-hf-order
        https://docs.kucoin.com/spot-hf/#obtain-details-of-a-single-hf-order-using-clientoid

        :param str id: Order id
        :param str symbol: not sent to exchange except for trigger orders with clientOid, but used internally by CCXT to filter
        :param dict [params]: exchange specific parameters
        :param bool [params.trigger]: True if fetching a trigger order
        :param bool [params.hf]: False,  # True for hf order
        :param bool [params.clientOid]: unique order id created by users to identify their orders
        :returns: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        rI  rJ  rN  r  FNz7 fetchOrder() requires a symbol parameter for hf ordersr5   r	  )rN  rI  rJ  r  z" fetchOrder() requires an order idrZ  r  r   )r  r  ra  rZ  rN  r#   r5   rW  (privateGetStopOrderQueryOrderByClientOidr  &privateGetHfOrdersClientOrderClientOid#privateGetOrderClientOrderClientOidr(   privateGetStopOrderOrderIdprivateGetHfOrdersOrderIdprivateGetOrdersOrderIdr  
isinstancer  r  r'  )r  r5   r	  r  r  rJ  r  r  rN  r  r  s              r  fetch_orderzkucoin.fetch_order	  s   & 	**6;P""669eD..v6
F[[(F~'2k(kll &tGH6#TU$#0GK %(.tGH%HHU\^dIefFFt{{SZ\bGcdCCDKKPWY_D`a
 z"477-Q#QRR!#GI::4;;wPV;WX99$++gv:VW77GV8TU~~h;lD)??<;Lf55r  orderc           	          | j                  |d      }| j                  |d      }| j                  |d      }| j                  |dd      }| j                  |d      }|d u}| j                  |dd      }	| j                  |dd	      }
| j                  |d
      }d }|
	|
du rd}nd}|r|dk(  rd}n|
s|	sd}|rd}|dk(  rd}| j	                  i d|d| j                  |g d      d| j                  |d      d| j                  ||d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d | j                  |d!      d"| j                  |d#      d$| j                  |d%      d&d d'|d(| j                  |      d)| j                  |      | j                  |d)      d*|d | j                  |d+      d d,|      S )-Nr	  	createdAtfeeCurrencycancelExistFrN  stopTriggeredisActiver  r   Tr  rx  NEW	cancelledcanceledfailrejectedr  r5   )r5   rZ  
newOrderIdcancelledOrderIdrJ  rI  r  r  r  rP  r  r  rL  r  r  r  r"  	dealFundsfilleddealSize	remainingr   r  rk  )r\  r"  avgDealPrice)r   lastTradeTimestampr  trades)
r  r  r/  ra  rj  safe_string_nsafe_symbolr;  r  r9  )r  r  rN  r  r   feeCurrencyIdr  responseStopr  r  r  responseStatusr   s                r  r'  zkucoin.parse_orderG  s   t ##E84%%e[9	((>nnUM5A''v6d*uouE##E:x@))%:4!&m$FV#F  
E 
$$$U,_` 
 T--e[A 
 d&&x=	 

 D$$UF3 
 4++E=A 
 uj9 
 D$$UF3 
 d&&uf5 
 T%%eW5 
 D,,UK@ 
 D$$UK8 
 d&&uj9 
  
  
  Y/! 
"  33MB((6# 
* "&''~>1 
2 3 	r  c           	      R    d|i}| j                  |||| j                  ||            S )aA  
        fetch all the trades made from a single order

        https://docs.kucoin.com/#list-fills
        https://docs.kucoin.com/spot-hf/#transaction-details

        :param str id: order id
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        rZ  )fetch_my_tradesr  )r  r5   r	  r  r  r  r  s          r  fetch_order_tradeszkucoin.fetch_order_trades  s4     r
 ##FE5$++gv:VWWr  c                 8   | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}| j                  |      \  }}|r|t	        | j
                  dz         d}|| j                  |      }|d   |d<   | j                  d   }	d}
d}| j                  d	||      \  }}|r0|||d
<   |||d<   | j                  | j                  ||            }no|	dk(  r)|||d<   | j                  | j                  ||            }nA|	dk(  r$d}
| j                  | j                  ||            }nt        | j
                  dz         | j                  |di       }d}|
r|}n| j                  |dg       }| j!                  ||||      S )a  

        https://docs.kucoin.com/#list-fills
        https://docs.kucoin.com/spot-hf/#transaction-details

        fetch all trades made by the user
        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch trades for
        :param int [limit]: the maximum number of trades structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: the latest time in ms to fetch entries for
        :param bool [params.hf]: False,  # True for hf order
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
        Fr{   r  Nz: fetchMyTrades() requires a symbol parameter for hf ordersr5   r	  r  r  r  r  r  private_get_limit_fillsTz% fetchMyTradesMethod() invalid methodr  r  )r  r+  r  rZ  r#   r5   rN  r  handle_until_optionprivateGetHfFillsr  privateGetFillsprivateGetLimitFillsr   r  r4  parse_trades)r  r	  r  r  r  r  r  r  rN  methodparseResponseDatar  r  r  s                 r  r  zkucoin.fetch_my_trades  s     	88R\]&44_feUZ\bcc..v6
F&.#DGG.j$jkk[[(F &tGH34!227GVL #(  %*	"--dkk'6.JKH** %*	"++DKK,HIH00 !%00Wf1MNH*Q QRRR ~~h3F^^D'26F  >>r  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )a5  
        get the list of most recent trades for a particular symbol

        https://www.kucoin.com/docs/rest/spot-trading/market-data/get-trade-histories

        :param str symbol: unified symbol of the market to fetch trades for
        :param int [since]: timestamp in ms of the earliest trade to fetch
        :param int [limit]: the maximum amount of trades to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
        r	  r5   r  )r  rN  publicGetMarketHistoriesr  r4  r  )	r  r	  r  r  r  rN  r  r  r  s	            r  fetch_tradeszkucoin.fetch_tradeso  sv     	V$fTl
 00Wf1MN &"5  >>r  r  c                 2   | j                  |d      }| j                  ||d      }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }|| j	                  |dz        }n| j                  |d	      }d
|v r||dz  }| j                  |dd      }| j                  |dd      }	| j                  |d      }
d }| j                  |d      }|J| j                  |d      }| j                  |      }||
dk(  r|d   n|d   }||| j                  |d      d}| j                  |d      }|dk(  rd }| j                  |dd
      }| j                  ||||| j                  |      |d   |||
||	||d|      S )Nr	  r  tradeIdr5   rZ  	liquidityr  i@B r  	dealValuer  r  	dealPricerL  r  r  rk  r  r  r  r  feeRate)r"  r\  rater  matchrK  )r  r5   r  r   r  r	  r  takerOrMakerr  r  r  r"  rk  )r  r  r  r  r  r9  
safe_trader  )r  r  rN  r  r5   rZ  r  r   priceStringrW  r  rk  feeCostStringr  r  r  rX  s                    r  parse_tradezkucoin.parse_trade  s   Z ##E84!!(FC8y$7""5)4''{;%%eV4	 )))g*=>I))%=Iu$9+@%,	((E))%Bv.((6$ ,,UMBM11-@K"26&.fWovf~%'((	:C
 v.7?D''wD
"Y/X&( " 
  	r  c                 t   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      | j                  |d      ddd	S )
az  
        fetch the trading fees for a market

        https://www.kucoin.com/docs/rest/funding/trade-fee/trading-pair-actual-fee-spot-margin-trade_hf

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
        r   r5   r  r   r	  r
  r  T)r  r	  r  r  r  r  )	r  rN  privateGetTradeFeesr  r4  r  r  r  r;  )	r  r	  r  rN  r  r  r  firstr  s	            r  fetch_trading_feezkucoin.fetch_trading_fee  s     	V$vd|
 ++DKK,HI ~~h3tQ'##E84&&x8%%e^<%%e^<
 	
r  r  c                 .   | j                  ||      \  }}| j                          | j                  |       | j                  |      }|d   |dd}|||d<   d}| j	                  |      \  }}|"| j                  |      j                         |d<   t        | j                  |||            |d<   d}	| j                  |dd	d
      \  }	}|	rd|d<   | j                  | j                  ||            }
| j                  |
di       }| j                  ||      S )a  
        make a withdrawal

        https://www.kucoin.com/docs/rest/funding/withdrawals/apply-withdraw-v3-

        :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>`
        r5   ADDRESS)r\  	toAddresswithdrawTypeNr  rx  r  r   r  FINTERNALfeeDeductTyper  )handle_withdraw_tag_and_paramsr  r   r\  r  r  r  floatcurrency_to_precisionr+  privatePostWithdrawalsr  r  parse_transaction)r  rj  r  r  r  r  r\  r  ry  r  r  r  s               r  r   zkucoin.withdraw>  s2    99#vFV7#==&  %
 ?!GFO"AA&IV"#66{CIIKGG!$"<"<T6;"WX
!::6:|]bc
F'1GO$..t{{7F/KL ~~h3%%dH55r  r   c                 6    ddddd}| j                  |||      S )Nr  pendingfailed)SUCCESS
PROCESSINGWALLET_PROCESSINGFAILUREr  r  r   statusess      r  parse_transaction_statuszkucoin.parse_transaction_statusq  s,    #!*	
 &&99r  transactionc                 (   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }| j                  |d      }|>|j                  d      }t        |      }	|	dkD  r|t        |d         dkD  r|d   }|d   }|dnd	}
| j                  |d
      }d }| j                  |d      }|>d }|t	        j
                  ||      }| j                  |      | j                  |      |d}| j                  |dd      }| j                  |d      }d|v}|rd|v rdnd	}
||dz  }||dz  }| j                  |d      }| j                  |d      }i d|d| j                  |dd      d|d| j                  |      d| j                  | j                  |d            d|d|dd d|d|dd d|d| j                  |      d|d |
d
| j                  |      d!| j                  |d"      |||d#S )$Nr\  r  r  
walletTxId@r   r   
withdrawalr  r   rk  )r"  r  r\  r  createAt	updatedAtr  isInnerr  r  r5   withdrawalIdr   r  r  rx  	addressToaddressFromr  tagTotagFromtxidr  r@   remark)internalrk  r  )r  r9  r8  r7  r0   
string_divr  safe_integer_2r  r/  r  r  rq  r  )r  r  r\  r  rj  r  r  r  	txidPartsnumTxidPartsr  	rawStatusrk  feeCostr  r   r  isV1r  r  s                       r  r  zkucoin.parse_transactionz  s   V %%k:>
&&z8<"";	:!!+x8\:

3Iy>La?9Q<(1,"+A,Q<D $|9$$[(;	"";6D!))'6:))'2))$/ C
 ''[*M	##K=;.$-$<<9D$%,	"!D.>>+y9{F3
K
$$$[$G
 
 Y/	

 t..t/?/?W/UV
 w
 
 4
 3
 S
 t
 
 d''/
 D
 D
  d33I>!
" t''X>#
$ !)
 	
r  c                 F   | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}|| j                  |      }|d   |d<   |||d<   | j	                  d||      \  }}d}|>|d	k  r9| j                  |d
z        |d<   | j                  | j                  ||            }n(|||d<   | j                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
| j                  |
|||ddi      S )a  
        fetch all deposits made to an account

        https://www.kucoin.com/docs/rest/funding/deposit/get-deposit-list
        https://www.kucoin.com/docs/rest/funding/deposit/get-v1-historical-deposits-list

        :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
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Frg   r  Nr5   r\  rz  r      |{r  r  r  r  r  r  )r  r+  r  r\  r  r  privateGetHistDepositsr  privateGetDepositsr  r4  parse_transactionsr  rj  r  r  r  r  r  r\  r  r  r  s              r  fetch_depositszkucoin.fetch_deposits  sW    	88R\]&44_dESXZ`aa}}T*H"*4.GJ"'GJ227GVL!6!%!2!254<!@GI224;;w3OPH %*	"..t{{7F/KLHN ~~h3tWb1&&uhuvyFYZZr  c                 F   | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}|| j                  |      }|d   |d<   |||d<   | j	                  d||      \  }}d}|>|d	k  r9| j                  |d
z        |d<   | j                  | j                  ||            }n(|||d<   | j                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
| j                  |
|||ddi      S )a  
        fetch all withdrawals made from an account

        https://www.kucoin.com/docs/rest/funding/withdrawals/get-withdrawals-list
        https://www.kucoin.com/docs/rest/funding/withdrawals/get-v1-historical-withdrawals-list

        :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
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
        Fr   r  Nr5   r\  rz  r  r  r  r  r  r  r  r  )r  r+  r  r\  r  r  privateGetHistWithdrawalsr  privateGetWithdrawalsr  r4  r  r  s              r  fetch_withdrawalszkucoin.fetch_withdrawals1  sY    	88ASU_`&445GuV[]cdd}}T*H"*4.GJ"'GJ227GVL!6!%!2!254<!@GI55dkk'66RSH %*	"11$++gv2NOHP ~~h3tWb1&&uhuv|F\]]r  c                 $   | j                         }| j                  |dd      |d<   | j                  |dd      |d<   | j                  |dd      |d<   | j                  |d	      }| j                  |d
      }t        j                  ||      |d<   |S )NholdBalanceholdusedavailableBalance	availablefreetotalBalancetotal	liabilityinterestdebt)r  r  r  r0   
string_add)r  rt  r  r  r  s        r  parse_balance_helperzkucoin.parse_balance_helper  s    ,,.,,UM6J,,U4FT--e^WM{3##E:6!,,T8<r  c                    | j                          | j                  |d      }d}|| j                  |      }| j                  | j                  ddd      }| j                  |d|      }| j                  | j                  d      }| j                  |||      }| j                  |d      }d}| j                  |      \  }}|r|dk7  rd	}| j                  d|      \  }	}
d}i }|	d
k(  xs |d
k(  }|	dk(  xs |dk(  }|r,||d   |d<   | j                  | j                  ||
            }nT|r"| j                  | j                  ||
            }n0||d   |d<   ||d<   | j                  | j                  ||
            }d}|ddd}|r| j                  |di       }| j                  |d|      }t        dt        |            D ]  }||   }| j                  |d      }| j!                  |dd      }| j                  |di       }| j                  |di       }| j#                  | j                  |d            }| j#                  | j                  |d            }i }| j%                  |      ||<   | j%                  |      ||<   | j'                  |      ||<    n@|r}| j                  |di       }| j)                  |dg       }t        dt        |            D ]>  }||   }| j                  |d      }| j#                  |      }| j%                  |      ||<   @ n| j)                  |dg       }t        dt        |            D ]  }||   }| j                  |d      }||k(  s | j                  |d      }| j#                  |      } | j+                         }!| j                  |d      |!d<   | j                  |d      |!d<   | j                  |d      |!d<   |!|| <    |}"|s| j'                  |      }"|"S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://www.kucoin.com/docs/rest/account/basic-info/get-account-list-spot-margin-trade_hf
        https://www.kucoin.com/docs/rest/funding/funding-overview/get-account-detail-margin
        https://www.kucoin.com/docs/rest/funding/funding-overview/get-account-detail-isolated-margin

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.marginMode]: 'cross' or 'isolated', margin type for fetching margin balance
        :param dict [params.type]: extra parameters specific to the exchange API endpoint
        :param dict [params.hf]: *default if False* if True, the result includes the balance of the high frequency account
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        rj  Nr\   r  rD   r  r  r  r  r  r  rE   r5   balanceCurrencyr\  )r  r   r  r  assetsr   r	  _	baseAsset
quoteAssetr   balancer  r
  r  holdsr  )r  r  r\  r  r  r  rW  rZ  r  privateGetIsolatedAccountsr  privateGetMarginAccountr  r  r6  r7  r  r9  r  safe_balancer4  r  )#r  r  rj  r\  r  r  r  r  r  r  rs  r  r  r  r  r  rL  r  rM  rt  r  r	  r  r  baseCode	quoteCode	subResultr   r  r  	codeInnerbalanceType
codeInner2r  
returnTypes#                                      r  fetch_balancezkucoin.fetch_balance  s7    	/}}T*H((~}V\]((E6FG}M66*..v6
F46>D >>~vV
E*,E$*2Dw&=DH,<#-5d^)*66t{{7E7RSH33DKK4OPH#&.tn
#"GFO..t{{7E/JKH\ 

 >>(FB7D__T8T:F1c&k* >q	++E8<))(D#>~~e["=ulB?2243C3CD*3UV 33D4D4DUJ4WX	"$	&*&?&?&E	(#'+'@'@'G	)$!%!2!29!=v> >>(FB7D~~dJ;H1c(m, G"1+!--gzB
 33J?	$($=$=g$Fy!	G >>(FB7D1c$i( 
1q'"..w?$&!%!1!1':!FJ!%!8!8!DJ"llnG'+'7'7'KGG$&*&6&6w&LGFO&*&6&6w&HGFO)0F:&
1 
**62Jr  fromAccount	toAccountc                    | j                          | j                  |      }| j                  ||      }| j                  |      }| j                  |      }	| j	                  || j
                        }
| j	                  |	| j
                        }|dk(  r|	dk7  rt        | j                  dz         |d   |d}d|vr| j                         |d<   | j                  | j                  ||            }| j                  |d      }| j                  ||      S |d   |d}|
s|rF| j	                  || j
                        r||d<   d	}| j	                  |	| j
                        r|	|d
<   d	}	||d<   |	|d<   d|vr| j                         |d<   | j                  | j                  ||            }| j                  |d      }| j                  ||      S )a  
        transfer currency internally between wallets on the same account

        https://www.kucoin.com/docs/rest/funding/transfer/inner-transfer
        https://docs.kucoin.com/futures/#transfer-funds-to-kucoin-main-account-2
        https://docs.kucoin.com/spot-hf/#internal-funds-transfers-in-high-frequency-trading-accounts

        :param str code: unified currency code
        :param float amount: amount to transfer
        :param str fromAccount: account to transfer from
        :param str toAccount: account to transfer to
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
        r  r  zK transfer() only supports transferring from futures account to main accountr5   )r\  r  bizNor  fromTagr  toTagfromtorI  )r  r\  r  convert_type_to_accountin_arrayidsr   r5   uuid22futuresPrivatePostTransferOutr  r  parse_transferrQ   privatePostAccountsInnerTransfer)r  rj  r  r&  r'  r  r\  requestedAmountfromIdtoIdfromIsolated
toIsolatedr  r  r  s                  r  r   zkucoin.transfer3  s    	==&44T6B--k:++I6}}VTXX6]]42
Zv~#DGG.{${||$TN)G v%#';;= 99$++gv:VWH2 >>(F3D&&tX66 %TN)G z==2)/GI&'F==txx0'+GG$%D$GFO GDM6)'+yy{$<<T[[RX=YZH >>(F3D&&tX66r  r   c           
         | j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  | j                  d      }| j                  |||      }	| j                  |||      }
| j                  |dd      | j                  ||      || j                  |      | j                  |d	      |	|
| j                  |      |d
	S )Nr  r\  r   payAccountTyperecAccountTyper  applyIdrZ  r  )	r5   r\  r   r  r  r&  r'  r   r  )
r  r  safe_string_lowerr  r  r  r9  r  r;  parse_transfer_status)r  r   r\  r   r  r  accountFromRawaccountToRawr  accountFrom	accountTos              r  r3  zkucoin.parse_transfer  s    F %%h<	%%h
;
$$Xx8	//:JK--h8HI6FG&&~~~V$$^\<P	$$Xy)D//
HE"Y/&&x:&"00;

 
	
r  c                 0    ddi}| j                  |||      S )Nr  r  r  r  s      r  r?  zkucoin.parse_transfer_status  s%    )
 &&99r  c                     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}| j                  |||      S )Nz%Assets Transferred in After Upgradingr   Depositr  
WithdrawalTransferTrade_Exchanger  zKuCoin BonusbonuszReferral Bonusr   RewardszAirdrop/ForkairdropzOther rewardsz
Fee Rebaterebatez
Buy CryptozSell Cryptor  zPublic Offering PurchasezRefunded Feesrk  zKCS Pay FeeszMargin TradeLoans)rN  zInstant ExchangezSub-account transferzLiquidation Feesr  )r  r  typess      r  parse_ledger_entry_typezkucoin.parse_ledger_entry_type  s    (
3Z(
}(
 -(
 
	(

 g(
 G(
 j(
 w(
 I(
 W(
 ((
 '(
 6(
  '!(
. U/(
0 E1(
2 G3(
4  !($. %E(
R tT22r  itemc                    | j                  |d      }| j                  |d      }| j                  ||      }| j                  ||      }| j                  |d      }d }| j                  |d      }| j	                  |      }	| j                  |d      }
| j                  |d      }| j                  |      }| j                  |d      }| j                  |d      }d }|F|d	k7  rA	 t        j                  |      }| j                  |d
      }| j                  |d      }||}n|}d }| j                  |d      }d }|dk7  r|}| j                  |      |d}| j                  |||
||||	||||d |d |d|      S # t        $ r}|}Y d }~cd }~ww xY w)Nr5   r\  r  bizType	directionr  accountTypecontextr  rZ  r  rk  rx  )r"  r\  )r  r5   rT  r  referenceIdreferenceAccountr  r\  r  r   r  beforeafterr   rk  )r  r9  safe_currencyr;  rP  r  r  jsonloads	Exceptionr  safe_ledger_entry)r  rQ  r\  r5   r  rj  r  balanceAfterrS  r  rT  r   r  r  rV  rW  r  rZ  r  excrk  r  r  s                          r  parse_ledger_entryzkucoin.parse_ledger_entry  s    dD)%%dJ7
&&z8<%%j(;!!$1""43++G4$$T;7	%%dK8	<<	*""47""43 7b=
&G,**69=**69=&")K")K ""4/c>K,,W5;OC%%"& '" !'
  ! 	  &%&s   #A E6 6	F?FFc                 
   | j                          | j                          d}| j                  |dd      \  }}d}| j                  |      \  }}|r| j	                  d||||      S i }|||d<   d}|| j                  |      }|d   |d<   | j                  d||      \  }}d}	| j                  d|      \  }	}d}
|rF|	"| j                  | j                  ||            }
nC| j                  | j                  ||            }
n!| j                  | j                  ||            }
| j                  |
d	      }|| j                  ||||      S | j                  |
d	      }| j                  |d
g       }| j                  ||||      S )a  
        fetch the history of changes, actions done by the user or operations that altered the balance of the user

        https://www.kucoin.com/docs/rest/account/basic-info/get-account-ledgers-spot-margin
        https://www.kucoin.com/docs/rest/account/basic-info/get-account-ledgers-trade_hf
        https://www.kucoin.com/docs/rest/account/basic-info/get-account-ledgers-margin_hf

        :param str [code]: unified currency code, default is None
        :param int [since]: timestamp in ms of the earliest ledger entry, default is None
        :param int [limit]: max number of ledger entries to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.hf]: default False, when True will fetch ledger entries for the high frequency trading account
        :param int [params.until]: the latest time in ms to fetch entries for
        :param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
        :returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
        Frr   r  Nr  r5   r\  r  r  r  )r  load_accountsr+  rZ  r  r\  r  r   privateGetHfMarginAccountLedgersr  privateGetHfAccountsLedgersprivateGetAccountsLedgersr4  parse_ledgerr  )r  rj  r  r  r  r  r  r  r\  r  r  dataListr  r  s                 r  fetch_ledgerzkucoin.fetch_ledgerB  s   " 	88PZ[&..v6
F44]D%QVX^__
 !&GI}}T*H"*4.GJ227GVL
!??vV
F%@@WV\A]^;;DKKQW<XY55dkk'66RSHL >>(F3$$XxFF~~h/tWb1  %??r  c                 h   | j                  | j                  di       }| j                  ||i       }| j                  ||i       }| j                  ||| j                  d         }	| j                  |d|	      }
|
dk(  r	d|v r|d   S |
dk(  r	d|v r|d   S |
dk(  r	d|v r|d   S | j                  |dd      S )Nr  r<   r  r=   r  r"  r   )r  r  r  r  )r  r   r  pathr  configr  apiVersionsmethodVersionsdefaultVersionr<   s              r  calculate_rate_limiter_costz"kucoin.calculate_rate_limiter_cost  s    >>$,,
B?nnXsB7VR@)).$Y@WX""69nEd?$<_$&.$<_$&.$<vvq11r  c                     | j                  |dd      }| j                  |dd       }| j                  |d      }| j                  ||      | j	                  |dd      d|| j                  |      |d	S )
Nr  r   r      r\  dailyIntRatedayRatioi \&)r\  r  periodr   r  r  )r  r  r  r9  rR  r  )r  r  r\  timestampIdr   r  s         r  parse_borrow_ratezkucoin.parse_borrow_rate  s    $ (({KH%%k!B&78	%%dJ7
//
HE&&t^ZH"Y/
 	
r  c                 Z   | j                          d}| j                  d|d      \  }}i }d}|'| j                  |      }|dk(  r	|d   |d<   n|d   |d<   d}	|| j                  |      }	d}
|dk(  r"| j	                  | j                  ||            }
n!| j                  | j                  ||            }
| j                  |
di       }|dk(  r| j                  |d	g       n| j                  |d
g       }| j                  ||	      }| j                  ||||      }| j                  ||||      S )a  
        fetch the interest owed by the user for borrowing currency for margin trading

        https://docs.kucoin.com/#get-repay-record
        https://docs.kucoin.com/#query-isolated-margin-account-info

        :param str [code]: unified currency code
        :param str [symbol]: unified market symbol, required for isolated margin
        :param int [since]: the earliest time in ms to fetch borrrow interest for
        :param int [limit]: the maximum number of structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' default is 'cross'
        :returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
        Nr]   r  r  r5   r  quoteCurrencyr  r  r   )r  r  r\  rN  r  r  privateGetMarginAccountsr  r4  parse_borrow_interestsfilter_by_currency_since_limitfilter_by_symbol_since_limit)r  rj  r	  r  r  r  r  r  r\  rN  r  r  r  r  filteredByCurrencys                  r  fetch_borrow_interestzkucoin.fetch_borrow_interest  sW    	
!??@UW]_fg
F}}T*HZ'-5d^)*+3D>([[(F#66t{{7F7STH44T[[&5QRHB ~~h38Bj8Ph3W[WeWefjlvxzW{..vv>!@@4QVX]^001CVUTYZZr  r  c                 (   | j                  |d      }|dnd}| j                  ||      }| j                  |d      }| j                  |d      }| j                  |di       }d }d }	d }
|dk(  r7| j	                  |d      }| j	                  |d      }	| j                  |d      }
n6| j	                  |d      }| j	                  |d	      }	| j                  |d      }
||| j                  |
      |	| j	                  |d
      |||| j                  |      d	S )Nr	  r  r  r  r  r  r  r\  accruedInterestrt  )	r  r	  r\  r  interestRateamountBorrowedr  r   r  )r  r  r  r  r;  r9  r  )r  r  rN  r  r  r	  r   isolatedBaser  r  r  s              r  parse_borrow_interestzkucoin.parse_borrow_interest4  s5   Z ##D(3!)!1W

!!(F3!!&(3%%dK8	~~dK<
#!--lKHN''jAH)),
CJ!--dK@N''.?@H))$
;J//
;  ,,T>B,$"Y/

 
	
r  c                 z   | j                          | j                  d|      }| j                  |dd      }|dk(  }d|i}|||d<   | j                  d||      \  }}|||d<   | j	                  | j                  ||            }	| j                  |	d	      }
| j                  |
d
g       }| j                  ||||      S )a  
        retrieves a history of a multiple currencies borrow interest rate at specific time slots, returns all currencies if no symbols passed, default is None

        https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/get-cross-isolated-margin-interest-records

        :param str[]|None codes: list of unified currency codes, default is None
        :param int [since]: timestamp in ms of the earliest borrowRate, default is None
        :param int [limit]: max number of borrow rate prices to return, default is None
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' default is 'cross'
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns dict: a dictionary of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` indexed by the market symbol
        r^   r   r  r  
isIsolated	startTimeendTimerz  r  r  )	r  r  r  r  privateGetMarginInterestr  r  r4  parse_borrow_rate_histories)r  codesr  r  r  r+  r  r  r  r  r  rowss               r  fetch_borrow_rate_historiesz"kucoin.fetch_borrow_rate_histories~  s     	99:TV\]%%lAw?
 J.
*
 #(GK 229gvN"'GJ00Wf1MN* ~~h/~~dGR0//eUEJJr  c                    | j                          | j                  d|      }| j                  |dd      }|dk(  }| j                  |      }||d   d}	|||	d<   | j	                  d|	|      \  }	}|||	d	<   | j                  | j                  |	|            }
| j                  |
d
      }| j                  |dg       }| j                  ||||      S )a<  
        retrieves a history of a currencies borrow interest rate at specific time slots

        https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/get-cross-isolated-margin-interest-records

        :param str code: unified currency code
        :param int [since]: timestamp for the earliest borrow rate
        :param int [limit]: the maximum number of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.marginMode]: 'cross' or 'isolated' default is 'cross'
        :param int [params.until]: the latest time in ms to fetch entries for
        :returns dict[]: an array of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
        r^   r   r  r  r5   )r  r\  r  r  rz  r  r  )
r  r  r  r\  r  r  r  r  r4  parse_borrow_rate_history)r  rj  r  r  r  r+  r  r  r\  r  r  r  r  s                r  fetch_borrow_rate_historyz kucoin.fetch_borrow_rate_history  s     	99:TV\]%%lAw?
 J.
==&$ 
 #(GK 229gvN"'GJ00Wf1MN* ~~h/~~dGR0--dD%GGr  c                    i }t        dt        |            D ]m  }||   }| j                  | j                  |d            }|| j	                  ||      s>||vrg ||<   | j                  |      }	||   }
|
j                  |	       o t        |j                               }t        dt        |            D ]!  }||   }| j                  ||   |||      ||<   # |S )Nr   r\  )
r6  r7  r9  r  r/  rx  r,  r  r  r}  )r  r  r  r  r  borrowRateHistoriesrM  rQ  rj  borrowRateStructureborrowRateHistoriesCoder  s               r  r  z"kucoin.parse_borrow_rate_histories  s    %'q#h-( 	DAA;D**4+;+;D*+MND}dE : 3302'-&*&<&<T&B#*=d*C''../BC	D ',,./q#d)$ 	{A7D(,(K(KL_`dLegkmrty(z%	{ #"r  c                    | j                          | j                  |      }|d   | j                  ||      dd}| j                  | j	                  ||            }| j                  |di       }| j                  ||      S )a  
        create a loan to borrow margin

        https://docs.kucoin.com/#1-margin-borrowing

        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoints
        :param str [params.timeInForce]: either IOC or FOK
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r5   r  )r\  rL  r  r  )r  r\  r  privatePostMarginBorrowr  r  parse_margin_loanr  rj  r  r  r\  r  r  r  s           r  borrow_cross_marginzkucoin.borrow_cross_margin  s     	==& ..tV< 

 //GV0LM ~~h3%%dH55r  c                 .   | j                          | j                  |      }| j                  |      }|d   | j                  ||      |d   ddd}| j	                  | j                  ||            }| j                  |di       }	| j                  |	|      S )a&  
        create a loan to borrow margin

        https://docs.kucoin.com/#1-margin-borrowing

        :param str symbol: unified market symbol, required for isolated margin
        :param str code: unified currency code of the currency to borrow
        :param float amount: the amount to borrow
        :param dict [params]: extra parameters specific to the exchange API endpoints
        :param str [params.timeInForce]: either IOC or FOK
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r5   r  T)r\  rL  r	  r  r  r  )r  rN  r\  r  r  r  r  r  
r  r	  rj  r  r  rN  r\  r  r  r  s
             r  borrow_isolated_marginzkucoin.borrow_isolated_margin$  s     	V$==& ..tV<Tl 
 //GV0LM ~~h3%%dH55r  c                     | j                          | j                  |      }|d   | j                  ||      d}| j                  | j	                  ||            }| j                  |di       }| j                  ||      S )a  
        repay borrowed margin and interest

        https://docs.kucoin.com/#2-repayment

        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoints
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r5   )r\  rL  r  )r  r\  r  privatePostMarginRepayr  r  r  r  s           r  repay_cross_marginzkucoin.repay_cross_marginK  s     	==& ..tV<
 ..t{{7F/KL ~~h3%%dH55r  c                 ,   | j                          | j                  |      }| j                  |      }|d   | j                  ||      |d   dd}| j	                  | j                  ||            }| j                  |di       }	| j                  |	|      S )a  
        repay borrowed margin and interest

        https://docs.kucoin.com/#2-repayment

        :param str symbol: unified market symbol
        :param str code: unified currency code of the currency to repay
        :param float amount: the amount to repay
        :param dict [params]: extra parameters specific to the exchange API endpoints
        :returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
        r5   T)r\  rL  r	  r  r  )r  rN  r\  r  r  r  r  r  r  s
             r  repay_isolated_marginzkucoin.repay_isolated_marginl  s     	V$==& ..tV<Tl	
 ..t{{7F/KL ~~h3%%dH55r  c                     | j                         }| j                  |d      }| j                  |d      | j                  ||      | j                  |d      d || j	                  |      |dS )Nr\  orderNo
actualSize)r5   r\  r  r	  r   r  r  )r  r  r9  r;  r  )r  r  r\  r   r  s        r  r  zkucoin.parse_margin_loan  ss     %%'	%%dJ7
""43//
HE&&t\:"Y/
 	
r  r  c                     | j                          | j                  |      }| j                  |dg       }| j                  ||d      S )a  
        fetch deposit and withdraw fees - *IMPORTANT* use fetchDepositWithdrawFee to get more in-depth info

        https://docs.kucoin.com/#get-currencies

        :param str[]|None codes: list 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>`
        r  r\  )r  ro  r4  parse_deposit_withdraw_fees)r  r  r  r  r  s        r  fetch_deposit_withdraw_feesz"kucoin.fetch_deposit_withdraw_fees  sI     	++F3& ~~h3//eZHHr  r  c                    | j                          d}d}| j                  dd|      \  }}||dk7  r.| j                  |      }|d   rt        | j                  dz         d}| j                  d|      \  }}|t        | j                  dz         i }|dk(  r|t        | j                  dz         ||d	   |d
<   t        |      |d<   |dk(  |d<   | j                  | j                  ||            S )a.  
        set the level of leverage for a market

        https://www.kucoin.com/docs/rest/margin-trading/margin-trading-v3-/modify-leverage-multiplier

        :param int [leverage]: New leverage multiplier. Must be greater than 1 and up to two decimal places, and cannot be less than the user's current debt leverage or greater than the system's maximum leverage
        :param str [symbol]: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nr   rD   r  z0 setLeverage currently supports only spot marginz, setLeverage requires a marginMode parameterr  z< setLeverage requires a symbol parameter for isolated marginr5   r	  r  r  )
r  handle_market_type_and_paramsrN  r*   r5   r  r#   str%privatePostPositionUpdateUserLeverager  )r  r  r	  r  rN  
marketTyper  r  s           r  set_leveragezkucoin.set_leverage  s    	
!??tU[\
F:#7[[(Fj!"477-_#_``
!??vV
F#DGG.\$\]]##DGG.l$lmm &tGH!(m
!+z!999$++gv:VWWr  r   r  c                 2   | j                  | j                  di       }| j                  ||i       }| j                  ||i       }	| j                  |	|| j                  d         }
| j                  |d|
      }| j                  |d      }d|z   dz   | j	                  ||      z   }|dk(  rd| j	                  ||      z   }|dk(  rd| j	                  ||      z   }| j                  || j                  |            }d}||ni }| j                  d	   |   }| j                  |      s?|d
k(  s|dk(  r|dk7  r|d| j                  |      z   z  }n| j                  |      }|}d|d<   ||z   }|dk(  }|dk(  }|dk(  }|dk(  }|s|s|s|r| j                          t        | j                               }| j                  d| j                  |d|      }| j                  |d      }|dk(  rZ| j                  | j!                  | j"                        | j!                  | j$                        t&        j(                  d      }||d<   n| j"                  |d<   ||z   |z   |z   }| j                  | j!                  |      | j!                  | j$                        t&        j(                  d      }||d<   | j                  | j                  di       }|r| j+                  |d|      n| j+                  |d|      }| j                  |d      }| j-                  |dd      }|c|a||z   | j                  z   }| j                  | j!                  |      | j!                  |      t&        j(                  d      }||d<   ||d <   d!|d"<   |r| j                  |d#      }|||d$<   ||||d%S )&Nr  r<   z/api/r  r   r   z/api/v1/r  r   r  r  zorders/multi-cancel?zapplication/jsonzContent-Typer   r   r   rl  )KC-API-KEY-VERSIONz
KC-API-KEYzKC-API-TIMESTAMPr  base64zKC-API-PASSPHRASEzKC-API-SIGNr  rG   rD   r5   r   r  zKC-API-PARTNER-SIGNzKC-API-PARTNERr  zKC-API-PARTNER-VERIFYr6   zKC-BROKER-NAME)r   r  bodyheaders)r  r  r  rW  implode_paramsextract_paramsr   is_empty	rawencoder\  r.  r  r  r  r   hmacencoder   r   hashlibsha256r  r  )r  rl  r   r  r  r  r  r  rn  ro  rp  r<   endpointrs  endpartr   isFuturePrivate	isPrivateisBrokerisEarnr   apiKeyVersion
passphrasepayload	signaturer  	partnerIdpartnerSecretpartnerPayloadpartnerSignature
brokerNames                                  r  signzkucoin.sign  s    >>$,,
B?nnXsB7VR@)).$Y@WX""69nE69-W$s*T-@-@v-NN-T00v>>H&=!D$7$7f$EEH		&$"5"5d";<%1'iis#}}U#5f&8H]@]C$.."777yy'*<'Hn"22I%	8O-8v++-DJJL)Ikk&)"kk$-# 	G
 !,,W6JKM#!YYt{{4=='A4;;t{{C[]d]k]kmuv
/9+,/3}}+,&(83g=G		$++g"6DKK8PRYR`R`bjkI%.GM"nnT\\9bAGETdoogxAZ^ZiZijqsy  |C  [DG(($7I ..w%HM%M,E!*Y!6!D#'99T[[-H$++VcJdfmftftv~# 1A-.,5()39/0!--gv>
)0:G,-fdwOOr  reasonr   r  r  r  c
                    |s!| j                  | j                  d   ||       y | j                  |d      }
| j                  |ddd      }| j                  dz   |z   }| j                  | j                  d   ||       | j                  | j                  d   |
|       | j                  | j                  d   ||       |
dk7  r|
d	k7  rt        |      y )
Nrv  rj  msgr  r   ru  200000rz  )throw_broadly_matched_exceptionr  r  r  r5   throw_exactly_matched_exceptionr   )r  rj  r  r   r  r  r  r  requestHeadersrequestBody	errorCodemessagefeedbacks                r  handle_errorszkucoin.handle_errors'  s    001I4QUV $$Xv6	$$XufbA77S=4',,T__W-EwPXY,,T__W-EyRZ[,,T__W-EtXV Y%%7))r  )F)N)n__name__
__module____qualname__r   r  r  r   r  r  r   r   rR  boolr3  rZ  r
   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.  r1  r5  r7  r   rA  rG  r  r^  r   rl  rt  r  r   r  r  r  r'  r  r  r   r  r  r   r  r   r   r  r  r   r  r  r   r%  r   r   r3  r?  rP  r   rb  rj  rq  rx  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__)r  s   @r  r2   r2   !   s   V# Vp D !# 3s 3& #% 
: $& }$v, }~4  +- 
 ') iZ iV %' 04= 0d 79 
# 
: <> (?s (?TC CJP"Y4 Y Y6 Yv 04B 3GW 3G7 3Gj 48 ( (w (  02 (/3 (/f (/T 46 /s /& /(
 
4 
* 26DW[df 4H# 4Hc 4HQT 4Hkoptku 4Hl 8: %:3 %:n %:N 79  :#  :^  :D
h 
R` 
& DF &0s &0$~J^ &0P :>b As A3 AY AF> gksu X.3 X.i X.y X.RW X.`c X.t _a _C _y _PU _$ RT O O5 O SU P PE P @B R'D$6 R'hs  os{} 7,3 7,i 7,y 7,Z_ 7,hk 7,r `drv  @B (.S (.# (.Y (.i (.Y\ (.lo (.T 37r qs qC qf /32 ' 'R <@daenp n?S n? n?[^ n?` 154VZce Q# QS QPS Qjnotju Q: /3TXac S S3 Sc Shlmrhs S> 26b <6c <63 <6|k kv k kZ 9=4^bkm XS X# XS XX[ X& -1tRV_a f?c f? f?C f?P 6:UW (?3 (?s (?# (?\`af\g (?T{ {v { {z 57 &
 &
;N &
P DHPR 16S 16% 16# 16Wb 16f:s :f
T f
X f
Q\ f
P *.Dt\^ M[3 M[c M[ M[cghsct M[^ -1tRV_a N^c N^ N^C N^fjkvfw N^` $& f( fP [] U7S U7% U7c U7c U7an U7n5
t 5
x 5
= 5
n:C :C :*3XMt Mx M; M^ (,$TZ\ \@ \@C \@s \@aefqar \@| MO 2
 
< 15DW[jnwy f[# f[c f[QT f[dg f[  C  DR  S f[PH
$ H
 H
. H
T 154VZce 1KS 1KPS 1Kf AESW`b 3Hc 3H# 3HS 3Hj#6 DF !6 !6U !6F TV %6S %6 %6U %6N <> 6s 6B LN #6C #6s #6J
 
& <@ I IB 9=R XS X# X@ &eBSW @PD# s  c TX `c r  r2   )9ccxt.base.exchanger   ccxt.abstract.kucoinr   r  r  r\  ccxt.base.typesr   r   r   r   r	   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+   r,   r-   ccxt.base.decimal_to_precisionr.   r/   ccxt.base.preciser0   r2    r  r  <module>r     s    ( ,    [  [  [  [  [  [  [  * 0 - - . ' & . + ) * ) . 1 ) 3 4 %XLX{ XLr  