
    E#icE                    X   S SK Jr  S SKJ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!J-r-  S SK.J/r/  S SK0J1r1   " S S\\5      r2g)    )kucoin)ImplicitAPI)AnyBalancesCurrencyDepositAddressIntLeverageLeverageTier
MarginModeMarginModificationMarketNumOrder	OrderBookOrderRequest	OrderSide	OrderTypePositionStrStringsTickerTickersFundingRateTradeTradingFeeInterfaceTransactionTransferEntry)List)AuthenticationError)PermissionDenied)AccountSuspended)ArgumentsRequired)
BadRequest)InsufficientFunds)InvalidOrder)OrderNotFound)NotSupported)RateLimitExceeded)ExchangeNotAvailable)InvalidNonce)	TICK_SIZE)Precisec                   d  ^  \ rS rSrS\4U 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S0 4S	\S
\S\
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0 4S	\S\4S jjr0 4S	\S\4S jjrS0 4S\S\4S jjrS\S\S\S\4S 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0 4S	\4S jjrS0 4S\S\\    4S jjr!SSS0 4S\S\
S\
4S jjr"S\S\S\4S jjr#S0 4S	\S \$S!\%S"\&S#\'4
S$ jjr(0 4S%\\)   4S& jjr*S0 4S	\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-S0 4S	\4S, jjr.0 4S	\S"\&S\/4S- jjr0S\S\S\/4S. jjr1SSS0 4S	\S\
S\
4S/ jjr2SSS0 4S	\S\
S\
S\\3   4S0 jjr4SSS0 4S	\S\
S\
S\\3   4S1 jjr5S0 4S(\S	\4S2 jjr6S\S3\S\S\34S4 jjr70 4S	\S\84S5 jjr90 4S	\S\84S6 jjr:S\S\S\84S7 jjr;S8 r<S\=4S9 jr>0 4S\=4S: jjr?0 4S\S"\&S;\S<\S\@4
S= jjrAS\S>\S?\BS\@4S@ jjrCSA\S\4SB jrDSC\S\4SD jrESSS0 4S	\S\
S\
4SE jjrFSS0 4S	\S\
S\
S\\G   4SF jjrHS\SG\S\S\G4SH jjrISSS0 4S\S\
S\
S\\J   4SI jjrKSSS0 4S\S\
S\
S\\J   4SJ jjrL0 4S	\S\\M   4SK jjrNS\S\S\\M   4SL jjrOSSS0 4S	\S\
S\
4SM jjrPS\S\4SN jjrQS0 4S	\S!\%S\34SO jjrR0 4S	\S\S4SP jjrT0 4S	\S\U4SQ jjrVS\SR\S\U4SS jjrWS0 4SR\S	\4ST jjrXS0 4SU\YS	\4SV jjrZ0 4S	\S\[4SW jjr\S0 4SX\]S	\4SY jjr^S\SX\S\S\[4SZ jjr_S[r`U =ra$ )]kucoinfutures   returnc                   > 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SSSSSSSSSSSSS SW.E_SXSYSZS[/S\S]S^S^S_S_S`Sa.Sb._ScSSSSd._Se0 SfSg_ShSg_SiSg_SjSg_SkSg_SlSm_SnSg_SoSg_SpSg_SqSg_SrSg_SsSg_StSg_SuSg_SvSg_SwSg_SxSg_SgSgSy.ESzSg0S{.0 S|Sm_S}S~_SSg_SSg_SSg_SSg_SSg_SSm_SSg_SSg_SSg_SSg_SS~_SS~_SSg_SSg_SS~_S~SgSgSgSgSgSgSgS.ESgSgSgSmSmSmSgSgSgSgSgSgSgSgSgS.SgSgSgS~SgSgSgSS.S.SSSg00S._S[        _S0 S[
        _S[        _S[        _S[        _S[        _S[
        _S[        _S[        _S[        _S[        _S[
        _S[        _S[        _S[        _S[        _S[        _S[        _[        [        [        [        [        [        [        [        [
        [        [        [        [        S.ES[        0S._SSSU R!                  S5      U R!                  S5      U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      //U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      /U R!                  S5      U R!                  S5      //S.S.SS0 0 S.S._SSSSSSSS._SgS SSSSSSS SSSSS.S
SSS0 0 SSSS.SSSSS.S.SSqS00S.SSSS.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.SS0SSS SSS.SSSSS.SSSSSS.S SSS S S SSSS.SS0S.	SS0SS0S.SS0SS0S.S.S.E5      $ (   Nidr/   namezKuCoin Futures	countriesSC	rateLimitK   versionv1	certifiedTprocommentzPlatform 2.0quoteJsonNumbersFhasCORSspotmarginswapfutureoption	addMargincancelAllOrderscancelOrdercancelOrderscloseAllPositionsclosePositionclosePositionscreateDepositAddresscreateOrdercreateOrders$createOrderWithTakeProfitAndStopLosscreateReduceOnlyOrdercreateStopLimitOrdercreateStopLossOrdercreateStopMarketOrdercreateStopOrdercreateTakeProfitOrdercreateTriggerOrderfetchAccountsfetchBalancefetchBidsAsksfetchBorrowRateHistoriesfetchBorrowRateHistoryfetchClosedOrdersfetchCrossBorrowRatefetchCrossBorrowRatesfetchCurrenciesfetchDepositAddressfetchDepositAddressesfetchDepositAddressesByNetworkfetchDepositsfetchDepositWithdrawFeefetchDepositWithdrawFeesfetchFundingHistoryfetchFundingIntervalfetchFundingIntervalsfetchFundingRatefetchFundingRateHistoryfetchIndexOHLCVfetchIsolatedBorrowRatefetchIsolatedBorrowRatesfetchL3OrderBookfetchLedgerfetchLeveragefetchLeverageTiersfetchMarginAdjustmentHistoryfetchMarginModefetchMarketLeverageTiersfetchMarketsfetchMarkOHLCVfetchMarkPricefetchMyTrades
fetchOHLCVfetchOpenOrders
fetchOrderfetchOrderBookfetchPositionfetchPositionHistoryfetchPositionModefetchPositionsfetchPositionsHistoryfetchPremiumIndexOHLCV)fetchStatusfetchTickerfetchTickers	fetchTimefetchTradesfetchTradingFeefetchTransactionFeefetchWithdrawalssetLeveragesetMarginModesetPositionModetransferwithdrawurlszdhttps://user-images.githubusercontent.com/1294454/147508995-9e35030a-d046-43a1-a006-6fabd981b554.jpgzhttps://docs.kucoin.com/futureszhttps://docs.kucoin.comzhttps://futures.kucoin.com/z(https://futures.kucoin.com/?rcode=E5wkqezhttps://openapi-v2.kucoin.comzhttps://api-futures.kucoin.comz)https://futures.kucoin.com/_api/web-front)publicprivatefuturesPrivatefuturesPublicwebExchange)logodocwwwreferralapirequiredCredentials)apiKeysecretpasswordr   zcontracts/active   zcontracts/{symbol}zcontracts/risk-limit/{symbol}ticker
allTickerszlevel2/snapshotgHzG?zlevel2/depth{limit}zlevel2/message/queryzlevel3/message/queryzlevel3/snapshotztrade/historyzinterest/queryzindex/queryzmark-price/{symbol}/currentzpremium/queryzfunding-rate/{symbol}/current	timestamp)statuszkline/queryzbullet-public)getpostzaccount-overviewztransaction-historyg(\@zdeposit-addresszdeposit-listzwithdrawals/quotaszwithdrawal-listztransfer-listorders
stopOrdersrecentDoneOrdersorders/{orderId}zorders/byClientOidfillsrecentFillsopenOrderStatisticsposition	positions)zfunding-historysub/api-keyztrade-statisticsz
trade-feeszhistory-positionsgetMaxOpenSizegetCrossUserLeverageposition/getMarginMode)withdrawalstransfer-outztransfer-inr   z	st-orderszorders/testz#position/margin/auto-deposit-statuszposition/margin/deposit-marginz position/risk-limit-level/changezbullet-privater   zsub/api-key/updatechangeCrossUserLeverageposition/changeMarginModeposition/switchPositionMode   )zwithdrawals/{withdrawalId}zcancel/transfer-outr   r   r   r   zorders/client-order/{clientOid}zorders/multi-cancel)r   r   deleter   zcontract/{symbol}/funding-rates)r   r   r   precisionMode
exceptions400401403404405415429500503100001100004101030200004230003260100300003300012)400001400002400003400004400005400006400007404000400100411100500000300009330008zPosition does not exist)exactbroadfeesz0.0006z0.0002050200z0.00051000z0.000420004000z0.000388000z0.0003515000z0.0003225000z0.0003400006000080000z0.02z0.015z0.01z-0.003z-0.006z-0.009z-0.012z-0.015)takermaker)	tierBased
percentager   r   tiers)r   r   r   deposit)tradingfundingcommonCurrenciesHOTNOWDADIWAXPTriasVAIOTBTC)HOTEDGEWAXTRYVAIXBT         <   x      i  i  i  i`'  )1m3m5m15m30m1h2h4h6h8h12h1d1w-USDTv2)r   r   r   )r   r   r   r   )GETPOSTr  )r   r   omniethtrx)OMNIERC20TRC20)r9   symbolSeparatordefaultTypecodemarginModesmarginTypesversionsnetworks)lastmarkindex)triggerPriceTypeprice)IOCFOKPOGTD)
marginModetriggerPricer'  triggerDirectionstopLossPricetakeProfitPriceattachedStopLossTakeProfittimeInForcehedgedtrailingleveragemarketBuyByCostmarketBuyRequiresPriceselfTradePreventionicebergmax     )r-  limitdaysBack	untilDayssymbolRequired)r-  triggerr5  rA  )r-  r>  rB  r5  rA  )r-  r>  r?  daysBackCanceledr@  rB  r5  rA  r>  i  )	sandboxrN   rO   ry   r|   r{   fetchOrdersr]   rz   extends	forDerivs)linearinverse)rA   rG  rC   rD   )
timeframesoptionsfeatures)deep_extendsuperr/   describer,   r$   r    r(   r)   r*   r'   r!   r%   r&   r+   r"   parse_number)self	__class__s    L/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/kucoinfutures.pyrO  kucoinfutures.describe   s   mT C E tH
/tH
$tH
 $tH
 	tH

 ttH
 tH
 4tH
 ~tH
 tH
  RRR %R 	R
 $R %R TR "4R tR R $UR  R !%R 'R tR  !R" 7#R$ (%R& ''R( &t)R* (+R, "4-R. (/R0 %d1R2  3R4 5R6  7R8 +E9R: )%;R< $T=R> '?R@ (ARB "5CRD &tERF (GRH 1%IRJ  KRL *5MRN +EORP &tQRR 'SRT (URV #DWRX *4YRZ "5[R\ *5]R^ +E_R` #DaRb tcRd  eRf %egRh /iRj "4kRl +DmRn oRp !%qRr !$sRt  uRv dwRx "4yRz d{R| !$}R~  R@ 'ARB $UCRD !$ERF (GRH )%IRJ  $# $!##'',$($!%#'  cRtH
z ~5- 5F=>&F%E#N{tH
Z " $[tH
d *A,a 8 !!	
 %a *4 .q / / *1 ( )! &q 6q (  8!" $Q#$ #$'(', (-"6*D-t *1 '	
 -a *1 ( !$ %a +A +A -a   &t .q  #A!" $T#$ ,0'(,-&'-.*+012338 ()()'("&%)'+?@:;<=*+'(./345678$ 78/0,-"&&''(;</1	[7#r 91 gXetH
V YWtH
X :. < <	
 < : , / / m j . / / /  /!" l#$ 2*11111*(.2*/=B .}C$YtH
b !%"&!..x8!..x8 "..s3T5F5Fx5PQ!..t4d6G6G6QR!..u5t7H7H7RS!..u5t7H7H7RS!..v68I8I(8ST!..v68I8I(8ST!..v68I8I)8TU!..v68I8I)8TU!..w79J9J99UV!..w79J9J89TU!..w79J9J89TU!..w79J9J89TU!..w79J9J89TU"  "..s3T5F5Fv5NO!..t4d6G6G6PQ!..u5t7H7H7PQ!..u5t7H7H7PQ!..v68I8I&8QR!..v68I8I#8NO!..v68I8I#8NO!..v68I8I#8NO!..w79J9J89TU!..w79J9J89TU!..w79J9J89TU!..w79J9J89TU!..w79J9J89TU"!%N "'"' "!	O-ctH
~ !tH
P	    #&%!!
 /3486:  -17;9=;?	!' -t &* #""9%N $&*(,$($(%)-
 -1)-+/04%)7
 $(#("&#(	( #($)$(+/27/3#'7$< r% '+!%$(%&*/& ',#($)*/	# ',!%#'$)*/( $(&+!%$(,0%)#'$)*/	*  #CDN "; "; 	 "; "; 	_Wy
tH
 t t	    c                     U R                  U5      nU R                  US0 5      nU R                  US5      nUS:X  a  SOSSSSUS.$ )aA  
the latest known information on the availability of the exchange API

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

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `status structure <https://docs.ccxt.com/#/?id=exchange-status-structure>`
datar   openokmaintenanceN)r   updatedetaurlinfo)futuresPublicGetStatus	safe_dictsafe_string)rQ  paramsresponserW  r   s        rS  fetch_statuskucoinfutures.fetch_status  s\     ..v6 ~~h3!!$1%/dm
 	
rU  c                 V   U R                  U5      n/ nU R                  US/ 5      n[        S[        U5      5       GH  nXE   nU R	                  US5      nU R                  US5      nU R	                  US5      SL n	U	(       + 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S
-   U-   S-   U-   nSnU	(       a  US-   U R                  US5      -   nS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S5      nUnUc  U R                  US5      nU R                  US5      nUc  U R                  US5      nU R                  US5      nUcJ  U R	                  US5      nU R	                  US5      nU R                  [        R                  " UU5      5      nUR                  0 SU_SU_SU_SU_SU_SU_SU_S U_S!U_S"S#_S$S#_SU
_SU	_S%S#_S&US':H  _S(S)_S*U(       + _UU R                  US+5      U R                  US,5      U R                  [        R                  " U5      5      UU R                  U5      SSUUS-.U R                  S.5      U R                  US/5      S0.UUS0.UUS0.U R                  US15      U R                  US5      S0.S2.U R                  US35      US4.E5        GM     U$ )5a  
retrieves data on all markets for kucoinfutures

https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbols-list

:param dict [params]: extra parameters specific to the exchange api endpoint
:returns dict[]: an array of objects representing market data
rW  r   symbol
expireDatenextFundingRateTimeNbaseCurrencyquoteCurrencysettleCurrency/:rC   r   rD   	isInverser   
multipliertickSizelotSizebaseMinSizemaxOrderQtybaseMaxSizemaxPricequoteMaxSizer3   basequotesettlebaseIdquoteIdsettleIdtyperA   FrB   rE   activeOpencontractTrH  takerFeeRatemakerFeeRate)amountr(  1maxLeverage)minr;  quoteMinSize)r6  r  r(  costfirstOpenDate)rI  r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedr^  )futuresPublicGetContractsActive	safe_listrangelenra  safe_integersafe_currency_codeyymmdd
safe_valuesafe_numberrP  r-   
string_divappend
string_absiso8601)rQ  rb  rc  resultrW  imarketr3   r  rD   rC   r|  r}  r~  ry  rz  r{  rg  r  rI  r   rq  rr  rs  limitAmountMinlimitAmountMaxlimitPriceMaxbaseMinSizeStringquoteMaxSizeStrings                                rS  fetch_marketskucoinfutures.fetch_markets  s    77?~ ~~h3q#d)$AWF!!&(3B&&v|<F%%f.CDLF:D%%fn=F&&v?G''0@AH**62D++G4E,,X6FCZ%'#-6FD#FB(??oofk:G%%fh7F))&,?J''
;H&&vy9G$N%!%!1!1&-!H!--fmDN%!%!1!1&-!H ,,VZ@M$$($4$4V]$K!%)%5%5fn%M" $ 1 1'2D2DEWYj2k lMM 2b2&2 2 	2
 &2 &2 72 H2 2 2 %2 2 &2 %2 6V+2  D!2" g+#2$ #))&.A))&.A $ 1 1'2D2DZ2P Q "&,,v"6"%%  $005#//F!
  .-
  (,
  $//G#//G$  ,,V_Ec2 2C %h rU  c                 H    U R                  U5      nU R                  US5      $ )aA  
fetches the current integer timestamp in milliseconds from the exchange server

https://www.kucoin.com/docs/rest/futures-trading/market-data/get-server-time

:param dict [params]: extra parameters specific to the exchange API endpoint
:returns int: the current integer timestamp in milliseconds from the exchange server
rW  )futuresPublicGetTimestampr  )rQ  rb  rc  s      rS  
fetch_timekucoinfutures.fetch_time  s)     11&9   622rU  r  Nrg  	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U R	                  U R
                  U5      n	SU0n
U	b  XS'   OX*S'   U R                  U5      S-  nU R                  5       nUb9  X:S	'   Uc  U R	                  U R                  S
S5      nU R                  X4U-  5      nOUb  XU-  -
  nX:S	'   XS'   U R                  U R                  X5      5      nU R                  US/ 5      nU R                  XX#U5      $ )aE  
fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

https://www.kucoin.com/docs/rest/futures-trading/market-data/get-klines

:param str symbol: unified symbol of the market to fetch OHLCV data for
:param str timeframe: the length of time each candle represents
:param int [since]: timestamp in ms of the earliest candle to fetch
:param int [limit]: the maximum amount of candles to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
: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
Frz   paginate   r3   rg  granularityr<  fromfetchOHLCVLimittorW  )load_marketshandle_option_and_params"fetch_paginated_call_deterministicr  r  rJ  parse_timeframemillisecondsrK  sumfuturesPublicGetKlineQueryextendr  parse_ohlcvs)rQ  rg  r  r  r>  rb  r  r  marketIdparsedTimeframerequestdurationendAtrc  rW  s                  rS  fetch_ohlcvkucoinfutures.fetch_ohlcv  s`    	88zZ::<X]jpruvvV$$<++DOOYGh
 &%4M"%.M"''	2T9!!##FO}))$,,8I3OHHUH$45EH,,E#FO224;;w3OP ~~h3  yGGrU  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  )rQ  ohlcvr  s      rS  parse_ohlcvkucoinfutures.parse_ohlcv  sn     eQ'UA&UA&UA&UA&UA&
 	
rU  r  c                 ^   U R                  5         U R                  U5      nUS   nSU0nU R                  U R                  XR5      5      nU R	                  US0 5      nU R                  US5      nUS:w  a  U R                  U5        UUU R                  US5      UU R                  US5      S.$ )	aX  
fetch the deposit address for a currency associated with self account

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

:param str code: unified currency code
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
r3   currencyrW  addressNIMchainmemo)r^  r  networkr  tag)r  r  futuresPrivateGetDepositAddressr  r`  ra  check_address)	rQ  r  rb  r  
currencyIdr  rc  rW  r  s	            rS  fetch_deposit_address#kucoinfutures.fetch_deposit_address  s     	==&d^


 77G8TU ~~h3""43w'"''g6##D&1
 	
rU  c           	      (   U R                  5         U R                  US5      nUS:w  a  Ub  [        U R                  S-   5      eU R	                  U5      nSUS   0nUb)  US:X  d  US:X  a  X&S'   O[        U R                  S	-   5      eSUS'   U R                  U R                  Xc5      5      nU R                  US
0 5      nU R                  U R                  US5      S-  5      n	U R                  XS   U	SSS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/futures-trading/market-data/get-part-order-book-level-2

:param str symbol: unified symbol of the market to fetch the order book for
:param int [limit]: the maximum amount of order book entries to return
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
levelr  z) fetchOrderBook() can only return level 2rg  r3   r   d   r>  z2 fetchOrderBook() limit argument must be 20 or 100rW  ts@B bidsasksr   r   sequencenonce)r  r  r$   r3   r   futuresPublicGetLevel2DepthLimitr  r`  parse_to_intr  parse_order_book)rQ  rg  r>  rb  r  r  r  rc  rW  r   	orderbooks              rS  fetch_order_bookkucoinfutures.fetch_order_book  s+    	  1A:%+TWW'RRSSV$fTl
 ##(  +_!_``!GG88W9UV& ~~h3%%d&7&7d&Cg&MN	))$x0@)VU[]^`ab	!..tZ@	'rU  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   U5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://www.kucoin.com/docs/rest/futures-trading/market-data/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
:returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
rg  r3   rW  )r  r  futuresPublicGetTickerr  parse_tickerrQ  rg  rb  r  r  rc  s         rS  fetch_tickerkucoinfutures.fetch_tickerG  sc     	V$fTl
 ..t{{7/KL&   &!16::rU  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   U5      $ )a  
fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

https://www.kucoin.com/docs/rest/futures-trading/market-data/get-current-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>`
rg  r3   rW  )r  r  &futuresPublicGetMarkPriceSymbolCurrentr  r  r  s         rS  fetch_mark_pricekucoinfutures.fetch_mark_pricek  sa     	V$fTl
 >>t{{7?[\  &!16::rU  symbolsc                 6   U R                  5         U R                  U5      nSnU R                  USSS5      u  p2SnUS:X  a  U R                  U5      nOU R	                  U5      nU R                  US5      nU R                  XQ5      nU R                  USU5      $ )ac  
fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

https://www.kucoin.com/docs/rest/futures-trading/market-data/get-symbols-list

:param str[] [symbols]: unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.method]: the method to use, futuresPublicGetAllTickers or futuresPublicGetContractsActive
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
Nr   methodr  futuresPublicGetAllTickersrW  rg  )r  market_symbolsr  r  r  r  parse_tickersfilter_by_array_tickers)rQ  r  rb  r  rc  rW  tickerss          rS  fetch_tickerskucoinfutures.fetch_tickers~  s     	%%g.66v~xYz{1166v>H;;FCH~ ~~h/$$T3++GXwGGrU  r   c           
         U R                  US5      nU R                  X2S5      nU R                  USS5      nU R                  USS5      nU R	                  0 SUS   _SU_SU R                  U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S _SU_SU_SS _SU R                  US5      _SU R                  US5      _SS _U R                  US5      U R                  US 5      U R                  US!S"5      U R                  US#5      US$.EU5      $ )%Nrg  r  r(  lastTradePricer  gư>r   datetimehigh	highPricelowlowPricebidbestBidPrice	bidVolumebestBidSizeaskbestAskPrice	askVolumebestAskSizevwaprX  closer$  previousClosechangepriceChgr   priceChgPctaveragevolumeOf24hturnoverOf24h	markPricevalue
indexPrice)
baseVolumequoteVolumer  r  r^  )ra  safe_marketsafe_string_2safe_integer_productsafe_tickerr  )rQ  r   r  r  r$  r   s         rS  r  kucoinfutures.parse_ticker  s   n ##FH5!!(C8!!&'3CD--fdHE	 !
fX&!
!
 Y/!
 D$$V[9	!

 4##FJ7!
 4##FN;!
 ))&-@!
 4##FN;!
 ))&-@!
 D!
 D!
 T!
 D!
 T!
 d&&vz:!
  $**6=A!!
" t#!
$ **6=A++FOD++FKI**6<@-!
. / 	rU  c                 J    SS0nU R                  XR                  X25      5      $ )an  
fetches the bid and ask price and volume for multiple markets
:param str[] [symbols]: unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a dictionary of `ticker structures <https://docs.ccxt.com/#/?id=ticker-structure>`
r  r  )r  r  )rQ  r  rb  r  s       rS  fetch_bids_askskucoinfutures.fetch_bids_asksH  s-     2
 !!';;w+GHHrU  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nSUS   0nUb  X&S'   Ub  X6S'   U R	                  U R                  Xd5      5      nU R                  US5      nU R                  US/ 5      n	/ n
[        S[        U	5      5       H  nX   nU R                  US	5      nU
R                  UUU R                  U R                  US
5      5      UU R                  U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      U R                  US5      S.5        M     U
$ )a  
fetch the history of funding payments paid and received on self account

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

:param str symbol: unified market symbol
:param int [since]: the earliest time in ms to fetch funding history for
:param int [limit]: the maximum number of funding history structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding history structure <https://docs.ccxt.com/#/?id=funding-history-structure>`
z1 fetchFundingHistory() requires a symbol argumentrg  r3   startAtmaxCountrW  dataListr   	timePointrl  r   fundingRater  positionQtypositionCost)r^  rg  r  r   r  r3   r  r)  r  r*  r+  )r#   r3   r  r  futuresPrivateGetFundingHistoryr  r  r  r  r  r  r  r  ra  r  r  )rQ  rg  r  r>  rb  r  r  rc  rW  r'  r   r  listItemr   s                 rS  fetch_funding_history#kucoinfutures.fetch_funding_historyT  s    >#DGG.a$abbV$fTl
 !&I"'J77G8TU. x0>>$
B7q#h-(A{H))(K@IKK  //0@0@K[0\]& LL3&&x6**8Y?#//-H!--hD#//-H $ 0 0> J  )  rU  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      $ )aK  

https://docs.kucoin.com/futures/#get-position-details

fetch data on an open position
:param str symbol: unified market symbol of the market the position is held in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `position structure <https://docs.ccxt.com/#/?id=position-structure>`
rg  r3   rW  )r  r  futuresPrivateGetPositionr  r`  parse_positionrQ  rg  rb  r  r  rc  rW  s          rS  fetch_positionkucoinfutures.fetch_position  so     	V$fTl
 11$++g2NOZ ~~h3""400rU  c                     U R                  5         U R                  U5      nU R                  US5      nU R                  XA5      $ )a7  
fetch all open positions

https://docs.kucoin.com/futures/#get-position-list

:param str[]|None symbols: list of unified market symbols
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
rW  )r  futuresPrivateGetPositionsr  parse_positions)rQ  r  rb  rc  rW  s        rS  fetch_positionskucoinfutures.fetch_positions  sD     	226:^ ~~h/##D22rU  c                 D   U R                  5         Uc  SnSU0nUb  X%S'   U R                  US5      nUb  U R                  US5      nXeS'   U R                  U R	                  XT5      5      nU R                  US5      nU R                  US/ 5      n	U R                  X5      $ )a.  
fetches historical positions

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

:param str[] [symbols]: list of unified market symbols
:param int [since]: the earliest time in ms to fetch position history for
:param int [limit]: the maximum number of entries to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:param int [params.until]: closing end time
:param int [params.pageId]: page id
:returns dict[]: a list of `position structure <https://docs.ccxt.com/#/?id=position-structure>`
r  r>  r  untilr  rW  items)r  r  omit!futuresPrivateGetHistoryPositionsr  r`  r  r8  )
rQ  r  r  r>  rb  r  r<  rc  rW  r=  s
             rS  fetch_positions_history%kucoinfutures.fetch_positions_history  s     	=EU
 #FO!!&'2YYvw/F!DM99$++g:VWN ~~h/tWb1##E33rU  r   c                 ~   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nS nU R                  US5      nUb>  [        R
                  " US5      (       a  SnO<[        R                  " US5      (       a  SnOUb  UR                  S5      S:  a  SnOSn[        R                  " U R                  US	5      5      nU R                  US
5      n	[        R                  " X5      n
U R                  US5      nU R                  US5      nS nUb  U(       a  SOSnU R                  0 SU_SU R                  USS5      _SU R                  US5      _SU_SU R                  U5      _SU R                  US5      _SU R                  U	5      _SU R                  U
5      _SU R                  US5      _SU R                  US5      _SU R!                  USS5      _SU R                  U5      _S U R!                  US!S 5      _S"U R                  U5      _S#U R                  [        R                  " U5      5      _S$U R                  US$5      _S%U R!                  US&S'5      _S U R                  US(5      U R                  US)5      S U R                  US*5      UUS S S S+.
E5      $ ),Nrg  currentTimestamp
currentQtyr  r   longshortposCostposInitunrealisedPnl	crossModecrossisolatedr^  r3   
positionIdr   r  lastUpdateTimestamp	closeTimeinitialMargininitialMarginPercentagemaintenanceMarginposMaintmaintenanceMarginPercentagemaintMarginReq
entryPriceavgEntryPrice	openPricenotionalr6  realLeverageunrealizedPnl	contractsr  realizedPnlrealisedPnlpnlliquidationPricer  maintMargin)
marginRatiora  r  	lastPrice
collateralr-  sider   r0  r1  )ra  r  r  safe_string_lowerr-   	string_gt	string_ltfindr  r  r  safe_positionr  r  rP  r  safe_number_2)rQ  r   r  rg  r   sizerf  r  rZ  rQ  rR  rJ  rK  r-  s                 rS  r2  kucoinfutures.parse_positionY  s&   L !!(H5!!&1%%h0BC	,7%%h7  s++""4--yy 2%%%d&6&6x&KL((9=")"4"4]"M((?COOHk:	
 $-:J!! #
H#
$$$Xt\B#
 d&&vx8#
 	#

 Y/#
 "4#4#4X{#K#
 T..}=#
 &t'8'89P'Q#
  !1!1(J!G#
 *4+;+;HFV+W#
 $,,XT#
 ))(3#
 **8^ZP#
 T..}=#
 **7+=+=d+CD#
  DOOFNC!#
" 4--huM##
$   $ 0 0;M N))(K@**8]C$!#7#
  	rU  r  rf  r  r(  c                    U R                  5         U R                  U5      nU R                  USS5      nU R                  US5      nU R	                  US5      SL=(       d    U R	                  US5      SLn	U R                  XX4XV5      n
SnU(       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                  X5      $ )a  
       Create an order on the exchange

       https://www.kucoin.com/docs/rest/futures-trading/orders/place-order
       https://www.kucoin.com/docs/rest/futures-trading/orders/place-take-profit-and-stop-loss-order#http-request

       :param str symbol: Unified CCXT market symbol
       :param str type: 'limit' or 'market'
       :param str side: 'buy' or 'sell'
       :param float amount: the amount of currency to trade
       :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
       :param dict [params]:  extra parameters specific to the exchange API endpoint
       :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered and the triggerPriceType
       :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered and the triggerPriceType
       :param float [params.triggerPrice]: The price a trigger order is triggered at
       :param float [params.stopLossPrice]: price to trigger stop-loss orders
       :param float [params.takeProfitPrice]: price to trigger take-profit orders
       :param bool [params.reduceOnly]: A mark to reduce the position size only. Set to False by default. Need to set the position size when reduceOnly is True.
       :param str [params.timeInForce]: GTC, GTT, IOC, or FOK, default is GTC, limit orders only
       :param str [params.postOnly]: Post only flag, invalid when timeInForce is IOC or FOK
       :param float [params.cost]: the cost of the order in units of USDT
       :param str [params.marginMode]: 'cross' or 'isolated', default is 'isolated'
       :param bool [params.hedged]: *swap and future only* True for hedged mode, False for one way mode, default is False
----------------- Exchange Specific Parameters -----------------
       :param float [params.leverage]: Leverage size of the order(mandatory param in request, default is 1)
       :param str [params.clientOid]: client order id, defaults to uuid if not passed
       :param str [params.remark]: remark for the order, length cannot exceed 100 utf8 characters
       :param str [params.stop]: 'up' or 'down', the direction the triggerPrice is triggered from, requires triggerPrice. down: Triggers when the price reaches or goes below the triggerPrice. up: Triggers when the price reaches or goes above the triggerPrice.
       :param str [params.triggerPriceType]: "last", "mark", "index" - defaults to "mark"
       :param str [params.stopPriceType]: exchange-specific alternative for triggerPriceType: TP, IP or MP
       :param bool [params.closeOrder]: set to True to close position
       :param bool [params.test]: set to True to use the test order endpoint(does not submit order, use to validate params)
       :param bool [params.forceHold]: A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to False by default.        :param str [params.positionSide]: *swap and future only* hedged two-way position side, LONG or SHORT
       :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
       testFstopLossN
takeProfitrW  )r  r  	safe_boolr>  r  create_contract_order_requestfuturesPrivatePostOrdersTestfuturesPrivatePostStOrdersfuturesPrivatePostOrdersr`  parse_order)rQ  rg  r  rf  r  r(  rb  r  	testOrderisTpAndSlOrderorderRequestrc  rW  s                rS  create_orderkucoinfutures.create_order  s    J 	V$NN6659	66*//&*=TI  Bt_egsOt  }A  PA99&V[d88FH::<H88F ~~h3--rU  r   c           	         U R                  5         / n[        S[        U5      5       H  nX   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S5      n
U R                  US5      nU R                  US0 5      nU R                  US   XXU5      nUR                  U5        M     U R                  U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/futures-trading/orders/place-multiple-orders

:param Array orders: list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
:param dict [params]:  extra parameters specific to the exchange API endpoint
:returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r   rg  r  rf  r  r(  rb  r3   rW  )r  r  r  ra  r  r  rt  r  futuresPrivatePostOrdersMultir  parse_orders)rQ  r   rb  ordersRequestsr  rawOrderrg  r  r  rf  r  r(  orderParamsr{  rc  rW  s                   rS  create_orderskucoinfutures.create_orders  s    	q#f+&AyH%%h9F[[(F##Hf5D##Hf5D__Xx8FOOHg6E//(HbAK==fTlDX^grsL!!,/ ' 55nE, ~~h3  &&rU  c                 n   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S.n	U R	                  US5      n
U
b  U R                  US5      nXS'   U R                  US5      nU R                  US5      nUb  U R                  X5      U	S'   O;US:  a  [        U R                  S	-   5      e[        U R                  X5      5      U	S
'   U R                  U5      u  pnU R                  US5      nU R                  US5      nSSSS.nU R                  USS5      nU R                  UUU5      nU R                  U/ SQ5      nU(       a(  US:X  a  SOSU	S'   U R                  X5      U	S'   UU	S'   GOUc  Ub  UnUbN  U R                  USS5      nU R                  UU5      U	S'   U R                  USS5      nU R                  UUU5      nUbN  U R                  USS5      nU R                  UU5      U	S'   U R                  USS5      nU R                  UUU5      nUU	S'   ObU(       d  U(       aT  U(       a"  US:X  a  SOSU	S'   U R                  X5      U	S'   O!US:X  a  SOSU	S'   U R                  X5      U	S'   SU	S'   UU	S'   UR                  5       nU R	                  US 5      nUS!:X  a7  Uc  [        U R                  S"-   5      eU R                  X5      U	S#'   Ub  UU	S '   S nU R!                  US$:H  S%U5      u  nnU(       a  SU	S&'   U R#                  US'5      nU(       a  Ub  [%        U R                  S(-   5      eU R#                  US)5      nU(       a-  U R#                  US*5      nUc  [        U R                  S+-   5      eU R'                  USS%5      nS nU R)                  US,S%5      u  nnU(       a  UU	S'   U(       a  US-:X  a  S.OS/nUU	S0'   OU(       a  US:X  a  S.OS/n U U	S0'   U R                  U/ S1Q5      nU R+                  X5      $ )2N	clientOidclientOrderIdr3   r   )r  rf  rg  r  r6  r-  r  valueQtyz1 createOrder() minimum contract order amount is 1rm  rq  rr  MPTPIP)r%  r$  r&  r'  r%  )r0  r1  r.  	stopPricerr  rq  buyupdownstopr  stopPriceTyper.  triggerStopDownPricer1  triggerStopUpPriceT
reduceOnlyr3  LIMITz9 createOrder() requires a price argument for limit ordersr(  r  FpostOnlyhiddenzW createOrder() does not support the postOnly parameter together with a hidden parameterr:  visibleSizezB createOrder() requires a visibleSize parameter for iceberg ordersr4  sellLONGSHORTpositionSide)r3  r  r.  r0  r1  r  r4  )r  r  uuidr>  safe_string_upperra  cost_to_precisionr&   r3   intamount_to_precisionhandle_trigger_pricesr`  price_to_precisionupperr#   handle_post_onlyr  r$   rs  handle_param_boolr  )!rQ  rg  r  rf  r  r(  rb  r  r  r  marginModeUpperr  r.  r0  r1  rq  rr  triggerPriceTypesr'  triggerPriceTypeValue	priceTypeslPricetpPriceuppercaseTyper3  r  r  r:  r  r  r4  reduceOnlyPosSideposSides!                                    rS  rt  +kucoinfutures.create_contract_order_requestE  s   V$**6;QUQZQZQ\]6K#AB&Tl
 00F&YYv|4F$3L!/66*"&"8"8"FGJz"477-`#`aa!$":":6"JKGFO7;7Q7QRX7Y4_>>&*5^^FL9
 #

  ++F4FO $ 0 01BDTVf g6#~'+u}d6GFO#'#:#:6#PGK '<GO$!Z%;-I#,,X~{S262I2I&RY2Z./ ,,X7I6R	 ,,->	9U	%,,ZIZ[040G0GPW0X,- ,,Z9KVT	 ,,->	9U	'0GO$o+/5=$v'+'>'>v'U$-1U]&'+'>'>v'W$$(GL!'<GO$

,,V]CG#}'2m(mnn#'#:#:6#I &)4&001A5&Q&"&GJ2+TWW  (A  A  B  B//&)4//&-@K"'2v(vww^^FL%@
//%H$.GL!/3v~FG!*;'%)U]&*1'6  $L  M{{7++rU  r3   c                    U R                  5         U R                  USS5      nU R                  US/5      n0 nSnUbY  Uc  [        U R                  S-   5      eU R                  U5      nUS   US'   XES'   U R                  U R                  XS5      5      nO$XS'   U R                  U R                  XS5      5      nU R                  SU05      $ )	a  
cancels an open order

https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-futures-order-by-orderid

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str [params.clientOrderId]: cancel order by client order id
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
r  r  NzJ cancelOrder() requires a symbol argument when cancelling by clientOrderIdr3   rg  orderIdr^  )
r  r  r>  r#   r3   r  .futuresPrivateDeleteOrdersClientOrderClientOidr  !futuresPrivateDeleteOrdersOrderId
safe_order)rQ  r3   rg  rb  r  r  rc  r  s           rS  cancel_orderkucoinfutures.cancel_order  s     	**6;P6O#45$~'2~(~[[(F &tGH#0K JJ4;;W^KghH!#I==dkk'>Z[H 122rU  idsc                 l   U R                  5         SnUb  U R                  U5      n/ nU R                  USS/ 5      nU R                  USS/5      nSn[	        S[        U5      5       HF  nSnUc  [        U R                  S-   5      eUR                  US   U R                  Xh5      S	.5        MH     [	        S[        U5      5       H  nUR                  X   5        M     U(       a  S
OSn	0 n
XZU	'   U R                  U R                  X5      5      nU R                  US/ 5      nU R                  X5      $ )a  
cancel multiple orders

