
    ei                       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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!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,m0Z0 d d
l,m1Z1 d dl,m2Z2 d dl,m3Z3 d dl,m4Z4 d dl,m5Z5 d dl,m6Z6 d dl,m7Z7 d dl,m8Z8 d dl,m9Z9 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@mAZA  G d dee          ZBdS )    )Exchange)ImplicitAPIN)!AccountAnyADLBalancesBorrowInterestBool
CurrenciesCurrencyDepositAddressIntLedgerEntryLeverageLeverageTierLeverageTiers
MarginModeMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)RestrictedLocation)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i fde	e
         fdZi fde	e
         fdZdd
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ddefdZd Zddede
defdZddede
defdZddede
defdZde de fdZ!di fde"de#fdZ$di fde"de#fdZ%d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(dde
de)fd$Z*d%ddi fd!ed&ed'ed(ede	e)         f
d)Z+d%ddi fd!ed&ed'ed(ede	e)         f
d*Z,d%ddi fd!ed&ed'ed(ede	e)         f
d+Z-d%ddi fd!ed&ed'ed(ede	e)         f
d,Z.i fdede/fd-Z0i fdede/fd.Z1i fdede/fd/Z2ddede/fd0Z3i fdede	e/         fd1Z4di fd!ed(ede5fd2Z6d3 Z7di fd!ede8d4e9d5e:d6e;f
d7Z<di fd!ede8d4e9d5e:d6e;f
d8Z=di fd!ede8d4e9d5e:d6e;f
d9Z>d!efd:Z?di fd!ede8d4e9d5e:d6e;f
d;Z@di fd!ede8d4e9d5e:d6e;f
d<ZAi fd!ed4e9d=e:fd>ZBi fd!ed=e:fd?ZCi fd!ed=e:fd@ZDi fdAe	eE         fdBZFi fdAe	eE         fdCZGi fdAe	eE         fdDZHddi fdEed!ede8d4e9d5e;d6e;fdFZIdi fdEed!e fdGZJdi fdEed!e fdHZKdi fdEed!e fdIZLdi fd!e fdJZMdi fd!e fdKZNdi fd!e fdLZOdddi fd!e d'ed(efdMZPdddi fd!e d'ed(efdNZQdddi fd!e d'ed(efdOZRdddi fd!e d'ed(ede	eS         fdPZTdddi fd!e d'ed(ede	eS         fdQZUdi fdEe d!e fdRZVdi fdEed!e fdSZWdi fdEe d!e fdTZXddUede
deSfdVZYddUede
deSfdWZZddUede
deSfdXZ[dddi fdEed!e d'ed(efdYZ\dddi fd!e d'ed(efdZZ]dddi fd!e d'ed(efd[Z^dddi fd!e d'ed(efd\Z_ddi fd!ed'ed(ede	e`         fd]Zadd^ede
de`fd_Zbdd^ede
de`fd`Zcdd^ede
de`fdaZdi fd!edeefdbZfdi fded5e:dcedde degf
deZhdfe fdgZiddhededegfdiZjdddi fde d'ed(ede	eg         fdjZkdddi fde d'ed(ede	eg         fdkZldddi fde d'ed(ede	eg         fdlZmdddi fde d'ed(ede	eg         fdmZndn Zoi fdepfdoZqi fdepfdpZri fded5e:dqedredesf
dsZtdte due defdvZuddwededesfdxZvdfe de fdyZwdz Zxd{ Zyd| Zzdd}edede{fd~Z|dddi fde d'ed(ede	e{         fdZ}i fdZ~ddefdZddddi fde d!e d'ed(ede	e         f
dZddede
defdZdddi fd'ed(efdZddi fded'ed(efdZd Zi fded5e:fdZi fd!eded5e:fdZi fdefdZi fd!edefdZddefdZdi fde"fdZi fd!edefdZdi fded!e fdZdi fded!e fdZi fd!edefdZi fd!edefdZdde
defdZd Zdddi fd!e d'ed(efdZdde
fdZdddi fd!e d'ed(efdZi fd!efdZdi fde"de	e         fdZdddi fde"d'ed(efdZddede
fdZdi fde	e         d!e fdZi fd!ed5e:defdZdde
defdZi fd!edefdZddedefdZdi fded!e fdZdi fded!e fdZdi fd!e fdZdi fd!ed4e9deSfdZi fd!ede	e         fdZdde
de	e         fdZdi fde"defdZddi ddfdZdedededededefdZdddi fde d'ed(ede	es         fdZdi fde"de	e         fdZddede
defdZ xZS )kucoinreturnc                 :   |                      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dddddddddhdidjdkdldldmdmdndodldldldp	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dddddd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ddxddxddxddxddxdd}dd}dd}dd}dd}dd}i dd}dd}dd}dd}ddxdd}dd}ddddddddxddxdd}dd}dd}dd}dd{i dddd{ddddddddxddxdd}dd}dd}dd}ddddddddxddxddٓi ddddddddddddddddxddxddxddxddxdddddddddddddi dddddddddddd{dddddddddddddddddddddd}i dd}dd}ddxdd}dd}dd}d d}ddxdddddd}ddddddddddddddddd	i ddd
ddddddddddddd}ddddxddddddxddddxddxddxdxd}d}ddxddxdxdxdxd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dd{dd#dxdxdxd$ddidi dd{d%dd&d'dddd{d(d'd)dddd*dddd+dddd,dd-d{d.d{d/dd0ddddd{d{d{d{d{d{d{d{d{d{d{d1i dddddd{d2d{dd{ddd3dd4dd5dd6dd7d{d8d{d9d{d:dd;dd<d{d=dd{d{dd{d{d{d{d{d{d{dd>d}d}ddd?d?ddddd@
ddAdd}dBid{d{d{d{d}d}d}d}dCd}ddddDdEdiddd}d}ddddddddddFdddGdHdiddAdddddddd{ddddddddIii dJddKddLddMdNdOd{dPddQddRddSddTddUddVddWddXddYddZd{d[dddd{d\ddNdd}dd}dddd{d]
dd^	d_d`dadbdcdddedfdgdhdidjdkdldmdndot          dpi dqt
          drt
          dst
          dtt
          dut
          dvt          dwt          dxt          dyt          dzt          d{t          d|t          d}t          d~t          dt          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          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           t          t          t          t          t          t
          t          t          t          t          t          t          dt          t          t          t
          ddddd|                     d          |                     d          |                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d           g|                     d          |                     d          gg|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d           g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          ggdddd|                     d          |                     d          |                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d           g|                     d          |                     d          gg|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d           g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          ggdddd|                     d          |                     d          |                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d           g|                     d          |                     d           g|                     d          |                     d           g|                     d          |                     d           gg|                     d          |                     d	          g|                     d          |                     d
          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          g|                     d          |                     d          ggddddi i dddddddddi dd d	dddddd d!d"dd5dddd#dKg d$dd%d&d'did(d)did.d*d+id_ddd ddddNd,d-d d.d/d0d1d2id3d4d5d5d
d5d5d6ii dd
dd5dd
dd
dd5dd5dddd5dd5dd5dÐd5dĐd5dŐd5dƐd5dǐd5dd5dȐd5i dɐd5dʐd5dːd5d̐d5d͐d5dΐd5dϐd5dАd5dѐd5dҐd5dӐd5dԐd5dڐd5dېd5dܐd5dݐd5dސd5d5d5d5d5d
dd7i dd
dd5dd
dd
dd5d8d5dd5dd5d d5dd5dڐd5dېd5dd5dd5dd5dd5d9d5dd5id5d5d5d5d5d5d5d5d5d5d5d5d:d;d
d
d
d
d<d
d
d
d
d=d>d4d?d
iid@dAdBdCdDdEdFdDdGdHdIddddJdKdKdLdLdMdNdLdOdPi dQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdri dsdtdudvdwdxdydzd{d|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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d8d9d:d;d<i d=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_d`dadbdcdddd dddd ddddddddddddddedfdidd d dgddhdddddiddjddddkd ddjd d dgddddldmdnido	dddddddpdddd ddqddddddddddddddedfdiddrd dgddhdddddiddrddddkd ddrd d d ddddldmdjido	dsdtidsdtidudsdtidsdtidudvdwdx          S (y  Nidr;   nameKuCoin	countriesSC	rateLimitg      @versionv2	certifiedTprocommentzPlatform 2.0quoteJsonNumbersFhasCORSspotmarginswapfutureoption	addMarginborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercancelOrders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fetchFundingIntervalfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersByStatusfetchOrderTradesfetchPositionfetchPositionADLRankfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsADLRank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earnuta
utaPrivatezhttps://www.kucoin.comzhttps://docs.kucoin.com)logoreferralapiwwwdocrequiredCredentials)apiKeysecretpasswordr   
currencies   currencies/{currency}symbols   zmarket/orderbook/level1   zmarket/allTickers   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margin/collateralRatiozconvert/symbolzconvert/currencieszbullet-public)getpostz	user-infozuser/api-keyaccountszaccounts/{accountId}zaccounts/ledgerszhf/accounts/ledgerszhf/margin/account/ledgersztransaction-historyzsub/userzsub-accounts/{subUserId}zsub-accountssub/api-keyzmargin/account(   zmargin/accountszisolated/accountsdeposit-addressesdepositszhist-depositswithdrawalszhist-withdrawals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/activezhf/margin/orders/donehf/margin/orders/{orderId})hf/margin/orders/client-order/{clientOid}zhf/margin/fillszhf/margin/stop-orderszhf/margin/stop-order/orderIdzhf/margin/stop-order/clientOidzhf/margin/oco-order/orderIdzhf/margin/oco-order/clientOidz"hf/margin/oco-order/detail/orderIdzhf/margin/oco-orderszetf/infozmargin/currencieszrisk/limit/strategyzisolated/symbolsmargin/symbolszisolated/account/{symbol}2   zmargin/borrowzmargin/repayzmargin/interestzproject/listzproject/marketInterestRateredeem/orderspurchase/orderszbroker/api/rebase/downloadzbroker/queryMyCommissionzbroker/queryUserzbroker/queryDetailByUidmigrate/user/account/statuszconvert/quotezconvert/order/detailzconvert/order/historyzconvert/limit/quotezconvert/limit/order/detail   )zconvert/limit/ordersaffiliate/inviter/statisticszsub/user/createdsub/api-key/updatezaccounts/universal-transferzaccounts/sub-transferzaccounts/inner-transfertransfer-outz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-allzorders/testzorders/multiz	oco/orderzhf/margin/orderzhf/margin/order/testzhf/margin/stop-orderzmargin/orderzmargin/order/testzhf/margin/oco-orderpurchaseredeemzlend/purchase/updatezconvert/order)zconvert/limit/orderbullet-privateposition/update-user-leveragedeposit-address/create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!hf/margin/stop-order/cancel-by-id(hf/margin/stop-order/cancel-by-clientOidhf/margin/stop-order/cancel hf/margin/oco-order/cancel-by-id'hf/margin/oco-order/cancel-by-clientOidhf/margin/oco-order/cancelzconvert/limit/order/cancel)r   r   deletezcontracts/active   zcontracts/{symbol}ticker
allTickerszlevel2/snapshotzlevel2/depth20zlevel2/depth100ztrade/historyzkline/queryzinterest/queryzindex/queryzpremium/querytrade-statisticszfunding-rate/{symbol}/currentzcontract/funding-ratesg&S?)r   zlevel2/message/querycontracts/risk-limit/{symbol}zlevel3/message/querylevel3/snapshotzaccount-overviewzaccount-overview-all   
stopOrdersrecentDoneOrderszorders/byClientOidrecentFillsopenOrderStatisticsposition	positionszmargin/maxWithdrawMarginr   )zfunding-historyz$copy-trade/futures/get-max-open-sizez6copy-trade/futures/position/margin/max-withdraw-marginzhistory-positionsposition/getMarginModeposition/getPositionModezdeposit-addresszdeposit-listr   zwithdrawal-listr   r   getMaxOpenSizegetCrossUserLeveragez	st-ordersz#position/margin/auto-deposit-statuszmargin/withdrawMarginzposition/margin/deposit-marginz position/risk-limit-level/changecopy-trade/futures/orderszcopy-trade/futures/orders/testzcopy-trade/futures/st-ordersz1copy-trade/futures/position/margin/deposit-marginz2copy-trade/futures/position/margin/withdraw-marginz3copy-trade/futures/position/risk-limit-level/changez6copy-trade/futures/position/margin/auto-deposit-status)z,copy-trade/futures/position/changeMarginModez3copy-trade/futures/position/changeCrossUserLeveragez(copy-trade/getCrossModeMarginRequirementz&copy-trade/position/switchPositionModechangeCrossUserLeverager   r   r   position/changeMarginModeposition/switchPositionModer   g      ?)
r   zorders/client-order/{clientOid}r   r   r
  z&copy-trade/futures/orders/client-orderorders/multi-cancelr   zcancel/transfer-outr   r   )zcurrency/currency/chain-infozcontract/{symbol}/funding-rates)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/discount-rate-configsz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struct-earn/dual/productsstruct-earn/orders)earn/ordersr  r  )zmarket/announcementzmarket/currencyzasset/currencieszmarket/instrumentzmarket/tickerzmarket/tradezmarket/klinezmarket/funding-ratezmarket/funding-rate-historyzmarket/cross-configz market/collateral-discount-ratiozmarket/index-pricezmarket/position-tierszmarket/open-interestzserver/statuszmarket/orderbookzaccount/balancezaccount/transfer-quotaaccount/mode<   zaccount/ledgerzaccount/interest-historyzasset/deposit/addresszaccount/deposit/addressz{accountMode}/account/balancez{accountMode}/account/overviewz{accountMode}/order/detailz{accountMode}/order/open-listz{accountMode}/order/historyz{accountMode}/order/executionz {accountMode}/position/open-listz{accountMode}/position/historyz{accountMode}/position/tiers)zsub-account/balancezuser/fee-ratez	dcp/query)
zaccount/transferr  z%{accountMode}/account/modify-leveragez{accountMode}/order/placez{accountMode}/order/place-batchz{accountMode}/order/cancelz {accountMode}/order/cancel-batchz{accountMode}/order/cancel-allzsub-account/canTransferOutzdcp/set)	r   r   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,Order not exist or not allow to be cancelledz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.zOrder size increment invalid.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.znot in the given range!z%recAccountType not in the given rangezUnsupported trading pair.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330012330005100001100004300003300012404000300009330008)z$pageSize should not greater than 500zExceeded the access frequencyzrequire more permissionzPosition does not exist)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  tiersz0.0002z0.00038z0.00032z0.02z0.015z0.01z-0.003z-0.006z-0.009z-0.012z-0.015)r  r  r   deposit)tradingrL   contractfundingBIFIFVAIOTWAXPAPTOSLAUNCHTOKENALTzFTX Users' Debt)BIFIVAIWAXr  KALTFUDhfv1symbolSeparator-fetchMyTradesMethodprivate_get_fillstimeDifferencer   adjustForTimeDifference)webApiEnablewebApiRetrieswebApiMuteFailurerL   rN   rO   r  )typesfetchTickersFeesr   
includeFeer   fillResponseFromRequestcodeUSDTx      i  i  i  i`'  )r%  r&  r'  r(  r)  r*  r+  r,  r-  r.  r/  r0  r1  versionsGETv3)r   r   r   r   r   )r   r   r   r   r   r  r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )r  POSTDELETE)r  r	  r  r  )r   r  r  r  )r  r  r   )r   r   r   r   partnerccxtz$9e58cc35-5b5e-4133-92ec-166e3f077cb8)r>   keyccxtfuturesz$1b327198-f30c-4f14-a0ac-918871282f15)rL   rO   accountsByTypetradeisolatedmainr  pooltrade_hf)rL   rM   crossmarginV2r  r  r  rO   rN   miningr  r  networks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OPTIMISM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TARAtaramarginModesMARGIN_TRADEMARGIN_ISOLATED_TRADETRADE)r  r  rL   )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    )r  r  r   r  r  )r  r  r  daysBackCanceledr  r   r  r  r    )	sandboxr]   r^   r   r   r   fetchOrdersrj   r   )lastmarkindex)r  price  extends	forDerivs)linearinverse)rL   r,  rN   rO   g     L@)commonCurrenciesoptionsfeaturesrollingWindowSize)deep_extendsuperr;   describer8   r2   r1   r'   r/   r,   r-   r(   r3   r4   r5   r)   r0   r6   r.   r*   parse_number)self	__class__s    W/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/async_support/kucoin.pyr5  zkucoin.describe%   s8   fd 3 3 < < > > HA
(HA
HHA
 $HA
 	HA

 tHA
 HA
 4HA
 ~HA
 HA
  aaa $a 	a
 %a %a Ta $Ta 'a "4a ta a $Ua  a 'a  /!a" ,T#a a$ 0%a& t'a( )a* &t+a, '-a. (/a0 "41a2 %d3a4 T5a6  7a8 9a: &t;a< +D=a> )$?a@ $TAaB 'CaD (Ea a aF "4GaH &tIaJ (KaL 1$MaN  OaP *4QaR +DSaT &tUaV 'WaX #DYaZ *4[a\ $U]a^ "5_a` *5aab +Ecad #Deaf tga a ah  iaj %ekal /man "4oap +Dqar sat !%uav !$wax "4yaz  {a| d}a~ $Ua@ +EAaB "4CaD dEaF !$GaH "5Ia a aJ &tKaL #DMaN  OaP 'QaR 'SaT $TUaV !$WaX (YaZ ([a\ )%]a^ t_a` taab cad Teaf tgah "4iaj #Eka al (,"&$($('+#!%#'  Aa a aHA
X ~P67&F%E#<=43":
 
 0- YHA
~ " $ $HA
H $a 0 "1	
 21 ,R ' "1 @ 5a 6q +A )! !! $Q  !!!$ 6q%& 1"'( *,)+24*+./3  : (9   D_#R_ '_ #A	_
 /_ +A_ .q_ 4Q_ .q_ #B_ 3B_ '_ &r_ )"_  *2!_" ,R#_$ ,Q%_& #A'_ _( ()_* &r+_, +B-_. -b/_0 01_2 (3_4 #A5_6 %a7_: 8;_< 21=_> 21?_@ -aA_B +AC_D 3AE_F 9!G_H )!I_J .qK_ _ _L =aM_N :1O_P #AQ_R !!S_T 'U_V +AW_X 9!Y_Z  [_\ &r]_^ %a__` /a_b ;Ac_d .qe_f 6qg_h 7i_j %ak_n 21o_ _ _p 0q_r 5as_t DQu_v *1w_x 0y_z 7{_| 9!}_~ 6q_@ 8A_B =aC_D /E_F #BG_H ,RI_J .rK_L +AM_N )!O_P 4RQ_ _ _R (S_T 'U_V *2W_X 'Y_Z 5a[_\ (]_^ *2__b 5ac_d 3Ae_f +Ag_h 21i_j 6qk_n (o_p /q_r 0s_t .ru_v 5aw_ _x 128:}_ _ _@-*B- &r- -b	- ,R- &q- 6q- 0- 22- '- &r- $Q- )!-  )!!-" *1#-$ /%-& *1'-( 4Q)- -* !!+-, &q--. '/-0 %a1-2 $Q3-6 *17-8 /9-: /;-< '=-> ,Q?-@ .qA-B (C-D 'E-F #BG-H !"I-J /K-N (O- -P 02*,9:24Y- - -\"%r" 5b	" .q" 3A" =a" B1" 5a" $Q" .r" +A" 9!" !""  /!"" <Q#"$ ,Q%"& .q'"( 7)"* '(67EF,-=>DE78<=CD6767C" " "_r rh*A,a !! %b	
 *1 )" *2 ( &q )" &q 6q ( +A 8  1"!" $Q#$ #$069:01+,/  6 (5" "@#-q# +B	#
 /# (# !!# %b# +B# +B# -b#  # &q# %a#  .r!#" #A##$ $Q%#& 3B'#( 8)#* ,.@ART-.2345+,()./+,'(,-*+01E# # #H &  &r 
 !!  $Q  &q  '  >q  0  9!  ;A  4Q  9!  7   LQ! " Mb# $ Nq% & QRS' ( IJOPDEBC34'('(./5678*,?     D -.;<"$&(58BE/168/1') MR# R#h 89;<   +,-.455678564556	 	 /0-.45;<	  3A# . ;=)*-./102,.3557135756.0  (*.0 
 &r' 0 /1+,,--.)+()()/079/1<>.01302)* (*A)2 1" '	
 )! 3B 0 21 8 9" 5a 8 6q 8 ;A  9!!" 7#$ 02)*%&)  . -.(*AC56;<67<=:<68#$ /# #cu uIHA
t  uHA
T YUHA
V GBMG/G &}G '	G
 &}G =lG @G 4\G N}G OPaG 7
