
    !:hF<                    X   d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlm Z  d dl!m"Z" d dl!m#Z# d dl!m$Z$ d dl!m%Z% d d	l!m&Z& d d
l!m'Z' d dl!m(Z( d dl!m)Z) d dl!m*Z* d dl!m+Z+ d dl!m,Z, d dl!m-Z- d dl.m/Z/ d dl0m1Z1  G d dee      Z2y)    )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                   X    e Zd Zdef fdZi fdZi fdee   fdZi fde	fdZ
dddi fded	e	d
e	dee   fdZdVdedefdZi fdedefdZdi fded
e	defdZi fdedefdZi fdedefdZdi fdedefdZdVdededefdZdi fdefdZdddi fded	e	d
e	fdZi fdefdZdi fdedee   fdZ dddi fded	e	d
e	fdZ!dVdedefdZ"di fdede#de$d e%d!e&f
d"Z'i fd#ee(   fd$Z)di fdede#de$d e%d!e&f
d%Z*di fd&edefd'Z+di fdefd(Z,di fdefd)Z-i fded e%de.fd*Z/dVdede.fd+Z0dddi fded	e	d
e	fd,Z1dddi fded	e	d
e	dee2   fd-Z3dddi fded	e	d
e	dee2   fd.Z4di fd&edefd/Z5dVd0edede2fd1Z6i fdede7fd2Z8i fdede7fd3Z9dVdede7fd4Z:d5 Z;de<fd6Z=i fde<fd7Z>i fded e%d8ed9ede?f
d:Z@dVd;ed<eAde?fd=ZBd>edefd?ZCd@edefdAZDdddi fded	e	d
e	fdBZEddi fded	e	d
e	deeF   fdCZGdVdDededeFfdEZHdddi fded	e	d
e	deeI   fdFZJdddi fded	e	d
e	deeI   fdGZKi fdedeeL   fdHZMdVdedeeL   fdIZNdddi fded	e	d
e	fdJZOdVdefdKZPdi fdede$de2fdLZQi fdedeRfdMZSi fdedeTfdNZUdVdOedeTfdPZVdi fdOedefdQZWi fdedeXfdRZYdi fdSe	defdTZZdVdSededeXfdUZ[ xZ\S )Wkucoinfuturesreturnc                    | j                  t        t        |          i ddddddgddd	d
dddddddddi dd ddddddddddddddddddddddddd dd!dd"dd#di d$dd%dd&dd'dd(dd)dd*dd+dd,dd-dd.dd/dd0dd1dd2dd3dd4di d5dd6dd7dd8dd9dd:dd;dd<dd=dd>dd?dd@ddAddBddCddDddEdi dFddGddHddIddJddKddLddMddNddOddPddQddRddSddTddUddVddddddddddddd dWdXdYdZd[gd\d]d^d^d_d_d`dadbdcddddddei dfdgdhdgdidgdjdgdkdgdldmdndgdodgdpdgdqdgdrdgdsdgdtdgdudgdvdgdwdgdxdgdgdgdydzdgid{i d|dmd}d~ddgddgddgddgddgddmddgddgddgddgdd~dd~ddgddgdd~d~dgdgdgdgdgdgdgddgdgdgdmdmdmdgdgdgdgdgdgdgdgddgdgdgd~dgdgdgddddddgiiddt        di dt
        dt        dt        dt        dt        dt
        dt        dt        dt        dt        dt
        dt        dt        dt        dt        dt        dt        t        t        t        t        t        t        t        t        t
        t        t        t        ddt        idddd| j!                  d      | j!                  d      | j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      gg| j!                  d      | j!                  d      g| j!                  d      | j!                  d«      g| j!                  d      | j!                  dë      g| j!                  d      | j!                  dë      g| j!                  d      | j!                  dë      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  d      g| j!                  d      | j!                  dī      g| j!                  d      | j!                  dū      g| j!                  d      | j!                  dƫ      g| j!                  d      | j!                  dǫ      g| j!                  d      | j!                  dȫ      ggdɜdʜddi i d˜d̜ddddddddԜdgd ddddddd dddddߜd
dddi i dddddddddddqdiiddddddd ddddddddddd dddddddddddddddddiddd ddddddddddddddd ddd d d ddddddid	ddiddidddiddiddd      S (   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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   )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300009z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   )GETPOSTr  )r   r   omniethtrx)OMNIERC20TRC20)r8   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)  triggerr1  r=  )r)  r:  r>  r1  r=  )r)  r:  r;  daysBackCanceledr<  r>  r1  r=  r:  i  )	sandboxrM   rN   rx   r{   rz   fetchOrdersr\   ry   extends	forDerivs)linearinverse)r@   rC  rB   rC   )
timeframesoptionsfeatures)deep_extendsuperr/   describer,   r$   r    r(   r)   r*   r&   r!   r%   r+   r"   r'   parse_number)self	__class__s    L/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/kucoinfutures.pyrK  zkucoinfutures.describe   s   mT C E pH
/pH
$pH
 $pH
 	pH

 tpH
 pH
 4pH
 ~pH
 pH
  QQQ %Q 	Q
 $Q %Q TQ "4Q tQ Q $UQ  Q !%Q 'Q tQ  !Q" 7#Q$ (%Q& ''Q( &t)Q* (+Q, "4-Q. (/Q0 %d1Q2  3Q4 5Q6  7Q8 +E9Q: )%;Q< $T=Q> '?Q@ (AQB "5CQD &tEQF (GQH 1%IQJ  KQL *5MQN +EOQP &tQQR 'SQT (UQV #DWQX *4YQZ "5[Q\ *5]Q^ +E_Q` #DaQb tcQd  eQf %egQh /iQj "4kQl +DmQn oQp !%qQr !$sQt  uQv dwQx "4yQz d{Q| !$}Q~  Q@ 'AQB $UCQD !$EQF (GQH )%IQJ  $# $!##'',$($!%  aQpH
x ~5- 5F=>&F%E#NypH
X " $YpH
b *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 ()()'("&%)'+?@:;<=*+'(./3456" 78/0,-"&&''(;</1	Y6#p 91 eWcpH
R YSpH
T :. < <	
 < : , / / l j . / / /  /!" l#$ 2*11111*(.2*;@ .}A#UpH
