
    E#iS                       S SK Jr  S SKJr  S SKrS SKrS SKrS SKJrJ	r	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!  S SK"J#r#  S SK$J%r%  S SK$J&r&  S SK$J'r'  S S	K$J(r(  S S
K$J)r)  S SK$J*r*  S SK$J+r+  S SK$J,r,  S SK$J-r-  S SK$J.r.  S SK$J/r/  S SK$J0r0  S SK$J1r1  S SK$J2r2  S SK$J3r3  S SK4J5r5  S SK4J6r6  S SK7J8r8   " S S\\5      r9g)    )Exchange)ImplicitAPIN)AccountAnyBalancesBorrowInterestBool
CurrenciesCurrencyDepositAddressIntLedgerEntryMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypeStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTransactionTransferEntry)List)ExchangeError)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)	BadSymbol)InsufficientFunds)InvalidAddress)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)InvalidNonce)TRUNCATE)	TICK_SIZE)Precisec                     ^  \ rS rSrS\4U 4S jjrS r0 4S\4S jjr0 4S jr	0 4S\
\   4S jjr0 4S\
\   4S jjrS{S	\4S
 jjr0 4S jr0 4S\4S jjr0 4S\
\   4S jjr0 4S\4S jjr0 4S\4S jjrS|S\4S jjrS rS|S\S\S\4S jjrS0 4S\S\4S jjr S0 4S\S\4S jjr!0 4S\S\4S jjr"0 4S\S\4S jjr#S|S\S\$4S jjr%SSS0 4S\S \S!\S"\S\
\$   4
S# jjr&0 4S\S\'4S$ jjr(0 4S\S\'4S% jjr)S|S\S\'4S& jjr*0 4S\S\
\'   4S' jjr+S0 4S\S"\S\,4S( jjr-S) r.S0 4S\S*\/S+\0S,\1S-\24
S. jjr30 4S\S+\0S/\14S0 jjr40 4S\S/\14S1 jjr50 4S\S/\14S2 jjr60 4S3\
\7   4S4 jjr8S\4S5 jr9S0 4S\S*\/S+\0S,\1S-\24
S6 jjr:SS0 4S7\S\S*\/S+\0S,\2S-\24S8 jjr;S0 4S7\S\<4S9 jjr=S0 4S\<4S: jjr>SSS0 4S\<S!\S"\4S; jjr?SSS0 4S\<S!\S"\S\
\@   4S< jjrASSS0 4S\<S!\S"\S\
\@   4S= jjrBS0 4S7\S\<4S> jjrCS|S?\S\S\@4S@ jjrDSSS0 4S7\S\<S!\S"\4SA jjrESSS0 4S\<S!\S"\4SB jjrFSS0 4S\S!\S"\S\
\G   4SC jjrHS|SD\S\S\G4SE jjrI0 4S\S\J4SF jjrKS0 4S\S,\1SG\SH\<S\L4
SI jjrMSJ\<4SK jrNS|SL\S\S\L4SM jjrOSSS0 4S\<S!\S"\S\
\L   4SN jjrPSSS0 4S\<S!\S"\S\
\L   4SO jjrQSP rR0 4S\S4SQ jjrT0 4S\S,\1SR\SS\S\U4
ST jjrVS|SU\S\S\U4SV jjrWSJ\<S\<4SW jrXSX rYS|SY\S\S\Z4SZ jjr[SSS0 4S\<S!\S"\S\
\Z   4S[ jjr\0 4S\ jr]S|S\4S] jjr^SSSS0 4S\<S\<S!\S"\S\
\_   4
S^ jjr`S|S_\S\S\_4S` jjraSSS0 4S!\S"\4Sa jjrbSS0 4S\S!\S"\4Sb jjrcSc rd0 4S\S,\14Sd jjre0 4S\S\S,\14Se jjrf0 4S\4Sf jjrg0 4S\S\4Sg jjrhS|S\4Sh jjriS0 4Si\4Sj jjrjS0 4Sk\kS\<4Sl jjrl0 4S\S\m4Sm jjrnS|S\S\m4Sn jjroSSS0 4S\<S!\S"\4So jjrpS|S\4Sp jjrqSqSr0 SS4Ss jrrS\kSt\Su\Sv\Sw\Sx\4Sy jrsSzrtU =ru$ )}kucoin!   returnc                 8!  > U R                  [        [        U ]  5       0 SS_SS_SS/_SS_S	S
_SS_SS_SS_SS_S0 SS _SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S_S!S_S"S_S#S_0 S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S_S,S_S-S_S.S_S/S_S0S_S1S_S2S_S3S_S4S_E0 S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S_S=S_S>S_S?S_S@S_SAS_SBS_SCS_SDS_SES_E0 SFS_SGS_SHS_SIS_SJS_SKS_SLS_SMS_SNS_SOS_SPS_SQS_SRS_SSS_STS_SUS_SVS_E0 SWS_SXS_SYS_SZS_S[S_S\S_S]S_S^S_S_S_S`S_SaS_SbS_ScS_SdS_SeS_SfS_SgS_ESSSSh.E_SiSjSkSlSlSmSmSnSoSlSlSp.SqSr/Ss._StSSSSu._Sv0 SwSx_SySx_SzS{_S|S}_S~S_SS_SSx_SS{_SS}_SS{_SSx_SSx_SSx_SSx_SSx_SS}_SS}_SSSS.ESS0S.0 SS_SS_SS_SS}_SS_SS_SS}_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS}_SS}_SS}_SS}_SS}_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS}_SS_SS}_SS_SS_SS_SS}_SS}_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS}_ES}S}S}S}SS.E0 SS_SS_SS_SS_SS_SS{_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS}_SS_0 SS_SS_SS}_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_E0 SS_SS_SS_SS_SS_SS_SS_SS_GS S_SS}_SS_SS_SS}_GSS_GSS}_SS}_SS}_S}SSSGS.EGS.0 GSSx_GSSx_GSS}_GSSx_GS	S_GS
S_GSS_GSSx_GSS_GSS}_SSx_GSSx_GSSx_GSS}_GSS_SS}_SS{_GSGS0ESS0S.0 SS}_GSS_GSGS_SS_SS}_GSGS_GSS_SS_GSS_SS_GSSx_GSS_GSS}_GSS}_GSS_GS S_GS!S_S{SGS".E0 SS_SS_SS}_SS}_SSx_GS#S{_GS$S_GS%S{_GS&S{_GS'S}_GS(S}_GS)S}_GS*S{_GS+S_GS,S}_GS-S{_GS.S}_S}SxS}SGS/.EGS0GS0SSGS0GS0GS1.GS.GS2GS3S00SSSS}SSSSGS4.SS}S}S}GS5.GS6S}0GS.SSSSSSSSSGS7.	GS8S0GS8S0GS.GS2SS}SSS}S}S}SSSS}GS9.0GS:._GS;GS<GS=GS>GS?GS@GSAGSBGSCGSDGSEGSFGSGGSHGSIGSJ._GSK[        _GSL0 GSM[
        _GSN[
        _GSO[
        _GSP[
        _GSQ[
        _GSR[        _GSS[        _GST[        _GSU[        _GSV[        _GSW[        _GSX[        _GSY[        _GSZ[        _GS[[        _GS\[        _GS][        _0 GS^[        _GS_[        _GS`[        _GSa[        _GSb[        _GSc[        _GSd[        _GSe[        _GSf[
        _GSg[        _GSh[        _GSi[        _GSj[        _GSk[
        _GSl[        _GSm[        _GSn[        _E0 GSo[        _GSp[        _GSq[        _GSr[        _GSs[        _GSt[        _GSu[        _GSv[        _GSw[        _GSx[        _GSy[        _GSz[        _GS{[        _GS|[        _GS}[        _GS~[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[
        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[         _GS[        _GS["        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _E0 GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[        _GS[         _GS[        _GS[        _GS[        _GS[$        _GS[        _GS[        _GS[        _GS[        _GS[        _E[        [        GS.E[        [        GS.GS._GSSSU R'                  GS5      U R'                  GS5      U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS`5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      //U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS`5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      /U R'                  GS5      U R'                  GS5      //GS.GS.SS0 0 GS.GS._GSGSGSGSGSGSGS.S GSGSGSGSSSSSGS.GSS0GSS0GSGSGSS
GSGSGS.00 SS
_SGS_SS
_SS
_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_0 SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_GSGS_SGS_GSS
_GSGS_E0 SS
_SGS_SS
_SS
_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_SGS_GSGSGSGSGSGSGS.GS.GSSGS00GS.GSGSGS.GSGS GS.GS.GSSSGSGSGSGSGSGSGSGS.
0 GS	GS
_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS _GS!GS"_GS#GS$_GS%GS&_GS'GS(_GS)GS*_0 GS+GS,_GS-GS._GS/GS0_GS1GS2_GS3GS4_GS5GS6_GS7GS8_GS9GS:_GS;GS<_GS=GS>_GS?GS@_GSAGSB_GSCGSD_GSEGSF_GSGGSH_GSIGSJ_GSKGSL_E0 GSMGSN_GSOGSP_GSQGSR_GSSGST_GSUGSV_GSWGSX_GSYGSZ_GS[GS\_GS]GS^_GS_GS`_GSaGSb_GScGSd_GSeGSf_GSgGSh_GSiGSj_GSkGSl_GSmGSn_E0 GSoGSp_GSqGSr_GSsGSt_GSuGSv_GSwGSx_GSyGSz_GS{GS|_GS}GS~_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_E0 GSGS_GSGS_GSGS_GSGS_GSGS_GSGS _GSGS_GSGS_GSGS_GSGS_GS	GS
_GSGS_GSGS_GSGS_GSGS_GSGS_GSGS_EGSGSGSGS.GS.SSSS SSSS SSSSGS.SSSSSSSGS.GSS0SS S GSSGS .SSSSGS!.SGS"SSSGS#.S SGS"S S GSSSSGS$.GS%GS&0GS'.	S S GS(.S S GS(.GS).GS*.E5      $ (+  Nidr3   nameKuCoin	countriesSC	rateLimit
   versionv2	certifiedTprocommentzPlatform 2.0quoteJsonNumbersFhasCORSspotmarginswapfutureoptionborrowCrossMarginborrowIsolatedMargincancelAllOrderscancelOrdercloseAllPositionsclosePositioncreateDepositAddresscreateMarketBuyOrderWithCostcreateMarketOrderWithCostcreateMarketSellOrderWithCostcreateOrdercreateOrderscreatePostOnlyOrdercreateStopLimitOrdercreateStopMarketOrdercreateStopOrdercreateTriggerOrder	editOrderfetchAccountsfetchBalancefetchBorrowInterestfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingRatefetchFundingRateHistoryfetchFundingRatesfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMarkPricesfetchMyTrades
fetchOHLCVfetchOpenInterestfetchOpenInterestHistoryfetchOpenOrders
fetchOrderfetchOrderBookfetchOrderBooksfetchOrdersByStatusfetchOrderTradesfetchPositionHistoryfetchPositionModefetchPositionsHistoryfetchPremiumIndexOHLCVfetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTradingFeesfetchTransactionFeefetchTransfersfetchWithdrawalsrepayCrossMarginrepayIsolatedMarginsetLeveragesetMarginModesetPositionMode)signIntransferwithdrawurlszdhttps://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpgz2https://www.kucoin.com/ucenter/signup?rcode=E5wkqezhttps://api.kucoin.comzhttps://api-futures.kucoin.comzhttps://kucoin.com/_apizhttps://api-broker.kucoin.com)publicprivatefuturesPrivatefuturesPublicwebExchangebrokerearnutazhttps://www.kucoin.comzhttps://docs.kucoin.com)logoreferralapiwwwdocrequiredCredentials)apiKeysecretpasswordr   
currenciesg      @currencies/{currency}symbols   zmarket/orderbook/level1   zmarket/allTickersg     6@zmarket/statsmarketsz%market/orderbook/level{level}_{limit}zmarket/orderbook/level2_20zmarket/orderbook/level2_100zmarket/historieszmarket/candlesprices	timestampstatuszmark-price/{symbol}/currentmark-price/all-symbols      )zmargin/configannouncementszmargin/collateralRatiozbullet-public   )getpostz	user-info   accountsg      @zaccounts/{accountId}zaccounts/ledgerszhf/accounts/ledgers   zhf/margin/account/ledgersztransaction-historyzsub/userzsub-accounts/{subUserId}zsub-accountszsub/api-keyzmargin/account(   zmargin/accountszisolated/accountsdeposit-addressesdepositszhist-depositswithdrawalszhist-withdrawalszwithdrawals/quotaszaccounts/transferableztransfer-listzbase-feez
trade-feeszmarket/orderbook/level{level}zmarket/orderbook/level2zmarket/orderbook/level3zhf/accounts/openedzhf/orders/activezhf/orders/active/symbolszhf/margin/order/active/symbolszhf/orders/donezhf/orders/{orderId}z"hf/orders/client-order/{clientOid}zhf/orders/dead-cancel-all/queryzhf/fillsorderszlimit/ordersorders/{orderId}zorder/client-order/{clientOid}fillszlimit/fillsz
stop-order   zstop-order/{orderId}z stop-order/queryOrderByClientOidoco/order/{orderId}zoco/order/details/{orderId}oco/client-order/{clientOid}
oco/orderszhf/margin/orders/active   zhf/margin/orders/donehf/margin/orders/{orderId})hf/margin/orders/client-order/{clientOid}   zhf/margin/fillszetf/infozmargin/currencieszrisk/limit/strategyzisolated/symbolszmargin/symbolszisolated/account/{symbol}2   zmargin/borrowzmargin/repayzmargin/interestzproject/listzproject/marketInterestRatezredeem/orderszpurchase/orderszbroker/api/rebase/download)zbroker/queryMyCommissionzbroker/queryUserzbroker/queryDetailByUidmigrate/user/account/statusaffiliate/inviter/statisticszsub/user/createdzsub/api-key/update-   zaccounts/universal-transferzaccounts/sub-transferzaccounts/inner-transferz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margin/orderzmargin/order/testpurchaseredeemzlend/purchase/updatebullet-privatezposition/update-user-leveragezdeposit-address/createzwithdrawals/{withdrawalId}zhf/orders/sync/{orderId}z'hf/orders/sync/client-order/{clientOid}zhf/orders/cancel/{orderId}zhf/orders/cancelAllz!stop-order/cancelOrderByClientOidzstop-order/cancel)r   r   r   hf/margin/orders)r   r   deletezcontracts/activezcontracts/{symbol}tickerzlevel2/snapshotzlevel2/depth20zlevel2/depth100ztrade/historyzkline/queryzinterest/queryzindex/queryzpremium/queryztrade-statisticszfunding-rate/{symbol}/currentzcontract/funding-rateszlevel2/message/queryg&S?zaccount-overviewzaccount-overview-all	   
stopOrdersrecentDoneOrderszorders/byClientOidrecentFillsopenOrderStatisticsposition	positionszmargin/maxWithdrawMarginzcontracts/risk-limit/{symbol}zfunding-history)z$copy-trade/futures/get-max-open-sizez6copy-trade/futures/position/margin/max-withdraw-marginz#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-statusz,copy-trade/futures/position/changeMarginMode)z3copy-trade/futures/position/changeCrossUserLeveragez(copy-trade/getCrossModeMarginRequirementz&copy-trade/position/switchPositionModer   g      ?)r   zorders/client-order/{clientOid}r   r   r   z&copy-trade/futures/orders/client-orderr   zcurrency/currency/chain-info)zbroker/nd/infobroker/nd/accountbroker/nd/account/apikeyzbroker/nd/rebase/downloadasset/ndbroker/deposit/listzbroker/nd/transfer/detailzbroker/nd/deposit/detailzbroker/nd/withdraw/detail)zbroker/nd/transferr   r   zbroker/nd/account/update-apikeyr   )	zotc-loan/loanzotc-loan/accountszearn/redeem-previewzearn/saving/productszearn/hold-assetszearn/promotion/productszearn/kcs-staking/productszearn/staking/productszearn/eth-staking/productszearn/orders)zmarket/announcementzmarket/currencyzmarket/instrumentzmarket/tickermarket/orderbookzmarket/tradezmarket/klinezmarket/funding-ratezmarket/funding-rate-historyzmarket/cross-configzserver/status)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.400401403404405415429500503101030103000130101130102130103130104130105130106130107130108130201130202130203130204130301130302130303130304130305130306130307130308130309130310130311130312130313130314130315126000126001126002126003126004126005126006126007126009126010126011126013126015126021126022126027126028126029126030126033126034126036126037126038126039126041126042126043126044126045126046126047126048135005135018200004210014210021230003260000260100300000400000400001400002400003400004400005400006400007400008400100400200400330400350400370400400400401400500400600400760401000408000411100415000400303500000260220600100)600101900014)zExceeded the access frequencyzrequire more permission)exactbroadfeesz0.001050200z0.0009z0.00081000z0.000720004000z0.00068000z0.000515000z0.0004525000z0.000440000z0.0003560000z0.000380000z0.00025z-0.00005)takermaker)	tierBased
percentager  r  tiers)r  r  r   deposit)tradingfundingBIFIFVAIOTWAXPAPTOSLAUNCHTOKENALTzFTX Users' Debt)BIFIVAIWAXr  KALTFUDv1-private_get_fillsr   )webApiEnablewebApiRetrieswebApiMuteFailurefetchTickersFees
includeFeeGETv3)r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r  POSTDELETEr  )r   r   r   ccxtz$9e58cc35-5b5e-4133-92ec-166e3f077cb8)r7   keyccxtfuturesz$1b327198-f30c-4f14-a0ac-918871282f15)rF   rI   tradeisolatedmaincontractpooltrade_hf)
rF   rG   crossr  r  r  rI   rH   mininghfBRC20btcBTCNATIVESEGWITbech32ERC20ethTRC20trxHRC20hecoMATICmaticKCCkccSOLsolALGOalgoEOSeosBEP20bscBEP2bnbARBONEarbitrumAVAXXavaxAVAXCavaxcTLOStlosCFXcfxACAaca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MARGIN_TRADEMARGIN_ISOLATED_TRADETRADE)r  r  rF   )r  r>   symbolSeparatorfetchMyTradesMethodtimeDifferenceadjustForTimeDifferencere   ry   r   versionspartneraccountsByTypenetworksmarginModes)IOCFOKPOGTD)
marginModetriggerPricetriggerPriceTypetriggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergmax   )r  limitdaysBack	untilDayssymbolRequired)r  triggerr  r  i  )r  r  r  r  r  )r  r  r  daysBackCanceledr  r  r  r  r    )	sandboxrU   rV   r}   r   r   fetchOrdersrb   r~   )linearinverse)rF   rH   rI   )commonCurrenciesoptionsfeatures)deep_extendsuperr3   describer0   r*   r)   r    r'   r%   r!   r+   r,   r-   r"   r(   r&   r.   r#   parse_number)self	__class__s    E/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/kucoin.pyr  kucoin.describe#   s'   fd < > {A
({A
H{A
 ${A
 	{A

 t{A
 {A
 4{A
 ~{A
 {A
  YYY $Y 	Y
 %Y %Y $TY 'Y "4Y tY $UY  Y 'Y /Y ,TY  0!Y" t#Y$ %Y& &t'Y( ')Y* (+Y, "4-Y. %d/Y0 T1Y2  3Y4 5Y6 &t7Y8 +D9Y: )$;Y< $T=Y> '?Y@ (AYB "4CYD &tEYF (GYH 1$IYJ  KYL *4MYN +DOYP &uQYR #DSYT *4UYV $UWYX "5YYZ *5[Y\ +E]Y^ #D_Y` taYb %ecYd /eYf "5gYh +EiYj kYl !%mYn !$oYp "4qYr  sYt duYv $UwYx +EyYz "4{Y| d}Y~ !$Y@ "5AYB &tCYD #DEYF 'GYH $UIYJ (KYL )%MYN tOYP tQYR SYT TUYV tWYX "4YYZ #E[Y\ &t]Y^ !%_Y` #DaYb #DcYd &teYf tgYh  iYj "5kYl    qY{A
H ~P67&F%E#<=43	 0-I{A
l " $m{A
v $c 0 "1	
 21 ,T ' "3 @ 5a 6q +C )# !# $S  !#!$ 6q%& 1!'( *,)+24-4 (3>P#RP #CP /	P
 +AP .qP 4QP .qP #BP 3DP 'P &rP )"P *2P  ,R!P" ,S#P$ #C%P& ('P( &r)P* +B+P, -b-P. 0/P0 (1P2 #A3P4 %a5P8 89P: 21;P< 21=P> -a?P@ +AAPB 3ACPD 9!EPF )!GPH .qIPJ =aKPL :1MPN #AOPP !!QPR 'SPT +AUPV 9!WPX  YPZ &r[P\ %a]P^ /_P` ;AaPb .qcPd 6qePf 7gPh %aiPl 21mPn 0oPp 5aqPr DQsPt *1uPv #BwPx ,RyPz .r{P| +B}P~ )!P@ 4RAPB (CPD 'EPF *2GPH 'IPJ 5cKPL (MPN *2OPR 5aSPT 56,-34788:_Pb(*D( &r( -b	( ,R( &s( 6q( 0( 22( '( &r( $Q( )!(  )!!(" *1#($ /%(& *1'(( 4Q)(* !!+(, &q-(. '/(0 %a1(2 $Q3(6 *17(8 /9(: ';(< ,Q=(> (?(@ 'A(B #BC(D !"E(F /G(J )"K(L 8M(N 1"O(R%r 5b	 .q 3A =a B1 5a $Q .r +A 9! !"  /!" <Q#$ ,Q%& .q'( 7)* '(67EF,.3wVp*C,c !! *3	
 )# *2 ( &s )# &q 6s ( +C 8 1#  $Q!" !!#& /'. (-"8-q +C	
 / ( !! %a +C +C -c   &s .r  #A!" $Q#$ 3B%& 8'( *3)* ABRT-0& &r
 !! &q ' >q 0 9! ;A 4Q 9! 7 LQ  Mb!" Nq#$ QRS%& G'( PQDGBC*,16 -0;>"$&*58BEg;#z 6  +,-.455678564556	 /0-.45;<	 3A#. *+-./203,/36581458
 &s &s( /1+,-.)+,-()()/078/1)*	Nw{A
T U{A
t Yu{A
v zBMz/z &}z '	z
 &}z =lz @z 4\z N}z OPaz 7
z Elz :z .z <z  <!z" <#z$ <%z& ,'z( /)z* /+z, .-z. l/z0 j1z2 m3z4 m5z6 m7z8 /9z: l;z< m=z> m?z@ .AzB mCzD /EzF jGzH /IzJ .KzL lMzN lOzP lQzR lSzT lUzV lWzX lYzZ m[z\ l]z^ l_z` lazb lczd lezf mgzh lizj mkzl lmzn mozp .qzr mszt muzv mwzx myzz m{z| /}z~ mz@ lAzB lCzD lEzF lGzH lIzJ lKzL lMzN lOzP lQzR mSzT mUzV mWzX mYzZ m[z\ m]z^ l_z` lazb lczd .ezf .gzh mizj mkzl /mzn lozp /qzr /szt nuzv /wzx lyzz i{z| 1}z~ lz@ 1AzB 1CzD 1EzF 1GzH 1IzJ lKzL /MzN lOzP lQzR lSzT lUzV jWzX 1YzZ l[z\ i]z^ l_z` jazb jczd .ezf jgzh .izj 2kzl nmzn /ozp +(szx 6G/?y@w{A
x !%"&!..w7!..w7 "..s3T5F5Fw5OP!..t4d6G6G6PQ!..u5t7H7H7RS!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..v68I8I(8ST!..v68I8I(8ST!..w79J9J99UV!..w79J9J89TU!..w79J9J99UV!..w79J9J89TU!..w79J9J99UV"  "..s3T5F5Fw5OP!..t4d6G6G6QR!..u5t7H7H7RS!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I#8NO!..v68I8I#8NO!..v68I8I#8NO!..w79J9J:9VW!..w79J9J:9VW!..w79J9J:9VW!..w79J9J:9VW!..w79J9J:9VW"!%N "'"' "!	O-y{A
V  ))! #&':"#+0$(%&)-$ '! !% *.59'+6:-1 	' ''  8'  '	' 
 +D'  .t'  0'  0'  6t'  6t'  <T'  24'   :4!' " ;D#' $ )$%' ( 6t)' * =d+' , 4T-' . 9$/' 0 H1' 2 .t3' 4 '5' 6 07' 8 ,T9' : +D;' < .t=' > +D?' @ 9$A' B ,TC' D .tE' F :4G' H -dI' J ;DK' L :4M' P!.! :4	!
 4T! 6t! +D! 5d! (! .t! 3D! ,T! +D!  '!!" %d#!$ 3D%!& <T'!( *4)!4 ;?IM0437<@*.#K Z *D!'o\@ %E
 ,E $&% *"%(&$$#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$ 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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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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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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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d , 7# w
`F  %&*(,,0,1)-+/6:#'#'"&#'	( #($)$)+/27/3#')$. q% '+!%$(%&*.& ',#'$)*.	# '+!$#'$)*.( $(&*!$$(,0%&#'$)*.	*  #u=~ ##
 ##GGg{A
 { {	    c                 B    U R                  5       U R                  S   -
  $ )Nr  )millisecondsr  )r  s    r  noncekucoin.noncea  s       "T\\2B%CCCr  c                 H    U R                  U5      nU R                  US5      $ )a  
fetches the current integer timestamp in milliseconds from the exchange server

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
data)publicGetTimestampsafe_integer)r  paramsresponses      r  
fetch_timekucoin.fetch_timed  s)     **62   622r  c                    SnU R                  USSS5      u  p!SnU(       a_  U R                  U R                  SS5      nUS:X  a  SOSnU R                  US	U5      nS	U0nU R	                  U R                  Xq5      5      nOU R                  U5      nU R                  US
0 5      nU R                  USS5      n	U	S:X  a  SOSSSSUS.$ )a  
the latest known information on the availability of the exchange API

https://docs.kucoin.com/#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 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defaultTyperF   SPOTFUTURES	tradeTyper  r   serverStatusopenokmaintenance)r   updatedetaurlinfo)	handle_option_and_paramssafe_stringr  safe_string_upperutaGetServerStatusextendpublicGetStatus	safe_dictsafe_string_2)
r  r  r   r  r  defaultTradeTyper  requestr  r   s
             r  fetch_statuskucoin.fetch_statusw  s     33FM5RWX**4<<OK*5*?vi..v{DTUIYG ..t{{7/KLH ++F3H ~~h3##D(NC%/dm
 	
r  c                    SnU R                  USSS5      u  p!SnU R                  USSS5      u  p1U(       a  U R                  U5      $ / nUR                  U R                  U5      5        U R	                  S5      nU=(       a    U R                  USS5      nU(       a@  UR                  U R                  U5      5        UR                  U R                  U5      5        U(       a   UR                  U R                  U5      5        U(       a  UR                  U R                  5       5        UnU R                  US   S	5      nU(       a  U R                  US
   S	0 5      O0 n	U R                  U	S/ 5      n
U R                  U
S5      nU(       a  US   O0 nU R                  US	/ 5      nU R                  US5      nU(       a  SOS
nU R                  X0 5      nU R                  U R                  US	0 5      S/ 5      nU R                  US5      n/ n[        S[        U5      5       GH  nUU   nU R                  US5      nUR!                  S5      u  nnU R#                  U5      nU R#                  U5      nU R                  UU0 5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nUU;   n UU;   n!U R                  USS5      =(       d    U =(       d    U!n"UR                  0 SU_SUS-   U-   _SU_SU_SS_SU_SU_SS_SS_SS_S U"_S!U U!S"._S#S_S$S_S%S_S&U R                  US'5      _S(S_SSU R%                  [&        R(                  " UU5      5      U R%                  [&        R(                  " UU5      5      SSSSSU R+                  US)5      U R+                  US*5      S+.SSS,.U R+                  US-5      U R+                  US.5      S,.SSS,.U R+                  US/5      U R+                  US05      S,.S1.SUS2.E5        GM     U R,                  S3   (       a  U R/                  5         U$ )4av  
retrieves data on all markets for kucoin

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

:param dict [params]: extra parameters specific to the exchange API endpoint
: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
Nry   r  Tr   Fmarginablesr   r  r   itemssymbolr   r   r   r  makerFeeRatetakerFeeRatemakerCoefficienttakerCoefficientisMarginEnabledr7   /r  quotesettlebaseIdquoteIdsettleIdtyperF   rG   r  )r  r  rH   rI   rJ   activeenableTradingr  baseIncrementpriceIncrementamountpriceminr  baseMinSizebaseMaxSizequoteMinSizequoteMaxSizer  r.  r/  cost)r  r  r  r  contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr  r  )r  fetch_uta_marketsappendpublicGetSymbolscheck_required_credentials	safe_boolprivateGetMarginSymbolsprivateGetIsolatedSymbolspublicGetMarketAllTickersload_migration_status	safe_listr  index_byrangelenr  splitsafe_currency_coder  r1   
string_mulsafe_numberr  load_time_difference)#r  r  r  r   promisescredentialsSetrequestMarginables	responsessymbolsData	crossData
crossItems	crossByIdisolatedDataisolatedItemsisolatedById
tickersIdxtickersResponsetickerItemstickersByIdresultimarketr7   r%  r&  r  r#  r   r  r  r  r   hasCrossMarginhasIsolatedMarginisMarginables#                                      r  fetch_marketskucoin.fetch_markets  s     #'#@#@Ykmq#r 33FNESXY))&11--f560 88?+[v}VZ0[OOD88@A OOD::6BC, OOD::6BC4 OOD6689	nnYq\6:@RDNN9Q<<XZ	^^Iw;
MM*h7	'9y|r|VR@}}]H=,Q!
..CnnT^^OVR%PRZ\^_mmK:q#k*+A ^F!!&(3B hhsmOFG**62D++G4E^^KR8F++FNCL++FNCL#//8JK#//8JK IoN!#|!3>>&2CUKr~rarLMM 6b6$*u,6 6 	6
 $6 &6 76 D6 6 6 ,6 + 1 6  !6" %#6$ %%6& $..A'6( E)6* **7+=+=lL\+]^**7+=+=lL\+]^ $"&""..vG!--f6FG  $#!
  $//F#//F
  $#
  $//G#//G$  k6 6 ,L <<12%%'r  c                    / nUR                  U R                  U R                  USS05      5      5        UR                  U R                  U R                  USS05      5      5        UnU R                  US   S0 5      nU R                  US   S0 5      nU R	                  US/ 5      nU R	                  US/ 5      nU R                  Xg5      n/ n	[        S[        U5      5       GHS  n
X   nU R                  US5      nU R                  US	5      nU R                  US
5      nU R                  US5      nU R                  U5      nU R                  U5      nU R                  U5      nU R                  US5      nUS:X  a  SOSnUS-   U-   nUb  USU-   -  nU R                  US5      nU R                  US5      nU R                  US5      nS nSnSnSnSnSnSnUb  SnUU:X  a  SnOSnUS:X  a  SnSnO	SnSnOSnSnU	R                  0 SU_SU_SU_SU_SU_SU_SU_SU_S U_SU_S!U_SU_SU_S"S_S#US:H  _S$U_S%U_UU R                  US&5      U R                  US'5      U R                  US(5      UU R                  U5      S S U R                  US)5      U R                  US*5      S+.S U R                  US,5      S-.U R                  US.5      U R                  US/5      S-.S U R                  US05      S-.U R                  US15      U R                  US25      S-.S3.U R                  US45      US5.E5        GMV     U R                  S6   (       a  U R                  5         U	$ )7Nr  r  r  r   r  r   listr  baseCurrencyquoteCurrencysettlementCurrencyr  1TFr"  :contractType
expiryTimetradingStatusry  rH   rI   rF   r7   r  r#  r$  r%  r&  r'  r(  rG   rJ   r)  r  r  r  r  unitSizelotSizetickSizer-  maxLeverager0  minBaseOrderSizemaxBaseOrderSizemaxPriceminQuoteOrderSizemaxQuoteOrderSizer6  
launchTime)r  r  r  r8  r9  r:  r;  r<  r=  r>  r?  r  r  )rA  utaGetMarketInstrumentr  r  rI  array_concatrK  rL  r  rN  r  rP  iso8601r  rQ  ) r  r  rR  rU  r  contractDataspotDatacontractSymbolsDatarV  ra  rb  rc  r7   r%  r&  r'  r  r#  r$  	hasMarginrf  r  rp  r9  r)  r(  rF   rH   rI   r  r  r  s                                    r  r@  kucoin.fetch_uta_marketsq  sO   33DKKV\H]4^_`B 	33DKKV_H`4abcL 	~~ilFB7~~ilFB?>>$3"nn\62F''Fq#k*+A ^F!!&(3B%%fn=F&&v?G''0DEH**62D++G4E,,X6F((>I$-$445LCZ%'F!#,&++FNCL&&v|<F%%fo>FDDDFHFG'F?!F"G3&!DD#D!F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 $ 0 0 D "&,,v"6""..vyA!--fjA  $#00G!
  $//8JK#//8JK
  $#//
C
  $//8KL#//8KL$  ,,V\Bc2 2O ,t <<12%%'r  forcec                     SU R                   ;  d  U R                   S   b  U(       a/  U R                  5       nU R                  US5      U R                   S'   g)z
:param boolean force: load account state for non hf
loads the migration status for the account(hf or not)

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

:returns any: ignore
r  r  T)r  privateGetHfAccountsOpenedrD  )r  r  ra  s      r  rH  kucoin.load_migration_status  sJ     $$,,t*<*D::<F!%!?DLLr  c                     U R                  U R                  SS5      nS nUb  U(       a  SnOSnU R                  USU5      nU R                  US5      nXA/$ )Nr  FT)rD  r  omit)r  r  migratedloadedHfr  s        r  handle_hf_and_paramskucoin.handle_hf_and_params-  sZ    dEB >>&$964(|r  c                 l   U R                  U5      nU R                  US/ 5      nU R                  U R                  S/ SQ5      n0 n[        S[	        U5      5       GH  nX6   nU R                  US5      nU R                  X5      (       a  M2  U R                  U5      n	0 n
U R                  US/ 5      n[	        U5      n[        SU5       H  nX   nU R                  US5      nU R                  X5      nUUU R                  US5      US	U R                  US
5      U R                  US5      U R                  US5      U R                  U R                  U R                  US5      5      5      U R                  US5      U R                  US5      S.U R                  US5      U R                  US5      S.S.S.
U
U'   M     U R                  US5      nU R                  U R                  U5      5      nUS:H  nU R                  UU R                  US5      U	U(       a  SOSUUU
S	S	S	S	S	S.5      XY'   GM     U$ )z
fetches all available currencies on an exchange

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

:param dict params: extra parameters specific to the exchange API endpoint
:returns dict: an associative dictionary of currencies
r  brokenCurrencies)00
OPEN_ERRORHUFBDTr   currencychainschainId	chainNameNwithdrawalMinFeeisDepositEnabledisWithdrawEnabledwithdrawPrecisionwithdrawalMinSizemaxWithdrawr0  depositMinSize
maxDepositr   r  )
r  r7   r8   coder)  feer  r   r=  r>  r=  fullNamefiatcrypto)r7   r8   r  r(  r=  r  r  r  r   r)  r  r>  )publicGetCurrenciesrI  r  rK  rL  r  in_arrayrN  network_id_to_coderP  rD  r  parse_precisionsafe_currency_structure)r  r  r  currenciesDatar  ra  rb  entryr7   r  r  r  chainsLengthjchainr  networkCoderawPrecisionr=  isFiats                       r  fetch_currencieskucoin.fetch_currencies9  sU    ++F3L &"=>>$,,8JLnoq#n-.A"%E!!%4B}}R22**2.DH^^E8R8Fv;L1l+	**5)<"55gD!! ,,UK@'"++E3EF#~~e5GH $u6I J!%!2!243G3GHXHXY^`sHt3u!v $(#3#3E;N#O#'#3#3E=#I%
 $(#3#3E;K#L#'#3#3E<#H$	)%	 ,4  ++E;?L))$*>*>|*LMI!Q&F77((
;"(h&$ 9 FLM /h r  c           	      N   U R                  U5      nU R                  US/ 5      n/ n[        S[        U5      5       He  nX5   nU R	                  US5      nU R	                  US5      nU R                  U5      n	U R	                  US5      n
UR                  UU
U	U	US.5        Mg     U$ )a(  
fetch all the accounts associated with a profile

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `account structures <https://docs.ccxt.com/#/?id=account-structure>` indexed by the account type
r  r   r7   r  r(  )r7   r(  r  r  r  )privateGetAccountsrI  rK  rL  r  rN  rA  )r  r  r  r  ra  rb  account	accountId
currencyIdr  r(  s              r  fetch_accountskucoin.fetch_accounts  s     **620 ~~h3q#d)$AgG(($7I))':>J**:6D##GV4DMM   % r  r  c                 d   U R                  5         U R                  U5      nSUS   0nSnU R                  U5      u  pRUb"  U R                  U5      R	                  5       US'   U R                  U R                  XB5      5      nU R                  US0 5      n0 nU R                  US5      X'   UU0 S.$ )a)  
*DEPRECATED* please use fetchDepositWithdrawFee instead

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

:param str code: unified currency code
:param dict params: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
r  r7   Nr  r  withdrawMinFee)r  r   r  )	load_marketsr  handle_network_code_and_paramsnetwork_code_to_idlowerprivateGetWithdrawalsQuotasr  r  rP  )	r  r  r  r  r  r  r  r  withdrawFeess	            r  fetch_transaction_feekucoin.fetch_transaction_fee  s     	==&
 "AA&I"#66{CIIKGG33DKK4PQ~~h3!--d4DE$
 	
r  c                 L   U R                  5         U R                  U5      nSUS   0nSnU R                  U5      u  pRUb"  U R                  U5      R	                  5       US'   U R                  U R                  XB5      5      nU R                  US5      nU R                  Xs5      $ )a  
fetch the fee for deposits and withdrawals

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

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: The chain of currency. This only apply for multi-chain currency, and there is no need for single chain currency; you can query the chain through the response of the GET /api/v2/currencies/{currency} interface
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
r  r7   Nr  r  )	r  r  r  r  r  r  r  r  parse_deposit_withdraw_feer  r  r  r  r  r  r  r  s           r  fetch_deposit_withdraw_fee!kucoin.fetch_deposit_withdraw_fee  s     	==&
 "AA&I"#66{CIIKGG33DKK4PQ& ~~h/..t>>r  Nr  c                    SU;   a  US SS.S S S.0 S.nU R                  US/ 5      n[        S[        U5      5       H[  nXE   nU R                  U R	                  US5      U R	                  US5      5      nU R                  USS	5      SS.S S S.S
.US   U'   M]     U$ U R                  US	5      nUUSS.S S S.0 S.n	U R	                  US5      n
U R                  XR	                  US5      5      nUS S S.S
.U	S   U'   U	$ )Nr  F)r  r  )r  r   r  r  r   r  r  r  r  r  r  r  )rI  rK  rL  r  r  safe_number_2rP  )r  r  r  	resultNewr  rb  r  networkCodeNewminWithdrawFeera  	networkIdr  s               r  r  !kucoin.parse_deposit_withdraw_fee  sm     s? "'
  "& I ^^C26F1c&k*	!%!8!89I9I%QZ9[]a]m]mnvx~]  "A  $11%9KM]^&+!
  $&* 	9	*%n5 + ))#/?@%#
 " 
 $$S'2	--i9I9I(TZ9[\&"+
z;' r  c                    U R                  U R                  USS5      nU R                  USU5      nU R                  U R                  S5      nU R                  XT5      nUcC  [	        UR                  5       5      n[        U R                  S-   SR                  U5      -   5      eU R                  US5      nUS:H  =(       d    US:H  =(       d    US	:H  $ )
Nr  r  r(  r  z' isFuturesMethod() type must be one of z, r  rI   futures)
r  r  r  r  rj  keysr    r7   joinr  )r  
methodNamer  r  requestedTyper  r(  r  s           r  is_futures_methodkucoin.is_futures_method_  s     ((z=RYZ((E6FG><++-.D*S SVZV_V_`dVe eff66*z!Otx'7OTY=NOr  r   rc  c           	      l   U R                  US5      nUb  [        R                  " US5      nU R                  U/ SQ5      nU R                  USU5      nU R                  US5      nU R	                  XRS5      nUS   nU R                  USS5      nU R                  US	S
5      nU R                  U/ SQ5      n	U R                  0 SU_SU	_SU R                  U	5      _SU R                  US5      _SU R                  US5      _SU R                  U/ SQ5      _SU R                  US5      _SU R                  U/ SQ5      _SU R                  US5      _SS _SU R                  US5      _SU_SU_SS _SU R                  US5      _SU_S U R                  US!5      _UUU R                  US"5      US#.EU5      $ )$N
changeRate100)lastlastTradedPrice	lastPricer/  r  r  vol
baseVolumevolValuequoteVolume)timedatetime	timePointr   r  highlowbid)buybestBidbestBidPrice	bidVolumebestBidSizeask)sellbestAskbestAskPrice	askVolumebestAskSizevwapr  closer  previousClosechangechangePricer  averageaveragePricevalue)r  r  	markPricer  )	r  r1   rO  safe_string_nsafe_marketr  safe_integer_nsafe_tickerr  )
r  r   rc  r  r  marketIdr  r  r  r   s
             r  parse_tickerkucoin.parse_tickerp  sD   T %%fl;
! ++J>J!!&*RS6##FH5!!(C8!''|D
((]K''0QR	 !
f!
!
 Y/!
 D$$VV4	!

 4##FE2!
 4%%f.PQ!
 ))&-@!
 4%%f.QR!
 ))&-@!
 D!
 D$$VV4!
 T!
 D!
 T!
 d&&v}=!
  *!!
" t''?#!
$ %&))&':+!
, - 	r  r   c                 P   U R                  5         0 nU R                  U5      nSnU R                  USSS5      u  pBSnU(       a  UbK  U R                  US5      nU R	                  U5      nSnU R                  SXr5      u  pUS:X  a  SUS'   OIS	US'   OCU R                  US5      n	U	c  [        U R                  S
-   5      eXS'   U R                  US5      nU R                  U R                  X25      5      nOU R                  U5      nU R                  US0 5      n
U R                  U
SS/ 5      nU R                  U
SS5      n0 n[!        S[#        U5      5       H8  nXU   S'   U R%                  X   5      nU R                  US5      nUc  M4  XU'   M:     U R'                  USU5      $ )a  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://docs.kucoin.com/#get-all-tickers
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.tradeType]: *uta only* set to SPOT or FUTURES
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   r   Fr   rF   r  r  r  zN fetchTickers() requires a tradeType parameter for uta, either SPOT or FUTURESr  r   rj  r  tsr  )r  market_symbolsr  r  rc  handle_market_type_and_paramsr  r$   r7   r  utaGetMarketTickerr  rG  r  safe_list_2safe_integer_2rK  rL  r  filter_by_array_tickers)r  r   r  r  r   r  r  rc  r(  r  r  tickersr  ra  rb  r   s                   r  fetch_tickerskucoin.fetch_tickers  s    	%%g.33FNESXY"))'15V,#AA.RXa6>+1GK(+4GK( 226;G	$+DGG  7G  -G  H  H'0$6;7..t{{7/KLH8 55f=H: ~~h3""462>""46q#g,'A!%AJv&&wz2F%%fh7F!!'v ( ++FHgFFr  c                     U R                  5         U R                  U5      nU R                  U5      nU R                  US/ 5      nU R	                  U5      $ )a  
fetches the mark price for multiple markets

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

:param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
r  )r  r  publicGetMarkPriceAllSymbolsrI  parse_tickers)r  r   r  r  r  s        r  fetch_mark_priceskucoin.fetch_mark_pricesE  sS     	%%g.44V<~~h3!!$''r  r  c                 "   U R                  5         U R                  U5      nSUS   0nSnU R                  USSS5      u  pRSnSnU(       a  SnU R                  SX25      u  pUS:X  a  SUS	'   OS
US	'   U R	                  U R                  XB5      5      nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  U
S0 5      nO3U R                  U R                  XB5      5      nU R                  US0 5      nU R                  Xs5      $ )a&  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://docs.kucoin.com/#get-24hr-stats
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>`
r  r7   Nr   r   FrF   r  r  r  r  rj  r   )
r  rc  r  r	  r
  r  r  rI  publicGetMarketStatsr  )r  r  r  rc  r  r   r  ra  r(  r  
resultLists              r  fetch_tickerkucoin.fetch_tickerU  s    	V$fTl
 33FM5RWXD==mV\LDv~'-$'0$..t{{7/KLH6 >>(FB7Dfb9J^^J26F00W1MNH0 ^^Hfb9F  00r  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )ac  
fetches the mark price for a specific market

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

:param str symbol: unified symbol of the market to fetch the ticker for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
r  r7   r  )r  rc  publicGetMarkPriceSymbolCurrentr  r  r  r  r  r  rc  r  r  r  s          r  fetch_mark_pricekucoin.fetch_mark_price  sl     	V$fTl
 77G8TU~~h3  ..r  c           	          U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      U R                  US5      /$ )Nr   r   r   r   r   r   )safe_timestamprP  )r  ohlcvrc  s      r  parse_ohlcvkucoin.parse_ohlcv  sn     q)UA&UA&UA&UA&UA&
 	
r  r   	timeframesincer  c           	         U R                  5         SnU R                  USS5      u  peU(       a  U R                  SXXBUS5      $ U R                  U5      nUS   nSU0n	U R	                  U5      S-  n
U R                  5       nUbi  U R                  [        [        R                  " US-  5      5      5      U	S	'   Uc  U R                  U R                  S
S5      nU R                  X4U
-  5      nO>Ub;  XU
-  -
  nU R                  [        [        R                  " US-  5      5      5      U	S	'   U R                  [        [        R                  " US-  5      5      5      U	S'   SnU R                  USSS5      u  pSnSnU(       a  SnU R                  SXu5      u  pUS:X  a  SU	S'   OSU	S'   U R                  U R                  X"5      U	S'   U R!                  U R#                  X5      5      nU R%                  US0 5      nU R'                  US/ 5      nORU R                  U R                  X"5      U	S'   U R)                  U R#                  X5      5      nU R'                  US/ 5      nU R+                  XX#U5      $ )a  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://docs.kucoin.com/#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
Fr~   paginater  r7   r    NstartAtfetchOHLCVLimitendAtr   rF   r  r  r  intervalr  rj  r(  )r  r  "fetch_paginated_call_deterministicrc  parse_timeframer  parse_to_intintmathfloorr  r  sumr	  r  r   utaGetMarketKliner  r  rI  publicGetMarketCandlesparse_ohlcvs)r  r  r%  r&  r  r  r(  rc  r  r  durationr,  r   r  ra  r(  r  s                    r  fetch_ohlcvkucoin.fetch_ohlcv  si     	88zZ::<X]jprvwwV$$<h
 ''	2T9!!#!%!2!23tzz%$,7O3P!QGI}
 ))$,,8I4PHHUH$45EH,,E!%!2!23tzz%$,7O3P!QGI,,SEDL1I-JK33FL%QVWD==lF[LDv~'-$'0$"&"2"24??I"YGJ--dkk'.JKH >>(FB7D^^D&"5F"..t	UGFO224;;w3OPH ^^Hfb9F  5IIr  c                 2   U R                  5         U R                  U5      nSUS   0nSnU R                  U5      u  pRUb  U R                  U5      US'   U R	                  U R                  XB5      5      nU R                  US0 5      nU R                  Xs5      $ )a  

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

create a currency deposit address
:param str code: unified currency code of the currency for the deposit address
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: the blockchain network name
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r  r7   Nr  r  )r  r  r  r  privatePostDepositAddressCreater  r  parse_deposit_addressr  s           r  create_deposit_addresskucoin.create_deposit_address*	  s     	==&
 "AA&I"#66{CGG77G8TU  ~~h3))$99r  c                    U R                  5         U R                  U5      nSUS   0nSnU R                  U5      u  pRUb"  U R                  U5      R	                  5       US'   U R
                  S   S   S   S   nS	U R
                  S   S   S   S'   U R                  U R                  XB5      5      nX`R
                  S   S   S   S'   U R                  US
5      nUc  [        U R                  S-   5      eU R                  X5      $ )a~  
fetch the deposit address for a currency associated with self account

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

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.network]: the blockchain network name
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r  r7   Nr  r  r   r  r   r  r  zr fetchDepositAddress() returned an empty response, you might try to run createDepositAddress() first and try again)r  r  r  r  r  r  privateGetDepositAddressesr  
safe_valuer    r7   r=  )	r  r  r  r  r  r  r>   r  r  s	            r  fetch_deposit_addresskucoin.fetch_deposit_addressQ	  s(    	==&
 "AA&I"#66{CIIKGG,,z*95e<=PQJNZ +E23FG224;;w3OP KRZ +E23FGx0<  +_  !_  `  `))$99r  c                    U R                  US5      nUb  UR                  SS5      nS nUb+  U R                  US   5      nUS:w  a  U R                  U5        UUU R	                  U R                  US5      5      UU R                  US5      S.$ )	Naddresszbitcoincash: r7   NIMr  memo)r  r  networkrF  tag)r  replacerN  check_addressr  )r  depositAddressr  rF  r  s        r  r=  kucoin.parse_deposit_addresss	  s    "">9=oonb9G**8D>:Du}""7+"..t/?/?PY/Z[##NF;
 	
r  c                    U R                  5         U R                  U5      nSUS   0nU R                  S   S   S   S   nSU R                  S   S   S   S'   U R                  U R	                  XB5      5      nXPR                  S   S   S   S'   U R                  US/ 5      nU R                  XsS	   /S
SUS	   05      nU R                  US5      $ )aO  

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

fetch the deposit address for a currency associated with self account
:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an array of `address structures <https://docs.ccxt.com/#/?id=address-structure>`
r  r7   r  r   r  r   r?   r  r  FrJ  )r  r  r  rA  r  rI  parse_deposit_addressesrJ  )	r  r  r  r  r  r>   r  r  parseds	            r  "fetch_deposit_addresses_by_network)kucoin.fetch_deposit_addresses_by_network	  s     	==&
 ,,z*95e<=PQJNZ +E23FG224;;w3OP  KRZ +E23FG&"5--f7G6H%(R
  }}VY//r  c           
         U R                  5         U R                  U5      nU R                  USS5      nSUS   0nU R                  S5      nSnU R	                  USSS5      u  pSn	U(       ao  Uc  [        U R                  S	-   5      eX&S
'   US   US'   Sn
U R                  SXC5      u  pU
S:X  a  SUS'   OSUS'   U R                  U R                  Xc5      5      n	OU(       a  Ube  US:X  a>  XVS'   Ub)  US:X  d  US:X  a  X&S
'   O[        U R                  S-   5      eU(       a  UOSUS
'   U R                  U R                  Xc5      5      n	O U R                  U R                  Xc5      5      n	U R                  U	S0 5      nU R                  US5      nU R                  XS   USSUS-
  US-
  5      nU R                  US5      US'   U$ )a  
fetches information on open orders with bid(buy) and ask(sell) prices, volumes and other data

https://www.kucoin.com/docs/rest/spot-trading/market-data/get-part-order-book-aggregated-
https://www.kucoin.com/docs/rest/spot-trading/market-data/get-full-order-book-aggregated-
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
levelr   r  r7   FNr   r   zO fetchOrderBook() requires a limit argument for uta, either 20, 50, 100 or FULLr  rF   r  r  r  r   d   z2 fetchOrderBook() limit argument must be 20 or 100r  r  bidsasksr   sequencer  )r  rc  r  rC  r  r$   r7   r	  utaGetMarketOrderbookr  r    'publicGetMarketOrderbookLevelLevelLimitprivateGetMarketOrderbookLevel2r  parse_order_book)r  r  r  r  rc  rV  r  isAuthenticatedr   r  r(  r  r   	orderbooks                 r  fetch_order_bookkucoin.fetch_order_book	  s    	V$!!&'15!6$<099%@33F<LeUZ[}'  3D  )D  E  E$G &tGHD==>NPV_LDv~'-$'0$11$++g2NOH& !E$5z#( $#+0(+DGG6j,jkk,15s CCDKKPWD`aH;;DKK<XYH@ ~~h3%%dF3	))$x0@)VU[]bef]fhmpqhqr	!..tZ@	'r  c                    U R                  USS5      nU R                  US5      nU R                  US5      nUS LnUS LnU(       a  U(       d  U(       a  U(       d  U(       a  U(       a  [        U R                  S-   5      eX#U/$ )Nr  	stopPricer  r  zW createOrder() - you should use either triggerPrice or stopLossPrice or takeProfitPrice)safe_value_2rB  r    r7   )r  r  r  r  r  
isStopLossisTakeProfits          r  handle_trigger_priceskucoin.handle_trigger_prices
  s    ((M@//&2CD"$.
&d2<\mQ]bn  +D  !D  E  E_==r  r(  sider.  r/  c                    U R                  5         U R                  U5      nU R                  USS5      nU R                  US5      nSn	U R	                  U5      u  pSn
U R                  USSS5      u  pU R                  U5      u  pnU R                  US5      nU=(       d    U=(       d    UnU R                  SU5      nU R                  US5      nUS:H  =(       d    USLnU R                  XX4XV5      nSnU(       aD  U(       a  U R                  U5      nOU	(       a  U R                  U5      nOU R                  U5      nOuU(       a  U R                  U5      nO\U(       a  U R                  U5      nOCU
(       a  U R                  U5      nO*U	(       a  U R!                  U5      nOU R#                  U5      nU R%                  US	0 5      nU R'                  UU5      $ )
a  
       Create an order on the exchange

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

       :param str symbol: Unified CCXT market symbol
       :param str type: 'limit' or 'market'
       :param str side: 'buy' or 'sell'
       :param float amount: the amount of currency to trade
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]:  extra parameters specific to the exchange API endpoint
       :param float [params.triggerPrice]: The price at which a trigger order is triggered at
       :param str [params.marginMode]: 'cross',  # cross(cross mode) and isolated(isolated mode), set to cross by default, the isolated mode will be released soon, stay tuned
       :param str [params.timeInForce]: GTC, GTT, IOC, or FOK, default is GTC, limit orders only
       :param str [params.postOnly]: Post only flag, invalid when timeInForce is IOC or FOK

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

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

:param str symbol: unified symbol of the market to create an order in
:param str side: 'buy' or 'sell'
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r7  rc  N)r  r  r  )r  r  rj  r7  r  reqs         r  create_market_order_with_cost$kucoin.create_market_order_with_costw
  sA     	D
   4tT[[QTE]^^r  c                 H    U R                  5         U R                  USX#5      $ )a  
create a market buy order by providing the symbol and cost

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

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r  r  r  r  r7  r  s       r  !create_market_buy_order_with_cost(kucoin.create_market_buy_order_with_cost
  s%     	11&%NNr  c                 H    U R                  5         U R                  USX#5      $ )a  
create a market sell order by providing the symbol and cost

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

:param str symbol: unified symbol of the market to create an order in
:param float cost: how much you want to trade in units of the quote currency
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r  r  s       r  "create_market_sell_order_with_cost)kucoin.create_market_sell_order_with_cost
  s%     	11&&$OOr  r   c           	         U R                  5         / nSn[        S[        U5      5       H  nX   nU R                  US5      nUc  UnOXG:w  a  [	        U R
                  S-   5      eU R                  US5      nUS:w  a  [	        U R
                  S-   5      eU R                  US5      n	U R                  US	5      n
U R                  US
5      nU R                  US0 5      nU R                  XxXX5      nUR                  U5        M     U R                  U5      nUS   US.nSnU R                  U5      u  nnSnU R                  USSS5      u  nnSnU(       a!  U R                  U R                  X5      5      nOHU(       a!  U R                  U R                  X5      5      nO U R                  U R                  X5      5      nU R!                  US0 5      nU R#                  US/ 5      nU R%                  U5      $ )a  
create a list of trade orders

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

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]:  extra parameters specific to the exchange API endpoint
:param bool [params.hf]: False,  # True for hf orders
:param bool [params.sync]: False,  # True to use the hf sync call
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr   r  z; createOrders() requires all orders to have the same symbolr(  r  z* createOrders() only supports limit ordersrj  r.  r/  r  r7   )r  	orderListFrV   rm  r  )r  rK  rL  r  r%   r7   rB  ro  rA  rc  r  r  privatePostHfOrdersMultiSyncr  privatePostHfOrdersMultiprivatePostOrdersMultir  rI  parse_orders)r  r   r  ordersRequestsr  rb  rawOrderr  r(  rj  r.  r/  orderParamsr~  rc  r  r  rz  r  r  s                       r  create_orderskucoin.create_orders
  s    	q#f+&AyH''(;H~!%$TWW/l%lmm##Hf5Dw +W!WXX##Hf5D__Xx8FOOHg6E//(HbAK44XTSXfL!!,/! '" V$Tl'
 ..v6
F77PVX]^88W9UVH44T[[5QRH224;;w3OPH> ~~h3~~dFB/  &&r  c                    U R                  U5      nU R                  U[        US   S   U R                  U R                  5      nUS:X  a9  [        U R                  S-   US   -   S-   U R                  US   S   5      -   5      eU$ )	Nr  quoteIncrementry  z amount of r  z2 must be greater than minimum amount precision of r=  r.  )rc  decimal_to_precisionr/   r  paddingModer)   r7   number_to_string)r  r  r.  rc  ra  s        r   market_order_amount_to_precision'kucoin.market_order_amount_to_precision
  s    V$**68VF^L\=]_c_q_qsw  tD  tD  ES=tww69II  MA   A  DH  DY  DY  Z`  al  Zm  nv  Zw  Dx   x  y  yr  c                    U R                  U5      nU R                  USSU R                  5       5      nU R                  USS/5      nUUUS   US.n	U R	                  USS5      n
S nS nS nU R                  SU5      u  pUS:X  aS  U
b*  U R                  USS/5      nU R                  X5      nXS'   OOU R                  X5      nU R                  X5      U	S	'   O)U R                  X5      nXS	'   U R                  X5      U	S
'   U R                  US5      nU R                  U5      u  nnnU=(       d    U=(       d    UnUS:H  =(       d    US LnU R                  U/ SQ5      nU(       a  U(       a  U R                  X5      U	S'   OZU(       d  U(       aL  U(       a#  US:X  a  SOSU	S'   U R                  UU5      U	S'   O"US:X  a  SOSU	S'   U R                  UU5      U	S'   US:X  a  [        U R                  S-   5      eUS:X  a  U R                  S   U   U	S'   OU(       a  US:X  a  SU	S'   S nU R                  US:H  SU5      u  nnU(       a  SU	S'   U R                  X5      $ )N	clientOidclientOrderIdr7   )r  rj  r  r(  r7  fundsrU   rc  sizer/  r  r  )r  r  r  rd  rd  r  r  lossstopr  z= createOrder does not support isolated margin for stop ordersr  r  marginModelFTpostOnly)rc  r  uuidr  r  rn  r  amount_to_precisionprice_to_precisionr  rh  r%   r7   r  handle_post_onlyr  )r  r  r(  rj  r.  r/  r  rc  r  r  quoteAmountamountString
costStringr  r  r  r  r  r{  r}  r  s                        r  ro  kucoin.create_order_request   s   V$**6;QUQZQZQ\]6K#AB&Tl	
 ((A

!??vV
8&6FG+<=!BB6W
#- #77G"&":":6"J33FCL*FO#66vEGG$$V[9	7;7Q7QRX7Y4m_&J-J?!^3Mz7M6#de'+'>'>v'T$/ 26%-gfGFO+/+B+B6=+YGK(15fWGFO+/+B+B6?+[GK(Z' +j!jkkw&'+||M'B:'N$Z')3&001A5&Q&"&GJ{{7++r  r7   c                 t   U R                  5         U R                  U5      nSUS   0n	U R                  USS5      n
U
b  XS'   OXS'   Ub  U R                  X%5      U	S'   Ub  U R	                  X&5      U	S'   U R                  U R                  X5      5      nU R                  US0 5      nU R                  X5      $ )	a  
edit an order, kucoin currently only supports the modification of HF orders

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

:param str id: order id
:param str symbol: unified symbol of the market to create an order in
:param str type: not used
:param str side: not used
:param float amount: how much of the currency you want to trade in units of the base currency
:param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.clientOrderId]: client order id, defaults to id if not passed
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r7   r  r  orderIdnewSizenewPricer  )	r  rc  r  r  r  privatePostHfOrdersAlterr  r  rx  )r  r7   r  r(  rj  r.  r/  r  rc  r  r  r  r  s                r  
edit_orderkucoin.edit_order9  s      	V$fTl
 **6;P$#0K !#I!%!9!9&!IGI"&"9"9&"HGJ00W1MN ~~h3--r  c                    U R                  5         0 nU R                  USS5      nU R                  USSS5      nSnU R                  U5      u  psSnU R	                  USSS5      u  pU(       d  U(       a4  Uc  [        U R                  S	-   5      eU R                  U5      n	U	S
   US'   Sn
U R                  U/ SQ5      nUb  XTS'   U(       a!  U R                  U R                  XC5      5      n
OpU(       a!  U R                  U R                  XC5      5      n
OHU(       a!  U R                  U R                  XC5      5      n
O U R                  U R                  XC5      5      n
U R                  U
S5      n
U R                  U
5      $ XS'   U(       a!  U R!                  U R                  XC5      5      n
OU(       a!  U R#                  U R                  XC5      5      n
OjU(       aC  U R%                  U R                  XC5      5      n
U R                  U
S5      n
U R                  U
5      $ U R'                  U R                  XC5      5      n
U R                  U
S5      nU R)                  US/ 5      nU R+                  US5      nU R-                  UUS.5      $ )a  
cancels an open order

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

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: True if cancelling a stop order
:param bool [params.hf]: False,  # True for hf order
:param bool [params.sync]: False,  # True to use the hf sync call
:returns: Response from the exchange
r  r  r  r  FNrN   rm  z8 cancelOrder() requires a symbol parameter for hf ordersr7   r  )r  r  r  r  r  r  cancelledOrderIdsr   )r  r7   )r  r  safe_bool_2r  r  r$   r7   rc  r  ,privateDeleteStopOrderCancelOrderByClientOidr  -privateDeleteHfOrdersSyncClientOrderClientOid)privateDeleteHfOrdersClientOrderClientOid&privateDeleteOrderClientOrderClientOidr  rx  privateDeleteStopOrderOrderId privateDeleteHfOrdersSyncOrderIdprivateDeleteHfOrdersOrderIdprivateDeleteOrdersOrderIdrI  r  
safe_order)r  r7   r  r  r  r  r  r  rz  rc  r  r  orderIdsr  s                 r  cancel_orderkucoin.cancel_orderc  sX   * 	**6;P""669eD..v6
77vW\]~'2l(lmm[[(F &tGH6#TU$#0K LLT[[Y`Mij MMdkkZaNjkII$++V]Jfg  FFt{{SZGcd ~~h7H##H--!#I==dkk'>Z[ @@WA]^<<T[[=YZ  >>(F;''11::4;;w;WX >>(F3D~~d,?DH&&x3G??$  r  c                    U R                  5         0 nU R                  USSS5      nSnU R                  U5      u  pRU R                  US5      nU R	                  SU5      u  pgUb  U R                  U5      US'   Ub:  U R                  S   U   US'   US	:X  a  U(       a  [        U R                  S
-   5      eSnU(       a!  U R                  U R                  X75      5      nOlU(       aE  Uc!  U R                  U R                  X75      5      nOAU R                  U R                  X75      5      nO U R                  U R                  X75      5      nU R                  SU05      /$ )a  
cancel all open orders

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

:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param bool [params.trigger]: *invalid for isolated margin* True if cancelling all stop orders
:param str [params.marginMode]: 'cross' or 'isolated'
:param str [params.orderIds]: *stop orders only* Comma seperated order IDs
:param bool [params.hf]: False,  # True for hf order
:returns: Response from the exchange
r  r  FNrM   r  r  r  r  zA cancelAllOrders does not support isolated margin for stop ordersr  )r  r  r  r  rn  	market_idr  r%   r7   privateDeleteStopOrderCancelr  privateDeleteHfOrdersCancelAllprivateDeleteHfOrdersprivateDeleteOrdersr  )	r  r  r  r  r  r  r  queryr  s	            r  cancel_all_orderskucoin.cancel_all_orders  sJ     	""69feD..v6
66* >>?PRXY
 $v 6GH!#'<<#>z#JGK Z'G +n!noo88W9TUH~>>t{{7?Z[55dkk'6QR//G0KLH 2344r  c                 (   U R                  5         UR                  5       nU R                  US5      nU R                  USSS5      nSn	U R	                  U5      u  pU	(       a  Uc  [        U R                  S-   5      eU R                  U/ SQ5      nU R                  SU5      u  pUS	:X  a  S
nOUS:X  a  SnSU0nSnUb  U R                  U5      nUS   US'   Ub  X<S'   Ub  XLS'   U(       a  X|S'   U R                  U R                  S   U
S5      US'   SnU(       a!  U R                  U R                  X5      5      nOuU	(       aN  US
:X  a!  U R                  U R                  X5      5      nOGUS:X  a   U R                  U R                  X5      5      nO U R!                  U R                  X5      5      nU R#                  US5      nUb  U R%                  XX45      $ U R'                  US0 5      nU R#                  US/ 5      nU R%                  UXU5      $ )aD  
fetch a list of orders

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

:param str status: *not used for stop orders* 'open' or 'closed'
:param str symbol: unified market symbol
:param int [since]: timestamp in ms of the earliest order
:param int [limit]: max number of orders to return
:param dict [params]: exchange specific params
:param int [params.until]: end time in ms
:param str [params.side]: buy or sell
:param str [params.type]: limit, market, limit_stop or market_stop
:param str [params.tradeType]: TRADE for spot trading, MARGIN_TRADE for Margin Trading
:param int [params.currentPage]: *trigger orders only* current page
:param str [params.orderIds]: *trigger orders only* comma seperated order ID list
:param bool [params.trigger]: True if fetching a trigger order
:param bool [params.hf]: False,  # True for hf order
:returns: An `array of order structures <https://docs.ccxt.com/#/?id=order-structure>`
untilr  r  FNz@ fetchOrdersByStatus() requires a symbol parameter for hf orders)r  r  tillr  r   r  r)  closeddoner   r7   r  r*  pageSizer,  r  r  r  r  r  )r  r  r  r  r  r$   r7   r  rn  rc  r  r  privateGetStopOrderr  privateGetHfOrdersActiveprivateGetHfOrdersDoneprivateGetOrdersrI  r  r  )r  r   r  r&  r  r  lowercaseStatusr  r  r  r  r  r  rc  r  listDataresponseDatar   s                     r  fetch_orders_by_statuskucoin.fetch_orders_by_status  s   0 	 ,,.!!&'2""669eD..v6
6>#DGG.p$pqq6#GH >>?TV\]
f$&O($Oo
 [[(F &tGH!&I"'J$G#//]0KZY`a//G0KLH(*88W9TU F*66t{{77RS,,T[[-HIHX >>(F3$$XuDD~~h;gr:  >>r  c                     U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ U R                  SXX45      $ )a  
fetches information on multiple closed orders made by the user

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

:param str symbol: unified market symbol of the market orders were made in
:param int [since]: the earliest time in ms to fetch orders for
:param int [limit]: the maximum number of order structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: end time in ms
:param str [params.side]: buy or sell
:param str [params.type]: limit, market, limit_stop or market_stop
:param str [params.tradeType]: TRADE for spot trading, MARGIN_TRADE for Margin Trading
:param bool [params.trigger]: True if fetching a trigger order
:param bool [params.hf]: False,  # True for hf order
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Frb   r(  r  r  r  fetch_paginated_call_dynamicr  r  r  r&  r  r  r(  s         r  fetch_closed_orderskucoin.fetch_closed_orderso  s]    , 	88ATV`a445H&Y^gg**66%PPr  c                     U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ U R                  SXX45      $ )aH  
fetch all unfilled currently open orders

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

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

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

:param str id: Order id
:param str symbol: not sent to exchange except for trigger orders with clientOid, but used internally by CCXT to filter
:param dict [params]: exchange specific parameters
:param bool [params.trigger]: True if fetching a trigger order
:param bool [params.hf]: False,  # True for hf order
:param bool [params.clientOid]: unique order id created by users to identify their orders
:returns: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r  r  r  FNz7 fetchOrder() requires a symbol parameter for hf ordersr7   r  )r  r  r  r  z" fetchOrder() requires an order idr  r  r   )r  r  r  r  rc  r$   r7   r  (privateGetStopOrderQueryOrderByClientOidr  &privateGetHfOrdersClientOrderClientOid#privateGetOrderClientOrderClientOidr)   privateGetStopOrderOrderIdprivateGetHfOrdersOrderIdprivateGetOrdersOrderIdr  
isinstancerj  rB  rx  )r  r7   r  r  r  r  r  r  rc  r  r  s              r  fetch_orderkucoin.fetch_order  s   & 	**6;P""669eD..v6
[[(F~'2k(kll &tGH6#TU$#0K %(.tGH%HHU\IefFFt{{SZGcdCCDKKPWD`a
 z"477-Q#QRR!#I::4;;w;WX99$++g:VW77G8TU~~h;lD))??<;L55r  orderc           	      N   U R                  US5      nU R                  US5      nU R                  US5      nU R                  USS5      nU R                  US5      nUS LnU R                  USS5      n	U R                  USS	5      n
U R                  US
5      nS nU
b
  U
SL a  SnOSnU(       a  US:X  a  SnOU
(       d	  U	(       d  SnU(       a  SnUS:X  a  SnU R	                  0 SU_SU R                  U/ SQ5      _SU R                  US5      _SU R                  X2S5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _SU R                  US5      _S U R                  US!5      _S"U R                  US#5      _S$U R                  US%5      _S&S _S'U_S(U R                  U5      _S)U R                  U5      U R                  US)5      S*._US U R                  US+5      S S,.EU5      $ )-Nr  	createdAtfeeCurrencycancelExistFr  stopTriggeredisActiver)  r   Tr  r  NEW	cancelledcanceledfailrejectedr  r7   )r7   r  
newOrderIdcancelledOrderIdr  r  r  r(  r  r  rj  r.  r  r/  r  rd  r7  	dealFundsfilleddealSize	remainingr   r  r  )r  r7  avgDealPrice)r   lastTradeTimestampr  trades)
r  r  rD  r  r  r  safe_symbolrP  r  rN  )r  r  rc  r  r   feeCurrencyIdr  responseStopr  r  r  responseStatusr   s                r  rx  kucoin.parse_order  s   t ##E84%%e[9	((>nnUM5A''v6d*uouE##E:x@))%:4!&m$FV#F  
E 
$$$U,_` 
 T--e[A 
 d&&x=	 

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

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

:param str id: order id
:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch trades for
:param int [limit]: the maximum number of trades to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
r  )fetch_my_tradesr  )r  r7   r  r&  r  r  r  s          r  fetch_order_tradeskucoin.fetch_order_trades  s.     r
 ##F5++g:VWWr  c                 R   U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nSnU R                  U5      u  ptU(       a  Uc  [	        U R
                  S-   5      eSnUb  U R                  U5      nUS   US'   U R                  S   n	Sn
SnU R                  S	Xd5      u  pdU(       a/  Ub  X6S
'   Ub  X&S'   U R                  U R                  Xd5      5      nOoU	S:X  a(  Ub  X&S'   U R                  U R                  Xd5      5      nOAU	S:X  a#  Sn
U R                  U R                  Xd5      5      nO[        U R
                  S-   5      eU R                  US0 5      nSnU
(       a  UnOU R                  US/ 5      nU R!                  XX#5      $ )a>  

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

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

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

: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>`
r  r7   Nr   r   FrF   r  r  r  r  rj  )
r  rc  r  r	  utaGetMarketTrader  r  rI  publicGetMarketHistoriesr  )r  r  r&  r  r  rc  r  r   r  r  r(  r  s               r  fetch_tradeskucoin.fetch_trades  s    	V$fTl
 33FM5RWXD==mV\LDv~'-$'0$--dkk'.JKH& >>(FB7D^^D&"5F44T[[5QRH ^^Hfb9F  >>r  r  c                 B   U R                  US5      nU R                  X2S5      nU R                  USS5      nU R                  US5      nU R                  US5      nU R                  USS5      nUb  U R	                  US	-  5      nO U R                  US
5      nSU;   a  Ub  US-  nU R                  USS5      nU R                  USS5      n	U R                  US5      n
S nU R                  US5      nUbL  U R                  US5      nU R                  U5      nUc  U
S:X  a  US   OUS   nUUU R                  US5      S.nU R                  US5      nUS:X  a  S nU R                  USS5      nU R                  UUUUU R                  U5      US   UUU
UU	UUS.U5      $ )Nr  r  tradeIdr7   r  	liquidityr  r  i@B r  	dealValuer)  r/  	dealPricer  r.  rj  r  r  r  r#  r  feeRate)r7  r  rater(  matchr  )r  r7   r  r   r  r  r(  takerOrMakerrj  r/  r.  r7  r  )	r  r   r  r  r0  r  rN  
safe_trader  )r  r  rc  r  r7   r  r&  r   priceStringr  rj  r  feeCostStringr  r  r(  r  s                    r  parse_tradekucoin.parse_trade^  s   p ##E84!!(C8y$7""5)4''{;''vt<	 )))g*=>I))%=Iu$9+@%,	((E))%Bv.((6$ ,,UMBM11-@K"26&.fWovf~%'((	:C
 v.7?D''wD
"Y/X&( " 
  	r  c                 p   U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US/ 5      nU R                  US5      nU R                  US5      nUU R                  X5      U R                  US5      U R                  US5      SSS	.$ )
aJ  
fetch the trading fees for a market

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
r   r7   r  r   r  r  r  T)r  r  r  r  r  r  )	r  rc  privateGetTradeFeesr  rI  r  r  r  rP  )	r  r  r  rc  r  r  r  firstr  s	            r  fetch_trading_feekucoin.fetch_trading_fee  s     	V$vd|
 ++DKK,HI ~~h3tQ'##E84&&x8%%e^<%%e^<
 	
r  rF  rK  c                 ,   U R                  XE5      u  pEU R                  5         U R                  U5        U R                  U5      nUS   USS.nUb  XGS'   SnU R	                  U5      u  pUb"  U R                  U5      R                  5       US'   [        U R                  XU5      5      US'   Sn	U R                  USS	S
5      u  pU	(       a  SUS'   U R                  U R                  Xu5      5      n
U R                  U
S0 5      nU R                  X5      $ )a  
make a withdrawal

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

:param str code: unified currency code
:param float amount: the amount to withdraw
:param str address: the address to withdraw to
:param str tag:
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transaction structure <https://docs.ccxt.com/#/?id=transaction-structure>`
r7   ADDRESS)r  	toAddresswithdrawTypeNrI  r  r.  r   r  FINTERNALfeeDeductTyper  )handle_withdraw_tag_and_paramsr  rM  r  r  r  r  floatcurrency_to_precisionr  privatePostWithdrawalsr  r  parse_transaction)r  r  r.  rF  rK  r  r  r  r  r  r  r  s               r  r   kucoin.withdraw  s"    99#F7#==&  %
 ?!FO"AA&I"#66{CIIKGG!$"<"<T;"WX
!::6:|]bc
'1GO$..t{{7/KL ~~h3%%d55r  r   c                 4    SSSSS.nU R                  X!U5      $ )Nr  pendingfailed)SUCCESS
PROCESSINGWALLET_PROCESSINGFAILUREr  r  r   statusess      r  parse_transaction_statuskucoin.parse_transaction_statusA  s*    #!*	
 &99r  transactionc                 H   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU R                  US5      nUbA  UR                  S5      n[        U5      n	U	S:  a  Uc  [        US   5      S:  a  US   nUS   nUc  SOS	n
U R                  US
5      nS nU R                  US5      nUb?  S nUb  [        R
                  " X5      nU R                  U5      U R                  U5      US.nU R                  USS5      nU R                  US5      nSU;  nU(       a  SU;   a  SOS	n
Ub  US-  nUb  US-  nU R                  US5      nU R                  US5      n0 SU_SU R                  USS5      _SU_SU R                  U5      _SU R                  U R                  US5      5      _SU_SU_SS _SU_SU_SS _SU_SU R                  U5      _SU_S U
_S
U R                  U5      _S!U R                  US"5      _UUUS#.E$ )$Nr  rF  r.  
walletTxId@r   r   
withdrawalr  r   r  )r7  r$  r  r  createAt	updatedAtr)  isInnerrI  r  r7   withdrawalIdr   r  rJ  r  	addressToaddressFromrK  tagTotagFromtxidr(  rB   remark)internalr  r	  )r  rN  rM  rL  r1   
string_divr  r  r  rD  r  r  r  rG  )r  rI  r  r  r  rF  r.  rV  	txidPartsnumTxidPartsr(  	rawStatusr  feeCostr$  r   r	  isV1rX  rK  s                       r  r;  kucoin.parse_transactionJ  s   V %%k:>
&&z<"";	:!!+x8\:

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

 t..t/?/?W/UV
 w
 
 4
 3
 S
 t
 
 d''/
 D
 D
  d33I>!
" t''X>#
$ !)
 	
r  c                 D   U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X6S'   U R	                  SXd5      u  pdSnUb>  US	:  a8  U R                  US
-  5      US'   U R                  U R                  Xd5      5      nO'Ub  X&S'   U R                  U R                  Xd5      5      nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  XX#SS05      $ )aT  
fetch all deposits made to an account

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

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Fri   r(  Nr7   r  r  r,      |{r)  r*  r  r  r(  r  )r  r  r  r  r  r0  privateGetHistDepositsr  privateGetDepositsr  rI  parse_transactionsr  r  r&  r  r  r(  r  r  r  r  r  s              r  fetch_depositskucoin.fetch_deposits  s@    	88R\]44_dSXaa}}T*H"*4.GJ"'J227GL!6!%!2!254<!@GI224;;w3OPH %*	"..t{{7/KLHN ~~h3tWb1&&uvyFYZZr  c                 D   U R                  5         SnU R                  USS5      u  pTU(       a  U R                  SXX45      $ 0 nSnUb  U R                  U5      nUS   US'   Ub  X6S'   U R	                  SXd5      u  pdSnUb>  US	:  a8  U R                  US
-  5      US'   U R                  U R                  Xd5      5      nO'Ub  X&S'   U R                  U R                  Xd5      5      nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  XX#SS05      $ )an  
fetch all withdrawals made from an account

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

:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch withdrawals for
:param int [limit]: the maximum number of withdrawals structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Fr   r(  Nr7   r  r  r,  ra  r)  r*  r  r  r(  rM  )r  r  r  r  r  r0  privateGetHistWithdrawalsr  privateGetWithdrawalsr  rI  rd  re  s              r  fetch_withdrawalskucoin.fetch_withdrawals  sB    	88ASU_`445GV[dd}}T*H"*4.GJ"'J227GL!6!%!2!254<!@GI55dkk'6RSH %*	"11$++g2NOHP ~~h3tWb1&&uv|F\]]r  c                 $   U R                  5       nU R                  USS5      US'   U R                  USS5      US'   U R                  USS5      US'   U R                  US	5      nU R                  US
5      n[        R                  " X45      US'   U$ )NholdBalanceholdusedavailableBalance	availablefreetotalBalancetotal	liabilityinterestdebt)r  r  r  r1   
string_add)r  r  r  rx  rw  s        r  parse_balance_helperkucoin.parse_balance_helperQ  s    ,,.,,UM6J,,U4FT--e^WM{3##E:6!,,T<r  c                 :   U R                  5         U R                  US5      nSnUb  U R                  U5      nU R                  U R                  SSS5      nU R                  USU5      nU R                  U R                  S5      nU R                  XeU5      nU R                  US5      nSnU R                  U5      u  pU(       a  US:w  a  S	nU R                  SU5      u  pSn0 nU	S
:H  =(       d    US
:H  nU	S:H  =(       d    US:H  nU(       a,  Ub  US   US'   U R                  U R                  X5      5      nOWU(       a!  U R                  U R                  X5      5      nO/Ub  US   US'   X|S'   U R                  U R                  X5      5      nSnUSSS.nU(       Ga  U R                  US0 5      nU R                  USU5      n[        S[        U5      5       H  nUU   nU R                  US5      nU R!                  USS5      nU R                  US0 5      nU R                  US0 5      nU R#                  U R                  US5      5      nU R#                  U R                  US5      5      n0 nU R%                  U5      UU'   U R%                  U5      UU'   U R'                  U5      UU'   M     GOKU(       a  U R                  US0 5      nU R)                  US/ 5      n[        S[        U5      5       H?  nUU   nU R                  US5      nU R#                  U5      nU R%                  U5      UU'   MA     OU R)                  US/ 5      n[        S[        U5      5       H  nUU   nU R                  US5      nUU:X  d  M"  U R                  US5      nU R#                  U5      n U R+                  5       n!U R                  US5      U!S'   U R                  US5      U!S'   U R                  US5      U!S'   U!UU '   M     Un"U(       d  U R'                  U5      n"U"$ )a3  
query for balance and get the amount of funds available for trading or funds locked in orders

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

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

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

:param str code: unified currency code
:param float amount: amount to transfer
:param str fromAccount: account to transfer from
:param str toAccount: account to transfer to
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `transfer structure <https://docs.ccxt.com/#/?id=transfer-structure>`
r  r  zK transfer() only supports transferring from futures account to main accountr7   )r  r.  bizNor  fromTagr  toTagfromtor  )r  r  r9  convert_type_to_accountr  idsr    r7   uuid22futuresPrivatePostTransferOutr  r  parse_transferr   privatePostAccountsInnerTransfer)r  r  r.  r  r  r  r  requestedAmountfromIdtoIdfromIsolated
toIsolatedr  r  r  s                  r  r   kucoin.transfer  s    	==&44TB--k:++I6}}VXX6]]42
Zv~#DGG.{${||$TN)G v%#';;= 99$++g:VWH2 >>(F3D&&t66 %TN)G z==22)/I&'F==xx00'+G$%D$FO DM6)'+yy{$<<T[[=YZH >>(F3D&&t66r  r   c           
         U R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  US5      nU R                  U R                  S5      nU R                  XU5      n	U R                  XU5      n
U R                  USS5      U R                  XB5      UU R                  U5      U R                  US	5      U	U
U R                  U5      US
.	$ )Nr  r  r   payAccountTyperecAccountTyper  applyIdr  r.  )	r7   r  r   r  r.  r  r  r   r  )
r  r  safe_string_lowerr  r  r  rN  r  rP  parse_transfer_status)r  r   r  r   r  r\  accountFromRawaccountToRawr  accountFrom	accountTos              r  r  kucoin.parse_transferZ  s    F %%h<	%%h
;
$$Xx8	//:JK--h8HI6FG&&~~V$$^<P	$$Xy)D//
E"Y/&&x:&"00;

 
	
r  c                 .    SS0nU R                  X!U5      $ )NrA  r>  rD  rE  s      r  r  kucoin.parse_transfer_status  s#    )
 &99r  c                     0 SS_SS_SS_SS_SS_S	S
_SS_SS
_SS_SS
_SS_SS_SS_SS_SS_SS_SS_SSSSS.EnU R                  X!U5      $ )Nz%Assets Transferred in After Upgradingr   DepositrI  
WithdrawalTransferTrade_Exchanger  zKuCoin BonusbonuszReferral Bonusr   RewardszAirdrop/ForkairdropzOther rewardsz
Fee Rebaterebatez
Buy CryptozSell Cryptor  zPublic Offering PurchasezRefunded Feesr  zKCS Pay FeeszMargin TradeLoans)r  zInstant ExchangezSub-account transferzLiquidation FeesrD  )r  r(  typess      r  parse_ledger_entry_typekucoin.parse_ledger_entry_type  s    (
3Z(
}(
 -(
 
	(

 g(
 G(
 j(
 w(
 I(
 W(
 ((
 '(
 6(
  '!(
. U/(
0 E1(
2 G3(
4  !($. %E(
R T22r  itemc                 &   U R                  US5      nU R                  US5      nU R                  XB5      nU R                  XB5      nU R                  US5      nS nU R                  US5      nU R	                  U5      n	U R                  US5      n
U R                  US5      nU R                  U5      nU R                  US5      nU R                  US5      nS nUbJ  US	:w  aD   [        R                  " U5      nU R                  US
5      nU R                  US5      nUb  UnOUn S nU R                  US5      nS nUS:w  a  UnU R                  U5      US.nU R                  UUU
UUUU	UUUUS US US.U5      $ ! [         a  nUn S nANeS nAff = f)Nr7   r  r.  bizType	directionr  accountTypecontextrG  r  r  r  ry  )r7  r  )r  r7   r  r  referenceIdreferenceAccountr(  r  r.  r   r  beforeafterr   r  )r  rN  safe_currencyrP  r  r  r  jsonloads	Exceptionr  safe_ledger_entry)r  r  r  r7   r  r  r.  balanceAfterr  r(  r  r   r  r  r  r  rR  r  r  excr  r]  r  s                          r  parse_ledger_entrykucoin.parse_ledger_entry  s    dD)%%dJ7
&&z<%%j;!!$1""43++G4$$T;7	%%dK8	<<	*""47""43 7b=
&G,**69=**69=&")K")K ""4/c>K,,W5;OC%%"& '" !'
  ! 	  &%&s   #?E: #E: :
FFFc                    U R                  5         U R                  5         SnU R                  USS5      u  pTSnU R                  U5      u  pdU(       a  U R	                  SXX45      $ 0 nUb  X'S'   SnUb  U R                  U5      nUS   US'   U R                  SXt5      u  ptSn	U R                  SU5      u  pSn
U(       aE  U	b!  U R                  U R                  Xt5      5      n
OAU R                  U R                  Xt5      5      n
O U R                  U R                  Xt5      5      n
U R                  U
S	5      nUb  U R                  XX#5      $ U R                  U
S	5      nU R                  US
/ 5      nU R                  XX#5      $ )ay  
fetch the history of changes, actions done by the user or operations that altered the balance of the user

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

:param str [code]: unified currency code, default is None
:param int [since]: timestamp in ms of the earliest ledger entry, default is None
:param int [limit]: max number of ledger entries to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param boolean [params.hf]: default False, when True will fetch ledger entries for the high frequency trading account
:param int [params.until]: the latest time in ms to fetch entries for
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns dict: a `ledger structure <https://docs.ccxt.com/#/?id=ledger>`
Frt   r(  Nr*  r7   r  r,  r  r  )r  load_accountsr  r  r  r  r  rn   privateGetHfMarginAccountLedgersr  privateGetHfAccountsLedgersprivateGetAccountsLedgersrI  parse_ledgerr  )r  r  r&  r  r  r(  r  r  r  r  r  dataListr  r  s                 r  fetch_ledgerkucoin.fetch_ledger  s   " 	88PZ[..v6
44]DQV__
 !&I}}T*H"*4.GJ227GL
!??vV
%@@WA]^;;DKK<XY55dkk'6RSHL >>(F3$$XFF~~h/tWb1  %??r  c                 t   U R                  U R                  S0 5      nU R                  Xa0 5      nU R                  Xr0 5      nU R                  XU R                  S   5      n	U R                  USU	5      n
U
S:X  a  SU;   a  US   $ U
S:X  a  SU;   a  US   $ U
S:X  a  SU;   a  US   $ U R                  USS5      $ )Nr  r>   r  r?   r  r7  r   )r  r  r  rB  )r  r   r  pathr  configr  apiVersionsmethodVersionsdefaultVersionr>   s              r  calculate_rate_limiter_cost"kucoin.calculate_rate_limiter_costp  s    >>$,,
B?nnXB7R@)).Y@WX""69nEd?$<_$&.$<_$&.$<vvq11r  c                     U R                  USS5      nU R                  USS 5      nU R                  US5      nU R                  XR5      U R	                  USS5      SUU R                  U5      US	.$ )
Nr  r   r      r  dailyIntRatedayRatioi \&)r  r$  periodr   r  r  )r  r0  r  rN  r  r  )r  r  r  timestampIdr   r  s         r  parse_borrow_ratekucoin.parse_borrow_rate~  s    $ (({KH%%k!B&78	%%dJ7
//
E&&t^ZH"Y/
 	
r  c                 T   U R                  5         SnU R                  SUS5      u  pe0 nSnUb(  U R                  U5      nUS:X  a	  US   US'   OUS   US'   Sn	Ub  U R                  U5      n	Sn
US:X  a!  U R	                  U R                  Xu5      5      n
O U R                  U R                  Xu5      5      n
U R                  U
S0 5      nUS:X  a  U R                  US	/ 5      OU R                  US
/ 5      nU R                  X5      nU R                  XX45      nU R                  XX45      $ )a  
fetch the interest owed by the user for borrowing currency for margin trading

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

:param str [code]: unified currency code
:param str [symbol]: unified market symbol, required for isolated margin
:param int [since]: the earliest time in ms to fetch borrrow interest for
:param int [limit]: the maximum number of structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated' default is 'cross'
:returns dict[]: a list of `borrow interest structures <https://docs.ccxt.com/#/?id=borrow-interest-structure>`
Nr_   r  r  r7   r}  rl  r  r~  r   )r  rn  r  rc  r  r  privateGetMarginAccountsr  rI  parse_borrow_interestsfilter_by_currency_since_limitfilter_by_symbol_since_limit)r  r  r  r&  r  r  r  r  r  rc  r  r  r~  rw  filteredByCurrencys                  r  fetch_borrow_interestkucoin.fetch_borrow_interest  sE    	
!??@UW]_fg
}}T*HZ'-5d^)*+3D>([[(F#66t{{77STH44T[[5QRHB ~~h38Bj8Ph3W[WeWefjlvxzW{..v>!@@QV^001CUZZr  r  c                 *   U R                  US5      nUc  SOSnU R                  X25      nU R                  US5      nU R                  US5      nU R                  US0 5      nS nS n	S n
US:X  a7  U R	                  US5      nU R	                  US5      n	U R                  US5      n
O6U R	                  US5      nU R	                  US	5      n	U R                  US5      n
UUU R                  U
5      U	U R	                  US
5      UUUU R                  U5      S.	$ )Nr  r  r  r  r  rv  rw  r  accruedInterestr  )	r  r  r  rw  interestRateamountBorrowedr  r   r  )r  r   r  r  rP  rN  r  )r  r  rc  r  r  r  r   isolatedBaser  rw  r  s              r  parse_borrow_interestkucoin.parse_borrow_interest  s3   Z ##D(3!)!1W