G ElG .zG <ZG 0G  :!G" .#G G$ <%G& <'G( <)G* <+G, ,-G. //G0 /1G2 .3G4 l5G6 j7G8 m9G: m;G< m=G> /?G@ lAGB mCGD mEG G GF .GGH mIGJ /KGL jMGN /OGP .QGR lSGT lUGV lWGX lYGZ l[G\ l]G^ l_G` maGb lcGd leGf lgG G Gh liGj lkGl mmGn loGp mqGr lsGt muGv .wGx myGz m{G| m}G~ mG@ mAGB /CGD mEGF lGGH lIG G GJ lKGL lMGN lOGP lQGR lSGT lUGV lWGX mYGZ m[G\ m]G^ m_G` maGb mcGd leGf lgGh liGj .kG G Gl .mGn moGp mqGr /sGt luGv /wGx /yGz n{G| /}G~ lG@ iAGB 1CGD lEGF 1GGH 1IGJ 1KGL 1MG G GN 1OGP lQGR jSGT lUGV lWGX lYGZ l[G\ j]G^ 1_G` 0aGb icGd leGf jgGh jiGj .kGl jmGn .oG Gp 3,/*(**+(/***/MG G GR =G5F/?/< SP PWHA
x !%"&!..w77!..w77 "..s33T5F5Fw5O5OP!..t44d6G6G6P6PQ!..u55t7H7H7R7RS!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I(8S8ST!..v668I8I(8S8ST!..v668I8I(8S8ST!..w779J9J99U9UV!..w779J9J89T9TU!..w779J9J99U9UV!..w779J9J89T9TU!..w779J9J99U9UV"  "..s33T5F5Fw5O5OP!..t44d6G6G6Q6QR!..u55t7H7H7R7RS!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I#8N8NO!..v668I8I#8N8NO!..v668I8I#8N8NO!..w779J9J:9V9VW!..w779J9J:9V9VW!..w779J9J:9V9VW!..w779J9J:9V9VW!..w779J9J:9V9VW"! % %N "&"&!..w77!..w77 "..s33T5F5Fw5O5OP!..t44d6G6G6P6PQ!..u55t7H7H7R7RS!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I(8S8ST!..v668I8I(8S8ST!..v668I8I(8S8ST!..w779J9J99U9UV!..w779J9J89T9TU!..w779J9J99U9UV!..w779J9J89T9TU!..w779J9J99U9UV"  "..s33T5F5Fw5O5OP!..t44d6G6G6Q6QR!..u55t7H7H7R7RS!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I#8N8NO!..v668I8I#8N8NO!..v668I8I#8N8NO!..w779J9J:9V9VW!..w779J9J:9V9VW!..w779J9J:9V9VW!..w779J9J:9V9VW!..w779J9J:9V9VW"! % %N "&"&!..x88!..x88 "..s33T5F5Fx5P5PQ!..t44d6G6G6Q6QR!..u55t7H7H7R7RS!..u55t7H7H7R7RS!..v668I8I(8S8ST!..v668I8I(8S8ST!..v668I8I)8T8TU!..v668I8I)8T8TU!..w779J9J99U9UV!..w779J9J89T9TU!..w779J9J89T9TU!..w779J9J89T9TU!..w779J9J89T9TU"  "..s33T5F5Fv5N5NO!..t44d6G6G6P6PQ!..u55t7H7H7P7PQ!..u55t7H7H7P7PQ!..v668I8I&8Q8QR!..v668I8I#8N8NO!..v668I8I#8N8NO!..v668I8I#8N8NO!..w779J9J89T9TU!..w779J9J89T9TU!..w779J9J89T9TU!..w779J9J89T9TU!..w779J9J89T9TU"! % %N "'"' "!	 gy yyHA
n  ))! !SdS4S "3S &':	S
 !!S *5S "$(%&)-$ $S CCC(,! !S   %!S& -t'S, F!-S2 "!! !!"!""# 3SV *.59'+6:-1   	. '.  8.  '	. 
 +D.  .t.  0.  0.  6t.  6t.  <T.  24.   :4!. " ;D#. $ )$%. ( 6t). * =d+. , 4T-.  . . 9$/. 0 H1. 2 .t3. 4 4T5. 6 ;D7. 8 =d9. : :4;. < <T=. > A$?. @ 3DA. B 'C. D 0E. F ,TG. H +DI. J .tK. L +DM. N 9$O.  . P .2/3;?.2<@;?[.  .  . ^!.! :4	!
 4T! 6t! +D! 5d! (! .t! 3D! 3D! ,T!  +D!!" 24#!$ '%!& %d'!( 3D)!* <T+!, *4-! !2 ;?IM04AEHL;?37<@*.@DGK:># #QV  V r /3486:8<	    -17;9=;?	! !' ' -t &au uWSB  %E 
 ,E  CS^ !#&% ( *"%(&$$ *# #_Sz  PUP%xP UP U	P
 VP WP 5P 5P FP 5P UP EP jP VP WP  F!P" 5#P P$ 5%P& 
'P( 5)P* F+P, F-P. F/P0 51P2 53P4 F5P6 77P8 F9P: 5;P< 5=P> 7?P@ HAPB FCPD FEP P PF 5GPH 5IPJ FKPL 5MPN 5OPP FQPR 5SPT FUPV 5WPX 5YPZ 6[P\ W]P^ 5_P` VaPb FcPd 5ePf 5gP P Ph WiPj 5kPl WmPn FoPp FqPr 5sPt 5uPv FwPx FyPz 5{P| 5}P~ 5P@ FAPB 5CPD FEPF 5GPH 5IP P PJ FKPL FMPN FOPP FQPR 5SPT $UPV 5WPX FYPZ 5[P\ 5]P^ F_P` 5aPb FcPd FePf WgPh 5iPj FkP P Pl UmPn WoPp 5qPr 5sPt 5uPv FwPx 5yPz 5{P| 5}P~ 5P@ 5APB 5CPD 5EPF 5GPH 5IPJ WKPL 5MP P PN eOPP 5QPR FSPT 5UPV 5WPX 5YPZ W[P^ F_P` 5aPb hcPf FgPh FiPj FkPl 5mPn $oPp FqPr FsP P Pt WuPv  wPx FyPz F{P| F}P~ FP@ FAPB FCPD FEPF 5GPJ WKPL FMPN FOPP $QPR FSPT FUPV FWP P{S\ + 7#   ]Sl  %&*(,,0,1)-+/6:#'#'"&#'	( ( #($)$)+/27/3#')$ $. q% '+!%$(%&*.& & ',#'$)*.	# # '+!$#'$)*.( ( $(&*!$$(,0%&#'$)*.	* 	*  #u= =~  %&*(,$($(%)- -
 -1)-+/04%)7 7
 $(#("&#(	( ( #($)$(+/27/3#'7$ $< r% '+!%$(%&*/& & ',#($)*/	# # ',!%#'$)*/( ( $(&+!%$(,0%)#'$)*/	* 	*  #CD DN "; "; 	  "; "; 	 YT Tj ")O,HA
 HA
 HA
 H H H	    c                 F    |                                  | j        d         z
  S )Nr  )millisecondsr0  )r7  s    r9  noncezkucoin.nonce  s!      ""T\2B%CCCr:  c                    K   d}|                      dd|          \  }}d}|dk    r"|dk    r|                     |           d{V }n|                     |           d{V }|                     |d          S )a  
        fetches the current integer timestamp in milliseconds from the exchange server

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-server-time
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-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
        Nr   rL   rM   data)handle_market_type_and_paramsfuturesPublicGetTimestamppublicGetTimestampsafe_integer)r7  paramstyperesponses       r9  
fetch_timezkucoin.fetch_time  s       99+tVTTfFNN!1!1 ";;FCCCCCCCCHH "44V<<<<<<<<H  6222r:  c                 d  K   d}|                      |ddd          \  }}d}|                     dd|          \  }}d}|rq|                     | j        dd          }|dk    rdnd}|                     |d	|          }d	|i}|                     |                     ||                     d{V }nC|dk    r"|d
k    r|                     |           d{V }n|                     |           d{V }| 	                    |di           }	| 
                    |	dd          }
|
dk    rdndddd|dS )a  
        the latest known information on the availability of the exchange API

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-service-status
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-service-status
        https://www.kucoin.com/docs-new/rest/ua/get-service-status

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.type]: spot or swap
        :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
        :param str [params.tradeType]: *uta only* set to SPOT or FUTURES
        :returns dict: a `status structure <https://docs.ccxt.com/?id=exchange-status-structure>`
        Nr   r   FdefaultTyperL   SPOTFUTURES	tradeTyperM   r?  r   serverStatusopenokmaintenance)r   updatedetaurlinfo)handle_option_and_paramsr@  safe_stringr0  safe_string_upperutaGetServerStatusextendfuturesPublicGetStatuspublicGetStatus	safe_dictsafe_string_2)r7  rD  r   rE  rF  rI  defaultTradeTyperL  requestr?  r   s              r9  fetch_statuszkucoin.fetch_status  s      33FM5RWXXV99-vVVf 	:**4<OOK*5*?*?vvi..v{DTUUIYG "44T[[&5Q5QRRRRRRRRHH fnn48#3#3!88@@@@@@@@HH "11&99999999H ~~h33##D(NCC%//ddm
 
 	
r:  c                   K   d}|                      |ddd          \  }}d}|                      |ddd          \  }}|r|                     |           d{V S g d}|                     | j        d          }|                     |d|          }|                     d          }|o|                     |d	d          }|                     |d	          }d}	|                     d
|          s,|                     d|          s|                     d|          rd}	|                     d|          }
|o|
}g }|
r(|	                    | 
                    |                     |rP|	                    |                     |                     |	                    |                     |                     |r(|	                    |                     |                     |	r(|	                    |                     |                     |r'|	                    |                                            t!          j        |  d{V }|
r|                     |d         d          ng }d}d}d}d}d}|
rd}|r.|}|                     |d          }|                     |d          }|r|}|                     |d          }|	r|}|r|                     ||         di           ni }|                     |dg           }|                     |d          }|r||         ni }|                     |dg           }|                     |d          }|r|                     ||i           ni }|                     |                     |di           dg           }|                     |d          }g }t)          dt+          |                    D ]B}||         }|                     |d          }|                    d          \  } }!|                     |           }"|                     |!          }#|                     ||i           }$|                     |$d          }%|                     |$d          }&|                     |$d          }'|                     |$d          }(||v })||v }*|                     |dd          p|)p|*}+|	                    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(|                     |d)          dddd|                     t5          j        |&|(                    |                     t5          j        |%|'                    ddddd|                     |d*          |                     |d+          d,ddd-|                     |d.          |                     |d/          d-ddd-|                     |d0          |                     |d1          d-d2d|d3           D|	r-|                     ||g           },|                     ||,          }| j        d4         r|                                  d{V  |S )5a*  
        retrieves data on all markets for kucoin

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-all-symbols
        https://www.kucoin.com/docs-new/rest/ua/get-symbol
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-all-symbols

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
        :returns dict[]: an array of objects representing market data
        Nr   r  Tr   Fr  r  marginablesrN   rO   r  rL   r   r?  r   r   itemssymbolr   r  makerFeeRatetakerFeeRatemakerCoefficienttakerCoefficientisMarginEnabledr>   /r   quotesettlebaseIdquoteIdsettleIdrE  rM   r  )r  r  rP   activeenableTradingbaseIncrementpriceIncrementamountr)  minr  baseMinSizebaseMaxSizequoteMinSizequoteMaxSizer  ru  r)  cost)r-  r.  r  r  contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedrT  r  )rU  fetch_uta_marketsr\  r0  	safe_listcheck_required_credentials	safe_boolomitin_arrayappendpublicGetSymbolsprivateGetMarginSymbolsprivateGetIsolatedSymbolspublicGetMarketAllTickersfetch_contract_marketsload_migration_statusasynciogathersumindex_byrangelenrV  splitsafe_currency_coder6  r9   
string_mulsafe_numberarray_concatload_time_difference)-r7  rD  r  r   defaultTypesfetchMarketsOptionsr  credentialsSetrequestMarginablesfetchContractMarketsfetchSpotMarketspromises	responsessymbolsData
crossIndexisolatedIndextickersIndexcontractIndex	nextIndex	crossData
crossItems	crossByIdisolatedDataisolatedItemsisolatedByIdtickersResponsetickerItemstickersByIdresultimarketr>   rm  rn  r   rk  r   re  rf  rg  rh  hasCrossMarginhasIsolatedMarginisMarginablecontractMarketss-                                                r9  fetch_marketszkucoin.fetch_markets  s       #'#@#@Ykmq#r#r &33FNESXYYV 	8//777777777==="nnT\>JJ2G\JJ88??+[v}VZ0[0[6=11$=='' 	(4==5+I+I 	(T]][eglMmMm 	(#' ==77+@0@ 	;OOD11&99:::0  	DOOD88@@AAA OOD::6BBCCC,  	D4 OOD::6BBCCC 	AOOD77??@@@ 	:OOD6688999!.(3333333	>NVdnnYq\6:::TV
	 	I 	4"JA..I HHZ33M 	/$LA..I 	&%MI[cDNN9Z#8&"EEEac	^^Iw;;
MM*h77	3EMy//2|VR@@}}]H==IYa$..L"EEE_annT^^OVR%P%PRZ\^__mmK::q#k**++ E	 E	A ^F!!&(33B hhsmmOFG**622D++G44E^^KR88F++FNCCL++FNCCL#//8JKK#//8JKK IoN!#|!3>>&2CUK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A'6( E)6* **7+=lL\+]+]^^**7+=lL\+]+]^^ $"&""..vGG!--f6FGG   $#! !
  $//FF#//FF 
  $# 
  $//GG#//GG  $  k6 6 6 6 6 6 6n   	@"nnYrJJO&&v??F<12 	.++---------r:  c                 `  K   |                      |           d {V }g }|                     |dg           }t          dt          |                    D ]X}||         }|                     |d          }|                     |d          }|                     |d          d u }	|	 }
|                     |d          }|                     |d          }|                     |d          }|                     |          }|                     |          }|                     |          }|d	z   |z   d
z   |z   }d}|	r|dz   |                     |d          z   }d}|                     |d          }|                     |d          }|                     |d          }| 	                    |d          }| 	                    |d          }|}|| 	                    |d          }| 	                    |d          }|| 	                    |d          }| 	                    |d          }|T|                     |d          }|                     |d          }| 
                    t          j        ||                    }|                    i d|d|d|d|d|d|d|d|d |d!d"d#d"d|
d|	d$d"d%|d&k    d'd(d)| || 	                    |d*          | 	                    |d+          | 
                    t          j        |                    ||                     |          d d ||d,| 
                    d-          | 	                    |d.          d/||d/||d/| 	                    |d0          | 	                    |d          d/d1|                     |d2          |d3           Z|S )4Nr?  r   rd  
expireDatenextFundingRateTimebaseCurrencyquoteCurrencysettleCurrencyrj  :rN   r   rO   	isInverser   
multipliertickSizelotSizerx  maxOrderQtyry  maxPricer{  r>   r   rk  rl  rm  rn  ro  rE  rL   FrM   rP   rp  Openr  Tr-  rf  re  rt  1maxLeveragerv  rz  r|  firstOpenDater.  r  r  r~  r  r  r  r  r  r  r  rT  )futuresPublicGetContractsActiver  r  r  rV  rC  r  yymmdd
safe_valuer  r6  r9   
string_divr  
string_absiso8601)r7  rD  rF  r  r?  r  r  r>   r  rO   rN   rm  rn  ro  r   rk  rl  rd  rE  r.  r   r  r  r  limitAmountMinlimitAmountMaxlimitPriceMaxbaseMinSizeStringquoteMaxSizeStrings                                r9  r  zkucoin.fetch_contract_markets  s     ==fEEEEEEEE~ ~~h33q#d))$$ S	 S	A!WF!!&(33B&&v|<<F%%f.CDDLF:D%%fn==F&&v??G''0@AAH**622D++G44E,,X66FCZ%'#-6FD  #FB(?(??oofk::G%%fh77F))&,??J''
;;H&&vy99G$N%!%!1!1&-!H!H!--fmDDN%!%!1!1&-!H!H ,,VZ@@M$$($4$4V]$K$K!%)%5%5fn%M%M" $ 1 1'2DEWYj2k2k l lMM 2b2&2 2 	2
 &2 &2 72 H2 2 2 %2 2 &2 %2 6V+2  D!2" g+#2$ #))&.AA))&.AA $ 1 1'2DZ2P2P Q Q "&,,v"6"6"%%   $0055#//FF! !
  .- 
  (, 
  $//GG#//GG  $  ,,V_EEc2 2 2 2 2 2 2f r:  c                 ,  K   g }|                     |                     |                     |ddi                               |                     |                     |                     |ddi                               t          j        |  d {V }|                     |d         di           }|                     |d         di           }|                     |dg           }|                     |dg           }|                     ||          }g }	t          dt          |                    D ]}
||
         }| 
                    |d          }| 
                    |d	          }| 
                    |d
          }| 
                    |d          }|                     |          }|                     |          }|                     |          }| 
                    |d          }|dk    rdnd}|dz   |z   }||d|z   z  }| 
                    |d          }|                     |d          }| 
                    |d          }d }d}d}d}d}d}d}|d}||k    rd}nd}|dk    rd}d}n	d}d}nd}d}|	                     i d|d|d|d|d|d|d|d|d |d|d!|d|d|d"dd#|dk    d$|d%|||                     |d&          |                     |d'          |                     |d(          ||                     |          d d |                     |d)          |                     |d*          d+d |                     |d,          d-|                     |d.          |                     |d/          d-d |                     |d0          d-|                     |d1          |                     |d2          d-d3|                     |d4          |d5           | j        d6         r|                                  d {V  |	S )7NrL  rJ  rK  r   r?  r   listrd  r  r  settlementCurrencyr  r  TFrj  r  contractType
expiryTimetradingStatusr  rN   rO   rL   r>   r   rk  rl  rm  rn  ro  rE  rM   rP   rp  r  r-  re  rf  unitSizer  r  rt  r  rv  minBaseOrderSizemaxBaseOrderSizer  minQuoteOrderSizemaxQuoteOrderSizer|  
launchTimer  r  )r  utaGetMarketInstrumentrY  r  r  r\  r  r  r  r  rV  r  rC  r  r  r0  r  ) r7  rD  r  r  r?  contractDataspotDatacontractSymbolsDatar  r  r  r  r>   rm  rn  ro  r   rk  rl  	hasMarginr  rd  r  r  rp  rE  rL   rN   rO   r  r-  r.  s                                    r9  r  zkucoin.fetch_uta_markets  sN     33DKKV\H]4^4^__```B 	33DKKV_H`4a4abbcccL ".(3333333	~~ilFB77~~ilFB??>>$33"nn\62FF''2EFFq#k**++ Y	 Y	A ^F!!&(33B%%fn==F&&v??G''0DEEH**622D++G44E,,X66F((>>I$-$4$4445LCZ%'F!#,&++FNCCL&&v|<<F%%fo>>FDDDFHFG'F??!FF"G3&&!DDD#D!FFMM 2b2&2 2 	2
 &2 &2 72 H2 2 2 ,2 2 &2 %2 6S=2  H!2" &#2$ #))&.AA))&.AA $ 0 0 D D "&,,v"6"6""..vyAA!--fjAA   $#00GG! !
  $//8JKK#//8JKK 
  $#//
CC 
  $//8KLL#//8KLL  $  ,,V\BBc2 2 2 2 2 2 2f <12 	.++---------r:  Fforcec                    K   d| j         vs| j         d         |r8|                                  d{V }|                     |d          | j         d<   dS )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  Nr?  T)r0  privateGetHfAccountsOpenedr  )r7  r  r  s      r9  r  zkucoin.load_migration_statusA  sh       $$$,t*<*D*D!%!@!@!B!BBBBBBBF!%!?!?DLtr:  c                     |                      | j        dd          }d }||rd}nd}|                      |d|          }|                     |d          }||gS )Nr  FT)r  r0  r  )r7  rD  migratedloadedHfr  s        r9  handle_hf_and_paramszkucoin.handle_hf_and_paramsO  sj    dEBB ! >>&$9964((F|r:  c                   K   d}|                      |dd|          \  }}d}|r|                     |           d{V }n|                     |           d{V }|                     |dg           }|                     | j        dg d          }i }t          dt          |                    D ]8}||         }|                     |d	          }	|                     |	|          r8| 	                    |	          }
i }| 
                    |d
dg           }t          |          }t          d|          D ]/}||         }|                     |d          }|                     ||
          }|||                     |d          |d|                     |dd          |                     |d          |                     |d          |                     |                     |                     |d                              |                     |dd          |                     |dd          d|                     |dd          |                     |dd          ddd
||<   1|                     |d          }|                     |                     |                    }|dk    }|                     |	|                     |d          |
|rd nd!|||dddddd"          ||
<   :|S )#a  
        fetches all available currencies on an exchange

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-all-currencies
        https://www.kucoin.com/docs-new/rest/ua/get-currencies

        :param dict params: extra parameters specific to the exchange API endpoint
        :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
        :returns dict: an associative dictionary of currencies
        Frm   r   Nr?  brokenCurrencies)00
OPEN_ERRORHUFBDTr   currencychainsrc  chainId	chainNamewithdrawalMinFeeminWithdrawFeeisDepositEnabledisWithdrawEnabledwithdrawPrecisionwithdrawalMinSizeminWithdrawSizemaxWithdrawmaxWithdrawSizerv  depositMinSizeminDepositSize
maxDepositmaxDepositSizer   r  )
rT  r>   r?   r  rp  feer  r   r  r  r  fullNamefiatcrypto)r>   r?   r  rE  r  rT  r  r  r   rp  r  r  )rU  utaGetAssetCurrenciespublicGetCurrenciesr  r0  r  r  rV  r  r  safe_list_2network_id_to_codesafe_number_2r  r6  parse_precisionsafe_currency_structure)r7  rD  r   rF  currenciesDatar  r  r  entryr>   r  r  r  chainsLengthjchainr  networkCoderawPrecisionr  isFiats                        r9  fetch_currencieszkucoin.fetch_currencies[  sn      33F<MuVYZZV J	>F "77????????HHN "55f========H&"==>>$,8JLnLnLnooq#n--.. 3	 3	A"1%E!!%44B}}R!122 **2..DH%%eXwCCFv;;L1l++  q	**5)<<"55gtDD!! ,,UK@@'"--e5GIYZZ#~~e5GHH $u6I J J!%!2!243G3GHXHXY^`sHtHt3u3u!v!v $(#5#5e=PRc#d#d#'#5#5e]L]#^#^% %
 $(#5#5e=MO_#`#`#'#5#5e\K[#\#\$ $	 	) )%%,  ++E;??L))$*>*>|*L*LMMI!Q&F77((
;;"(6h&$ 9 9  F4LL r:  c           	        K   |                      |           d{V }|                     |dg           }g }t          dt          |                    D ]|}||         }|                     |d          }|                     |d          }|                     |          }	|                     |d          }
|                    ||
|	|	|d           }|S )a  
        fetch all the accounts associated with a profile

        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-list-spot

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `account structures <https://docs.ccxt.com/?id=account-structure>` indexed by the account type
        Nr?  r   r>   r  rE  )r>   rE  r  r  rT  )privateGetAccountsr  r  r  rV  r  r  )r7  rD  rF  r?  r  r  account	accountId
currencyIdr  rE  s              r9  fetch_accountszkucoin.fetch_accounts  s       00888888880 ~~h33q#d))$$ 	 	A1gG(($77I))':>>J**:66D##GV44DMM       r:  r  c                   K   |                                   d{V  |                     |          }d|d         i}d}|                     |          \  }}|*|                     |                                          |d<   |                     |                     ||                     d{V }|                     |di           }i }|                     |d          ||<   ||i dS )aW  
        *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>`
        Nr  r>   r  r?  withdrawMinFee)rT  r   r  )	load_marketsr  handle_network_code_and_paramsnetwork_code_to_idlowerprivateGetWithdrawalsQuotasrY  r\  r  )	r7  r  rD  r  r_  r  rF  r?  withdrawFeess	            r9  fetch_transaction_feezkucoin.fetch_transaction_fee	  s      !!!!!!!!!==&&
 "AA&IIV"#66{CCIIKKGG99$++gv:V:VWWWWWWWW~~h33!--d4DEET$
 
 	
r:  c                   K   |                                   d{V  |                     |          }d|d         i}d}|                     |          \  }}|*|                     |                                          |d<   |                     |                     ||                     d{V }|                     |d          }|                     ||          S )ag  
        fetch the fee for deposits and withdrawals

        https://www.kucoin.com/docs-new/rest/account-info/withdrawals/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>`
        Nr  r>   r  r?  )	r(  r  r)  r*  r+  r,  rY  r\  parse_deposit_withdraw_feer7  r  rD  r  r_  r  rF  r?  s           r9  fetch_deposit_withdraw_feez!kucoin.fetch_deposit_withdraw_fee<	  s       !!!!!!!!!==&&
 "AA&IIV"#66{CCIIKKGG99$++gv:V:VWWWWWWWW& ~~h//..tX>>>r:  Nr  c                 `   d|v r|d ddd d di d}|                      |dg           }t          dt          |                    D ]q}||         }|                     |                     |d          |                     |d                    }|                     |dd	          ddd d dd
|d         |<   r|S |                     |d	          }||ddd d di d}	|                     |d          }
|                     |
|                     |d                    }|d d dd
|	d         |<   |	S )Nr  F)r  r  )rT  r   r  r  r   r  r  r  r'  r  r  r  )r  r  r  r  rV  r  r  )r7  r  r  	resultNewr  r  r  networkCodeNewr  r  	networkIdr  s               r9  r0  z!kucoin.parse_deposit_withdraw_feef	  s     s?? "' 
  "&   I ^^C266F1c&kk**  q	!%!8!89I9I%QZ9[9[]a]m]mnvx~]]  "A  "A  $11%9KM]^^&+! !
  $&*   	9 	9	*%n55 ))#/?@@%# 
 "  
 
 $$S'22	--i9I9I(TZ9[9[\\&" +
 +