\ !%"&!..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-]pH
x !ypH
J	    #&%!!
 /3486:  -17;9=!' -t &( #""7$L $&*(,$($(%)-
 -1)-+/04%)7
 $(#("&#(	( #($)$(+/27/3#'7$< r% '+!%$(%&*/& ',#($)*/	# ',!%#'$)*/( $(&+!%$(,0%)#'$)*/	*  #CDN "; "; 	 "; "; 	_Wq
pH
 p p	    c                     | j                  |      }| j                  |di       }| j                  |d      }|dk(  rdndddd|dS )ai  
        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_valuesafe_string)rM  paramsresponserR  r   s        rO  fetch_statuszkucoinfutures.fetch_status  s\     ..v6 x4!!$1%/dm
 	
rP  c                    | j                  |      }g }| j                  |dg       }t        dt        |            D ]  }||   }| j	                  |d      }| j                  |d      }|rdnd}	|	 }
| j	                  |d      }| j	                  |d      }| j	                  |d	      }| j                  |      }| j                  |      }| j                  |      }|d
z   |z   dz   |z   }d}|	r|dz   | j                  |d      z   }d}| j                  |d      }| j	                  |d      }| j	                  |d      }| j                  |d      }| j                  |d      }|}|| j                  |d      }| j                  |d      }|| j                  |d      }| j                  |d      }|I| j	                  |d      }| j	                  |d      }| j                  t        j                  ||            }|j                  i d|d|d|d|d|d|d |d!|d"|d#dd$dd|
d|	d%dd&|d'k(  d(dd)| || j                  |d*      | j                  |d+      | j                  t        j                  |            || j                  |      dd||d,| j                  d-      | j                  |d.      d/||d/||d/| j                  |d0      | j                  |d      d/d1| j                  |d2      |d3        |S )4a4  
        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
        rR  r   symbol
expireDateTFbaseCurrencyquoteCurrencysettleCurrency/:rB   r   rC   	isInverser   
multipliertickSizelotSizeNbaseMinSizemaxOrderQtybaseMaxSizemaxPricequoteMaxSizer2   basequotesettlebaseIdquoteIdsettleIdtyper@   rA   rD   activeOpencontractrD  takerFeeRatemakerFeeRate)amountr$  1maxLeverage)minr7  quoteMinSize)r2  r~  r$  costfirstOpenDate)rE  r   r   contractSizeexpiryexpiryDatetimestrike
optionType	precisionlimitscreatedrY  )futuresPublicGetContractsActiver[  rangelenr\  safe_integersafe_currency_codeyymmddsafe_numberrL  r-   
string_divappend
string_absiso8601)rM  r]  r^  resultrR  imarketr2   r  rC   rB   ru  rv  rw  rr  rs  rt  ra  rx  rE  r   rj  rk  rl  limitAmountMinlimitAmountMaxlimitPriceMaxbaseMinSizeStringquoteMaxSizeStrings                                rO  fetch_marketszkucoinfutures.fetch_markets  s    77?~ x4q#d)$ S	A!WF!!&(3B&&v|<F#TF: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S	h rP  c                 H    | j                  |      }| j                  |d      S )ai  
        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
        rR  )futuresPublicGetTimestampr  )rM  r]  r^  s      rO  
fetch_timezkucoinfutures.fetch_time  s)     11&9   622rP  r  Nra  sincer:  c           	         | j                          d}| j                  |dd      \  }}|r| j                  d|||||d      S | j                  |      }|d   }| j	                  | j
                  |      }	d|i}
|	|	|
d<   n||
d<   | j                  |      dz  }| j                         }|:||
d	<   || j	                  | j                  d
d      }| j                  |||z        }n||||z  z
  }||
d	<   ||
d<   | j                  | j                  |
|            }| j                  |dg       }| j                  |||||      S )a  
        fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market

        https://www.kucoin.com/docs/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
        Fry   paginate   r2   ra  granularityr8  fromfetchOHLCVLimittorR  )load_marketshandle_option_and_params"fetch_paginated_call_deterministicr  r  rF  parse_timeframemillisecondsrG  sumfuturesPublicGetKlineQueryextend	safe_listparse_ohlcvs)rM  ra  	timeframer  r:  r]  r  r  marketIdparsedTimeframerequestdurationendAtr^  rR  s                  rO  fetch_ohlcvzkucoinfutures.fetch_ohlcv  s|    	88zZ&::<QVX]_hjpruvvV$$<++DOOYGh
 &%4GM"%.GM"''	2T9!!##GFO}))$,,8I3OHHUEH$45EEH,,E#GFO224;;w3OP ~~h3  vy%GGrP  r  c           	          | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      gS )Nr   r            r   )r  r  )rM  ohlcvr  s      rO  parse_ohlcvzkucoinfutures.parse_ohlcv  sn     eQ'UA&UA&UA&UA&UA&
 	
rP  r  c                 ^   | j                          | j                  |      }|d   }d|i}| j                  | j                  ||            }| j	                  |di       }| j                  |d      }|dk7  r| j                  |       ||| j                  |d      || j                  |d      dS )	a  
        fetch the deposit address for a currency associated with self account

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

        :param str code: unified currency code
        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: an `address structure <https://docs.ccxt.com/#/?id=address-structure>`
        r2   currencyrR  addressNIMchainmemo)rY  r  networkr  tag)r  r  futuresPrivateGetDepositAddressr  r[  r\  check_address)	rM  r  r]  r  
currencyIdr  r^  rR  r  s	            rO  fetch_deposit_addressz#kucoinfutures.fetch_deposit_address  s     	==&d^


 77GV8TU x4""43w'"''g6##D&1
 	