!!(3!!&(3%%dK8	~~dK<
#!--lKHN''jAH)),
CJ!--dK@N''.?@H))$
;J//
;  ,,T>B,$"Y/

 
	
r  c                 p   U R                  5         U R                  SU5      nU R                  USS5      nUS:H  nSU0nUb  X(S'   U R                  SX5      u  pUb  X8S'   U R	                  U R                  X5      5      n	U R                  U	S	5      n
U R                  U
S
/ 5      nU R                  XX#5      $ )aV  
retrieves a history of a multiple currencies borrow interest rate at specific time slots, returns all currencies if no symbols passed, default is None

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

:param str[]|None codes: list of unified currency codes, default is None
:param int [since]: timestamp in ms of the earliest borrowRate, default is None
:param int [limit]: max number of borrow rate prices to return, default is None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated' default is 'cross'
:param int [params.until]: the latest time in ms to fetch entries for
:returns dict: a dictionary of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` indexed by the market symbol
r`   r   r  r  
isIsolated	startTimeendTimer  r  r  )	r  rn  r  r  privateGetMarginInterestr  r  rI  parse_borrow_rate_histories)r  codesr&  r  r  r|  r  r  r  r  r  rowss               r  fetch_borrow_rate_histories"kucoin.fetch_borrow_rate_historiesN  s     	99:TV\]%%lAw?
 J.