z;' r:  c                    |                      | j        |dd          }|                     |d|          }|                     | j        d          }|                     ||          }|Nt	          |                                          }t          | j        dz   d                    |          z             | 	                    |d          }|dk    p|dk    p|d	k    S )
NrI  r  rE  r  z' isFuturesMethod() type must be one of z, r  rO   futures)
r]  r0  rV  r\  r  keysr'   r>   joinr  )r7  
methodNamerD  rI  requestedTyper  rE  r9  s           r9  is_futures_methodzkucoin.is_futures_method	  s     ((z=RYZZ((EE6FGG>><++--..D*S SVZV_V_`dVeVe efff66**z!Otx'7OTY=NOr:  r   r  c           	         |                      |d          }|t          j        |d          }|                     |g d          }|                      |d|          }|                      |d          }|                     ||d          }|d         }|                     |dd          }|                     |d	d
          }|                     |g d          }	|                     i d|d|	d|                     |	          d|                      |d          d|                      |d          d|                     |g d          d|                      |d          d|                     |g d          d|                      |d          dd d|                      |d          d|d|dd d|                      |d          d|d |                      |d!          |||                      |d"          |d#|          S )$N
changeRate100)r&  lastTradedPrice	lastPricer)  rd  r  vol
baseVolumevolValuequoteVolume)timedatetime	timePointr   rH  highlowbid)buybestBidbestBidPrice	bidVolumebestBidSizeask)sellbestAskbestAskPrice	askVolumebestAskSizevwaprN  closer&  previousClosechangechangePricer  averageaveragePricevalue)rD  rF  	markPricerT  )	rV  r9   r  safe_string_nsafe_marketr]  safe_integer_nsafe_tickerr  )
r7  r   r  r  r&  marketIdrd  rD  rF  r   s
             r9  parse_spot_or_uta_tickerzkucoin.parse_spot_or_uta_ticker	  s   T %%fl;;
! +J>>J!!&*R*R*RSS66##FH55!!(FC88!''|DD
((]KK''0Q0Q0QRR	 !
f!
!
 Y//!
 D$$VV44	!

 4##FE22!
 4%%f.P.P.PQQ!
 ))&-@@!
 4%%f.Q.Q.QRR!
 ))&-@@!
 D!
 D$$VV44!
 T!
 D!
 T!
 d&&v}==!
  *!!
" t''??#!
$ %&))&'::+!
 !
 !
, -  	r:  c                 .    |                      ||          S N)parse_contract_ticker)r7  r   r  s      r9  parse_tickerzkucoin.parse_ticker)
  s     ))&&999r:  c           
      n   |                      |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$|          S )%Nrd  r  r)  lastTradePricetsgư>r   rH  rJ  	highPricerK  lowPricerL  rO  rP  rQ  rR  rU  rV  rW  rX  rN  rY  r&  rZ  r[  priceChgr  priceChgPctr]  volumeOf24hturnoverOf24hr`  r_  
indexPrice)rD  rF  r`  rt  rT  )rV  rb  r]  safe_integer_productrd  r  )r7  r   r  re  r&  r   s         r9  ri  zkucoin.parse_contract_ticker.
  s=   n ##FH55!!(FC88!!&'3CDD--fdHEE	 !
fX&!
!
 Y//!
 D$$V[99	!

 4##FJ77!
 4##FN;;!
 ))&-@@!
 4##FN;;!
 ))&-@@!
 D!
 D!
 T!
 D!
 T!
 d&&vz::!
  $**6=AA!!
" t#!
$ **6=AA++FODD++FKII**6<@@-!
 !
 !
. /  	r:  rE  c                 <    dddd}|                      |||          S )NrJ  MARGINrK  )rL   rM   rN   rV  )r7  rE  
tradeTypess      r9  type_to_trade_typezkucoin.type_to_trade_type
  s1    
 


 
D$777r:  r   c                   K   |                                   d{V  i }|                     |ddd          }d}|                     |ddd          \  }}|                     |d          }d}|+|                     |d          }|                     |          }d}|                     d||          \  }}d}	||rJ||                     |          |d<   |                     |                     ||                     d{V }	nC|dk    r"|d	k    r| 	                    ||           d{V S | 
                    |           d{V }	|                     |	d
i           }
|                     |
ddg           }|                     |
dd          }i }t          dt          |                    D ]E}|||         d<   |                     ||                   }|                     |d          }||||<   F|                     |d|          S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-all-tickers
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-all-tickers
        https://www.kucoin.com/docs-new/rest/ua/get-ticker

        :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
        :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
        :param str [params.type]: spot or swap(default is spot)
        :param str [params.method]: *swap only* the method to use, futuresPublicGetContractsActive or futuresPublicGetAllTickers(default is futuresPublicGetContractsActive)
        :returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/?id=ticker-structure>`
        NTr   r   FrL  r   rL   rM   r?  r   r  rG  rm  rd  )r(  market_symbolsrU  rV  r  r@  rz  utaGetMarketTickerrY  fetch_contract_tickersr  r\  r  safe_integer_2r  r  rf  filter_by_array_tickers)r7  r   rD  r_  r   rL  firstMarketfirstSymbolrE  rF  r?  tickersrG  r  r  r   rd  s                    r9  fetch_tickerszkucoin.fetch_tickers
  sf      !!!!!!!!!%%gtT4@@33FNESXYYV$$V[99	**7A66K++k22K99.+W]^^f!c! '+'>'>t'D'D$!44T[[&5Q5QRRRRRRRRHH6 fnn48#3#344WfEEEEEEEEE!;;FCCCCCCCCH: ~~h33""462>>""466q#g,,'' 	( 	(A!%GAJv2271:>>F%%fh77F!!'v++FHgFFFr:  c                 D  K   d }|                      |ddd          \  }}d }|dk    r|                     |           d {V }n|                     |           d {V }|                     |d          }|                     ||          }|                     |d|          S )Nr   methodr  futuresPublicGetAllTickersr?  rd  )rU  r  r  r  parse_tickersr  )r7  r   rD  r  rF  r?  r  s          r9  r~  zkucoin.fetch_contract_tickers  s      66v~xYz{{111!<<VDDDDDDDDHH!AA&IIIIIIIIH~ ~~h//$$T733++GXwGGGr:  c                    K   |                                   d{V  |                     |          }|                     |           d{V }|                     |dg           }|                     |          S )a  
        fetches the mark price for multiple markets

        https://www.kucoin.com/docs-new/rest/margin-trading/market-data/get-mark-price-list

        :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>`
        Nr?  )r(  r|  publicGetMarkPriceAllSymbolsr  r  r7  r   rD  rF  r?  s        r9  fetch_mark_priceszkucoin.fetch_mark_pricesZ  s       !!!!!!!!!%%g..::6BBBBBBBB~~h33!!$'''r:  rd  c                   K   |                                   d{V  |                     |          }d|d         i}d}|                     |ddd          \  }}d}d}d}|                     d||          \  }}|r|                     |          |d<   |                     |                     ||                     d{V }|                     |di           }	|                     |	d	g           }
|                     |
d
i           }n|d         r\| 	                    |                     ||                     d{V }|                     |di           }	| 
                    |	|          S |                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-24hr-stats
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-ticker
        https://www.kucoin.com/docs-new/rest/ua/get-ticker

        :param str symbol: unified symbol of the market to fetch the ticker for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
        :returns dict: a `ticker structure <https://docs.ccxt.com/?id=ticker-structure>`
        Nrd  r>   r   r   FrL  r?  r  r   r  )r(  r  rU  r@  rz  r}  rY  r\  r  futuresPublicGetTickerrj  publicGetMarketStatsrf  )r7  rd  rD  r  r_  r   rF  r  rE  r?  
resultLists              r9  fetch_tickerzkucoin.fetch_tickerj  s      !!!!!!!!!V$$fTl
 33FM5RWXXV99-QWXXf O	:#'#:#:4#@#@GK !44T[[&5Q5QRRRRRRRRH6 >>(FB77Dfb99J^^J266FFJ /	:!88Wf9U9UVVVVVVVVH& >>(FB77D$$T6222!66t{{7F7S7STTTTTTTTH0 ^^Hfb99F,,VV<<<r:  c                   K   |                                   d{V  |                     |          }d|d         i}d}|d         r\|                     |                     ||                     d{V }|                     |di           }|                     ||          S |                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetches the mark price for a specific market

        https://www.kucoin.com/docs-new/rest/margin-trading/market-data/get-mark-price-detail
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/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>`
        Nrd  r>   r  r?  )r(  r  &futuresPublicGetMarkPriceSymbolCurrentrY  r\  rj  publicGetMarkPriceSymbolCurrentrf  r7  rd  rD  r  r_  rF  r?  s          r9  fetch_mark_pricezkucoin.fetch_mark_price  s       !!!!!!!!!V$$fTl
 * 	?!HHU\^dIeIeffffffffH>>(FB77D$$T6222!AA$++gW]B^B^________H>>(FB77D00v>>>r:  c           	      X   |                      |d          }|t          |          dk    r|                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          gS )Nr   r   r   r   r   r   r   )rV  r  safe_timestampr  rC  )r7  ohlcvr  timestampStrings       r9  parse_ohlcvzkucoin.parse_ohlcv  s-    **5!44&3+?+?2+E+E ##E1--  **  **  **  **  **  !!%++  **  **  **  **  ** r:  r%  	timeframesincer  c                 l  K   |                                   d{V  |                     |          }d}|                     |ddd          \  }}|r|                     |||||           d{V S |d         r|                     |||||           d{V S |                     |||||           d{V S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-klines
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-klines
        https://www.kucoin.com/docs-new/rest/ua/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.uta]: set to True for the unified trading account(uta), defaults to False
        :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
        Nr   r   Fr  )r(  r  rU  fetch_utaohlcvfetch_contract_ohlcvfetch_spot_ohlcv)r7  rd  r  r  r  rD  r  r   s           r9  fetch_ohlcvzkucoin.fetch_ohlcv  s     " !!!!!!!!!V$$33FL%QVWWV 	X,,VYufUUUUUUUUUJ 	X2269eUTZ[[[[[[[[[..vy%PVWWWWWWWWWr:  c           	        K   |                                   d{V  d}d}|                     |dd          \  }}|r!|                     d||||||           d{V S |                     |          }|d         |                     | j        ||          d}	|                     |          d	z  }
|                                 }d	}|r|                     t          t          j        ||z                                |	d
<   ||                     | j        d|          }|                     |||
z            }nD|B|||
z  z
  }|                     t          t          j        ||z                                |	d
<   |                     t          t          j        ||z                                |	d<   d}|                     d||          \  }}|dk    s|dk    rd|	d<   nd|	d<   |                     |                     |	|                     d{V }|                     |di           }|                     |dg           }|                     |||||          S )aD  
 @ignore
        helper method for fetchOHLCV

        https://www.kucoin.com/docs-new/rest/ua/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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr#  Fr   paginatefetchUTAOHLCVr>   )rd  intervalr*  startAtfetchOHLCVLimitendAtrL   rM   rJ  rL  rK  r?  r  )r(  rU  "fetch_paginated_call_deterministicr  rV  r  parse_timeframer<  parse_to_intintmathfloorrC  r0  r  r@  utaGetMarketKlinerY  r\  r  parse_ohlcvs)r7  rd  r  r  r  rD  maxLimitr  r  r_  durationr  denominatorrE  rF  r?  r  s                    r9  r  zkucoin.fetch_utaohlcv,  s      !!!!!!!!!88zZZ& 	E@@RXZ_afhqsy  |D  E  E  E  E  E  E  E  E  EV$$Tl(()YOO
 
 ''	22T9!!##!%!2!23tz%+BU7V7V3W3W!X!XGI} ))$,8I8TTHHUEH$455EEEH,,E!%!2!23tz%+BU7V7V3W3W!X!XGI,,SEK<O1P1P-Q-QRR99,PVWWfFNN 0 0#)GK  #,GK //GV0L0LMMMMMMMM ~~h33fb11  E5IIIr:  c           	      .  K   |                                   d{V  d}d}|                     |dd          \  }}|r!|                     d||||||           d{V S |                     |          }|d         |                     | j        ||          d}	|                     |          d	z  }
|                                 }d	}|r|                     t          t          j        ||z                                |	d
<   ||                     | j        d|          }|                     |||
z            }nD|B|||
z  z
  }|                     t          t          j        ||z                                |	d
<   |                     t          t          j        ||z                                |	d<   |                     |                     |	|                     d{V }|                     |dg           }|                     |||||          S )aZ  
 @ignore
        helper method for fetchOHLCV

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        Nr#  Fr   r  fetchSpotOHLCVr>   )rd  rE  r*  r  r  r  r?  )r(  rU  r  r  rV  r  r  r<  r  r  r  r  rC  r0  r  publicGetMarketCandlesrY  r  r  )r7  rd  r  r  r  rD  r  r  r  r_  r  r  r  rF  r?  s                  r9  r  zkucoin.fetch_spot_ohlcvl  sg      !!!!!!!!!88zZZ& 	F@@AQSY[`bgirtz  }E  F  F  F  F  F  F  F  F  FV$$Tl$$T_iKK
 
 ''	22T9!!##!%!2!23tz%+BU7V7V3W3W!X!XGI} ))$,8I8TTHHUEH$455EEEH,,E!%!2!23tz%+BU7V7V3W3W!X!XGI,,SEK<O1P1P-Q-QRR44T[[&5Q5QRRRRRRRR ~~h33  vy%GGGr:  c           	      b  K   |                                   d{V  d}d}|                     |dd          \  }}|r!|                     d||||||           d{V S |                     |          }d|d         i}	|                     | j        d	i           }
|                     |
d
i           }|                     ||          }|||	d<   n||	d<   |                     |          dz  }|                                 }|=||	d<   ||                     | j        d|          }| 	                    |||z            }n||||z  z
  }||	d<   ||	d<   | 
                    |                     |	|                     d{V }|                     |dg           }|                     |||||          S )a]  
 @ignore
        helper method for fetchOHLCV

        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/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
        :returns int[][]: A list of candles ordered, open, high, low, close, volume
        N   Fr   r  fetchContractOHLCVrd  r>   r  rN   granularityr*  fromr  tor?  )r(  rU  r  r  r\  r0  rC  r  r<  r  futuresPublicGetKlineQueryrY  r  r  )r7  rd  r  r  r  rD  r  r  r  r_  timeframeOptionsswapTimeframesparsedTimeframer  r  rF  r?  s                    r9  r  zkucoin.fetch_contract_ohlcv  s6      !!!!!!!!!88zZZ& 	J@@AUW]_dfkmvx~  AI  J  J  J  J  J  J  J  J  JV$$fTl
  >>$,bII(8&"EE++NIFF&%4GM""%.GM"''	22T9!!###GFO} ))$,8I8TTHHUEH$455EEEH,,E#GFO88Wf9U9UVVVVVVVV ~~h33  vy%GGGr:  c                   K   |                                   d{V  |                     |          }d|d         i}d}|                     |          \  }}||                     |          |d<   |                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  

        https://www.kucoin.com/docs-new/rest/account-info/deposit/add-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>`
        Nr  r>   r  r?  )r(  r  r)  r*  privatePostDepositAddressCreaterY  r\  parse_deposit_addressr1  s           r9  create_deposit_addresszkucoin.create_deposit_address  s       !!!!!!!!!==&&
 "AA&IIV"#66{CCGG==dkk'SY>Z>Z[[[[[[[[  ~~h33))$999r:  c                 ~  K   |                                   d{V  d}|                     |dd|          \  }}|                     | j        di           }|                     |||          }|dk    r|                     ||           d{V S |                     |          }d|d         i}d}|                     |          \  }}|*|                     |          	                                |d	<   | j        d
         d         d         d         }d| j        d
         d         d         d<   | 
                    |                     ||                     d{V }	|| j        d
         d         d         d<   |                     |	d          }
|
t          | j        dz             |                     |
|          S )a'  
        fetch the deposit address for a currency associated with self account

        https://www.kucoin.com/docs-new/rest/account-info/deposit/get-deposit-address-v3/en

        :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
        :param str [params.accountType]: 'main' or 'contract'(default is 'main')
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        Nr  rn   accountTyper  r  r  r>   r  r  r   r  r   r  r?  zr fetchDepositAddress() returned an empty response, you might try to run createDepositAddress() first and try again)r(  rU  r\  r0  rV  fetch_contract_deposit_addressr  r)  r*  r+  privateGetDepositAddressesrY  r  r'   r>   r  )r7  r  rD  r  r  r  r_  r  rD   rF  r?  s              r9  fetch_deposit_addresszkucoin.fetch_deposit_address  s      !!!!!!!!!";;FDY[hjuvvV6FKK&&~{KPP*$$<<T6JJJJJJJJJ==&&
 "AA&IIV"#66{CCIIKKGG,z*95e<=PQJNZ +E23FG88Wf9U9UVVVVVVVV KRZ +E23FGx00<  +_  !_  `  `  `))$999r:  c                   K   |                                   d{V  |                     |          }|d         }d|i}|                     |                     ||                     d{V }|                     |di           }|                     |d          }|dk    r|                     |           |||                     |d          ||                     |d          d	S )
a  
        fetch the deposit address for a currency associated with self account

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

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/?id=address-structure>`
        Nr>   r  r?  addressNIMr  memorT  r  networkr  tag)r(  r  futuresPrivateGetDepositAddressrY  r\  rV  check_address)	r7  r  rD  r  r$  r_  rF  r?  r  s	            r9  r  z%kucoin.fetch_contract_deposit_address+  s      !!!!!!!!!==&&d^


 ==dkk'SY>Z>Z[[[[[[[[ ~~h33""433w'''"''g66##D&11
 
 	
r:  c                 X   |                      |d          }||                    dd          }d }|6|                     |d                   }|dk    r|                     |           |||                     |                      |d                    ||                      |d          dS )	Nr  zbitcoincash:r  r>   r  r  r  r  )rV  replacer  r  r  )r7  depositAddressr  r  r  s        r9  r  zkucoin.parse_deposit_addressR  s    "">9==oonb99G**8D>::Du}}""7+++"..t/?/?PY/Z/Z[[##NF;;
 
 	
r:  c                 ,  K   |                                   d{V  |                     |          }d|d         i}| j        d         d         d         d         }d| j        d         d         d         d<   |                     |                     ||                     d{V }|| j        d         d         d         d<   |                     |d	g           }|                     ||d
         gdd|d
         i          }|                     |d          S )a  

        https://www.kucoin.com/docs-new/rest/account-info/deposit/get-deposit-address-v3/en

        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>`
        Nr  r>   r  r   r  r   rE   r?  r  Fr  )r(  r  r0  r  rY  r  parse_deposit_addressesr  )	r7  r  rD  r  r_  rD   rF  r  parseds	            r9  "fetch_deposit_addresses_by_networkz)kucoin.fetch_deposit_addresses_by_networke  s8      !!!!!!!!!==&&
 ,z*95e<=PQJNZ +E23FG88Wf9U9UVVVVVVVV  KRZ +E23FG&"55--fx7G6H%(R
   }}VY///r:  c           
        K   |                                   d{V  |                     |          }|                     |dd          }d|d         i}|                     d          }d}|                     |ddd          \  }}d}	d}
|                     d||          \  }
}|rq|t          | j        d	z             ||d
<   |d         |d<   |
dk    s|
dk    rd|d<   nd|d<   |                     | 	                    ||                     d{V }	nR|
dk    r|
dk    r|dk    r|t          | j        dz             ||dk    r0|                     | 	                    ||                     d{V }	n|dk    r0|                     | 	                    ||                     d{V }	nt          | j        dz             |r|o|dk    r9||d<   |)|dk    s|dk    r||d
<   nt          | j        dz             |r|nd|d
<   |                     | 	                    ||                     d{V }	n/|                     | 	                    ||                     d{V }	|                     |	di           }|                     |d          }|0|                     |d          }||                     |dz            }|                     ||d         |dd|dz
  |dz
            }|                     |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-new/rest/spot-trading/market-data/get-part-orderbook
        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-full-orderbook
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-part-orderbook
        https://www.kucoin.com/docs-new/rest/ua/get-orderbook

        :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
        :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
        :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/?id=order-book-structure>` indexed by market symbols
        Nlevelr   rd  r>   Fr   r   zO fetchOrderBook() requires a limit argument for uta, either 20, 50, 100 or FULLr  rL   rM   rJ  rL  rK  z) fetchOrderBook() can only return level 2r   d   z2 fetchOrderBook() limit argument must be 20 or 100r?  rG  rm  @B bidsasksr   sequencer=  )r(  r  rC  r  rU  r@  r+   r>   utaPrivateGetMarketOrderbookrY  r,   futuresPublicGetLevel2Depth20futuresPublicGetLevel2Depth100r'   'publicGetMarketOrderbookLevelLevelLimitprivateGetMarketOrderbookLevel2r\  r  parse_order_book)r7  rd  r  rD  r  r  r_  isAuthenticatedr   rF  rE  r?  r   nanoseconds	orderbooks                  r9  fetch_order_bookzkucoin.fetch_order_book  s      !!!!!!!!!V$$!!&'155!6$<099%@@33F<LeUZ[[V99:JFTZ[[f B	`}'  3D  )D  E  E  E$GG &tGHDH$4$4'-$$'0$!>>t{{7TZ?[?[\\\\\\\\HH& fnn48#3#3zze/ +V!VWWW%2++& "&!C!CDKKPWY_D`D`!a!aaaaaaa#!%!D!DT[[QXZ`EaEa!b!bbbbbbb +_!_```  	`E$5zz#( $#+0((+DG6j,jkkk,1#:55s !II$++V]_eJfJfggggggggHH!AA$++gW]B^B^________H@ ~~h33%%dF33	++D$77K& --kG.CDD	))$x0@)VU[]bef]fhmpqhqrr	!..tZ@@	'r:  c                     |                      |dd          }|                     |d          }|                     |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'   r>   )r7  rD  r  r  r  
isStopLossisTakeProfits          r9  handle_trigger_priceszkucoin.handle_trigger_prices  s    ((MM@@//&2CDD"$.
&d2 	E< 	E\ 	Em 	EQ] 	Ebn 	E  +D  !D  E  E  Em_==r:  sideru  r)  c                 D  K   |                                   d{V  |                     |          }|d         r |                     ||||||           d{V S |d         r |                     ||||||           d{V S t	          | j        dz   |d         z             )a  
        Create an order on the exchange

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order-sync
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order-test
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-stop-order
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-order-test
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-stop-order
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order-test
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-take-profit-and-stop-loss-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
 Check createSpotOrder() and createContractOrder() for more details on the extra parameters that can be used in params
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NrL   r  z' createOrder() does not support market rE  )r(  r  create_spot_ordercreate_contract_orderr3   r>   )r7  rd  rE  r  ru  r)  rD  r  s           r9  create_orderzkucoin.create_order  s      0 !!!!!!!!!V$$&> 	e//dFESYZZZZZZZZZJ 	e33FD$PUW]^^^^^^^^^tw)RRU[\bUccdddr:  c                 &  K   |                                   d{V  |                     |          }|                     |dd          }|                     |d          }d}	|                     |          \  }	}d}
|                     |ddd          \  }
}|                     |          \  }}}|                     |d          }|p|p|}|                     d|          }|                     |d          }|dk    p|du}| 	                    ||||||          }d}|rx|r<|	r| 
                    |           d{V }n&|                     |           d{V }n	|	r|                     |           d{V }n|                     |           d{V }n|r:|r|                     |           d{V }n|                     |           d{V }n|r:|	r|                     |           d{V }ns|                     |           d{V }nW|