rP  c           	      $   | j                          | j                  |d      }|dk7  r|t        | j                  dz         | j	                  |      }d|d   i}|(|dk(  s|dk(  r||d<   nt        | j                  d	z         d|d<   | j                  | j                  ||            }| j                  |d
i       }| j                  | j                  |d      dz        }	| j                  ||d   |	dddd      }
| j                  |d      |
d<   |
S )aV  
        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 2ra  r2   r   d   r:  z2 fetchOrderBook() limit argument must be 20 or 100rR  ts@B bidsasksr   r   sequencenonce)r  r  r$   r2   r   futuresPublicGetLevel2DepthLimitr  r[  parse_to_intr  parse_order_book)rM  ra  r:  r]  r  r  r  r^  rR  r   	orderbooks              rO  fetch_order_bookzkucoinfutures.fetch_order_book  s1    	  1A:%+TWW'RRSSV$fTl
 ##(  +_!_``!GG88Wf9UV& x4%%d&7&7d&Cg&MN	))$x0@)VU[]^`ab	!..tZ@	'rP  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d   |      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://www.kucoin.com/docs/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>`
        ra  r2   rR  )r  r  futuresPublicGetTickerr  parse_tickerrM  ra  r]  r  r  r^  s         rO  fetch_tickerzkucoinfutures.fetch_tickerC  se     	V$fTl
 ..t{{7F/KL&   &!16::rP  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |d   |      S )a  
        fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market

        https://www.kucoin.com/docs/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>`
        ra  r2   rR  )r  r  &futuresPublicGetMarkPriceSymbolCurrentr  r  r  s         rO  fetch_mark_pricezkucoinfutures.fetch_mark_priceg  sd     	V$fTl
 >>t{{7TZ?[\  &!16::rP  symbolsc                 8   | j                          | j                  |      }d}| j                  |ddd      \  }}d}|dk(  r| j                  |      }n| j	                  |      }| j                  |d      }| j                  ||      }| j                  |d|      S )a  
        fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market

        https://www.kucoin.com/docs/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  futuresPublicGetAllTickersrR  ra  )r  market_symbolsr  r  r  r  parse_tickersfilter_by_array_tickers)rM  r  r]  r  r^  rR  tickerss          rO  fetch_tickerszkucoinfutures.fetch_tickersz  s     	%%g.66v~xYz{1166v>H;;FCH~ ~~h/$$T73++GXwGGrP  r   c           
         | j                  |d      }| j                  ||d      }| j                  |dd      }| j                  |dd      }| j	                  i d|d   d|d| j                  |      d	| j                  |d
      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      d| j                  |d      dd dd d|d|dd d| j                  |d      d| j                  |d      dd | j                  |d      | j                  |d       | j                  |d!d"      | j                  |d#      |d$|      S )%Nra  r  r$  lastTradePricer  gư>r   datetimehigh	highPricelowlowPricebidbestBidPrice	bidVolumebestBidSizeaskbestAskPrice	askVolumebestAskSizevwaprS  closer   previousClosechangepriceChgr   priceChgPctaveragevolumeOf24hturnoverOf24h	markPricevalue
indexPrice)
baseVolumequoteVolumer  r  rY  )r\  safe_marketsafe_string_2safe_integer_productsafe_tickerr  )rM  r   r  r  r   r   s         rO  r  zkucoinfutures.parse_ticker  s   n ##FH5!!(FC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<@-!
. / 	rP  c                 N    ddi}| j                  || j                  ||            S )a  
        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  )rM  r  r]  r  s       rO  fetch_bids_askszkucoinfutures.fetch_bids_asksD  s1     2
 !!'4;;w+GHHrP  c                    |t        | j                  dz         | j                          | j                  |      }d|d   i}|||d<   |||d<   | j	                  | j                  ||            }| j                  |d      }| j                  |dg       }	g }
t        dt        |	            D ]  }|	|   }| j                  |d	      }|
j                  ||| j                  | j                  |d
            || j                  |      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      | j                  |d      d        |
S )aR  
        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 argumentra  r2   startAtmaxCountrR  dataListr   	timePointre  r   fundingRater  positionQtypositionCost)rY  ra  r  r   r  r2   r~  r  r  r  r  )r#   r2   r  r  futuresPrivateGetFundingHistoryr  r[  r  r  r  r  r  r\  r  r  )rM  ra  r  r:  r]  r  r  r^  rR  r  r   r  listItemr   s                 rO  fetch_funding_historyz#kucoinfutures.fetch_funding_historyP  s    >#DGG.a$abbV$fTl
 !&GI"'GJ77GV8TU. x0??4R8q#h-( 	A{H))(K@IKK  //0@0@K[0\]& LL3&&x6**8Y?#//-H!--hD#//-H $ 0 0> J 	  rP  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )a{  

        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>`
        ra  r2   rR  )r  r  futuresPrivateGetPositionr  	safe_dictparse_positionrM  ra  r]  r  r  r^  rR  s          rO  fetch_positionzkucoinfutures.fetch_position  ss     	V$fTl
 11$++gv2NOZ ~~h3""400rP  c                     | j                          | j                  |      }| j                  |d      }| j                  ||      S )ag  
        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>`
        rR  )r  futuresPrivateGetPositionsr  parse_positions)rM  r  r]  r^  rR  s        rO  fetch_positionszkucoinfutures.fetch_positions  sF     	226:^ ~~h/##D'22rP  c                 F   | j                          |d}d|i}|||d<   | j                  |d      }|| j                  |d      }||d<   | j                  | j	                  ||            }| j                  |d      }| j                  |dg       }	| j                  |	|      S )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  rR  items)r  r  omit!futuresPrivateGetHistoryPositionsr  r  r  r$  )
rM  r  r  r:  r]  r  r'  r^  rR  r(  s
             rO  fetch_positions_historyz%kucoinfutures.fetch_positions_history  s     	=EU
 #GFO!!&'2YYvw/F!GDM99$++gv:VWN ~~h/tWb1##E733rP  r   c                 R   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }d }| j                  |d      }|2t	        j
                  |d      rd}n4t	        j                  |d      rd}n||j                  d      dkD  rd}nd}t	        j                  | j                  |d	            }| j                  |d
      }	t	        j                  |	|      }
| j                  |d      }| j                  |d      }d }||rdnd}| j                  i d|d| j                  |dd      d| j                  |d      d|d| j                  |      d| j                  |d      d| j                  |	      d| j                  |
      d| j                  |d      d| j                  |d      d| j!                  |dd      d| j                  |      d | j!                  |d!d       d"| j                  |      d#| j                  t	        j                  |            d$| j                  |d$      d%| j!                  |d&d'      d | j                  |d(      | j                  |d)      d | j                  |d*      ||d d d d+
      S ),Nra  currentTimestamp