https://www.kucoin.com/docs/rest/futures-trading/orders/batch-cancel-orders

:param str[] ids: order ids
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:param str[] [params.clientOrderIds]: client order ids
:returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
NclientOrderIds
clientOidsFr   TzL cancelOrders() requires a symbol argument when cancelling by clientOrderIdsr3   )rg  r  clientOidsListorderIdsListrW  )r  r  safe_list_2r>  r  r  r#   r3   r  ra  %futuresPrivateDeleteOrdersMultiCancelr  r  r  )rQ  r  rg  rb  r  r  r  useClientorderIdr  
requestKeyr  rc  r   s                rS  cancel_orderskucoinfutures.cancel_orders  sH    	[[(F))&2BLRTU6$4l#CD q#n-.A#~'  3A  )A  B  B!! ,!--n@# 	 / q#c(#A!!#&) $)9%~
,
==dkk'>Z[* &"5  00rU  c                    U R                  5         0 nUb  U R                  U5      US'   U R                  USS5      nU R                  USS/5      nSnU(       a!  U R	                  U R                  X25      5      nO U R                  U R                  X25      5      nU R                  US5      nU R                  SU05      /$ )a  
cancel all open orders

https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-limit-orders
https://www.kucoin.com/docs/rest/futures-trading/orders/cancel-multiple-futures-stop-orders

:param str symbol: unified market symbol, only orders in the market of self symbol are cancelled when symbol is not None
:param dict [params]: extra parameters specific to the exchange API endpoint
:param dict [params.trigger]: When True, all the trigger orders will be cancelled
:returns: Response from the exchange
Nrg  r  rB  rW  r^  )	r  	market_idsafe_value_2r>  futuresPrivateDeleteStopOrdersr  futuresPrivateDeleteOrdersr`  r  )rQ  rg  rb  r  rB  rc  rW  s          rS  cancel_all_orderskucoinfutures.cancel_all_orders  s     	 $v 6GH##FFI>6FI#67::4;;w;WXH66t{{77STH ~~h//00rU  c                 ^   U R                  5         U R                  U5      nU R                  5       nUS   U R                  X5      US.nU R	                  U R                  Xc5      5      nU R                  US5      nU R                  U R                  X5      U R                  X5      SS.5      $ )aW  
add margin

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

:param str symbol: unified market symbol
:param float amount: amount of margin to add
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin structure <https://docs.ccxt.com/#/?id=add-margin-structure>`
r3   )rg  rB   bizNorW  in)r  	direction)r  r  r  r  -futuresPrivatePostPositionMarginDepositMarginr  r  parse_margin_modification)	rQ  rg  r  rb  r  r  r  rc  rW  s	            rS  
add_marginkucoinfutures.add_margin+  s     	V$yy{Tl..v>

 EEdkkRYFbcd x0{{499$G..v>J
  	rU  c                 b   U R                  US5      nU R                  X25      nU R                  US5      nU R                  US5      nU(       a  SOSnU R                  US5      nU R                  US5      nUU R	                  Xr5      S US S U R                  U5      S UU R                  U5      S.
$ )	Nr3   rl  rK  rL  rM  rg  rC  )
r^  rg  r  r-  r  totalr  r   r   r  )ra  r  r  r  safe_symbolr  r  )	rQ  r^  r  r3   r  rK  moder  r   s	            rS  r  'kucoinfutures.parse_margin_modificationv  s    \ dD)!!"-%%d,<=
OOD+6	#w##FH5%%d,>?	&&x8++J7"Y/
 	