*
 #(K 229gN"'J00W1MN* ~~h/~~dGR0//UJJr  c                    U R                  5         U R                  SU5      nU R                  USS5      nUS:H  nU R                  U5      nUUS   S.n	Ub  X)S'   U R	                  SX5      u  pUb  X9S	'   U R                  U R                  X5      5      n
U R                  U
S
5      nU R                  US/ 5      nU R                  XX#5      $ )a  
retrieves a history of a currencies borrow interest rate at specific time slots

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

:param str code: unified currency code
:param int [since]: timestamp for the earliest borrow rate
:param int [limit]: the maximum number of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>` to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.marginMode]: 'cross' or 'isolated' default is 'cross'
:param int [params.until]: the latest time in ms to fetch entries for
:returns dict[]: an array of `borrow rate structures <https://docs.ccxt.com/#/?id=borrow-rate-structure>`
r`   r   r  r  r7   )r  r  r  r  r  r  r  )
r  rn  r  r  r  r  r  r  rI  parse_borrow_rate_history)r  r  r&  r  r  r|  r  r  r  r  r  r  r   s                r  fetch_borrow_rate_history kucoin.fetch_borrow_rate_history  s     	99:TV\]%%lAw?
 J.
==&$ 
 #(K 229gN"'J00W1MN* ~~h/~~dGR0--d%GGr  c                    0 n[        S[        U5      5       Hr  nX   nU R                  U R                  US5      5      nUb  U R	                  X5      (       d  MC  X;  a  / XX'   U R                  U5      n	XX   n
U
R                  U	5        Mt     [        UR                  5       5      n[        S[        U5      5       H  nX   nU R                  XX   XU5      XX'   M      U$ )Nr   r  )
rK  rL  rN  r  r  r  rA  rj  r  r  )r  r  r  r&  r  borrowRateHistoriesrb  r  r  borrowRateStructureborrowRateHistoriesCoder  s               r  r  "kucoin.parse_borrow_rate_histories  s     %'q#h-(A;D**4+;+;D*+MND}d : :302'-&*&<&<T&B#*=*C''../BC ) ',,./q#d)$A7D(,(K(KL_Legkty(z% % #"r  c                     U R                  5         U R                  U5      nUS   U R                  X5      SS.nU R                  U R	                  XS5      5      nU R                  US0 5      nU R                  Xt5      $ )a  
create a loan to borrow margin

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

:param str code: unified currency code of the currency to borrow
:param float amount: the amount to borrow
:param dict [params]: extra parameters specific to the exchange API endpoints
:param str [params.timeInForce]: either IOC or FOK
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
r7   r  )r  r  r  r  )r  r  r9  privatePostMarginBorrowr  r  parse_margin_loanr  r  r.  r  r  r  r  r  s           r  borrow_cross_marginkucoin.borrow_cross_margin  s}     	==& ..t< 

 //G0LM ~~h3%%d55r  c                 (   U R                  5         U R                  U5      nU R                  U5      nUS   U R                  X#5      US   SSS.nU R	                  U R                  Xt5      5      nU R                  US0 5      n	U R                  X5      $ )a  
create a loan to borrow margin

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

:param str symbol: unified market symbol, required for isolated margin
:param str code: unified currency code of the currency to borrow
:param float amount: the amount to borrow
:param dict [params]: extra parameters specific to the exchange API endpoints
:param str [params.timeInForce]: either IOC or FOK
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
r7   r  T)r  r  r  r  r  r  )r  rc  r  r9  r  r  r  r  
r  r  r  r.  r  rc  r  r  r  r  s
             r  borrow_isolated_marginkucoin.borrow_isolated_margin  s     	V$==& ..t<Tl 
 //G0LM ~~h3%%d55r  c                     U R                  5         U R                  U5      nUS   U R                  X5      S.nU R                  U R	                  XS5      5      nU R                  US0 5      nU R                  Xt5      $ )a_  
repay borrowed margin and interest

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

:param str code: unified currency code of the currency to repay
:param float amount: the amount to repay
:param dict [params]: extra parameters specific to the exchange API endpoints
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
r7   )r  r  r  )r  r  r9  privatePostMarginRepayr  r  r  r  s           r  repay_cross_marginkucoin.repay_cross_margin  sz     	==& ..t<
 ..t{{7/KL ~~h3%%d55r  c                 &   U R                  5         U R                  U5      nU R                  U5      nUS   U R                  X#5      US   SS.nU R	                  U R                  Xt5      5      nU R                  US0 5      n	U R                  X5      $ )a  
repay borrowed margin and interest

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

:param str symbol: unified market symbol
:param str code: unified currency code of the currency to repay
:param float amount: the amount to repay
:param dict [params]: extra parameters specific to the exchange API endpoints
:returns dict: a `margin loan structure <https://docs.ccxt.com/#/?id=margin-loan-structure>`
r7   T)r  r  r  r  r  )r  rc  r  r9  r  r  r  r  r  s
             r  repay_isolated_marginkucoin.repay_isolated_margin<  s     	V$==& ..t<Tl	
 ..t{{7/KL ~~h3%%d55r  c                     U R                  5       nU R                  US5      nU R                  US5      U R                  XB5      U R                  US5      S UU R	                  U5      US.$ )Nr  orderNo
actualSize)r7   r  r.  r  r   r  r  )r  r  rN  rP  r  )r  r  r  r   r  s        r  r  kucoin.parse_margin_loana  sq     %%'	%%dJ7
""43//
E&&t\:"Y/
 	