currentQtyrx  r   longshortposCostposInitunrealisedPnl	crossModecrossisolatedrY  r2   
positionIdr   r  lastUpdateTimestamp	closeTimeinitialMargininitialMarginPercentagemaintenanceMarginposMaintmaintenanceMarginPercentagemaintMarginReq
entryPriceavgEntryPrice	openPricenotionalr2  realLeverageunrealizedPnl	contractsr  realizedPnlrealisedPnlpnlliquidationPricer  maintMargin)
marginRatiorK  r  	lastPrice
collateralr)  sider   r,  r-  )r\  r  r  safe_string_lowerr-   	string_gt	string_ltfindr  r  r[  safe_positionr  r  rL  r  safe_number_2)rM  r   r  ra  r   sizerP  rx  rD  r;  r<  r4  r5  r)  s                 rO  r  zkucoinfutures.parse_positionU  s#   L !!(H5!!&&1%%h0BC	,7%%h7  s+""4-yy 2%%%d&6&6x&KL((9=")"4"4]H"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#
  	rP  rx  rP  r~  r$  c                    | j                          | j                  |      }| j                  |dd      }| j                  |d      }| j	                  |d      duxs | j	                  |d      du}	| j                  ||||||      }
d}|r| j                  |
      }n%|	r| j                  |
      }n| j                  |
      }| j                  |di       }| j                  ||      S )aS  
        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'
 ----------------- 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.
        :returns dict: an `order structure <https://docs.ccxt.com/#/?id=order-structure>`
        testFstopLossN
takeProfitrR  )r  r  	safe_boolr)  r[  create_contract_order_requestfuturesPrivatePostOrdersTestfuturesPrivatePostStOrdersfuturesPrivatePostOrdersr  parse_order)rM  ra  rx  rP  r~  r$  r]  r  	testOrderisTpAndSlOrderorderRequestr^  rR  s                rO  create_orderzkucoinfutures.create_order  s    F 	V$NN6659	66*//&*=TI  Bt_egsOt  }A  PA99&$fV[]cd88FH::<H88F ~~h3f--rP  r   c           	         | j                          g }t        dt        |            D ]  }||   }| j                  |d      }| j	                  |      }| j                  |d      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |di       }| j                  |d   ||	|
||      }|j                  |        | j                  |      }| j                  |d	g       }| j                  |      S )
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   ra  rx  rP  r~  r$  r]  r2   rR  )r  r  r  r\  r  r[  r]  r  futuresPrivatePostOrdersMultir  parse_orders)rM  r   r]  ordersRequestsr  rawOrderra  r  rx  rP  r~  r$  orderParamsrd  r^  rR  s                   rO  create_orderszkucoinfutures.create_orders  s    	q#f+& 
	0AayH%%h9F[[(F##Hf5D##Hf5D__Xx8FOOHg6E//(HbAK==fTlDRVX^`egrsL!!,/
	0 55nE, ~~h3  &&rP  c                 R   | j                  |      }| j                  |dd| j                               }| j                  |ddg      }|||d   |dd}	| j	                  |d      }
|
| j                  |d      }|
|	d<   | j                  |d      }| j                  |d      }|| j                  ||      |	d<   n;|dk  rt        | j                  d	z         t        | j                  ||            |	d
<   | j                  |      \  }}}| j                  |d      }| j                  |d      }dddd}| j                  |dd      }| j                  |||      }| j                  |g d      }|r'|dk(  rdnd|	d<   | j                  ||      |	d<   ||	d<   n|||}|N| j                  |dd      }| j                  ||      |	d<   | j                  |dd      }| j                  |||      }|N| j                  |dd      }| j                  ||      |	d<   | j                  |dd      }| j                  |||      }||	d<   nS|s|rO|r"|dk(  rdnd|	d<   | j                  ||      |	d<   n!|dk(  rdnd|	d<   | j                  ||      |	d<   d|	d<   ||	d<   |j                         }| j	                  |d       }|d!k(  r6|t        | j                  d"z         | j                  ||      |	d#<   |||	d <   d }| j!                  |d$k(  d%|      \  }}|rd|	d&<   | j#                  |d'      }|r|t%        | j                  d(z         | j#                  |d)      }|r,| j#                  |d*      }|t        | j                  d+z         | j                  |g d,      }| j'                  |	|      S )-N	clientOidclientOrderIdr2   r   )rn  rP  ra  rx  r2  r)  r  valueQtyz1 createOrder() minimum contract order amount is 1rW  rZ  r[  MPTPIP)r!  r   r"  r#  r!  )r,  r-  r*  	stopPricer[  rZ  buyupdownstoprt  stopPriceTyper*  triggerStopDownPricer-  triggerStopUpPriceT
reduceOnlyr/  LIMITz9 createOrder() requires a price argument for limit ordersr$  r  FpostOnlyhiddenzW createOrder() does not support the postOnly parameter together with a hidden parameterr6  visibleSizezB createOrder() requires a visibleSize parameter for iceberg orders)r/  rt  r*  r,  r-  )r  r  uuidr)  safe_string_upperr\  cost_to_precisionr&   r2   intamount_to_precisionhandle_trigger_pricesr  price_to_precisionupperr#   handle_post_onlyr[  r$   r  )rM  ra  rx  rP  r~  r$  r]  r  ro  r  marginModeUpperr  r*  r,  r-  rZ  r[  triggerPriceTypesr#  triggerPriceTypeValue	priceTypeslPricetpPriceuppercaseTyper/  r~  r  r6  r  s                                rO  r]  z+kucoinfutures.create_contract_order_request?  s:   V$**6;QUQZQZQ\]6K#AB&Tl
 00F&YYv|4F$3GL!/66*"&"8"8"FGJz"477-`#`aa!$":":66"JKGFO7;7Q7QRX7Y4m_>>&*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#'#:#:65#I &)4&001A5&Q&"&GJ2+TWW  (A  A  B  B//&)4//&-@K"'2v(vww6#st{{7F++rP  r2   c                    | j                          | j                  |dd      }| j                  |dg      }i }d}|Z|t        | j                  dz         | j                  |      }|d   |d<   ||d<   | j                  | j                  ||            }n&||d<   | j                  | j                  ||            }| j                  |d      S )	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>`
        rn  ro  NzJ cancelOrder() requires a symbol argument when cancelling by clientOrderIdr2   ra  orderIdrR  )