rU  c                    U R                  5         SnU R                  USS5      u  peU(       a  U R                  SX#XE5      $ U R                  USS5      nU R	                  US5      nU R                  U/ SQ5      nUS:X  a  S	nOUS
:X  a  Sn0 n	U(       d  XS'   OUS:w  a  [        U R                  S-   5      eSn
Ub  U R                  U5      n
U
S   U	S'   Ub  X9S'   Ub  XS'   SnU(       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                  XX45      $ )a  
fetches a list of orders placed on the exchange

https://docs.kucoin.com/futures/#get-order-list
https://docs.kucoin.com/futures/#get-untriggered-stop-order-list

:param str status: 'active' or 'closed', only 'active' is valid for stop orders
:param str symbol: unified symbol for the market to retrieve orders from
:param int [since]: timestamp in ms of the earliest order to retrieve
:param int [limit]: The maximum number of orders to retrieve
:param dict [params]: exchange specific parameters
:param bool [params.trigger]: set to True to retrieve untriggered stop orders
:param int [params.until]: End time in ms
:param str [params.side]: buy or sell
:param str [params.type]: limit or market
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns: An `array of order structures <https://docs.ccxt.com/#/?id=order-structure>`
FfetchOrdersByStatusr  r  rB  r<  )r  r<  rB  closeddonerX  r  r   z= fetchOrdersByStatus() can only fetch untriggered stop ordersNr3   rg  r%  r  rW  r=  )r  r  fetch_paginated_call_dynamicsafe_bool_2r  r>  r$   r3   r  futuresPrivateGetStopOrdersr  futuresPrivateGetOrdersr`  r  r  )rQ  r   rg  r  r>  rb  r  rB  r<  r  r  rc  responseDatar   s                 rS  fetch_orders_by_status$kucoinfutures.fetch_orders_by_status  s}   & 	88AVXbc445JF[`ii""669=!!&'26#?@XFvF &HxTWW'ffgg[[(F &tGH!&I$G77G8TUH33DKK4PQHh ~~h;gr:  >>rU  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      $ )aS  
fetches information on multiple closed orders made by the user

https://docs.kucoin.com/futures/#get-order-list

: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, or market
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Order[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
Fr]   r  r  r  r  r  r  rQ  rg  r  r>  rb  r  s         rS  fetch_closed_orders!kucoinfutures.fetch_closed_orders   s]      	88ATV`a445H&Y^gg**66%PPrU  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 open orders made by the user

https://docs.kucoin.com/futures/#get-order-list
https://docs.kucoin.com/futures/#get-untriggered-stop-order-list

: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, or market
:param boolean [params.trigger]: set to True to retrieve untriggered stop orders
: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  rX  r  r  s         rS  fetch_open_orderskucoinfutures.fetch_open_orders7  s]    $ 	88ART^_445FW\ee**66%PPrU  c                    U R                  5         0 nSnUcg  U R                  USS5      nUc  [        U R                  S-   5      eXdS'   U R	                  USS/5      nU R                  U R                  XC5      5      nO$XS'   U R                  U R                  XC5      5      nUb  U R                  U5      OSnU R                  US5      nU R                  X5      $ )ap  
fetches information on an order made by the user

https://docs.kucoin.com/futures/#get-details-of-a-single-order

:param str id: order id
:param str symbol: unified symbol of the market the order was made in
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: An `order structure <https://docs.ccxt.com/#/?id=order-structure>`
Nr  r  z7 fetchOrder() requires parameter id or params.clientOidr  rW  )r  r  r&   r3   r>  "futuresPrivateGetOrdersByClientOidr  futuresPrivateGetOrdersOrderIdr  r`  rx  )	rQ  r3   rg  rb  r  rc  r  r  r  s	            rS  fetch_orderkucoinfutures.fetch_orderP  s     	: ..v{OTM$"477-f#fgg#0K YYv_'EFF>>t{{7?[\H!#I::4;;w;WXHX *0);V$$~~h755rU  orderc           
      P   U R                  US5      nU R                  X25      nUS   nU R                  USS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
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S5      nU R                  US5      nU R                  US5      nUc  [        R                  " US5      (       au  U R                  US5      nUS   (       a-  [        R                  " U[        R                  " UU5      5      nO,[        R                  " [        R                  " UU5      U5      nU R                  US5      nU R                  USS5      nS nUb  U(       a  SOSnU(       a  SOUnS nUb  UUS.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S5      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 R                  US 5      _S!U_S"U_S#S _S$U_S%U_S	U_UUS UUS S&.EU5      $ )'Nrg  r3   r  r  	createdAtr(  rf  feeCurrencyfeerm  
filledSizefilledValueavgDealPricer   r  rH  isActivecancelExistFrX  r  canceled)r  r  r  r3  r  r  	updatedAtr  r  r.  r  r  filled	remainingr   r  )r   r^  lastTradeTimestamprO  r  trades)ra  r  r  r  r  r  r  r-   rh  r  
string_mulr  rs  r  )rQ  r  r  r  rg  r  r  r   r  r(  rf  feeCurrencyIdr  feeCostr  r  r  r  r  r  r  r   r  r  r3  r  r  rO  s                               rS  rx  kucoinfutures.parse_order  sE   v ##E84!!(3!$$UD)<v.%%e[9	<<	*  0 v.((>--m<""5%0!!%0!!%6}5""5.9O!2!263!?!?++FNCLh!,,T73E3ElTZ3[\!,,W-?-?f-UW[\ ??5*5nnUM5A'VXF*'C ((<&&um<??5*5__UL9
"//{C  
' 
] 
 f 
 D	 

 ; 
  
 * 
 D 
 f 
 U 
 D,,UK@ 
 D 
 f 
  
  
  ! 