r  r  c                     U R                  5         U R                  U5      nU R                  US/ 5      nU R                  XAS5      $ )aj  
fetch deposit and withdraw fees - *IMPORTANT* use fetchDepositWithdrawFee to get more in-depth info

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

:param str[]|None codes: list of unified currency codes
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a list of `fee structures <https://docs.ccxt.com/#/?id=fee-structure>`
r  r  )r  r  rI  parse_deposit_withdraw_fees)r  r  r  r  r  s        r  fetch_deposit_withdraw_fees"kucoin.fetch_deposit_withdraw_feest  sG     	++F3& ~~h3//ZHHr  r  c                    U R                  5         SnSnU R                  SSU5      u  pSUc  US:w  a3  U R                  U5      nUS   (       a  [        U R                  S-   5      eSnU R                  SU5      u  pcUc  [        U R                  S-   5      e0 nUS:X  a  Uc  [        U R                  S-   5      eUb  US	   US
'   [        U5      US'   US:H  US'   U R                  U R                  Xs5      5      $ )a  
set the level of leverage for a market

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

:param int [leverage]: New leverage multiplier. Must be greater than 1 and up to two decimal places, and cannot be less than the user's current debt leverage or greater than the system's maximum leverage
:param str [symbol]: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
Nr   rF   r  z0 setLeverage currently supports only spot marginz, setLeverage requires a marginMode parameterr  z< setLeverage requires a symbol parameter for isolated marginr7   r  r  r  )
r  r	  rc  r+   r7   rn  r$   str%privatePostPositionUpdateUserLeverager  )r  r  r  r  rc  
marketTyper  r  s           r  set_leveragekucoin.set_leverage  s    	
!??tU[\
:#7[[(Fj!"477-_#_``
!??vV
#DGG.\$\]]##DGG.l$lmm &tGH!(m
!+z!999$++g:VWWr  c                     U R                  5         U R                  U5      nSUS   0nU R                  U R                  XB5      5      nU R	                  US0 5      nU R                  Xc5      $ )a8  
fetch the current funding rate