r  r  r)  r#   r2   r  .futuresPrivateDeleteOrdersClientOrderClientOidr  !futuresPrivateDeleteOrdersOrderIdr[  )rM  r2   ra  r]  ro  r  r^  r  s           rO  cancel_orderzkucoinfutures.cancel_order  s     	**6;P6O#45$~'2~(~[[(F &tGH#0GK JJ4;;W^`fKghH!#GI==dkk'SY>Z[H x00rP  c                 `   | j                          d}|| j                  |      }g }| j                  |ddg       }| j                  |ddg      }d}t	        dt        |            D ]E  }d}|t        | j                  dz         |j                  |d   | j                  ||      d	       G t	        dt        |            D ]  }|j                  ||           |rd
nd}	i }
||
|	<   | j                  | j                  |
|            }| j                  |dg       }| j                  ||      S )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 clientOrderIdsr2   )ra  rn  clientOidsListorderIdsListrR  )r  r  safe_list_2r)  r  r  r#   r2   r  r\  %futuresPrivateDeleteOrdersMultiCancelr  r  rh  )rM  idsra  r]  r  ri  r  useClientorderIdr  
requestKeyr  r^  r   s                rO  cancel_orderszkucoinfutures.cancel_orders  s]    	[[(F))&2BLRTU6$4l#CD q#n-. 	A#~'  3A  )A  B  B!! ,!--na@# 		 q#c(# 	*A!!#a&)	*)9%~
,
==dkk'SY>Z[* &"5  00rP  c                 R   | j                          i }|| j                  |      |d<   | j                  |dd      }| j                  |ddg      }d}|r"| j	                  | j                  ||            }n!| j                  | j                  ||            }| j                  |d      S )aP  
        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
        Nra  rx  r>  rR  )r  	market_idsafe_value_2r)  futuresPrivateDeleteStopOrdersr  futuresPrivateDeleteOrdersr[  )rM  ra  r]  r  r>  r^  s         rO  cancel_all_orderszkucoinfutures.cancel_all_orders  s     	 $v 6GH##FFI>6FI#67::4;;wPV;WXH66t{{7F7STH x00rP  c                 f   | j                          | j                  |      }| j                         }|d   | j                  ||      |d}| j	                  | j                  ||            }| j                  |d      }| j                  | j                  ||      | j                  ||      dd      S )a  
        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>`
        r2   )ra  rA   bizNorR  in)r~  	direction)r  r  r  r  -futuresPrivatePostPositionMarginDepositMarginr  r[  parse_margin_modification)	rM  ra  r~  r]  r  r  r  r^  rR  s	            rO  
add_marginzkucoinfutures.add_margin  s     	V$yy{Tl..vv>

 EEdkkRY[aFbcd x0{{499$G..vv>J
  	rP  c                 \   | j                  |d      }| j                  ||      }| j                  |d      }| j                  |d      }|rdnd}| j                  |d      }| j                  |d      }|| j	                  ||      d |d d | j                  |      d || j                  |      d
S )	Nr2   re  r5  r6  r7  ra  r-  )
rY  ra  rx  r)  r~  totalr  r   r   r  )r\  r  r[  r  safe_symbolr  r  )	rM  rY  r  r2   r  r5  moder  r   s	            rO  r  z'kucoinfutures.parse_margin_modificationc  s    \ dD)!!"f-%%d,<=
OOD+6	#w##FH5%%d,>?	&&x8++J7"Y/
 	
rP  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S | j                  |dd      }| j	                  |d      }| j                  |g d      }|dk(  rd	}n|d
k(  rd}i }	|s||	d<   n|dk7  rt        | j                  dz         d}
|| j                  |      }
|
d   |	d<   |||	d<   |||	d<   d}|r"| j                  | j                  |	|            }n!| j                  | j                  |	|            }| j                  |di       }| j                  |dg       }| j                  ||
||      S )at  
        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  rx  r>  r'  )rx  r'  r>  closeddonerS  ry  r   z= fetchOrdersByStatus() can only fetch untriggered stop ordersNr2   ra  r  r  rR  r(  )r  r  fetch_paginated_call_dynamicsafe_bool_2r  r)  r$   r2   r  futuresPrivateGetStopOrdersr  futuresPrivateGetOrdersr[  r  rh  )rM  r   ra  r  r:  r]  r  r>  r'  r  r  r^  responseDatar   s                 rO  fetch_orders_by_statusz$kucoinfutures.fetch_orders_by_status  s   & 	88AVXbc&445JFTY[`bhii""669=!!&'26#?@XFvF &GHxTWW'ffgg[[(F &tGH!&GI$GG77GV8TUH33DKK4PQHh x<gr:  >>rP  c                     | j                          d}| j                  |dd      \  }}|r| j                  d||||      S | j                  d||||      S )a  
        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  rM  ra  r  r:  r]  r  s         rO  fetch_closed_ordersz!kucoinfutures.fetch_closed_orders  si      	88ATV`a&445H&RWY^`fgg**665%PPrP  c                     | j                          d}| j                  |dd      \  }}|r| j                  d||||      S | j                  d||||      S )aS  
        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>`
        Frz   r  rS  r  r  s         rO  fetch_open_orderszkucoinfutures.fetch_open_orders$  si    $ 	88ART^_&445FPUW\^dee**665%PPrP  c                    | j                          i }d}|h| j                  |dd      }|t        | j                  dz         ||d<   | j	                  |ddg      }| j                  | j                  ||            }n&||d<   | j                  | j                  ||            }|| j                  |      nd}| j                  |d      }| j                  ||      S )a  
        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>`
        Nrn  ro  z7 fetchOrder() requires parameter id or params.clientOidr  rR  )r  r  r&   r2   r)  "futuresPrivateGetOrdersByClientOidr  futuresPrivateGetOrdersOrderIdr  r  ra  )	rM  r2   ra  r]  r  r^  ro  r  r  s	            rO  fetch_orderzkucoinfutures.fetch_order=  s     	: ..v{OTM$"477-f#fgg#0GK YYv_'EFF>>t{{7TZ?[\H!#GI::4;;wPV;WXHX *0);V$$~~h7f55rP  orderc           
         | j                  |d      }| j                  ||      }|d   }| j                  |dd      }| j                  |d      }| j                  |d      }| j	                  |      }| j                  |d      }	| j                  |d      }