" 3# 
$ "&#6/ 
0 1 	rU  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      $ )aN  
fetch the current funding rate

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
rg  r3   rW  )r  r  (futuresPublicGetFundingRateSymbolCurrentr  r`  parse_funding_rater3  s          rS  fetch_funding_rate kucoinfutures.fetch_funding_rate	  sn     	V$fTl
 @@WA]^ ~~h3&&t44rU  c                 $    U R                  X5      $ )aW  
fetch the current funding rate interval

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `funding rate structure <https://docs.ccxt.com/#/?id=funding-rate-structure>`
)r  )rQ  rg  rb  s      rS  fetch_funding_interval$kucoinfutures.fetch_funding_interval8	  s     &&v66rU  c                 z   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U R                  US5      _SS _SS _SS _SS _SS _SU R                  U R                  US5      5      0E$ )Nr(  rg  r^  r  r  r  interestRateestimatedSettlePricer   r  r)  r  fundingTimestampfundingDatetimenextFundingRatepredictedValuenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeintervalr  )r  ra  r  r  r  parse_funding_interval)rQ  rW  r  r  r  s        rS  r   kucoinfutures.parse_funding_rateD	  sT     ,,T;?##D(3
D
d&&xzJ
 
 $	

 D
 #D
 
 
 4++D':
  0
 t||,<=
 t//6FG
 #D
 "4
 "4
  '!