r|                     |           d{V }n9|	r|                     |           d{V }n|                     |           d{V }|                     |d	i           }|                     ||          S )
a  
        helper method for creating spot orders

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order-sync
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order-test
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-stop-order
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-order-test
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-stop-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>`
        NtestFr]   syncrL  r   r  r?  )r(  r  r  r  r  rU  r  rV  handle_margin_mode_and_paramscreate_spot_order_requestprivatePostHfMarginOrderTestprivatePostMarginOrderTestprivatePostHfOrdersTestprivatePostOrdersTestprivatePostHfMarginStopOrderprivatePostStopOrderprivatePostHfMarginOrderprivatePostMarginOrderprivatePostHfOrdersSyncprivatePostHfOrdersprivatePostOrdersr\  parse_order)r7  rd  rE  r  ru  r)  rD  r  	testOrderr  useSyncr  r  r  rL  isTriggerOrdermarginResultr  isMarginOrderorderRequestrF  r?  s                         r9  r  zkucoin.create_spot_order=  sx     Z !!!!!!!!!V$$NN66599	66**..v66
F77vW\]]7;7Q7QRX7Y7Y4m_$$V[99	&J-J?99-PP%%lA66
!^3Mz7M55fdD&RWY_`` 	B J S%)%F%F|%T%TTTTTTTHH%)%D%D\%R%RRRRRRRHH J!%!=!=l!K!KKKKKKK!%!;!;L!I!IIIIIII 	B I!%!B!B<!P!PPPPPPP!%!:!:<!H!HHHHHHH 
	B K!%!>!>|!L!LLLLLLL!%!<!<\!J!JJJJJJJ 	B!99,GGGGGGGGHH 	B!55lCCCCCCCCHH!33LAAAAAAAAH ~~h33f---r:  c                    |                      |          }|                     |dd|                                           }|                     |ddg          }|||d         |d}	|                     |dd          }
d }d }d }|                     d|          \  }}|dk    rf|
4|                     |ddg          }|                     ||
          }||	d<   nd|                     ||          }|                     ||          |	d	<   n4|                     ||          }||	d	<   |                     ||          |	d
<   | 	                    |d          }| 
                    |          \  }}}|p|p|}|dk    p|d u}|                     |g d          }|r|r|                     ||          |	d<   nS|s|rO|r'|dk    rdnd|	d<   |                     ||          |	d<   n&|dk    rdnd|	d<   |                     ||          |	d<   |dk    rt          | j        dz             |dk    r| j        d         |         |	d<   n|r|dk    rd|	d<   d }|                     |dk    d|          \  }}|rd|	d<   |                     |	|          S )N	clientOidclientOrderIdr>   )r  r  rd  rE  r}  fundsr]   r  sizer)  rL  r  )r  r  r  r  r  rM  r  lossstopr  z= createOrder does not support isolated margin for stop ordersr  r  marginModelFTpostOnly)r  r]  uuidr  r  r   market_order_amount_to_precisionamount_to_precisionprice_to_precisionrV  r  r,   r>   r0  handle_post_onlyrY  )r7  rd  rE  r  ru  r)  rD  r  r  r_  quoteAmountamountString
costStringr  rL  r  r  r  r
  r  r  s                        r9  r  z kucoin.create_spot_order_request  s$   V$$**6;QUQZQZQ\Q\]]6K#ABB&Tl	
 
 ((AA

!??vVV
F8&6FG+<==!BB6;WW
#-  #77GG"&":":66"J"J33FFCCL*GFO#66vuEEGG$$V[99	7;7Q7QRX7Y7Y4m_&J-J?!^3Mz7M6#d#d#dee 	4 \'+'>'>v|'T'T$$ \/ \  \26%--ggfGFO+/+B+B6=+Y+YGK((15ffWGFO+/+B+B6?+[+[GK(Z'' +j!jkkkw&&'+|M'B:'N$ 	4Z'')3&001A5&QQ& 	'"&GJ{{7F+++r:  c                 .   |                      |          }|                     |t          |d         d         | j        | j                  }|dk    rEt          | j        dz   |d         z   dz   |                     |d         d                   z             |S )	NrT  quoteIncrementr  z amount of rd  z2 must be greater than minimum amount precision of r  ru  )r  decimal_to_precisionr7   r3  paddingModer1   r>   number_to_string)r7  rd  ru  r  r  s        r9  r  z'kucoin.market_order_amount_to_precision  s    V$$**68VF^L\=]_c_qsw  tD  E  ES==tw69II  MA   A  DH  DY  DY  Z`  al  Zm  nv  Zw  Dx  Dx   x  y  y  yr:  c                 ^  K   |                                   d{V  |                     |          }|                     |dd          }|                     |d          }|                     |d          dup|                     |d          du}	|                     ||||||          }
d}|r|                     |
           d{V }n9|	r|                     |
           d{V }n|                     |
           d{V }| 	                    |di           }| 
                    ||          S )a  
        helper method for creating contract orders

        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order-test
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-take-profit-and-stop-loss-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 dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered and the triggerPriceType
        :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered and the triggerPriceType
        :param float [params.triggerPrice]: The price a trigger order is triggered at
        :param float [params.stopLossPrice]: price to trigger stop-loss orders
        :param float [params.takeProfitPrice]: price to trigger take-profit orders
        :param bool [params.reduceOnly]: A mark to reduce the position size only. Set to False by default. Need to set the position size when reduceOnly is True.
        :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
        :param float [params.cost]: the cost of the order in units of USDT
        :param str [params.marginMode]: 'cross' or 'isolated', default is 'isolated'
        :param bool [params.hedged]: *swap and future only* True for hedged mode, False for one way mode, default is False
 ----------------- Exchange Specific Parameters -----------------
        :param float [params.leverage]: Leverage size of the order(mandatory param in request, default is 1)
        :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.stop]: 'up' or 'down', the direction the triggerPrice is triggered from, requires triggerPrice. down: Triggers when the price reaches or goes below the triggerPrice. up: Triggers when the price reaches or goes above the triggerPrice.
        :param str [params.triggerPriceType]: "last", "mark", "index" - defaults to "mark"
        :param str [params.stopPriceType]: exchange-specific alternative for triggerPriceType: TP, IP or MP
        :param bool [params.closeOrder]: set to True to close position
        :param bool [params.test]: set to True to use the test order endpoint(does not submit order, use to validate params)
        :param bool [params.forceHold]: A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to False by default.        :param str [params.positionSide]: *swap and future only* hedged two-way position side, LONG or SHORT
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  FstopLoss
takeProfitr?  )r(  r  r  r  r  create_contract_order_requestfuturesPrivatePostOrdersTestfuturesPrivatePostStOrdersfuturesPrivatePostOrdersr\  r  )r7  rd  rE  r  ru  r)  rD  r  r  hasTpOrSlOrderr  rF  r?  s                r9  r  zkucoin.create_contract_order  sz     L !!!!!!!!!V$$NN66599	66**//&*==TI  Bt_egsOtOt  }A  PA99&$fV[]cdd 	M!>>|LLLLLLLLHH M!%!@!@!N!NNNNNNN!%!>!>|!L!LLLLLLL ~~h33f---r:  c                 P	   |                      |          }|                     |dd|                                           }|                     |ddg          }|||d         |dd}	|                     |d          }
|
|                     |d          }|
|	d<   |                     |d          }|                     |d          }||                     ||          |	d<   nC|dk     rt          | j        d	z             t          | 
                    ||                    |	d
<   |                     |          \  }}}|                     |d          }|                     |d          }|d u}|d u}dddd}|                     |dd          }|                     |||          }|                     |g d          }|r-|dk    rdnd|	d<   |                     ||          |	d<   ||	d<   n)|s|r|}|r^|                     |dd          }|                     ||          |	d<   |                     |dd          }|                     |||          }|r^|                     |dd          }|                     ||          |	d<   |                     |dd          }|                     |||          }||	d<   n]|s|rY|r'|dk    rdnd|	d<   |                     ||          |	d<   n&|dk    rdnd|	d<   |                     ||          |	d<   d|	d<   ||	d<   |                                }|                     |d           }|d!k    r9|t          | j        d"z             |                     ||          |	d#<   |||	d <   d }|                     |d$k    d%|          \  }}|rd|	d&<   |                     |d'          }|r|t%          | j        d(z             |                     |d)          }|r/|                     |d*          }|t          | j        d+z             |                     |dd%          }d } |                     |d,d%          \  } }|r||	d<   | r|d-k    rd.nd/}!|!|	d0<   n| r|dk    rd.nd/}"|"|	d0<   |                     |g d1          }|                     |	|          S )2Nr  r  r>   r   )r  r  rd  rE  r  r  r}  valueQtyz1 createOrder() minimum contract order amount is 1r  r%  r&  MPTPIP)r'  r&  r(  r  r'  )r  r  r  r  r&  r%  rM  updownr  r  stopPriceTyper  triggerStopDownPricer  triggerStopUpPriceT
reduceOnlyr  LIMITz9 createOrder() requires a price argument for limit ordersr)  r  Fr  hiddenzW createOrder() does not support the postOnly parameter together with a hidden parameterr  visibleSizezB createOrder() requires a visibleSize parameter for iceberg ordersr  rS  LONGSHORTpositionSide)r  r  r  r  r  r6  r  )r  r]  r  r  rW  rV  cost_to_precisionr1   r>   r  r  r  r\  r  upperr+   r  r  r,   r  handle_param_boolrY  )#r7  rd  rE  r  ru  r)  rD  r  r  r_  marginModeUpperr}  r  r  r  r%  r&  hasStopLosshasTakeProfittriggerPriceTypesr  triggerPriceTypeValue	priceTypeslPricetpPriceuppercaseTyper  r  r8  r  r9  r6  r  reduceOnlyPosSideposSides#                                      r9  r'  z$kucoin.create_contract_order_request  s   V$$**6;QUQZQZQ\Q\]]6K#ABB&Tl
 
 00FF&YYv|44F$3GL!//66**"&"8"8"F"FGJzz"47-`#`aaa!$":":66"J"JKKGFO7;7Q7QRX7Y7Y4m_>>&*55^^FL99
d*"$. #
 #

  ++F4FOO $ 0 01BDTVf g g6#~#~#~ 	='+u}}dd6GFO#'#:#:6<#P#PGK '<GO$$ 	=M 	=-I V,,X~{SS262I2I&RY2Z2Z./ ,,X7I6RR	 ,,->	9UU	 V,,ZIZ[[040G0GPW0X0X,- ,,Z9KVTT	 ,,->	9UU	'0GO$$ 	=o 	= X+/5==$$v'+'>'>v}'U'U$$-1U]]&&'+'>'>v'W'W$$(GL!'<GO$

,,V]CCG##}'2m(mnnn#'#:#:65#I#I &)4&001A5&QQ& 	'"&GJ22 	B+TW  (A  A  B  B  B//&)44 	x//&-@@K"'2v(vwww^^FL%@@
//%HH 	2$.GL! </3v~~FFG!*;' 2%)U]]&&*1'6  $L  $L  $L  M  M{{7F+++r:  r}  c                    K   |                                   d{V  d|i}|                     |d||d|                     ||                     d{V S )ab  
        create a market order by providing the symbol, side and cost

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-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>`
        Nr}  r  )r(  r  rY  )r7  rd  r  r}  rD  reqs         r9  create_market_order_with_costz$kucoin.create_market_order_with_cost  sz       !!!!!!!!!D
 &&vxtT4;;WZ\bKcKcdddddddddr:  c                 v   K   |                                   d{V  |                     |d||           d{V S )a7  
        create a market buy order by providing the symbol and cost

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-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>`
        NrM  r(  rM  r7  rd  r}  rD  s       r9  !create_market_buy_order_with_costz(kucoin.create_market_buy_order_with_cost  sX       !!!!!!!!!77tVTTTTTTTTTr:  c                 v   K   |                                   d{V  |                     |d||           d{V S )a8  
        create a market sell order by providing the symbol and cost

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-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>`
        NrS  rO  rP  s       r9  "create_market_sell_order_with_costz)kucoin.create_market_sell_order_with_cost  sX       !!!!!!!!!77fUUUUUUUUUr:  r   c                 
  K   |                                   d{V  d}d}t          dt          |                    D ]X}|                     ||          }|                     |d          }|                     |          }|d         rd}N|d         rd}Y|r|rt          | j        dz             |r|                     ||           d{V S |r| 	                    ||           d{V S t          | j        d	z             )
a  
        create a list of trade orders

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-add-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-add-orders-sync

        :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
 Check createSpotOrders() and createContractOrders() for more details on the extra parameters that can be used in params
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        NFr   rd  rL   Tr  zA createOrders() requires all orders to be either spot or contractzC createOrders() does not support the markets of the orders provided)r(  r  r  r\  rV  r  r,   r>   create_spot_orderscreate_contract_ordersr3   )	r7  r   rD  isSpot
isContractr  orderrd  r  s	            r9  create_orderszkucoin.create_orders  sS      !!!!!!!!!
q#f++&& 	" 	"ANN61--E%%eX66F[[((Ff~ "
# "!
 	pj 	pTW'jjkkk 	p00@@@@@@@@@ 	p44VVDDDDDDDDDtw)nnooor:  c           	        K   |                                   d{V  g }d}t          dt          |                    D ]}||         }|                     |d          }||}n||k    rt	          | j        dz             |                     |d          }|dk    rt	          | j        dz             |                     |d          }	|                     |d	          }
|                     |d
          }|                     |di           }|                     |||	|
||          }|                    |           | 	                    |          }|d         |d}d}| 
                    |          \  }}d}|                     |ddd          \  }}d}|r0|                     |                     ||                     d{V }na|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }|                     |dg           }|                     |          S )a%  
        helper method for creating spot orders in batch

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-add-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-add-orders-sync
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/batch-add-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   rd  z; createOrders() requires all orders to have the same symbolrE  r  z* createOrders() only supports limit ordersr  ru  r)  rD  r>   )rd  	orderListFr^   r  r?  )r(  r  r  rV  r,   r>   r  r  r  r  r  rU  privatePostHfOrdersMultiSyncrY  privatePostHfOrdersMultiprivatePostOrdersMultir\  r  parse_orders)r7  r   rD  ordersRequestsrd  r  rawOrderre  rE  r  ru  r)  orderParamsr  r  r_  r  r	  rF  r?  s                       r9  rU  zkucoin.create_spot_orders  s      !!!!!!!!!q#f++&& 	0 	0AayH''(;;H~!X%%$TW/l%lmmm##Hf55Dw +W!WXXX##Hf55D__Xx88FOOHg66E//(HbAAK99(D$PVX]_jkkL!!,////V$$Tl'
 
 ..v66
F77PVX]^^ 	W!>>t{{7TZ?[?[\\\\\\\\HH 	W!::4;;wPV;W;WXXXXXXXXHH!88Wf9U9UVVVVVVVVH> ~~h33~~dFB//  &&&r:  c           	        K   |                                   d{V  g }t          dt          |                    D ]}||         }|                     |d          }|                     |          }|                     |d          }|                     |d          }	|                     |d          }
|                     |d          }|                     |di           }|                     |d	         ||	|
||          }|                    |           |                     |           d{V }| 	                    |d
g           }| 
                    |          S )a  
        helper method for creating contract orders in batch

        https://www.kucoin.com/docs-new/rest/futures-trading/orders/batch-add-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
        :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   rd  rE  r  ru  r)  rD  r>   r?  )r(  r  r  rV  r  r  r'  r  futuresPrivatePostOrdersMultir  r`  )r7  r   rD  ra  r  rb  rd  r  rE  r  ru  r)  rc  r  rF  r?  s                   r9  rV  zkucoin.create_contract_orders(  sp      !!!!!!!!!q#f++&& 
	0 
	0AayH%%h99F[[((F##Hf55D##Hf55D__Xx88FOOHg66E//(HbAAK==fTlDRVX^`egrssL!!,////;;NKKKKKKKK, ~~h33  &&&r:  r>   c                   K   |                                   d{V  |                     |          }d|d         i}	|                     |dd          }
|
|
|	d<   n||	d<   ||                     ||          |	d<   ||                     ||          |	d<   |                     |                     |	|                     d{V }|                     |d	i           }|                     ||          S )
aS  
        edit an order, kucoin currently only supports the modification of HF orders

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/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>`
        Nrd  r>   r  r  orderIdnewSizenewPricer?  )	r(  r  r]  r  r  privatePostHfOrdersAlterrY  r\  r  )r7  r>   rd  rE  r  ru  r)  rD  r  r_  r  rF  r?  s                r9  
edit_orderzkucoin.edit_orderX  s#       !!!!!!!!!V$$fTl
 **6;PP$#0GK  !#GI!%!9!9&&!I!IGI"&"9"9&%"H"HGJ66t{{7F7S7STTTTTTTT ~~h33f---r:  c                 0  K   |                                   d{V  d}d}||                     |          }|                     d||          \  }}|dk    s|dk    r|                     |||           d{V S |                     |||           d{V S )a  
        cancels an open order

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-orderld
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-orderld-sync
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-clientoid-sync
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-stop-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-stop-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-stop-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-stop-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-order-by-orderld
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-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 str [params.type]: 'spot' or 'swap', used if symbol is not provided(default is 'spot')
        :param str [params.marginMode]: *spot only* 'cross' or 'isolated'
 Check cancelSpotOrder() and cancelContractOrder() for more details on the extra parameters that can be used in params
        :returns: Response from the exchange
        NrU   rL   rM   )r(  r  r@  cancel_spot_ordercancel_contract_orderr7  r>   rd  rD  
marketTyper  s         r9  cancel_orderzkucoin.cancel_order  s      2 !!!!!!!!!
[[((F!??vW]^^
F&  jH&<&<//FFCCCCCCCCC33BGGGGGGGGGr:  c                 8	  K   |                                   d{V  i }|                     |dd          }|                     |ddd          }d}|                     |          \  }}d}|                     |ddd          \  }}d}	|                     d	|          \  }	}|                     |d
          }
|
dk    p|	du}|s|s|r;|s9|t          | j        dz             | 	                    |          }|d         |d<   d}| 
                    |g d          }|||d<   |r|r|                     |                     ||                     d{V }|                     |d          }|                     |dg           }|                     |d          }|                     ||d          S |                     |                     ||                     d{V }n|r0|                     |                     ||                     d{V }n|r0|                     |                     ||                     d{V }na|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d          }|                     |          S ||d<   |rc|r1|                     |                     ||                     d{V }n|                     |                     ||                     d{V }n|r0|                     |                     ||                     d{V }n|r0|                     |                     ||                     d{V }n|rZ|                     |                     ||                     d{V }|                     |d          }|                     |          S |                     |                     ||                     d{V }|                     |d          }|                     |d          }|                     |dg           }|                     |d|          }|                     ||d          S )a  
        helper method for cancelling spot orders

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-orderld
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-orderld-sync
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-clientoid-sync
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-stop-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-stop-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-stop-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-stop-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
        :param str [params.marginMode]: 'cross' or 'isolated'
        :returns: Response from the exchange
        Nr  r  r  r   FrU   r  r]   rL  r  z8 cancelOrder() requires a symbol parameter for hf ordersr>   rd  )r  r  r  r   rL  r?  cancelledOrderIdsr   )rT  r>   rg  )r(  r]  safe_bool_2r  rU  r  rV  r+   r>   r  r  /privateDeleteHfMarginStopOrderCancelByClientOidrY  r\  r  
safe_order,privateDeleteStopOrderCancelOrderByClientOid/privateDeleteHfMarginOrdersClientOrderClientOid-privateDeleteHfOrdersSyncClientOrderClientOid)privateDeleteHfOrdersClientOrderClientOid&privateDeleteOrderClientOrderClientOidr  (privateDeleteHfMarginStopOrderCancelByIdprivateDeleteStopOrderOrderId"privateDeleteHfMarginOrdersOrderId privateDeleteHfOrdersSyncOrderIdprivateDeleteHfOrdersOrderIdprivateDeleteOrdersOrderId)r7  r>   rd  rD  r_  r  r   r  r	  r  rL  r  r  rF  r?  orderIdsrg  s                    r9  rm  zkucoin.cancel_spot_order  s     0 !!!!!!!!!**6;PP""669eDD..v66
F77vW\]]
!??vVV
F$$V[99	!^3Mz7M 	1 	1M 	1 1>+DG6p,pqqqV,,$*4L!6#a#a#abb$#0GK  $k  u%)%Y%YZ^ZeZefmouZvZv%w%wwwwwwwH>>(F;;D#~~d4GLLH"..x;;G?? $%, ,    &*%V%VW[WbWbcjlrWsWs%t%tttttttHH k!%!U!UVZVaVabikqVrVr!s!sssssss k!%!S!STXT_T_`gioTpTp!q!qqqqqqq k!%!O!OPTP[P[\cekPlPl!m!mmmmmmm "&!L!LT[[Y`bhMiMi!j!jjjjjjj ~~h77H##H---!#GI _  	f%)%R%RSWS^S^_fhnSoSo%p%pppppppHH &*%G%GT[]cHdHd%e%eeeeeeeHH _!%!H!HU\^dIeIe!f!fffffff _!%!F!Ft{{SZ\bGcGc!d!ddddddd _!%!B!B4;;wX^C_C_!`!```````  >>(F;;''111!%!@!@WV\A]A]!^!^^^^^^^ >>(F33D&&tY77G~~d,?DDH&&xG<<G??$ $   r:  c                   K   |                                   d{V  |                     |dd          }|                     |dg          }i }d}|n|t          | j        dz             |                     |          }|d         |d<   ||d<   |                     |                     ||                     d{V }n4||d<   |                     |                     ||                     d{V }| 	                    d|i          S )	a`  
        helper method for cancelling contract orders

        https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-order-by-orderld
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-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 str [params.clientOrderId]: cancel order by client order id
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  r  zJ cancelOrder() requires a symbol argument when cancelling by clientOrderIdr>   rd  rg  rT  )
r(  r]  r  r+   r>   r  .futuresPrivateDeleteOrdersClientOrderClientOidrY  !futuresPrivateDeleteOrdersOrderIdrv  )r7  r>   rd  rD  r  r_  rF  r  s           r9  rn  zkucoin.cancel_contract_order3  s?      !!!!!!!!!**6;PP6O#455$~'2~(~[[((F &tGH#0GK !PPQUQ\Q\]dflQmQmnnnnnnnnHH!#GI!CCDKKPWY_D`D`aaaaaaaaH 1222r:  c                 ,  K   |                                   d{V  d}d}||                     |          }|                     d||          \  }}|dk    s|dk    r|                     ||           d{V S |                     ||           d{V S )aS  
        cancel all open orders

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-all-orders-by-symbol
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-all-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-cancel-stop-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-all-orders-by-symbol
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/batch-cancel-stop-orders
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-all-orders
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-all-stop-orders

        :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 str [params.type]: 'spot' or 'swap', used if symbol is not provided(default is 'spot')
        :param str [params.marginMode]: *spot only* 'cross' or 'isolated'
        :returns: Response from the exchange
        NrU   rL   rM   )r(  r  r@  cancel_all_spot_orderscancel_all_contract_orders)r7  rd  rD  rp  r  s        r9  cancel_all_orderszkucoin.cancel_all_orders[  s      $ !!!!!!!!!
[[((F!??vW]^^
F&  jH&<&<44VVDDDDDDDDD88HHHHHHHHHr:  c                 l  K   |                                   d{V  i }|                     |ddd          }d}|                     |          \  }}|                     |ddg          }|                     d|          \  }}|du}||                     |          |d<   n|s|rt          | j        dz             |r5| j        d         |         |d	<   |d
k    r|rt          | j        dz             d}	|rb|r0| 
                    |                     ||                     d{V }	n|                     |                     ||                     d{V }	n|r0|                     |                     ||                     d{V }	n|rb|0|                     |                     ||                     d{V }	n_|                     |                     ||                     d{V }	n/|                     |                     ||                     d{V }	|                     d|	i          gS )a=  
        helper method for cancelling all spot orders

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-all-orders-by-symbol
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-all-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-cancel-stop-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-all-orders-by-symbol
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/batch-cancel-stop-orders

        :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 separated order IDs
        :param bool [params.hf]: False,  # True for hf order
        :returns: Response from the exchange
        Nr   r  FrT   rd  zK cancelAllOrders() requires a symbol argument for margin non-trigger ordersr  rL  r  zA cancelAllOrders does not support isolated margin for stop ordersrT  )r(  rt  r  r  r  	market_idr+   r>   r0  r,   $privateDeleteHfMarginStopOrderCancelrY  privateDeleteStopOrderCancelprivateDeleteHfMarginOrdersprivateDeleteHfOrdersCancelAllprivateDeleteHfOrdersprivateDeleteOrdersrv  )
r7  rd  rD  r_  r   r  r  queryisMarginOrdersrF  s
             r9  r  zkucoin.cancel_all_spot_ordersx  s     $ !!!!!!!!!""69feDD..v66