| j                  |d      }| j                  |      }| j                  |d	      }| j                  |d
      }| j                  |d      }| j                  |d      }| j                  |d      }|t        j                  |d      rl| j                  |d      }|d   r+t        j                  |t        j                  ||            }n*t        j                  t        j                  ||      |      }| j                  |d      }| j                  |dd      }d }||rdnd}|rdn|}d }|||d}| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  |d      }| j                  i d|d|d|d|d|d|d|d|
d|d|	d| j                  |d       d!|d"|d#d d$|d%|d	|||d ||d d&|      S )'Nra  r2   r  rx  	createdAtr$  rP  feeCurrencyfeerW  
filledSizefilledValueavgDealPricer   r  rD  isActivecancelExistFrS  r  canceled)r  r  rn  r/  r~  r|  	updatedAtro  r~  r*  rt  r  filled	remainingr   r  )r   rY  lastTradeTimestampr9  r  trades)r\  r  r  r  r  r  r  r-   rR  r  
string_mulr[  r\  
safe_order)rM  r  r  r  ra  r  rx  r   r  r$  rP  feeCurrencyIdr  feeCostr~  r  r  r  r  r  r  r   r  ro  r/  r~  r|  r9  s                               rO  ra  zkucoinfutures.parse_order  sD   v ##E84!!(F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 	rP  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )a~  
        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>`
        ra  r2   rR  )r  r  (futuresPublicGetFundingRateSymbolCurrentr  r  parse_funding_rater   s          rO  fetch_funding_ratez kucoinfutures.fetch_funding_rate	  ss     	V$fTl
 @@WV\A]^ ~~h3&&tV44rP  c                 &    | j                  ||      S )a  
        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  )rM  ra  r]  s      rO  fetch_funding_intervalz$kucoinfutures.fetch_funding_interval%	  s     &&vv66rP  c                 |   | j                  |d      }| j                  |d      }i d|d| j                  ||d d      dd dd dd dd d	d d
d d| j                  |d      d|d| j	                  |      d| j                  |d      dd dd dd dd dd d| j                  | j                  |d            iS )Nr  ra  rY  r{  r  r  interestRateestimatedSettlePricer   r  r  r  fundingTimestampfundingDatetimenextFundingRatepredictedValuenextFundingTimestampnextFundingDatetimepreviousFundingRatepreviousFundingTimestamppreviousFundingDatetimeintervalr  )r  r\  r  r  r  parse_funding_interval)rM  rR  r  r  r  s        rO  r  z kucoinfutures.parse_funding_rate1	  sV     ,,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%
 	
rP  c                 8    dddddd}| j                  |||      S )Nr  r  r
  16h24h)360000014400000288000005760000086400000r\  )rM  r  	intervalss      rO  r  z$kucoinfutures.parse_funding_intervalR	  s/    
	 	8X>>rP  c                    |d d d}| j                  |d      }| j                  |d      }| j                  |      }| j                         }| j                  |d      |d<   | j                  |d      |d<   |||<   | j	                  |      S )N)rY  r   r  rR  r  availableBalancefreeaccountEquityr  )r[  r\  r  accountsafe_balance)rM  r^  r  rR  r  r  r  s          rO  parse_balancezkucoinfutures.parse_balance\	  s    

 x0%%dJ7
&&z2,,.**41CD++D/Bt  ((rP  c                 t   | j                          | j                  | j                  d      }| j                  | j                  di       }| j                  |d|      }| j                  |d|      }| j	                  |      }d|d   i}| j                  | j                  ||            }| j                  |      S )a  
        query for balance and get the amount of funds available for trading or funds locked in orders

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

        :param dict [params]: extra parameters specific to the exchange API endpoint
        :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
        r  rX   r  r2   )r  r\  rG  r[  r   futuresPrivateGetAccountOverviewr  r  )rM  r]  defaultCodefetchBalanceOptionsr  r  r  r^  s           rO  fetch_balancezkucoinfutures.fetch_balancek	  s     	&&t||V<"oodllNBO&&':FKP<==&
 88Wf9UV  !!(++rP  fromAccount	toAccountc                 d   | j                          | j                  |      }| j                  ||      }| j                  |d      |d}| j	                  |      }	d}
|	dk(  s|	dk(  r'|	|d<   | j                  | j                  ||            }
n]|dk(  s
|dk(  s|d	k(  r6| j	                  |      |d
<   | j                  | j                  ||            }
nt        | j                  dz         | j                  |
di       }| j                  | j                  ||      | j                  |      ||d      S )a  
        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>`
        r2   )r  r~  NTRADEMAINrecAccountTyperC   rB   r{  payAccountTypezR transfer() only supports transfers between future/swap, spot and funding accountsrR  )r~  r  r  )r  r  currency_to_precisionr\  parse_transfer_typefuturesPrivatePostTransferOutr  futuresPrivatePostTransferInr$   r2   r  parse_transferrL  )rM  r  r~  r  r  r]  r  amountToPrecisionr  toAccountStringr^  rR  s               rO  r   zkucoinfutures.transfer	  sD    	==& 66tVD((48'
 229=g%F)B(7G$%99$++gv:VWH2 ("i6&9Y*=T(,(@(@(MG$%88Wf9UVH TWW'{{||~~h3{{4..tX>''(9:&"A
  	rP  r   r  c                     | j                  |d      }| j                  |d      || j                  |      | j                  d |      | j	                  |d      d d | j                  |d      |d	S )Nr  applyIdr~  r   )	r2   r   r  r  r~  r  r  r   rY  )r  r\  r  r  r  )rM  r   r  r   s       rO  r  zkucoinfutures.parse_transfer	  sx    < %%h<	""8Y7"Y///h?&&x:&&x:

 
	