" &t#
$ 33D4D4DT=4YZ%
 	
rU  c                 6    SSSSSS.nU R                  X!U5      $ )Nr
  r  r  16h24h)360000014400000288000005760000086400000ra  )rQ  r  	intervalss      rS  r  $kucoinfutures.parse_funding_intervale	  s-    
	 	X>>rU  c                    US S S.nU R                  US5      n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'   XbU'   U R	                  U5      $ )N)r^  r   r  rW  r  availableBalancefreeaccountEquityr  )r  ra  r  accountsafe_balance)rQ  rc  r  rW  r  r  r+  s          rS  parse_balancekucoinfutures.parse_balanceo	  s    

 x0%%dJ7
&&z2,,.**41CD++D/Bt  ((rU  c                 r   U R                  5         U R                  U R                  S5      nU R                  U R                  S0 5      nU R                  USU5      nU R                  USU5      nU R	                  U5      nSUS   0nU R                  U R                  Xa5      5      nU R                  U5      $ )a  
query for balance and get the amount of funds available for trading or funds locked in orders

https://www.kucoin.com/docs/rest/funding/funding-overview/get-account-detail-futures

:param dict [params]: extra parameters specific to the exchange API endpoint
:param dict [params.code]: the unified currency code to fetch the balance for, if not provided, the default .options['fetchBalance']['code'] will be used
:returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
r  rY   r  r3   )r  ra  rK  r  r   futuresPrivateGetAccountOverviewr  r-  )rQ  rb  defaultCodefetchBalanceOptionsr  r  r  rc  s           rS  fetch_balancekucoinfutures.fetch_balance~	  s     	&&t||V<"oodllNBO&&':FKP<==&
 88W9UV  !!(++rU  fromAccount	toAccountc                 d   U R                  5         U R                  U5      nU R                  X5      nU R                  US5      US.nU R	                  U5      n	Sn
U	S:X  d  U	S:X  a%  XS'   U R                  U R                  X5      5      n
O_US:X  d  US:X  d  US	:X  a5  U R	                  U5      US
'   U R                  U R                  X5      5      n
O[        U R                  S-   5      eU R                  U
S0 5      nU R                  U R                  X5      U R                  U5      UUS.5      $ )a7  
transfer currency internally between wallets on the same account

https://www.kucoin.com/docs/rest/funding/transfer/transfer-to-main-or-trade-account
https://www.kucoin.com/docs/rest/funding/transfer/transfer-to-futures-account

: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>`
r3   )r  r  NTRADEMAINrecAccountTyperD   rC   r  payAccountTypezR transfer() only supports transfers between future/swap, spot and funding accountsrW  )r  r5  r6  )r  r  currency_to_precisionra  parse_transfer_typefuturesPrivatePostTransferOutr  futuresPrivatePostTransferInr$   r3   r`  parse_transferrP  )rQ  r  r  r5  r6  rb  r  amountToPrecisionr  toAccountStringrc  rW  s               rS  r   kucoinfutures.transfer	  s:    	==& 66tD((48'
 229=g%F)B(7$%99$++g:VWH2 ("i6&9Y*=T(,(@(@(MG$%88W9UVH TWW'{{||~~h3{{4..t>''(9:&"A
  	rU  r   r  c                     U R                  US5      nU R                  US5      UU R                  U5      U R                  S U5      U R	                  US5      S S U R                  US5      US.	$ )Nr  applyIdr  r   )	r3   r   r  r  r  r5  r6  r   r^  )r  ra  r  r  r  )rQ  r   r  r   s       rS  r@  kucoinfutures.parse_transfer	  sx    < %%h<	""8Y7"Y///h?&&x:&&x:

 
	