F6FI#677 >>?PRXYY
E#4/ $v 6 6GH 	}^ 	}#DG.{${||| 	p#'<#>z#JGK Z''G' +n!nooo 	S `!%!J!J4;;W^`eKfKf!g!ggggggg!%!B!B4;;wX]C^C^!_!_______ 	S!==dkk'SX>Y>YZZZZZZZZHH 	S~!%!D!DT[[QXZ_E`E`!a!aaaaaaa!%!;!;DKKQV<W<W!X!XXXXXXX!55dkk'56Q6QRRRRRRRRH 23344r:  c                   K   |                                   d{V  i }||                     |          |d<   |                     |dd          }|                     |ddg          }d}|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d          }|                     d|i          gS )aR  
        helper method for cancelling all contract orders

        https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-all-orders
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-all-stop-orders

        :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 dict [params.trigger]: When True, all the trigger orders will be cancelled
        :returns: Response from the exchange
        Nrd  r  r   r?  rT  )	r(  r  r  r  futuresPrivateDeleteStopOrdersrY  futuresPrivateDeleteOrdersr\  rv  )r7  rd  rD  r_  r   rF  r?  s          r9  r  z!kucoin.cancel_all_contract_orders  s"      !!!!!!!!! $v 6 6GH##FFI>>6FI#677 	[!@@WV\A]A]^^^^^^^^HH!<<T[[RX=Y=YZZZZZZZZH ~~h////00r:  c                   K   |                                   d{V  d}|h|                     |d          }|dk    s|dk    s|dk    s|dk    s|dk    r|}|                     |d          }n8|                     ddi           \  }}n|                     |          }|d         }|dk    s|dk    r|                     |||||           d{V S |                     |||||           d{V S )	aB  
        fetches a list of orders placed on the exchange

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-open-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-closed-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-orders-list
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-open-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-closed-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-list
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-list
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-stop-order-list

        :param str status: 'active' or 'closed', only 'active' is valid for stop orders
        :param str symbol: unified symbol for the market to retrieve orders from
        :param int [since]: timestamp in ms of the earliest order to retrieve
        :param int [limit]: The maximum number of orders to retrieve
        :param dict [params]: exchange specific parameters
 Check fetchSpotOrdersByStatus() and fetchContractOrdersByStatus() for more details on the extra parameters that can be used in params
        :returns: An `array of order structures <https://docs.ccxt.com/?id=order-structure>`
        NrE  rL   rM   rN   rO   r  r   )r(  rV  r  r@  r  fetch_spot_orders_by_statusfetch_contract_orders_by_status)	r7  r   rd  r  r  rD  rp  rE  r  s	            r9  fetch_orders_by_statuszkucoin.fetch_orders_by_status  sF     * !!!!!!!!!
>##FF33Dv~~!1!1TV^^txGWGW[_cm[m[m!
6622%)%G%GH]_ceg%h%h"
FF[[((FJ&  jH&<&<99&&%QVX^_________==ffeUZ\bcccccccccr:  c                 N  K   |                                   d{V  |                                }|                     |d          }|                     |ddd          }d}	|                     |          \  }	}|	r|t          | j        dz             |                     |g d          }|                     d|          \  }
}|
du}|d	k    rd
}n|dk    rd}i }d}| | 	                    |          }|d         |d<   | 
                    | j        d         |
d          |d<   d}|r9|d
k    r3|s1|                     |                     ||                     d{V }nO|s||d<   |||d<   |||d<   |r||d<   |rb|r0|                     |                     ||                     d{V }n|                     |                     ||                     d{V }n|r0|                     |                     ||                     d{V }n|	rl|d
k    r0|                     |                     ||                     d{V }ne|dk    r/|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d          }||                     ||||          S |                     |di           }|                     |dg           }|                     ||||          S )aV  
        fetch a list of spot orders

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-open-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-closed-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-orders-list
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-open-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-closed-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-list

        :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 or MARGIN_ISOLATED_TRADE for Margin Trading
        :param int [params.currentPage]: *trigger orders only* current page
        :param str [params.orderIds]: *trigger orders only* comma separated order ID list
        :param bool [params.trigger]: True if fetching a trigger order
        :param bool [params.hf]: False,  # True for hf order
        :param str [params.marginMode]: 'cross' or 'isolated', only for margin orders
        :returns: An `array of order structures <https://docs.ccxt.com/?id=order-structure>`
        Nuntilr  r   Fz@ fetchOrdersByStatus() requires a symbol parameter for hf orders)r  r   tillr  r   rN  rp  closeddoner>   rd  r  r  rL  r   r  pageSizer  r?  rc  )r(  r+  rC  rt  r  r+   r>   r  r  r  rV  r0  privateGetHfMarginOrdersActiverY  privateGetHfMarginStopOrdersprivateGetStopOrderprivateGetHfMarginOrdersDoneprivateGetHfOrdersActiveprivateGetHfOrdersDoneprivateGetOrdersr  r`  r\  )r7  r   rd  r  r  rD  lowercaseStatusr  r   r  r  r  r  r_  r  rF  listDataresponseDatar   s                      r9  r  z"kucoin.fetch_spot_orders_by_status  s     6 !!!!!!!!! ,,..!!&'22""669eDD..v66
F 	r6>#DG.p$pqqq6#G#G#GHH >>?TV\]]
E"$.f$$&OO(($O[[((F &tGH#//]0KZY`aa 	T_88'8!@@WV[A\A\]]]]]]]]HH  4$3! %*	" &+
# )#(  T  [%)%F%Ft{{SZ\aGbGb%c%cccccccHH%)%=%=dkk'SX>Y>Y%Z%ZZZZZZZHH T!%!B!B4;;wX]C^C^!_!_______ T"h..%)%B%B4;;wX]C^C^%_%_______HH$..%)%@%@WV[A\A\%]%]]]]]]]H!%!6!6t{{7E7R7R!S!SSSSSSSX >>(F33$$XvueDDD~~h;;gr::  >>>r:  c                 d  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S |                     |dd          }|                     |d          }|                     |g d          }|d	k    rd
}n|dk    rd}i }	|s||	d<   n|dk    rt          | j        dz             d}
| |                     |          }
|
d         |	d<   |||	d<   |||	d<   d}|r0| 	                    | 
                    |	|                     d{V }n/|                     | 
                    |	|                     d{V }|                     |di           }|                     |dg           }|                     ||
||          S )a  
        fetches a list of contract orders placed on the exchange

        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-list
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-stop-order-list

        :param str status: 'active' or 'closed', only 'active' is valid for stop orders
        :param str symbol: unified symbol for the market to retrieve orders from
        :param int [since]: timestamp in ms of the earliest order to retrieve
        :param int [limit]: The maximum number of orders to retrieve
        :param dict [params]: exchange specific parameters
        :param bool [params.trigger]: set to True to retrieve untriggered stop orders
        :param int [params.until]: End time in ms
        :param str [params.side]: buy or sell
        :param str [params.type]: limit or market
        :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: An `array of order structures <https://docs.ccxt.com/?id=order-structure>`
        NFr   r  r  r   r  )r  r  r   r  r  rN  rp  r   z= fetchOrdersByStatus() can only fetch untriggered stop ordersr>   rd  r  r  r?  rc  )r(  rU  fetch_paginated_call_dynamicrt  rC  r  r,   r>   r  futuresPrivateGetStopOrdersrY  futuresPrivateGetOrdersr\  r  r`  )r7  r   rd  r  r  rD  r  r   r  r_  r  rF  r  r   s                 r9  r  z&kucoin.fetch_contract_orders_by_statuss  s7     & !!!!!!!!!88AVXbcc& 	p::;PRXZ_afhnooooooooo""669==!!&'226#?#?#?@@XFFvF 	h &GHxTW'ffggg[[((F &tGH!&GI$GG 	X!==dkk'SY>Z>Z[[[[[[[[HH!99$++gv:V:VWWWWWWWWHh ~~h;;gr::  >>>r:  c                    K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S |                     d||||           d{V S )ap  
        fetches information on multiple closed orders made by the user

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-closed-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-orders-list
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-list
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-stop-order-list
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-open-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-closed-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>`
        NFrj   r  r  r(  rU  r  r  r7  rd  r  r  rD  r  s         r9  fetch_closed_orderszkucoin.fetch_closed_orders  s      0 !!!!!!!!!88ATV`aa& 	n::;NPVX]_dflmmmmmmmmm00vVVVVVVVVVr:  c                    K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S |                     d||||           d{V S )a>  
        fetch all unfilled currently open orders

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-open-orders
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-orders-list
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-list
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-stop-order-list
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-open-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-closed-orders
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-list

        :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 separated 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>`
        NFr   r  rp  r  r  s         r9  fetch_open_orderszkucoin.fetch_open_orders  s      6 !!!!!!!!!88ART^__& 	l::;LfV[]bdjkkkkkkkkk0065%QWXXXXXXXXXr:  c                 >  K   |                                   d{V  d}||                     dd|          \  }}n|                     |          }|d         }|dk    s|dk    r|                     |||           d{V S |                     |||           d{V S )a  
        fetches information on an order made by the user

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-order-by-orderld
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-order-by-orderld
        https://www.kucoin.com/docs-new/rest/spot-trading/get-stop-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-by-orderld
        https://www.kucoin.com/docs-new/rest/futures-trading/get-stop-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 str [params.type]: 'spot' or 'swap', used if symbol is not provided(default is 'spot')
 Check fetchSpotOrder() and fetchContractOrder() for more details on the extra parameters that can be used in params
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr   rE  rL   rM   )r(  r@  r  fetch_spot_orderfetch_contract_orderro  s         r9  fetch_orderzkucoin.fetch_order  s      , !!!!!!!!!
>!%!C!CLRVX^!_!_J[[((FJ&  jH&<&<..r66BBBBBBBBB222vvFFFFFFFFFr:  c                   K   |                                   d{V  i }|                     |dd          }|                     |ddd          }d}|                     |          \  }}d}|                     d|          \  }}|du}	d}
||                     |          }
|s|	r&|s$|t          | j        dz             |
d	         |d
<   |                     |g d          }d}|||d<   |rq|	r1| 	                    | 
                    ||                     d{V }n||
d	         |d
<   |                     | 
                    ||                     d{V }n|	r1|                     | 
                    ||                     d{V }ny|r1|                     | 
                    ||                     d{V }nF|                     | 
                    ||                     d{V }n|t          | j        dz             ||d<   |rb|	r0|                     | 
                    ||                     d{V }n|                     | 
                    ||                     d{V }n|	r0|                     | 
                    ||                     d{V }na|r0|                     | 
                    ||                     d{V }n/|                     | 
                    ||                     d{V }|                     |di           }t-          |t.                    r|                     |d          }|                     ||
          S )aF  
        fetch a spot order

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-order-by-orderld
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-order-by-orderld
        https://www.kucoin.com/docs-new/rest/spot-trading/get-stop-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-order-by-clientoid
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-by-orderld
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-by-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
        :param dict [params.marginMode]: 'cross' or 'isolated'
        :returns: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  r  r  r   Fr   zB fetchOrder() requires a symbol parameter for hf and margin ordersr>   rd  )r  r  r  r   z" fetchOrder() requires an order idrg  r?  r   )r(  r]  rt  r  r  r  r+   r>   r  $privateGetHfMarginStopOrderClientOidrY  (privateGetStopOrderQueryOrderByClientOid,privateGetHfMarginOrdersClientOrderClientOid&privateGetHfOrdersClientOrderClientOid#privateGetOrderClientOrderClientOidr1   "privateGetHfMarginStopOrderOrderIdprivateGetStopOrderOrderIdprivateGetHfMarginOrdersOrderIdprivateGetHfOrdersOrderIdprivateGetOrdersOrderIdr\  
isinstancer  r  r  )r7  r>   rd  rD  r_  r  r   r  r  r  r  rF  r  s                r9  r  zkucoin.fetch_spot_order>  s,     , !!!!!!!!!**6;PP""669eDD..v66
F
!??fUU
F"$.[[((F 	1 	1 1>+DG6z,z{{{$*4L!6#T#T#TUU$#0GK  h  q%)%N%Nt{{[bdjOkOk%l%lllllllHH),24L)%)%R%RSWS^S^_fhnSoSo%p%pppppppHH h!%!R!RSWS^S^_fhnSoSo!p!ppppppp h!%!L!LT[[Y`bhMiMi!j!jjjjjjj!%!I!I$++V]_eJfJf!g!ggggggg
 z"47-Q#QRRR!#GI 
\  c%)%L%LT[[Y`bhMiMi%j%jjjjjjjHH%)%D%DT[[QXZ`EaEa%b%bbbbbbbHH \!%!E!EdkkRY[aFbFb!c!ccccccc \!%!?!?GU[@\@\!]!]]]]]]]!%!=!=dkk'SY>Z>Z![![[[[[[[~~h;;lD)) 	<??<;;Lf555r:  c                 2  K   |                                   d{V  i }d}|                     |dd          }|M||d<   |                     |ddg          }|                     |                     ||                     d{V }nM|t          | j        dz             ||d<   |                     |                     ||                     d{V }||                     |          nd}| 	                    |d          }| 
                    ||          S )a  
        fetc contract order

        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-by-orderld
        https://www.kucoin.com/docs-new/rest/futures-trading/get-stop-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
        :returns dict: An `order structure <https://docs.ccxt.com/?id=order-structure>`
        Nr  r  zF fetchOrder() requires an order id argument or clientOrderId in paramsrg  r?  )r(  r]  r  "futuresPrivateGetOrdersByClientOidrY  r+   r>   futuresPrivateGetOrdersOrderIdr  r\  r  )	r7  r>   rd  rD  r_  rF  r  r  r  s	            r9  r  zkucoin.fetch_contract_order  sL      !!!!!!!!!**6;PP$#0GK YYv_'EFFF!DDT[[QXZ`EaEabbbbbbbbHHz'2z(z{{{!#GI!@@WV\A]A]^^^^^^^^HX *0);V$$$$~~h77f555r:  rY  c                     |                      |d          }|                     ||          }||d         r|                     ||          S |                     ||          S )Nrd  r  )rV  rb  parse_contract_orderparse_spot_order)r7  rY  r  re  s       r9  r  zkucoin.parse_order  sh    ##E844!!(F33VJ%7,,UF;;;((777r:  c           
         |                      |d          }|                     ||          }|d         }|                     |dd          }|                      |d          }|                     |d          }|                     |          }|                      |d          }	|                      |d          }
|                      |d          }|                     |          }|                     |d	          }|                      |d
          }|                      |d          }|                      |d          }|                      |d          }|t          j        |d          ro|                      |d          }|d         r)t          j	        |t          j
        ||                    }n(t          j	        t          j
        ||          |          }|                     |d          }|                     |dd          }d }||rdnd}|rdn|}d }|||d}|                      |d          }|                      |d          }|                     |d          }|                     |d          }|                     |d          }|                     i d|d|d|d|d|d|d|d|
d|d|	d|                     |d           d!|d"|d#d d$|d%|d	|||d ||d d&|          S )'Nrd  r>   rg  rE  	createdAtr)  r  feeCurrencyr  r  
filledSizefilledValueavgDealPricer  r~  r-  isActivecancelExistFrN  r  canceledr  r}  r  r  r  r6  	updatedAtr  ru  r  r  r}  filled	remainingr   rH  )r   rT  lastTradeTimestamplastUpdateTimestampr]  trades)rV  rb  r]  rC  r  r  r  r9   	string_gtr  r  r  r  rv  )r7  rY  r  re  rd  rg  rE  r   rH  r)  r  feeCurrencyIdr  feeCostru  r  r}  r]  r~  r  r  r   r  r  r  r  r6  r  s                               r9  r  zkucoin.parse_contract_order  s   v ##E844!!(F33!$$UD)<<v..%%e[99	<<	**  00 v..((>>--m<<""5%00!!%00!!%66}55""5.99O!263!?!?O++FNCCLh ]!,T73ElTZ3[3[\\!,W-?f-U-UW[\\ ??5*55nnUM5AA'5VVXF*6' C ((<<&&um<<??5*55__UL99
"//{CC  
' 
] 
 f 
 D	 

 ; 
  
 * 
 D 
 f 
 U 
 D,,UK@@ 
 D 
 f 
  
  
  ! 
" 3# 
$ "&#6/ 
  
  
0 1  	r:  c           	         |                      |d          }|                     |d          }|                      |d          }|                     |dd          }|                      |d          }|d u}|                     |dd          }	|                     |dd	          }
|                      |d
          }d }|
	|
du rd}nd}|r|dk    rd}n|
s|	sd}|rd}|dk    rd}|                     i d|d|                     |g d          d|                      |d          d|                     ||d          d|                      |d          d|                      |d          d|                     |d          d|                      |d          d|                      |d          d|                      |d          d |                     |d!          d"|                      |d#          d$|                      |d%          d&d d'|d(|                     |          d)| 	                    |          |                     |d)          d*|d |                      |d+          d d,|          S )-Nrd  r  r  r  Fr  stopTriggeredr  rp  r   TrN  r  NEW	cancelledr  failrejectedrT  r>   )r>   rg  
newOrderIdcancelledOrderIdr  r  r  rE  r  r  r  ru  r  r)  r  r  r}  	dealFundsr  dealSizer  r   rH  r  r  r  )r   r  r]  r  )
rV  rC  r  rt  rv  ra  safe_symbolr  r  r  )r7  rY  r  re  r   r  r  responseStopr   r  r  responseStatusr   s                r9  r  zkucoin.parse_spot_order^  s:   t ##E844%%e[99	((>>nnUM5AA''v66d*uouEE##E:x@@))%::4! 	%&& %m %$ 	 FV##F  
E 
$$$U,_,_,_`` 
 T--e[AA 
 d&&x==	 

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

        https://docs.kucoin.com/#list-fills
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-trade-history
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-trade-history

        :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
        :param str [params.type]: 'spot' or 'swap', used if symbol is not provided(default is 'spot')
        :returns dict[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        rg  N)fetch_my_tradesrY  )r7  r>   rd  r  r  rD  r_  s          r9  fetch_order_tradeszkucoin.fetch_order_trades  sQ      " r
 ))&%GU[@\@\]]]]]]]]]r:  c                 4  K   |                                   d{V  d}d}||                     |          }|                     d||          \  }}|dk    s|dk    r|                     ||||           d{V S |                     ||||           d{V S )a1  

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-trade-history
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-trade-history

        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 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)
        :param str [params.type]: 'spot' or 'swap', used if symbol is not provided(default is 'spot')
 Check fetchMySpotTrades() and fetchMyContractTrades() for more details on the extra parameters that can be used in params
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=trade-structure>`
        Nr   rL   rM   )r(  r  r@  fetch_my_spot_tradesfetch_my_contract_trades)r7  rd  r  r  rD  rp  r  s          r9  r  zkucoin.fetch_my_trades   s        !!!!!!!!!
[[((F!??QWY_``
F&  jH&<&<2265%PPPPPPPPP66vueVTTTTTTTTTr:  c                   K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S i }d}|                     |          \  }}d}|                     d|          \  }}|du}	|	r'd}|                     | j        d         ||          |d<   |r|t          | j        dz             d}
| | 	                    |          }
|
d	         |d
<   | j        d         }d}d}| 
                    d||          \  }}|rp|||d<   |||d<   |	r0|                     |                     ||                     d{V }n|                     |                     ||                     d{V }n|dk    r7|||d<   |                     |                     ||                     d{V }nO|dk    r2d}|                     |                     ||                     d{V }nt!          | j        dz             |                     |di           }d}|r|}n|                     |dg           }|                     ||
||          S )a6  

        https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-trade-history
        https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-trade-history

        fetch all spot 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 str [params.marginMode]: 'cross' or 'isolated', only for margin trades
        :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>`
        NFr   r  Tr  rL  zD fetchMyTrades() requires a symbol parameter for hf or margin ordersr>   rd  r  r  r  r  r  private_get_limit_fillsz% fetchMyTradesMethod() invalid methodr?  rc  )r(  rU  r  r  r  rV  r0  r+   r>   r  handle_until_optionprivateGetHfMarginFillsrY  privateGetHfFillsprivateGetFillsprivateGetLimitFillsr'   r\  r  parse_trades)r7  rd  r  r  rD  r  r_  r  r  isMarginr  r  parseResponseDatarF  r?  r  s                   r9  r  zkucoin.fetch_my_spot_trades;  s.     " !!!!!!!!!88R\]]& 	j::?FTY[`bhiiiiiiiii..v66
F
!??QWXX
FT) 	iB#'#3#3DL4OQ[]g#h#hGK  	v&.#DG.t$tuuu[[((F &tGH34!227GVLL 	S #(  %*	" V!%!=!=dkk'SY>Z>Z![![[[[[[[!%!7!7GV8T8T!U!UUUUUUU*** %*	"!11$++gv2N2NOOOOOOOOHH000 !%!66t{{7F7S7STTTTTTTTHH*Q QRRRR ~~h33 	7FF^^D'266F  >>>r:  c                 V  K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S i }d}| |                     |          }|d         |d<   |||d<   |t	          d|          |d	<   |                     d
||          \  }}|                     |                     ||                     d{V }|                     |di           }	| 	                    |	dg           }
| 
                    |
|||          S )a9  

        https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-trade-history

        fetch all contract 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]: End time in ms
        :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>`
        NFr   r  r>   rd  r  r*  r  r  r?  rc  )r(  rU  r  r  rw  r  futuresPrivateGetFillsrY  r\  r  r  )r7  rd  r  r  rD  r  r_  r  rF  r?  r  s              r9  r  zkucoin.fetch_my_contract_trades  sz      !!!!!!!!!88R\]]& 	j::?FTY[`bhiiiiiiiii
 [[((F &tGH!&GI"%dE"2"2GJ227GVLL44T[[&5Q5QRRRRRRRRD ~~h33gr22  >>>r:  c                 B  K   |                                   d{V  |                     |          }d|d         i}d}|                     |ddd          \  }}d}d}	d}
|                     d||          \  }
}|ru|
dk    s|
dk    rd	|d
<   nd|d
<   |                     |                     ||                     d{V }|                     |di           }|                     |dg           }	n|
dk    s|
dk    rG|                     |                     ||                     d{V }|                     |dg           }	nF| 	                    |                     ||                     d{V }|                     |dg           }	| 
                    |	|||          S )a4  
        get the list of most recent trades for a particular symbol

        https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-trade-history
        https://www.kucoin.com/docs-new/rest/ua/get-trades
        https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-trade-history

        :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
        :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to False
        :returns Trade[]: a list of `trade structures <https://docs.ccxt.com/?id=public-trades>`
        Nrd  r>   r   r   FrL   rM   rJ  rL  rK  r?  r  )r(  r  rU  r@  utaGetMarketTraderY  r\  r  publicGetMarketHistoriesfuturesPublicGetTradeHistoryr  )r7  rd  r  r  rD  r  r_  r   rF  r  rE  r?  s               r9  fetch_tradeszkucoin.fetch_trades  s      !!!!!!!!!V$$fTl
 33FM5RWXXV99-QWXXf >	:DH$4$4'-$$'0$!33DKK4P4PQQQQQQQQH& >>(FB77D^^D&"55FFfnn$("2"2!::4;;wPV;W;WXXXXXXXXH ^^Hfb99FF!>>t{{7TZ?[?[\\\\\\\\H$ ^^Hfb99F  >>>r:  r  c                     |                      |d          }|                     ||          }||d         r|                     ||          S |                     ||          S )Nrd  rL   )rV  rb  parse_spot_or_uta_tradeparse_contract_trade)r7  r  r  re  s       r9  parse_tradezkucoin.parse_tradeY  se    ##E844!!(F33NvN//v>>>,,UF;;;r:  c                    |                      |d          }|                     ||d          }|                     |dd          }|                      |d          }|                      |d          }|                     |dd          }||                     |d	z            }n!|                     |d
          }d|v r||dz  }|                     |dd          }|                     |dd          }	|                      |d          }
d }|                      |d          }|]|                      |d          }|                     |          }||
dk    r|d         n|d         }|||                      |d          d}|                      |d          }|dk    rd }|                     |dd          }|                     |||||                     |          |d         |||
||	||d|          S )Nrd  r  tradeIdr>   rg  	liquidityrG  rm  r  r  	dealValuer*  r)  	dealPricer  ru  r  r  r  rS  rk  r   feeRater}  r  raterE  matchr  rT  r>   rY  r   rH  rd  rE  takerOrMakerr  r)  ru  r}  r  )	rV  rb  r]  r  r  rC  r  
safe_trader  )r7  r  r  re  r>   rg  r  r   priceStringr  r  r  feeCostStringr  r  rE  r  s                    r9  r  zkucoin.parse_spot_or_uta_tradea  s@   p ##E844!!(FC88y$77""5)44''{;;''vt<<	 )))g*=>>II))%==Iu$$9+@%,	((EE))%BBv..((66$ ,,UMBBM11-@@K"26&..fWoovf~%'((	:: C
 v..7??D''wDD