rP  r   c                 0    ddi}| j                  |||      S )N
PROCESSINGpendingr  )rM  r   statusess      rO  parse_transfer_statusz#kucoinfutures.parse_transfer_status
  s%    )
 &&99rP  transferTypec                 2    ddd}| j                  |||      S )Nr  r  )r@   r   )r  )rM  r  transferTypess      rO  r  z!kucoinfutures.parse_transfer_type
  s&    
 %%m\<PPrP  c                    | j                          d}| j                  |dd      \  }}|r| j                  d||||      S i }d}|| j                  |      }|d   |d<   |||d<   |t	        d|      |d	<   | j                  d
||      \  }}| j                  | j                  ||            }| j                  |di       }	| j                  |	dg       }
| j                  |
|||      S )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>`
        Frx   r  Nr2   ra  r  r8  pageSizer  rR  r(  )r  r  r  r  r  handle_until_optionfuturesPrivateGetFillsr  r  r  parse_trades)rM  ra  r  r:  r]  r  r  r  r^  rR  r  s              rO  fetch_my_tradeszkucoinfutures.fetch_my_trades
  s    	88R\]&44_feUZ\bcc
 [[(F &tGH!&GI"%dE"2GJ227GVL..t{{7F/KLD ~~h3gr2  >>rP  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  ||||      S )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>`
        ra  r2   rR  )r  r  futuresPublicGetTradeHistoryr  r  r   )	rM  ra  r  r:  r]  r  r  r^  r  s	            rO  fetch_tradeszkucoinfutures.fetch_tradesX
  sv     	V$fTl
 44T[[&5QR$ &"5  >>rP  tradec                    | j                  |d      }| j                  ||d      }| j                  |dd      }| j                  |d      }| j                  |d      }| j                  |d      }|| j	                  |dz        }n| j                  |d	      }d
|v r||dz  }| j                  |dd      }| j                  |dd      }	| j                  |d      }
d }| j                  |d      }|J| j                  |d      }| j                  |      }||
dk(  r|d   n|d   }||| j                  |d      d}| j                  |dd      }|dk(  rd }| j                  |dd      }|>| j                  |d      }t        j                  ||	      }t        j                  ||      }| j                  ||||| j                  |      |d   |||
||	||d|      S )Nra  r  tradeIdr2   r  	liquidityr  r  r  	dealValuer8  r$  	dealPricerW  r~  rP  r  r  sellrs  rr  feeRate)r  r  raterx  	orderTypematchfundsr  r  )rY  r2   r  r   r  ra  rx  takerOrMakerrP  r$  r~  r  r  )
r\  r  r  r  r  r  r-   r  
safe_trader  )rM  r%  r  r  r2   r  r1  r   priceStringamountStringrP  r  feeCostStringr  r  rx  
costStringr  contractCosts                      rO  parse_tradezkucoinfutures.parse_trade~
  s,   X ##E84!!(FC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&( " 
  	rP  c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }|d   d   }| j	                  ||||dd	i      S )
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>`
        Nr2   r  r  r  rR  r(  rx  r   )r  r  futuresPrivateGetDepositListr  parse_transactions	rM  r  r  r:  r]  r  r  r^  r  s	            rO  fetch_depositszkucoinfutures.fetch_deposits
  s     	}}T*H"*4.GJ"'GJ!&GI44T[[&5QR8  '0&&|XuefV_M`aarP  c                     | j                          i }d}|| j                  |      }|d   |d<   |||d<   |||d<   | j                  | j                  ||            }|d   d   }| j	                  ||||dd	i      S )
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>`
        Nr2   r  r  r  rR  r(  rx  
withdrawal)r  r  futuresPrivateGetWithdrawalListr  r;  r<  s	            rO  fetch_withdrawalszkucoinfutures.fetch_withdrawals0  s     	}}T*H"*4.GJ"'GJ!&GI77GV8TU8  '0&&|XuefVbMcddrP  c                    | j                          | j                  |      }|d   st        | j                  dz         d|d   i}| j	                  | j                  ||            }| j                  |d      }| j                  ||      S )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 onlyra  r2   rR  )r  r  r$   r2   (futuresPublicGetContractsRiskLimitSymbolr  r[  parse_market_leverage_tiersr   s          rO  fetch_market_leverage_tiersz)kucoinfutures.fetch_market_leverage_tiersb  s     	V$j!TWW'ccddfTl
 @@WV\A]^$ x0//f==rP  c                 j   g }t        dt        |            D ]  }||   }| j                  |d      }|j                  | j	                  |d      | j                  ||dd      |d   | j	                  |d      | j	                  |d      | j	                  |d	      | j	                  |d
      |d        |S )zz
 @ignore
        :param dict info: Exchange market response for 1 market
        :param dict market: CCXT market
        r   ra  r  Nr{  rr  minRiskLimitmaxRiskLimitmaintainMarginr  )tierra  r  minNotionalmaxNotionalmaintenanceMarginRater  rY  )r  r  r\  r  r  r  )rM  rY  r  r   r  rJ  r  s          rO  rD  z)kucoinfutures.parse_market_leverage_tiers  s    " q#d)$ 	A7D''h7HLL((w7**8VT:N"6N#//nE#//nE)-)9)9$@P)Q#//mD	 		 rP  c                    |t        | j                  dz         | j                          | j                  |      }|d   d| j	                         d}| j                  |d      }| j                  |dg      }|||d<   ||dz   |d<   |||d<   ||dz
  |d<   | j                  | j                  ||            }| j                  |d	      }	| j                  |	|||      S )
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 argumentr2   r   )ra  r  r  r'  r  l    PRW r  rR  )r#   r2   r  r  r  r  r)  $futuresPublicGetContractFundingRatesr  r[  parse_funding_rate_histories)
rM  ra  r  r:  r]  r  r  r'  r^  rR  s
             rO  fetch_funding_rate_historyz(kucoinfutures.fetch_funding_rate_history  s    >#DGG.e$effV$Tl##%

 !!&'26G9-#GFO} %(@ @!GDM} %(@ @<<T[[RX=YZ x000vueLLrP  c                     | j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      || j	                  |      dS )N	timepointra  r  )rY  ra  r  r   r  )r  r\  r  r  r  )rM  rY  r  r   r  s        rO  parse_funding_rate_historyz(kucoinfutures.parse_funding_rate_history  sb    %%dK8	##D(3&&x8++D-@"Y/
 	
rP  c                    | j                          | j                  |      }| j                  |d      }| j                  |dd      }| j	                  |ddg      }|| j                  | j                               }|d   d|dd}d}|r"| j                  | j                  ||            }n!| j                  | j                  ||            }| j                  ||      S )	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>`
        ro  rY  FNr2   Tr  )ra  