rU  r   c                 .    SS0nU R                  X!U5      $ )N
PROCESSINGpendingr$  )rQ  r   statusess      rS  parse_transfer_status#kucoinfutures.parse_transfer_status
  s#    )
 &99rU  transferTypec                 0    SSS.nU R                  X!U5      $ )Nr8  r9  )rA   r   )r  )rQ  rM  transferTypess      rS  r=  !kucoinfutures.parse_transfer_type
  s$    
 %%m<PPrU  c                    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  X&S'   Ub  [	        SU5      US	'   U R                  S
Xd5      u  pdU R                  U R                  Xd5      5      nU R                  US0 5      n	U R                  U	S/ 5      n
U R                  XX#5      $ )a  

https://docs.kucoin.com/futures/#get-fills

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]: End time in ms
:param boolean [params.paginate]: default False, when True will automatically paginate by calling self endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=trade-structure>`
Fry   r  Nr3   rg  r%  r<  pageSizer  rW  r=  )r  r  r  r  r  handle_until_optionfuturesPrivateGetFillsr  r`  r  parse_trades)rQ  rg  r  r>  rb  r  r  r  rc  rW  r   s              rS  fetch_my_tradeskucoinfutures.fetch_my_trades"
  s    	88R\]44_fUZcc
 [[(F &tGH!&I"%dE"2GJ227GL..t{{7/KLD ~~h3gr2  >>rU  c                     U R                  5         U R                  U5      nSUS   0nU 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/futures-trading/market-data/get-transaction-history

:param str symbol: unified symbol of the market to fetch trades for
:param int [since]: timestamp in ms of the earliest trade to fetch
:param int [limit]: the maximum amount of trades to fetch
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns Trade[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
rg  r3   rW  )r  r  futuresPublicGetTradeHistoryr  r  rU  )	rQ  rg  r  r>  rb  r  r  rc  r   s	            rS  fetch_tradeskucoinfutures.fetch_tradesl
  sp     	V$fTl
 44T[[5QR$ &"5  >>rU  tradec                    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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S5      nUS:X  a  S nU R                  USS5      nUc?  U R                  US5      n[        R                  " X5      n[        R                  " UU5      nU R                  UUUUU R                  U5      US   UUU
UU	UUS.U5      $ )Nrg  r  tradeIdr3   r  	liquidityr  r  r  	dealValuer<  r(  	dealPricerm  r  rf  r  r  r  rz  ry  feeRate)r  r  rater  	orderTypematchfundsr  r  )r^  r3   r  r   r  rg  r  takerOrMakerrf  r(  r  r  r  )
ra  r  r  r  r  r  r-   r  
safe_trader  )rQ  r\  r  r  r3   r  rg  r   priceStringamountStringrf  r  feeCostStringr  r  r  
costStringr  contractCosts                      rS  parse_tradekucoinfutures.parse_trade
  s(   X ##E84!!(C8y$7""5)4''{;%%eT2	 )))g*=>I))%=Iu$9+@%,	((E))%Bv.((6$ ,,UMBM11-@K"26&.fWovf~%'((	:C
 !!%=7?D''w@
++FNCL"--kHL ++L,GJ"Y/X&( " 
  	rU  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X5S'   Ub  X%S'   U R                  U R                  XT5      5      nUS   S   nU R	                  XX#SS	05      $ )
a  
fetch all deposits made to an account
:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch deposits for
:param int [limit]: the maximum number of deposits structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr3   r  rR  r%  rW  r=  r  r   )r  r  futuresPrivateGetDepositListr  parse_transactions	rQ  r  r  r>  rb  r  r  rc  r  s	            rS  fetch_depositskucoinfutures.fetch_deposits  s     	}}T*H"*4.GJ"'J!&I44T[[5QR8  '0&&|ufV_M`aarU  c                     U R                  5         0 nSnUb  U R                  U5      nUS   US'   Ub  X5S'   Ub  X%S'   U R                  U R                  XT5      5      nUS   S   nU R	                  XX#SS	05      $ )
a  
fetch all withdrawals made from an account
:param str code: unified currency code
:param int [since]: the earliest time in ms to fetch withdrawals for
:param int [limit]: the maximum number of withdrawals structures to retrieve
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict[]: a list of `transaction structures <https://docs.ccxt.com/#/?id=transaction-structure>`
Nr3   r  rR  r%  rW  r=  r  
withdrawal)r  r  futuresPrivateGetWithdrawalListr  rr  rs  s	            rS  fetch_withdrawalskucoinfutures.fetch_withdrawalsD  s     	}}T*H"*4.GJ"'J!&I77G8TU8  '0&&|ufVbMcddrU  c                    U R                  5         U R                  U5      nUS   (       d  [        U R                  S-   5      eSUS   0nU R	                  U R                  XB5      5      nU R                  US/ 5      nU R                  Xc5      $ )a  
retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market

https://www.kucoin.com/docs/rest/futures-trading/risk-limit/get-futures-risk-limit-level

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `leverage tiers structure <https://docs.ccxt.com/#/?id=leverage-tiers-structure>`
r  z: fetchMarketLeverageTiers() supports contract markets onlyrg  r3   rW  )r  r  r$   r3   (futuresPublicGetContractsRiskLimitSymbolr  r  parse_market_leverage_tiersr3  s          rS  fetch_market_leverage_tiers)kucoinfutures.fetch_market_leverage_tiersv  s     	V$j!TWW'ccddfTl
 @@WA]^$ ~~h3//==rU  c                 j   / n[        S[        U5      5       H  nX   nU R                  US5      nUR                  U R	                  US5      U R                  XbSS5      US   U R	                  US5      U R	                  US5      U R	                  US	5      U R	                  US