https://www.kucoin.com/docs-new/rest/ua/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  r7   r  )r  rc  utaGetMarketFundingRater  r  parse_funding_rater  s          r  fetch_funding_ratekucoin.fetch_funding_rate  sn     	V$fTl
 //G0LM ~~h3&&t44r  c                    U R                  US5      nU R                  US5      n0 SU_SU R                  XBS S5      _SS _SS _SS _SS _S	S _S
S _SU R                  US5      _SU_SU R	                  U5      _SS _SS _SS _SS _SS _SS _SS 0E$ )NfundingTimer  r  r  r  
indexPricer  estimatedSettlePricer   r  fundingRatenextFundingRatefundingTimestampfundingDatetimenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimer-  )r  r  r  rP  r  )r  r  rc  r6  r  s        r  r-  kucoin.parse_funding_rate  s/     ,,T=A##D(3
D
d&&xzJ
 
 $	

 D
 #D
 
 
 4++D2CD
  0
 t||,<=
 t
 #D
 "4
 "4
  '!
" &t#
$ %
 	
r  c                    Uc  [        U R                  S-   5      eUc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nU R	                  US5      nU R                  US5      nUb  X&S'   Uc  U R                  5       US'   Ub  XvS'   U R                  U R                  Xd5      5      nU R                  US0 5      n	U R                  U	S	/ 5      n
U R                  XX#5      $ )
ac  
fetches historical funding rate prices

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
:returns dict[]: a list of `funding rate structures <https://docs.ccxt.com/#/?id=funding-rate-history-structure>`
z5 fetchFundingRateHistory() requires a symbol argumentz4 fetchFundingRateHistory() requires a since argumentr  r7   r  r*  r,  r  rj  )r$   r7   r  rc  r  r  r  utaGetMarketFundingRateHistoryr  r  rI  parse_funding_rate_histories)r  r  r&  r  r  rc  r  r  r  r  ra  s              r  fetch_funding_rate_history!kucoin.fetch_funding_rate_history  s    >#DGG.e$eff=#DGG.d$deeV$fTl
 !!&'267+!&I}#'#4#4#6 $G66t{{77ST ~~h3fb100NNr  c                     U R                  US5      nUU R                  S U5      U R                  US5      UU R                  U5      S.$ )Nr  r4  )r  r  r4  r   r  )r  r  rP  r  )r  r  rc  r   s       r  parse_funding_rate_history!kucoin.parse_funding_rate_history&  sR     %%dD1	&&tV4++D-@"Y/
 	