closeOrderrn  rx  )r  r  r\  r\  r)  number_to_stringr  r^  r  r`  ra  )	rM  ra  rP  r]  r  ro  rb  r  r^  s	            rO  close_positionzkucoinfutures.close_position  s     	V$((ANN6659	6FO#<=  11$**,?MTl&	
 88Wf9UVH44T[[&5QRH&11rP  c                 t   | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |dg       }| j                  |d      }| j                  |d      }|| j                  ||      | j                  |d      | j                  |d      ddd	S )
am  
        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  r2   rR  r   ra  r}  r|  T)rY  ra  r   r   r   r   )	r  r  privateGetTradeFeesr  r  r  r\  r  r  )	rM  ra  r]  r  r  r^  rR  firstr  s	            rO  fetch_trading_feezkucoinfutures.fetch_trading_fee  s     	V$vd|
 ++DKK,HI ~~h3tQ'##E84&&x8%%e^<%%e^<
 	
rP  c                     | j                          | j                  |      }d|d   i}| j                  | j                  ||            }| j	                  |di       }| j                  ||      S )a  
        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>`
        ra  r2   rR  )r  r  &futuresPrivateGetPositionGetMarginModer  r  parse_margin_moder   s          rO  fetch_margin_modezkucoinfutures.fetch_margin_mode*  ss     	V$fTl
 >>t{{7TZ?[\ ~~h3%%dF33rP  r)  c                 J    | j                  |d      }|dk(  rdnd}||d   |dS )Nr)  ISOLATEDr7  r6  ra  )rY  ra  r)  r  )rM  r)  r  
marginTypes       rO  r_  zkucoinfutures.parse_margin_modeF  s:    %%j,?
$.*$<Z7
X&$
 	
rP  c                 \   |t        | j                  dz         | j                  d|dddg       | j                          | j	                  |      }|d   |j                         d}| j                  | j                  ||            }| j                  |di       }| j                  ||      S )	a  
        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)  r6  r7  r2   )ra  r)  rR  )
r#   r2   check_required_argumentr  r  r  *futuresPrivatePostPositionChangeMarginModer  r  r_  )rM  r)  ra  r]  r  r  r^  rR  s           rO  set_margin_modezkucoinfutures.set_margin_modeO  s     >#DGG.[$[\\$$_j,QXZdPefV$Tl$**,
 BB4;;wX^C_` ~~h3%%dF33rP  c                 n   d}| j                  ||      \  }}|dk7  rt        | j                  dz         | j                          | j	                  |      }d|d   i}| j                  | j                  ||            }| j                  |di       }| j                  ||      }| j                  |d|i      S )ay  
        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>`
        Nr6  zG fetchLeverage() currently supports only params["marginMode"] = "cross"ra  r2   rR  r)  )	handle_margin_mode_and_paramsr(   r2   r  r  %futuresPrivateGetGetCrossUserLeverager  r  parse_leverage)	rM  ra  r]  r)  r  r  r^  rR  parseds	            rO  fetch_leveragezkucoinfutures.fetch_leveragep  s     
!??O
F tww)rrssV$fTl
 ==dkk'SY>Z[ ~~h3$$T62{{6*$
  	rP  r2  c                 4   d}| j                  ||      \  }}|dk7  rt        | j                  dz         | j                          | j	                  |      }|d   t        |      d}| j                  | j                  ||            }| j                  ||      S )a  
        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
        Nr6  zE setLeverage() currently supports only params["marginMode"] = "cross"r2   )ra  r2  )	ri  r(   r2   r  r  str)futuresPrivatePostChangeCrossUserLeverager  rk  )rM  r2  ra  r]  r)  r  r  r^  s           rO  set_leveragezkucoinfutures.set_leverage  s     
!??O
F tww)ppqqV$TlH
 AA$++gW]B^_ ""8V44rP  c                     | j                  |d      }| j                  ||      }| j                  |d      }||d   d ||dS )Nra  r2  )rY  ra  r)  longLeverageshortLeverage)r\  r  r  )rM  r2  r  r  leverageNums        rO  rk  zkucoinfutures.parse_leverage  sV    ##Hh7!!(F3''*=X&'(
 	
rP  )N)]__name__
__module____qualname__r   rK  r_  r   r   r  r	   r  ro  listr  r  r   r  r   r  r   r  r  r   r   r  dictr  r  r   r  r!  r   r%  r+  r  r   r   floatr   re  r   rl  r]  r  r  r  r   r  r  r  r   r  r  r  ra  r   r  r  r  r  r   r  r  r   r   r   r  r  r  r!  r   r$  r8  r   r=  rA  r   rE  rD  rQ  rT  rX  r   r\  r   r`  r_  rg  r
   rm  rq  rk  __classcell__)rN  s   @rO  r/   r/      s   q# qf #% 
: $& ^$v, ^@ !# 3s 3$ 26DW[df 4H# 4Hc 4HQT 4Hkoptku 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 :.x @B .'D$6 .'` x|  EG T,C T,y T,PY T,ch T,qt T,l 37r %1s %1C %1N 04B 71 71r /32 !1 !1F =? 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?) ) $& #,( #,J [] 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 24 !S ! !F 9=R 5S 5# 5<

t 

V 

x 

rP  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/    rP  rO  <module>r     st     3 r  r  r  r  r  r  r  0 - - . ' . ) * ) . 1 ) 4 %a2
FK a2
rP  