"Y//X&( " 
  
   	r:  c                 f   |                      |d          }|                     ||d          }|                     |dd          }|                      |d          }|                      |d          }|                     |d          }||                     |dz            }n!|                     |d	          }d
|v r||dz  }|                     |dd          }|                     |dd          }	|                      |d          }
d }|                      |d          }|]|                      |d          }|                     |          }||
dk    r|d         n|d         }|||                      |d          d}|                     |dd          }|dk    rd }|                     |dd          }|@|                      |d          }t          j        ||	          }t          j        ||          }|                     ||||| 	                    |          |d         |||
||	||d|          S )Nrd  r  r  r>   rg  r  rm  r  r  r	  r*  r)  r
  r  ru  r  r  r  rS  rk  r   r  r  rE  	orderTyper  r  r_  r~  r  )
rV  rb  r]  rC  r  r  r9   r  r  r  )r7  r  r  re  r>   rg  r  r   r  r  r  r  r  r  r  rE  r  r~  contractCosts                      r9  r  zkucoin.parse_contract_trade  s   X ##E844!!(FC88y$77""5)44''{;;%%eT22	 )))g*=>>II))%==Iu$$9+@%,	((EE))%BBv..((66$ ,,UMBBM11-@@K"26&..fWoovf~%'((	:: C
 !!%==7??D''w@@
++FNCCL"-k<HHL +L,GGJ"Y//X&( " 
  
   	r:  c                   K   |                                   d{V  |                     |          }i }d}d}|d         rh|d         |d<   |                     |                     ||                     d{V }|                     |dg           }|                     |d          }nP|d         |d<   |                     |                     ||                     d{V }|                     |d          }|                     |d          }||                     ||          | 	                    |d          | 	                    |d	          d
d
dS )a  
        fetch the trading fees for a market

        https://www.kucoin.com/docs-new/rest/account-info/trade-fee/get-actual-fee-spot-margin
        https://www.kucoin.com/docs-new/rest/account-info/trade-fee/get-actual-fee-futures

        :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>`
        NrL   r>   r   r?  r   rd  re  rf  T)rT  rd  r  r  r  r  )
r(  r  privateGetTradeFeesrY  r  r\  futuresPrivateGetTradeFeesrV  r  r  )	r7  rd  rD  r  r_  rF  r  r?  re  s	            r9  fetch_trading_feezkucoin.fetch_trading_feei  s      !!!!!!!!!V$$&> 	5!'GI!55dkk'66R6RSSSSSSSSH >>(FB77DNN4++EE &tGH!<<T[[RX=Y=YZZZZZZZZH NN8V44E##E844&&x88%%e^<<%%e^<<
 
 	
r:  r  r  c                   K   |                      ||          \  }}|                                  d{V  |                     |           |                     |          }|d         |dd}|||d<   d}|                     |          \  }}|*|                     |                                          |d<   t          |                     |||                    |d<   d}	| 	                    |dd	d
          \  }	}|	rd|d<   | 
                    |                     ||                     d{V }
|                     |
di           }|                     ||          S )a  
        make a withdrawal

        https://www.kucoin.com/docs-new/rest/account-info/withdrawals/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>`
        Nr>   ADDRESS)r  	toAddresswithdrawTyper  r  ru  r   r  FINTERNALfeeDeductTyper?  )handle_withdraw_tag_and_paramsr(  r  r  r)  r*  r+  floatcurrency_to_precisionrU  privatePostWithdrawalsrY  r\  parse_transaction)r7  r  ru  r  r  rD  r  r_  r  r  rF  r?  s               r9  r   zkucoin.withdraw  s      99#vFFV!!!!!!!!!7###==&&  %
 
 ?!GFO"AA&IIV"#66{CCIIKKGG!$"<"<T6;"W"WXX
!::6:|]bcc
F 	2'1GO$44T[[&5Q5QRRRRRRRR ~~h33%%dH555r:  r   c                 >    ddddd}|                      |||          S )NrO  pendingfailed)SUCCESS
PROCESSINGWALLET_PROCESSINGFAILURErx  r7  r   statusess      r9  parse_transaction_statuszkucoin.parse_transaction_status  s4    #!*	
 
 &&999r:  transactionc                    |                      |d          }|                     ||          }|                      |d          }|                      |d          }|                      |d          }|U|                    d          }t          |          }	|	dk    r#|!t          |d                   dk    r|d         }|d         }|dnd	}
|                      |d
          }d }|                      |d          }|Ed }|t	          j        ||          }|                     |          |                     |          |d}|                     |dd          }|                     |d          }d|v}|rd|v rdnd	}
||dz  }||dz  }| 	                    |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#S )$Nr  r  ru  
walletTxId@r   r   
withdrawalr  r   r  )r}  r  r  r  createAtr  r*  isInnerr  rT  r>   withdrawalIdr   rH  r  r  	addressToaddressFromr  tagTotagFromtxidrE  rH   remark)internalr  rQ  )rV  r  r  r  r9   r  r6  r  rC  r  r]  r  r  r/  )r7  r0  r  r$  r  r  ru  r<  	txidPartsnumTxidPartsrE  	rawStatusr  r  r  r   rQ  isV1r>  r  s                       r9  r%  zkucoin.parse_transaction  sE   V %%k:>>
&&z8<<"";	::!!+x88\::

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

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

        https://www.kucoin.com/docs-new/rest/account-info/deposit/get-deposit-history
        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]: *main account only* 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)
        :param str [params.accountType]: 'main' or 'contract'(default is 'main')
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nr  rq   r  r  r  Fr  r>   r  r  r      |{r*  r  r?  rc  rE  r  )r(  rU  r\  r0  rV  fetch_contract_depositsr  r  r  r  privateGetHistDepositsrY  privateGetDepositsr  parse_transactionsr7  r  r  r  rD  r  r  r  r_  r  rF  r?  rc  s                r9  fetch_depositszkucoin.fetch_depositsG  sd     " !!!!!!!!!";;FOUbdoppV6FKK&&~{KPP*$$55dE5&QQQQQQQQQ88R\]]& 	h::?DRWY^`fggggggggg}}T**H"*4.GJ"'GJ227GVLL!6!6!%!2!254<!@!@GI!88Wf9U9UVVVVVVVVHH %*	"!44T[[&5Q5QRRRRRRRRHN ~~h33tWb11&&uhuvyFYZZZr:  c                 R  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                     d{V }|d         d         }|                     ||||dd	i          S )
a  
        helper method for fetching deposits for futures accounts
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch deposits for
        :param int [limit]: the maximum number of deposits structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nr>   r  r  r  r?  rc  rE  r  )r(  r  futuresPrivateGetDepositListrY  rH  	r7  r  r  r  rD  r_  r  rF  r  s	            r9  rE  zkucoin.fetch_contract_deposits  s       !!!!!!!!!}}T**H"*4.GJ"'GJ!&GI::4;;wPV;W;WXXXXXXXX8  '0&&|XuefV_M`aaar:  c                   K   |                                   d{V  d}|                     |dd|          \  }}|                     | j        di           }|                     |||          }|dk    r|                     ||||           d{V S d}|                     |dd          \  }}|r |                     d||||d	           d{V S i }d}	| |                     |          }	|	d
         |d<   |||d<   |                     d||          \  }}d}
|Q|dk     rK| 	                    |dz            |d<   | 
                    |                     ||                     d{V }
n6|||d<   |                     |                     ||                     d{V }
|                     |
di           }|                     |dg           }|                     ||	||ddi          S )a  
        fetch all withdrawals made from an account

        https://www.kucoin.com/docs-new/rest/account-info/withdrawals/get-withdrawal-history
        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]: *main account only* 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)
        :param str [params.accountType]: 'main' or 'contract'(default is 'main')
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nr  r   r  r  r  Fr  r!  r>   r  r  r  rD  r*  r  r?  rc  rE  r4  )r(  rU  r\  r0  rV  fetch_contract_withdrawalsr  r  r  r  privateGetHistWithdrawalsrY  privateGetWithdrawalsr  rH  rI  s                r9  fetch_withdrawalszkucoin.fetch_withdrawals  sk     " !!!!!!!!!";;FDVXegrssV6FKK&&~{KPP*$$88ueVTTTTTTTTT88ASU_``& 	p::;MtUZ\aciknooooooooo}}T**H"*4.GJ"'GJ227GVLL!6!6!%!2!254<!@!@GI!;;DKKQW<X<XYYYYYYYYHH %*	"!77GV8T8TUUUUUUUUHP ~~h33tWb11&&uhuv|F\]]]r:  c                 R  K   |                                   d{V  i }d}| |                     |          }|d         |d<   |||d<   |||d<   |                     |                     ||                     d{V }|d         d         }|                     ||||dd	i          S )
a  
        helper method for fetching withdrawals for futures accounts
        :param str code: unified currency code
        :param int [since]: the earliest time in ms to fetch withdrawals for
        :param int [limit]: the maximum number of withdrawals structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `transaction structures <https://docs.ccxt.com/?id=transaction-structure>`
        Nr>   r  r  r  r?  rc  rE  r4  )r(  r  futuresPrivateGetWithdrawalListrY  rH  rM  s	            r9  rO  z!kucoin.fetch_contract_withdrawals(  s       !!!!!!!!!}}T**H"*4.GJ"'GJ!&GI==dkk'SY>Z>Z[[[[[[[[8  '0&&|XuefVbMcdddr:  c                 R   |                                  }|                     |dd          |d<   |                     |dd          |d<   |                     |dd          |d<   |                     |d	          }|                     |d
          }t          j        ||          |d<   |S )NholdBalanceholdusedavailableBalance	availablefreetotalBalancetotal	liabilityinterestdebt)r"  r]  rV  r9   
string_add)r7  r  r"  r`  r_  s        r9  parse_balance_helperzkucoin.parse_balance_helperZ  s    ,,..,,UM6JJ,,U4FTT--e^WMM{33##E:66!,T8<<r:  c                 	  K   |                                   d{V  |                     |d          }d}||                     |          }d}|                     dd|          \  }}|                     | j        di           }|                     |||          }|                     |d          }|dk    r|                     |           d{V S d}|                     |          \  }}|r|dk    rd	}| 	                    d|          \  }}	d}
i }|d
k    p|d
k    }|dk    p|dk    }|r=||d         |d<   | 
                    |                     ||	                     d{V }
ns|r0|                     |                     ||	                     d{V }
nA||d         |d<   ||d<   |                     |                     ||	                     d{V }
d}|
ddd}|rQ|                     |
di           }|                     |d|          }t          dt!          |                    D ]}||         }|                     |d          }|                     |dd          }|                     |di           }|                     |di           }|                     |                     |d                    }|                     |                     |d                    }i }|                     |          ||<   |                     |          ||<   |                     |          ||<   n|r|                     |
di           }|                     |dg           }t          dt!          |                    D ]M}||         }|                     |d          }|                     |          }|                     |          ||<   Nn|                     |
dg           }t          dt!          |                    D ]}||         }|                     |d          }||k    r|                     |d          }|                     |          }|                                 } |                     |d          | d<   |                     |d          | d<   |                     |d          | d<   | ||<   |}!|s|                     |          }!|!S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-detail-spot
        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-cross-margin
        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-isolated-margin
        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-futures

        :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>`
        Nr  rL   rf   r  rE  r  r  r  r  r  rM   r>   balanceCurrencyr  rT  r   rH  r?  assetsr   rd  _	baseAsset
quoteAssetr   balancer]  rZ  r[  holdsrX  )r(  rV  r  r@  r\  r0  r  fetch_contract_balancer  r  privateGetIsolatedAccountsrY  privateGetMarginAccountr!  r  r  r  r  r  rb  safe_balancer  r"  )"r7  rD  r  r  r<  r  rE  r  r  r  rF  r_  r  r  r?  r  rf  r  r  re  rd  r   rk  baseCode	quoteCode	subResultr   rj  r$  	codeInnerbalanceType
codeInner2r"  
returnTypes"                                     r9  fetch_balancezkucoin.fetch_balanced  sr      !!!!!!!!!//}}T**H $ B B>SWY_ ` `v6FKK}MM66**:44V<<<<<<<<<..v66
F 	46>>D >>~vVV
E*,E$*2Dw&=DH,< 
	R#-5d^)*!<<T[[RW=X=XYYYYYYYYHH 	R!99$++gu:U:UVVVVVVVVHH#&.tn
#"GFO!44T[[%5P5PQQQQQQQQH\ 
 

  #	1>>(FB77D__T8T::F1c&kk** > >q	++E8<<))(D#>>~~e["==ulB??2243C3CD*3U3UVV 33D4D4DUJ4W4WXX	"$	&*&?&?&E&E	(#'+'@'@'G'G	)$!%!2!29!=!=v>  	1>>(FB77D~~dJ;;H1c(mm,, G G"1+!--gzBB
 33J??	$($=$=g$F$Fy!!	G >>(FB77D1c$ii(( 
1 
1q'"..w??$&&!%!1!1':!F!FJ!%!8!8!D!DJ"llnnG'+'7'7'K'KGG$&*&6&6w&L&LGFO&*&6&6w&H&HGFO)0F:&
 	3**622Jr:  c                   K   |                                   d{V  |                     | j        d          }|                     | j        di           }|                     |d|          }|                     |d|          }|                     |          }d|d         i}|                     |                     ||                     d{V }|ddd}|                     |d          }	|                     |	d          }
|                     |
|          }|                                 }|                     |	d          |d	<   |                     |	d
          |d<   |||<   | 	                    |          S )a!  
        query for balance and get the amount of funds available for trading or funds locked in orders

        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-futures

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param dict [params.code]: the unified currency code to fetch the balance for, if not provided, the default .options['fetchBalance']['code'] will be used
        :returns dict: a `balance structure <https://docs.ccxt.com/?id=balance-structure>`
        Nr  rf   r  r>   re  r?  rY  r[  accountEquityr]  )
r(  rV  r0  r  r   futuresPrivateGetAccountOverviewrY  r  r"  ro  )r7  rD  defaultCodefetchBalanceOptionsr  r  r_  rF  r  r?  r$  currencyCoder"  s                r9  rl  zkucoin.fetch_contract_balance  s      !!!!!!!!!&&t|V<<"oodlNBOO&&':FKPP<<==&&
 >>t{{7TZ?[?[\\\\\\\\" 
 

 x00%%dJ77
..z8DD,,..**41CDD++D/BB&|  (((r:  fromAccount	toAccountc                   K   |                                   d{V  |                     |          }|                     ||          }|d         |d}d}	|                     |dd|	          \  }	}|	dk    rd|vrt	          | j        d	z             n!|	d
k    rd|vrt	          | j        dz             d|vr|                                 |d<   |                     |          }
|                     |          }|                     |
| j	                  }|                     || j	                  }|r|
|d<   d}
|r||d<   d}| 
                    |
|          }d}|r:|
|d<   ||d<   |                     |                     ||                     d{V }nb|	|d<   |
                                |d<   |                                |d<   |                     |                     ||                     d{V }|                     |d          }|                     ||          }|                     | j        di           }|                     |dd          }|r||d<   ||d<   ||d<   d|d<   |S )a8  
        transfer currency internally between wallets on the same account

        https://www.kucoin.com/docs-new/rest/account-info/transfer/flex-transfer?lang=en_US&

        :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
        :param str [params.transferType]: INTERNAL, PARENT_TO_SUB, SUB_TO_PARENT(default is INTERNAL)
        :param str [params.fromUserId]: required if transferType is SUB_TO_PARENT
        :param str [params.toUserId]: required if transferType is PARENT_TO_SUB
        :returns dict: a `transfer structure <https://docs.ccxt.com/?id=transfer-structure>`
        Nr>   )r  ru  r  transferTyperE  PARENT_TO_SUBtoUserIdzA transfer() requires a toUserId param for PARENT_TO_SUB transfersSUB_TO_PARENT
fromUserIdzC transfer() requires a fromUserId param for SUB_TO_PARENT transfersr  fromAccountTagr  toAccountTagr  r  fromAccountTypetoAccountTyper?  r   r  Tru  r~  r  rO  r   )r(  r  r#  handle_param_string_2r'   r>   r  convert_type_to_accountr  idsis_hf_or_mining privatePostAccountsInnerTransferrY  r>  $privatePostAccountsUniversalTransferr\  parse_transferr0  r  )r7  r  ru  r~  r  rD  r  requestedAmountr_  r  fromIdtoIdfromIsolated
toIsolated
hfOrMiningrF  r?  r   transferOptionsr  s                       r9  r   zkucoin.transferA  s       !!!!!!!!!==&&44T6BB %
 
 "#99&.RXZfggf?**&((#DG.q$qrrr )_,, F**#DG.s$stttv%%#'99;;GK --k::++I66}}VTX66]]422
 	 (.G$%F 	&*GN#D))&$77
 	e %GFO GDM!BB4;;wX^C_C_````````HH*GFO)/G%&'+zz||GO$ "FFt{{SZ\bGcGcddddddddH~~h//&&tX66..z2FF"&..B[]a"b"b" 	&!'HX&1H]#$-H[!!%HXr:  r  r  c                 2    |dk    p|dk    p|dk    p|dk    S )Nr  r   )r7  r  r  s      r9  r  zkucoin.is_hf_or_mining  s-    #_tz'9_Vv=M_QUY_Q_`r:  r   c           
         |                      |dd          }|                     |d          }|                     |d          }|                     |d          }|d u}d }d }	|r>|                     |d          }
|                     |d          }|dk    r|
}n5|d	k    r|
}	n,|                     |d
          }|                     |d          }	|                     | j        d          }|                     |||          }|                     ||	|	          }|                     |g d          |                     ||          ||                     |          |                     |d          ||| 	                    |          |d	S )Nr  rG  r  r   bizTyper  	directionoutinpayAccountTyperecAccountTyper  )r>   applyIdrg  ru  )	r>   r  r   rH  ru  r~  r  r   rT  )
r  rV  safe_string_lowerr\  r0  ra  r  r  r  parse_transfer_status)r7  r   r  r   r$  rA  r  isLedgerEntryaccountFromRawaccountToRawr  r  r  accountFrom	accountTos                  r9  r  zkucoin.parse_transfer  s   | ''+vFF	%%h
;;
$$Xx88	""8Y77 , 	N00=IIK((;??IE!!!,d""* "33H>NOON11(<LMML6FGG&&~~~VV$$^\<PP	$$X/K/K/KLL//
HEE"Y//&&x::&"00;;

 

 
	
r:  c                 8    ddi}|                      |||          S )Nr*  r'  rx  r-  s      r9  r  zkucoin.parse_transfer_status  s(    )
 &&9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}|                      |||          S )Nz%Assets Transferred in After Upgradingr   Depositr0  
WithdrawalTransferTrade_Exchanger  zKuCoin BonusbonuszReferral Bonusr   RewardszAirdrop/ForkairdropzOther rewardsz
Fee Rebaterebatez
Buy CryptozSell CryptorS  zPublic Offering PurchasezRefunded Feesr  zKCS Pay FeeszMargin TradeLoans)r  zInstant ExchangezSub-account transferzLiquidation Feesrx  )r7  rE  r  s      r9  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22r:  c                 >    ddddd}|                      |||          S )Nr  r  )r  r  
TransferInTransferOutrx  )r7  r  
directionss      r9  parse_ledger_directionzkucoin.parse_ledger_direction!  s4     	
 

 
IyAAAr:  c                 :    ddd}|                      |||          S )NrO  r'  )	CompletedPendingrx  r-  s      r9  parse_ledger_statuszkucoin.parse_ledger_status*  s.     
 
 &&999r:  itemc                    |                      |d          }|                      |d          }|                     ||          }|                     ||          }|                      |d          }d }|                      |d          }|                     |          }	|                     |dd          }
|                      |d          }|                     |d          }||                     |d	          }|d
}|                     |          }|                      |d          }d }|h|dk    rb	 t          j        |          }|                      |d          }|                      |d          }||}n|}n# t          $ r}|}Y d }~nd }~ww xY wd }| 
                    |                      |d                    }d }||}|                     |          |d}|                      |d          }|                     |||                     |
          ||||	||                     t          j        |                    ||d ||                     |          |d|          S )Nr>   r  ru  r  r  rE  r  r  rG  CONTRACTcontextr  rg  r  r  )r}  r  r   )rT  r>   r  r"  referenceIdreferenceAccountrE  r  ru  r   rH  beforeafterr   r  )rV  r  safe_currencyr  r]  rC  r  jsonloads	Exception	omit_zeror6  safe_ledger_entryr  r9   r  r  )r7  r  r  r>   r$  r  ru  balanceAfterr  rE  r  r"  r   rH  r  r  r  rg  r  excr  r  r  r   s                           r9  parse_ledger_entryzkucoin.parse_ledger_entry1  s   8 dD))%%dJ77