r  r   r  c                    U R                  U R                  S0 5      nU R                  Xr0 5      nU R                  X0 5      n	U R                  XU R                  S   5      n
U R                  USU
5      nU R                  US5      nSU-   S-   U R	                  X5      -   nUS:X  a  SU R	                  X5      -   nUS:X  a  SU R	                  X5      -   nSnUS	:X  a  S
U R	                  X5      -   nUS:X  a  SnU R                  X@R                  U5      5      nSnUb  UO0 nU R                  S   U   nU R                  U5      (       dB  US:X  d  US:X  a  US:w  a  USU R                  U5      -   -  nOU R                  U5      nUnSUS'   UU-   nUS:H  nUS:H  nUS:H  nUS:H  nU(       d  U(       d  U(       d  U(       d  U(       Ga  U R                  5         [        U R                  5       5      nU R                  SU R                  US.U5      nU R                  US5      nUS:X  aZ  U R                  U R!                  U R"                  5      U R!                  U R$                  5      [&        R(                  S5      nUUS'   OU R"                  US'   UU-   U-   U-   nU R                  U R!                  U5      U R!                  U R$                  5      [&        R(                  S5      nUUS'   U R                  U R                  S0 5      nU(       a  U R+                  USU5      OU R+                  US U5      nU R                  US!5      nU R-                  US"S#5      nUbd  Uba  UU-   U R                  -   nU R                  U R!                  U5      U R!                  U5      [&        R(                  S5      nUUS$'   UUS%'   S&US''   U(       a  U R                  US(5      nUb  UUS)'   UX6US*.$ )+Nr  r>   z/api/r"  r   r   z/api/v1/Fr   z/api/ua/v1/r   TrG  r   r  r  zorders/multi-cancel?zapplication/jsonzContent-Typer   r   r   2)KC-API-KEY-VERSIONz
KC-API-KEYzKC-API-TIMESTAMPrI  base64zKC-API-PASSPHRASEzKC-API-SIGNr  rI   rF   r7   r   r  zKC-API-PARTNER-SIGNzKC-API-PARTNERr  zKC-API-PARTNER-VERIFYr8   zKC-BROKER-NAME)r  r  bodyheaders)r  r  r  r  implode_paramsextract_paramsr   is_empty	rawencoder  rC  r&  r  r  r   hmacencoder   r   hashlibsha256rB  r  ) r  r  r   r  r  rL  rK  r  r  r  r  r>   endpointisUtaPrivater  endpartr  isFuturePrivate	isPrivateisBrokerisEarnr   apiKeyVersion
passphrasepayload	signaturer  	partnerIdpartnerSecretpartnerPayloadpartnerSignature
brokerNames                                    r  signkucoin.sign6  s    >>$,,
B?nnXB7R@)).Y@WX""69nE69-W$s*T-@-@-NN-T00>>H&=!D$7$7$EEH%<$t':':4'HHH))#		&"5"5d";<%1'iis#}}U##5f&8H]@]C$.."777yy'*<'Hn"22I%	8O-8v++-DJJL)Ikk&)"kk$-# 	G
 !,,W6JKM#!YYt{{4=='A4;;t{{C[]d]k]kmuv