5      US.5        M     U$ )zv
@ignore
       :param dict info: Exchange market response for 1 market
       :param dict market: CCXT market
       r   rg  r  Nr  ry  minRiskLimitmaxRiskLimitmaintainMarginr  )tierrg  r  minNotionalmaxNotionalmaintenanceMarginRater  r^  )r  r  ra  r  r  r  )rQ  r^  r  r   r  r  r  s          rS  r}  )kucoinfutures.parse_market_leverage_tiers  s    " q#d)$A7D''h7HLL((w7**8T:N"6N#//nE#//nE)-)9)9$@P)Q#//mD	 	 % rU  c                    Uc  [        U R                  S-   5      eU R                  5         U R                  U5      nUS   SU R	                  5       S.nU R                  US5      nU R                  US/5      nUb  X&S'   Uc  US-   US'   Ub  XvS'   Uc  US-
  US'   U R                  U R                  Xd5      5      nU R                  US	/ 5      n	U R                  XX#5      $ )
a  

https://www.kucoin.com/docs/rest/futures-trading/funding-fees/get-public-funding-history#request-url

fetches historical funding rate prices
: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 argumentr3   r   )rg  r  r  r<  r  l    PRW r  rW  )r#   r3   r  r  r  r  r>  $futuresPublicGetContractFundingRatesr  r  parse_funding_rate_histories)
rQ  rg  r  r>  rb  r  r  r<  rc  rW  s
             rS  fetch_funding_rate_history(kucoinfutures.fetch_funding_rate_history  s     >#DGG.e$effV$Tl##%

 !!&'26G9-#FO} %(@ @!DM} %(@ @<<T[[=YZ ~~h300uLLrU  c                     U R                  US5      nU R                  US5      nUU R                  XB5      U R                  US5      UU R	                  U5      S.$ )N	timepointrg  r)  )r^  rg  r)  r   r  )r  ra  r  r  r  )rQ  r^  r  r   r  s        rS  parse_funding_rate_history(kucoinfutures.parse_funding_rate_history  s`    %%dK8	##D(3&&x8++D-@"Y/
 	
rU  c                    U R                  5         U R                  U5      nU R                  US5      nU R                  USS5      nU R	                  USS/5      nUc  U R                  U R                  5       5      nUS   SUSS.nSnU(       a!  U R                  U R                  Xs5      5      nO U R                  U R                  Xs5      5      nU R                  X5      $ )	a  
closes open positions for a market

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

:param str symbol: Unified CCXT market symbol
:param str side: not used by kucoinfutures closePositions
:param dict [params]: extra parameters specific to the okx api endpoint
:param str [params.clientOrderId]: client order id of the order
:returns dict[]: `A list of position structures <https://docs.ccxt.com/#/?id=position-structure>`
r  rp  FNr3   Tr  )rg  
closeOrderr  r  )r  r  ra  rs  r>  number_to_stringr  ru  r  rw  rx  )	rQ  rg  rf  rb  r  r  ry  r  rc  s	            rS  close_positionkucoinfutures.close_position  s     	V$((ANN6659	6FO#<=  11$**,?MTl&	
 88W9UVH44T[[5QRH11rU  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	.$ )
a=  
fetch the trading fees for a market

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `fee structure <https://docs.ccxt.com/#/?id=fee-structure>`
r  r3   rW  r   rg  r  r  T)r^  rg  r   r   r   r   )	r  r  privateGetTradeFeesr  r  r`  ra  r  r  )	rQ  rg  rb  r  r  rc  rW  firstr  s	            rS  fetch_trading_feekucoinfutures.fetch_trading_fee  s     	V$vd|
 ++DKK,HI ~~h3tQ'##E84&&x8%%e^<%%e^<
 	
rU  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      $ )ao  
fetches the margin mode of a trading pair

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

:param str symbol: unified symbol of the market to fetch the margin mode for
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `margin mode structure <https://docs.ccxt.com/#/?id=margin-mode-structure>`
rg  r3   rW  )r  r  &futuresPrivateGetPositionGetMarginModer  r`  parse_margin_moder3  s          rS  fetch_margin_modekucoinfutures.fetch_margin_mode>  sn     	V$fTl
 >>t{{7?[\ ~~h3%%d33rU  r-  c                 L    U R                  US5      nUS:X  a  SOSnUUS   US.$ )Nr-  ISOLATEDrM  rL  rg  )r^  rg  r-  r$  )rQ  r-  r  
marginTypes       rS  r  kucoinfutures.parse_margin_modeZ  s:    %%j,?
$.*$<Z7
X&$
 	
rU  c                 Z   Uc  [        U R                  S-   5      eU R                  SUSSS/5        U R                  5         U R	                  U5      nUS   UR                  5       S.nU R                  U R                  XS5      5      nU R                  US0 5      nU R                  Xt5      $ )	aG  
set margin mode to 'cross' or 'isolated'

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

:param str marginMode: 'cross' or 'isolated'
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
z+ setMarginMode() requires a symbol argumentr   r-  rL  rM  r3   )rg  r-  rW  )
r#   r3   check_required_argumentr  r  r  *futuresPrivatePostPositionChangeMarginModer  r`  r  )rQ  r-  rg  rb  r  r  rc  rW  s           rS  set_margin_modekucoinfutures.set_margin_modec  s     >#DGG.[$[\\$$_j,QXZdPefV$Tl$**,
 BB4;;wC_` ~~h3%%d33rU  r4  c                     U R                  5         U(       a  SOSnSU0nU R                  U R                  XS5      5      nU$ )a@  
set hedged to True or False for a market

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

:param bool hedged: set to True to use two way position
:param str [symbol]: not used by bybit setPositionMode()
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a response from the exchange
r  r   positionMode)r  ,futuresPrivatePostPositionSwitchPositionModer  )rQ  r4  rg  rb  posModer  rc  s          rS  set_position_modekucoinfutures.set_position_mode  sH     	#SG
 DDT[[QXEab rU  c                 h   SnU R                  X5      u  p2US:w  a  [        U R                  S-   5      eU R                  5         U R	                  U5      nSUS   0nU R                  U R                  XR5      5      nU R                  US0 5      nU R                  Xt5      nU R                  USU05      $ )aI  
fetch the set leverage for a market

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

:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: a `leverage structure <https://docs.ccxt.com/#/?id=leverage-structure>`
NrL  zG fetchLeverage() currently supports only params["marginMode"] = "cross"rg  r3   rW  r-  )	handle_margin_mode_and_paramsr(   r3   r  r  %futuresPrivateGetGetCrossUserLeverager  r`  parse_leverage)	rQ  rg  rb  r-  r  r  rc  rW  parseds	            rS  fetch_leveragekucoinfutures.fetch_leverage  s     
!??O
 tww)rrssV$fTl
 ==dkk'>Z[ ~~h3$$T2{{6*$
  	rU  r6  c                 .   SnU R                  X#5      u  pCUS:w  a  [        U R                  S-   5      eU R                  5         U R	                  U5      nUS   [        U5      S.nU R                  U R                  Xc5      5      nU R                  Xu5      $ )aN  
set the level of leverage for a market

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

:param float leverage: the rate of leverage
:param str symbol: unified market symbol
:param dict [params]: extra parameters specific to the exchange API endpoint
:returns dict: response from the exchange
NrL  zE setLeverage() currently supports only params["marginMode"] = "cross"r3   )rg  r6  )	r  r(   r3   r  r  str)futuresPrivatePostChangeCrossUserLeverager  r  )rQ  r6  rg  rb  r-  r  r  rc  s           rS  set_leveragekucoinfutures.set_leverage  s     
!??O
 tww)ppqqV$TlH
 AA$++gB^_ ""844rU  c                     U R                  US5      nU R                  X25      nU R                  US5      nUUS   S UUS.$ )Nrg  r6  )r^  rg  r-  longLeverageshortLeverage)ra  r  r  )rQ  r6  r  r  leverageNums        rS  r  kucoinfutures.parse_leverage  sT    ##Hh7!!(3''*=X&'(
 	
rU   )N)b__name__
__module____qualname____firstlineno__r   rO  rd  r   r   r  r	   r  r  listr  r  r   r  r   r  r   r  r  r   r   r  dictr  r"  r   r.  r4  r   r9  r@  r2  r   r   floatr   r|  r   r  rt  r  r  r  r   r  r  r  r   r  r  r  rx  r   r  r  r  r  r   r-  r3  r   r   r   r@  rK  r=  rV  r   rZ  rn  r   rt  ry  r   r~  r}  r  r  r  r   r  r   r  r  r  boolr  r
   r  r  r  r  __static_attributes____classcell__)rR  s   @rS  r/   r/      s1   u# un #% 
: $& ^$v, ^@ !# 3s 3$ 9=4^bkm 4H# 4H# 4HS 4HX[ 4Hrvw{r| 4Hl
 
4 
* 79 %
# %
^ %
N :>b 1s 13 1Y 1f 02 ";3 ";f ";H 46 ;s ;& ;& 04B THW TH7 THlr4 r r6 rh 26b 
Iw 
I 37TX\eg BC Bs BRU BH 24 =1S =1~ 26b ;3w ;3T(^ ;3z :>D_cln C4w C4c C4Y\ C4J|t |V || gksu <.3 <.i <.y <.RW <.`c <.| @B .'D$6 .'` x|  EG `,C `,y `,PY `,ch `,qt `,D 37r %3s %3C %3N ;?r 71c 71C 71r /32 "1 "1H =? I Ie ICU IV@
f @
HZ @
D <@daenp f?S f? f?[^ f?P 154VZce Q# QS QPS Qjnotju Q. /3TXac Q Q3 Qc Qhlmrhs Q2 26b E6c E63 E6N v  B 68 5 5K 5@ :< 
7S 
7 
7
v 
 
B?) ) $& $,( $,L [] DS D% Dc Dc Dan DL)
t )
x )
= )
V:C :C :Q Q Q -1tRV_a H?c H? H?C H?T 6:UW $?3 $?s $?# $?\`af\g $?L~ ~v ~ ~@ *.Dt\^ 0b3 0bc 0b 0bcghsct 0bd -1tRV_a 0ec 0e 0eC 0efjkvfw 0ed ?A $># $>T,EW $>L $|J\ B 8<$]ajl .M .MC .MWZ .M`	
v 	
 =A 2S 2	 2PU 2@ 57 $
 $
;N $
L 57 4 4: 48
D 
* 
 >B" 4# 4s 4B =A  c 6 24 !S ! !F 9=R 5S 5# 5<

t 

V 

x 

 

rU  r/   N)3ccxt.kucoinr   ccxt.abstract.kucoinfuturesr   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+   ccxt.base.decimal_to_precisionr,   ccxt.base.preciser-   r/   r  rU  rS  <module>r     st     3 r  r  r  r  r  r  r  0 - - . ' . ) * ) . 1 ) 4 %P3
FK P3
rU  