&&z8<<%%j(;;!!$11""433++G44&&t[&AA	""477%%dK88	))$77I$$<<	**""433 7b==
&G,,**69==**69==&")KK")K & & &%&..!1!1$!>!>??K,,W55;OOC!!$11%%44Y??& '''(:6(B(BCC" !..v66'
 '
  !  	s   1AE9 9
FF

Fc                   K   |                                   d{V  |                                  d{V  d}|                     |dd          \  }}d}|                     |          \  }}|r|                     d||||           d{V S i }|||d<   d}| |                     |          }|d         |d<   |                     d||          \  }}d}	|                     d|          \  }	}d}
|                     dd|          \  }
}| 	                    | j
        d	          }|                     ||
|
          }
d}|rb|	0|                     |                     ||                     d{V }n|                     |                     ||                     d{V }ne|
d
k    r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |d          }||                     ||||          S | 	                    |d          }|                     |ddg           }|                     ||||          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-new/rest/account-info/account-funding/get-account-ledgers-spot-margin
        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-tradehf
        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-marginhf
        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-futures

        :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 dict [params.type]: 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-entry-structure>`
        NFr}   r  r  r>   r  r  r  r  r?  rc  dataList)r(  load_accountsrU  r  r  r  r  r  r@  r\  r0  rV   privateGetHfMarginAccountLedgersrY  privateGetHfAccountsLedgers#futuresPrivateGetTransactionHistoryprivateGetAccountsLedgersr  parse_ledgerr  )r7  r  r  r  rD  r  r  r_  r  r  rE  r  rF  r  r?  rc  s                   r9  fetch_ledgerzkucoin.fetch_ledger  s     & !!!!!!!!!  """""""""88PZ[[&..v66
F 	f::=$PUW\^deeeeeeeee
 !&GI}}T**H"*4.GJ227GVLL
!??vVV
F99-vVVf6FGGd;; 	Z%!%!F!Ft{{SZ\bGcGc!d!ddddddd!%!A!A$++gW]B^B^!_!_______Z, "EEdkkRY[aFbFbccccccccHH!;;DKKQW<X<XYYYYYYYYHL >>(F33$$XxFFF~~h//  w
B??  %???r:  c                    |                      | j        di           }|                      ||i           }|                      ||i           }|                     ||| j        d                   }	|                     |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 |                     |dd          S )Nr  rD   r  rE   r  r}  r   )r\  r0  rV  r  )r7  r   r  pathrD  configr  apiVersionsmethodVersionsdefaultVersionrD   s              r9  calculate_rate_limiter_costz"kucoin.calculate_rate_limiter_cost  s    >>$,
B??nnXsB77VR@@)).$Y@WXX""69nEEd??$<__$&..$<__$&..$<vvq111r:  c                     |                      |dd          }|                     |dd                   }|                     |d          }|                     ||          |                     |dd          d||                     |          |d	S )
Nr  r   r      r  dailyIntRatedayRatioi \&)r  r  periodr   rH  rT  )r]  r  rV  r  r  r  )r7  rT  r  timestampIdr   r$  s         r9  parse_borrow_ratezkucoin.parse_borrow_rate  s    $ (({KHH%%k!B$&788	%%dJ77
//
HEE&&t^ZHH"Y//
 
 	
r:  c                   K   |                                   d{V  d}|                     d|d          \  }}i }d}|2|                     |          }|dk    r|d         |d<   n|d         |d<   d}	||                     |          }	d}
|dk    r0|                     |                     ||                     d{V }
n/|                     |                     ||                     d{V }
|                     |
di           }|dk    r|                     |d	g           n|                     |d
g           }| 	                    ||	          }| 
                    ||||          }|                     ||||          S )ac  
        fetch the interest owed by the user for borrowing currency for margin trading

        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-cross-margin
        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-isolated-margin

        :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>`
        Nrg   r  r  r>   rd  r  r?  rf  r   )r(  r  r  r  rm  rY  privateGetMarginAccountsr\  r  parse_borrow_interestsfilter_by_currency_since_limitfilter_by_symbol_since_limit)r7  r  rd  r  r  rD  r  r_  r  r  rF  r?  rf  r_  filteredByCurrencys                  r9  fetch_borrow_interestzkucoin.fetch_borrow_interest9  s      !!!!!!!!!
!??@UW]_fgg
F}}T**HZ''-5d^)**+3D>([[((F##!<<T[[RX=Y=YZZZZZZZZHH!::4;;wPV;W;WXXXXXXXXHB ~~h338Bj8P8Ph333W[WeWefjlvxzW{W{..vv>>!@@4QVX]^^001CVUTYZZZr:  rT  c                    |                      |d          }|dnd}|                     ||          }|                      |d          }|                     |d          }|                     |di           }d }d }	d }
|dk    rC|                     |d          }|                     |d          }	|                      |d          }
nB|                     |d          }|                     |d	          }	|                      |d          }
|||                     |
          |	|                     |d
          ||||                     |          d	S )Nrd  r  r  r  rh  r^  r_  r  accruedInterestr  )	rT  rd  r  r_  interestRateamountBorrowedr  r   rH  )rV  rb  rC  r\  r  r  r  )r7  rT  r  re  r  rd  r   isolatedBaser  r_  r$  s              r9  parse_borrow_interestzkucoin.parse_borrow_interest  sk   Z ##D(33!)!1WW

!!(F33!!&(33%%dK88	~~dK<<
##!--lKHHN''jAAH)),
CCJJ!--dK@@N''.?@@H))$
;;J//
;;  ,,T>BB,$"Y//

 

 
	
r:  c                   K   |                                   d{V  |                     d|          }|                     |dd          }|dk    }d|i}|||d<   |                     d||          \  }}|||d	<   |                     |                     ||                     d{V }	|                     |	d
          }
|                     |
dg           }|                     ||||          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-new/rest/margin-trading/debit/get-interest-history

        :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
        Nrh   r   r  r  
isIsolated	startTimeendTimer  r?  rc  )	r(  r  rV  r  privateGetMarginInterestrY  r\  r  parse_borrow_rate_histories)r7  codesr  r  rD  r  r  r  r_  rF  r?  rowss               r9  fetch_borrow_rate_historiesz"kucoin.fetch_borrow_rate_histories  s$      !!!!!!!!!99:TV\]]%%lAw??
 J.
*
 #(GK 229gvNN"'GJ66t{{7F7S7STTTTTTTT* ~~h//~~dGR00//eUEJJJr:  c                   K   |                                   d{V  |                     d|          }|                     |dd          }|dk    }|                     |          }||d         d}	|||	d<   |                     d	|	|          \  }	}|||	d
<   |                     |                     |	|                     d{V }
|                     |
d          }|                     |dg           }| 	                    ||||          S )a  
        retrieves a history of a currencies borrow interest rate at specific time slots

        https://www.kucoin.com/docs-new/rest/margin-trading/debit/get-interest-history

        :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>`
        Nrh   r   r  r  r>   )r  r  r  r  r  r?  rc  )
r(  r  rV  r  r  r  rY  r\  r  parse_borrow_rate_history)r7  r  r  r  rD  r  r  r  r  r_  rF  r?  r  s                r9  fetch_borrow_rate_historyz kucoin.fetch_borrow_rate_history  s?      !!!!!!!!!99:TV\]]%%lAw??
 J.
==&&$ 
 
 #(GK 229gvNN"'GJ66t{{7F7S7STTTTTTTT* ~~h//~~dGR00--dD%GGGr:  c                 &   i }t          dt          |                    D ]}||         }|                     |                     |d                    }||                     ||          r;||vrg ||<   |                     |          }	||         }
|
                    |	           t          |                                          }t          dt          |                    D ]+}||         }| 	                    ||         |||          ||<   ,|S )Nr   r  )
r  r  r  rV  r  r  r  r  r9  r  )r7  rF  r  r  r  borrowRateHistoriesr  r  r  borrowRateStructureborrowRateHistoriesCoder9  s               r9  r  z"kucoin.parse_borrow_rate_historiesS  s0    %'q#h--(( 	D 	DAA;D**4+;+;D*+M+MNND}dE : :} 33302'-&*&<&<T&B&B#*=d*C''../BCCC',,..//q#d))$$ 	{ 	{A7D(,(K(KL_`dLegkmrty(z(z%%""r:  c                 \  K   |                                   d{V  |                     |          }|d         |                     ||          dd}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        create a loan to borrow margin

        https://www.kucoin.com/docs-new/rest/margin-trading/debit/borrow

        :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>`
        Nr>   r  )r  r  r  r?  )r(  r  r#  privatePostMarginBorrowrY  r\  parse_margin_loanr7  r  ru  rD  r  r_  rF  r?  s           r9  borrow_cross_marginzkucoin.borrow_cross_marginn  s       !!!!!!!!!==&& ..tV<< 
 

 55dkk'66R6RSSSSSSSS ~~h33%%dH555r:  c                   K   |                                   d{V  |                     |          }|                     |          }|d         |                     ||          |d         ddd}|                     |                     ||                     d{V }|                     |di           }	|                     |	|          S )a9  
        create a loan to borrow margin

        https://www.kucoin.com/docs-new/rest/margin-trading/debit/borrow

        :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>`
        Nr>   r  T)r  r  rd  r  r  r?  )r(  r  r  r#  r  rY  r\  r  
r7  rd  r  ru  rD  r  r  r_  rF  r?  s
             r9  borrow_isolated_marginzkucoin.borrow_isolated_margin  s       !!!!!!!!!V$$==&& ..tV<<Tl 
 
 55dkk'66R6RSSSSSSSS ~~h33%%dH555r:  c                 Z  K   |                                   d{V  |                     |          }|d         |                     ||          d}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        repay borrowed margin and interest

        https://www.kucoin.com/docs-new/rest/margin-trading/debit/repay

        :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>`
        Nr>   )r  r  r?  )r(  r  r#  privatePostMarginRepayrY  r\  r  r  s           r9  repay_cross_marginzkucoin.repay_cross_margin  s       !!!!!!!!!==&& ..tV<<
 
 44T[[&5Q5QRRRRRRRR ~~h33%%dH555r:  c                   K   |                                   d{V  |                     |          }|                     |          }|d         |                     ||          |d         dd}|                     |                     ||                     d{V }|                     |di           }	|                     |	|          S )a  
        repay borrowed margin and interest

        https://www.kucoin.com/docs-new/rest/margin-trading/debit/repay

        :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>`
        Nr>   T)r  r  rd  r  r?  )r(  r  r  r#  r  rY  r\  r  r	  s
             r9  repay_isolated_marginzkucoin.repay_isolated_margin  s       !!!!!!!!!V$$==&& ..tV<<Tl	
 
 44T[[&5Q5QRRRRRRRR ~~h33%%dH555r:  c                    |                                  }|                     |d          }|                     |d          |                     ||          |                     |d          d ||                     |          |dS )Nr  orderNo
actualSize)r>   r  ru  rd  r   rH  rT  )r<  rV  r  r  r  )r7  rT  r  r   r$  s        r9  r  zkucoin.parse_margin_loan  s     %%''	%%dJ77
""433//
HEE&&t\::"Y//
 
 	
r:  r  c                    K   |                                   d{V  |                     |           d{V }|                     |dg           }|                     ||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>`
        Nr?  r  )r(  r  r  parse_deposit_withdraw_fees)r7  r  rD  rF  r?  s        r9  fetch_deposit_withdraw_feesz"kucoin.fetch_deposit_withdraw_fees  s       !!!!!!!!!11&99999999& ~~h33//eZHHHr:  c                   K   d}|                      ||          \  }}|dk    rt          | j        dz             |                                  d{V  |                     |          }|d         st          | j        dz             d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          }|                     |d	|i          S )
a{  
        fetch the set leverage for a market

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-cross-margin-leverage

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `leverage structure <https://docs.ccxt.com/?id=leverage-structure>`
        Nr  zG fetchLeverage() currently supports only params["marginMode"] = "cross"r  z/ fetchLeverage() supports contract markets onlyrd  r>   r?  r  )	r  r3   r>   r(  r  %futuresPrivateGetGetCrossUserLeveragerY  r\  parse_leverage)	r7  rd  rD  r  r  r_  rF  r?  r  s	            r9  fetch_leveragezkucoin.fetch_leverage2  s6      
!??OO
F  tw)rrsss!!!!!!!!!V$$j! 	\tw)ZZ[[[fTl
 CCDKKPWY_D`D`aaaaaaaa ~~h33$$T622{{6*$
   	r:  r  c                 ^  K   |                                   d{V  d}d}|                     dd|          \  }}||dk    r@|dk    r:|                     |          }|d         r|                     |||           d{V S d}|                     d|          \  }}|t          | j        dz             i }|dk    r|t          | j        dz             ||d	         |d
<   t          |          |d<   |dk    |d<   |                     | 	                    ||                     d{V S )a~  
        set the level of leverage for a market

        https://www.kucoin.com/docs-new/rest/margin-trading/debit/modify-leverage
        https://www.kucoin.com/docs-new/rest/futures-trading/positions/modify-cross-margin-leverage

        :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   rL   rM   r  z, setLeverage requires a marginMode parameterr  z< setLeverage requires a symbol parameter for isolated marginr>   rd  r  r  )
r(  r@  r  set_contract_leverager  r+   r>   str%privatePostPositionUpdateUserLeveragerY  )r7  r  rd  rD  r  rp  r  r_  s           r9  set_leveragezkucoin.set_leverageW  s      !!!!!!!!!
!??tU[\\
FZ6%9%9
h@V@V[[((Fj! R!77&&QQQQQQQQQ
!??vVV
F#DG.\$\]]]###DG.l$lmmm &tGH!(mm
!+z!9??GU[@\@\]]]]]]]]]r:  c                   K   d}|                      ||          \  }}|dk    rt          | j        dz             |                                  d{V  |                     |          }|d         t          |          d}|                     |                     ||                     d{V }|                     |d          }||d         d||dS )	a  
        set the level of leverage for a market

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/modify-cross-margin-leverage

        :param float leverage: the rate of 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  zS setLeverage() currently supports only params["marginMode"] = "cross" for contractsr>   )rd  r  r  rd  )rT  rd  r  longLeverageshortLeverage)	r  r3   r>   r(  r  r  )futuresPrivatePostChangeCrossUserLeveragerY  rC  )	r7  r  rd  rD  r  r  r_  rF  leverageNums	            r9  r  zkucoin.set_contract_leveragex  s
      
!??OO
F  tw)~~!!!!!!!!!V$$TlH
 
 GGT[]cHdHdeeeeeeee ''*==X&'(
 
 	
r:  c                 j   K   |                      ||                     |ddi                     d{V S )a  
        fetch the current funding rate interval

        https://www.kucoin.com/docs-new/rest/futures-trading/funding-fees/get-current-funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        r   FN)fetch_funding_raterY  )r7  rd  rD  s      r9  fetch_funding_intervalzkucoin.fetch_funding_interval  sC       ,,VT[[%QV5X5XYYYYYYYYYr:  c                   K   |                                   d{V  |                     |          }d|d         i}d}|                     |dd|          \  }}d}|r0|                     |                     ||                     d{V }n/|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetch the current funding rate

        https://www.kucoin.com/docs-new/rest/ua/get-current-funding-rate
        https://www.kucoin.com/docs-new/rest/futures-trading/funding-fees/get-current-funding-rate

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.uta]: set to True for the unified trading account(uta)
        :returns dict: a `funding rate structure <https://docs.ccxt.com/?id=funding-rate-structure>`
        Nrd  r>   Frv   r   r?  )r(  r  rU  utaGetMarketFundingRaterY  (futuresPublicGetFundingRateSymbolCurrentr\  parse_funding_rate)r7  rd  rD  r  r_  r   rF  r?  s           r9  r%  zkucoin.fetch_funding_rate  s      !!!!!!!!!V$$fTl
 33F<NPUWZ[[V 	i "99$++gv:V:VWWWWWWWWHH$ "JJ4;;W^`fKgKghhhhhhhhH~~h33&&tV444r:  c                 8   |                      |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                    iS )NfundingTimerI  rd  rT  r  r`  rt  r  dailyInterestRateestimatedSettlePricer   rH  fundingRatenextFundingRater_  fundingTimestampfundingDatetimepredictedValuenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer  r  )rC  rV  r  r  r  r  parse_funding_interval)r7  r?  r  r1  r7  re  s         r9  r*  zkucoin.parse_funding_rate  s   .  ,,T=AA#'#4#4T;#G#G ##D(33
D
d&&xzJJ
 
 $	

 D,,T3FGG
 #D
 
 
 4--d4EwOO
  0
 t||,<==
 t//6FGG
 #D
 "4
 "4
  '(@!
" &t||4L'M'M#
$ 33D4D4DT=4Y4YZZ%
 
 	
r:  c                 @    dddddd}|                      |||          S )Nr*  r,  r.  16h24h)360000014400000288000005760000086400000rx  )r7  r  	intervalss      r9  r9  zkucoin.parse_funding_interval  s7    
 
	 	8X>>>r:  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|                     |d          }d}|                     |dd|          \  }}|                     |d          }|}	|}
|d	}	||                                 }
d}d
}|rS|	|d<   |
|d<   |                     | 	                    ||                     d{V }| 
                    |d
i           }d}n9|	|d<   |
|d<   |                     | 	                    ||                     d{V }|                     ||g           }|                     ||||          S )at  
        fetches historical funding rate prices

        https://www.kucoin.com/docs-new/rest/futures-trading/funding-fees/get-public-funding-history
        https://www.kucoin.com/docs-new/rest/ua/get-history-funding-rate

        :param str symbol: unified symbol of the market to fetch the funding rate history for
        :param int [since]: not used by kucuoinfutures
        :param int [limit]: the maximum amount of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>` to fetch
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: end time in ms
        :param boolean [params.uta]: set to True for the unified trading account(uta), defaults to True
        :returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/?id=funding-rate-history-structure>`
        Nz5 fetchFundingRateHistory() requires a symbol argumentrd  r>   r  Trw   r   r   r?  r  r  r  r  r  )r+   r>   r(  r  rC  rU  r  r<  utaGetMarketFundingRateHistoryrY  r\  $futuresPublicGetContractFundingRatesr  parse_funding_rate_histories)r7  rd  r  r  rD  r  r_  r  r   startendrF  	resultKeyutaResponser  s                  r9  fetch_funding_rate_historyz!kucoin.fetch_funding_rate_history  s      >#DG.e$efff!!!!!!!!!V$$fTl
 !!&'2233F<UW\^abbV67++=E=##%%C	 #	e!&GI"GG !% C CDKKPWY_D`D` a aaaaaaaK~~k62>>HII#GFOGDM "FFt{{SZ\bGcGcddddddddH)R8800NNNr:  c                     |                      |d          }|                     |dd          }||                     ||          |                     |d          ||                     |          dS )Nrd  rm  	timepointr/  )rT  rd  r/  r   rH  )rV  r  r  r  r  )r7  rT  r  re  r   s        r9  parse_funding_rate_historyz!kucoin.parse_funding_rate_historyb  sz     ##D(33''dK@@	&&x88++D-@@"Y//
 
 	
r:  c                   K   |t          | j        dz             |                                  d{V  |                     |          }d|d         i}|||d<   |||d<   |                     |                     ||                     d{V }|                     |d          }|                     |dg           }	g }
t          d	t          |	                    D ]}|	|         }| 
                    |d
          }|
                    |||                     |                     |d                    ||                     |          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          |                     |d          d           |
S )a\  
        fetch the history of funding payments paid and received on self account

        https://www.kucoin.com/docs-new/rest/futures-trading/funding-fees/get-private-funding-history

        :param str symbol: unified market symbol
        :param int [since]: the earliest time in ms to fetch funding history for
        :param int [limit]: the maximum number of funding history structures to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `funding history structure <https://docs.ccxt.com/?id=funding-history-structure>`
        Nz1 fetchFundingHistory() requires a symbol argumentrd  r>   r  maxCountr?  r  r   rI  r  r  r/  r`  positionQtypositionCost)rT  rd  r  r   rH  r>   ru  r/  r`  rQ  rR  )r+   r>   r(  r  futuresPrivateGetFundingHistoryrY  r  r  r  r  rC  r  r  rV  r  r  )r7  rd  r  r  rD  r  r_  rF  r?  r  r  r  listItemr   s                 r9  fetch_funding_historyzkucoin.fetch_funding_history{  s      >#DG.a$abbb!!!!!!!!!V$$fTl
 !&GI"'GJ==dkk'SY>Z>Z[[[[[[[[. x00>>$
B77q#h--(( 	 	A{H))(K@@IKK  //0@0@K[0\0\]]& LL33&&x66**8Y??#//-HH!--hDD#//-HH $ 0 0> J J      r:  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-details

        fetch data on an open position
        :param str symbol: unified market symbol of the market the position is held in
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nrd  r>   r?  )r(  r  futuresPrivateGetPositionrY  r\  parse_positionr  s          r9  fetch_positionzkucoin.fetch_position  s       !!!!!!!!!V$$fTl
 77GV8T8TUUUUUUUUZ ~~h33""4000r:  c                    K   |                                   d{V  |                     |           d{V }|                     |d          }|                     ||          S )a  
        fetch all open positions

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-list

        :param str[]|None symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr?  )r(  futuresPrivateGetPositionsr  parse_positionsr  s        r9  fetch_positionszkucoin.fetch_positions  s}       !!!!!!!!!88@@@@@@@@^ ~~h//##D'222r:  c                   K   |                                   d{V  |d}d|i}|||d<   |                     |d          }||                     |d          }||d<   |                     |                     ||                     d{V }|                     |d          }|                     |dg           }	|                     |	|          S )	a  
        fetches historical positions

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-positions-history

        :param str[] [symbols]: list of unified market symbols
        :param int [since]: the earliest time in ms to fetch position history for
        :param int [limit]: the maximum number of entries to retrieve
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param int [params.until]: closing end time
        :param int [params.pageId]: page id
        :returns dict[]: a list of `position structure <https://docs.ccxt.com/?id=position-structure>`
        Nr  r  r  r  r  r?  rc  )r(  rC  r  !futuresPrivateGetHistoryPositionsrY  r\  r  r\  )
r7  r   r  r  rD  r_  r  rF  r?  rc  s
             r9  fetch_positions_historyzkucoin.fetch_positions_history;   s       !!!!!!!!!=EU
 #GFO!!&'22YYvw//F!GDM??GU[@\@\]]]]]]]]N ~~h//tWb11##E7333r:  r  c                 2   |                      |d          }|                     ||          }|                     |d          }|                      |d          }d }|                     |d          }|0t	          j        |d          rd}n8t	          j        |d          rd}n ||                    d          dk    rd}nd}t	          j        |                      |d	                    }|                      |d
          }	t	          j	        |	|          }
|                      |d          }| 
                    |d          }d }||rdn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#|                     t	          j        |                    d$| 
                    |d$          d%|                     |d&d'          d |                     |d(          |                     |d)          d |                     |d*          ||d d d d+
          S ),Nrd  currentTimestamp
currentQtyrE  r  longshortposCostposInitunrealisedPnl	crossModer  r  rT  r>   
positionIdr   rH  r  	closeTimeinitialMargininitialMarginPercentagemaintenanceMarginposMaintmaintenanceMarginPercentagemaintMarginReq
entryPriceavgEntryPrice	openPricenotionalr  realLeverageunrealizedPnl	contractsr~  realizedPnlrealisedPnlpnlliquidationPricer`  maintMargin)
marginRatior}  r`  rB  
collateralr  r  r  r  r  )rV  rb  rC  r  r9   r  	string_ltfindr  r  r  safe_positionr]  r  r6  r  r  )r7  r  r  rd  r   r  r  rE  rv  rm  rn  ri  rj  r  s                 r9  rX  zkucoin.parse_position   s   L !!(H55!!&&11%%h0BCC	,77%%h77 s++ "4-- yy  2%%%d&6&6x&K&KLL((9==")"4]H"M"M((?CCOOHk::	
 $-=:J!! #
H#
$$$Xt\BB#
 d&&vx88#
 	#

 Y//#
 "4#4#4X{#K#K#
 T..}==#
 &t'8'89P'Q'Q#
  !1!1(J!G!G#
 *4+;+;HFV+W+W#
 $,,XTT#
 ))(33#
 **8^ZPP#
 T..}==#
 **7+=d+C+CDD#
  DOOFNCC!#
" 4--huMM##
$   $ 0 0;M N N))(K@@**8]CC$!#7#
 #
 #
   	r:  r  c                   K   |                                   d{V  d}||                     |          }g }|                     |ddg           }|                     |ddg          }d}t	          dt          |                    D ]O}d}|t          | j        dz             |                    |d         | 	                    ||          d	           Pt	          dt          |                    D ]}|                    ||                    |rd
nd}	i }
||
|	<   | 
                    |                     |
|                     d{V }|                     |dg           }|                     ||          S )a  
        cancel multiple orders for contract markets

        https://www.kucoin.com/docs-new/3470241e0

        :param str[] ids: order ids
        :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 str[] [params.clientOrderIds]: client order ids
        :returns dict: an list of `order structures <https://docs.ccxt.com/?id=order-structure>`
        NclientOrderIds
clientOidsFr   TzL cancelOrders() requires a symbol argument when cancelling by clientOrderIdsr>   )rd  r  clientOidsListorderIdsListr?  )r(  r  r  r  r  r  r+   r>   r  rV  %futuresPrivateDeleteOrdersMultiCancelrY  r  r`  )r7  r  rd  rD  r  ra  r  useClientorderIdr  
requestKeyr_  rF  r   s                r9  cancel_orderszkucoin.cancel_orders   s      !!!!!!!!![[((F))&2BLRTUU6$4l#CDD q#n--.. 	 	A#~'  3A  )A  B  B  B!! ,!--na@@# #     q#c((## 	* 	*A!!#a&)))))9M%%~
,
CCDKKPWY_D`D`aaaaaaaa* &"55  000r:  c                   K   |                                   d{V  |                     |          }|                                 }|d         |                     ||          |d}|                     |                     ||                     d{V }|                     |d          }|                     |                     ||          |                     ||          dd          S )a  
        add margin

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/add-isolated-margin

        :param str symbol: unified market symbol
        :param float amount: amount of margin to add
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param str [params.positionSide]: *required for hedged position* 'BOTH', 'LONG' or 'SHORT'(default is 'BOTH')
        :returns dict: a `margin structure <https://docs.ccxt.com/?id=margin-structure>`
        Nr>   )rd  rM   bizNor?  r  )ru  r  )r(  r  r  r  -futuresPrivatePostPositionMarginDepositMarginrY  r  parse_margin_modification)	r7  rd  ru  rD  r  r  r_  rF  r?  s	            r9  
add_marginzkucoin.add_margin8!  s
      !!!!!!!!!V$$yy{{Tl..vv>>
 

 KKDKKX_agLhLhiiiiiiiid x00{{499$GG..vv>>J
 J
   	r:  c                    |                      |d          }|                     ||          }|                      |d          }|                     |d          }|rdnd}|                      |d          }|                     |d          }||                     ||          d |d d |                     |          d ||                     |          d
S )	Nr>   r  rj  r  r  rd  rb  )
rT  rd  rE  r  ru  r]  r  r   r   rH  )rV  rb  r  rC  r  r  r  )	r7  rT  r  r>   r$  rj  modere  r   s	            r9  r  z kucoin.parse_margin_modification!  s    \ dD))!!"f--%%d,<==
OOD+66	#3ww##FH55%%d,>??	&&x88++J77"Y//
 
 	
r:  c                 0  K   |                                   d{V  |                     |          }d|d         i}|                     |                     ||                     d{V }|                     |di           }|                     ||          S )a  
        fetches the margin mode of a trading pair

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-margin-mode

        :param str symbol: unified symbol of the market to fetch the margin mode for
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `margin mode structure <https://docs.ccxt.com/?id=margin-mode-structure>`
        Nrd  r>   r?  )r(  r  &futuresPrivateGetPositionGetMarginModerY  r\  parse_margin_moder  s          r9  fetch_margin_modezkucoin.fetch_margin_mode!  s       !!!!!!!!!V$$fTl
 DDT[[QXZ`EaEabbbbbbbb ~~h33%%dF333r:  r  c                 Z    |                      |d          }|dk    rdnd}||d         |dS )Nr  ISOLATEDr  r  rd  )rT  rd  r  rx  )r7  r  r  
marginTypes       r9  r  zkucoin.parse_margin_mode!  sG    %%j,??
$.*$<$<ZZ7
X&$
 
 	
r:  c                   K   |t          | j        dz             |                     d|dddg           |                                  d{V  |                     |          }|d         st          | j        dz             |d	         |                                d
}|                     |                     ||                     d{V }| 	                    |di           }| 
                    ||          S )a  
        set margin mode to 'cross' or 'isolated'

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/switch-margin-mode

        :param str marginMode: 'cross' or 'isolated'
        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: response from the exchange
        Nz+ setMarginMode() requires a symbol argumentr   r  r  r  r  z/ setMarginMode() supports contract markets onlyr>   )rd  r  r?  )r+   r>   check_required_argumentr(  r  r3   r>  *futuresPrivatePostPositionChangeMarginModerY  r\  r  )r7  r  rd  rD  r  r_  rF  r?  s           r9  set_margin_modezkucoin.set_margin_mode!  s#      >#DG.[$[\\\$$_j,QXZdPefff!!!!!!!!!V$$j! 	\tw)ZZ[[[Tl$**,,
 
 HHU\^dIeIeffffffff ~~h33%%dF333r:  r  c                    K   |                                   d{V  |rdnd}d|i}|                     |                     ||                     d{V }|S )a  
        set hedged to True or False for a market

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/switch-position-mode

        :param bool hedged: set to True to use two way position
        :param str [symbol]: not used by bybit setPositionMode()
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a response from the exchange
        Nr  r  positionMode)r(  ,futuresPrivatePostPositionSwitchPositionModerY  )r7  r  rd  rD  posModer_  rF  s          r9  set_position_modezkucoin.set_position_mode"  s       !!!!!!!!!(##SG
 JJ4;;W^`fKgKghhhhhhhh r:  c                    K   |                      |           d{V }|                     |di           }|                     |d          }||dk    dS )a  
        fetchs the position mode, hedged or one way

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-mode

        :param str [symbol]: unified symbol of the market to fetch the position mode for(not used in blofin fetchPositionMode)
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an object detailing whether the market is in hedged or one-way mode
        Nr?  r  r   )rT  r  )(futuresPrivateGetPositionGetPositionModer\  rC  )r7  rd  rD  rF  r?  r  s         r9  fetch_position_modezkucoin.fetch_position_mode)"  sq       FFvNNNNNNNN~~h33((~>>"a'
 
 	
r:  c                 L  K   |                                   d{V  |                     |          }|                     |d          }|                     |dd          }|                     |ddg          }|'|                     |                                           }|d         d|dd}d}|r0|                     |                     ||                     d{V }n/| 	                    |                     ||                     d{V }| 
                    ||          S )	aH  
        closes open positions for a market

        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
        https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order-test

        :param str symbol: Unified CCXT market symbol
        :param str side: not used by kucoin closePositions
        :param dict [params]: extra parameters specific to the okx api endpoint
        :param str [params.clientOrderId]: client order id of the order
        :returns dict[]: `A list of position structures <https://docs.ccxt.com/?id=position-structure>`
        Nr  r  Fr>   Tr  )rd  
closeOrderr  rE  )r(  r  rV  r  r  r#  r=  r(  rY  r*  r  )	r7  rd  r  rD  r  r  r  r_  rF  s	            r9  close_positionzkucoin.close_position;"  sL      !!!!!!!!!V$$((AANN66599	6FO#<==  11$**,,??MTl&	
 
  	Y!>>t{{7TZ?[?[\\\\\\\\HH!::4;;wPV;W;WXXXXXXXXH&111r:  c                   K   |                                   d{V  |                     |          }|d         st          | j        dz             d}|                     |dd|          \  }}|r4|                     |g|           d{V }|                     ||g           S d|d         i}|                     |                     ||                     d{V }|                     |d	g           }| 	                    ||          S )
au  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-isolated-margin-risk-limit

        :param str symbol: unified market symbol
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :param boolean [params.uta]: set to True to fetch leverage tiers for unified trading account instead of futures account(default is False)
        :returns dict: a `leverage tiers structure <https://docs.ccxt.com/?id=leverage-tiers-structure>`
        Nr  z: fetchMarketLeverageTiers() supports contract markets onlyFr   r   rd  r>   r?  )
r(  r  r,   r>   rU  fetch_leverage_tiersr  (futuresPublicGetContractsRiskLimitSymbolrY  parse_market_leverage_tiers)	r7  rd  rD  r  r   r  r_  rF  r?  s	            r9  fetch_market_leverage_tiersz"kucoin.fetch_market_leverage_tiers\"  sA      !!!!!!!!!V$$j! 	eTW'ccddd33F<VX]_bccV 	644fXvFFFFFFFFF>>&&"555fTl
 FFt{{SZ\bGcGcdddddddd$ ~~h33//f===r:  c                    g }t          dt          |                    D ]}|                     ||          }|                     |d          }|                     ||          }|                    |                     |dd          |d         |d         |                     |dd          |                     |dd	          |                     |d
d          |                     |d          |d           |S )zz
 @ignore
        :param dict info: Exchange market response for 1 market
        :param dict market: CCXT market
        r   rd  r  tierr   minRiskLimitminSizemaxRiskLimitmaxSizemaintainMarginmaintainMarginRater  )r  rd  r  minNotionalmaxNotionalmaintenanceMarginRater  rT  )r  r  r\  rV  rb  r  r  r  )r7  rT  r  r  r  r  re  s          r9  r  z"kucoin.parse_market_leverage_tiers"  s   : q#d))$$ 	 	A>>$**D''h77H%%h77FLL**4&AA *"6N#11$	RR#11$	RR)-););DBRTh)i)i#//mDD	 	 	 	 	 	 r:  c                 8  K   |                                   d{V  |t          | j        dz             |                     |ddd          }d}|                     d||          \  }}|                                }|dk    rt          | j        d	z             |                     |          }d
|ddd                    |          d}| 	                    | 
                    ||                     d{V }|                     |dg           }i }|                     |          }	t          dt          |	                    D ]T}
|                     |	|
          }|                     |d          }|$||vrg ||<   ||                             |           U|S )a  
        retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes

        https://www.kucoin.com/docs-new/rest/ua/get-position-tiers

        :param str[] symbols: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a dictionary of `leverage tiers structures <https://docs.ccxt.com/?id=leverage-tiers-structure>`, indexed by market symbols
        Nz1 fetchLeverageTiers() requires a symbols argumentrN   FTr  r   CROSSz0 fetchLeverageTiers() supports cross margin onlyrK  
RISK_LIMITUNIFIED,)rL  r  r?  r  rd  r?  r   rd  )r(  r+   r>   r|  r  r>  r,   
market_idsr:  utaGetMarketPositionTiersrY  r  r  r  r  r\  rV  r  )r7  r   rD  r  	marketIdsr_  rF  r?  r  r  r  r  rd  s                r9  r  zkucoin.fetch_leverage_tiers"  s      !!!!!!!!!?#DG.a$abbb%%gvudCC
!??@TV\^hii
F%%''
  TW'YYZZZOOG,,	"$ $hhy))
 
 77GV8T8TUUUUUUUU4 ~~h330066q#e**%% 	, 	,A>>%++D%%dH55F!&((%'F6Nv%%d+++r:  r   r  c                 N   |                      | j        di           }|                      ||i           }|                      ||i           }	|                     |	|| j        d                   }
|                     |d|
          }|                     |d          }d|z   dz   |                     ||          z   }|dk    rd|                     ||          z   }|dk    rd|                     ||          z   }d}|d	k    s|d
k    r!d|                     ||          z   }|d
k    rd}|                     ||                     |                    }d}||ni }| j        d         |         }|                     |          sJ|dk    s|dk    r"|dk    r|d|                     |          z   z  }n| 	                    |          }|}d|d<   ||z   }|dk    }|dk    }|dk    }|dk    }|s	|s|s|s|r/| 
                                 t          |                                           }|                     d| j        |d|          }|                     |d          }|dk    rX|                     |                     | j                  |                     | j                  t&          j        d          }||d<   n
| j        |d<   ||z   |z   |z   }|                     |                     |          |                     | j                  t&          j        d          }||d<   |                      | j        di           }|r|                     |d|          n|                     |d |          }|                     |d!          }|                     |d"d#          }|f|d||z   | j        z   }|                     |                     |          |                     |          t&          j        d          }||d$<   ||d%<   d&|d'<   |r|                     |d(          }|||d)<   ||||d*S )+Nr  rD   z/api/rj  r   r   z/api/v1/Fr   r   z/api/ua/v1/Tr  r   r  r  r  ?zapplication/jsonzContent-Typer   r   r   2)KC-API-KEY-VERSIONz
KC-API-KEYzKC-API-TIMESTAMPr  base64zKC-API-PASSPHRASEzKC-API-SIGNr  rO   rL   r>   r   r  zKC-API-PARTNER-SIGNzKC-API-PARTNERr  zKC-API-PARTNER-VERIFYr?   zKC-BROKER-NAME)rS  r  bodyheaders)r\  r0  rV  r  implode_paramsextract_paramsr   is_empty	rawencoder  r  r  r=  rY  r   hmacencoder   r   hashlibsha256r  r]  ) r7  r  r   r  rD  r  r  r  r  r  r  rD   endpointisUtaPrivater  endpartrS  isFuturePrivate	isPrivateisBrokerisEarnr   apiKeyVersion
passphrasepayload	signaturer  	partnerIdpartnerSecretpartnerPayloadpartnerSignature
brokerNames                                    r9  signzkucoin.sign"  s    >>$,
B??nnXsB77VR@@)).$Y@WXX""69nEE69--W$s*T-@-@v-N-NN-T00v>>>H&==!D$7$7f$E$EEH5LLc\11$t':':4'H'HHHl""#		&$"5"5d";";<<%1''is#}}U## 	=5f&8&8H]@]@]C$.."7"777yy''*<'Hn"22I%	8O- 	; 	;8 	;v 	; 	;++---DJJLL))Ikk&)"k$-# # 	 G
 !,,W6JKKM##!YYt{{4='A'A4;;t{C[C[]d]kmuvv
/9+,,/3}+,&(83g=G		$++g"6"6DK8P8PRYR`bjkkI%.GM"nnT\9bAAGET  DdoogxAAAZ^ZiZijqsy  |C  [D  [DG(($77I ..w%HHM%M,E!*Y!6!D#'99T[[-H-H$++VcJdJdfmftv~## 1A-.,5()39/0 ;!--gv>>
)0:G,-fdwOOOr:  reasonrS  r  r  r  c
                    |s$|                      | j        d         ||           d S |                     |d          }
|                     |ddd          }| j        dz   |z   }|                     | j        d         ||           |                     | j        d         |
|           |                      | j        d         ||           |
dk    r|
d	k    rt          |          d S )
Nr  r  msgr?  r   r  200000r  )throw_broadly_matched_exceptionr4  rV  r]  r>   throw_exactly_matched_exceptionr'   )r7  r  r  rS  r  r  r  rF  requestHeadersrequestBody	errorCodemessagefeedbacks                r9  handle_errorszkucoin.handle_errors>#  s     	001I4QUVVV4 $$Xv66	$$XufbAA7S=4',,T_W-EwPXYYY,,T_W-EyRZ[[[,,T_W-EtXVVV  Y%%7%7)))tr:  c                   K   |                                   d{V  d}|                     |dd          \  }}|r|                     d||||           d{V S ddi}|                     |d          }||                     |d          }||d<   d}| |                     |          }|d	         |d
<   |||d<   |||d<   nd|d<   |                     d||          \  }}|                     |                     ||                     d{V }	| 	                    |	di           }
| 
                    |
dg           }|                     ||||          S )a  
        fetch a history of internal transfers made on an account

        https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-spot-margin

        :param str [code]: unified currency code of the currency transferred
        :param int [since]: the earliest time in ms to fetch transfers for
        :param int [limit]: the maximum number of transfer 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 transfers 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 `transfer structures <https://docs.ccxt.com/?id=transfer-structure>`
        NFr   r  r  TRANSFERr  r  r>   r  r  r  r!  r?  rc  )r(  rU  r  rC  r  r  r  r  rY  r\  r  parse_transfers)r7  r  r  r  rD  r  r_  r  r  rF  r?  rc  s               r9  fetch_transferszkucoin.fetch_transfersR#  s      !!!!!!!!!88AQS]^^& 	i::;KTSXZ_aghhhhhhhhhz
 !!&'22YYvw//F$GG}}T**H"*4.GJ!&GI"'GJ"%GJ227GVLL77GV8T8TUUUUUUUU4 ~~h33tWb11##E8UEBBBr:  c                    K   |                                   d{V  |                     |dddd          }|                     |           d{V }|                     |dg           }|                     ||          S )a  
        fetches the auto deleveraging rank and risk percentage for a list of symbols

        https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-list

        :param str[] [symbols]: list of unified market symbols
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict[]: an array of `auto de leverage structures <https://docs.ccxt.com/?id=auto-de-leverage-structure>`
        NTr?  )r(  r|  r[  r  parse_adl_ranksr  s        r9  fetch_positions_adl_rankzkucoin.fetch_positions_adl_rank#  s       !!!!!!!!!%%gtT4FF88@@@@@@@@^ ~~h33##D'222r:  c           
      8   |                      |d          }|                     |d          }|                      |d          }||                     ||d d          d d |                     t	          j        |d                    ||                     |          dS )Nrd  openingTimestampdelevPercentager  r@  )rT  rd  rankratingr  r   rH  )rV  rC  r  r6  r9   r  r  )r7  rT  r  re  r   r  s         r9  parse_adl_rankzkucoin.parse_adl_rank#  s    X ##D(33%%d,>??	%%d,=>>
&&xzJJ++G,>z5,Q,QRR"Y//
 
 	
r:  )Frh  )__name__
__module____qualname__r   r5  r=  r   rG  r`  r&   r   r  r  r  boolr  r  r   r  r   r%  r  r.  r2  r   r0  r=  dictr   rf  rj  ri  r   rz  r   r    r  r~  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r   r  r  r   r   r"  r   r  r  r  r  r  r'  rM  rQ  rS  r   rZ  rU  rV  rk  rq  rm  rn  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r"   r  r  r  r  r#   r  r$   r   r/  r%  rJ  rE  rR  rO  rb  r   rw  rl  r%   r   r  r  r  r  r  r  r   r  r  r  r  r	   r  r  r  r  r  r  r
  r  r  r  r  r   r  r  r  r  r!   r&  r%  r*  r9  rK  rN  rU  rY  r   r]  r`  rX  r  r   r  r  r   r  r  r  r  r  r  r   r  r  r   r  r  r  r  r   r  r  __classcell__)r8  s   @r9  r;   r;   #   s0       I# I I I I I IV,D D D ') 3 3S 3 3 3 3@ )+ C
 C
 C
 C
J *, a aV a a a aF 35 V Vf V V V Vp .0 l lDL l l l l\      +- 
 
 
 
 -/ P P: P P P Pd +- 0 0g 0 0 0 0d =? 
 
 
 
 
 
: BD (? (?S (? (? (? (?TC C C C C CJP P P"k kt kV kv k k k kZ: :4 : :6 : : : :
r rD r& rF r r r rh8s 8s 8 8 8 8 6:" dG dG7 dG dG dG dG dGL ?C2 HH HHG HHRY HH HH HH HHT :>b ( (w (W ( ( ( (  68 h= h= h=F h= h= h= h=T :< ? ?S ? ? ? ? ?4     4        D ?CQUdhqs X X X X3 X^a Xx|  ~B  yC X X X X8 BFTXgktv >J >J3 >J3 >Jc >Jad >J{  AE  |F >J >J >J >J@ DHVZimvx 3H 3HS 3HS 3HPS 3Hcf 3H  ~B  CG  ~H 3H 3H 3H 3Hj HLZ^mqz| 8H 8H 8H 8HTW 8Hgj 8H  BF  GK  BL 8H 8H 8H 8Ht >@ %: %: %:N %: %: %: %:N =? ': ': ':> ': ': ': ':R FH %
 %
 %
N %
 %
 %
 %
N
 
h 
R` 
 
 
 
& JL &0 &0S &0PTUcPd &0 &0 &0 &0P @DB C CS C CS\ C C C CJ> > > mqy{ e e eI eY eX] efi e e e eB rv  A a. a.c a. a.) a.]b a.kn a. a. a. a.F tx  AC 7, 7, 7,9 7,I 7,_d 7,mp 7, 7, 7, 7,rs     vz  CE =. =.# =.Y =.i =.af =.or =. =. =. =.~ x|  EG b, b,C b,y b,PY b,ch b,qt b, b, b, b,H eg e e# eY eV[ e e e e& XZ U Uc U U U U U Y[ V Vs V% V V V V FH p p$|*< p p p p@ KM R' R'tL/A R' R' R' R'h OQ .' .'43E .' .' .' .'` fjx|  FH (. (.3 (. (.9 (.I (._b (.ru (. (. (. (.T 9=R "H "HS "H# "H "H "H "HH >B" K K# Ks K K K KZ BFb &3 &3c &33 &3 &3 &3 &3P 59 I Ic I I I I: :>b 15 153 15 15 15 15f >B" "1 "1s "1 "1 "1 "1H BFTXgktv %d %d3 %dc %dad %d %d %d %dN GKY]lpy{ {? {? {?SV {?fi {? {? {? {?z KO]apt} f? f?C f?WZ f?jm f? f? f? f?P 7;\`ik W W W3 WVY Wptuzp{ W W W W> 59tZ^gi  Y  Yc  Y  YTW  Ynrsxny  Y  Y  Y  YD 8<B  G  GC  G  G  G  G  GD =A M6 M6 M6c M6 M6 M6 M6^ AER F6 F6S F6# F6 F6 F6 F6P8 8 8v 8 8 8 8 8 $  %    Bk kd kF ke k k k kZ ?CQUdhqs ^ ^3 ^ ^3 ^^a ^ ^ ^ ^* 37TX\eg U UC Us URU U U U U6 8<$]ajl p? p? p?C p?WZ p? p? p? p?d <@daenp H? H?S H? H?[^ H? H? H? H?T <@d[] `? `? `?S `? `?bfglbm `? `? `? `?D< < <v < < < < <F FT F6 FU F F F FP~ ~$ ~ ~% ~ ~ ~ ~@ ;= 8
 8
c 8
AT 8
 8
 8
 8
t QU]_ 16 163 16 16 16# 16do 16 16 16 16f:s : : : :f
 f
T f
X f
Q\ f
 f
 f
 f
P 04$UYbd U[ U[ U[C U[s U[imnyiz U[ U[ U[ U[n 9=4^bkm 0b 0b# 0bS 0bX[ 0brv  xC  sD 0b 0b 0b 0bd 37TX\eg V^ V^C V^s V^RU V^lpq|l} V^ V^ V^ V^p <@daenp 0e 0eS 0e 0e[^ 0euy  {F  vG 0e 0e 0e 0ed   *, i i i i i iV 35 0) 0) 0) 0) 0) 0)d ac I I3 I IC ITW Igt I I I IVac a a a a a a^
 ^
t ^
x ^
= ^
 ^
 ^
 ^
@:C :C : : : :*3 *3 *3XB B B: : :_ _t _x _; _ _ _ _B .2SW`b y@ y@s y@# y@S y@gklwgx y@ y@ y@ y@v MO 2 2 2 2
 
 
 
 
 
< 7;$]apt} f[ f[ f[C f[WZ f[jm f[  EI  JX  EY f[ f[ f[ f[PH
 H
$ H
 H
. H
 H
 H
 H
T 7;\`ik 1K 1K3 1KVY 1K 1K 1K 1Kf GKY]fh 3H 3HC 3H 3HSV 3H 3H 3H 3Hj# # #6 JL !6 !6c !65 !6 !6 !6 !6F Z\ %6 %63 %6c %65 %6 %6 %6 %6N BD 6 6S 6 6 6 6B RT #6 #6# #6S #6 #6 #6 #6J
 
 
 
 
 
& BFb I Iw I I I IB 8: # #3 #h # # # #J ?C2 ^ ^3 ^ ^ ^ ^ ^B HLTV #
 #
C #
 #
 #
 #
 #
J @B 
Z 
Z3 
Zk 
Z 
Z 
Z 
Z <> 55 55s 55+ 55 55 55 55n-
 -
v -
 -
 -
 -
 -
^? ? ? >BPTcgpr GO GOs GO# GO]` GO GO GO GOR
 
v 
 
 
 
2 9=4^bkm B B# BS BX[ B B B BH 8: =1 =13 =1 =1 =1 =1~ 8<B ;3 ;3W ;34PX> ;3 ;3 ;3 ;3z @DRVeirt C4 C4W C4C C4_b C4 C4 C4 C4J| |t |V | | | || AER 81 81tCy 81# 81 81 81 81t CE J Js JE JI[ J J J JX@
 @
f @
HZ @
 @
 @
 @
D ;= 4 4c 4 4 4 4 48
 
D 
* 
 
 
 
 DHPR !4 !4 !4S !4 !4 !4 !4F CGr  d C    6 7;2 
 
 
 
 
 
$ CGr 2 23 2i 2V[ 2 2 2 2B EG *> *> *>4P\K] *> *> *> *>X, , ,$|J\ , , , ,\ =A ? ?' ?P] ? ? ? ?B &eBSW EP EP EP EPN# s  c TX `c    ( 154VZce AC AC# ACS ACPS ACjno|j} AC AC AC ACF AER <3 <3g <3TXY\T] <3 <3 <3 <3|7
 7
4 7
 7
3 7
 7
 7
 7
 7
 7
 7
 7
r:  r;   )C ccxt.async_support.base.exchanger   ccxt.abstract.kucoinr   r  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   r   r   r    r!   r"   r#   r$   r%   typingr&   ccxt.base.errorsr'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   ccxt.base.decimal_to_precisionr7   r8   ccxt.base.preciser9   r;   r  r:  r9  <module>r	     s   6 5 5 5 5 5 , , , , , ,     ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~       * * * * * * 0 0 0 0 0 0 - - - - - - - - - - - - . . . . . . ' ' ' ' ' ' & & & & & & / / / / / / . . . . . . + + + + + + ) ) ) ) ) ) * * * * * * ) ) ) ) ) ) . . . . . . 1 1 1 1 1 1 ) ) ) ) ) ) 3 3 3 3 3 3 4 4 4 4 4 4 % % % % % %gO
 gO
 gO
 gO
 gO
X{ gO
 gO
 gO
 gO
 gO
r:  