/9+,/3}}+,&(83g=G		$++g"6DKK8PRYR`R`bjkI%.GM"nnT\\9bAGETdoogxAZ^ZiZijqsy  |C  [DG(($7I ..w%HM%M,E!*Y!6!D#'99T[[-H$++VcJdfmftftv~# 1A-.,5()39/0!--gv>
)0:G,-fwOOr  reasonr  r  rL  rK  c
                    U(       d   U R                  U R                  S   Xf5        g U R                  US5      n
U R                  USSS5      nU R                  S-   U-   nU R                  U R                  S   X5        U R                  U R                  S   X5        U R                  U R                  S   Xl5        U
S:w  a  U
S	:w  a  [        U5      eg )
Nrw  r  msgr  rG   rv  200000r{  )throw_broadly_matched_exceptionr  r  r  r7   throw_exactly_matched_exceptionr    )r  r  rg  r  r  rL  rK  r  requestHeadersrequestBody	errorCodemessagefeedbacks                r  handle_errorskucoin.handle_errors}  s    001I4V $$Xv6	$$XufbA77S=4',,T__W-EwY,,T__W-Ey[,,T__W-EtV Y%%7))r   )F)N)v__name__
__module____qualname____firstlineno__r   r  r  r   r  r  r   r   rg  r@  boolrH  r  r
   r  r   r  r&  r  r  r   r  r  dictr   r  r   r   r  r  r  r  rj  r#  r9  r   r>  rC  r=  rS  r   ra  rh  r   r   r8  r   r  r  r  r  r   r  r  ro  r  r   r  r  r  r   r  r  r  rx  r  r  r   r  r*  r   r/  r   r   rG  r;  rf  rk  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#  r1  r)  r   r.  r-  rA  rD  re  rs  __static_attributes____classcell__)r  s   @r  r3   r3   !   sv	   |# ||!D !# 3s 3& #% 4
l $& B$v, BH (* ld6l l\4  +- 
 ') fZ fP %' 04= 0d 79 
# 
: <> (?s (?TC CJP"k4 k k6 kZ 04B fGW fG7 fGP 48 ( (w (  02 T13 T1f T1l 46 /s /& /(
 
4 
* 9=4^bkm TJ# TJ# TJS TJX[ TJrvw{r| TJl 8: %:3 %:n %:N 79  :#  :^  :D
h 
R` 
& DF &0s &0$~J^ &0P :>b cs c3 cY cJ> gksu X.3 X.i X.y X.RW X.`c X.t _a _C _y _PU _$ RT O O5 O SU P PE P @B R'D$6 R'hs  os{} 7,3 7,i 7,y 7,Z_ 7,hk 7,r `drv  @B (.S (.# (.Y (.i (.Y\ (.lo (.T 37r qs qC qf /32 '5 '5R <@daenp n?S n? n?[^ n?` 154VZce Q# QS QPS Qjnotju Q: /3TXac S S3 Sc Shlmrhs S> 26b <6c <63 <6|k kv k kZ 9=4^bkm XS X# XS XX[ X& -1tRV_a f?c f? f?C f?P 6:UW K?3 K?s K?# K?\`af\g K?ZF Fv F FP 57 &
 &
;N &
P KOWY 16S 16% 16# 16C 16^i 16f:s :f
T f
X f
Q\ f
P *.Dt\^ M[3 M[c M[ M[cghsct M[^ -1tRV_a N^c N^ N^C N^fjkvfw N^` $& f( fP [] U7S U7% U7c U7c U7an U7n5
t 5
x 5
= 5
n:C :C :*3XMt Mx M; M^ (,$TZ\ \@ \@C \@s \@aefqar \@| MO 2
 
< 15DW[jnwy f[# f[c f[QT f[dg f[  C  DR  S f[PH
$ H
 H
. H
T 154VZce 1KS 1KPS 1Kf AESW`b 3Hc 3H# 3HS 3Hj#6 DF !6 !6U !6F TV %6S %6 %6U %6N <> 6s 6B LN #6C #6s #6J
 
& <@ I IB 9=R XS X# X@ 68 5 5K 5>
v 
 
B 8<$]ajl /O /OC /OWZ /Ob
v 
  &eBSW EPN# s  c TX `c  r  r3   ):ccxt.base.exchanger   ccxt.abstract.kucoinr   rS  r2  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   typingr   ccxt.base.errorsr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   ccxt.base.decimal_to_precisionr/   r0   ccxt.base.preciser1   r3   ru  r  r  <module>r     s    ( ,    h  h  h  h  h  h  h  * 0 - - . ' & . + ) * ) . 1 ) 3 4 %nUX{ nUr  